Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

BigInt: Stage 2 #569

Closed
littledan opened this issue Jun 6, 2017 · 3 comments
Closed

BigInt: Stage 2 #569

littledan opened this issue Jun 6, 2017 · 3 comments

Comments

@littledan
Copy link

littledan commented Jun 6, 2017

New Issue: babel/proposals#2


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

Parser

  • Similar to Numeric Separator: Stage 1 #538, we'll need to modify the tokenizer to accept 10n
    as a valid number. (Check that PR)
  • From a syntactic perspective, the only thing added is numeric literals of the form 987235987032n. These permit hexadecimal, octal and binary prefixes, but no exponential form, and no decimal place. See the grammar in this section of the proposed spec.

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.
@wdhorton
Copy link
Contributor

wdhorton commented Jun 6, 2017

I'd like to take on this issue!

@amilajack
Copy link

All arithmetic operations and comparisons should be replaced by calls to functions which provide the appropriate behavior depending whether arguments are BigInts or Numbers.

I've done some work on this in a babel plugin that prevents coercion in JS. Here's the related code for that

@littledan
Copy link
Author

@wdhorton Let me know if you want any help with reviews, interpreting the spec, etc!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants