Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
a7d83593
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
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,发现更多精彩内容 >>
提交
a7d83593
编写于
7月 16, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 支付宝小程序支持作用域插槽 fixed #1253
上级
79f0f467
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
6 deletion
+64
-6
packages/uni-mp-alipay/lib/uni.compiler.js
packages/uni-mp-alipay/lib/uni.compiler.js
+51
-5
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
...ni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+13
-1
未找到文件。
packages/uni-mp-alipay/lib/uni.compiler.js
浏览文件 @
a7d83593
const
t
=
require
(
'
@babel/types
'
)
const
traverse
=
require
(
'
@babel/traverse
'
).
default
function
cached
(
fn
)
{
const
cache
=
Object
.
create
(
null
)
return
function
cachedFn
(
str
)
{
...
...
@@ -82,12 +85,55 @@ module.exports = {
type
:
'
view
'
,
attr
:
{
slot
:
slotName
},
children
:
normalizeChildren
(
traverseExpr
(
returnExprNodes
,
state
))
}
}
if
(
paramExprNode
&&
paramExprNode
.
type
===
'
Identifier
'
)
{
node
.
scoped
=
paramExprNode
.
name
if
(
paramExprNode
)
{
if
(
t
.
isIdentifier
(
paramExprNode
))
{
const
scoped
=
paramExprNode
.
name
node
.
attr
[
'
slot-scope
'
]
=
scoped
}
else
if
(
t
.
isObjectPattern
(
paramExprNode
))
{
const
paramName
=
'
__SCOPED__
'
node
.
attr
[
'
slot-scope
'
]
=
paramName
const
start
=
returnExprNodes
.
start
const
end
=
returnExprNodes
.
end
const
names
=
[]
paramExprNode
.
properties
.
forEach
(
property
=>
{
const
key
=
property
.
key
const
value
=
property
.
value
if
(
t
.
isIdentifier
(
value
))
{
if
(
value
.
name
!==
key
.
name
)
{
state
.
errors
.
add
(
`解构插槽 Prop 时,不支持将
${
key
.
name
}
重命名为
${
value
.
name
}
,重命名后会影响性能`
)
return
}
}
else
if
(
t
.
isAssignmentPattern
(
value
))
{
state
.
errors
.
add
(
`解构插槽 Prop 时,不支持为
${
key
.
name
}
设置默认值`
)
return
}
names
.
push
(
key
.
name
)
})
traverse
({
type
:
'
Program
'
,
start
,
end
,
body
:
[{
type
:
'
ExpressionStatement
'
,
start
,
end
,
expression
:
returnExprNodes
}],
sourceType
:
'
module
'
},
{
Identifier
(
path
)
{
const
node
=
path
.
node
const
name
=
node
.
name
if
(
names
.
includes
(
name
)
&&
path
.
key
!==
'
key
'
&&
path
.
key
!==
'
property
'
&&
!
(
path
.
scope
&&
path
.
scope
.
hasBinding
(
name
)))
{
path
.
replaceWithSourceString
(
`
${
paramName
}
.
${
name
}
`
)
}
}
})
}
}
node
.
children
=
normalizeChildren
(
traverseExpr
(
returnExprNodes
,
state
))
return
node
}
}
}
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
浏览文件 @
a7d83593
...
...
@@ -60,6 +60,18 @@ describe('mp:compiler-mp-alipay', () => {
'
<component1 vue-id="551070e6-1" onVueInit="__l">text<view slot="right"></view></component1>
'
)
})
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"><view slot="default" slot-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></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"><view slot="default" slot-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></view></component1>
'
)
})
it
(
'
generate class binding
'
,
()
=>
{
assertCodegen
(
'
<div :class="{ active: isActive }">1</div>
'
,
...
...
@@ -148,4 +160,4 @@ describe('mp:compiler-mp-alipay', () => {
'
<movable-view data-event-opts="{{[[
\'
changeEnd
\'
,[[
\'
changeEnd
\'
,[
\'
$event
\'
]]]]]}}" onChangeEnd="__e"></movable-view>
'
)
})
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录