Skip to content

Commit

Permalink
fix: minify infinity in expressions (#841)
Browse files Browse the repository at this point in the history
* fix: minify infinity in expressions

* fix object expressions transformations

* address review comments
  • Loading branch information
boopathi authored and vigneshshanmugam committed May 14, 2018
1 parent 9939bca commit 18dcfe1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
@@ -0,0 +1,12 @@
function foo() {
let [Infinity] = some();
return Infinity;
}

function bar() {
let [...Infinity] = some();
}

function baz() {
let { inf = Infinity } = some();
}
@@ -0,0 +1,14 @@
function foo() {
let [Infinity] = some();
return Infinity;
}

function bar() {
let [...Infinity] = some();
}

function baz() {
let {
inf = 1 / 0
} = some();
}
@@ -0,0 +1,10 @@
let x = [Infinity, Infinity];

let y = [
{
a: Infinity
},
{
a: Infinity
}
];
@@ -0,0 +1,6 @@
let x = [1 / 0, 1 / 0];
let y = [{
a: 1 / 0
}, {
a: 1 / 0
}];
9 changes: 8 additions & 1 deletion packages/babel-plugin-minify-infinity/src/index.js
Expand Up @@ -28,7 +28,14 @@ module.exports = function({ types: t }) {
return;
}

if (path.isLVal() && !path.parentPath.isExpressionStatement()) {
const bindingIds = path.parentPath.getBindingIdentifierPaths();

if (
bindingIds["Infinity"] === path &&
// ObjectProperty is common for ObjectExpression and ObjectPattern and only
// one of them is a Binding, the other is simply a reference
!path.parentPath.parentPath.isObjectExpression()
) {
return;
}

Expand Down

0 comments on commit 18dcfe1

Please sign in to comment.