diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-08-30 17:21:18 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-08-30 17:21:18 +0800 |
| commit | efbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch) | |
| tree | 2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/babel-plugin-minify-infinity | |
| parent | 43acceb75957c880a5ba5a31aae221394a36d5f6 (diff) | |
node fixes, updates
Diffstat (limited to 'node_modules/babel-plugin-minify-infinity')
| -rw-r--r-- | node_modules/babel-plugin-minify-infinity/README.md | 47 | ||||
| -rw-r--r-- | node_modules/babel-plugin-minify-infinity/lib/index.js | 44 | ||||
| -rw-r--r-- | node_modules/babel-plugin-minify-infinity/package.json | 14 |
3 files changed, 105 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-minify-infinity/README.md b/node_modules/babel-plugin-minify-infinity/README.md new file mode 100644 index 00000000..91c6ad84 --- /dev/null +++ b/node_modules/babel-plugin-minify-infinity/README.md @@ -0,0 +1,47 @@ +# babel-plugin-minify-infinity + +## Example + +**In** + +```javascript +Infinity; +``` + +**Out** + +```javascript +1 / 0; +``` + +## Installation + +```sh +npm install babel-plugin-minify-infinity --save-dev +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["minify-infinity"] +} +``` + +### Via CLI + +```sh +babel --plugins minify-infinity script.js +``` + +### Via Node API + +```javascript +require("@babel/core").transform("code", { + plugins: ["minify-infinity"] +}); +``` 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 diff --git a/node_modules/babel-plugin-minify-infinity/package.json b/node_modules/babel-plugin-minify-infinity/package.json new file mode 100644 index 00000000..2aae6c0c --- /dev/null +++ b/node_modules/babel-plugin-minify-infinity/package.json @@ -0,0 +1,14 @@ +{ + "name": "babel-plugin-minify-infinity", + "version": "0.4.3", + "description": "", + "keywords": [ + "babel-plugin" + ], + "homepage": "https://github.com/babel/minify#readme", + "bugs": "https://github.com/babel/minify/issues", + "license": "MIT", + "author": "amasad", + "main": "lib/index.js", + "repository": "https://github.com/babel/minify/tree/master/packages/babel-plugin-minify-infinity" +} |
