提交 cf40fb71 编写于 作者: Q qiang

fix: 解决App端使用小程序组件时局部组件不显示的问题

上级 bce0f7ee
......@@ -122,6 +122,37 @@ global['__wxVueOptions'] = {
source: '../icon/loading.vue'
}
])
assertCodegen(
`import myButton from '@/components/my-button/my-button.vue';
export default {
components: {
myButton
}
}
import VanButton from '../button/index.vue'
import VanSearch from '../search/index.vue'
exports.default.components = Object.assign({
'van-button': VanButton,
'van-search': VanSearch,
},exports.default.components || {})`,
[
{
name: 'van-button',
value: 'VanButton',
source: '../button/index.vue'
},
{
name: 'van-search',
value: 'VanSearch',
source: '../search/index.vue'
},
{
name: 'myButton',
value: 'myButton',
source: '@/components/my-button/my-button.vue'
}
])
})
it('parse global component', () => {
......@@ -147,4 +178,4 @@ global['__wxVueOptions'] = {
source: '@/components/tab-nvue/mediaList.vue'
}], false)
})
})
})
......@@ -34,15 +34,16 @@ function handleObjectExpression (declaration, path, state) {
}
}
function handleComponentsObjectExpression (componentsObjExpr, path, state) {
function handleComponentsObjectExpression (componentsObjExpr, path, state, prepend) {
const properties = componentsObjExpr.properties
.filter(prop => t.isObjectProperty(prop) && t.isIdentifier(prop.value))
state.components = parseComponents(properties.map(prop => {
const components = parseComponents(properties.map(prop => {
return {
name: prop.key.name || prop.key.value,
value: prop.value.name
}
}), path.scope.bindings, path)
state.components = prepend ? components.concat(state.components) : components
}
module.exports = function (ast, state = {
......@@ -74,7 +75,7 @@ module.exports = function (ast, state = {
rightExpression.arguments.length === 2 &&
t.isObjectExpression(rightExpression.arguments[0])
) {
handleComponentsObjectExpression(rightExpression.arguments[0], path, state)
handleComponentsObjectExpression(rightExpression.arguments[0], path, state, true)
}
},
ExportDefaultDeclaration (path) {
......@@ -105,4 +106,4 @@ module.exports = function (ast, state = {
ast,
state
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册