Skip to content

Commit

Permalink
fix(compiler-sfc): support tsx in setup script (#3825)
Browse files Browse the repository at this point in the history
close #3808
  • Loading branch information
gzzhanghao committed May 24, 2021
1 parent f7c54ca commit 01e8ba8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 01e8ba8

Please sign in to comment.