chore: fix snapshot + simplify fix

This commit is contained in:
Evan You 2022-05-13 11:04:04 +08:00
parent 3b7b107120
commit de7a879cda
2 changed files with 142 additions and 143 deletions

View File

@ -942,12 +942,11 @@ export function compileScript(
// we need to move the block up so that `const __default__` is // we need to move the block up so that `const __default__` is
// declared before being used in the actual component definition // declared before being used in the actual component definition
if (scriptStartOffset! > startOffset) { if (scriptStartOffset! > startOffset) {
s.move(scriptStartOffset!, scriptEndOffset!, 0) // if content doesn't end with newline, add one
const content = s.slice(scriptStartOffset!, scriptEndOffset!) if (!/\n$/.test(script.content.trim())) {
// when the script content not end with `\n` we add `\n` for the script content s.appendLeft(scriptEndOffset!, `\n`)
if(!/(\n *$)/.test(content)) {
s.overwrite(scriptStartOffset!,scriptEndOffset!,`${content}\n`)
} }
s.move(scriptStartOffset!, scriptEndOffset!, 0)
} }
} }