JS already has a Uint8Array, so bignum libraries are easy. (Let me tell you though, there were JS bignum libraries before Uint8Array, and they were, ahem, “interesting.” I think a popular one built a byte-array abstraction on top of hex-encoded strings, and then built bignums on that.)
Actually supporting the literal syntax or the operators via a plain library is impossible; but you can just do it the other way around: encourage developers to use a bignum library (for now), and have said library just “bake down” to native BigInts when they’re available.
Since everybody until now who was using bignums in JS was using them through a library, this won’t be a hard change to make.
(And it’s already been done! https://www.npmjs.com/package/big-integer now bakes down to native BigInts when it can.)
As for the brazen developers who start writing code to directly use the native BigInt... I suppose they’ll have to have two versions of their compiled code units in their minified blob, with a loader shim that evals out the version of the class/module that does/doesn’t use bigints. Maybe we’ll see an JS-pipeline pass to generate this. (I’m not a JS dev, so I’m not sure if there’s already support for this kind of thing.)
Can't you rewrite the syntax into something usable at runtime? Not that it were a good idea.
I’m guessing this has been done, to let the browser run—without backend compilation—<script type=“foo”> where foo is CoffeeScript or TypeScript or ClojureScript or what-have-you; but this one would be especially bad, because the thing it’d be targeting would still be Javascript, and so you’d have to rewrite all Javascript sources you encounter, with most of them likely never using native bigints but suffering the double-parsing overhead anyway.
Oh, and you’d have to override the ES6 module loader with one that also rewrites what it loads. Ugly.
Or if your String type doesn't do any of those. Javascript strings will happily hold an arbitrary series of 16 bit numbers.
Even when something requires valid code points, you can still easily store arbitrary 8 bit values. Or 15/16/17/20 depending on how fussy you are. Unless you want it to be hacky, it shouldn't be notably worse than an array.
https://developers.google.com/web/updates/2018/05/bigint#pol...
That doesn't sound like a recommendation.
For this to work, you need a library whose bigint behavior either exactly matches the built in implementation, or whose deviations are known and can reasonably be account for when translating to built in bigints.
The library they recommend is a JavaScript translation of their implementation of built in bigints, so should match numerically what the built in implementation does.
There may be other libraries that would be suitable, but it would be nice if everyone agreed on just one for this so that when the time comes to use Babel or similar to replace the library calls with use of the built ins, it only has to deal with one library.
[1]: https://github.com/GoogleChromeLabs/jsbi
[2]: https://github.com/GoogleChromeLabs/babel-plugin-transform-j...