babel / babel/minify

comparisons-flip-minify-plugin-babel flips too much 🐛

Open
#868 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

babel-plugin-minify-flip-comparisons flips some things that shouldn't be flipped.

**To Reproduce**

```js
let nine = () => 9;
let six = () => (nine = () => 7, 6);
console.log([nine()]*[six()]);
```

**Actual Output**

```js
let nine=()=>9,six=()=>(nine=()=>7,6);console.log([six()]*[nine()]);
//42
```

**Expected Output**

```js
let nine=()=>9,six=()=>(nine=()=>7,6);console.log([nine()]*[six()]);
//54
```

**Additional context**

Can't currently think of any reasons why serious code would do anything like this, but reporting anyway.

An array or object literal shouldn't be treated as pure, unless its contents are pure.

Also, `42*(x/y)` and `42*(x%y)` should probably be flipped to `x/y*42` and `x%y*42`, instead of the other way around, to save the `()`.

Contributor guide

Open the contributing guide

Research direction

Start with the babel-plugin-minify-flip-comparisons entry point and run the JavaScript reproduction from the issue. Compare the minified output and runtime result with the expected output, especially around array or object literals whose contents may be impure. Done means the example preserves evaluation order and no longer produces 42.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.