Skip to content

Commit 93a950d

Browse files
committed
fix(compiler-sfc): support const enum
1 parent b771fdb commit 93a950d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,21 @@ return { a, b, c, d, x }
540540
}"
541541
`;
542542
543+
exports[`SFC compile <script setup> with TypeScript const Enum 1`] = `
544+
"import { defineComponent as _defineComponent } from 'vue'
545+
const enum Foo { A = 123 }
546+
547+
export default _defineComponent({
548+
setup(__props, { expose }) {
549+
expose()
550+
551+
552+
return { Foo }
553+
}
554+
555+
})"
556+
`;
557+
543558
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (exported interface) 1`] = `
544559
"import { defineComponent as _defineComponent } from 'vue'
545560
export interface Emits { (e: 'foo' | 'bar'): void }

Diff for: packages/compiler-sfc/__tests__/compileScript.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,18 @@ const emit = defineEmits(['a', 'b'])
794794
Foo: BindingTypes.SETUP_CONST
795795
})
796796
})
797+
798+
test('const Enum', () => {
799+
const { content, bindings } = compile(
800+
`<script setup lang="ts">
801+
const enum Foo { A = 123 }
802+
</script>`
803+
)
804+
assertCode(content)
805+
expect(bindings).toStrictEqual({
806+
Foo: BindingTypes.SETUP_CONST
807+
})
808+
})
797809
})
798810

799811
describe('async/await detection', () => {

Diff for: packages/compiler-sfc/src/compileScript.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ export function compileScript(
10081008

10091009
if (isTS) {
10101010
// runtime enum
1011-
if (node.type === 'TSEnumDeclaration' && !node.const) {
1011+
if (node.type === 'TSEnumDeclaration') {
10121012
registerBinding(setupBindings, node.id, BindingTypes.SETUP_CONST)
10131013
}
10141014

0 commit comments

Comments
 (0)