Repository: babel/minify (js)

Issue:
babel-plugin-transform-inline-environment-variables - Blacklist/whitelist?
I've been using `babel-plugin-node-env-inline` for a while when compiling code that is to be used in Node. I'm getting to the point where I would like to inline other environment variables for dead code elimination while not inlining others for use with `dotenv`. Would it make sense to have an optional blacklist/whitelist to specify which environment variables should be inlined or not?

Pull request description:
Add whitelist/blacklist to transform-inline-environment-variables
Fixes #513 

Patch:
diff --git a/packages/babel-plugin-transform-inline-environment-variables/README.md b/packages/babel-plugin-transform-inline-environment-variables/README.md
index 92c6189..b9e7089 100644
--- a/packages/babel-plugin-transform-inline-environment-variables/README.md
+++ b/packages/babel-plugin-transform-inline-environment-variables/README.md
@@ -30,9 +30,21 @@ npm install babel-plugin-transform-inline-environment-variables
 **.babelrc**
 
 ```json
+// without options
 {
   "plugins": ["transform-inline-environment-variables"]
 }
+
+// with options
+{
+  "plugins": [
+    ["transform-inline-environment-variables", {
+      "include": [
+        "NODE_ENV"
+      ]
+    }]
+  ]
+}
 ```
 
 ### Via CLI
@@ -48,3 +60,8 @@ require("babel-core").transform("code", {
   plugins: ["transform-inline-environment-variables"]
 });
 ```
+
+## Options
+
++ `include` - array of environment variables to include
++ `exclude` - array of environment variables to exclude
diff --git a/packages/babel-plugin-transform-inline-environment-variables/src/index.js b/packages/babel-plugin-transform-inline-environment-variables/src/index.js
index 4bbaaf0..f6c5777 100644
--- a/packages/babel-plugin-transform-inline-environment-variables/src/index.js
+++ b/packages/babel-plugin-transform-inline-environment-variables/src/index.js
@@ -4,10 +4,14 @@ module.exports = function({ types: t }) {
   return {
     name: "transform-inline-environment-variables",
     visitor: {
-      MemberExpression(path) {
+      MemberExpression(path, { opts: { include, exclude } = {} }) {
         if (path.get("object").matchesPattern("process.env")) {
           const key = path.toComputedKey();
-          if (t.isStringLiteral(key)) {
+          if (
+            t.isStringLiteral(key) &&
+            (!include || include.indexOf(key.value) !== -1) &&
+            (!exclude || exclude.indexOf(key.value) === -1)
+          ) {
             path.replaceWith(t.valueToNode(process.env[key.value]));
           }
         }


Test patch:
diff --git a/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js b/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js
index 76b020b..a2bf041 100644
--- a/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js
+++ b/packages/babel-plugin-transform-inline-environment-variables/__tests__/inline-env-var-test.js
@@ -1,8 +1,7 @@
 jest.autoMockOff();
 
-const thePlugin = require("../../../utils/test-transform")(
-  require("../src/index")
-);
+const plugin = require("../src/index");
+const thePlugin = require("../../../utils/test-transform")(plugin);
 
 describe("inline-env-plugin", () => {
   let prev;
@@ -10,6 +9,9 @@ describe("inline-env-plugin", () => {
     prev = process.env.NODE_ENV;
     process.env.NODE_ENV = "development";
   });
+  afterAll(() => {
+    process.env.NODE_ENV = prev;
+  });
 
   thePlugin(
     "should inline environment variables",
@@ -21,7 +23,21 @@ describe("inline-env-plugin", () => {
   `
   );
 
-  afterAll(() => {
-    process.env.NODE_ENV = prev;
-  });
+  thePlugin(
+    "should only include whitelisted variables if include option is specified",
+    "process.env.NODE_ENV",
+    "process.env.NODE_ENV;",
+    {
+      plugins: [[plugin, { include: ["IS_ELECTRON"] }]]
+    }
+  );
+
+  thePlugin(
+    "should not include blacklisted variables if exclude option is specified",
+    "process.env.NODE_ENV",
+    "process.env.NODE_ENV;",
+    {
+      plugins: [[plugin, { exclude: ["NODE_ENV"] }]]
+    }
+  );
 });