Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
1ac12bed
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,体验更适合开发者的 AI 搜索 >>
提交
1ac12bed
编写于
11月 12, 2020
作者:
L
liuxiaohang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp-weixin): 修复for循环中,事件引用循环值报错
上级
158a9934
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
38 deletion
+56
-38
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
...es/uni-template-compiler/__tests__/compiler-extra.spec.js
+5
-0
packages/uni-template-compiler/lib/script/traverse/data/event.js
...s/uni-template-compiler/lib/script/traverse/data/event.js
+51
-38
未找到文件。
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
浏览文件 @
1ac12bed
...
...
@@ -699,6 +699,11 @@ describe('mp:compiler-extra', () => {
'
<view v-for="item in list" @click="test(item)">{{ item }}</view>
'
,
'
<block wx:for="{{list}}" wx:for-item="item" wx:for-index="__i0__"><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
test
\'
,[
\'
$0
\'
],[[[
\'
list
\'
,
\'\'
,__i0__]]]]]]]}}" bindtap="__e">{{item}}</view></block>
'
)
assertCodegen
(
'
<view v-for="(item, index) in [{x:[1,2,3,4]}]"><view v-for="item2 in item.x" @click="test(item2)">{{ item2 }}+{{index}}</view></view>
'
,
'
<block wx:for="{{[{x:[1,2,3,4]}]}}" wx:for-item="item" wx:for-index="index"><view><block wx:for="{{item.x}}" wx:for-item="item2" wx:for-index="__i0__"><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
e0
\'
,[
\'
$event
\'
]]]]]}}" data-event-params="{{({item2})}}" bindtap="__e">{{item2+"+"+index}}</view></block></view></block>
'
,
'
with(this){if(!_isMounted){e0=function($event,item2){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item2=_temp2.item2;var _temp,_temp2;return test(item2)}}}
'
)
})
it
(
'
generate bool attr
'
,
()
=>
{
assertCodegen
(
...
...
packages/uni-template-compiler/lib/script/traverse/data/event.js
浏览文件 @
1ac12bed
...
...
@@ -304,47 +304,60 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
}
}
anonymous
&&
funcPath
.
traverse
({
noScope
:
true
,
MemberExpression
(
path
)
{
if
(
path
.
node
.
object
.
name
===
'
$event
'
&&
path
.
node
.
property
.
name
===
'
stopPropagation
'
)
{
isCatch
=
true
path
.
stop
()
}
},
AssignmentExpression
(
path
)
{
// "update:title": function($event) {title = $event}
const
left
=
path
.
node
.
left
const
right
=
path
.
node
.
right
// v-bind:title.sync="title"
if
(
t
.
isIdentifier
(
left
)
&&
t
.
isIdentifier
(
right
)
&&
right
.
name
===
'
$event
'
&&
type
.
indexOf
(
'
update:
'
)
===
0
)
{
methods
.
push
(
t
.
arrayExpression
(
// ['$set',['title','$event']]
[
t
.
stringLiteral
(
INTERNAL_SET_SYNC
),
t
.
arrayExpression
([
t
.
identifier
(
left
.
name
),
t
.
stringLiteral
(
left
.
name
),
t
.
stringLiteral
(
'
$event
'
)
])
]
))
anonymous
=
false
path
.
stop
()
}
},
ReturnStatement
(
path
)
{
const
argument
=
path
.
node
.
argument
if
(
t
.
isCallExpression
(
argument
))
{
if
(
t
.
isIdentifier
(
argument
.
callee
))
{
// || t.isMemberExpression(argument.callee)
// 判断是否是复杂表达式 数组 或 对象
const
isNotDynamicExpression
=
(
state
)
=>
{
if
(
!
(
state
.
scoped
[
0
]))
{
return
true
}
const
value
=
state
.
scoped
[
0
].
forExtra
[
0
].
elements
[
0
].
value
return
!
(
typeof
value
===
'
string
'
&&
(
value
.
startsWith
(
'
[
'
)
||
value
.
startsWith
(
'
}
'
)))
}
// 如果v-for遍历的值为 数组、对象 则进入复杂表达式
if
(
isNotDynamicExpression
(
state
))
{
anonymous
&&
funcPath
.
traverse
({
noScope
:
true
,
MemberExpression
(
path
)
{
if
(
path
.
node
.
object
.
name
===
'
$event
'
&&
path
.
node
.
property
.
name
===
'
stopPropagation
'
)
{
isCatch
=
true
path
.
stop
()
}
},
AssignmentExpression
(
path
)
{
// "update:title": function($event) {title = $event}
const
left
=
path
.
node
.
left
const
right
=
path
.
node
.
right
// v-bind:title.sync="title"
if
(
t
.
isIdentifier
(
left
)
&&
t
.
isIdentifier
(
right
)
&&
right
.
name
===
'
$event
'
&&
type
.
indexOf
(
'
update:
'
)
===
0
)
{
methods
.
push
(
t
.
arrayExpression
(
// ['$set',['title','$event']]
[
t
.
stringLiteral
(
INTERNAL_SET_SYNC
),
t
.
arrayExpression
([
t
.
identifier
(
left
.
name
),
t
.
stringLiteral
(
left
.
name
),
t
.
stringLiteral
(
'
$event
'
)
])
]
))
anonymous
=
false
parseEventByCallExpression
(
argument
,
methods
)
path
.
stop
()
}
},
ReturnStatement
(
path
)
{
const
argument
=
path
.
node
.
argument
if
(
t
.
isCallExpression
(
argument
))
{
if
(
t
.
isIdentifier
(
argument
.
callee
))
{
// || t.isMemberExpression(argument.callee)
anonymous
=
false
parseEventByCallExpression
(
argument
,
methods
)
}
}
}
}
})
})
}
if
(
anonymous
)
{
// 处理复杂表达式中使用的局部变量(主要在v-for中定义)
funcPath
.
traverse
({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录