]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
Revert "fix(compiler-sfc): infer correct type for enums"
authorEvan You <yyx990803@gmail.com>
Tue, 28 Mar 2023 08:55:19 +0000 (16:55 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 28 Mar 2023 08:55:19 +0000 (16:55 +0800)
This reverts commit 2e074a70091e76359e930e733785100cd7dc66ed.

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

index d0559423e7eb7f673a7d4ab6a97723857518d6e5..b7a13e568510a10767ee486fadab199543b0fef5 100644 (file)
@@ -1677,8 +1677,6 @@ interface Test {}
 
       type Alias = number[]
 
-      enum Enum { one = '1', two = '2' }
-
       
 export default /*#__PURE__*/_defineComponent({
   props: {
@@ -1704,7 +1702,6 @@ export default /*#__PURE__*/_defineComponent({
     symbol: { type: Symbol, required: true },
     extract: { type: Number, required: true },
     exclude: { type: [Number, Boolean], required: true },
-    enum: { type: Object, required: true },
     uppercase: { type: String, required: true },
     params: { type: Array, required: true },
     nonNull: { type: String, required: true },
@@ -1722,7 +1719,7 @@ export default /*#__PURE__*/_defineComponent({
 
       
       
-return { Enum }
+return {  }
 }
 
 })"
index 0c53a155a5a44e6d010a877eb2afb1c90b0ed5f5..8f96ecc11c53a944b3ab8a1ed7198be70271faab 100644 (file)
@@ -998,8 +998,6 @@ const emit = defineEmits(['a', 'b'])
 
       type Alias = number[]
 
-      enum Enum { one = '1', two = '2' }
-
       defineProps<{
         string: string
         number: number
@@ -1023,7 +1021,6 @@ const emit = defineEmits(['a', 'b'])
         symbol: symbol
         extract: Extract<1 | 2 | boolean, 2>
         exclude: Exclude<1 | 2 | boolean, 2>
-        enum: Enum
         uppercase: Uppercase<'foo'>
         params: Parameters<(foo: any) => void>
         nonNull: NonNullable<string | null>
@@ -1069,7 +1066,6 @@ const emit = defineEmits(['a', 'b'])
       expect(content).toMatch(
         `exclude: { type: [Number, Boolean], required: true }`
       )
-      expect(content).toMatch(`enum: { type: Object, required: true }`)
       expect(content).toMatch(`uppercase: { type: String, required: true }`)
       expect(content).toMatch(`params: { type: Array, required: true }`)
       expect(content).toMatch(`nonNull: { type: String, required: true }`)
@@ -1119,9 +1115,7 @@ const emit = defineEmits(['a', 'b'])
         foo: BindingTypes.PROPS,
         uppercase: BindingTypes.PROPS,
         params: BindingTypes.PROPS,
-        nonNull: BindingTypes.PROPS,
-        enum: BindingTypes.PROPS,
-        Enum: BindingTypes.LITERAL_CONST
+        nonNull: BindingTypes.PROPS
       })
     })
 
index dff71e642f20267405ffe3035b20f3cffb376d39..e2e129924e3d68873cafefb4fbffe55ae099f0a9 100644 (file)
@@ -1369,15 +1369,14 @@ export function compileScript(
     if (isTS) {
       // move all Type declarations to outer scope
       if (
-        node.type.startsWith('TS') ||
-        (node.type === 'ExportNamedDeclaration' &&
-          node.exportKind === 'type') ||
-        (node.type === 'VariableDeclaration' && node.declare)
+        (node.type.startsWith('TS') ||
+          (node.type === 'ExportNamedDeclaration' &&
+            node.exportKind === 'type') ||
+          (node.type === 'VariableDeclaration' && node.declare)) &&
+        node.type !== 'TSEnumDeclaration'
       ) {
         recordType(node, declaredTypes)
-        if (node.type !== 'TSEnumDeclaration') {
-          hoistNode(node)
-        }
+        hoistNode(node)
       }
     }
   }
@@ -1958,10 +1957,7 @@ interface PropTypeData {
 }
 
 function recordType(node: Node, declaredTypes: Record<string, string[]>) {
-  if (
-    node.type === 'TSInterfaceDeclaration' ||
-    node.type === 'TSEnumDeclaration'
-  ) {
+  if (node.type === 'TSInterfaceDeclaration') {
     declaredTypes[node.id.name] = [`Object`]
   } else if (node.type === 'TSTypeAliasDeclaration') {
     declaredTypes[node.id.name] = inferRuntimeType(