Skip to content

Commit

Permalink
fix(compiler-core): fix vOn compiled code (vuejs#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jan 3, 2020
1 parent 7770d6d commit ee2cc15
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function render() {
return (openBlock(), createBlock(\\"div\\", null, [
createVNode(\\"div\\", null, [
createVNode(\\"div\\", {
onClick: _cache[1] || (_cache[1] = $event => (_ctx.foo($event)))
onClick: _cache[1] || (_cache[1] = $event => {_ctx.foo($event)})
})
])
]))
Expand Down
10 changes: 5 additions & 5 deletions packages/compiler-core/__tests__/transforms/vOn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('compiler: transform v-on', () => {
key: { content: `onClick` },
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`$event => (`, { content: `i++` }, `)`]
children: [`$event => {`, { content: `i++` }, `}`]
}
})
})
Expand All @@ -151,13 +151,13 @@ describe('compiler: transform v-on', () => {
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`$event => (`,
`$event => {`,
{ content: `_ctx.foo` },
`(`,
// should NOT prefix $event
{ content: `$event` },
`)`,
`)`
`}`
]
}
})
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('compiler: transform v-on', () => {
index: 1,
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`$event => (`, { content: `_ctx.foo($event)` }, `)`]
children: [`$event => {`, { content: `_ctx.foo($event)` }, `}`]
}
})
})
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('compiler: transform v-on', () => {
index: 1,
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`$event => (`, { content: `_ctx.foo` }, `++`, `)`]
children: [`$event => {`, { content: `_ctx.foo` }, `++`, `}`]
}
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/vOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export const transformOn: DirectiveTransform = (
if (isInlineStatement || (isCacheable && isMemberExp)) {
// wrap inline statement in a function expression
exp = createCompoundExpression([
`$event => (`,
`$event => {`,
...(exp.type === NodeTypes.SIMPLE_EXPRESSION ? [exp] : exp.children),
`)`
`}`
])
}
}
Expand Down

0 comments on commit ee2cc15

Please sign in to comment.