Skip to content

Commit

Permalink
fix(transformer): exponentiation transform: do not assume Math is n…
Browse files Browse the repository at this point in the history
…ot a local var (#6302)

`Math` is hopefully a global var (and transform will be incorrect if it isn't), but make sure scope tree is correct either way.
  • Loading branch information
overlookmotel committed Oct 6, 2024
1 parent 15cc8af commit 56d50cf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/oxc_transformer/src/es2016/exponentiation_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
}
}

/// `left ** right` -> `Math.pow(left, right)`
/// `Math.pow(left, right)`
fn math_pow(
left: Expression<'a>,
right: Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) -> Expression<'a> {
let math_symbol_id = ctx.scopes().find_binding(ctx.current_scope_id(), "Math");
let ident_math =
ctx.create_unbound_reference_id(SPAN, ctx.ast.atom("Math"), ReferenceFlags::Read);
ctx.create_reference_id(SPAN, Atom::from("Math"), math_symbol_id, ReferenceFlags::Read);
let object = ctx.ast.expression_from_identifier_reference(ident_math);
let property = ctx.ast.identifier_name(SPAN, "pow");
let callee =
Expand Down

0 comments on commit 56d50cf

Please sign in to comment.