fix(compiler-sfc): <script> after <script setup> the script content not end with \\n
This commit is contained in:
parent
242914d938
commit
3b7b107120
@ -43,6 +43,21 @@ return { a }
|
|||||||
})"
|
})"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`SFC compile <script setup> <script> after <script setup> the script content not end with \`\\n\` 1`] = `
|
||||||
|
"const n = 1
|
||||||
|
import { x } from './x'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
setup(__props, { expose }) {
|
||||||
|
expose();
|
||||||
|
|
||||||
|
|
||||||
|
return { n, x }
|
||||||
|
}
|
||||||
|
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`SFC compile <script setup> <script> and <script setup> co-usage script first 1`] = `
|
exports[`SFC compile <script setup> <script> and <script setup> co-usage script first 1`] = `
|
||||||
"import { x } from './x'
|
"import { x } from './x'
|
||||||
|
|
||||||
|
@ -168,6 +168,16 @@ defineExpose({ foo: 123 })
|
|||||||
expect(content).toMatch(/\bexpose\(\{ foo: 123 \}\)/)
|
expect(content).toMatch(/\bexpose\(\{ foo: 123 \}\)/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('<script> after <script setup> the script content not end with `\\n`',() => {
|
||||||
|
const { content } = compile(`
|
||||||
|
<script setup>
|
||||||
|
import { x } from './x'
|
||||||
|
</script>
|
||||||
|
<script>const n = 1</script>
|
||||||
|
`)
|
||||||
|
assertCode(content)
|
||||||
|
})
|
||||||
|
|
||||||
describe('<script> and <script setup> co-usage', () => {
|
describe('<script> and <script setup> co-usage', () => {
|
||||||
test('script first', () => {
|
test('script first', () => {
|
||||||
const { content } = compile(`
|
const { content } = compile(`
|
||||||
|
@ -943,6 +943,11 @@ export function compileScript(
|
|||||||
// 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)
|
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`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user