Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yiicenne
uni-app
提交
fc8b6535
U
uni-app
项目概览
yiicenne
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fc8b6535
编写于
3月 15, 2023
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): merge node for native scoped slot
上级
17c95bca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
28 deletion
+40
-28
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
...ni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+3
-3
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
...uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
+4
-4
packages/uni-template-compiler/lib/template/traverse.js
packages/uni-template-compiler/lib/template/traverse.js
+33
-21
未找到文件。
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
浏览文件 @
fc8b6535
...
...
@@ -97,11 +97,11 @@ describe('mp:compiler-mp-alipay', () => {
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<component1 :text="
\'
text
\'
"><template v-slot="props"><view :class="{text:props.text}">{{props.text}}</view></template></component1>
'
,
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
block slot-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></block
></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}" slot-scope="props">{{props.text}}</view
></component1>
'
)
assertCodegen
(
'
<component1 :text="
\'
text
\'
"><template v-slot="{text}"><view :class="{text:text}">{{text}}</view></template></component1>
'
,
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
block slot-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></block
></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}"><
view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}" slot-scope="__SCOPED__">{{__SCOPED__.text}}</view
></component1>
'
)
})
...
...
@@ -112,7 +112,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<foo><template v-slot:[test]="{user}"><view>{{user}}</view></template></foo>
'
,
'
<foo vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[test]}}"><view slot="{{test}}" slot-scope="__SCOPED__">
<view>{{__SCOPED__.user}}</view>
</view></foo>
'
'
<foo vue-id="551070e6-1" onVueInit="__l" vue-slots="{{[test]}}"><view slot="{{test}}" slot-scope="__SCOPED__">
{{__SCOPED__.user}}
</view></foo>
'
)
})
...
...
packages/uni-template-compiler/__tests__/compiler-mp-baidu.spec.js
浏览文件 @
fc8b6535
...
...
@@ -40,7 +40,7 @@ describe('mp:compiler-mp-baidu', () => {
)
assertCodegen
(
'
<foo><view slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
block><view>{{foo}}</view></block
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
default
\'
]}}"><
view>{{foo}}</view
></foo>
'
)
})
...
...
@@ -51,7 +51,7 @@ describe('mp:compiler-mp-baidu', () => {
)
assertCodegen
(
'
<foo><view slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
block slot="foo"><view>{{foo}}</view></block
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
view slot="foo">{{foo}}</view
></foo>
'
)
})
...
...
@@ -62,7 +62,7 @@ describe('mp:compiler-mp-baidu', () => {
)
assertCodegen
(
'
<foo><view v-if="
\n
show
\n
" slot="foo" slot-scope="bar">{{ bar.foo }}</view></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
block slot="foo"><block s-if="{{show}}"><view>{{foo}}</view></block></block
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[
\'
foo
\'
]}}"><
view slot="foo" s-if="{{show}}">{{foo}}</view
></foo>
'
)
})
...
...
@@ -88,7 +88,7 @@ describe('mp:compiler-mp-baidu', () => {
)
assertCodegen
(
'
<foo><template v-slot:[test]="{user}"><view>{{user}}</view></template></foo>
'
,
'
<foo vue-id="551070e6-1" vue-slots="{{[test]}}"><
block slot="{{test}}"><view>{{user}}</view></block
></foo>
'
'
<foo vue-id="551070e6-1" vue-slots="{{[test]}}"><
view slot="{{test}}">{{user}}</view
></foo>
'
)
})
...
...
packages/uni-template-compiler/lib/template/traverse.js
浏览文件 @
fc8b6535
...
...
@@ -390,9 +390,10 @@ function traverseResolveScopedSlots (callExprNode, state) {
vIfs
.
push
(
attr
[
vIfAttrName
])
delete
attr
[
vIfAttrName
]
}
node
.
type
=
child
.
type
node
.
attr
=
child
.
attr
=
nodeAttr
=
Object
.
assign
(
attr
,
nodeAttr
)
node
.
children
=
child
.
children
child
.
attr
=
nodeAttr
=
Object
.
assign
(
attr
,
nodeAttr
)
for
(
const
key
in
child
)
{
node
[
key
]
=
child
[
key
]
}
child
=
node
}
else
{
resolveVIf
()
...
...
@@ -412,9 +413,14 @@ function traverseResolveScopedSlots (callExprNode, state) {
slotNode
=
node
}
if
(
slotNode
&&
slotNode
!==
top
)
{
// TODO 多层 v-for 嵌套时,此处理导致作用域发生变化,需安全重命名
slotNode
.
attr
.
slot
=
top
.
attr
.
slot
delete
top
.
attr
.
slot
// TODO 多层 v-for 嵌套时,此处理导致作用域发生变化,需安全重命名 slot name
[
'
slot
'
,
'
slot-scope
'
].
forEach
(
key
=>
{
const
topAttr
=
top
.
attr
if
(
key
in
topAttr
)
{
slotNode
.
attr
[
key
]
=
topAttr
[
key
]
delete
topAttr
[
key
]
}
})
}
}
resolveVIf
()
...
...
@@ -472,25 +478,31 @@ function traverseResolveScopedSlots (callExprNode, state) {
const
parentName
=
parentNode
.
type
const
paramExprNode
=
fnProperty
.
value
.
params
[
0
]
return
options
.
platform
.
resolveScopedSlots
(
const
node
=
options
.
platform
.
resolveScopedSlots
(
slotName
,
{
genCode
,
generate
,
ownerName
,
parentName
,
parentNode
,
resourcePath
,
paramExprNode
,
returnExprNodes
,
traverseExpr
:
function
(
exprNode
,
state
)
{
const
ast
=
traverseExpr
(
exprNode
,
state
)
initParent
(
ast
)
return
ast
genCode
,
generate
,
ownerName
,
parentName
,
parentNode
,
resourcePath
,
paramExprNode
,
returnExprNodes
,
traverseExpr
:
function
(
exprNode
,
state
)
{
const
ast
=
traverseExpr
(
exprNode
,
state
)
initParent
(
ast
)
return
ast
},
normalizeChildren
},
normalizeChildren
},
state
)
// 对原生支持作用域插槽的小程序平台,优化节点
if
([
'
mp-baidu
'
,
'
mp-alipay
'
].
includes
(
platformName
))
{
node
.
attr
[
ATTR_SLOT_ORIGIN
]
=
slotNameOrigin
return
merge
(
node
,
[
'
template
'
,
'
block
'
])
}
return
node
}
if
(
options
.
scopedSlotsCompiler
===
'
auto
'
&&
slotNode
.
scopedSlotsCompiler
===
'
augmented
'
)
{
parentNode
.
attr
[
'
scoped-slots-compiler
'
]
=
'
augmented
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录