Skip to content

Commit

Permalink
fix(cli&core): fixed not to use Function.name in mini application
Browse files Browse the repository at this point in the history
fix #1903
  • Loading branch information
Gcaufy committed Nov 7, 2018
1 parent cc498ba commit 51fa9ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
11 changes: 5 additions & 6 deletions packages/cli/core/plugins/template/directives/v-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}
Expand Down
6 changes: 1 addition & 5 deletions packages/core/weapp/init/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit 51fa9ed

Please sign in to comment.