transformer: inline const enum
Babel Option: https://babel.dev/docs/babel-preset-typescript#optimizeconstenums
Example:
Input:
const enum X {
FOO
}
X.FOO
Output:
0 /* X.FOO */;
Babel revisits the AST https://github.com/babel/babel/blob/94e166782a37074d8c0031fc869f37e1b456194f/packages/babel-plugin-transform-typescript/src/const-enum.ts#L69
For us it should be adding enum data to semantic.
struct EnumTable {
enums: FxHashMap<AstNodeId, EnumData>
}
struct EnumData {
symbol_id: SymbolId,
scope_id: ScopeId,
...
}
In the transformer, if the symbol is a const enum, we can lookup the enum value from semantic.
I'm thinking about implementing inline literal enum values across modules in rolldown.
It would be good if oxc also collects non-const enum data. Rolldown could use this information to inline literal enum values across modules.
I'm thinking about implementing inline literal enum values across modules in rolldown.
It would be good if oxc also collects non-const enum data. Rolldown could use this information to inline literal enum values across modules.
I'm keen to work on exposing enum data from Semantic, but there are some prerequisites need to be fulfilled before this. Do you have an estimate time of arrival for this feature?
Do you have an estimate time of arrival for this feature?
Nope.
Let's have a discussion in the weekly-meeting.
Any updates? This will cause my downstream to throw undefined XXX because my upstream uses const enum.
This would be really nice for Vue Router: I use const enums as a trick to minimize the bundle a bit
Any updates on the progress? @Boshen