summaryrefslogtreecommitdiff
path: root/node_modules/babel-plugin-minify-infinity/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/babel-plugin-minify-infinity/lib')
-rw-r--r--node_modules/babel-plugin-minify-infinity/lib/index.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-minify-infinity/lib/index.js b/node_modules/babel-plugin-minify-infinity/lib/index.js
new file mode 100644
index 00000000..b4a87ad5
--- /dev/null
+++ b/node_modules/babel-plugin-minify-infinity/lib/index.js
@@ -0,0 +1,44 @@
+"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);
+ }
+
+ }
+ };
+}; \ No newline at end of file