]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/linter/node-event-generator.js
import 8.3.0 source
[pve-eslint.git] / eslint / tests / lib / linter / node-event-generator.js
index f9010c32138c24e16148e99f5b37531b14171e0a..44f8e512d6796c78854e104ac027915b9e4018d6 100644 (file)
@@ -17,8 +17,9 @@ const assert = require("assert"),
     createEmitter = require("../../../lib/linter/safe-emitter"),
     NodeEventGenerator = require("../../../lib/linter/node-event-generator");
 
+
 //------------------------------------------------------------------------------
-// Tests
+// Constants
 //------------------------------------------------------------------------------
 
 const ESPREE_CONFIG = {
@@ -31,6 +32,10 @@ const ESPREE_CONFIG = {
 
 const STANDARD_ESQUERY_OPTION = { visitorKeys: vk.KEYS, fallback: Traverser.getKeys };
 
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
 describe("NodeEventGenerator", () => {
     EventGeneratorTester.testEventGeneratorInterface(
         new NodeEventGenerator(createEmitter(), STANDARD_ESQUERY_OPTION)
@@ -252,6 +257,20 @@ describe("NodeEventGenerator", () => {
             ]
         );
 
+        assertEmissions(
+            "function foo(){} var x; (function (p){}); () => {};",
+            [":function", "ExpressionStatement > :function", "VariableDeclaration, :function[params.length=1]"],
+            ast => [
+                [":function", ast.body[0]], // function foo(){}
+                ["VariableDeclaration, :function[params.length=1]", ast.body[1]], // var x;
+                [":function", ast.body[2].expression], // function (p){}
+                ["ExpressionStatement > :function", ast.body[2].expression], // function (p){}
+                ["VariableDeclaration, :function[params.length=1]", ast.body[2].expression], // function (p){}
+                [":function", ast.body[3].expression], // () => {}
+                ["ExpressionStatement > :function", ast.body[3].expression] // () => {}
+            ]
+        );
+
         assertEmissions(
             "foo;",
             [
@@ -309,6 +328,15 @@ describe("NodeEventGenerator", () => {
                 ["[name.length=3]:exit", ast.body[1].expression]
             ]
         );
+
+        // https://github.com/eslint/eslint/issues/14799
+        assertEmissions(
+            "const {a = 1} = b;",
+            ["Property > .key"],
+            ast => [
+                ["Property > .key", ast.body[0].declarations[0].id.properties[0].key]
+            ]
+        );
     });
 
     describe("traversing the entire non-standard AST", () => {