Skip to content

Commit

Permalink
fix: Make babel-plugin-minify-infinity work again. (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyp committed May 14, 2018
1 parent 9939bca commit 73eec1d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
function a(Infinity) {}
function b(...Infinity) {}
function c({ Infinity }) {}
function d([Infinity]) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ function b(...Infinity) {}

function c({
Infinity
}) {}
}) {}

function d([Infinity]) {}
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
Infinity;
[Infinity];
let infobj = {inf: Infinity};
func(Infinity);
1/Infinity;
let inf = Infinity;
while (Infinity) break;
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
1 / 0;
1 / 0;
[1 / 0];
let infobj = {
inf: 1 / 0
};
func(1 / 0);
1 / (1 / 0);
let inf = 1 / 0;

while (1 / 0) break;
8 changes: 7 additions & 1 deletion packages/babel-plugin-minify-infinity/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ module.exports = function({ types: t }) {
t.numericLiteral(1),
t.numericLiteral(0)
);
const badTransforms = {
ArrayPattern: true,
AssignmentExpression: true,
//ObjectProperty: bad if path.container.shorthand is true,
RestElement: true
};
return {
name: "minify-infinity",
visitor: {
Expand All @@ -28,7 +34,7 @@ module.exports = function({ types: t }) {
return;
}

if (path.isLVal() && !path.parentPath.isExpressionStatement()) {
if (path.isLVal() && (badTransforms[path.parentPath.type] || path.container.shorthand)) {
return;
}

Expand Down

0 comments on commit 73eec1d

Please sign in to comment.