]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): fix import usage check for last expression
authorEvan You <yyx990803@gmail.com>
Mon, 9 Aug 2021 20:22:20 +0000 (16:22 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 9 Aug 2021 20:22:20 +0000 (16:22 -0400)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index 85aa31337e1e63181aa23d9d4266b3962131cf6b..6c76e5fe75b05abd98a6e42a7d0074ddd31cd59c 100644 (file)
@@ -206,7 +206,7 @@ return { x }
 
 exports[`SFC compile <script setup> imports imports not used in <template> should not be exposed 1`] = `
 "import { defineComponent as _defineComponent } from 'vue'
-import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y } from './x'
+import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y, Last } from './x'
         
 export default _defineComponent({
   setup(__props, { expose }) {
@@ -214,7 +214,7 @@ export default _defineComponent({
 
         const fooBar: FooBar = 1
         
-return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y }
+return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y, Last }
 }
 
 })"
index 0731d0f23fc23a924a1a44eef72edb0142eea21b..406462f399701eb1c6ce73c7e0d1d91f7eaef71a 100644 (file)
@@ -213,13 +213,14 @@ defineExpose({ foo: 123 })
     test('imports not used in <template> should not be exposed', () => {
       const { content } = compile(`
         <script setup lang="ts">
-        import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y } from './x'
+        import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y, Last } from './x'
         const fooBar: FooBar = 1
         </script>
         <template>
           <FooBaz v-my-dir>{{ x }} {{ yy }} {{ x$y }}</FooBaz>
           <foo-qux/>
           <div :id="z + 'y'">FooBar</div>
+          <Last/>
         </template>
         `)
       assertCode(content)
@@ -231,7 +232,7 @@ defineExpose({ foo: 123 })
       // y: should not be matched by {{ yy }} or 'y' in binding exps
       // x$y: #4274 should escape special chars when creating Regex
       expect(content).toMatch(
-        `return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y }`
+        `return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y, Last }`
       )
     })
   })
index 89a33f2ecc887131922ce554dbf043cdce14d582..9a558f25f869d2ddf766068d4911f45f8e168fa6 100644 (file)
@@ -2220,6 +2220,7 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
     ]
   })
 
+  code += ';'
   templateUsageCheckCache.set(content, code)
   return code
 }