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

fix(transformer/typescript): create Reference for Infinity #8354

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
fix(transformer/typescript): create Reference for Infinity (#8354)
Create a `Reference` when generating new `IdentifierReference` for `Infinity`.
  • Loading branch information
overlookmotel committed Jan 9, 2025
commit 78d7c97357b1881f95806d8c72c00d52d28e6ec9
10 changes: 8 additions & 2 deletions crates/oxc_transformer/src/typescript/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,18 @@ impl<'a> TypeScriptEnum<'a> {
ctx.ast.expression_numeric_literal(SPAN, value, None, NumberBase::Decimal)
}

fn get_initializer_expr(value: f64, ctx: &TraverseCtx<'a>) -> Expression<'a> {
fn get_initializer_expr(value: f64, ctx: &mut TraverseCtx<'a>) -> Expression<'a> {
let is_negative = value < 0.0;

// Infinity
let expr = if value.is_infinite() {
ctx.ast.expression_identifier_reference(SPAN, "Infinity")
let infinity_symbol_id = ctx.scopes().find_binding(ctx.current_scope_id(), "Infinity");
ctx.create_ident_expr(
SPAN,
Atom::from("Infinity"),
infinity_symbol_id,
ReferenceFlags::Read,
)
} else {
let value = if is_negative { -value } else { value };
Self::get_number_literal_expression(value, ctx)
Expand Down
14 changes: 2 additions & 12 deletions tasks/coverage/snapshots/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13683,9 +13683,7 @@ after transform: ScopeId(0): [ScopeId(1)]
rebuilt : ScopeId(0): []

tasks/coverage/typescript/tests/cases/compiler/fakeInfinity2.ts
semantic error: Missing ReferenceId: "Infinity"
Missing ReferenceId: "Infinity"
Missing SymbolId: "X"
semantic error: Missing SymbolId: "X"
Missing SymbolId: "_X"
Missing ReferenceId: "_X"
Missing ReferenceId: "f"
Expand Down Expand Up @@ -13718,14 +13716,9 @@ rebuilt : SymbolId(4): [ReferenceId(9)]
Reference symbol mismatch for "X":
after transform: SymbolId(3) "X"
rebuilt : SymbolId(2) "X"
Unresolved references mismatch:
after transform: ["Error"]
rebuilt : ["Error", "Infinity"]

tasks/coverage/typescript/tests/cases/compiler/fakeInfinity3.ts
semantic error: Missing ReferenceId: "Infinity"
Missing ReferenceId: "Infinity"
Missing SymbolId: "X"
semantic error: Missing SymbolId: "X"
Missing SymbolId: "_X"
Missing ReferenceId: "_X"
Missing ReferenceId: "f"
Expand Down Expand Up @@ -13755,9 +13748,6 @@ rebuilt : SymbolId(4): SymbolFlags(FunctionScopedVariable)
Symbol reference IDs mismatch for "f":
after transform: SymbolId(6): []
rebuilt : SymbolId(4): [ReferenceId(9)]
Symbol reference IDs mismatch for "Infinity":
after transform: SymbolId(8): []
rebuilt : SymbolId(6): [ReferenceId(2), ReferenceId(5)]
Reference symbol mismatch for "X":
after transform: SymbolId(3) "X"
rebuilt : SymbolId(2) "X"
Expand Down
6 changes: 1 addition & 5 deletions tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ after transform: ["const"]
rebuilt : []

* computed-constant-value/input.ts
Missing ReferenceId: "Infinity"
Missing ReferenceId: "Infinity"
Missing ReferenceId: "Infinity"
Missing ReferenceId: "Infinity"
Bindings mismatch:
after transform: ScopeId(1): ["A", "a", "b", "c", "d", "e"]
rebuilt : ScopeId(1): ["A"]
Expand Down Expand Up @@ -97,7 +93,7 @@ Unresolved references mismatch:
after transform: ["Infinity", "NaN"]
rebuilt : ["Infinity"]
Unresolved reference IDs mismatch for "Infinity":
after transform: [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3)]
after transform: [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(8), ReferenceId(11), ReferenceId(14), ReferenceId(18)]
rebuilt : [ReferenceId(2), ReferenceId(5), ReferenceId(8), ReferenceId(12)]

* elimination-declare/input.ts
Expand Down
Loading