Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: minify infinity in expressions #841

Merged
merged 3 commits into from May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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