perf: Use logical expression instead of regexp for isUnitTestSetUp (#16035)

This commit is contained in:
SUZUKI Sosuke authored and GitHub committed 2024-02-08 23:05:58 +09:00
1 parent 99bc9d0b6d
commit 06c9d77bc5
1 file changed
+8 -7
+8 -7
View File
@@ -323,15 +323,16 @@ function isSimpleType(node) {
}
/**
* @param {CallExpression} node
* @param {*} node
* @returns {boolean}
*/
function isUnitTestSetUp(node) {
const unitTestSetUpRe = /^(?:before|after)(?:Each|All)$/;
function isUnitTestSetupIdentifier(node) {
return (
node.callee.type === "Identifier" &&
node.arguments.length === 1 &&
unitTestSetUpRe.test(node.callee.name)
node.type === "Identifier" &&
(node.name === "beforeEach" ||
node.name === "beforeAll" ||
node.name === "afterEach" ||
node.name === "afterAll")
);
}
@@ -375,7 +376,7 @@ function isTestCall(node, parent) {
return isFunctionOrArrowExpression(node.arguments[0]);
}
if (isUnitTestSetUp(node)) {
if (isUnitTestSetupIdentifier(node.callee)) {
return isAngularTestWrapper(node.arguments[0]);
}
} else if (