Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transformer/nullish-coalescing-operator): generate the correct binding name #4974

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: 2 additions & 8 deletions crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,8 @@ impl<'a> NullishCoalescingOperator<'a> {
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
// Add `var name` to scope
let name = match expr {
Expression::Identifier(ident) => ident.name.as_str(),
// TODO: needs to port generateUidIdentifierBasedOnNode
// https://github.com/babel/babel/blob/419644f27c5c59deb19e71aaabd417a3bc5483ca/packages/babel-traverse/src/scope/index.ts#L543-L545
_ => "nullish_coalescing_operator",
};
let symbol_id =
ctx.generate_uid_in_current_scope(name, SymbolFlags::FunctionScopedVariable);
let symbol_id = ctx
.generate_uid_in_current_scope_based_on_node(expr, SymbolFlags::FunctionScopedVariable);
let symbol_name = ctx.ast.atom(ctx.symbols().get_name(symbol_id));

{
Expand Down
8 changes: 4 additions & 4 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,9 @@ ReferenceId mismatch after transform
* assumption-noDocumentAll/transform-in-default-param/input.js
Bindings Mismatch:
previous scope ScopeId(0): ["bar", "foo"]
current scope ScopeId(0): ["_nullish_coalescing_operator", "bar", "foo"]
current scope ScopeId(0): ["_foo$bar", "bar", "foo"]
Bindings Mismatch:
previous scope ScopeId(1): ["_nullish_coalescing_operator", "foo", "qux"]
previous scope ScopeId(1): ["_foo$bar", "foo", "qux"]
current scope ScopeId(1): ["foo", "qux"]
Symbols mismatch after transform
ReferenceId mismatch after transform
Expand All @@ -1334,9 +1334,9 @@ ReferenceId mismatch after transform
* nullish-coalescing/transform-in-default-param/input.js
Bindings Mismatch:
previous scope ScopeId(0): ["bar", "foo"]
current scope ScopeId(0): ["_nullish_coalescing_operator", "bar", "foo"]
current scope ScopeId(0): ["_foo$bar", "bar", "foo"]
Bindings Mismatch:
previous scope ScopeId(1): ["_nullish_coalescing_operator", "foo", "qux"]
previous scope ScopeId(1): ["_foo$bar", "foo", "qux"]
current scope ScopeId(1): ["foo", "qux"]
Symbols mismatch after transform
ReferenceId mismatch after transform
Expand Down