Skip to content

Commit 6f5698c

Browse files
committed
Revert "fix(compiler-sfc): infer correct type for enums"
This reverts commit 2e074a7.
1 parent 2e074a7 commit 6f5698c

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,6 @@ interface Test {}
16771677

16781678
type Alias = number[]
16791679

1680-
enum Enum { one = '1', two = '2' }
1681-
16821680

16831681
export default /*#__PURE__*/_defineComponent({
16841682
props: {
@@ -1704,7 +1702,6 @@ export default /*#__PURE__*/_defineComponent({
17041702
symbol: { type: Symbol, required: true },
17051703
extract: { type: Number, required: true },
17061704
exclude: { type: [Number, Boolean], required: true },
1707-
enum: { type: Object, required: true },
17081705
uppercase: { type: String, required: true },
17091706
params: { type: Array, required: true },
17101707
nonNull: { type: String, required: true },
@@ -1722,7 +1719,7 @@ export default /*#__PURE__*/_defineComponent({
17221719

17231720

17241721

1725-
return { Enum }
1722+
return { }
17261723
}
17271724

17281725
})"

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,6 @@ const emit = defineEmits(['a', 'b'])
998998
999999
type Alias = number[]
10001000
1001-
enum Enum { one = '1', two = '2' }
1002-
10031001
defineProps<{
10041002
string: string
10051003
number: number
@@ -1023,7 +1021,6 @@ const emit = defineEmits(['a', 'b'])
10231021
symbol: symbol
10241022
extract: Extract<1 | 2 | boolean, 2>
10251023
exclude: Exclude<1 | 2 | boolean, 2>
1026-
enum: Enum
10271024
uppercase: Uppercase<'foo'>
10281025
params: Parameters<(foo: any) => void>
10291026
nonNull: NonNullable<string | null>
@@ -1069,7 +1066,6 @@ const emit = defineEmits(['a', 'b'])
10691066
expect(content).toMatch(
10701067
`exclude: { type: [Number, Boolean], required: true }`
10711068
)
1072-
expect(content).toMatch(`enum: { type: Object, required: true }`)
10731069
expect(content).toMatch(`uppercase: { type: String, required: true }`)
10741070
expect(content).toMatch(`params: { type: Array, required: true }`)
10751071
expect(content).toMatch(`nonNull: { type: String, required: true }`)
@@ -1119,9 +1115,7 @@ const emit = defineEmits(['a', 'b'])
11191115
foo: BindingTypes.PROPS,
11201116
uppercase: BindingTypes.PROPS,
11211117
params: BindingTypes.PROPS,
1122-
nonNull: BindingTypes.PROPS,
1123-
enum: BindingTypes.PROPS,
1124-
Enum: BindingTypes.LITERAL_CONST
1118+
nonNull: BindingTypes.PROPS
11251119
})
11261120
})
11271121

packages/compiler-sfc/src/compileScript.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,15 +1369,14 @@ export function compileScript(
13691369
if (isTS) {
13701370
// move all Type declarations to outer scope
13711371
if (
1372-
node.type.startsWith('TS') ||
1373-
(node.type === 'ExportNamedDeclaration' &&
1374-
node.exportKind === 'type') ||
1375-
(node.type === 'VariableDeclaration' && node.declare)
1372+
(node.type.startsWith('TS') ||
1373+
(node.type === 'ExportNamedDeclaration' &&
1374+
node.exportKind === 'type') ||
1375+
(node.type === 'VariableDeclaration' && node.declare)) &&
1376+
node.type !== 'TSEnumDeclaration'
13761377
) {
13771378
recordType(node, declaredTypes)
1378-
if (node.type !== 'TSEnumDeclaration') {
1379-
hoistNode(node)
1380-
}
1379+
hoistNode(node)
13811380
}
13821381
}
13831382
}
@@ -1958,10 +1957,7 @@ interface PropTypeData {
19581957
}
19591958

19601959
function recordType(node: Node, declaredTypes: Record<string, string[]>) {
1961-
if (
1962-
node.type === 'TSInterfaceDeclaration' ||
1963-
node.type === 'TSEnumDeclaration'
1964-
) {
1960+
if (node.type === 'TSInterfaceDeclaration') {
19651961
declaredTypes[node.id.name] = [`Object`]
19661962
} else if (node.type === 'TSTypeAliasDeclaration') {
19671963
declaredTypes[node.id.name] = inferRuntimeType(

0 commit comments

Comments
 (0)