]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): support const enum
authorEvan You <yyx990803@gmail.com>
Mon, 19 Jul 2021 21:31:13 +0000 (17:31 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 19 Jul 2021 21:31:13 +0000 (17:31 -0400)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index d71f41b80023ab3052ddf518d49dabcaa8411391..fde572c8610fe6108081986e12e62982c7f12811 100644 (file)
@@ -540,6 +540,21 @@ return { a, b, c, d, x }
 }"
 `;
 
+exports[`SFC compile <script setup> with TypeScript const Enum 1`] = `
+"import { defineComponent as _defineComponent } from 'vue'
+const enum Foo { A = 123 }
+        
+export default _defineComponent({
+  setup(__props, { expose }) {
+  expose()
+
+        
+return { Foo }
+}
+
+})"
+`;
+
 exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (exported interface) 1`] = `
 "import { defineComponent as _defineComponent } from 'vue'
 export interface Emits { (e: 'foo' | 'bar'): void }
index 4b701bf373e4b8f307de9a62439869839107c960..1fc9827cd6e3cf905bd4a483d0c88a8bfe80c0ff 100644 (file)
@@ -794,6 +794,18 @@ const emit = defineEmits(['a', 'b'])
         Foo: BindingTypes.SETUP_CONST
       })
     })
+
+    test('const Enum', () => {
+      const { content, bindings } = compile(
+        `<script setup lang="ts">
+        const enum Foo { A = 123 }
+        </script>`
+      )
+      assertCode(content)
+      expect(bindings).toStrictEqual({
+        Foo: BindingTypes.SETUP_CONST
+      })
+    })
   })
 
   describe('async/await detection', () => {
index 0aab4d2855e6d4352014fa48dad3f9e2a218b69e..9999bcc7a72045038fd06d9a4db24baecb01fe9a 100644 (file)
@@ -1008,7 +1008,7 @@ export function compileScript(
 
     if (isTS) {
       // runtime enum
-      if (node.type === 'TSEnumDeclaration' && !node.const) {
+      if (node.type === 'TSEnumDeclaration') {
         registerBinding(setupBindings, node.id, BindingTypes.SETUP_CONST)
       }