Skip to content
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

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

Merged
merged 3 commits into from Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/babel-parser/src/parser/error-message.js
Expand Up @@ -71,6 +71,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:
"Invalid or missing exponent after 'e' in floating-point number",
InvalidOrUnexpectedToken: "Unexpected character '%0'",
InvalidParenthesizedAssignment: "Invalid parenthesized assignment pattern",
InvalidPrivateFieldResolution: "Private name #%0 is not defined",
Expand Down
5 changes: 3 additions & 2 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -1033,7 +1033,6 @@ export default class Tokenizer extends ParserErrors {
++this.state.pos;
continue;
}

if (code >= charCodes.lowercaseA) {
val = code - charCodes.lowercaseA + charCodes.lineFeed;
} else if (code >= charCodes.uppercaseA) {
Expand Down Expand Up @@ -1149,7 +1148,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: Invalid or missing exponent after 'e' in floating-point number (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: Invalid or missing exponent after 'e' in floating-point number (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: Invalid or missing exponent after 'e' in floating-point number (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: Invalid or missing exponent after 'e' in floating-point number (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: Invalid or missing exponent after 'e' in floating-point number (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: Invalid or missing exponent after 'e' in floating-point number (1:0)"
],
"program": {
"type": "Program",
Expand Down