Skip to content

Commit 27f60d6

Browse files
authored
Merge pull request #1858 from didi/fix-setup-compiler-move-error
fix: 修复<script setup>标签后顶格写import语句时构建报错
2 parents 04829fa + 5e06a05 commit 27f60d6

File tree

1 file changed

+6
-2
lines changed
  • packages/webpack-plugin/lib/script-setup-compiler

1 file changed

+6
-2
lines changed

packages/webpack-plugin/lib/script-setup-compiler/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ function compileScriptSetup (
380380

381381
if (node.type === 'ImportDeclaration') {
382382
// import declarations are moved to top
383-
_s.move(start, end, 0)
383+
if (start !== 0) {
384+
_s.move(start, end, 0)
385+
}
384386
// dedupe imports
385387
let removed = 0
386388
const removeSpecifier = (i) => {
@@ -533,7 +535,9 @@ function compileScriptSetup (
533535
(node.type === 'VariableDeclaration' && node.declare)
534536
) {
535537
recordType(node, declaredTypes)
536-
_s.move(node.start, node.end + 1, 0)
538+
if (node.start !== 0) {
539+
_s.move(node.start, node.end + 1, 0)
540+
}
537541
}
538542
}
539543

0 commit comments

Comments
 (0)