Add BigInt#179
Conversation
|
|
||
| ```js | ||
| interface BigIntLiteral <: Literal { | ||
| bigint: string; |
There was a problem hiding this comment.
Other Literals use value as the property name.
There was a problem hiding this comment.
As far as I understand, the idea here is to have it similar to RegExpLiteral where value might or might not be representable on the target runtime so another field is needed to represent the parsing result in these cases.
There was a problem hiding this comment.
Actually, you were the one who suggested that in #169 (comment)
There was a problem hiding this comment.
Ah, that's right, there's no "type" or anything distinguishing it from other Literals. Got it. Okay, what should the value of these nodes be? Currently bigints are not allowed in the value field.
There was a problem hiding this comment.
You suggested to use a BigInt literal for value. For that we would need to amend the Literal interface (extend interface Literal { type: string | boolean | null | number | RegExp | bigint;) and add value: bigint to this interface, right?
There was a problem hiding this comment.
I pushed it, but with property value, not type.
|
|
||
| interface BigIntLiteral <: Literal { | ||
| value: bigint; | ||
| bigint: string; |
There was a problem hiding this comment.
How about raw and cooked? (i.e.raw would be "12345n" and cooked would be 12345n (as a BigInt))?
Also, how would this be represented on platforms without BigInt support?
There was a problem hiding this comment.
cooked only exists with template literals. raw is not part of the spec for (non-template) literals (see #14).
As for platforms without BigInt support, I've been asking this myself, too. Babylon doesn't emit the value, so I'm not aware of any precedents. I can think of a) emitting null b) casting to a regular number, which is lossy.
There was a problem hiding this comment.
FYI “platforms without BigInt support” includes (and will include, for all eternity[citation needed]) JSON.
There was a problem hiding this comment.
You are right, just as regular expressions. There's a discussion in #64 about JSON.
There was a problem hiding this comment.
I think emitting null if bigint is not in safe integer space makes sense and would be in line with regular expression literals.
There was a problem hiding this comment.
Why safe integer space? Use a bigint if the platform supports it (regardless of magnitude), null otherwise.
There was a problem hiding this comment.
I've made value: bigint | null for now, but I would still prefer to drop or phase out value as explained in #64 (comment).
|
Should |
This is my try at representing what I understood to be the agreed-upon solution in #169.