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: Make babel-plugin-minify-infinity work again. (#839) #840

Closed
wants to merge 1 commit into from
Closed
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
@@ -1,3 +1,4 @@
function a(Infinity) {}
function b(...Infinity) {}
function c({ Infinity }) {}
function d([Infinity]) {}
Expand Up @@ -4,4 +4,6 @@ function b(...Infinity) {}

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

function d([Infinity]) {}
@@ -1 +1,8 @@
Infinity;
[Infinity];
let infobj = {inf: Infinity};
func(Infinity);
1/Infinity;
let inf = Infinity;
while (Infinity) break;
inf = Infinity;
@@ -1 +1,12 @@
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;

inf = 1 / 0;
12 changes: 11 additions & 1 deletion packages/babel-plugin-minify-infinity/src/index.js
Expand Up @@ -6,11 +6,18 @@ module.exports = function({ types: t }) {
t.numericLiteral(1),
t.numericLiteral(0)
);
const badTransforms = {
ArrayPattern: () => true,
AssignmentExpression: path => path.container.left === path.node,
ObjectProperty: path => path.container.shorthand,
RestElement: () => true
};
return {
name: "minify-infinity",
visitor: {
// Infinity -> 1 / 0
Identifier(path) {
path.isLVal();
if (path.node.name !== "Infinity") {
return;
}
Expand All @@ -28,7 +35,10 @@ module.exports = function({ types: t }) {
return;
}

if (path.isLVal() && !path.parentPath.isExpressionStatement()) {
if (
path.isLVal() &&
(badTransforms[path.parentPath.type] || (() => false))(path)
) {
return;
}

Expand Down