Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonJS support #45

Open
heri16 opened this issue May 22, 2018 · 1 comment
Open

CommonJS support #45

heri16 opened this issue May 22, 2018 · 1 comment

Comments

@heri16
Copy link

heri16 commented May 22, 2018

Is there a plugin/flag that does similar to this but leaves only CommonJS support?

@lpinca
Copy link
Member

lpinca commented May 22, 2018

I didn't test but this patch should work:

$ git diff
diff --git a/index.js b/index.js
index fd023f9..686b3f3 100644
--- a/index.js
+++ b/index.js
@@ -22,25 +22,11 @@ function prune(code) {
 
   estraverse.replace(ast, {
     leave: function leave(node, parent) {
-      var ret;
-
-      if ('IfStatement' === node.type) {
-        if ('BinaryExpression' !== node.test.type) return;
-
-        if ('self' === node.test.left.argument.name) {
-          node.alternate = null;
-        } else if ('global' === node.test.left.argument.name) {
-          ret = node.alternate;
-        }
-
-        return ret;
-      }
-
       if (
           'BlockStatement' === node.type
         && 'FunctionExpression' === parent.type
       ) {
-        return node.body[0].alternate.alternate;
+        return node.body[0].consequent;
       }
     }
   });

Anyway I think it's out of the scope of this module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants