-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Bug]: expectContextual drops token information and throws generic "unexpected token" error. #14144
Copy link
Copy link
Closed
Labels
i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
💻
- 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
- Babel version: 7.16.8
- https://runkit.com/tolmasky/expectcontextual-drops-token-information
Possible solution
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue