Skip to content

Commit a81a992

Browse files
committed
fix(reactivity-transform): apply transform on exported variable declarations
fix #5298
1 parent ae4b078 commit a81a992

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`$ unwrapping 1`] = `
44
"
55
import { ref, shallowRef } from 'vue'
66
let foo = (ref())
7-
let a = (ref(1))
7+
export let a = (ref(1))
88
let b = (shallowRef({
99
count: 0
1010
}))

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('$ unwrapping', () => {
1919
const { code, rootRefs } = transform(`
2020
import { ref, shallowRef } from 'vue'
2121
let foo = $(ref())
22-
let a = $(ref(1))
22+
export let a = $(ref(1))
2323
let b = $(shallowRef({
2424
count: 0
2525
}))
@@ -30,7 +30,7 @@ test('$ unwrapping', () => {
3030
expect(code).not.toMatch(`$(ref(1))`)
3131
expect(code).not.toMatch(`$(shallowRef({`)
3232
expect(code).toMatch(`let foo = (ref())`)
33-
expect(code).toMatch(`let a = (ref(1))`)
33+
expect(code).toMatch(`export let a = (ref(1))`)
3434
expect(code).toMatch(`
3535
let b = (shallowRef({
3636
count: 0

packages/reactivity-transform/src/reactivityTransform.ts

+7
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ export function transformAST(
229229
stmt.left.type === 'VariableDeclaration'
230230
) {
231231
walkVariableDeclaration(stmt.left)
232+
} else if (
233+
stmt.type === 'ExportNamedDeclaration' &&
234+
stmt.declaration &&
235+
stmt.declaration.type === 'VariableDeclaration'
236+
) {
237+
walkVariableDeclaration(stmt.declaration, isRoot)
232238
}
233239
}
234240
}
@@ -562,6 +568,7 @@ export function transformAST(
562568
return
563569
}
564570

571+
// skip type nodes
565572
if (
566573
parent &&
567574
parent.type.startsWith('TS') &&

0 commit comments

Comments
 (0)