proposals
proposals copied to clipboard
BigInt (Stage 3)
Champion: @littledan Spec Repo: https://github.com/tc39/proposal-bigint Spec Text: https://tc39.github.io/proposal-bigint Slides (to Stage 3 at May TC39 Meeting): https://docs.google.com/presentation/d/1lrcjQzIFgdUXczeeAzs4GkTXJsRQU21UhtmXef70Qic/edit#slide=id.p
moved to Stage 3 at July TC39 Meeting https://github.com/tc39/agendas/blob/master/2017/07.md
The syntax has been implemented in Babylon, see https://github.com/babel/babylon/issues/569#issuecomment-306478858 . What remains is a plugin to implement the transform.
- All arithmetic operations and comparisons should be replaced by calls to functions which provide the appropriate behavior depending whether arguments are BigInts or Numbers.
- The transform is slow, so it will really be more of a toy rather than something that should be used in production. For this reason, I'd argue it should be left out of Babel presets.
- Polyfill needed--ideally, this would be a thin wrapper around another BigNum library from npm. There are just a few methods to support. Some functions will have to be a bit different to get close to the right behavior, for example,
valueOf()
should throw a TypeError, so that implicitly casting to Number throws a TypeError, even if it would really return the BigInt. Additionally, the polyfill needs BigInt64Array and DataView operations. - A good starting point from @amilajack:
I've done some work on this in a babel plugin that prevents coercion in JS. Here's the related code for that
Now that the syntax has been implemented, I can go ahead and work on the transform too
How's this implementation coming along? Anything I could help with?
BTW there are some tests to start with in test262 here from my colleague @cxielarko at Igalia, but there's a lot of room for additional tests.
@littledan apologies for the delay on this, haven't had as much time to work on it as I expected. i'm planning on digging in this weekend and hopefully getting through a lot of it, and i just put up a WIP PR with the transform for adding BigInts, with a few questions https://github.com/babel/babel/pull/6015
any developments on this? Somewhere you might want help?
There's a PR with some progress in https://github.com/babel/babel/pull/6015. I'd also love to see this working, as Chrome has built-in support for bigints now (https://developers.google.com/web/updates/2018/05/bigint), so it would make sense to start writing code with the new syntax.
Seems like this would be a good project for someone to pick up.
FYI: typescript have merged their BigInt support! https://github.com/Microsoft/TypeScript/pull/25886