@babel/eslint-parser: fix BigIntLiteral node to match ESTree spec (#10827)
* @babel/eslint-parser: fix BigIntLiteral node to match ESTree spec * Move token conversion to @babel/eslint-parser * Add estree plugin tests * Update test helpers to handle BigInt serializing * Update Literal union type to include BigIntLiteral * Add FlowIgnore comment for BigInt
This commit is contained in:
committed by
Nicolò Ribaudo
parent
b2429fe203
commit
fb100eee41
@@ -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;
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user