Skip to content

Commit a05b000

Browse files
committed
fix(reactivity-transform): apply transform for labelled variable declarations
ref #5298 (comment)
1 parent a81a992 commit a05b000

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

packages/reactivity-transform/__tests__/__snapshots__/reactivityTransform.spec.ts.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exports[`$ unwrapping 1`] = `
1010
}))
1111
let c = () => {}
1212
let d
13+
label: var e = (ref())
1314
"
1415
`;
1516

@@ -34,12 +35,13 @@ exports[`$ref & $shallowRef declarations 1`] = `
3435
"import { ref as _ref, shallowRef as _shallowRef } from 'vue'
3536
3637
let foo = _ref()
37-
let a = _ref(1)
38+
export let a = _ref(1)
3839
let b = _shallowRef({
3940
count: 0
4041
})
4142
let c = () => {}
4243
let d
44+
label: var e = _ref()
4345
"
4446
`;
4547

packages/reactivity-transform/__tests__/reactivityTransform.spec.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test('$ unwrapping', () => {
2525
}))
2626
let c = () => {}
2727
let d
28+
label: var e = $(ref())
2829
`)
2930
expect(code).not.toMatch(`$(ref())`)
3031
expect(code).not.toMatch(`$(ref(1))`)
@@ -39,19 +40,21 @@ test('$ unwrapping', () => {
3940
// normal declarations left untouched
4041
expect(code).toMatch(`let c = () => {}`)
4142
expect(code).toMatch(`let d`)
42-
expect(rootRefs).toStrictEqual(['foo', 'a', 'b'])
43+
expect(code).toMatch(`label: var e = (ref())`)
44+
expect(rootRefs).toStrictEqual(['foo', 'a', 'b', 'e'])
4345
assertCode(code)
4446
})
4547

4648
test('$ref & $shallowRef declarations', () => {
4749
const { code, rootRefs, importedHelpers } = transform(`
4850
let foo = $ref()
49-
let a = $ref(1)
51+
export let a = $ref(1)
5052
let b = $shallowRef({
5153
count: 0
5254
})
5355
let c = () => {}
5456
let d
57+
label: var e = $ref()
5558
`)
5659
expect(code).toMatch(
5760
`import { ref as _ref, shallowRef as _shallowRef } from 'vue'`
@@ -69,7 +72,8 @@ test('$ref & $shallowRef declarations', () => {
6972
// normal declarations left untouched
7073
expect(code).toMatch(`let c = () => {}`)
7174
expect(code).toMatch(`let d`)
72-
expect(rootRefs).toStrictEqual(['foo', 'a', 'b'])
75+
expect(code).toMatch(`label: var e = _ref()`)
76+
expect(rootRefs).toStrictEqual(['foo', 'a', 'b', 'e'])
7377
expect(importedHelpers).toStrictEqual(['ref', 'shallowRef'])
7478
assertCode(code)
7579
})

packages/reactivity-transform/src/reactivityTransform.ts

+5
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ export function transformAST(
235235
stmt.declaration.type === 'VariableDeclaration'
236236
) {
237237
walkVariableDeclaration(stmt.declaration, isRoot)
238+
} else if (
239+
stmt.type === 'LabeledStatement' &&
240+
stmt.body.type === 'VariableDeclaration'
241+
) {
242+
walkVariableDeclaration(stmt.body, isRoot)
238243
}
239244
}
240245
}

0 commit comments

Comments
 (0)