Skip to content

[Bug]: Incorrect MissingSemicolon SyntaxError when errorRecovery is false, but correct InvalidDigit SyntaxError when errorRecovery is true #14146

@tolmasky

Description

@tolmasky

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

Another error I ran into while fixing #14123, and the fix for that will include a fix for this too. Compare the following runs of the parser, one with errorRecovery set to false, the other to true:

require("@babel/parser").parse("0b111199", { errorRecovery: true }).errors
require("@babel/parser").parse("0b111199", { errorRecovery: false })

See it here: https://runkit.com/tolmasky/incorrect-missingsemicolon-syntaxerror-when-errorrecover-set-to-false

You'll see the first gives you the error you expect: Expected number in radix 2. (1:6), while the second gives you an erroneous error of Missing semicolon. (1:6).

Configuration file name

No response

Configuration

No response

Current and expected behavior

Explained above.

Environment

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions