babel / babel/babel

[Bug]: Wrong evaluation order when using spread in function argument

Open
#14,999 1 comment 0 reactions 0 assignees View on GitHub
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).

![Image](https://user-images.githubusercontent.com/68288688/193253938-da0beb40-90e4-4fb2-8d87-9df3056feea9.png)

```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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.