fix(reactivity-transform): add semicolon after statements (#6303)

This commit is contained in:
三咲智子 Kevin Deng 2022-11-08 09:38:47 +08:00 committed by GitHub
parent f67bb500b6
commit c4f213b425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 14 deletions

View File

@ -6,8 +6,8 @@ exports[`sfc props transform $$() escape 1`] = `
export default { export default {
props: ['foo'], props: ['foo'],
setup(__props) { setup(__props) {
const __props_bar = _toRef(__props, 'bar') const __props_bar = _toRef(__props, 'bar');
const __props_foo = _toRef(__props, 'foo') const __props_foo = _toRef(__props, 'foo');
console.log((__props_foo)) console.log((__props_foo))
@ -160,7 +160,7 @@ export default {
props: ['foo', 'bar', 'baz'], props: ['foo', 'bar', 'baz'],
setup(__props) { setup(__props) {
const rest = _createPropsRestProxy(__props, [\\"foo\\",\\"bar\\"]) const rest = _createPropsRestProxy(__props, [\\"foo\\",\\"bar\\"]);

View File

@ -1419,7 +1419,7 @@ export function compileScript(
startOffset, startOffset,
`\nconst ${propsDestructureRestId} = ${helper( `\nconst ${propsDestructureRestId} = ${helper(
`createPropsRestProxy` `createPropsRestProxy`
)}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))})\n` )}(__props, ${JSON.stringify(Object.keys(propsDestructuredBindings))});\n`
) )
} }
// inject temp variables for async context preservation // inject temp variables for async context preservation

View File

@ -61,7 +61,7 @@ exports[`array destructure 1`] = `
let n = _ref(1), __$temp_1 = (useFoo()), let n = _ref(1), __$temp_1 = (useFoo()),
a = _toRef(__$temp_1, 0), a = _toRef(__$temp_1, 0),
b = _toRef(__$temp_1, 1, 1) b = _toRef(__$temp_1, 1, 1);
console.log(n.value, a.value, b.value) console.log(n.value, a.value, b.value)
" "
`; `;
@ -90,7 +90,7 @@ exports[`macro import alias and removal 1`] = `
let a = _ref(1) let a = _ref(1)
const __$temp_1 = (useMouse()), const __$temp_1 = (useMouse()),
x = _toRef(__$temp_1, 'x'), x = _toRef(__$temp_1, 'x'),
y = _toRef(__$temp_1, 'y') y = _toRef(__$temp_1, 'y');
" "
`; `;
@ -130,10 +130,10 @@ exports[`nested destructure 1`] = `
"import { toRef as _toRef } from 'vue' "import { toRef as _toRef } from 'vue'
let __$temp_1 = (useFoo()), let __$temp_1 = (useFoo()),
b = _toRef(__$temp_1[0].a, 'b') b = _toRef(__$temp_1[0].a, 'b');
let __$temp_2 = (useBar()), let __$temp_2 = (useBar()),
d = _toRef(__$temp_2.c, 0), d = _toRef(__$temp_2.c, 0),
e = _toRef(__$temp_2.c, 1) e = _toRef(__$temp_2.c, 1);
console.log(b.value, d.value, e.value) console.log(b.value, d.value, e.value)
" "
`; `;
@ -183,9 +183,9 @@ exports[`object destructure 1`] = `
c = _toRef(__$temp_1, 'b'), c = _toRef(__$temp_1, 'b'),
d = _toRef(__$temp_1, 'd', 1), d = _toRef(__$temp_1, 'd', 1),
f = _toRef(__$temp_1, 'e', 2), f = _toRef(__$temp_1, 'e', 2),
h = _toRef(__$temp_1, g) h = _toRef(__$temp_1, g);
let __$temp_2 = (useSomething(() => 1)), let __$temp_2 = (useSomething(() => 1)),
foo = _toRef(__$temp_2, 'foo'); foo = _toRef(__$temp_2, 'foo');;
console.log(n.value, a.value, c.value, d.value, f.value, h.value, foo.value) console.log(n.value, a.value, c.value, d.value, f.value, h.value, foo.value)
" "
`; `;
@ -194,7 +194,7 @@ exports[`object destructure w/ mid-path default values 1`] = `
"import { toRef as _toRef } from 'vue' "import { toRef as _toRef } from 'vue'
const __$temp_1 = (useFoo()), const __$temp_1 = (useFoo()),
b = _toRef((__$temp_1.a || { b: 123 }), 'b') b = _toRef((__$temp_1.a || { b: 123 }), 'b');
console.log(b.value) console.log(b.value)
" "
`; `;

View File

@ -321,8 +321,8 @@ export function transformAST(
s.overwrite(pattern.start! + offset, pattern.end! + offset, tempVar) s.overwrite(pattern.start! + offset, pattern.end! + offset, tempVar)
} }
for (const p of pattern.properties) {
let nameId: Identifier | undefined let nameId: Identifier | undefined
for (const p of pattern.properties) {
let key: Expression | string | undefined let key: Expression | string | undefined
let defaultValue: Expression | undefined let defaultValue: Expression | undefined
if (p.type === 'ObjectProperty') { if (p.type === 'ObjectProperty') {
@ -391,6 +391,9 @@ export function transformAST(
) )
} }
} }
if (nameId) {
s.appendLeft(call.end! + offset, ';')
}
} }
function processRefArrayPattern( function processRefArrayPattern(
@ -405,10 +408,10 @@ export function transformAST(
s.overwrite(pattern.start! + offset, pattern.end! + offset, tempVar) s.overwrite(pattern.start! + offset, pattern.end! + offset, tempVar)
} }
let nameId: Identifier | undefined
for (let i = 0; i < pattern.elements.length; i++) { for (let i = 0; i < pattern.elements.length; i++) {
const e = pattern.elements[i] const e = pattern.elements[i]
if (!e) continue if (!e) continue
let nameId: Identifier | undefined
let defaultValue: Expression | undefined let defaultValue: Expression | undefined
if (e.type === 'Identifier') { if (e.type === 'Identifier') {
// [a] --> [__a] // [a] --> [__a]
@ -438,6 +441,9 @@ export function transformAST(
) )
} }
} }
if (nameId) {
s.appendLeft(call.end! + offset, ';')
}
} }
type PathSegmentAtom = Expression | string | number type PathSegmentAtom = Expression | string | number
@ -545,7 +551,7 @@ export function transformAST(
offset, offset,
`const __props_${publicKey} = ${helper( `const __props_${publicKey} = ${helper(
`toRef` `toRef`
)}(__props, '${publicKey}')\n` )}(__props, '${publicKey}');\n`
) )
} }
} }