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

Unsupported logical operator ?? #79

Open
blutorange opened this issue Dec 4, 2020 · 0 comments
Open

Unsupported logical operator ?? #79

blutorange opened this issue Dec 4, 2020 · 0 comments

Comments

@blutorange
Copy link

blutorange commented Dec 4, 2020

?? is a new operator not supported by this plugin yet.

patch-package patch to fix this:

eslint-plugin-tree-shaking+1.8.0.patch

diff --git a/

node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js b/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js
index 16c42ca..10e4728 100644
--- a/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js
+++ b/node_modules/eslint-plugin-tree-shaking/lib/rules/no-side-effects-in-initialization.js
@@ -150,6 +150,17 @@ const reportSideEffectsInProgram = (context, programNode) => {
         return leftValue
       }
       return getAndReportRight()
+    },
+    '??': (getAndReportLeft, getAndReportRight) => {
+      const leftValue = getAndReportLeft()
+      if (!leftValue.hasValue) {
+        getAndReportRight()
+        return leftValue
+      }
+      if (leftValue.value) {
+        return leftValue
+      }
+      return getAndReportRight()
     }
   }
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

1 participant