[Bug]: Order between TDZ errors and other errors
- 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/cli
### Input code
```js
let x = { x = 0 ( ) } = 0 ;
```
### Configuration file name
.babelrc
### Configuration
```json
{
"plugins": [
[
"@babel/plugin-transform-block-scoping",
{
"tdz": true
}
]
]
}
```
### Current and expected behavior
Input code is expected to throw `TypeError`:
```console
$ node input.js
input.js:1
let x = { x = 0 ( ) } = 0 ;
^
TypeError: 0 is not a function
at Object. (input.js:1:17)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Node.js v18.11.0
```
but output code is transpiled as following:
```js
function _tdz(name) { throw new ReferenceError(name + " is not defined - temporal dead zone"); }
var x = (_tdz("x"), ({
x = 0()
} = 0));
```
and is throwing `ReferenceError` due to `_tdz` function:
```console
$ npx babel input.js | node
[stdin]:1
function _tdz(name) { throw new ReferenceError(name + " is not defined - temporal dead zone"); }
^
ReferenceError: x is not defined - temporal dead zone
at _tdz ([stdin]:1:29)
at [stdin]:2:10
at Script.runInThisContext (node:vm:129:12)
at Object.runInThisContext (node:vm:313:38)
at node:internal/process/execution:79:19
at [stdin]-wrapper:6:22
at evalScript (node:internal/process/execution:78:60)
at node:internal/main/eval_stdin:30:5
at Socket. (node:internal/process/execution:195:5)
at Socket.emit (node:events:525:35)
Node.js v18.11.0
```
### Environment
Babel version: 7.20.2
Node: v18.11.0
npm version: 8.19.2
OS: macos 13.0
### Possible solution
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start with the minimal JavaScript input and the .babelrc configuration using @babel/plugin-transform-block-scoping with tdz enabled, then run it through @babel/cli. Compare the transformed program's error ordering with Node's native result; done means the transformed input raises the expected TypeError instead of the TDZ ReferenceError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100