提交 211d4749 编写于 作者: Q qiang

fix: 解决 H5 端事件为函数表达式时无法触发的问题

上级 faecbaf0
const {
tags
} = require('@dcloudio/uni-cli-shared')
const parser = require('@babel/parser')
const t = require('@babel/types')
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
function isFunction (expr) {
try {
const body = parser.parse(expr).program.body[0]
const expression = body.expression
return t.isFunctionDeclaration(body) || t.isArrowFunctionExpression(expression) || t.isFunctionExpression(expression)
} catch (error) { }
}
function processEvent (expr, filterModules) {
const isMethodPath = simplePathRE.test(expr)
if (isMethodPath) {
if (isMethodPath || isFunction(expr)) {
if (filterModules.find(name => expr.indexOf(name + '.') === 0)) {
return `
$event = $handleWxsEvent($event);
${expr}($event, $getComponentDescriptor())
(${expr})($event, $getComponentDescriptor())
`
} else {
expr = expr + '(...arguments)'
expr = `(${expr})(...arguments)`
}
}
return `
......@@ -97,4 +107,4 @@ module.exports = {
}
}
}]
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册