Skip to content

Commit 184eeea

Browse files
[optimizeConstEnums] Inline const enum if only exported as type (#14723)
1 parent f1c4ea3 commit 184eeea

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

packages/babel-plugin-transform-typescript/src/const-enum.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ export default function transpileConstEnum(
1616
isExported = path.parent.body.some(
1717
stmt =>
1818
t.isExportNamedDeclaration(stmt) &&
19+
stmt.exportKind !== "type" &&
1920
!stmt.source &&
2021
stmt.specifiers.some(
21-
spec => t.isExportSpecifier(spec) && spec.local.name === name,
22+
spec =>
23+
t.isExportSpecifier(spec) &&
24+
spec.exportKind !== "type" &&
25+
spec.local.name === name,
2226
),
2327
);
2428
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const enum WhitespaceFlag {
2+
before = 1 << 0,
3+
after = 1 << 1,
4+
}
5+
6+
export type { WhitespaceFlag as WF1 };
7+
export { WhitespaceFlag as WF2 };
8+
9+
export const before = WhitespaceFlag.before;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var WhitespaceFlag = {
2+
before: 1,
3+
after: 2
4+
};
5+
export { WhitespaceFlag as WF2 };
6+
export const before = WhitespaceFlag.before;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const enum WhitespaceFlag {
2+
before = 1 << 0,
3+
after = 1 << 1,
4+
}
5+
6+
export type { WhitespaceFlag as WF1 };
7+
export { type WhitespaceFlag as WF2 };
8+
9+
export const before = WhitespaceFlag.before;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {};
2+
export const before = 1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy