-
Notifications
You must be signed in to change notification settings - Fork 18
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
What to do about B
and -2147483648
in mappings
#123
Comments
Decoding is
There are also bugs with round-tripping values >= to 1,073,741,824.
Values this large have the 31st bit set, and when we encode we perform Rather than standardize broken behavior, I think we should fix the impls, including the proper decoding of |
To help with this discussion, I built https://justin.ridgewell.name/integer-toy/ |
Given that until #119 we were very hand-wavy about how out base64 VLQs work, there is an ambiguity when it comes to decoding
B
(whose bit pattern is 00001).My reading of our spec was that:
and thus B decodes to "-0", which is simply 0 because we are working with integers.
@jridgewell's reading is that (@jridgewell is this correct? I tried applying this same "algorithm" to F and it does not work):
and this B decodes to 1000_0000_0000_0000_0000_0000_0000_0000, which when interpreted as an i32 is -2147483648
I did some testing in various implementations:
Test 1
0gggggC is 2^30+10, so in implementations that decode B as -2^31 the error will be reported as being thrown at line 2^30+10 - 2^31 + 2^30+10 = 20 (or 21 if 1-based)
In implementations that decode B as 0 this overflows, so the result is unspecified and test does not apply.
Test 2
C is 1, so in implementations that decode B as 0 the error will be reported as being thrown at line 1 + 0 = 1 (or 2 1-based)
In implementations that decode B as -2^31 this yields a negative number (-2147483647), so the test does not apply.
These are the results:
--enable-source-maps
npm:source-map-support
Bun
I also tried Bun using this trick. You need to prefix the file with
@bun
line, prefix the"mappings"
string with;
, and re-encode the source map to Base 64. However, in both test case it errors with "Could not decode sourcemap".My proposal
We should clarify that B is decoded to 0 and not to -2^31, ratifying what Deno/Chrome/Firefox/Safari do.
I propose that we go even one step further, and say that encoders must encode 0 as A and not as B. This carves out some space in the
mappings
field in case we'll ever need it in the future: we can one day give a special meaning to,B,
, and tools that do not recognize this meaning would simply fallback to considering it as a no-op :)The text was updated successfully, but these errors were encountered: