fix(compiler-sfc): <script> after <script setup> the script content not end with \\n

This commit is contained in:
liulinboyi
2022-04-24 20:39:18 +08:00
committed by Evan You
parent 242914d938
commit 3b7b107120
3 changed files with 166 additions and 136 deletions

View File

@@ -943,6 +943,11 @@ export function compileScript(
// declared before being used in the actual component definition
if (scriptStartOffset! > startOffset) {
s.move(scriptStartOffset!, scriptEndOffset!, 0)
const content = s.slice(scriptStartOffset!, scriptEndOffset!)
// when the script content not end with `\n` we add `\n` for the script content
if(!/(\n *$)/.test(content)) {
s.overwrite(scriptStartOffset!,scriptEndOffset!,`${content}\n`)
}
}
}