Skip to content

Commit

Permalink
fix(reactivity-transform): semicolon after statements with nested des…
Browse files Browse the repository at this point in the history
…tructure
  • Loading branch information
skywalker512 committed Dec 6, 2022
1 parent fe77e2b commit 2226394
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
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

0 comments on commit 2226394

Please sign in to comment.