]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity-transform): apply transform on exported variable declarations
authorEvan You <yyx990803@gmail.com>
Thu, 20 Jan 2022 23:40:35 +0000 (07:40 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 20 Jan 2022 23:40:35 +0000 (07:40 +0800)
fix #5298

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

index b120724ff6a18b2db8b519cdb706f97aad95cc18..793ee307632fc14746ecd2d085f5a3f2835f6dca 100644 (file)
@@ -4,7 +4,7 @@ exports[`$ unwrapping 1`] = `
 "
     import { ref, shallowRef } from 'vue'
     let foo = (ref())
-    let a = (ref(1))
+    export let a = (ref(1))
     let b = (shallowRef({
       count: 0
     }))
index c3c90aae57ef6daeda907467e5e85d5a87faa61c..916bd5a7d595d6e8d226021abadbd853b58d193b 100644 (file)
@@ -19,7 +19,7 @@ test('$ unwrapping', () => {
   const { code, rootRefs } = transform(`
     import { ref, shallowRef } from 'vue'
     let foo = $(ref())
-    let a = $(ref(1))
+    export let a = $(ref(1))
     let b = $(shallowRef({
       count: 0
     }))
@@ -30,7 +30,7 @@ test('$ unwrapping', () => {
   expect(code).not.toMatch(`$(ref(1))`)
   expect(code).not.toMatch(`$(shallowRef({`)
   expect(code).toMatch(`let foo = (ref())`)
-  expect(code).toMatch(`let a = (ref(1))`)
+  expect(code).toMatch(`export let a = (ref(1))`)
   expect(code).toMatch(`
     let b = (shallowRef({
       count: 0
index 706b09ec5ad77e24a3da0dbae4b675f3d507baaa..be6ceb75693fa9d65d846d07d677403b6a3c9683 100644 (file)
@@ -229,6 +229,12 @@ export function transformAST(
         stmt.left.type === 'VariableDeclaration'
       ) {
         walkVariableDeclaration(stmt.left)
+      } else if (
+        stmt.type === 'ExportNamedDeclaration' &&
+        stmt.declaration &&
+        stmt.declaration.type === 'VariableDeclaration'
+      ) {
+        walkVariableDeclaration(stmt.declaration, isRoot)
       }
     }
   }
@@ -562,6 +568,7 @@ export function transformAST(
         return
       }
 
+      // skip type nodes
       if (
         parent &&
         parent.type.startsWith('TS') &&