Skip to content

Commit 43eab92

Browse files
committed
fix(compiler-sfc): should not remove import statements with no specifier when compiling script setup
1 parent a76e58e commit 43eab92

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+3
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,13 @@ return { a, b }
181181
182182
exports[`SFC compile <script setup> imports should hoist and expose imports 1`] = `
183183
"import { ref } from 'vue'
184+
import 'foo/css'
185+
184186
export default {
185187
expose: [],
186188
setup(__props) {
187189
190+
188191
return { ref }
189192
}
190193

packages/compiler-sfc/__tests__/compileScript.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ const myEmit = defineEmit(['foo', 'bar'])
123123
describe('imports', () => {
124124
test('should hoist and expose imports', () => {
125125
assertCode(
126-
compile(`<script setup>import { ref } from 'vue'</script>`).content
126+
compile(`<script setup>
127+
import { ref } from 'vue'
128+
import 'foo/css'
129+
</script>`).content
127130
)
128131
})
129132

packages/compiler-sfc/src/compileScript.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ export function compileScript(
638638
)
639639
}
640640
}
641-
if (removed === node.specifiers.length) {
641+
if (node.specifiers.length && removed === node.specifiers.length) {
642642
s.remove(node.start! + startOffset, node.end! + startOffset)
643643
}
644644
}

0 commit comments

Comments
 (0)