提交 6c8d5993 编写于 作者: Q qiang

fix: 修复H5事件为空时编译报错的问题

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