]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix: should be able to parse decorators in script lang="ts" & jsx (#2088)
authorHaoqun Jiang <haoqunjiang@gmail.com>
Tue, 15 Sep 2020 01:51:15 +0000 (09:51 +0800)
committerGitHub <noreply@github.com>
Tue, 15 Sep 2020 01:51:15 +0000 (21:51 -0400)
* fix: should be able to parse decorators in script lang="ts"

* fix: should also support parsing jsx

Added to `compileScript` instead of `babelParserDefaultPlugins` because
it's not needed for template expression parsing

packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index 11f739752073c43ffdb61e9202f73d98162a33b3..0a6b9d0042d79eb667d0279f57f3737c29447565 100644 (file)
@@ -520,6 +520,22 @@ describe('SFC compile <script setup>', () => {
 })
 
 describe('SFC analyze <script> bindings', () => {
+  it('can parse decorators syntax in typescript block', () => {
+    const { scriptAst } = compile(`
+      <script lang="ts">
+        import { Options, Vue } from 'vue-class-component';
+        @Options({
+          components: {
+            HelloWorld,
+          },
+          props: ['foo', 'bar']
+        })
+        export default class Home extends Vue {}
+      </script>
+    `)
+
+    expect(scriptAst).toBeDefined()
+  })
   it('recognizes props array declaration', () => {
     const { bindings } = compile(`
       <script>
index 1eec51604adc4ee045b026bbaea1506bcf68df02..c74a3fdd8f025f94ec3e7892d1a229b7bdd9e83e 100644 (file)
@@ -60,9 +60,9 @@ export function compileScript(
   const scriptLang = script && script.lang
   const scriptSetupLang = scriptSetup && scriptSetup.lang
   const isTS = scriptLang === 'ts' || scriptSetupLang === 'ts'
-  const plugins: ParserPlugin[] = [...babelParserDefaultPlugins]
+  const plugins: ParserPlugin[] = [...babelParserDefaultPlugins, 'jsx']
   if (options.babelParserPlugins) plugins.push(...options.babelParserPlugins)
-  if (isTS) plugins.push('typescript')
+  if (isTS) plugins.push('typescript', 'decorators-legacy')
 
   if (!scriptSetup) {
     if (!script) {