From cd1ef5cd7dcbe6011fa5173637ced6560eb91b70 Mon Sep 17 00:00:00 2001 From: lizhonghan Date: Wed, 4 Sep 2024 17:30:40 +0800 Subject: [PATCH] [ArkTS Linter] Revert linter cache funtion change Issue: https://gitee.com/openharmony/third_party_typescript/issues/IAO9I4 1. Revert standalnoe linter cache for normalizePath() Change-Id: I637c2c48a9d1265e4de1deb6fe56b83bd70b5825 Signed-off-by: lizhonghan --- lib/tsserver.js | 21 +++---------------- lib/tsserverlibrary.d.ts | 1 - lib/tsserverlibrary.js | 21 +++---------------- lib/typescript.d.ts | 1 - lib/typescript.js | 21 +++---------------- lib/typescriptServices.d.ts | 1 - lib/typescriptServices.js | 21 +++---------------- src/linter/ArkTSLinter_1_1/LinterRunner.ts | 5 ++--- src/linter/ArkTSLinter_1_1/Utils.ts | 16 +------------- .../reference/api/tsserverlibrary.d.ts | 1 - tests/baselines/reference/api/typescript.d.ts | 1 - 11 files changed, 15 insertions(+), 95 deletions(-) diff --git a/lib/tsserver.js b/lib/tsserver.js index b291d5de83..c2c12bd82f 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -196510,7 +196510,7 @@ var ts; function srcFilePathContainsDirectory(srcFile, dir) { var pathComps = srcFilePathComponents.get(srcFile); if (!pathComps) { - pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName)); + pathComps = ts.getPathComponents(ts.normalizePath(srcFile.fileName)); srcFilePathComponents.set(srcFile, pathComps); } for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) { @@ -197281,23 +197281,9 @@ var ts; return exportDeclSet; } Utils.searchFileExportDecl = searchFileExportDecl; - var normalizedPathCache = new ts.Map(); - function normalizePath(path) { - normalizedPathCache = normalizedPathCache ? normalizedPathCache : new ts.Map(); - var cached = normalizedPathCache.get(path); - if (cached) { - return cached; - } - var normalized = ts.normalizePath(path); - normalizedPathCache.set(path, normalized); - return normalized; - } - Utils.normalizePath = normalizePath; function clearUtilsGlobalvariables() { parentSymbolCache === null || parentSymbolCache === void 0 ? void 0 : parentSymbolCache.clear(); parentSymbolCache = undefined; - normalizedPathCache === null || normalizedPathCache === void 0 ? void 0 : normalizedPathCache.clear(); - normalizedPathCache = undefined; } Utils.clearUtilsGlobalvariables = clearUtilsGlobalvariables; })(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {})); @@ -200552,15 +200538,14 @@ var ts; ArkTSLinter_1_1.Utils.setTypeChecker(ArkTSLinter_1_1.TypeScriptLinter.tsTypeChecker); linter.lint(); // Get list of bad nodes from the current run. - currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; + currentDiagnostics = (_a = tscStrictDiagnostics.get(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; ArkTSLinter_1_1.TypeScriptLinter.problemsInfos.forEach(function (x) { return currentDiagnostics.push(translateDiag(fileToLint, x)); }); } else { ArkTSLinter_1_1.InteropTypescriptLinter.initStatic(); var isKit = ts.getBaseFileName(fileToLint.fileName).indexOf('@kit.') === 0; var etsLoaderPath = program.getCompilerOptions().etsLoaderPath; - var isInSdk = etsLoaderPath ? - ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; + var isInSdk = etsLoaderPath ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; var isInOhModules = ts.isOHModules(fileToLint.fileName); var tsImportSendableEnable = program.getCompilerOptions().tsImportSendableEnable; if (isKit || isInOhModules || (!tsImportSendableEnable && !isInSdk)) { diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 8b838b7cd5..f5f102cb4b 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -13457,7 +13457,6 @@ declare namespace ts { function isNonSendableFunctionTypeAlias(type: ts.Type): boolean; function isWrongSendableFunctionAssignment(lhsType: ts.Type, rhsType: ts.Type): boolean; function searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts.SyntaxKind[]): Set; - function normalizePath(path: string): string; function clearUtilsGlobalvariables(): void; } } diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index b8f0e7ea05..ed445fcf15 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -196255,7 +196255,7 @@ var ts; function srcFilePathContainsDirectory(srcFile, dir) { var pathComps = srcFilePathComponents.get(srcFile); if (!pathComps) { - pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName)); + pathComps = ts.getPathComponents(ts.normalizePath(srcFile.fileName)); srcFilePathComponents.set(srcFile, pathComps); } for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) { @@ -197026,23 +197026,9 @@ var ts; return exportDeclSet; } Utils.searchFileExportDecl = searchFileExportDecl; - var normalizedPathCache = new ts.Map(); - function normalizePath(path) { - normalizedPathCache = normalizedPathCache ? normalizedPathCache : new ts.Map(); - var cached = normalizedPathCache.get(path); - if (cached) { - return cached; - } - var normalized = ts.normalizePath(path); - normalizedPathCache.set(path, normalized); - return normalized; - } - Utils.normalizePath = normalizePath; function clearUtilsGlobalvariables() { parentSymbolCache === null || parentSymbolCache === void 0 ? void 0 : parentSymbolCache.clear(); parentSymbolCache = undefined; - normalizedPathCache === null || normalizedPathCache === void 0 ? void 0 : normalizedPathCache.clear(); - normalizedPathCache = undefined; } Utils.clearUtilsGlobalvariables = clearUtilsGlobalvariables; })(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {})); @@ -200297,15 +200283,14 @@ var ts; ArkTSLinter_1_1.Utils.setTypeChecker(ArkTSLinter_1_1.TypeScriptLinter.tsTypeChecker); linter.lint(); // Get list of bad nodes from the current run. - currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; + currentDiagnostics = (_a = tscStrictDiagnostics.get(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; ArkTSLinter_1_1.TypeScriptLinter.problemsInfos.forEach(function (x) { return currentDiagnostics.push(translateDiag(fileToLint, x)); }); } else { ArkTSLinter_1_1.InteropTypescriptLinter.initStatic(); var isKit = ts.getBaseFileName(fileToLint.fileName).indexOf('@kit.') === 0; var etsLoaderPath = program.getCompilerOptions().etsLoaderPath; - var isInSdk = etsLoaderPath ? - ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; + var isInSdk = etsLoaderPath ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; var isInOhModules = ts.isOHModules(fileToLint.fileName); var tsImportSendableEnable = program.getCompilerOptions().tsImportSendableEnable; if (isKit || isInOhModules || (!tsImportSendableEnable && !isInSdk)) { diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 0f3518d3a7..930f6ec28b 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -9511,7 +9511,6 @@ declare namespace ts { function isNonSendableFunctionTypeAlias(type: ts.Type): boolean; function isWrongSendableFunctionAssignment(lhsType: ts.Type, rhsType: ts.Type): boolean; function searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts.SyntaxKind[]): Set; - function normalizePath(path: string): string; function clearUtilsGlobalvariables(): void; } } diff --git a/lib/typescript.js b/lib/typescript.js index 5760b767a9..c1bcf9b744 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -185349,7 +185349,7 @@ var ts; function srcFilePathContainsDirectory(srcFile, dir) { var pathComps = srcFilePathComponents.get(srcFile); if (!pathComps) { - pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName)); + pathComps = ts.getPathComponents(ts.normalizePath(srcFile.fileName)); srcFilePathComponents.set(srcFile, pathComps); } for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) { @@ -186120,23 +186120,9 @@ var ts; return exportDeclSet; } Utils.searchFileExportDecl = searchFileExportDecl; - var normalizedPathCache = new ts.Map(); - function normalizePath(path) { - normalizedPathCache = normalizedPathCache ? normalizedPathCache : new ts.Map(); - var cached = normalizedPathCache.get(path); - if (cached) { - return cached; - } - var normalized = ts.normalizePath(path); - normalizedPathCache.set(path, normalized); - return normalized; - } - Utils.normalizePath = normalizePath; function clearUtilsGlobalvariables() { parentSymbolCache === null || parentSymbolCache === void 0 ? void 0 : parentSymbolCache.clear(); parentSymbolCache = undefined; - normalizedPathCache === null || normalizedPathCache === void 0 ? void 0 : normalizedPathCache.clear(); - normalizedPathCache = undefined; } Utils.clearUtilsGlobalvariables = clearUtilsGlobalvariables; })(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {})); @@ -189391,15 +189377,14 @@ var ts; ArkTSLinter_1_1.Utils.setTypeChecker(ArkTSLinter_1_1.TypeScriptLinter.tsTypeChecker); linter.lint(); // Get list of bad nodes from the current run. - currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; + currentDiagnostics = (_a = tscStrictDiagnostics.get(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; ArkTSLinter_1_1.TypeScriptLinter.problemsInfos.forEach(function (x) { return currentDiagnostics.push(translateDiag(fileToLint, x)); }); } else { ArkTSLinter_1_1.InteropTypescriptLinter.initStatic(); var isKit = ts.getBaseFileName(fileToLint.fileName).indexOf('@kit.') === 0; var etsLoaderPath = program.getCompilerOptions().etsLoaderPath; - var isInSdk = etsLoaderPath ? - ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; + var isInSdk = etsLoaderPath ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; var isInOhModules = ts.isOHModules(fileToLint.fileName); var tsImportSendableEnable = program.getCompilerOptions().tsImportSendableEnable; if (isKit || isInOhModules || (!tsImportSendableEnable && !isInSdk)) { diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 0ae14e24f4..7acf16570a 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -9511,7 +9511,6 @@ declare namespace ts { function isNonSendableFunctionTypeAlias(type: ts.Type): boolean; function isWrongSendableFunctionAssignment(lhsType: ts.Type, rhsType: ts.Type): boolean; function searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts.SyntaxKind[]): Set; - function normalizePath(path: string): string; function clearUtilsGlobalvariables(): void; } } diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 0a72f2c5c9..812e43048a 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -185349,7 +185349,7 @@ var ts; function srcFilePathContainsDirectory(srcFile, dir) { var pathComps = srcFilePathComponents.get(srcFile); if (!pathComps) { - pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName)); + pathComps = ts.getPathComponents(ts.normalizePath(srcFile.fileName)); srcFilePathComponents.set(srcFile, pathComps); } for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) { @@ -186120,23 +186120,9 @@ var ts; return exportDeclSet; } Utils.searchFileExportDecl = searchFileExportDecl; - var normalizedPathCache = new ts.Map(); - function normalizePath(path) { - normalizedPathCache = normalizedPathCache ? normalizedPathCache : new ts.Map(); - var cached = normalizedPathCache.get(path); - if (cached) { - return cached; - } - var normalized = ts.normalizePath(path); - normalizedPathCache.set(path, normalized); - return normalized; - } - Utils.normalizePath = normalizePath; function clearUtilsGlobalvariables() { parentSymbolCache === null || parentSymbolCache === void 0 ? void 0 : parentSymbolCache.clear(); parentSymbolCache = undefined; - normalizedPathCache === null || normalizedPathCache === void 0 ? void 0 : normalizedPathCache.clear(); - normalizedPathCache = undefined; } Utils.clearUtilsGlobalvariables = clearUtilsGlobalvariables; })(Utils = ArkTSLinter_1_1.Utils || (ArkTSLinter_1_1.Utils = {})); @@ -189391,15 +189377,14 @@ var ts; ArkTSLinter_1_1.Utils.setTypeChecker(ArkTSLinter_1_1.TypeScriptLinter.tsTypeChecker); linter.lint(); // Get list of bad nodes from the current run. - currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; + currentDiagnostics = (_a = tscStrictDiagnostics.get(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : []; ArkTSLinter_1_1.TypeScriptLinter.problemsInfos.forEach(function (x) { return currentDiagnostics.push(translateDiag(fileToLint, x)); }); } else { ArkTSLinter_1_1.InteropTypescriptLinter.initStatic(); var isKit = ts.getBaseFileName(fileToLint.fileName).indexOf('@kit.') === 0; var etsLoaderPath = program.getCompilerOptions().etsLoaderPath; - var isInSdk = etsLoaderPath ? - ArkTSLinter_1_1.Utils.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; + var isInSdk = etsLoaderPath ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false; var isInOhModules = ts.isOHModules(fileToLint.fileName); var tsImportSendableEnable = program.getCompilerOptions().tsImportSendableEnable; if (isKit || isInOhModules || (!tsImportSendableEnable && !isInSdk)) { diff --git a/src/linter/ArkTSLinter_1_1/LinterRunner.ts b/src/linter/ArkTSLinter_1_1/LinterRunner.ts index dfecedf8a1..f28501fb9e 100644 --- a/src/linter/ArkTSLinter_1_1/LinterRunner.ts +++ b/src/linter/ArkTSLinter_1_1/LinterRunner.ts @@ -94,14 +94,13 @@ export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: Sourc linter.lint(); // Get list of bad nodes from the current run. - currentDiagnostics = tscStrictDiagnostics.get(Utils.normalizePath(fileToLint.fileName)) ?? []; + currentDiagnostics = tscStrictDiagnostics.get(normalizePath(fileToLint.fileName)) ?? []; TypeScriptLinter.problemsInfos.forEach((x) => currentDiagnostics.push(translateDiag(fileToLint, x))); } else { InteropTypescriptLinter.initStatic(); const isKit = ts.getBaseFileName(fileToLint.fileName).indexOf('@kit.') === 0; const etsLoaderPath = program.getCompilerOptions().etsLoaderPath; - const isInSdk = etsLoaderPath ? - Utils.normalizePath(fileToLint.fileName).indexOf(resolvePath(etsLoaderPath, '../..')) === 0 : false; + const isInSdk = etsLoaderPath ? normalizePath(fileToLint.fileName).indexOf(resolvePath(etsLoaderPath, '../..')) === 0 : false; const isInOhModules = isOHModules(fileToLint.fileName); const tsImportSendableEnable = program.getCompilerOptions().tsImportSendableEnable; if (isKit || isInOhModules || (!tsImportSendableEnable && !isInSdk)) { diff --git a/src/linter/ArkTSLinter_1_1/Utils.ts b/src/linter/ArkTSLinter_1_1/Utils.ts index 53b6c9a2db..b6dc69c2eb 100644 --- a/src/linter/ArkTSLinter_1_1/Utils.ts +++ b/src/linter/ArkTSLinter_1_1/Utils.ts @@ -1534,7 +1534,7 @@ const srcFilePathComponents = new Map(); export function srcFilePathContainsDirectory(srcFile: SourceFile, dir: string): boolean { let pathComps = srcFilePathComponents.get(srcFile); if (!pathComps) { - pathComps = getPathComponents(Utils.normalizePath(srcFile.fileName)); + pathComps = getPathComponents(normalizePath(srcFile.fileName)); srcFilePathComponents.set(srcFile, pathComps); } for (const subdir of pathComps) { @@ -2355,23 +2355,9 @@ export function searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts return exportDeclSet; } -let normalizedPathCache: ESMap | undefined = new Map(); -export function normalizePath(path: string): string { - normalizedPathCache = normalizedPathCache ? normalizedPathCache : new Map(); - const cached = normalizedPathCache.get(path); - if (cached) { - return cached; - } - const normalized = ts.normalizePath(path); - normalizedPathCache.set(path, normalized); - return normalized; -} - export function clearUtilsGlobalvariables(): void { parentSymbolCache?.clear(); parentSymbolCache = undefined; - normalizedPathCache?.clear(); - normalizedPathCache = undefined; } } } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 8b838b7cd5..f5f102cb4b 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -13457,7 +13457,6 @@ declare namespace ts { function isNonSendableFunctionTypeAlias(type: ts.Type): boolean; function isWrongSendableFunctionAssignment(lhsType: ts.Type, rhsType: ts.Type): boolean; function searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts.SyntaxKind[]): Set; - function normalizePath(path: string): string; function clearUtilsGlobalvariables(): void; } } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0f3518d3a7..930f6ec28b 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -9511,7 +9511,6 @@ declare namespace ts { function isNonSendableFunctionTypeAlias(type: ts.Type): boolean; function isWrongSendableFunctionAssignment(lhsType: ts.Type, rhsType: ts.Type): boolean; function searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts.SyntaxKind[]): Set; - function normalizePath(path: string): string; function clearUtilsGlobalvariables(): void; } }