{"_id":"babel-plugin-transform-replace-expressions","_rev":"2882915","name":"babel-plugin-transform-replace-expressions","description":"Replace JavaScript expressions with other expressions","dist-tags":{"latest":"0.2.0"},"maintainers":[{"name":"jviide","email":""},{"name":"npm:jviide","email":""}],"time":{"modified":"2022-10-06T07:34:20.000Z","created":"2019-02-24T00:46:00.556Z","0.2.0":"2019-03-11T23:23:51.995Z","0.1.1":"2019-02-24T21:14:19.438Z","0.1.0":"2019-02-24T18:27:59.360Z","0.0.3":"2019-02-24T03:32:00.033Z","0.0.2":"2019-02-24T02:35:34.713Z","0.0.1":"2019-02-24T00:46:00.556Z"},"users":{},"author":{"name":"Joachim Viide","email":"jviide@iki.fi"},"repository":{"type":"git","url":"https://github.com/jviide/babel-plugin-transform-replace-expressions.git"},"versions":{"0.2.0":{"name":"babel-plugin-transform-replace-expressions","version":"0.2.0","description":"Replace JavaScript expressions with other expressions","main":"index.js","license":"MIT","repository":{"type":"git","url":"https://github.com/jviide/babel-plugin-transform-replace-expressions.git"},"author":{"name":"Joachim Viide","email":"jviide@iki.fi"},"keywords":["babel-plugin"],"scripts":{"test":"mocha","lint":"eslint --max-warnings 0 --ignore-path .gitignore ."},"dependencies":{"@babel/parser":"^7.3.3"},"devDependencies":{"@babel/core":"^7.3.3","@babel/types":"^7.3.3","chai":"^4.2.0","eslint":"^5.14.1","eslint-config-prettier":"^4.0.0","eslint-plugin-prettier":"^3.0.1","mocha":"^6.0.1","prettier":"^1.16.4"},"peerDependencies":{"@babel/core":"^7.0.0-0"},"licenseText":"MIT License\n\nCopyright (c) 2019 Joachim Viide\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"babel-plugin-transform-replace-expressions@0.2.0","dist":{"shasum":"59cba8df4b4a675e7c78cd21548f8e7685bbc30d","size":2845,"noattachment":false,"key":"/babel-plugin-transform-replace-expressions/-/babel-plugin-transform-replace-expressions-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-replace-expressions/download/babel-plugin-transform-replace-expressions-0.2.0.tgz"},"maintainers":[{"name":"jviide","email":""},{"name":"npm:jviide","email":""}],"_npmUser":{"name":"jviide","email":"jviide@iki.fi"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-replace-expressions_0.2.0_1552346631812_0.8309376113408062"},"_hasShrinkwrap":false,"publish_time":1552346631995,"_cnpm_publish_time":1552346631995,"_cnpmcore_publish_time":"2021-12-16T20:08:59.536Z"},"0.1.1":{"name":"babel-plugin-transform-replace-expressions","version":"0.1.1","description":"Replace JavaScript expressions with other expressions","main":"index.js","license":"MIT","repository":{"type":"git","url":"https://github.com/jviide/babel-plugin-transform-replace-expressions.git"},"author":{"name":"Joachim Viide","email":"jviide@iki.fi"},"keywords":["babel-plugin"],"scripts":{"test":"mocha","lint":"eslint --max-warnings 0 --ignore-path .gitignore ."},"dependencies":{"@babel/parser":"^7.3.3"},"devDependencies":{"@babel/core":"^7.3.3","@babel/types":"^7.3.3","chai":"^4.2.0","eslint":"^5.14.1","eslint-config-prettier":"^4.0.0","eslint-plugin-prettier":"^3.0.1","mocha":"^6.0.1","prettier":"^1.16.4"},"peerDependencies":{"@babel/core":"^7.0.0-0"},"licenseText":"MIT License\n\nCopyright (c) 2019 Joachim Viide\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"babel-plugin-transform-replace-expressions@0.1.1","dist":{"shasum":"b1918de6c53fa0d9eaf48e5bf103b6ad5d485c81","size":2251,"noattachment":false,"key":"/babel-plugin-transform-replace-expressions/-/babel-plugin-transform-replace-expressions-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-replace-expressions/download/babel-plugin-transform-replace-expressions-0.1.1.tgz"},"maintainers":[{"name":"jviide","email":""},{"name":"npm:jviide","email":""}],"_npmUser":{"name":"jviide","email":"jviide@iki.fi"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-replace-expressions_0.1.1_1551042859308_0.006230530781150989"},"_hasShrinkwrap":false,"publish_time":1551042859438,"_cnpm_publish_time":1551042859438,"_cnpmcore_publish_time":"2021-12-16T20:08:59.765Z"},"0.1.0":{"name":"babel-plugin-transform-replace-expressions","version":"0.1.0","description":"Replace JavaScript expressions with other expressions","main":"index.js","license":"MIT","repository":{"type":"git","url":"https://github.com/jviide/babel-plugin-transform-replace-expressions.git"},"author":{"name":"Joachim Viide","email":"jviide@iki.fi"},"keywords":["babel-plugin"],"scripts":{"test":"mocha","lint":"eslint --max-warnings 0 --ignore-path .gitignore ."},"dependencies":{"@babel/parser":"^7.3.3"},"devDependencies":{"@babel/core":"^7.3.3","@babel/types":"^7.3.3","chai":"^4.2.0","eslint":"^5.14.1","eslint-config-prettier":"^4.0.0","eslint-plugin-prettier":"^3.0.1","mocha":"^6.0.1","prettier":"^1.16.4"},"peerDependencies":{"@babel/core":"^7.0.0-0"},"licenseText":"MIT License\n\nCopyright (c) 2019 Joachim Viide\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"babel-plugin-transform-replace-expressions@0.1.0","dist":{"shasum":"d6801da73d45603c1534a630b479ce734213a554","size":2179,"noattachment":false,"key":"/babel-plugin-transform-replace-expressions/-/babel-plugin-transform-replace-expressions-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-replace-expressions/download/babel-plugin-transform-replace-expressions-0.1.0.tgz"},"maintainers":[{"name":"jviide","email":""},{"name":"npm:jviide","email":""}],"_npmUser":{"name":"jviide","email":"jviide@iki.fi"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-replace-expressions_0.1.0_1551032879215_0.2677323294680425"},"_hasShrinkwrap":false,"publish_time":1551032879360,"_cnpm_publish_time":1551032879360,"_cnpmcore_publish_time":"2021-12-16T20:08:59.979Z"},"0.0.3":{"name":"babel-plugin-transform-replace-expressions","version":"0.0.3","description":"Replace JavaScript expressions with other expressions","main":"index.js","license":"MIT","repository":{"type":"git","url":"https://github.com/jviide/babel-plugin-transform-replace-expressions.git"},"author":{"name":"Joachim Viide","email":"jviide@iki.fi"},"dependencies":{"@babel/parser":"^7.0.0"},"keywords":["babel-plugin"],"licenseText":"MIT License\n\nCopyright (c) 2019 Joachim Viide\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"babel-plugin-transform-replace-expressions@0.0.3","dist":{"shasum":"784d41ca5a6e35675c185ab1f1a3d5cf804be51b","size":1700,"noattachment":false,"key":"/babel-plugin-transform-replace-expressions/-/babel-plugin-transform-replace-expressions-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-replace-expressions/download/babel-plugin-transform-replace-expressions-0.0.3.tgz"},"maintainers":[{"name":"jviide","email":""},{"name":"npm:jviide","email":""}],"_npmUser":{"name":"jviide","email":"jviide@iki.fi"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-replace-expressions_0.0.3_1550979119879_0.6713253936425123"},"_hasShrinkwrap":false,"publish_time":1550979120033,"_cnpm_publish_time":1550979120033,"_cnpmcore_publish_time":"2021-12-16T20:09:00.198Z"},"0.0.2":{"name":"babel-plugin-transform-replace-expressions","version":"0.0.2","main":"index.js","license":"MIT","devDependencies":{"@babel/cli":"^7.2.3","@babel/core":"^7.3.3"},"dependencies":{"@babel/parser":"^7.0.0"},"description":"Replace JavaScript expressions with other expressions.","licenseText":"MIT License\n\nCopyright (c) 2019 Joachim Viide\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"babel-plugin-transform-replace-expressions@0.0.2","dist":{"shasum":"503ee10dc8ac56e275178a822bcf2245c5d5e3f0","size":1880,"noattachment":false,"key":"/babel-plugin-transform-replace-expressions/-/babel-plugin-transform-replace-expressions-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-replace-expressions/download/babel-plugin-transform-replace-expressions-0.0.2.tgz"},"maintainers":[{"name":"jviide","email":""},{"name":"npm:jviide","email":""}],"_npmUser":{"name":"jviide","email":"jviide@iki.fi"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-replace-expressions_0.0.2_1550975734566_0.8325299854739074"},"_hasShrinkwrap":false,"publish_time":1550975734713,"_cnpm_publish_time":1550975734713,"_cnpmcore_publish_time":"2021-12-16T20:09:00.474Z"},"0.0.1":{"name":"babel-plugin-transform-replace-expressions","version":"0.0.1","main":"index.js","license":"MIT","devDependencies":{"@babel/cli":"^7.2.3","@babel/core":"^7.3.3"},"dependencies":{"@babel/parser":"^7.0.0"},"description":"Replace JavaScript expressions with other expressions.","licenseText":"MIT License\n\nCopyright (c) 2019 Joachim Viide\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"babel-plugin-transform-replace-expressions@0.0.1","dist":{"shasum":"64d880084779a952e934ee841bd038ab03a55039","size":1883,"noattachment":false,"key":"/babel-plugin-transform-replace-expressions/-/babel-plugin-transform-replace-expressions-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-replace-expressions/download/babel-plugin-transform-replace-expressions-0.0.1.tgz"},"maintainers":[{"name":"jviide","email":""},{"name":"npm:jviide","email":""}],"_npmUser":{"name":"jviide","email":"jviide@iki.fi"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-replace-expressions_0.0.1_1550969160443_0.7829266126567038"},"_hasShrinkwrap":false,"publish_time":1550969160556,"_cnpm_publish_time":1550969160556,"_cnpmcore_publish_time":"2021-12-16T20:09:00.674Z"}},"readme":"# babel-plugin-transform-replace-expressions [![CircleCI](https://circleci.com/gh/jviide/babel-plugin-transform-replace-expressions.svg?style=shield)](https://circleci.com/gh/jviide/babel-plugin-transform-replace-expressions) [![npm](https://img.shields.io/npm/v/babel-plugin-transform-replace-expressions.svg)](https://www.npmjs.com/package/babel-plugin-transform-replace-expressions)\n\nReplace JavaScript expressions with other expressions.\n\n## Installation\n\n```\n$ yarn add --dev babel-plugin-transform-replace-expressions\n```\n\n## Example\n\nInput file:\n\n```js\nconst env = process.env.NODE_ENV;\n\ntypeof Hello === \"number\";\n```\n\n`.babelrc`:\n\n```json\n{\n  \"plugins\": [\n    [\n      \"babel-plugin-transform-replace-expressions\",\n      {\n        \"replace\": {\n          \"process.env.NODE_ENV\": \"\\\"production\\\"\",\n          \"typeof Hello\": \"42\"\n        }\n      }\n    ]\n  ]\n}\n```\n\nOutput:\n\n```js\nconst env = \"production\";\n\n42 === \"number\";\n```\n\n## Conflict resolution\n\nA conflict happens when two replacements have the same Babel [abstract syntax tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) representation. For example expressions `typeof A` and `typeof (A)` are formatted differently but have the same AST representation as far as the plugin is concerned. In those situations the default is to raise an error, and can be overwritten by setting the option `allowConflictingReplacements` to `true`. \n\nYou can also always give the replacements as an array of key-value pairs. When `allowConflictingReplacements` is set to `true` the _last_ conflicting replacement gets selected.\n\n```js\n{\n  \"plugins\": [\n    [\n      \"babel-plugin-transform-replace-expressions\",\n      {\n        \"replace\": [\n          [\"typeof A\", \"B\"],\n          [\"typeof (A)\", \"C\"]\n        ],\n        \"allowConflictingReplacements\": true\n      }\n    ]\n  ]\n}\n```\n\n## Notes\n\n * Replacements are only applied to expressions. Therefore replacing `DEBUG` with `false` in `const DEBUG = true` does nothing, but for `if (DEBUG) {}` the result is `if (false) {}`.\n \n * Only *full* expressions count. You can't replace `env` in `process.env.NODE_ENV`, you have to replace `process.env`, which is a proper expression in Babel AST.\n \n * A replacement is only applied when the result is valid JavaScript. For example replacing `a` with `2` in the following code:\n \n   ```js\n   a = 1;\n   b = a;\n   ```\n   \n   yields\n   \n   ```js\n   a = 1;\n   b = 2;\n   ```\n\n## License\n\nThis plugin is licensed under the MIT license. See [LICENSE](./LICENSE).\n","_attachments":{},"license":"MIT"}