Skip to content

Commit

Permalink
fix(compiler-sfc): support const enum
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 19, 2021
1 parent b771fdb commit 93a950d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
12 changes: 12 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 93a950d

Please sign in to comment.