babel / babel/minify

broken minified code: v + "" == "x";

Open
#886 1 comment 0 reactions 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**
There is a bug in the minification of the following code.

**To Reproduce**
[babel try it out](https://babeljs.io/repl/#?babili=true&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABBOBbADgQwE4FMAUAbgJSIDeAUIonlCNkoYgNSIBEbiAvF-wB5sA3BQC-QA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&sourceType=module&lineWrap=true&presets=es2017%2Creact%2Cbabili&prettier=true&targets=&version=6.26.0&envVersion=)

**input**
```js
function compare(v) {
return v + "" == "x";
}
compare(4) // false
compare('a') // false
```

**Actual Output**

```js
function compare(a) {
return a + "x";
}
compare(4) // '4x'
compare('a') // 'ax'
```

**Expected Output**
don't minify this case

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue in the linked Babel REPL with the provided compare function, then trace the minification transform that rewrites the string comparison. Done means the minifier preserves the comparison's behavior for the shown numeric and string inputs and a regression test covers this case.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.