Skip to content

Commit

Permalink
fix(compiler-sfc): should not remove import statements with no specif…
Browse files Browse the repository at this point in the history
…ier when compiling script setup
  • Loading branch information
yyx990803 committed Nov 28, 2020
1 parent a76e58e commit 43eab92
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
5 changes: 4 additions & 1 deletion packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 43eab92

Please sign in to comment.