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
// 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`)
// if content doesn't end with newline, add one
if (!/\n$/.test(script.content.trim())) {
s.appendLeft(scriptEndOffset!, `\n`)
}
s.move(scriptStartOffset!, scriptEndOffset!, 0)
}
}