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 1 commit
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Could you just make this lowercase? (don't use GH's "Apply changes" button because you need to regenerate the tests locally)

Suggested change
"Invalid or Missing exponent after 'e' in floating-point number",
"Invalid or missing exponent after 'e' in floating-point number",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe just delete "Invalid or", I don't have a preference in either direction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we can drop "Invalid or" or:

"Floating-point numbers require a valid exponent after the 'e'."

Copy link
Contributor Author

@iamfotx iamfotx Sep 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo , what do you think if I work around and throw accordingly by figuring out if it is actually missing or invalid?

For example: 3ea would also throw with the same error message. I would consider, it (3ea) is invalid, that's why I used "invalid"...

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