Skip to content

Commit

Permalink
[parser] Better error message for missing number exponent (#12072)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
iamfotx and existentialism committed Oct 14, 2020
1 parent f697e79 commit 59d97d9
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/babel-parser/src/parser/error-message.js
Expand Up @@ -77,6 +77,8 @@ export const ErrorMessages = Object.freeze({
InvalidLhs: "Invalid left-hand side in %0",
InvalidLhsBinding: "Binding invalid left-hand side in %0",
InvalidNumber: "Invalid number",
InvalidOrMissingExponent:
"Floating-point numbers require a valid exponent after the 'e'",
InvalidOrUnexpectedToken: "Unexpected character '%0'",
InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern",
InvalidPrivateFieldResolution: "Private name #%0 is not defined",
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -1149,7 +1149,9 @@ export default class Tokenizer extends ParserErrors {
if (next === charCodes.plusSign || next === charCodes.dash) {
++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;
hasExponent = true;
next = this.input.charCodeAt(this.state.pos);
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}},
"errors": [
"SyntaxError: Invalid number (1:0)"
"SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [
"SyntaxError: Invalid number (1:0)"
"SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [
"SyntaxError: Invalid number (1:0)"
"SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}},
"errors": [
"SyntaxError: Invalid number (1:0)"
"SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [
"SyntaxError: Invalid number (1:0)"
"SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
"errors": [
"SyntaxError: Invalid number (1:0)"
"SyntaxError: Floating-point numbers require a valid exponent after the 'e' (1:0)"
],
"program": {
"type": "Program",
Expand Down

0 comments on commit 59d97d9

Please sign in to comment.