]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): should not remove import statements with no specifier when compili...
authorEvan You <yyx990803@gmail.com>
Sat, 28 Nov 2020 18:51:32 +0000 (13:51 -0500)
committerEvan You <yyx990803@gmail.com>
Sat, 28 Nov 2020 18:51:32 +0000 (13:51 -0500)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index 662693d243d86109d25b42791cf2b88ce553a5f3..a68625d607c7e1f251d4da9fc7d38a887cb9b991 100644 (file)
@@ -181,10 +181,13 @@ return { a, b }
 
 exports[`SFC compile <script setup> imports should hoist and expose imports 1`] = `
 "import { ref } from 'vue'
+          import 'foo/css'
+        
 export default {
   expose: [],
   setup(__props) {
 
+          
 return { ref }
 }
 
index 66b46b7dcfd556e4bb6e589b72f7f6c22eb21b9d..b15f5b9719b7e31b647128fdba5603bbd890c632 100644 (file)
@@ -123,7 +123,10 @@ const myEmit = defineEmit(['foo', 'bar'])
   describe('imports', () => {
     test('should hoist and expose imports', () => {
       assertCode(
-        compile(`<script setup>import { ref } from 'vue'</script>`).content
+        compile(`<script setup>
+          import { ref } from 'vue'
+          import 'foo/css'
+        </script>`).content
       )
     })
 
index 921f5c177d2f9a33b48b91b34db38d6ba7a1e5d0..7dca8606e2a639649f166a0f2f23ca848176778d 100644 (file)
@@ -638,7 +638,7 @@ export function compileScript(
           )
         }
       }
-      if (removed === node.specifiers.length) {
+      if (node.specifiers.length && removed === node.specifiers.length) {
         s.remove(node.start! + startOffset, node.end! + startOffset)
       }
     }