提交 8def9994 编写于 作者: Q qiang

fix(mp): event arguments with other MemberExpression (question/170728)

上级 55bb312b
...@@ -865,6 +865,11 @@ describe('mp:compiler-extra', () => { ...@@ -865,6 +865,11 @@ describe('mp:compiler-extra', () => {
'<button type="primary" data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" bindtap="__e">click me</button>', '<button type="primary" data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" bindtap="__e">click me</button>',
'with(this){if(!_isMounted){e0=()=>test(encodeURIComponent(JSON.stringify(arr)))}}' 'with(this){if(!_isMounted){e0=()=>test(encodeURIComponent(JSON.stringify(arr)))}}'
) )
assertCodegen(
'<button type="primary" @click="test(a().b)">click me</button>',
'<button type="primary" data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" bindtap="__e">click me</button>',
'with(this){if(!_isMounted){e0=function($event){test(a().b)}}}'
)
}) })
it('generate bool attr', () => { it('generate bool attr', () => {
assertCodegen( assertCodegen(
......
...@@ -322,7 +322,16 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false, ...@@ -322,7 +322,16 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
const funcParams = funcPath.node.params const funcParams = funcPath.node.params
if (body && body.length && funcParams && funcParams.length === 1 && !hasMemberExpression(funcPath)) { if (body && body.length && funcParams && funcParams.length === 1 && !hasMemberExpression(funcPath)) {
const exprStatements = body.filter(node => { const exprStatements = body.filter(node => {
return t.isExpressionStatement(node) && t.isCallExpression(node.expression) return t.isExpressionStatement(node) && t.isCallExpression(node.expression) && !node.expression.arguments.find(element => {
// click1(item().a)
if (t.isMemberExpression(element)) {
try {
getIdentifierName(element)
} catch {
return true
}
}
})
}) })
if (exprStatements.length === body.length) { if (exprStatements.length === body.length) {
const paramPath = funcPath.get('params')[0] const paramPath = funcPath.get('params')[0]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册