Skip to content

Commit

Permalink
fix(compiler-sfc): fix parse-only mode when there is no script setup …
Browse files Browse the repository at this point in the history
…block
  • Loading branch information
yyx990803 committed Jul 2, 2021
1 parent dd280dd commit 253ca27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/compiler-sfc/__tests__/compileScriptParseOnlyMode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ describe('compileScript parseOnly mode', () => {
const { ranges } = compile(`<script setup lang="ts">${src}</script>`)
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()
})
})
9 changes: 7 additions & 2 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -126,7 +131,7 @@ export function compileScript(
type: 'script',
content: '',
attrs: {},
loc: null as any
loc: locStub
}
}

Expand Down

0 comments on commit 253ca27

Please sign in to comment.