fix(compiler-sfc): fix prefixIdentifier default value

This commit is contained in:
Evan You 2024-08-15 14:29:14 +08:00
parent fe008152c0
commit 3d6f01571b
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
2 changed files with 18 additions and 1 deletions

View File

@ -234,3 +234,19 @@ test('namespace / dot component usage', () => {
expect(content).toMatch('return { get Foo() { return Foo } }') expect(content).toMatch('return { get Foo() { return Foo } }')
assertCode(content) assertCode(content)
}) })
test('check when has explicit parse options', () => {
const { content } = compile(
`
<script setup lang="ts">
import { x } from './x'
</script>
<template>
{{ x }}
</template>
`,
undefined,
{ templateParseOptions: {} },
)
expect(content).toMatch('return { get x() { return x } }')
})

View File

@ -133,7 +133,7 @@ export function parse(
pad = false, pad = false,
ignoreEmpty = true, ignoreEmpty = true,
compiler = CompilerDOM, compiler = CompilerDOM,
templateParseOptions = { prefixIdentifiers: true }, templateParseOptions = {},
} = options } = options
const descriptor: SFCDescriptor = { const descriptor: SFCDescriptor = {
@ -152,6 +152,7 @@ export function parse(
const errors: (CompilerError | SyntaxError)[] = [] const errors: (CompilerError | SyntaxError)[] = []
const ast = compiler.parse(source, { const ast = compiler.parse(source, {
parseMode: 'sfc', parseMode: 'sfc',
prefixIdentifiers: true,
...templateParseOptions, ...templateParseOptions,
onError: e => { onError: e => {
errors.push(e) errors.push(e)