[Bug]: Wrong evaluation order when using spread in function argument
- 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?
Other (Next.js, Gatsby, vue-cli, ...)
### Input code
```js
null ( 0 , ... x ) ;
```
### Configuration file name
_No response_
### Configuration
_No response_
### Current and expected behavior
`ReferenceError` is expected (in step 3) in the input program but the transpiled program throws `TypeError` (in step 5).

```console
❯ node
Welcome to Node.js v18.10.0.
Type ".help" for more information.
> null ( 0 , ... x ) ;
Uncaught ReferenceError: x is not defined
```
### Environment
[Reproductions on Babel's own REPL](https://babeljs.io/repl#?browsers=&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=HYVwNmAEAUAMA0kB0LIA8CUBuIA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=script&lineWrap=true&presets=env%2Creact%2Cstage-2&prettier=true&targets=&version=7.19.3&externalPlugins=&assumptions=%7B%7D)
### Possible solution
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Reproduce the input `null ( 0 , ... x ) ;` in Babel's REPL and compare its result with Node.js v18.10.0. Trace the generated evaluation order for the spread function argument; done means the transpiled program raises the expected ReferenceError rather than TypeError.
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