Skip to content

[Bug]: expectContextual drops token information and throws generic "unexpected token" error. #14144

@tolmasky

Description

@tolmasky

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

I ran into this while fixing #14123, and the fix for that will include a fix for this too. If you try the following code:

require("@babel/parser").parse("import * from 'pizza'", { sourceType: "module" });

See it here: https://runkit.com/tolmasky/expectcontextual-drops-token-information

You'll get SyntaxError: Unexpected token (1:9), despite the code having enough information to say "Unexpected token, expect "as"", and in fact it appears like it was originally designed to do so. However, this information is lost between the conversion from expectContextual and unexpected.

Configuration file name

No response

Configuration

No response

Current and expected behavior

Should say something like "Unexpected token, expect "as"",

Environment

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions