feat: enable numericSeparator parsing support (#11863)

This commit is contained in:
Huáng Jùnliàng 2020-07-22 04:47:27 -04:00
parent ccd98f042c
commit 0e985fb287
358 changed files with 20 additions and 59 deletions

View File

@ -1016,28 +1016,26 @@ export default class Tokenizer extends ParserErrors {
const code = this.input.charCodeAt(this.state.pos); const code = this.input.charCodeAt(this.state.pos);
let val; let val;
if (this.hasPlugin("numericSeparator")) { if (code === charCodes.underscore) {
if (code === charCodes.underscore) { const prev = this.input.charCodeAt(this.state.pos - 1);
const prev = this.input.charCodeAt(this.state.pos - 1); const next = this.input.charCodeAt(this.state.pos + 1);
const next = this.input.charCodeAt(this.state.pos + 1); if (allowedSiblings.indexOf(next) === -1) {
if (allowedSiblings.indexOf(next) === -1) { this.raise(this.state.pos, Errors.UnexpectedNumericSeparator);
this.raise(this.state.pos, Errors.UnexpectedNumericSeparator); } else if (
} else if ( forbiddenSiblings.indexOf(prev) > -1 ||
forbiddenSiblings.indexOf(prev) > -1 || forbiddenSiblings.indexOf(next) > -1 ||
forbiddenSiblings.indexOf(next) > -1 || Number.isNaN(next)
Number.isNaN(next) ) {
) { this.raise(this.state.pos, Errors.UnexpectedNumericSeparator);
this.raise(this.state.pos, Errors.UnexpectedNumericSeparator);
}
if (!allowNumSeparator) {
this.raise(this.state.pos, Errors.NumericSeparatorInEscapeSequence);
}
// Ignore this _ character
++this.state.pos;
continue;
} }
if (!allowNumSeparator) {
this.raise(this.state.pos, Errors.NumericSeparatorInEscapeSequence);
}
// Ignore this _ character
++this.state.pos;
continue;
} }
if (code >= charCodes.lowercaseA) { if (code >= charCodes.lowercaseA) {
@ -1088,10 +1086,6 @@ export default class Tokenizer extends ParserErrors {
} }
const next = this.input.charCodeAt(this.state.pos); const next = this.input.charCodeAt(this.state.pos);
if (next === charCodes.underscore) {
this.expectPlugin("numericSeparator", this.state.pos);
}
if (next === charCodes.lowercaseN) { if (next === charCodes.lowercaseN) {
++this.state.pos; ++this.state.pos;
isBigInt = true; isBigInt = true;
@ -1133,7 +1127,7 @@ export default class Tokenizer extends ParserErrors {
const integer = this.input.slice(start, this.state.pos); const integer = this.input.slice(start, this.state.pos);
if (this.state.strict) { if (this.state.strict) {
this.raise(start, Errors.StrictOctalLiteral); this.raise(start, Errors.StrictOctalLiteral);
} else if (this.hasPlugin("numericSeparator")) { } else {
// disallow numeric separators in non octal decimals and legacy octal likes // disallow numeric separators in non octal decimals and legacy octal likes
const underscorePos = integer.indexOf("_"); const underscorePos = integer.indexOf("_");
if (underscorePos > 0) { if (underscorePos > 0) {
@ -1165,10 +1159,6 @@ export default class Tokenizer extends ParserErrors {
next = this.input.charCodeAt(this.state.pos); next = this.input.charCodeAt(this.state.pos);
} }
if (next === charCodes.underscore) {
this.expectPlugin("numericSeparator", this.state.pos);
}
if (next === charCodes.lowercaseN) { if (next === charCodes.lowercaseN) {
// disallow floats, legacy octal syntax and non octal decimals // disallow floats, legacy octal syntax and non octal decimals
// new style octal ("0o") is handled in this.readRadixNumber // new style octal ("0o") is handled in this.readRadixNumber

Some files were not shown because too many files have changed in this diff Show More