babel / babel/minify

Incorrect code with jQuery functionality

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

Description

A function defined in jQuery sections is incorrectly optimized

**To Reproduce**

Minimal code to reproduce the bug

```
(function($) {
Math.gcd = function(x, y) {
return y === 0 ? x : Math.gcd(y, x % y);
};
})(typeof jQuery !== 'undefined' ? jQuery : {});

$(document).ready(function() {
var test = Math.gcd(170, 150);
console.log(test);
});
```

**Actual Output**

If there is no Error thrown,

```
(function() {
var a=Math.gcd;
a=function(b,c) {
return 0===c ? b : a (c,b%c)
}
}) ("undefined"==typeof jQuery ? { } : jQuery)

$(document).ready(function() {
var a=Math.gcd(170,150);
console.log(a)
}
);
```

**Expected Output**

```
(function($) {
Math.gcd=function(b,c) {
return 0===c ? b : Math.gcd(c,b%c)
}
}) ("undefined"==typeof jQuery ? { } : jQuery)

$(document).ready(function() {
var a=Math.gcd(170,150);
console.log(a)
}
);
```
**Configuration**

How are you using babel-minify?

`babel-minify CLI`

babel-minify version: `0.4.3`

babel version : `7.0.0-beta.46`

babel-minify-config:

Default

Contributor guide

Open the contributing guide

Research direction

Reproduce the supplied snippet with the babel-minify CLI using babel-minify 0.4.3 and Babel 7.0.0-beta.46, then trace the optimization that changes the jQuery-wrapped Math.gcd definition. Done means the minified output preserves the expected Math.gcd behavior and the reproduction is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, jquery
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.