Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reactivity-transform): semicolon after statements with nested destructure #7279

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -159,11 +159,13 @@ exports[`nested destructure 1`] = `
"import { toRef as _toRef } from 'vue'

let __$temp_1 = (useFoo()),
b = _toRef(__$temp_1[0].a, 'b');
b = _toRef(__$temp_1[0].a, 'b'),
n = _toRef(__$temp_1[0].z, 'n');
let __$temp_2 = (useBar()),
d = _toRef(__$temp_2.c, 0),
e = _toRef(__$temp_2.c, 1);
console.log(b.value, d.value, e.value)
e = _toRef(__$temp_2.c, 1),
h = _toRef(__$temp_2.f, 0);
console.log(b.value, d.value, e.value, h.value, n.value)
"
`;

Expand Down
Expand Up @@ -281,14 +281,16 @@ test('array destructure', () => {

test('nested destructure', () => {
const { code, rootRefs } = transform(`
let [{ a: { b }}] = $(useFoo())
let { c: [d, e] } = $(useBar())
console.log(b, d, e)
let [{ a: { b }, z: { n }}] = $(useFoo())
let { c: [d, e], f: [h] } = $(useBar())
console.log(b, d, e, h, n)
`)
expect(code).toMatch(`b = _toRef(__$temp_1[0].a, 'b')`)
expect(code).toMatch(`n = _toRef(__$temp_1[0].z, 'n')`)
expect(code).toMatch(`d = _toRef(__$temp_2.c, 0)`)
expect(code).toMatch(`e = _toRef(__$temp_2.c, 1)`)
expect(rootRefs).toStrictEqual(['b', 'd', 'e'])
expect(code).toMatch(`h = _toRef(__$temp_2.f, 0)`)
expect(rootRefs).toStrictEqual(['b', 'n', 'd', 'e', 'h'])
assertCode(code)
})

Expand Down
8 changes: 2 additions & 6 deletions packages/reactivity-transform/src/reactivityTransform.ts
Expand Up @@ -343,8 +343,10 @@ export function transformAST(
registerRefBinding(id, isConst)
} else if (id.type === 'ObjectPattern') {
processRefObjectPattern(id, call, isConst)
s.appendLeft(call.end! + offset, ';')
} else if (id.type === 'ArrayPattern') {
processRefArrayPattern(id, call, isConst)
s.appendLeft(call.end! + offset, ';')
}
} else {
// shorthands
Expand Down Expand Up @@ -451,9 +453,6 @@ export function transformAST(
)
}
}
if (nameId) {
s.appendLeft(call.end! + offset, ';')
}
}

function processRefArrayPattern(
Expand Down Expand Up @@ -502,9 +501,6 @@ export function transformAST(
)
}
}
if (nameId) {
s.appendLeft(call.end! + offset, ';')
}
}

type PathSegmentAtom = Expression | string | number
Expand Down