]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/no-extra-bind.js
import 7.12.1 upstream release
[pve-eslint.git] / eslint / tests / lib / rules / no-extra-bind.js
index 121979671765d18a15174b6f57136ab453a7cbd8..8422f3de77172e6176380ad0d705627ec7ce12a4 100644 (file)
@@ -102,6 +102,16 @@ ruleTester.run("no-extra-bind", rule, {
             output: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }",
             errors: [{ messageId: "unexpected", type: "CallExpression", column: 71 }]
         },
+        {
+            code: "var a = (function() { return 1; }).bind(this)",
+            output: "var a = (function() { return 1; })",
+            errors
+        },
+        {
+            code: "var a = (function() { return 1; }.bind)(this)",
+            output: "var a = (function() { return 1; })",
+            errors
+        },
 
         // Should not autofix if bind expression args have side effects
         {
@@ -180,6 +190,44 @@ ruleTester.run("no-extra-bind", rule, {
             code: "var a = function() {}.bind(b)/**/",
             output: "var a = function() {}/**/",
             errors
+        },
+
+        // Optional chaining
+        {
+            code: "var a = function() { return 1; }.bind?.(b)",
+            output: "var a = function() { return 1; }",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "var a = function() { return 1; }?.bind(b)",
+            output: "var a = function() { return 1; }",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "var a = (function() { return 1; }?.bind)(b)",
+            output: "var a = (function() { return 1; })",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "var a = function() { return 1; }['bind']?.(b)",
+            output: "var a = function() { return 1; }",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "var a = function() { return 1; }?.['bind'](b)",
+            output: "var a = function() { return 1; }",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unexpected" }]
+        },
+        {
+            code: "var a = (function() { return 1; }?.['bind'])(b)",
+            output: "var a = (function() { return 1; })",
+            parserOptions: { ecmaVersion: 2020 },
+            errors: [{ messageId: "unexpected" }]
         }
     ]
 });