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

Chore: improve performance of :function selector #15181

Merged
merged 1 commit into from Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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