babel-plugin-transform-replace-expressions
Advanced tools
Comparing version 0.0.3 to 0.1.0
const { parseExpression } = require("@babel/parser"); | ||
module.exports = function({ types: t }, replace = {}) { | ||
module.exports = function({ types: t }, options = {}) { | ||
const replace = options.replace || {}; | ||
const replacements = Object.keys(replace).map(key => { | ||
@@ -28,2 +29,3 @@ const kExpr = parseExpression(key); | ||
} | ||
path.skip(); | ||
return; | ||
@@ -30,0 +32,0 @@ } |
{ | ||
"name": "babel-plugin-transform-replace-expressions", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Replace JavaScript expressions with other expressions", | ||
@@ -9,8 +9,25 @@ "main": "index.js", | ||
"author": "Joachim Viide <jviide@iki.fi>", | ||
"keywords": [ | ||
"babel-plugin" | ||
], | ||
"scripts": { | ||
"test": "mocha", | ||
"lint": "eslint --max-warnings 0 --ignore-path .gitignore ." | ||
}, | ||
"dependencies": { | ||
"@babel/parser": "^7.0.0" | ||
"@babel/parser": "^7.3.3" | ||
}, | ||
"keywords": [ | ||
"babel-plugin" | ||
] | ||
"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" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# babel-plugin-transform-replace-expressions | ||
# 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) | ||
@@ -21,3 +21,3 @@ Replace JavaScript expressions with other expressions. | ||
`.babelrc`: | ||
`.babelrc`: | ||
@@ -30,4 +30,6 @@ ```json | ||
{ | ||
"process.env.NODE_ENV": "\"production\"", | ||
"typeof Hello": "42" | ||
"replace": { | ||
"process.env.NODE_ENV": "\"production\"", | ||
"typeof Hello": "42" | ||
} | ||
} | ||
@@ -47,4 +49,24 @@ ] | ||
## Notes | ||
* 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) {}`. | ||
* 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. | ||
* A replacement is only applied when the result is valid JavaScript. For example replacing `a` with `2` in the following code: | ||
```js | ||
a = 1; | ||
b = a; | ||
``` | ||
yields | ||
```js | ||
a = 1; | ||
b = 2; | ||
``` | ||
## License | ||
This plugin is licensed under the MIT license. See [LICENSE](./LICENSE). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4449
36
70
2
8
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/compat-data@7.26.2(transitive)
+ Added@babel/core@7.26.0(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-compilation-targets@7.25.9(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-module-transforms@7.26.0(transitive)
+ Added@babel/helper-validator-option@7.25.9(transitive)
+ Added@babel/helpers@7.26.0(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedbrowserslist@4.24.2(transitive)
+ Addedcaniuse-lite@1.0.30001679(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedelectron-to-chromium@1.5.55(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
+ Addedyallist@3.1.1(transitive)
Updated@babel/parser@^7.3.3