refactor(compiler-core): remove unnecessary arg in cached handler codegen

This commit is contained in:
Evan You 2020-07-08 11:36:31 -04:00
parent 829b35e426
commit 4b5ce8b456
3 changed files with 7 additions and 11 deletions

View File

@ -209,7 +209,7 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createBlock(\\"div\\", null, [ return (_openBlock(), _createBlock(\\"div\\", null, [
_createVNode(\\"div\\", null, [ _createVNode(\\"div\\", null, [
_createVNode(\\"div\\", { _createVNode(\\"div\\", {
onClick: _cache[1] || (_cache[1] = ($event, ...args) => (_ctx.foo($event, ...args))) onClick: _cache[1] || (_cache[1] = (...args) => (_ctx.foo(...args)))
}) })
]) ])
])) ]))

View File

@ -400,11 +400,7 @@ describe('compiler: transform v-on', () => {
index: 1, index: 1,
value: { value: {
type: NodeTypes.COMPOUND_EXPRESSION, type: NodeTypes.COMPOUND_EXPRESSION,
children: [ children: [`(...args) => (`, { content: `_ctx.foo(...args)` }, `)`]
`($event, ...args) => (`,
{ content: `_ctx.foo($event, ...args)` },
`)`
]
} }
}) })
}) })

View File

@ -70,9 +70,9 @@ export const transformOn: DirectiveTransform = (
// process the expression since it's been skipped // process the expression since it's been skipped
if (!__BROWSER__ && context.prefixIdentifiers) { if (!__BROWSER__ && context.prefixIdentifiers) {
context.addIdentifiers(`$event`) isInlineStatement && context.addIdentifiers(`$event`)
exp = processExpression(exp, context, false, hasMultipleStatements) exp = processExpression(exp, context, false, hasMultipleStatements)
context.removeIdentifiers(`$event`) isInlineStatement && context.removeIdentifiers(`$event`)
// with scope analysis, the function is hoistable if it has no reference // with scope analysis, the function is hoistable if it has no reference
// to scope variables. // to scope variables.
isCacheable = isCacheable =
@ -83,9 +83,9 @@ export const transformOn: DirectiveTransform = (
// avoiding the need to be patched. // avoiding the need to be patched.
if (isCacheable && isMemberExp) { if (isCacheable && isMemberExp) {
if (exp.type === NodeTypes.SIMPLE_EXPRESSION) { if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {
exp.content += `($event, ...args)` exp.content += `(...args)`
} else { } else {
exp.children.push(`($event, ...args)`) exp.children.push(`(...args)`)
} }
} }
} }
@ -102,7 +102,7 @@ export const transformOn: DirectiveTransform = (
if (isInlineStatement || (isCacheable && isMemberExp)) { if (isInlineStatement || (isCacheable && isMemberExp)) {
// wrap inline statement in a function expression // wrap inline statement in a function expression
exp = createCompoundExpression([ exp = createCompoundExpression([
`${isInlineStatement ? `$event` : `($event, ...args)`} => ${ `${isInlineStatement ? `$event` : `(...args)`} => ${
hasMultipleStatements ? `{` : `(` hasMultipleStatements ? `{` : `(`
}`, }`,
exp, exp,