diff --git a/packages/compiler-sfc/__tests__/compileScriptParseOnlyMode.spec.ts b/packages/compiler-sfc/__tests__/compileScriptParseOnlyMode.spec.ts index 50a8a112..86a5a7bf 100644 --- a/packages/compiler-sfc/__tests__/compileScriptParseOnlyMode.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScriptParseOnlyMode.spec.ts @@ -74,4 +74,14 @@ describe('compileScript parseOnly mode', () => { const { ranges } = compile(``) expect(getRange(src, ranges!.emitsTypeArg!)).toBe(`{ (e: 'x'): void }`) }) + + test('no script setup block', () => { + const src = `import { x } from './x'` + const { ranges } = compile(``) + expect(getRange(src, ranges!.scriptBindings[0])).toBe(`x`) + }) + + test('no script block', () => { + expect(() => compile(``)).not.toThrow() + }) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index bf4cec67..6d4733f0 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1,5 +1,10 @@ import MagicString from 'magic-string' -import { BindingMetadata, BindingTypes, UNREF } from '@vue/compiler-core' +import { + BindingMetadata, + BindingTypes, + locStub, + UNREF +} from '@vue/compiler-core' import { ScriptSetupTextRanges, SFCDescriptor, @@ -126,7 +131,7 @@ export function compileScript( type: 'script', content: '', attrs: {}, - loc: null as any + loc: locStub } }