Skip to content

Commit

Permalink
Merge pull request #1032 from JLHwung/fix-1028
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo authored May 6, 2022
2 parents f051377 + 335cb88 commit 6d0227e
Show file tree
Hide file tree
Showing 12 changed files with 1,053 additions and 805 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"watch": "gulp watch"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-transform-block-scoping": "^7.8.3",
"@babel/preset-env": "^7.9.0",
"@babel/core": "^7.17.0",
"@babel/plugin-transform-block-scoping": "^7.16.7",
"@babel/preset-env": "^7.17.10",
"babel-jest": "^24.9.0",
"butternut": "^0.4.6",
"bytes": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ function foo() {
set a(b) {}

};

class A {
return new class {
set c(d) {
x.a = 5;
}

}

return new A();
}();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Foo {
get all() {
return false;
}
constructor() {
var _this = this;
(function () {
return _this.all != null;
}).call(document);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Foo {
get all() {
return false;
}

constructor() {
var _this = this;

(function () {
return _this.all != null;
}).call(document);
}

}
13 changes: 10 additions & 3 deletions packages/babel-plugin-minify-dead-code-elimination/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,29 @@ module.exports = ({ types: t, traverse }) => {
refPath.scope.getBinding(replacement.name) === binding &&
binding.constantViolations.length === 0
);
} else if (replacementPath.isThisExpression()) {
bail = true;
} else {
replacementPath.traverse({
Function(path) {
path.skip();
},

ThisExpression(path) {
bail = true;
path.stop();
},

ReferencedIdentifier({ node }) {
if (bail) {
return;
}
const binding = scope.getBinding(node.name);
if (
binding &&
refPath.scope.getBinding(node.name) === binding
) {
bail = binding.constantViolations.length > 0;
if (bail) {
path.stop();
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
!function () {
var b = 1;
b--;
var b = 10;
a(b);
var a = 1;
a--;
var a = 10;
b(a);

function a() {
function b() {
var a = 10;
a++;
var a = 20;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
function d3_svg_line(a) {
var c = d3_geom_pointX,
d = d3_geom_pointY,
var b = d3_geom_pointX,
c = d3_geom_pointY,
e = d3_true,
f = d3_svg_lineLinear,
g = f.key,
h = 0.7;

function b(b) {
var j = [],
k = [],
l = -1,
m = b.length,
n,
o = d3_functor(c);
function i(c) {
var g = [],
j = [],
k = -1,
l = c.length,
m,
n = d3_functor(b);

function g() {
j.push("M", f(a(k), h));
function o() {
g.push("M", f(a(j), h));
}

while (++l < m) {
if (e.call(this, n = b[l], l)) {
k.push([+o.call(this, n, l)]);
} else if (k.length) {
g();
k = [];
while (++k < l) {
if (e.call(this, m = c[k], k)) {
j.push([+n.call(this, m, k)]);
} else if (j.length) {
o();
j = [];
}
}

if (k.length) g();
return j.length ? j.join("") : null;
if (j.length) o();
return g.length ? g.join("") : null;
}

return b;
return i;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
(function () {
class Foo {}

const b = class Bar extends Foo {};
var c = class Baz {};
const a = class Bar extends Foo {};
var b = class Baz {};

function a() {
new c();
function c() {
new b();
}

a();
c();
})();
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
function Foo() {
var ba, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
var aa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y;
var Z, $;
ba, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
aa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y;
Z, $;

function aa() {
var aa, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
function _() {
var h, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y;
var Z, $;
aa, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
h, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y;
Z, $;

function h() {
function _() {
var aa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y;
var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y;
var Z, $;
Expand All @@ -23,8 +23,8 @@ function Foo() {
Z, $;
}

h();
_();
}

aa();
_();
}
28 changes: 21 additions & 7 deletions packages/babel-preset-minify/__tests__/minify-env-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ describe("preset along with env", () => {
}
`,
`
function _defineProperties(a, b) { for (var c, d = 0; d < b.length; d++) c = b[d], c.enumerable = c.enumerable || !1, c.configurable = !0, "value" in c && (c.writable = !0), Object.defineProperty(a, c.key, c); }
function _createClass(a, b, c) { return b && _defineProperties(a.prototype, b), c && _defineProperties(a, c), Object.defineProperty(a, "prototype", { writable: !1 }), a; }
function _classCallCheck(a, b) { if (!(a instanceof b)) throw new TypeError("Cannot call a class as a function"); }
function a() {
return function a() {
var a = /*#__PURE__*/_createClass(function a() {
"use strict";
_classCallCheck(this, a);
};
});
return a;
}
`
);
Expand Down Expand Up @@ -237,16 +243,20 @@ describe("preset along with env", () => {
}
`,
`
function _defineProperties(a, b) { for (var c, d = 0; d < b.length; d++) c = b[d], c.enumerable = c.enumerable || !1, c.configurable = !0, "value" in c && (c.writable = !0), Object.defineProperty(a, c.key, c); }
function _createClass(a, b, c) { return b && _defineProperties(a.prototype, b), c && _defineProperties(a, c), Object.defineProperty(a, "prototype", { writable: !1 }), a; }
function _classCallCheck(a, b) { if (!(a instanceof b)) throw new TypeError("Cannot call a class as a function"); }
function bar() {
var c = console;
return {
a: function b(a) {
a: /*#__PURE__*/_createClass(function d(b) {
"use strict";
_classCallCheck(this, b), c.log(a);
}
_classCallCheck(this, d), c.log(b);
})
};
}
`
Expand All @@ -261,13 +271,17 @@ describe("preset along with env", () => {
exports.A = A;
`,
`
function _defineProperties(a, b) { for (var c, d = 0; d < b.length; d++) c = b[d], c.enumerable = c.enumerable || !1, c.configurable = !0, "value" in c && (c.writable = !0), Object.defineProperty(a, c.key, c); }
function _createClass(a, b, c) { return b && _defineProperties(a.prototype, b), c && _defineProperties(a, c), Object.defineProperty(a, "prototype", { writable: !1 }), a; }
function _classCallCheck(a, b) { if (!(a instanceof b)) throw new TypeError("Cannot call a class as a function"); }
var A = function a() {
var A = /*#__PURE__*/_createClass(function a() {
"use strict";
_classCallCheck(this, a);
};
});
A.B = {}, exports.A = A;
`
Expand Down
2 changes: 1 addition & 1 deletion utils/test-runner/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function testRunner(dir) {
.filter(dir => fs.isDirectorySync(pathJoin(fixturesDir, dir)));

const flags = parseArgs(process.argv);
const updateFixtures = Boolean(flags["update-fixtures"]);
const updateFixtures = !!process.env.OVERWRITE || Boolean(flags["update-fixtures"]);

describe(pkgName, () => {
for (const fixture of fixtures) {
Expand Down
Loading

0 comments on commit 6d0227e

Please sign in to comment.