mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 04:10:04 +02:00
40 lines
794 B
JavaScript
40 lines
794 B
JavaScript
"use strict";
|
|
|
|
module.exports = function ({
|
|
types: t
|
|
}) {
|
|
const INFINITY = t.binaryExpression("/", t.numericLiteral(1), t.numericLiteral(0));
|
|
return {
|
|
name: "minify-infinity",
|
|
visitor: {
|
|
// Infinity -> 1 / 0
|
|
Identifier(path) {
|
|
if (path.node.name !== "Infinity") {
|
|
return;
|
|
} // It's a referenced identifier
|
|
|
|
|
|
if (path.scope.getBinding("Infinity")) {
|
|
return;
|
|
}
|
|
|
|
if (path.parentPath.isObjectProperty({
|
|
key: path.node
|
|
})) {
|
|
return;
|
|
}
|
|
|
|
if (path.parentPath.isMemberExpression()) {
|
|
return;
|
|
}
|
|
|
|
if (path.isLVal() && !path.parentPath.isExpressionStatement()) {
|
|
return;
|
|
}
|
|
|
|
path.replaceWith(INFINITY);
|
|
}
|
|
|
|
}
|
|
};
|
|
}; |