Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
c5b25d9f
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c5b25d9f
编写于
2月 18, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): 修复事件中包含stop修饰符时复杂表达式编译错误的问题
上级
2c86c8a3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
8 deletion
+19
-8
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
...es/uni-template-compiler/__tests__/compiler-extra.spec.js
+9
-0
packages/uni-template-compiler/lib/script/traverse/data/event.js
...s/uni-template-compiler/lib/script/traverse/data/event.js
+10
-8
未找到文件。
packages/uni-template-compiler/__tests__/compiler-extra.spec.js
浏览文件 @
c5b25d9f
...
@@ -736,6 +736,10 @@ describe('mp:compiler-extra', () => {
...
@@ -736,6 +736,10 @@ describe('mp:compiler-extra', () => {
'
<view v-for="item in list" @click="test(item)">{{ item }}</view>
'
,
'
<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>
'
'
<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 in list" @click.stop="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__]]]]]]]}}" catchtap="__e">{{item}}</view></block>
'
)
assertCodegen
(
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>
'
,
'
<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>
'
,
'
<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>
'
,
...
@@ -751,6 +755,11 @@ describe('mp:compiler-extra', () => {
...
@@ -751,6 +755,11 @@ describe('mp:compiler-extra', () => {
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
e0
\'
,[
\'
$event
\'
]]]]]}}" data-event-params="{{({item})}}" bindtap="__e"></view></view></block>
'
,
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
e0
\'
,[
\'
$event
\'
]]]]]}}" data-event-params="{{({item})}}" bindtap="__e"></view></view></block>
'
,
'
with(this){var l0=array();if(!_isMounted){e0=function($event,item){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item=_temp2.item;var _temp,_temp2;return test(item)}}$mp.data=Object.assign({},{$root:{l0:l0}})}
'
'
with(this){var l0=array();if(!_isMounted){e0=function($event,item){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item=_temp2.item;var _temp,_temp2;return test(item)}}$mp.data=Object.assign({},{$root:{l0:l0}})}
'
)
)
assertCodegen
(
'
<view v-for="(item, index) in array()"><view @click.stop="test(item)"></view></view>
'
,
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
e0
\'
,[
\'
$event
\'
]]]]]}}" data-event-params="{{({item})}}" catchtap="__e"></view></view></block>
'
,
'
with(this){var l0=array();if(!_isMounted){e0=function($event,item){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item=_temp2.item;var _temp,_temp2;$event.stopPropagation();return test(item)}}$mp.data=Object.assign({},{$root:{l0:l0}})}
'
)
assertCodegen
(
assertCodegen
(
'
<view v-for="(item, index) in array()"><view @click="test(item)">{{item}}</view></view>
'
,
'
<view v-for="(item, index) in array()"><view @click="test(item)">{{item}}</view></view>
'
,
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
e0
\'
,[
\'
$event
\'
]]]]]}}" data-event-params="{{({item})}}" bindtap="__e">{{item}}</view></view></block>
'
,
'
<block wx:for="{{$root.l0}}" wx:for-item="item" wx:for-index="index"><view><view data-event-opts="{{[[
\'
tap
\'
,[[
\'
e0
\'
,[
\'
$event
\'
]]]]]}}" data-event-params="{{({item})}}" bindtap="__e">{{item}}</view></view></block>
'
,
...
...
packages/uni-template-compiler/lib/script/traverse/data/event.js
浏览文件 @
c5b25d9f
...
@@ -320,19 +320,21 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
...
@@ -320,19 +320,21 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
}
}
}
}
const
testCatch
=
function
(
path
)
{
const
testCatch
=
function
(
stop
)
{
// TODO 仅使用 name 容易误判
return
function
(
path
)
{
if
(
path
.
node
.
object
.
name
===
'
$event
'
&&
path
.
node
.
property
.
name
===
// TODO 仅使用 name 容易误判
'
stopPropagation
'
)
{
if
(
path
.
node
.
object
.
name
===
'
$event
'
&&
path
.
node
.
property
.
name
===
isCatch
=
true
'
stopPropagation
'
)
{
path
.
stop
()
isCatch
=
true
stop
&&
path
.
stop
()
}
}
}
}
}
// 如果 v-for 遍历的值为 数组、对象、方法 则进入底部匿名表达式处理
// 如果 v-for 遍历的值为 数组、对象、方法 则进入底部匿名表达式处理
if
(
anonymous
&&
isSafeScoped
(
state
))
{
if
(
anonymous
&&
isSafeScoped
(
state
))
{
funcPath
.
traverse
({
funcPath
.
traverse
({
noScope
:
true
,
noScope
:
true
,
MemberExpression
:
testCatch
,
MemberExpression
:
testCatch
()
,
AssignmentExpression
(
path
)
{
// "update:title": function($event) {title = $event}
AssignmentExpression
(
path
)
{
// "update:title": function($event) {title = $event}
const
left
=
path
.
node
.
left
const
left
=
path
.
node
.
left
const
right
=
path
.
node
.
right
const
right
=
path
.
node
.
right
...
@@ -370,7 +372,7 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
...
@@ -370,7 +372,7 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
if
(
anonymous
)
{
if
(
anonymous
)
{
// 处理复杂表达式中使用的局部变量(主要在v-for中定义)
// 处理复杂表达式中使用的局部变量(主要在v-for中定义)
funcPath
.
traverse
({
funcPath
.
traverse
({
MemberExpression
:
testCatch
,
MemberExpression
:
testCatch
()
,
Identifier
(
path
)
{
Identifier
(
path
)
{
const
scope
=
path
.
scope
const
scope
=
path
.
scope
const
node
=
path
.
node
const
node
=
path
.
node
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录