Skip to content

Commit

Permalink
[optimizeConstEnums] Inline const enum if only exported as type (#14723)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 5, 2022
1 parent f1c4ea3 commit 184eeea
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/babel-plugin-transform-typescript/src/const-enum.ts
Expand Up @@ -16,9 +16,13 @@ export default function transpileConstEnum(
isExported = path.parent.body.some(
stmt =>
t.isExportNamedDeclaration(stmt) &&
stmt.exportKind !== "type" &&
!stmt.source &&
stmt.specifiers.some(
spec => t.isExportSpecifier(spec) && spec.local.name === name,
spec =>
t.isExportSpecifier(spec) &&
spec.exportKind !== "type" &&
spec.local.name === name,
),
);
}
Expand Down
@@ -0,0 +1,9 @@
const enum WhitespaceFlag {
before = 1 << 0,
after = 1 << 1,
}

export type { WhitespaceFlag as WF1 };
export { WhitespaceFlag as WF2 };

export const before = WhitespaceFlag.before;
@@ -0,0 +1,6 @@
var WhitespaceFlag = {
before: 1,
after: 2
};
export { WhitespaceFlag as WF2 };
export const before = WhitespaceFlag.before;
@@ -0,0 +1,9 @@
const enum WhitespaceFlag {
before = 1 << 0,
after = 1 << 1,
}

export type { WhitespaceFlag as WF1 };
export { type WhitespaceFlag as WF2 };

export const before = WhitespaceFlag.before;
@@ -0,0 +1,2 @@
export {};
export const before = 1;

0 comments on commit 184eeea

Please sign in to comment.