Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
b619458a
U
uni-app
项目概览
小浣熊撸代码
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b619458a
编写于
6月 29, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 解决App端局部组件props中的id会覆盖根节点id属性的问题 question/99900
上级
06c594dd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
81 addition
and
4 deletion
+81
-4
packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/util.js
...i-plugin-uni/packages/webpack-uni-app-loader/view/util.js
+3
-2
packages/webpack-uni-mp-loader/__tests__/components.spec.js
packages/webpack-uni-mp-loader/__tests__/components.spec.js
+62
-0
packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
...pack-uni-mp-loader/lib/babel/scoped-component-traverse.js
+16
-2
未找到文件。
packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/util.js
浏览文件 @
b619458a
...
...
@@ -19,7 +19,8 @@ function parseComponents (content, traverse) {
components
:
[],
options
:
{
name
:
null
,
inheritAttrs
:
null
inheritAttrs
:
null
,
props
:
null
}
})
return
{
...
...
@@ -30,4 +31,4 @@ function parseComponents (content, traverse) {
module
.
exports
=
{
parseComponents
}
}
packages/webpack-uni-mp-loader/__tests__/components.spec.js
浏览文件 @
b619458a
...
...
@@ -22,6 +22,28 @@ function assertCodegen (content, expectedComponents, isScoped = true) {
expect
(
JSON
.
stringify
(
components
)).
toBe
(
JSON
.
stringify
(
expectedComponents
))
}
function
assertCodegenOptions
(
content
,
expectedOptions
,
isScoped
=
true
)
{
const
{
state
:
{
options
}
}
=
(
isScoped
?
scopedComponentTraverse
:
globalComponentTraverse
)(
parser
.
parse
(
content
,
{
sourceType
:
'
module
'
,
plugins
:
[
'
typescript
'
]
}),
{
components
:
[],
options
:
{
name
:
null
,
inheritAttrs
:
null
,
props
:
null
}
})
expect
(
JSON
.
stringify
(
options
)).
toBe
(
JSON
.
stringify
(
expectedOptions
))
}
describe
(
'
mp:loader
'
,
()
=>
{
it
(
'
parse scoped component
'
,
()
=>
{
assertCodegen
(
...
...
@@ -153,6 +175,46 @@ global['__wxVueOptions'] = {
source
:
'
@/components/my-button/my-button.vue
'
}
])
assertCodegenOptions
(
`export default {
name: 'test'
}`
,
{
name
:
'
"test"
'
,
inheritAttrs
:
null
,
props
:
null
}
)
assertCodegenOptions
(
`export default {
props: ['id', 'test']
}`
,
{
name
:
null
,
inheritAttrs
:
null
,
props
:
'
["id","test"]
'
}
)
assertCodegenOptions
(
`export default {
props: {
id: {
type: String
},
'test': {
type: String
}
}
}`
,
{
name
:
null
,
inheritAttrs
:
null
,
props
:
'
["id","test"]
'
}
)
})
it
(
'
parse global component
'
,
()
=>
{
...
...
packages/webpack-uni-mp-loader/lib/babel/scoped-component-traverse.js
浏览文件 @
b619458a
...
...
@@ -6,7 +6,7 @@ const {
}
=
require
(
'
./util
'
)
function
handleObjectExpression
(
declaration
,
path
,
state
)
{
if
(
state
.
options
)
{
// name,inheritAttrs
if
(
state
.
options
)
{
// name,inheritAttrs
,props
Object
.
keys
(
state
.
options
).
forEach
(
name
=>
{
const
optionProperty
=
declaration
.
properties
.
filter
(
prop
=>
{
return
t
.
isObjectProperty
(
prop
)
&&
...
...
@@ -14,7 +14,21 @@ function handleObjectExpression (declaration, path, state) {
prop
.
key
.
name
===
name
})[
0
]
if
(
optionProperty
)
{
if
(
t
.
isStringLiteral
(
optionProperty
.
value
))
{
if
(
name
===
'
props
'
)
{
if
(
t
.
isArrayExpression
(
optionProperty
.
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
})
=>
{
if
(
t
.
isIdentifier
(
key
))
{
props
.
push
(
key
.
name
)
}
else
if
(
t
.
isStringLiteral
(
key
))
{
props
.
push
(
key
.
value
)
}
})
state
.
options
[
name
]
=
JSON
.
stringify
(
props
)
}
}
else
if
(
t
.
isStringLiteral
(
optionProperty
.
value
))
{
state
.
options
[
name
]
=
JSON
.
stringify
(
optionProperty
.
value
.
value
)
}
else
{
state
.
options
[
name
]
=
optionProperty
.
value
.
value
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录