Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Chore: improve performance of :function selector (#15181)
  • Loading branch information
mdjermanovic committed Oct 21, 2021
1 parent 31af1c8 commit 90a5b6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/linter/node-event-generator.js
Expand Up @@ -98,6 +98,13 @@ function getPossibleTypes(parsedSelector) {
case "adjacent":
return getPossibleTypes(parsedSelector.right);

case "class":
if (parsedSelector.name === "function") {
return ["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"];
}

return null;

default:
return null;

Expand Down
14 changes: 14 additions & 0 deletions tests/lib/linter/node-event-generator.js
Expand Up @@ -257,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;",
[
Expand Down

0 comments on commit 90a5b6b

Please sign in to comment.