Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit b54ac90

Browse files
committed
fix: support enum, close #35
1 parent 03394fe commit b54ac90

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/core/identifiers.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { PrivateName, Expression, Statement, SpreadElement, Node } from '@babel/types'
22

33
export function getIdentifierDeclarations(nodes: Statement[], identifiers = new Set<string>()) {
4-
for (const node of nodes) {
4+
for (let node of nodes) {
5+
if (node.type === 'ExportNamedDeclaration') {
6+
node = node.declaration!
7+
if (!node)
8+
continue
9+
}
510
if (node.type === 'ImportDeclaration') {
611
for (const specifier of node.specifiers)
712
identifiers.add(specifier.local.name)
@@ -38,6 +43,10 @@ export function getIdentifierDeclarations(nodes: Statement[], identifiers = new
3843
if (node.id)
3944
identifiers.add(node.id.name)
4045
}
46+
else if (node.type === 'TSEnumDeclaration') {
47+
if (node.id)
48+
identifiers.add(node.id.name)
49+
}
4150
// else {
4251
// console.log(node)
4352
// }

test/__snapshots__/transform.test.ts.snap

+22
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@ export default __sfc_main;
168168
169169
exports[`transform fixtures test/fixtures/Empty.vue 1`] = `""`;
170170
171+
exports[`transform fixtures test/fixtures/Enum.vue 1`] = `
172+
"<template>
173+
<div>{{ MyEnum }}</div>
174+
</template>
175+
176+
<script lang=\\"ts\\">
177+
enum MyEnum {
178+
test = 'true',
179+
}
180+
const __sfc_main = {};
181+
182+
__sfc_main.setup = (__props, __ctx) => {
183+
return {
184+
MyEnum
185+
};
186+
};
187+
188+
export default __sfc_main;
189+
</script>
190+
"
191+
`;
192+
171193
exports[`transform fixtures test/fixtures/Macros.vue 1`] = `
172194
"<template>
173195
<div @click=\\"emit(props.msg)\\">{{ msg }}</div>

test/fixtures/Enum.vue

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<div>{{ MyEnum }}</div>
3+
</template>
4+
5+
<script setup lang="ts">
6+
enum MyEnum {
7+
test = 'true',
8+
}
9+
</script>

0 commit comments

Comments
 (0)