Skip to content

Commit 4b5ce8b

Browse files
committed
refactor(compiler-core): remove unnecessary arg in cached handler codegen
1 parent 829b35e commit 4b5ce8b

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function render(_ctx, _cache) {
209209
return (_openBlock(), _createBlock(\\"div\\", null, [
210210
_createVNode(\\"div\\", null, [
211211
_createVNode(\\"div\\", {
212-
onClick: _cache[1] || (_cache[1] = ($event, ...args) => (_ctx.foo($event, ...args)))
212+
onClick: _cache[1] || (_cache[1] = (...args) => (_ctx.foo(...args)))
213213
})
214214
])
215215
]))

packages/compiler-core/__tests__/transforms/vOn.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,7 @@ describe('compiler: transform v-on', () => {
400400
index: 1,
401401
value: {
402402
type: NodeTypes.COMPOUND_EXPRESSION,
403-
children: [
404-
`($event, ...args) => (`,
405-
{ content: `_ctx.foo($event, ...args)` },
406-
`)`
407-
]
403+
children: [`(...args) => (`, { content: `_ctx.foo(...args)` }, `)`]
408404
}
409405
})
410406
})

packages/compiler-core/src/transforms/vOn.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export const transformOn: DirectiveTransform = (
7070

7171
// process the expression since it's been skipped
7272
if (!__BROWSER__ && context.prefixIdentifiers) {
73-
context.addIdentifiers(`$event`)
73+
isInlineStatement && context.addIdentifiers(`$event`)
7474
exp = processExpression(exp, context, false, hasMultipleStatements)
75-
context.removeIdentifiers(`$event`)
75+
isInlineStatement && context.removeIdentifiers(`$event`)
7676
// with scope analysis, the function is hoistable if it has no reference
7777
// to scope variables.
7878
isCacheable =
@@ -83,9 +83,9 @@ export const transformOn: DirectiveTransform = (
8383
// avoiding the need to be patched.
8484
if (isCacheable && isMemberExp) {
8585
if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {
86-
exp.content += `($event, ...args)`
86+
exp.content += `(...args)`
8787
} else {
88-
exp.children.push(`($event, ...args)`)
88+
exp.children.push(`(...args)`)
8989
}
9090
}
9191
}
@@ -102,7 +102,7 @@ export const transformOn: DirectiveTransform = (
102102
if (isInlineStatement || (isCacheable && isMemberExp)) {
103103
// wrap inline statement in a function expression
104104
exp = createCompoundExpression([
105-
`${isInlineStatement ? `$event` : `($event, ...args)`} => ${
105+
`${isInlineStatement ? `$event` : `(...args)`} => ${
106106
hasMultipleStatements ? `{` : `(`
107107
}`,
108108
exp,

0 commit comments

Comments
 (0)