diff --git a/packages/babel-parser/src/parser/error-message.js b/packages/babel-parser/src/parser/error-message.js index 90c0b1025e0f..a9d609930b1d 100644 --- a/packages/babel-parser/src/parser/error-message.js +++ b/packages/babel-parser/src/parser/error-message.js @@ -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", diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index cbc0efab0fe8..573db84a3273 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -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); diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/349/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/349/output.json index b2d2e40318a4..6afcaf3f5045 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/349/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/349/output.json @@ -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", diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/350/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/350/output.json index 1591ec979e44..34027472096c 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/350/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/350/output.json @@ -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", diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/351/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/351/output.json index 42c6c5a67aff..666fcca21213 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/351/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/351/output.json @@ -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", diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0004/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0004/output.json index b2d2e40318a4..6afcaf3f5045 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0004/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0004/output.json @@ -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", diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0005/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0005/output.json index 1591ec979e44..34027472096c 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0005/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0005/output.json @@ -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", diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0006/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0006/output.json index 42c6c5a67aff..666fcca21213 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0006/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0006/output.json @@ -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",