[Bug]: Filename does not appear in SyntaxErrors when using Node < 16.9.0
- Dominant language
- TypeScript
- Stars
- 44k
- Forks
- 6k
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 23
Description
### 💻
- [ ] Would you like to work on a fix?
### How are you using Babel?
@babel/node
### Input code
https://github.com/codebling/babel-issue-example contains a minimal reproducible example, along with instructions and expected and actual results. Key points of the README are copied here:
```
git clone https://github.com/codebling/babel-issue-example.git
cd babel-issue-example
nvm use 16.8 # or any version between 12 and 16.8, possibly even earlier versions
npm i
npm start # or: ./node_modules/.bin/babel-node index.js
```
### Configuration file name
package.json
### Configuration
_No response_
### Current and expected behavior
## Expected Result
Using Node 16.9.0 or later, the problematic file name and lines are logged.
```
SyntaxError: /tmp/babel-issue-example/index.js: Legacy octal literals are not allowed in strict mode. (1:4)
> 1 | a = 01;
| ^
2 |
at Parser._raise (/tmp/babel-issue-example/node_modules/@babel/parser/lib/index.js:569:17
```
## Actual Result
Using Node 16.8 or earlier, we don't see the file name (though the line numbers still appear).
```
SyntaxError: Legacy octal literals are not allowed in strict mode. (1:4)
at Parser._raise (/tmp/babel-issue-example/node_modules/@babel/parser/lib/index.js:569:17)
```
### Environment
- Babel version: ^7.16
- Node version: <= 16.8 (works in >= 16.9.0)
- OS: linux or Mac
### Possible solution
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Clone the linked babel-issue-example, follow its README commands with Node 16.8 and then 16.9 to reproduce the differing SyntaxError output. Start from the @babel/node entry point and package.json configuration, then trace how the parser error is displayed. Done means the filename and source location appear for the affected Node versions, with the relevant tests passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100