Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/oxc_transformer/src/typescript/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@ impl<'a, 'b> VisitMut<'a> for IdentifierReferenceRename<'a, 'b> {
None
}
Expression::Identifier(ident) => {
// If the identifier is binding in current/parent scopes,
// and it is not a member of the enum,
// we don't need to rename it.
// `var c = 1; enum A { a = c }` -> `var c = 1; enum A { a = c }
if !self.previous_enum_members.contains_key(&ident.name)
&& self.ctx.scopes().has_binding(self.ctx.current_scope_id(), &ident.name)
{
return;
}

// TODO: shadowed case, e.g. let ident = 1; ident; // ident is not an enum
// enum_name.identifier
let ident_reference = IdentifierReference::new(SPAN, self.enum_name.clone());
Expand Down
2 changes: 1 addition & 1 deletion tasks/transform_conformance/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 4bd1b2c2

Passed: 3/3
Passed: 4/4

# All Passed:
* babel-plugin-transform-typescript
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var x = 10;

enum Foo {
a = 10,
b = a,
c = b + x,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var x = 10;
var Foo = function(Foo) {
Foo[Foo['a'] = 10] = 'a';
Foo[Foo['b'] = 10] = 'b';
Foo[Foo['c'] = Foo.b + x] = 'c';
return Foo;
}(Foo || {});