fix(compiler-sfc): support tsx in setup script (#3825)

close #3808
This commit is contained in:
Jason 2021-05-25 00:13:37 +08:00 committed by GitHub
parent f7c54caeb1
commit 01e8ba8f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,7 +101,11 @@ export function compileScript(
sfc.template && sfc.template.attrs['inherit-attrs'] === 'false'
const scriptLang = script && script.lang
const scriptSetupLang = scriptSetup && scriptSetup.lang
const isTS = scriptLang === 'ts' || scriptSetupLang === 'ts'
const isTS =
scriptLang === 'ts' ||
scriptLang === 'tsx' ||
scriptSetupLang === 'ts' ||
scriptSetupLang === 'tsx'
const plugins: ParserPlugin[] = [...babelParserDefaultPlugins, 'jsx']
if (options.babelParserPlugins) plugins.push(...options.babelParserPlugins)
if (isTS) plugins.push('typescript', 'decorators-legacy')
@ -110,7 +114,7 @@ export function compileScript(
if (!script) {
throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`)
}
if (scriptLang && scriptLang !== 'ts') {
if (scriptLang && !isTS && scriptLang !== 'jsx') {
// do not process non js/ts script blocks
return script
}
@ -156,7 +160,7 @@ export function compileScript(
)
}
if (scriptSetupLang && scriptSetupLang !== 'ts') {
if (scriptSetupLang && !isTS && scriptSetupLang !== 'jsx') {
// do not process non js/ts script blocks
return scriptSetup
}