mirror of
https://gitee.com/openharmony/third_party_typescript
synced 2024-11-27 00:51:12 +00:00
[ArkTS Linter] Optimize linter function perfomance
Issue: https://gitee.com/openharmony/third_party_typescript/issues/IAML46 1. Optimize normalizePath, getParentSymbolName, pathContainsDirectory and getAllDiagnostics functions. 2. update test item #13912.json for ArkUI error. Change-Id: I33cf96aac831fa1aa971d929a339a02d7253fd17 Signed-off-by: lizhonghan <lizhonghan1@huawei.com>
This commit is contained in:
parent
e8cac0f758
commit
fc47370fc9
@ -196345,10 +196345,18 @@ var ts;
|
||||
"BigInt64Array",
|
||||
"BigUint64Array",
|
||||
];
|
||||
var parentSymbolCache = new ts.Map();
|
||||
function getParentSymbolName(symbol) {
|
||||
parentSymbolCache = parentSymbolCache ? parentSymbolCache : new ts.Map();
|
||||
var cached = parentSymbolCache.get(symbol);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
var name = typeChecker.getFullyQualifiedName(symbol);
|
||||
var dotPosition = name.lastIndexOf(".");
|
||||
return (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
var result = (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
parentSymbolCache.set(symbol, result);
|
||||
return result;
|
||||
}
|
||||
Utils.getParentSymbolName = getParentSymbolName;
|
||||
function isGlobalSymbol(symbol) {
|
||||
@ -196466,19 +196474,19 @@ var ts;
|
||||
Utils.hasLibraryType = hasLibraryType;
|
||||
function isLibrarySymbol(sym) {
|
||||
if (sym && sym.declarations && sym.declarations.length > 0) {
|
||||
var srcFile = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile) {
|
||||
var srcFile_1 = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile_1) {
|
||||
return false;
|
||||
}
|
||||
var fileName_2 = srcFile.fileName;
|
||||
var fileName_2 = srcFile_1.fileName;
|
||||
// Symbols from both *.ts and *.d.ts files should obey interop rules.
|
||||
// We disable such behavior for *.ts files in the test mode due to lack of 'ets'
|
||||
// extension support.
|
||||
var ext = ts.getAnyExtensionFromPath(fileName_2);
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return pathContainsDirectory(ts.normalizePath(fileName_2), ignore); }) ||
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return srcFilePathContainsDirectory(srcFile_1, ignore); }) ||
|
||||
Utils.ARKTS_IGNORE_FILES.some(function (ignore) { return ts.getBaseFileName(fileName_2) === ignore; });
|
||||
var isEts = (ext === '.ets');
|
||||
var isTs = (ext === '.ts' && !srcFile.isDeclarationFile);
|
||||
var isTs = (ext === '.ts' && !srcFile_1.isDeclarationFile);
|
||||
var isStatic_2 = (isEts || (isTs && testMode)) && !isThirdPartyCode;
|
||||
var isStdLib = Utils.STANDARD_LIBRARIES.includes(ts.getBaseFileName(fileName_2).toLowerCase());
|
||||
// We still need to confirm support for certain API from the
|
||||
@ -196489,6 +196497,22 @@ var ts;
|
||||
return false;
|
||||
}
|
||||
Utils.isLibrarySymbol = isLibrarySymbol;
|
||||
var srcFilePathComponents = new ts.Map();
|
||||
function srcFilePathContainsDirectory(srcFile, dir) {
|
||||
var pathComps = srcFilePathComponents.get(srcFile);
|
||||
if (!pathComps) {
|
||||
pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName));
|
||||
srcFilePathComponents.set(srcFile, pathComps);
|
||||
}
|
||||
for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) {
|
||||
var subdir = pathComps_1[_i];
|
||||
if (subdir === dir) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Utils.srcFilePathContainsDirectory = srcFilePathContainsDirectory;
|
||||
function pathContainsDirectory(targetPath, dir) {
|
||||
for (var _i = 0, _a = ts.getPathComponents(targetPath); _i < _a.length; _i++) {
|
||||
var subdir = _a[_i];
|
||||
@ -197248,6 +197272,25 @@ 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 = {}));
|
||||
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
|
||||
})(ts || (ts = {}));
|
||||
@ -200350,8 +200393,8 @@ var ts;
|
||||
TSCCompiledProgram.prototype.getBuilderProgram = function () {
|
||||
return this.diagnosticsExtractor.nonStrictProgram;
|
||||
};
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (fileName) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(fileName);
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(sourceFile);
|
||||
};
|
||||
TSCCompiledProgram.prototype.doAllGetDiagnostics = function () {
|
||||
this.diagnosticsExtractor.doAllGetDiagnostics();
|
||||
@ -200366,10 +200409,10 @@ var ts;
|
||||
/**
|
||||
* Returns diagnostics which appear in strict compilation mode only
|
||||
*/
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (fileName) {
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
// workaround for a tsc bug
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ false);
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ false);
|
||||
// collect hashes for later easier comparison
|
||||
var nonStrictHashes = nonStrict.reduce(function (result, value) {
|
||||
var hash = hashDiagnostic(value);
|
||||
@ -200396,21 +200439,20 @@ var ts;
|
||||
};
|
||||
return TypeScriptDiagnosticsExtractor;
|
||||
}());
|
||||
function getAllDiagnostics(builderProgram, fileName, isStrict) {
|
||||
/**
|
||||
* Actually, we only run `getSemanticDiagnostics`,
|
||||
* because the linter care only about strict errors, which do not include syntactic diagnostics.
|
||||
*/
|
||||
function getAllDiagnostics(builderProgram, sourceFile, isStrict) {
|
||||
if (isStrict === void 0) { isStrict = false; }
|
||||
var program = builderProgram.getProgram();
|
||||
var sourceFile = program.getSourceFile(fileName);
|
||||
var syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
|
||||
if (isStrict) {
|
||||
if (!builderProgram.builderProgramForLinter) {
|
||||
return [];
|
||||
}
|
||||
return builderProgram.builderProgramForLinter.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
return builderProgram.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
function hashDiagnostic(diagnostic) {
|
||||
@ -200501,14 +200543,15 @@ 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(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : [];
|
||||
currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.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 ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false;
|
||||
var isInSdk = etsLoaderPath ?
|
||||
ArkTSLinter_1_1.Utils.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)) {
|
||||
@ -200549,6 +200592,7 @@ var ts;
|
||||
ArkTSLinter_1_1.InteropTypescriptLinter.clearTsTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTrueSymbolAtLocationCache();
|
||||
ArkTSLinter_1_1.Utils.clearUtilsGlobalvariables();
|
||||
}
|
||||
function collectChangedFilesFromProgramState(state, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) {
|
||||
var changedFiles = new ts.Set(state.changedFilesSet);
|
||||
@ -200594,7 +200638,7 @@ var ts;
|
||||
function getTscDiagnostics(tscDiagnosticsLinter, sourceFiles) {
|
||||
var strictDiagnostics = new ts.Map();
|
||||
sourceFiles.forEach(function (file) {
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file.fileName);
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file);
|
||||
if (diagnostics.length !== 0) {
|
||||
strictDiagnostics.set(ts.normalizePath(file.fileName), diagnostics);
|
||||
}
|
||||
|
5
lib/tsserverlibrary.d.ts
vendored
5
lib/tsserverlibrary.d.ts
vendored
@ -13398,6 +13398,7 @@ declare namespace ts {
|
||||
function isLibraryType(type: Type): boolean;
|
||||
function hasLibraryType(node: Node): boolean;
|
||||
function isLibrarySymbol(sym: Symbol | undefined): boolean;
|
||||
function srcFilePathContainsDirectory(srcFile: SourceFile, dir: string): boolean;
|
||||
function pathContainsDirectory(targetPath: string, dir: string): boolean;
|
||||
function getScriptKind(srcFile: SourceFile): ScriptKind;
|
||||
function isStdLibraryType(type: Type): boolean;
|
||||
@ -13455,6 +13456,8 @@ 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<ts.Node>;
|
||||
function normalizePath(path: string): string;
|
||||
function clearUtilsGlobalvariables(): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13739,7 +13742,7 @@ declare namespace ts {
|
||||
constructor(program: BuilderProgram);
|
||||
getProgram(): Program;
|
||||
getBuilderProgram(): BuilderProgram;
|
||||
getStrictDiagnostics(fileName: string): Diagnostic[];
|
||||
getStrictDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
doAllGetDiagnostics(): void;
|
||||
}
|
||||
}
|
||||
|
@ -196090,10 +196090,18 @@ var ts;
|
||||
"BigInt64Array",
|
||||
"BigUint64Array",
|
||||
];
|
||||
var parentSymbolCache = new ts.Map();
|
||||
function getParentSymbolName(symbol) {
|
||||
parentSymbolCache = parentSymbolCache ? parentSymbolCache : new ts.Map();
|
||||
var cached = parentSymbolCache.get(symbol);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
var name = typeChecker.getFullyQualifiedName(symbol);
|
||||
var dotPosition = name.lastIndexOf(".");
|
||||
return (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
var result = (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
parentSymbolCache.set(symbol, result);
|
||||
return result;
|
||||
}
|
||||
Utils.getParentSymbolName = getParentSymbolName;
|
||||
function isGlobalSymbol(symbol) {
|
||||
@ -196211,19 +196219,19 @@ var ts;
|
||||
Utils.hasLibraryType = hasLibraryType;
|
||||
function isLibrarySymbol(sym) {
|
||||
if (sym && sym.declarations && sym.declarations.length > 0) {
|
||||
var srcFile = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile) {
|
||||
var srcFile_1 = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile_1) {
|
||||
return false;
|
||||
}
|
||||
var fileName_2 = srcFile.fileName;
|
||||
var fileName_2 = srcFile_1.fileName;
|
||||
// Symbols from both *.ts and *.d.ts files should obey interop rules.
|
||||
// We disable such behavior for *.ts files in the test mode due to lack of 'ets'
|
||||
// extension support.
|
||||
var ext = ts.getAnyExtensionFromPath(fileName_2);
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return pathContainsDirectory(ts.normalizePath(fileName_2), ignore); }) ||
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return srcFilePathContainsDirectory(srcFile_1, ignore); }) ||
|
||||
Utils.ARKTS_IGNORE_FILES.some(function (ignore) { return ts.getBaseFileName(fileName_2) === ignore; });
|
||||
var isEts = (ext === '.ets');
|
||||
var isTs = (ext === '.ts' && !srcFile.isDeclarationFile);
|
||||
var isTs = (ext === '.ts' && !srcFile_1.isDeclarationFile);
|
||||
var isStatic_2 = (isEts || (isTs && testMode)) && !isThirdPartyCode;
|
||||
var isStdLib = Utils.STANDARD_LIBRARIES.includes(ts.getBaseFileName(fileName_2).toLowerCase());
|
||||
// We still need to confirm support for certain API from the
|
||||
@ -196234,6 +196242,22 @@ var ts;
|
||||
return false;
|
||||
}
|
||||
Utils.isLibrarySymbol = isLibrarySymbol;
|
||||
var srcFilePathComponents = new ts.Map();
|
||||
function srcFilePathContainsDirectory(srcFile, dir) {
|
||||
var pathComps = srcFilePathComponents.get(srcFile);
|
||||
if (!pathComps) {
|
||||
pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName));
|
||||
srcFilePathComponents.set(srcFile, pathComps);
|
||||
}
|
||||
for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) {
|
||||
var subdir = pathComps_1[_i];
|
||||
if (subdir === dir) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Utils.srcFilePathContainsDirectory = srcFilePathContainsDirectory;
|
||||
function pathContainsDirectory(targetPath, dir) {
|
||||
for (var _i = 0, _a = ts.getPathComponents(targetPath); _i < _a.length; _i++) {
|
||||
var subdir = _a[_i];
|
||||
@ -196993,6 +197017,25 @@ 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 = {}));
|
||||
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
|
||||
})(ts || (ts = {}));
|
||||
@ -200095,8 +200138,8 @@ var ts;
|
||||
TSCCompiledProgram.prototype.getBuilderProgram = function () {
|
||||
return this.diagnosticsExtractor.nonStrictProgram;
|
||||
};
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (fileName) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(fileName);
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(sourceFile);
|
||||
};
|
||||
TSCCompiledProgram.prototype.doAllGetDiagnostics = function () {
|
||||
this.diagnosticsExtractor.doAllGetDiagnostics();
|
||||
@ -200111,10 +200154,10 @@ var ts;
|
||||
/**
|
||||
* Returns diagnostics which appear in strict compilation mode only
|
||||
*/
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (fileName) {
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
// workaround for a tsc bug
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ false);
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ false);
|
||||
// collect hashes for later easier comparison
|
||||
var nonStrictHashes = nonStrict.reduce(function (result, value) {
|
||||
var hash = hashDiagnostic(value);
|
||||
@ -200141,21 +200184,20 @@ var ts;
|
||||
};
|
||||
return TypeScriptDiagnosticsExtractor;
|
||||
}());
|
||||
function getAllDiagnostics(builderProgram, fileName, isStrict) {
|
||||
/**
|
||||
* Actually, we only run `getSemanticDiagnostics`,
|
||||
* because the linter care only about strict errors, which do not include syntactic diagnostics.
|
||||
*/
|
||||
function getAllDiagnostics(builderProgram, sourceFile, isStrict) {
|
||||
if (isStrict === void 0) { isStrict = false; }
|
||||
var program = builderProgram.getProgram();
|
||||
var sourceFile = program.getSourceFile(fileName);
|
||||
var syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
|
||||
if (isStrict) {
|
||||
if (!builderProgram.builderProgramForLinter) {
|
||||
return [];
|
||||
}
|
||||
return builderProgram.builderProgramForLinter.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
return builderProgram.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
function hashDiagnostic(diagnostic) {
|
||||
@ -200246,14 +200288,15 @@ 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(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : [];
|
||||
currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.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 ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false;
|
||||
var isInSdk = etsLoaderPath ?
|
||||
ArkTSLinter_1_1.Utils.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)) {
|
||||
@ -200294,6 +200337,7 @@ var ts;
|
||||
ArkTSLinter_1_1.InteropTypescriptLinter.clearTsTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTrueSymbolAtLocationCache();
|
||||
ArkTSLinter_1_1.Utils.clearUtilsGlobalvariables();
|
||||
}
|
||||
function collectChangedFilesFromProgramState(state, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) {
|
||||
var changedFiles = new ts.Set(state.changedFilesSet);
|
||||
@ -200339,7 +200383,7 @@ var ts;
|
||||
function getTscDiagnostics(tscDiagnosticsLinter, sourceFiles) {
|
||||
var strictDiagnostics = new ts.Map();
|
||||
sourceFiles.forEach(function (file) {
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file.fileName);
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file);
|
||||
if (diagnostics.length !== 0) {
|
||||
strictDiagnostics.set(ts.normalizePath(file.fileName), diagnostics);
|
||||
}
|
||||
|
5
lib/typescript.d.ts
vendored
5
lib/typescript.d.ts
vendored
@ -9452,6 +9452,7 @@ declare namespace ts {
|
||||
function isLibraryType(type: Type): boolean;
|
||||
function hasLibraryType(node: Node): boolean;
|
||||
function isLibrarySymbol(sym: Symbol | undefined): boolean;
|
||||
function srcFilePathContainsDirectory(srcFile: SourceFile, dir: string): boolean;
|
||||
function pathContainsDirectory(targetPath: string, dir: string): boolean;
|
||||
function getScriptKind(srcFile: SourceFile): ScriptKind;
|
||||
function isStdLibraryType(type: Type): boolean;
|
||||
@ -9509,6 +9510,8 @@ 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<ts.Node>;
|
||||
function normalizePath(path: string): string;
|
||||
function clearUtilsGlobalvariables(): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9793,7 +9796,7 @@ declare namespace ts {
|
||||
constructor(program: BuilderProgram);
|
||||
getProgram(): Program;
|
||||
getBuilderProgram(): BuilderProgram;
|
||||
getStrictDiagnostics(fileName: string): Diagnostic[];
|
||||
getStrictDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
doAllGetDiagnostics(): void;
|
||||
}
|
||||
}
|
||||
|
@ -185184,10 +185184,18 @@ var ts;
|
||||
"BigInt64Array",
|
||||
"BigUint64Array",
|
||||
];
|
||||
var parentSymbolCache = new ts.Map();
|
||||
function getParentSymbolName(symbol) {
|
||||
parentSymbolCache = parentSymbolCache ? parentSymbolCache : new ts.Map();
|
||||
var cached = parentSymbolCache.get(symbol);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
var name = typeChecker.getFullyQualifiedName(symbol);
|
||||
var dotPosition = name.lastIndexOf(".");
|
||||
return (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
var result = (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
parentSymbolCache.set(symbol, result);
|
||||
return result;
|
||||
}
|
||||
Utils.getParentSymbolName = getParentSymbolName;
|
||||
function isGlobalSymbol(symbol) {
|
||||
@ -185305,19 +185313,19 @@ var ts;
|
||||
Utils.hasLibraryType = hasLibraryType;
|
||||
function isLibrarySymbol(sym) {
|
||||
if (sym && sym.declarations && sym.declarations.length > 0) {
|
||||
var srcFile = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile) {
|
||||
var srcFile_1 = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile_1) {
|
||||
return false;
|
||||
}
|
||||
var fileName_2 = srcFile.fileName;
|
||||
var fileName_2 = srcFile_1.fileName;
|
||||
// Symbols from both *.ts and *.d.ts files should obey interop rules.
|
||||
// We disable such behavior for *.ts files in the test mode due to lack of 'ets'
|
||||
// extension support.
|
||||
var ext = ts.getAnyExtensionFromPath(fileName_2);
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return pathContainsDirectory(ts.normalizePath(fileName_2), ignore); }) ||
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return srcFilePathContainsDirectory(srcFile_1, ignore); }) ||
|
||||
Utils.ARKTS_IGNORE_FILES.some(function (ignore) { return ts.getBaseFileName(fileName_2) === ignore; });
|
||||
var isEts = (ext === '.ets');
|
||||
var isTs = (ext === '.ts' && !srcFile.isDeclarationFile);
|
||||
var isTs = (ext === '.ts' && !srcFile_1.isDeclarationFile);
|
||||
var isStatic_2 = (isEts || (isTs && testMode)) && !isThirdPartyCode;
|
||||
var isStdLib = Utils.STANDARD_LIBRARIES.includes(ts.getBaseFileName(fileName_2).toLowerCase());
|
||||
// We still need to confirm support for certain API from the
|
||||
@ -185328,6 +185336,22 @@ var ts;
|
||||
return false;
|
||||
}
|
||||
Utils.isLibrarySymbol = isLibrarySymbol;
|
||||
var srcFilePathComponents = new ts.Map();
|
||||
function srcFilePathContainsDirectory(srcFile, dir) {
|
||||
var pathComps = srcFilePathComponents.get(srcFile);
|
||||
if (!pathComps) {
|
||||
pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName));
|
||||
srcFilePathComponents.set(srcFile, pathComps);
|
||||
}
|
||||
for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) {
|
||||
var subdir = pathComps_1[_i];
|
||||
if (subdir === dir) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Utils.srcFilePathContainsDirectory = srcFilePathContainsDirectory;
|
||||
function pathContainsDirectory(targetPath, dir) {
|
||||
for (var _i = 0, _a = ts.getPathComponents(targetPath); _i < _a.length; _i++) {
|
||||
var subdir = _a[_i];
|
||||
@ -186087,6 +186111,25 @@ 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 = {}));
|
||||
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
|
||||
})(ts || (ts = {}));
|
||||
@ -189189,8 +189232,8 @@ var ts;
|
||||
TSCCompiledProgram.prototype.getBuilderProgram = function () {
|
||||
return this.diagnosticsExtractor.nonStrictProgram;
|
||||
};
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (fileName) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(fileName);
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(sourceFile);
|
||||
};
|
||||
TSCCompiledProgram.prototype.doAllGetDiagnostics = function () {
|
||||
this.diagnosticsExtractor.doAllGetDiagnostics();
|
||||
@ -189205,10 +189248,10 @@ var ts;
|
||||
/**
|
||||
* Returns diagnostics which appear in strict compilation mode only
|
||||
*/
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (fileName) {
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
// workaround for a tsc bug
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ false);
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ false);
|
||||
// collect hashes for later easier comparison
|
||||
var nonStrictHashes = nonStrict.reduce(function (result, value) {
|
||||
var hash = hashDiagnostic(value);
|
||||
@ -189235,21 +189278,20 @@ var ts;
|
||||
};
|
||||
return TypeScriptDiagnosticsExtractor;
|
||||
}());
|
||||
function getAllDiagnostics(builderProgram, fileName, isStrict) {
|
||||
/**
|
||||
* Actually, we only run `getSemanticDiagnostics`,
|
||||
* because the linter care only about strict errors, which do not include syntactic diagnostics.
|
||||
*/
|
||||
function getAllDiagnostics(builderProgram, sourceFile, isStrict) {
|
||||
if (isStrict === void 0) { isStrict = false; }
|
||||
var program = builderProgram.getProgram();
|
||||
var sourceFile = program.getSourceFile(fileName);
|
||||
var syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
|
||||
if (isStrict) {
|
||||
if (!builderProgram.builderProgramForLinter) {
|
||||
return [];
|
||||
}
|
||||
return builderProgram.builderProgramForLinter.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
return builderProgram.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
function hashDiagnostic(diagnostic) {
|
||||
@ -189340,14 +189382,15 @@ 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(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : [];
|
||||
currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.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 ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false;
|
||||
var isInSdk = etsLoaderPath ?
|
||||
ArkTSLinter_1_1.Utils.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)) {
|
||||
@ -189388,6 +189431,7 @@ var ts;
|
||||
ArkTSLinter_1_1.InteropTypescriptLinter.clearTsTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTrueSymbolAtLocationCache();
|
||||
ArkTSLinter_1_1.Utils.clearUtilsGlobalvariables();
|
||||
}
|
||||
function collectChangedFilesFromProgramState(state, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) {
|
||||
var changedFiles = new ts.Set(state.changedFilesSet);
|
||||
@ -189433,7 +189477,7 @@ var ts;
|
||||
function getTscDiagnostics(tscDiagnosticsLinter, sourceFiles) {
|
||||
var strictDiagnostics = new ts.Map();
|
||||
sourceFiles.forEach(function (file) {
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file.fileName);
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file);
|
||||
if (diagnostics.length !== 0) {
|
||||
strictDiagnostics.set(ts.normalizePath(file.fileName), diagnostics);
|
||||
}
|
||||
|
5
lib/typescriptServices.d.ts
vendored
5
lib/typescriptServices.d.ts
vendored
@ -9452,6 +9452,7 @@ declare namespace ts {
|
||||
function isLibraryType(type: Type): boolean;
|
||||
function hasLibraryType(node: Node): boolean;
|
||||
function isLibrarySymbol(sym: Symbol | undefined): boolean;
|
||||
function srcFilePathContainsDirectory(srcFile: SourceFile, dir: string): boolean;
|
||||
function pathContainsDirectory(targetPath: string, dir: string): boolean;
|
||||
function getScriptKind(srcFile: SourceFile): ScriptKind;
|
||||
function isStdLibraryType(type: Type): boolean;
|
||||
@ -9509,6 +9510,8 @@ 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<ts.Node>;
|
||||
function normalizePath(path: string): string;
|
||||
function clearUtilsGlobalvariables(): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9793,7 +9796,7 @@ declare namespace ts {
|
||||
constructor(program: BuilderProgram);
|
||||
getProgram(): Program;
|
||||
getBuilderProgram(): BuilderProgram;
|
||||
getStrictDiagnostics(fileName: string): Diagnostic[];
|
||||
getStrictDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
doAllGetDiagnostics(): void;
|
||||
}
|
||||
}
|
||||
|
@ -185184,10 +185184,18 @@ var ts;
|
||||
"BigInt64Array",
|
||||
"BigUint64Array",
|
||||
];
|
||||
var parentSymbolCache = new ts.Map();
|
||||
function getParentSymbolName(symbol) {
|
||||
parentSymbolCache = parentSymbolCache ? parentSymbolCache : new ts.Map();
|
||||
var cached = parentSymbolCache.get(symbol);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
var name = typeChecker.getFullyQualifiedName(symbol);
|
||||
var dotPosition = name.lastIndexOf(".");
|
||||
return (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
var result = (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
parentSymbolCache.set(symbol, result);
|
||||
return result;
|
||||
}
|
||||
Utils.getParentSymbolName = getParentSymbolName;
|
||||
function isGlobalSymbol(symbol) {
|
||||
@ -185305,19 +185313,19 @@ var ts;
|
||||
Utils.hasLibraryType = hasLibraryType;
|
||||
function isLibrarySymbol(sym) {
|
||||
if (sym && sym.declarations && sym.declarations.length > 0) {
|
||||
var srcFile = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile) {
|
||||
var srcFile_1 = sym.declarations[0].getSourceFile();
|
||||
if (!srcFile_1) {
|
||||
return false;
|
||||
}
|
||||
var fileName_2 = srcFile.fileName;
|
||||
var fileName_2 = srcFile_1.fileName;
|
||||
// Symbols from both *.ts and *.d.ts files should obey interop rules.
|
||||
// We disable such behavior for *.ts files in the test mode due to lack of 'ets'
|
||||
// extension support.
|
||||
var ext = ts.getAnyExtensionFromPath(fileName_2);
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return pathContainsDirectory(ts.normalizePath(fileName_2), ignore); }) ||
|
||||
var isThirdPartyCode = Utils.ARKTS_IGNORE_DIRS.some(function (ignore) { return srcFilePathContainsDirectory(srcFile_1, ignore); }) ||
|
||||
Utils.ARKTS_IGNORE_FILES.some(function (ignore) { return ts.getBaseFileName(fileName_2) === ignore; });
|
||||
var isEts = (ext === '.ets');
|
||||
var isTs = (ext === '.ts' && !srcFile.isDeclarationFile);
|
||||
var isTs = (ext === '.ts' && !srcFile_1.isDeclarationFile);
|
||||
var isStatic_2 = (isEts || (isTs && testMode)) && !isThirdPartyCode;
|
||||
var isStdLib = Utils.STANDARD_LIBRARIES.includes(ts.getBaseFileName(fileName_2).toLowerCase());
|
||||
// We still need to confirm support for certain API from the
|
||||
@ -185328,6 +185336,22 @@ var ts;
|
||||
return false;
|
||||
}
|
||||
Utils.isLibrarySymbol = isLibrarySymbol;
|
||||
var srcFilePathComponents = new ts.Map();
|
||||
function srcFilePathContainsDirectory(srcFile, dir) {
|
||||
var pathComps = srcFilePathComponents.get(srcFile);
|
||||
if (!pathComps) {
|
||||
pathComps = ts.getPathComponents(Utils.normalizePath(srcFile.fileName));
|
||||
srcFilePathComponents.set(srcFile, pathComps);
|
||||
}
|
||||
for (var _i = 0, pathComps_1 = pathComps; _i < pathComps_1.length; _i++) {
|
||||
var subdir = pathComps_1[_i];
|
||||
if (subdir === dir) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Utils.srcFilePathContainsDirectory = srcFilePathContainsDirectory;
|
||||
function pathContainsDirectory(targetPath, dir) {
|
||||
for (var _i = 0, _a = ts.getPathComponents(targetPath); _i < _a.length; _i++) {
|
||||
var subdir = _a[_i];
|
||||
@ -186087,6 +186111,25 @@ 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 = {}));
|
||||
})(ArkTSLinter_1_1 = ts.ArkTSLinter_1_1 || (ts.ArkTSLinter_1_1 = {}));
|
||||
})(ts || (ts = {}));
|
||||
@ -189189,8 +189232,8 @@ var ts;
|
||||
TSCCompiledProgram.prototype.getBuilderProgram = function () {
|
||||
return this.diagnosticsExtractor.nonStrictProgram;
|
||||
};
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (fileName) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(fileName);
|
||||
TSCCompiledProgram.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(sourceFile);
|
||||
};
|
||||
TSCCompiledProgram.prototype.doAllGetDiagnostics = function () {
|
||||
this.diagnosticsExtractor.doAllGetDiagnostics();
|
||||
@ -189205,10 +189248,10 @@ var ts;
|
||||
/**
|
||||
* Returns diagnostics which appear in strict compilation mode only
|
||||
*/
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (fileName) {
|
||||
TypeScriptDiagnosticsExtractor.prototype.getStrictDiagnostics = function (sourceFile) {
|
||||
// workaround for a tsc bug
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ false);
|
||||
var strict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ true).filter(function (diag) { return !(diag.length === 0 && diag.start === 0); });
|
||||
var nonStrict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ false);
|
||||
// collect hashes for later easier comparison
|
||||
var nonStrictHashes = nonStrict.reduce(function (result, value) {
|
||||
var hash = hashDiagnostic(value);
|
||||
@ -189235,21 +189278,20 @@ var ts;
|
||||
};
|
||||
return TypeScriptDiagnosticsExtractor;
|
||||
}());
|
||||
function getAllDiagnostics(builderProgram, fileName, isStrict) {
|
||||
/**
|
||||
* Actually, we only run `getSemanticDiagnostics`,
|
||||
* because the linter care only about strict errors, which do not include syntactic diagnostics.
|
||||
*/
|
||||
function getAllDiagnostics(builderProgram, sourceFile, isStrict) {
|
||||
if (isStrict === void 0) { isStrict = false; }
|
||||
var program = builderProgram.getProgram();
|
||||
var sourceFile = program.getSourceFile(fileName);
|
||||
var syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
|
||||
if (isStrict) {
|
||||
if (!builderProgram.builderProgramForLinter) {
|
||||
return [];
|
||||
}
|
||||
return builderProgram.builderProgramForLinter.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
return builderProgram.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(function (diag) { return diag.file === sourceFile; });
|
||||
}
|
||||
function hashDiagnostic(diagnostic) {
|
||||
@ -189340,14 +189382,15 @@ 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(ts.normalizePath(fileToLint.fileName))) !== null && _a !== void 0 ? _a : [];
|
||||
currentDiagnostics = (_a = tscStrictDiagnostics.get(ArkTSLinter_1_1.Utils.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 ? ts.normalizePath(fileToLint.fileName).indexOf(ts.resolvePath(etsLoaderPath, '../..')) === 0 : false;
|
||||
var isInSdk = etsLoaderPath ?
|
||||
ArkTSLinter_1_1.Utils.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)) {
|
||||
@ -189388,6 +189431,7 @@ var ts;
|
||||
ArkTSLinter_1_1.InteropTypescriptLinter.clearTsTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTypeChecker();
|
||||
ArkTSLinter_1_1.Utils.clearTrueSymbolAtLocationCache();
|
||||
ArkTSLinter_1_1.Utils.clearUtilsGlobalvariables();
|
||||
}
|
||||
function collectChangedFilesFromProgramState(state, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) {
|
||||
var changedFiles = new ts.Set(state.changedFilesSet);
|
||||
@ -189433,7 +189477,7 @@ var ts;
|
||||
function getTscDiagnostics(tscDiagnosticsLinter, sourceFiles) {
|
||||
var strictDiagnostics = new ts.Map();
|
||||
sourceFiles.forEach(function (file) {
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file.fileName);
|
||||
var diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file);
|
||||
if (diagnostics.length !== 0) {
|
||||
strictDiagnostics.set(ts.normalizePath(file.fileName), diagnostics);
|
||||
}
|
||||
|
@ -94,13 +94,14 @@ export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: Sourc
|
||||
linter.lint();
|
||||
|
||||
// Get list of bad nodes from the current run.
|
||||
currentDiagnostics = tscStrictDiagnostics.get(normalizePath(fileToLint.fileName)) ?? [];
|
||||
currentDiagnostics = tscStrictDiagnostics.get(Utils.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 ? normalizePath(fileToLint.fileName).indexOf(resolvePath(etsLoaderPath, '../..')) === 0 : false;
|
||||
const isInSdk = etsLoaderPath ?
|
||||
Utils.normalizePath(fileToLint.fileName).indexOf(resolvePath(etsLoaderPath, '../..')) === 0 : false;
|
||||
const isInOhModules = isOHModules(fileToLint.fileName);
|
||||
const tsImportSendableEnable = program.getCompilerOptions().tsImportSendableEnable;
|
||||
if (isKit || isInOhModules || (!tsImportSendableEnable && !isInSdk)) {
|
||||
@ -141,6 +142,7 @@ function releaseReferences(): void {
|
||||
InteropTypescriptLinter.clearTsTypeChecker();
|
||||
Utils.clearTypeChecker();
|
||||
Utils.clearTrueSymbolAtLocationCache();
|
||||
Utils.clearUtilsGlobalvariables();
|
||||
}
|
||||
|
||||
function collectChangedFilesFromProgramState(
|
||||
@ -202,7 +204,7 @@ function getTscDiagnostics(
|
||||
): Map<Diagnostic[]> {
|
||||
const strictDiagnostics = new Map<string, Diagnostic[]>();
|
||||
sourceFiles.forEach(file => {
|
||||
const diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file.fileName);
|
||||
const diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file);
|
||||
if (diagnostics.length !== 0) {
|
||||
strictDiagnostics.set(normalizePath(file.fileName), diagnostics);
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ export class TSCCompiledProgram {
|
||||
return this.diagnosticsExtractor.nonStrictProgram;
|
||||
}
|
||||
|
||||
public getStrictDiagnostics(fileName: string): Diagnostic[] {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(fileName);
|
||||
public getStrictDiagnostics(sourceFile: SourceFile): Diagnostic[] {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(sourceFile);
|
||||
}
|
||||
|
||||
public doAllGetDiagnostics(): void {
|
||||
@ -47,11 +47,11 @@ class TypeScriptDiagnosticsExtractor {
|
||||
/**
|
||||
* Returns diagnostics which appear in strict compilation mode only
|
||||
*/
|
||||
public getStrictDiagnostics(fileName: string): Diagnostic[] {
|
||||
public getStrictDiagnostics(sourceFile: SourceFile): Diagnostic[] {
|
||||
// workaround for a tsc bug
|
||||
const strict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ true).filter(
|
||||
const strict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ true).filter(
|
||||
diag => !(diag.length === 0 && diag.start === 0));
|
||||
const nonStrict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ false);
|
||||
const nonStrict = getAllDiagnostics(this.nonStrictProgram, sourceFile, /* isStrict */ false);
|
||||
|
||||
// collect hashes for later easier comparison
|
||||
const nonStrictHashes = nonStrict.reduce((result, value) => {
|
||||
@ -79,20 +79,19 @@ class TypeScriptDiagnosticsExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
function getAllDiagnostics(builderProgram: BuilderProgram, fileName: string, isStrict: boolean = false): Diagnostic[] {
|
||||
let program = builderProgram.getProgram();
|
||||
const sourceFile = program.getSourceFile(fileName);
|
||||
const syntacticDiagnostics: readonly DiagnosticWithLocation[] = program.getSyntacticDiagnostics(sourceFile);
|
||||
/**
|
||||
* Actually, we only run `getSemanticDiagnostics`,
|
||||
* because the linter care only about strict errors, which do not include syntactic diagnostics.
|
||||
*/
|
||||
function getAllDiagnostics(builderProgram: BuilderProgram, sourceFile: SourceFile, isStrict: boolean = false): Diagnostic[] {
|
||||
if (isStrict) {
|
||||
if (!builderProgram.builderProgramForLinter) {
|
||||
return [];
|
||||
}
|
||||
return builderProgram.builderProgramForLinter.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(diag => diag.file === sourceFile);
|
||||
}
|
||||
return builderProgram.getSemanticDiagnostics(sourceFile)
|
||||
.concat(syntacticDiagnostics)
|
||||
.filter(diag => diag.file === sourceFile);
|
||||
}
|
||||
|
||||
|
@ -1376,10 +1376,18 @@ export const TYPED_ARRAYS = [
|
||||
"BigUint64Array",
|
||||
];
|
||||
|
||||
let parentSymbolCache: ESMap<Symbol, string | undefined> | undefined = new Map<Symbol, string | undefined>();
|
||||
export function getParentSymbolName(symbol: Symbol): string | undefined {
|
||||
parentSymbolCache = parentSymbolCache ? parentSymbolCache : new Map<Symbol, string | undefined>();
|
||||
const cached = parentSymbolCache.get(symbol);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const name = typeChecker.getFullyQualifiedName(symbol);
|
||||
const dotPosition = name.lastIndexOf(".");
|
||||
return (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
const result = (dotPosition === -1) ? undefined : name.substring(0, dotPosition);
|
||||
parentSymbolCache.set(symbol, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function isGlobalSymbol(symbol: Symbol): boolean {
|
||||
@ -1507,7 +1515,7 @@ export function isLibrarySymbol(sym: Symbol | undefined) {
|
||||
// extension support.
|
||||
const ext = getAnyExtensionFromPath(fileName);
|
||||
const isThirdPartyCode =
|
||||
ARKTS_IGNORE_DIRS.some(ignore => pathContainsDirectory(normalizePath(fileName), ignore)) ||
|
||||
ARKTS_IGNORE_DIRS.some(ignore => srcFilePathContainsDirectory(srcFile, ignore)) ||
|
||||
ARKTS_IGNORE_FILES.some(ignore => getBaseFileName(fileName) === ignore);
|
||||
const isEts = (ext === '.ets');
|
||||
const isTs = (ext === '.ts' && !srcFile.isDeclarationFile);
|
||||
@ -1522,6 +1530,21 @@ export function isLibrarySymbol(sym: Symbol | undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const srcFilePathComponents = new Map<SourceFile, string[]>();
|
||||
export function srcFilePathContainsDirectory(srcFile: SourceFile, dir: string): boolean {
|
||||
let pathComps = srcFilePathComponents.get(srcFile);
|
||||
if (!pathComps) {
|
||||
pathComps = getPathComponents(Utils.normalizePath(srcFile.fileName));
|
||||
srcFilePathComponents.set(srcFile, pathComps);
|
||||
}
|
||||
for (const subdir of pathComps) {
|
||||
if (subdir === dir) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function pathContainsDirectory(targetPath: string, dir: string): boolean {
|
||||
for (const subdir of getPathComponents(targetPath)) {
|
||||
if (subdir === dir) {
|
||||
@ -2331,6 +2354,25 @@ export function searchFileExportDecl(sourceFile: ts.SourceFile, targetDecls?: ts
|
||||
});
|
||||
return exportDeclSet;
|
||||
}
|
||||
|
||||
let normalizedPathCache: ESMap<string, string> | undefined = new Map<string, string>();
|
||||
export function normalizePath(path: string): string {
|
||||
normalizedPathCache = normalizedPathCache ? normalizedPathCache : new Map<string, string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13398,6 +13398,7 @@ declare namespace ts {
|
||||
function isLibraryType(type: Type): boolean;
|
||||
function hasLibraryType(node: Node): boolean;
|
||||
function isLibrarySymbol(sym: Symbol | undefined): boolean;
|
||||
function srcFilePathContainsDirectory(srcFile: SourceFile, dir: string): boolean;
|
||||
function pathContainsDirectory(targetPath: string, dir: string): boolean;
|
||||
function getScriptKind(srcFile: SourceFile): ScriptKind;
|
||||
function isStdLibraryType(type: Type): boolean;
|
||||
@ -13455,6 +13456,8 @@ 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<ts.Node>;
|
||||
function normalizePath(path: string): string;
|
||||
function clearUtilsGlobalvariables(): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13739,7 +13742,7 @@ declare namespace ts {
|
||||
constructor(program: BuilderProgram);
|
||||
getProgram(): Program;
|
||||
getBuilderProgram(): BuilderProgram;
|
||||
getStrictDiagnostics(fileName: string): Diagnostic[];
|
||||
getStrictDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
doAllGetDiagnostics(): void;
|
||||
}
|
||||
}
|
||||
|
@ -9452,6 +9452,7 @@ declare namespace ts {
|
||||
function isLibraryType(type: Type): boolean;
|
||||
function hasLibraryType(node: Node): boolean;
|
||||
function isLibrarySymbol(sym: Symbol | undefined): boolean;
|
||||
function srcFilePathContainsDirectory(srcFile: SourceFile, dir: string): boolean;
|
||||
function pathContainsDirectory(targetPath: string, dir: string): boolean;
|
||||
function getScriptKind(srcFile: SourceFile): ScriptKind;
|
||||
function isStdLibraryType(type: Type): boolean;
|
||||
@ -9509,6 +9510,8 @@ 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<ts.Node>;
|
||||
function normalizePath(path: string): string;
|
||||
function clearUtilsGlobalvariables(): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9793,7 +9796,7 @@ declare namespace ts {
|
||||
constructor(program: BuilderProgram);
|
||||
getProgram(): Program;
|
||||
getBuilderProgram(): BuilderProgram;
|
||||
getStrictDiagnostics(fileName: string): Diagnostic[];
|
||||
getStrictDiagnostics(sourceFile: SourceFile): Diagnostic[];
|
||||
doAllGetDiagnostics(): void;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,13 @@
|
||||
"reportLine": 10,
|
||||
"reportColumn": 22,
|
||||
"description": "'injectEvent' is system api"
|
||||
},
|
||||
{
|
||||
"origin": "WARN: ArkTS:WARN File: /entry/src/main/ets/pages/cases/#13912.ets:10:22\n To use this API, you need to apply for the permissions: ohos.permission.INJECT_INPUT_EVENT\n\n",
|
||||
"severity": 1,
|
||||
"reportLine": 10,
|
||||
"reportColumn": 22,
|
||||
"description": "To use this API, you need to apply for the permissions: ohos.permission.INJECT_INPUT_EVENT"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user