Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
9d30f60b
U
uni-app
项目概览
DCloud
/
uni-app
4 个月 前同步成功
通知
730
Star
38707
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9d30f60b
编写于
12月 02, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): defineComponent #2166
上级
7c70802a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
37 deletion
+66
-37
packages/webpack-uni-mp-loader/__tests__/components.spec.js
packages/webpack-uni-mp-loader/__tests__/components.spec.js
+42
-33
packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
...pack-uni-mp-loader/lib/babel/scoped-component-traverse.js
+24
-4
未找到文件。
packages/webpack-uni-mp-loader/__tests__/components.spec.js
浏览文件 @
9d30f60b
...
...
@@ -46,6 +46,24 @@ function assertCodegenOptions (content, expectedOptions, isScoped = true) {
describe
(
'
mp:loader
'
,
()
=>
{
it
(
'
parse scoped component
'
,
()
=>
{
assertCodegen
(
`import { uniBadge,uniCard} from '@dcloudio/uni-ui';
export default defineComponent({
components: {
'uni-badge':uniBadge,
'uni-card':uniCard
}
})`
,
[{
name
:
'
uni-badge
'
,
value
:
'
uniBadge
'
,
source
:
'
@dcloudio/uni-ui/lib/uni-badge/uni-badge
'
},
{
name
:
'
uni-card
'
,
value
:
'
uniCard
'
,
source
:
'
@dcloudio/uni-ui/lib/uni-card/uni-card
'
}])
assertCodegen
(
`
import mediaList from '@/components/tab-nvue/mediaList.vue';
...
...
@@ -158,29 +176,27 @@ global['__wxVueOptions'] = {
'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
'
}
[{
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
'
}
])
assertCodegenOptions
(
`export default {
name: 'test'
}`
,
{
}`
,
{
name
:
'
"test"
'
,
inheritAttrs
:
null
,
props
:
null
...
...
@@ -191,8 +207,7 @@ global['__wxVueOptions'] = {
`const options = {
name: 'test'
}
export default options`
,
{
export default options`
,
{
name
:
'
"test"
'
,
inheritAttrs
:
null
,
props
:
null
...
...
@@ -204,8 +219,7 @@ global['__wxVueOptions'] = {
options = {
name: 'test'
}
export default options`
,
{
export default options`
,
{
name
:
'
"test"
'
,
inheritAttrs
:
null
,
props
:
null
...
...
@@ -216,8 +230,7 @@ global['__wxVueOptions'] = {
`const options = Vue.extend({
name: 'test'
})
export default options`
,
{
export default options`
,
{
name
:
'
"test"
'
,
inheritAttrs
:
null
,
props
:
null
...
...
@@ -229,8 +242,7 @@ global['__wxVueOptions'] = {
options = Vue.extend({
name: 'test'
})
export default options`
,
{
export default options`
,
{
name
:
'
"test"
'
,
inheritAttrs
:
null
,
props
:
null
...
...
@@ -241,8 +253,7 @@ global['__wxVueOptions'] = {
`const options = {
name: 'test'
}
export default Vue.extend(options)`
,
{
export default Vue.extend(options)`
,
{
name
:
'
"test"
'
,
inheritAttrs
:
null
,
props
:
null
...
...
@@ -252,8 +263,7 @@ global['__wxVueOptions'] = {
assertCodegenOptions
(
`export default {
props: ['id', 'test']
}`
,
{
}`
,
{
name
:
null
,
inheritAttrs
:
null
,
props
:
'
["id","test"]
'
...
...
@@ -270,8 +280,7 @@ global['__wxVueOptions'] = {
type: String
}
}
}`
,
{
}`
,
{
name
:
null
,
inheritAttrs
:
null
,
props
:
'
["id","test"]
'
...
...
@@ -302,4 +311,4 @@ global['__wxVueOptions'] = {
source
:
'
@/components/tab-nvue/mediaList.vue
'
}],
false
)
})
})
})
packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
浏览文件 @
9d30f60b
...
...
@@ -16,10 +16,15 @@ function handleObjectExpression (declaration, path, state) {
if
(
optionProperty
)
{
if
(
name
===
'
props
'
)
{
if
(
t
.
isArrayExpression
(
optionProperty
.
value
))
{
state
.
options
[
name
]
=
JSON
.
stringify
(
optionProperty
.
value
.
elements
.
filter
(
element
=>
t
.
isStringLiteral
(
element
)).
map
(({
value
})
=>
value
))
state
.
options
[
name
]
=
JSON
.
stringify
(
optionProperty
.
value
.
elements
.
filter
(
element
=>
t
.
isStringLiteral
(
element
)).
map
(({
value
})
=>
value
))
}
else
if
(
t
.
isObjectExpression
(
optionProperty
.
value
))
{
const
props
=
[]
optionProperty
.
value
.
properties
.
forEach
(({
key
})
=>
{
optionProperty
.
value
.
properties
.
forEach
(({
key
})
=>
{
if
(
t
.
isIdentifier
(
key
))
{
props
.
push
(
key
.
name
)
}
else
if
(
t
.
isStringLiteral
(
key
))
{
...
...
@@ -60,7 +65,9 @@ function handleComponentsObjectExpression (componentsObjExpr, path, state, prepe
state
.
components
=
prepend
?
components
.
concat
(
state
.
components
)
:
components
}
function
handleIdentifier
({
name
},
path
,
state
)
{
function
handleIdentifier
({
name
},
path
,
state
)
{
// 仅做有限查找
for
(
let
i
=
path
.
container
.
length
;
i
>
0
;
i
--
)
{
const
node
=
path
.
container
[
i
-
1
]
...
...
@@ -101,6 +108,19 @@ module.exports = function (ast, state = {
options
:
{}
})
{
babelTraverse
(
ast
,
{
CallExpression
(
path
)
{
const
callee
=
path
.
node
.
callee
const
args
=
path
.
node
.
arguments
const
objExpr
=
args
[
0
]
if
(
t
.
isIdentifier
(
callee
)
&&
callee
.
name
===
'
defineComponent
'
&&
args
.
length
===
1
&&
t
.
isObjectExpression
(
objExpr
)
)
{
handleObjectExpression
(
objExpr
,
path
,
state
)
}
},
AssignmentExpression
(
path
)
{
const
leftExpression
=
path
.
node
.
left
const
rightExpression
=
path
.
node
.
right
...
...
@@ -162,4 +182,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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录