fix(compiler-sfc): fix parse-only mode when there is no script setup block

This commit is contained in:
Evan You 2021-07-02 08:24:24 -04:00
parent dd280ddaba
commit 253ca2729d
2 changed files with 17 additions and 2 deletions

View File

@ -74,4 +74,14 @@ describe('compileScript parseOnly mode', () => {
const { ranges } = compile(`<script setup lang="ts">${src}</script>`) const { ranges } = compile(`<script setup lang="ts">${src}</script>`)
expect(getRange(src, ranges!.emitsTypeArg!)).toBe(`{ (e: 'x'): void }`) expect(getRange(src, ranges!.emitsTypeArg!)).toBe(`{ (e: 'x'): void }`)
}) })
test('no script setup block', () => {
const src = `import { x } from './x'`
const { ranges } = compile(`<script>${src}</script>`)
expect(getRange(src, ranges!.scriptBindings[0])).toBe(`x`)
})
test('no script block', () => {
expect(() => compile(`<style>hello</style>`)).not.toThrow()
})
}) })

View File

@ -1,5 +1,10 @@
import MagicString from 'magic-string' import MagicString from 'magic-string'
import { BindingMetadata, BindingTypes, UNREF } from '@vue/compiler-core' import {
BindingMetadata,
BindingTypes,
locStub,
UNREF
} from '@vue/compiler-core'
import { import {
ScriptSetupTextRanges, ScriptSetupTextRanges,
SFCDescriptor, SFCDescriptor,
@ -126,7 +131,7 @@ export function compileScript(
type: 'script', type: 'script',
content: '', content: '',
attrs: {}, attrs: {},
loc: null as any loc: locStub
} }
} }