From 51fa9edea38d65e306beacc0ef8e54185c18abed Mon Sep 17 00:00:00 2001 From: Gcaufy Date: Wed, 7 Nov 2018 21:14:52 +0800 Subject: [PATCH] fix(cli&core): fixed not to use Function.name in mini application fix #1903 --- packages/cli/core/plugins/template/directives/v-on.js | 11 +++++------ packages/core/weapp/init/methods.js | 6 +----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/cli/core/plugins/template/directives/v-on.js b/packages/cli/core/plugins/template/directives/v-on.js index 65c7af8c6..1bf399ec0 100644 --- a/packages/cli/core/plugins/template/directives/v-on.js +++ b/packages/cli/core/plugins/template/directives/v-on.js @@ -10,12 +10,11 @@ const parseHandlerProxy = (expr, scope) => { let injectParams = []; let handlerExpr = expr; - let functionName = 'proxyHandler'; + let eventInArg = false; if (/^\w+$/.test(expr)) { // @tap="doSomething" - injectParams.push('$event'); handlerExpr += '($event)'; - functionName = 'proxyHandlerWithEvent'; + eventInArg = true; } else { let identifiers; try { @@ -37,13 +36,13 @@ const parseHandlerProxy = (expr, scope) => { } if (identifiers.$event) { - injectParams.push('$event'); - functionName = 'proxyHandlerWithEvent'; + eventInArg = true; } } - let proxy = `function ${functionName} (${injectParams.join(', ')}) { + let proxy = `function proxy (${injectParams.join(', ')}) { + ${eventInArg ? 'let $event = arguments[arguments.length - 1];' : ''} with (this) { return (function () { ${handlerExpr} diff --git a/packages/core/weapp/init/methods.js b/packages/core/weapp/init/methods.js index ddee77756..aca62bbd0 100644 --- a/packages/core/weapp/init/methods.js +++ b/packages/core/weapp/init/methods.js @@ -75,11 +75,7 @@ const proxyHandler = function (e) { let $event = new Event(e); if (isFunc(fn)) { - if (fn.name === 'proxyHandlerWithEvent') { - return fn.apply(vm, params.concat($event)); - } else { - return fn.apply(vm, params); - } + return fn.apply(vm, params.concat($event)); } else if (!model) { throw new Error('Unrecognized event'); }