[parser] Better error message for missing number exponent (#12072)

* fix(babel-parser) better error message for missing number exponent after 'e'

* fix(babel-parser) requested changes

* msg

Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
iamfotx 2020-10-15 00:17:38 +05:00 committed by GitHub
parent f697e7995d
commit 59d97d9bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 7 deletions

View File

@ -77,6 +77,8 @@ export const ErrorMessages = Object.freeze({
InvalidLhs: "Invalid left-hand side in %0", InvalidLhs: "Invalid left-hand side in %0",
InvalidLhsBinding: "Binding invalid left-hand side in %0", InvalidLhsBinding: "Binding invalid left-hand side in %0",
InvalidNumber: "Invalid number", InvalidNumber: "Invalid number",
InvalidOrMissingExponent:
"Floating-point numbers require a valid exponent after the 'e'",
InvalidOrUnexpectedToken: "Unexpected character '%0'", InvalidOrUnexpectedToken: "Unexpected character '%0'",
InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern", InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern",
InvalidPrivateFieldResolution: "Private name #%0 is not defined", InvalidPrivateFieldResolution: "Private name #%0 is not defined",

View File

@ -1149,7 +1149,9 @@ export default class Tokenizer extends ParserErrors {
if (next === charCodes.plusSign || next === charCodes.dash) { if (next === charCodes.plusSign || next === charCodes.dash) {
++this.state.pos; ++this.state.pos;
} }
if (this.readInt(10) === null) this.raise(start, Errors.InvalidNumber); if (this.readInt(10) === null) {
this.raise(start, Errors.InvalidOrMissingExponent);
}
isFloat = true; isFloat = true;
hasExponent = true; hasExponent = true;
next = this.input.charCodeAt(this.state.pos); next = this.input.charCodeAt(this.state.pos);

View File

@ -2,7 +2,7 @@
"type": "File", "type": "File",
"start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}, "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}},
"errors": [ "errors": [
"SyntaxError: Invalid number (1:0)" "SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
], ],
"program": { "program": {
"type": "Program", "type": "Program",

View File

@ -2,7 +2,7 @@
"type": "File", "type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, "start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [ "errors": [
"SyntaxError: Invalid number (1:0)" "SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
], ],
"program": { "program": {
"type": "Program", "type": "Program",

View File

@ -2,7 +2,7 @@
"type": "File", "type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, "start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [ "errors": [
"SyntaxError: Invalid number (1:0)" "SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
], ],
"program": { "program": {
"type": "Program", "type": "Program",

View File

@ -2,7 +2,7 @@
"type": "File", "type": "File",
"start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}, "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}},
"errors": [ "errors": [
"SyntaxError: Invalid number (1:0)" "SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
], ],
"program": { "program": {
"type": "Program", "type": "Program",

View File

@ -2,7 +2,7 @@
"type": "File", "type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, "start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [ "errors": [
"SyntaxError: Invalid number (1:0)" "SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
], ],
"program": { "program": {
"type": "Program", "type": "Program",

View File

@ -2,7 +2,7 @@
"type": "File", "type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}}, "start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [ "errors": [
"SyntaxError: Invalid number (1:0)" "SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
], ],
"program": { "program": {
"type": "Program", "type": "Program",