-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Show filename when parse fail #9509
base: main
Are you sure you want to change the base?
Conversation
clinyong
commented
Feb 14, 2019
•
edited by gitpod-io
bot
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | No |
Patch: Bug Fix? | No |
Major: Breaking Change? | No |
Minor: New Feature? | No |
Tests Added + Pass? | Yes |
Documentation PR Link | No |
Any Dependency Changes? | No |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/55306/ |
Can you show a before/after comparison? |
@nicolo-ribaudo I think that means we have no tests for it. |
@nicolo-ribaudo An small reproducible example const babelParser = require('@babel/parser')
babelParser.parse('const t: any = null')
// with filename
// babelParser.parse('const t: any = null', {sourceFilename: 'path/to/input-file.js'}) before
after (same with before)
after with filename - SyntaxError: Unexpected token (1:7)
+ SyntaxError: Unexpected token (path/to/input-file.js:1:7)
at Parser.raise (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:3833:17)
at Parser.unexpected (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:5145:16)
at Parser.parseVar (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:7888:18)
at Parser.parseVarStatement (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:7713:10)
at Parser.parseStatementContent (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:7309:21)
at Parser.parseStatement (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:7250:17)
at Parser.parseBlockOrModuleBlockBody (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:7814:25)
at Parser.parseBlockBody (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:7801:10)
at Parser.parseTopLevel (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:7183:10)
at Parser.parse (/Users/Leo/workfile/ts-demo/node_modules/@babel/parser/lib/index.js:8662:17) @xtuc test case is added. |
Babel itself already does this in
|
@loganfsmyth Can we remove the |
The issue is that users on older versions of If we make this change, it'd probably need to be toggled with an off-by-default option. |
@loganfsmyth You are right. And should we make this change? I means is it better to show fail filename here. If it is, I can add the option to |
This seems nice to have, so that I get proper @JLHwung @liuxingbaoyu Given #9509 (comment), wdyt about doing this for Babel 8? |
CI failure should be fixed by #15884. |