Skip to content

Add BigInt#179

Closed
adrianheine wants to merge 1 commit into
estree:masterfrom
adrianheine:bigint
Closed

Add BigInt#179
adrianheine wants to merge 1 commit into
estree:masterfrom
adrianheine:bigint

Conversation

@adrianheine

Copy link
Copy Markdown
Member

This is my try at representing what I understood to be the agreed-upon solution in #169.

Comment thread experimental/bigint.md

```js
interface BigIntLiteral <: Literal {
bigint: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other Literals use value as the property name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you were the one who suggested that in #169 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that should do it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed it, but with property value, not type.

Comment thread experimental/bigint.md

interface BigIntLiteral <: Literal {
value: bigint;
bigint: string;

@j-f1 j-f1 Dec 20, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI “platforms without BigInt support” includes (and will include, for all eternity[citation needed]) JSON.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, just as regular expressions. There's a discussion in #64 about JSON.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think emitting null if bigint is not in safe integer space makes sense and would be in line with regular expression literals.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why safe integer space? Use a bigint if the platform supports it (regardless of magnitude), null otherwise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made value: bigint | null for now, but I would still prefer to drop or phase out value as explained in #64 (comment).

@adrianheine adrianheine mentioned this pull request Dec 20, 2017
@goodmind

goodmind commented Mar 13, 2019

Copy link
Copy Markdown

Should value be null if integer isn't in safe space or always null? (for JSON dump of AST)
Or maybe you can reconsider to drop value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants