Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-replace-expressions

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-replace-expressions - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

4

index.js
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).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc