New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@babel/eslint-parser: fix BigIntLiteral node to match ESTree spec #10827
Changes from all commits
4dada50
444f51f
ccd0c7d
45d2b07
99e066a
4ead529
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,6 @@ const astTransformVisitor = { | |
} | ||
|
||
// modules | ||
|
||
if (path.isImportDeclaration()) { | ||
delete node.isType; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// @flow | ||
|
||
/* global BigInt */ | ||
|
||
import { types as tt, TokenType } from "../tokenizer/types"; | ||
import type Parser from "../parser"; | ||
import * as N from "../types"; | ||
|
@@ -31,6 +33,16 @@ export default (superClass: Class<Parser>): Class<Parser> => | |
return node; | ||
} | ||
|
||
estreeParseBigIntLiteral(value: any): N.Node { | ||
// https://github.com/estree/estree/blob/master/es2020.md#bigintliteral | ||
// $FlowIgnore | ||
const bigInt = typeof BigInt !== "undefined" ? BigInt(value) : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a test case to show that the parsed result is different on node.js 6 and 8, which does not have BigInt support. https://github.com/estree/estree/blob/master/es2020.md#bigintliteral
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, are we not testing in older Node versions at the moment? I tested it locally with older Node versions and assumed this was already being done in CI? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right - sorry, I was thinking of the |
||
const node = this.estreeParseLiteral(bigInt); | ||
node.bigint = String(node.value || value); | ||
|
||
return node; | ||
} | ||
|
||
estreeParseLiteral(value: any): N.Node { | ||
return this.parseLiteral(value, "Literal"); | ||
} | ||
|
@@ -244,13 +256,16 @@ export default (superClass: Class<Parser>): Class<Parser> => | |
|
||
parseExprAtom(refShorthandDefaultPos?: ?Pos): N.Expression { | ||
switch (this.state.type) { | ||
case tt.regexp: | ||
return this.estreeParseRegExpLiteral(this.state.value); | ||
|
||
case tt.num: | ||
case tt.string: | ||
return this.estreeParseLiteral(this.state.value); | ||
|
||
case tt.regexp: | ||
return this.estreeParseRegExpLiteral(this.state.value); | ||
|
||
case tt.bigint: | ||
return this.estreeParseBigIntLiteral(this.state.value); | ||
|
||
case tt._null: | ||
return this.estreeParseLiteral(null); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const a = 1n; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"type": "File", | ||
"start": 0, | ||
"end": 13, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 13 | ||
} | ||
}, | ||
"program": { | ||
"type": "Program", | ||
"start": 0, | ||
"end": 13, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 13 | ||
} | ||
}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start": 0, | ||
"end": 13, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 13 | ||
} | ||
}, | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start": 6, | ||
"end": 12, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 6 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 12 | ||
} | ||
}, | ||
"id": { | ||
"type": "Identifier", | ||
"start": 6, | ||
"end": 7, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 6 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 7 | ||
}, | ||
"identifierName": "a" | ||
}, | ||
"name": "a" | ||
}, | ||
"init": { | ||
"type": "Literal", | ||
"start": 10, | ||
"end": 12, | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 10 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 12 | ||
} | ||
}, | ||
"value": "1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't the actual correct value in the AST (it's the |
||
"raw": "1n", | ||
"bigint": "1" | ||
} | ||
} | ||
], | ||
"kind": "const" | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"estree", | ||
"bigInt" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"plugins": ["classProperties", ["decorators", { "decoratorsBeforeExport": false }]] | ||
"plugins": [ | ||
"classProperties", | ||
["decorators", { "decoratorsBeforeExport": false }] | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Muuuuuch better 😄