Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
89184583
U
uni-app
项目概览
MuGuiLin
/
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,发现更多精彩内容 >>
提交
89184583
编写于
6月 28, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): named slot with v-if fixed #2635
上级
66d611b2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
5 deletion
+39
-5
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
...es/uni-template-compiler/__tests__/compiler-extra.spec.js
+23
-0
packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
...late-compiler/lib/script/traverse/resolve-scoped-slots.js
+7
-2
packages/uni-template-compiler/lib/template/traverse.js
packages/uni-template-compiler/lib/template/traverse.js
+9
-3
未找到文件。
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
浏览文件 @
89184583
...
...
@@ -274,6 +274,29 @@ describe('mp:compiler-extra', () => {
)
})
it
(
'
generate v-slot with v-if
'
,
()
=>
{
assertCodegen
(
'
<custom-view><template v-if="show">hello</template></custom-view>
'
,
'
<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
default
\'
]}}"><block wx:if="{{show}}">hello</block></custom-view>
'
)
assertCodegen
(
'
<custom-view><template v-if="show" #name>hello</template></custom-view>
'
,
'
<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
name
\'
]}}"><view slot="name" wx:if="{{show}}">hello</view></custom-view>
'
)
assertCodegen
(
'
<custom-view><template v-if="show" #name><text>hello</text></template></custom-view>
'
,
'
<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
name
\'
]}}"><text slot="name" wx:if="{{show}}">hello</text></custom-view>
'
)
assertCodegen
(
'
<custom-view><template v-if="show" #name><view>hello</view></template></custom-view>
'
,
'
<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
name
\'
]}}"><view slot="name" wx:if="{{show}}">hello</view></custom-view>
'
)
assertCodegen
(
'
<custom-view><template v-if="show" #name><view v-if="test1||test2">hello</view></template></custom-view>
'
,
'
<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
name
\'
]}}"><view slot="name" wx:if="{{(show)&&(test1||test2)}}">hello</view></custom-view>
'
)
})
it
(
'
generate events inside v-for
'
,
()
=>
{
assertCodegen
(
'
<view v-for="item in dataList" :key="item.id" @click="click1(item, 1);click2(item, 2);"/>
'
,
...
...
packages/uni-template-compiler/lib/script/traverse/resolve-scoped-slots.js
浏览文件 @
89184583
...
...
@@ -51,7 +51,12 @@ function replaceId (path, ids) {
}
module
.
exports
=
function
getResolveScopedSlots
(
parent
,
state
)
{
const
properties
=
parent
.
get
(
'
arguments.0.elements.0.properties
'
)
let
objectPath
=
parent
.
get
(
'
arguments.0.elements.0
'
)
// TODO v-else
if
(
objectPath
.
isConditionalExpression
())
{
objectPath
=
objectPath
.
get
(
'
consequent
'
)
}
const
properties
=
objectPath
.
get
(
'
properties
'
)
const
fn
=
properties
.
find
(
path
=>
path
.
get
(
'
key
'
).
isIdentifier
({
name
:
'
fn
'
}))
const
params
=
fn
.
get
(
'
value.params.0
'
)
if
(
!
params
)
{
...
...
@@ -83,7 +88,7 @@ module.exports = function getResolveScopedSlots (parent, state) {
const
test
=
t
.
callExpression
(
t
.
identifier
(
'
$hasScopedSlotsParams
'
),
[
vueId
])
orgin
.
replaceWith
(
t
.
arrayExpression
([
t
.
conditionalExpression
(
test
,
node
,
t
.
callExpression
(
t
.
identifier
(
METHOD_CREATE_EMPTY_VNODE
),
[]))]))
// scopedSlotsCompiler auto
parent
.
get
(
'
arguments.0.elements.0
'
)
.
node
.
scopedSlotsCompiler
=
'
augmented
'
objectPath
.
node
.
scopedSlotsCompiler
=
'
augmented
'
}
}
}
packages/uni-template-compiler/lib/template/traverse.js
浏览文件 @
89184583
...
...
@@ -341,9 +341,9 @@ function traverseRenderSlot (callExprNode, state) {
function
traverseResolveScopedSlots
(
callExprNode
,
state
)
{
const
options
=
state
.
options
const
vIfAttrName
=
options
.
platform
.
directive
+
'
if
'
function
single
(
node
,
slotName
,
ignore
)
{
function
single
(
node
,
slotName
,
vIfCode
,
ignore
)
{
let
last
=
node
const
vIfs
=
[]
const
vIfs
=
vIfCode
?
[
vIfCode
]
:
[]
function
find
(
children
)
{
if
(
Array
.
isArray
(
children
)
&&
children
.
length
===
1
)
{
const
child
=
children
[
0
]
...
...
@@ -373,6 +373,12 @@ function traverseResolveScopedSlots (callExprNode, state) {
let
keyProperty
=
false
let
fnProperty
=
false
let
proxyProperty
=
false
let
vIfCode
// TODO v-else
if
(
t
.
isConditionalExpression
(
slotNode
))
{
vIfCode
=
genCode
(
slotNode
.
test
)
slotNode
=
slotNode
.
consequent
}
slotNode
.
properties
.
forEach
(
property
=>
{
switch
(
property
.
key
.
name
)
{
case
'
key
'
:
...
...
@@ -422,7 +428,7 @@ function traverseResolveScopedSlots (callExprNode, state) {
return
single
({
type
:
'
block
'
,
children
:
normalizeChildren
(
traverseExpr
(
returnExprNodes
,
state
))
},
slotName
,
[
'
template
'
,
'
block
'
])
},
slotName
,
vIfCode
,
[
'
template
'
,
'
block
'
])
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录