]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): support tsx in setup script (#3825)
authorJason <jason.daurus@gmail.com>
Mon, 24 May 2021 16:13:37 +0000 (00:13 +0800)
committerGitHub <noreply@github.com>
Mon, 24 May 2021 16:13:37 +0000 (12:13 -0400)
close #3808

packages/compiler-sfc/src/compileScript.ts

index 5bb8a2461a90c8dc69ab4035e027ab938fb53c85..10912838e5343a3535149c926afd94276530a26c 100644 (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
   }