From be5da7fcc57ea2789f51f964d853677803d4cc4e Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 29 Mar 2024 10:39:12 +0200 Subject: [PATCH] refactor: Optimize resource filtering --- src/detectors/typeChecker/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/detectors/typeChecker/index.ts b/src/detectors/typeChecker/index.ts index 2ca4918bc..8e6ada42d 100644 --- a/src/detectors/typeChecker/index.ts +++ b/src/detectors/typeChecker/index.ts @@ -220,19 +220,19 @@ export class TsProjectDetector extends ProjectBasedDetector { // Rewrite fs-paths to virtual paths resourcePaths = [...allResources, ...allTestResources].map((res: Resource) => { - if (absoluteFilePaths.includes(res.getSourceMetadata().fsPath)) { - return res.getPath(); + if (!absoluteFilePaths.includes(res.getSourceMetadata().fsPath)) { + return; } + + let resPath = res.getPath(); + if (resPath.endsWith(".html")) { + resPath = resPath.replace(/\.[a-z]+$/, ".jsx"); + } else if (!resPath.endsWith(".js")) { + resPath = resPath.replace(/\.[a-z]+$/, ".js"); + } + return resPath; }) - .filter(($: string | undefined) => $) - .map((res) => { - if (res && res.endsWith(".html")) { - res = res.replace(/\.[a-z]+$/, ".jsx"); - } else if (res && !res.endsWith(".js")) { - res = res.replace(/\.[a-z]+$/, ".js"); - } - return res; - }); + .filter(($: string | undefined) => $); } else { resourcePaths = Array.from(resources.keys()); }