Skip to content

Fix the package no longer compiling to JavaScript (a 3.5.18 regression) - #475

Merged
isoos merged 1 commit into
isoos:masterfrom
xvrh:xha/js_compatible_infinity_sentinels
Oct 7, 2026
Merged

isoos merged 1 commit into
isoos:masterfrom
xvrh:xha/js_compatible_infinity_sentinels

Conversation

@xvrh

@xvrh xvrh commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Since 3.5.18, any program that imports package:postgres fails to compile with dart2js:

lib/src/time_converters.dart:32:36:
Error: The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
const timestampPosInfinityMicros = 9223372036854775807;
                                   ^^^^^^^^^^^^^^^^^^^
lib/src/time_converters.dart:33:37:
Error: The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
const timestampNegInfinityMicros = -9223372036854775807 - 1;
                                    ^^^^^^^^^^^^^^^^^^^

The driver does not run in a browser. But we share code between a server and a Flutter web client, and that code imports this package for its types and exceptions. So the web build has to compile it, and 3.5.17 did.

The fix

The sentinels are now built from their 32-bit halves, so no literal is out of range:

const timestampPosInfinityMicros = 0x7FFFFFFF * 0x100000000 + 0xFFFFFFFF;
const timestampNegInfinityMicros = -timestampPosInfinityMicros - 1;

On the VM the values are unchanged: the int64 maximum and minimum. The existing infinity decode tests in encoding_test.dart still pass.

The test

test/js_compile_test.dart compiles both public libraries with dart compile js. It fails on master with the error above and passes with this change. It needs no database.

The `infinity` sentinels for `timestamp` were written as 64-bit integer
literals. JavaScript cannot represent them exactly, so dart2js rejects
any program that imports the package:

    Error: The integer literal 9223372036854775807 can't be represented
    exactly in JavaScript.

Build them from their 32-bit halves instead. The values are unchanged on
the VM.

The driver does not run in a browser, but apps that share code between
a server and a web client compile it there. A test now compiles the
public libraries with dart2js.

@isoos isoos left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix, thanks!

@isoos
isoos merged commit 7a9f44d into isoos:master Oct 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants