Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit f9a86b9

Browse files
xiaoxiangmoeantfu
authored andcommitted
fix: v-on multiple line statement
1 parent 4bbc77e commit f9a86b9

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/core/parseSFC.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,22 @@ export function parseSFC(code: string, id?: string, options?: ScriptSetupTransfo
132132
}
133133

134134
if (value !== '' && (key.startsWith('v-') || key.startsWith('@') || key.startsWith(':'))) {
135-
if (key === 'v-for')
135+
if (key === 'v-for') {
136136
// we strip out delectations for v-for before `in` or `of`
137137
expressions.add(`(${value.replace(/^.*\s(?:in|of)\s/, '')})`)
138-
else
139-
expressions.add(`(${value})`)
138+
}
139+
else if (key.startsWith('@') || key.startsWith('v-on')) {
140+
if (value.trimStart()[0] === '{')
141+
expressions.add(`(${value})`)
142+
else
143+
expressions.add(`$event => {${value};}`)
144+
}
145+
else {
146+
if (value.trimStart()[0] === '{')
147+
expressions.add(`(${value})`)
148+
else
149+
expressions.add(`${value};`)
150+
}
140151
}
141152

142153
if (

test/__snapshots__/transform.test.ts.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export default __sfc_main;
481481
482482
exports[`transform fixtures test/fixtures/MacrosType3.vue 1`] = `
483483
"<template>
484-
<div @click=\\"emit('update', msg)\\">
484+
<div @click=\\"emit('update', msg);emit('update', msg + value);\\">
485485
{{ msg }}
486486
</div>
487487
</template>
@@ -509,8 +509,10 @@ __sfc_main.props = {
509509
510510
__sfc_main.setup = (__props, __ctx) => {
511511
const emit = __ctx.emit;
512+
const value = 'bar';
512513
return {
513-
emit
514+
emit,
515+
value
514516
};
515517
};
516518

test/fixtures/MacrosType3.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div @click="emit('update', msg)">
2+
<div @click="emit('update', msg);emit('update', msg + value);">
33
{{ msg }}
44
</div>
55
</template>
@@ -11,4 +11,5 @@ withDefaults(
1111
)
1212
1313
const emit = defineEmits(['update'])
14+
const value = 'bar'
1415
</script>

0 commit comments

Comments
 (0)