You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JavaScript: a long literal outside ±(2^53−1) is written as a plain Number and silently changes value #168
JavaScript numbers are IEEE doubles, so any integer larger in magnitude than Number.MAX_SAFE_INTEGER is rounded when it is parsed.
Repro
new VariableDeclaration("big", "long", new LiteralExpression<long>(9007199254740993L)) generates:
letbig=9007199254740993;
Node 22 prints 9007199254740992.
The other six targets keep the exact value:
C# emits …993L.
Rust, Go, C and C++ use 64-bit integer types.
Python's int has arbitrary precision.
Why it matters
This silently corrupts data rather than failing to compile. It affects 64-bit IDs, hashes, nanosecond timestamps and bit masks. The AST says long, but the JavaScript output computes with a different number.
Suggested fix / acceptance criteria
In JavaScriptGenerator, write a long literal whose magnitude is above 9007199254740991 as a BigInt literal, e.g. 9007199254740993n. The value stays exact, and mixing a BigInt with Number arithmetic throws a TypeError instead of silently giving the wrong answer.
Alternative: keep the plain literal but add a note, following the repo's convention of stating a limitation rather than dropping it silently.
Literals within the safe range stay unchanged.
Add a test that runs the generated output under Node and checks the exact value.
Priority: High. The generated JavaScript compiles and runs, but silently changes the value of any long literal outside ±(2^53−1). That corrupts IDs, hashes and bit masks with no error.
Area / suggested owner:JavaScriptGenerator literal emission (override of TryGenerateCommonNode for LiteralExpression<long>).
Duplicates / in progress: No duplicate found. No open PR covers it. Coder#124 maps long to int for Python, which is a different target.
Next step: Emit a BigInt literal (…n) when the magnitude exceeds Number.MAX_SAFE_INTEGER, and add a Node-executed test that checks the exact value.
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
longliteral outside ±(2^53−1). That corrupts IDs, hashes and bit masks with no error.JavaScriptGeneratorliteral emission (override ofTryGenerateCommonNodeforLiteralExpression<long>).longtointfor Python, which is a different target.…n) when the magnitude exceedsNumber.MAX_SAFE_INTEGER, and add a Node-executed test that checks the exact value.Generated by Claude Code