* Fix workflow * Trigger * [auto] Update compiled version * [auto] Commit modules * Push Windows changes * Fix * [auto] Update compiled version * Try removing cwd * [auto] Update compiled version * Try with path module * [auto] Update compiled version * Fix path * [auto] Update compiled version * Use raw path * [auto] Update compiled version * Other path * [auto] Update compiled version * Avoid @action/exec * [auto] Update compiled version * test * [auto] Update compiled version * test * [auto] Update compiled version * test * [auto] Update compiled version * test * [auto] Update compiled version * Try with shelljs * [auto] Update compiled version * Fix my stupidity * Copy scripts to local dir * [auto] Update compiled version * Still use path * [auto] Update compiled version * Delete entrypoint.sh * [auto] Update compiled version * Make file executable * [auto] Update compiled version * Try using bash * [auto] Update compiled version
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
path.replaceWith(INFINITY);
|
|
}
|
|
|
|
}
|
|
};
|
|
}; |