mirror of
https://gitee.com/openharmony/third_party_typescript
synced 2024-11-23 15:00:36 +00:00
!376 [ArkTSLinter] Blue sync with yellow
Merge pull request !376 from ironrain/work_0510_sync
This commit is contained in:
commit
dc975fe87f
@ -193865,7 +193865,7 @@ var ts;
|
||||
function isReadonlyArrayType(tsType) {
|
||||
var _a, _b, _c;
|
||||
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === 'ReadonlyArray'));
|
||||
}
|
||||
Utils.isReadonlyArrayType = isReadonlyArrayType;
|
||||
function isTypedArray(tsType) {
|
||||
@ -197347,10 +197347,9 @@ var ts;
|
||||
return _this.checkInRange(rangesToFilter, pos);
|
||||
},
|
||||
_a), this.libraryTypeCallDiagnosticChecker);
|
||||
for (var _i = 0, diagnosticMessages_2 = diagnosticMessages; _i < diagnosticMessages_2.length; _i++) {
|
||||
var msgChain = diagnosticMessages_2[_i];
|
||||
diagnosticMessages.forEach(function (msgChain) {
|
||||
TypeScriptLinter.filteredDiagnosticMessages.push(msgChain);
|
||||
}
|
||||
});
|
||||
};
|
||||
TypeScriptLinter.prototype.handleNewExpression = function (node) {
|
||||
var tsNewExpr = node;
|
||||
@ -198055,15 +198054,17 @@ var ts;
|
||||
};
|
||||
ArkTSLinterTimePrinter.prototype.formatMapAsTable = function (map) {
|
||||
if (!map.has(TimePhase.START)) {
|
||||
return "ArkTSLinterTimePrinter: START phase is not exist!";
|
||||
return 'ArkTSLinterTimePrinter: START phase is not exist!';
|
||||
}
|
||||
var maxKeyLength = 0, lastVal = 0, sum = 0;
|
||||
var maxKeyLength = 0;
|
||||
var lastVal = 0;
|
||||
var sum = 0;
|
||||
var printMap = new ts.Map(map);
|
||||
printMap.forEach(function (value, key) {
|
||||
maxKeyLength = Math.max(maxKeyLength, key.toString().length);
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var relativeVal = value - lastVal;
|
||||
if (key != TimePhase.GET_PROGRAM) {
|
||||
if (key !== TimePhase.GET_PROGRAM) {
|
||||
sum += relativeVal;
|
||||
}
|
||||
printMap.set(key, relativeVal / 1000.0);
|
||||
@ -198073,7 +198074,7 @@ var ts;
|
||||
printMap.set('total', sum / 1000.0);
|
||||
var table = '';
|
||||
printMap.forEach(function (value, key) {
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var paddedKey = key.toString().padEnd(maxKeyLength, ' ');
|
||||
table += "".concat(paddedKey, " | ").concat(value.toString(), "\n");
|
||||
}
|
||||
|
@ -193610,7 +193610,7 @@ var ts;
|
||||
function isReadonlyArrayType(tsType) {
|
||||
var _a, _b, _c;
|
||||
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === 'ReadonlyArray'));
|
||||
}
|
||||
Utils.isReadonlyArrayType = isReadonlyArrayType;
|
||||
function isTypedArray(tsType) {
|
||||
@ -197092,10 +197092,9 @@ var ts;
|
||||
return _this.checkInRange(rangesToFilter, pos);
|
||||
},
|
||||
_a), this.libraryTypeCallDiagnosticChecker);
|
||||
for (var _i = 0, diagnosticMessages_2 = diagnosticMessages; _i < diagnosticMessages_2.length; _i++) {
|
||||
var msgChain = diagnosticMessages_2[_i];
|
||||
diagnosticMessages.forEach(function (msgChain) {
|
||||
TypeScriptLinter.filteredDiagnosticMessages.push(msgChain);
|
||||
}
|
||||
});
|
||||
};
|
||||
TypeScriptLinter.prototype.handleNewExpression = function (node) {
|
||||
var tsNewExpr = node;
|
||||
@ -197800,15 +197799,17 @@ var ts;
|
||||
};
|
||||
ArkTSLinterTimePrinter.prototype.formatMapAsTable = function (map) {
|
||||
if (!map.has(TimePhase.START)) {
|
||||
return "ArkTSLinterTimePrinter: START phase is not exist!";
|
||||
return 'ArkTSLinterTimePrinter: START phase is not exist!';
|
||||
}
|
||||
var maxKeyLength = 0, lastVal = 0, sum = 0;
|
||||
var maxKeyLength = 0;
|
||||
var lastVal = 0;
|
||||
var sum = 0;
|
||||
var printMap = new ts.Map(map);
|
||||
printMap.forEach(function (value, key) {
|
||||
maxKeyLength = Math.max(maxKeyLength, key.toString().length);
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var relativeVal = value - lastVal;
|
||||
if (key != TimePhase.GET_PROGRAM) {
|
||||
if (key !== TimePhase.GET_PROGRAM) {
|
||||
sum += relativeVal;
|
||||
}
|
||||
printMap.set(key, relativeVal / 1000.0);
|
||||
@ -197818,7 +197819,7 @@ var ts;
|
||||
printMap.set('total', sum / 1000.0);
|
||||
var table = '';
|
||||
printMap.forEach(function (value, key) {
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var paddedKey = key.toString().padEnd(maxKeyLength, ' ');
|
||||
table += "".concat(paddedKey, " | ").concat(value.toString(), "\n");
|
||||
}
|
||||
|
@ -182704,7 +182704,7 @@ var ts;
|
||||
function isReadonlyArrayType(tsType) {
|
||||
var _a, _b, _c;
|
||||
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === 'ReadonlyArray'));
|
||||
}
|
||||
Utils.isReadonlyArrayType = isReadonlyArrayType;
|
||||
function isTypedArray(tsType) {
|
||||
@ -186186,10 +186186,9 @@ var ts;
|
||||
return _this.checkInRange(rangesToFilter, pos);
|
||||
},
|
||||
_a), this.libraryTypeCallDiagnosticChecker);
|
||||
for (var _i = 0, diagnosticMessages_2 = diagnosticMessages; _i < diagnosticMessages_2.length; _i++) {
|
||||
var msgChain = diagnosticMessages_2[_i];
|
||||
diagnosticMessages.forEach(function (msgChain) {
|
||||
TypeScriptLinter.filteredDiagnosticMessages.push(msgChain);
|
||||
}
|
||||
});
|
||||
};
|
||||
TypeScriptLinter.prototype.handleNewExpression = function (node) {
|
||||
var tsNewExpr = node;
|
||||
@ -186894,15 +186893,17 @@ var ts;
|
||||
};
|
||||
ArkTSLinterTimePrinter.prototype.formatMapAsTable = function (map) {
|
||||
if (!map.has(TimePhase.START)) {
|
||||
return "ArkTSLinterTimePrinter: START phase is not exist!";
|
||||
return 'ArkTSLinterTimePrinter: START phase is not exist!';
|
||||
}
|
||||
var maxKeyLength = 0, lastVal = 0, sum = 0;
|
||||
var maxKeyLength = 0;
|
||||
var lastVal = 0;
|
||||
var sum = 0;
|
||||
var printMap = new ts.Map(map);
|
||||
printMap.forEach(function (value, key) {
|
||||
maxKeyLength = Math.max(maxKeyLength, key.toString().length);
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var relativeVal = value - lastVal;
|
||||
if (key != TimePhase.GET_PROGRAM) {
|
||||
if (key !== TimePhase.GET_PROGRAM) {
|
||||
sum += relativeVal;
|
||||
}
|
||||
printMap.set(key, relativeVal / 1000.0);
|
||||
@ -186912,7 +186913,7 @@ var ts;
|
||||
printMap.set('total', sum / 1000.0);
|
||||
var table = '';
|
||||
printMap.forEach(function (value, key) {
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var paddedKey = key.toString().padEnd(maxKeyLength, ' ');
|
||||
table += "".concat(paddedKey, " | ").concat(value.toString(), "\n");
|
||||
}
|
||||
|
@ -182704,7 +182704,7 @@ var ts;
|
||||
function isReadonlyArrayType(tsType) {
|
||||
var _a, _b, _c;
|
||||
return (isTypeReference(tsType) && ((_a = tsType.typeArguments) === null || _a === void 0 ? void 0 : _a.length) === 1 && ((_b = tsType.target.typeParameters) === null || _b === void 0 ? void 0 : _b.length) === 1 &&
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === "ReadonlyArray"));
|
||||
(((_c = tsType.getSymbol()) === null || _c === void 0 ? void 0 : _c.getName()) === 'ReadonlyArray'));
|
||||
}
|
||||
Utils.isReadonlyArrayType = isReadonlyArrayType;
|
||||
function isTypedArray(tsType) {
|
||||
@ -186186,10 +186186,9 @@ var ts;
|
||||
return _this.checkInRange(rangesToFilter, pos);
|
||||
},
|
||||
_a), this.libraryTypeCallDiagnosticChecker);
|
||||
for (var _i = 0, diagnosticMessages_2 = diagnosticMessages; _i < diagnosticMessages_2.length; _i++) {
|
||||
var msgChain = diagnosticMessages_2[_i];
|
||||
diagnosticMessages.forEach(function (msgChain) {
|
||||
TypeScriptLinter.filteredDiagnosticMessages.push(msgChain);
|
||||
}
|
||||
});
|
||||
};
|
||||
TypeScriptLinter.prototype.handleNewExpression = function (node) {
|
||||
var tsNewExpr = node;
|
||||
@ -186894,15 +186893,17 @@ var ts;
|
||||
};
|
||||
ArkTSLinterTimePrinter.prototype.formatMapAsTable = function (map) {
|
||||
if (!map.has(TimePhase.START)) {
|
||||
return "ArkTSLinterTimePrinter: START phase is not exist!";
|
||||
return 'ArkTSLinterTimePrinter: START phase is not exist!';
|
||||
}
|
||||
var maxKeyLength = 0, lastVal = 0, sum = 0;
|
||||
var maxKeyLength = 0;
|
||||
var lastVal = 0;
|
||||
var sum = 0;
|
||||
var printMap = new ts.Map(map);
|
||||
printMap.forEach(function (value, key) {
|
||||
maxKeyLength = Math.max(maxKeyLength, key.toString().length);
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var relativeVal = value - lastVal;
|
||||
if (key != TimePhase.GET_PROGRAM) {
|
||||
if (key !== TimePhase.GET_PROGRAM) {
|
||||
sum += relativeVal;
|
||||
}
|
||||
printMap.set(key, relativeVal / 1000.0);
|
||||
@ -186912,7 +186913,7 @@ var ts;
|
||||
printMap.set('total', sum / 1000.0);
|
||||
var table = '';
|
||||
printMap.forEach(function (value, key) {
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
var paddedKey = key.toString().padEnd(maxKeyLength, ' ');
|
||||
table += "".concat(paddedKey, " | ").concat(value.toString(), "\n");
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ function makeDiag(category: DiagnosticCategory, code: number, file: SourceFile,
|
||||
export function translateDiag(srcFile: SourceFile, problemInfo: ProblemInfo): Diagnostic {
|
||||
const LINTER_MSG_CODE_START = -1;
|
||||
const severity = (problemInfo.severity === Utils.ProblemSeverity.ERROR ? DiagnosticCategory.Error : DiagnosticCategory.Warning);
|
||||
return makeDiag(severity, LINTER_MSG_CODE_START /*+ problemInfo.ruleTag */, srcFile , problemInfo.start, (problemInfo.end - problemInfo.start + 1), problemInfo.rule);
|
||||
return makeDiag(severity, LINTER_MSG_CODE_START /*+ problemInfo.ruleTag */, srcFile, problemInfo.start, (problemInfo.end - problemInfo.start + 1), problemInfo.rule);
|
||||
}
|
||||
|
||||
export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: SourceFile,
|
||||
@ -55,7 +55,7 @@ export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: Sourc
|
||||
tscDiagnosticsLinter.doAllGetDiagnostics();
|
||||
|
||||
let srcFiles: SourceFile[] = [];
|
||||
if(!!srcFile) {
|
||||
if (!!srcFile) {
|
||||
srcFiles.push(srcFile);
|
||||
} else {
|
||||
srcFiles = program.getSourceFiles() as SourceFile[];
|
||||
@ -66,9 +66,9 @@ export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: Sourc
|
||||
|
||||
TypeScriptLinter.initGlobals();
|
||||
|
||||
for(const fileToLint of srcFiles) {
|
||||
for (const fileToLint of srcFiles) {
|
||||
TypeScriptLinter.initStatic();
|
||||
if(TypeScriptLinter.lintEtsOnly && fileToLint.scriptKind !==ScriptKind.ETS) {
|
||||
if (TypeScriptLinter.lintEtsOnly && fileToLint.scriptKind !== ScriptKind.ETS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ export class TSCCompiledProgram {
|
||||
}
|
||||
|
||||
public getProgram(): Program {
|
||||
return this.diagnosticsExtractor.nonStrictProgram.getProgram()
|
||||
return this.diagnosticsExtractor.nonStrictProgram.getProgram();
|
||||
}
|
||||
|
||||
public getBuilderProgram(): BuilderProgram {
|
||||
@ -35,7 +35,7 @@ export class TSCCompiledProgram {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(fileName);
|
||||
}
|
||||
|
||||
public doAllGetDiagnostics() {
|
||||
public doAllGetDiagnostics(): void {
|
||||
this.diagnosticsExtractor.doAllGetDiagnostics();
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,7 @@ class TypeScriptDiagnosticsExtractor {
|
||||
/**
|
||||
* Returns diagnostics which appear in strict compilation mode only
|
||||
*/
|
||||
public getStrictDiagnostics(fileName: string): Diagnostic[] {
|
||||
public getStrictDiagnostics(fileName: string): Diagnostic[] {
|
||||
// workaround for a tsc bug
|
||||
const strict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ true).filter(
|
||||
diag => !(diag.length === 0 && diag.start === 0));
|
||||
@ -68,7 +68,7 @@ class TypeScriptDiagnosticsExtractor {
|
||||
});
|
||||
}
|
||||
|
||||
public doAllGetDiagnostics() {
|
||||
public doAllGetDiagnostics(): void {
|
||||
const timePrinterInstance = ts.ArkTSLinterTimePrinter.getInstance();
|
||||
this.nonStrictProgram.getSemanticDiagnostics();
|
||||
timePrinterInstance.appendTime(ts.TimePhase.NON_STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS);
|
||||
|
@ -23,7 +23,7 @@ function makeDiag(category: DiagnosticCategory, code: number, file: SourceFile,
|
||||
export function translateDiag(srcFile: SourceFile, problemInfo: ProblemInfo): Diagnostic {
|
||||
const LINTER_MSG_CODE_START = -1;
|
||||
const severity = (problemInfo.severity === Common.ProblemSeverity.ERROR ? DiagnosticCategory.Error : DiagnosticCategory.Warning);
|
||||
return makeDiag(severity, LINTER_MSG_CODE_START /*+ problemInfo.ruleTag */, srcFile , problemInfo.start, (problemInfo.end - problemInfo.start + 1), problemInfo.rule);
|
||||
return makeDiag(severity, LINTER_MSG_CODE_START /*+ problemInfo.ruleTag */, srcFile, problemInfo.start, (problemInfo.end - problemInfo.start + 1), problemInfo.rule);
|
||||
}
|
||||
|
||||
export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: SourceFile,
|
||||
@ -55,7 +55,7 @@ export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: Sourc
|
||||
tscDiagnosticsLinter.doAllGetDiagnostics();
|
||||
|
||||
let srcFiles: SourceFile[] = [];
|
||||
if(!!srcFile) {
|
||||
if (!!srcFile) {
|
||||
srcFiles.push(srcFile);
|
||||
} else {
|
||||
srcFiles = program.getSourceFiles() as SourceFile[];
|
||||
@ -66,9 +66,9 @@ export function runArkTSLinter(tsBuilderProgram: BuilderProgram, srcFile?: Sourc
|
||||
|
||||
TypeScriptLinter.initGlobals();
|
||||
|
||||
for(const fileToLint of srcFiles) {
|
||||
for (const fileToLint of srcFiles) {
|
||||
TypeScriptLinter.initStatic();
|
||||
if(TypeScriptLinter.lintEtsOnly && fileToLint.scriptKind !==ScriptKind.ETS) {
|
||||
if (TypeScriptLinter.lintEtsOnly && fileToLint.scriptKind !== ScriptKind.ETS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ export class TSCCompiledProgram {
|
||||
}
|
||||
|
||||
public getProgram(): Program {
|
||||
return this.diagnosticsExtractor.nonStrictProgram.getProgram()
|
||||
return this.diagnosticsExtractor.nonStrictProgram.getProgram();
|
||||
}
|
||||
|
||||
public getBuilderProgram(): BuilderProgram {
|
||||
@ -35,7 +35,7 @@ export class TSCCompiledProgram {
|
||||
return this.diagnosticsExtractor.getStrictDiagnostics(fileName);
|
||||
}
|
||||
|
||||
public doAllGetDiagnostics() {
|
||||
public doAllGetDiagnostics(): void {
|
||||
this.diagnosticsExtractor.doAllGetDiagnostics();
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,7 @@ class TypeScriptDiagnosticsExtractor {
|
||||
/**
|
||||
* Returns diagnostics which appear in strict compilation mode only
|
||||
*/
|
||||
public getStrictDiagnostics(fileName: string): Diagnostic[] {
|
||||
public getStrictDiagnostics(fileName: string): Diagnostic[] {
|
||||
// workaround for a tsc bug
|
||||
const strict = getAllDiagnostics(this.nonStrictProgram, fileName, /* isStrict */ true).filter(
|
||||
diag => !(diag.length === 0 && diag.start === 0));
|
||||
@ -68,7 +68,7 @@ class TypeScriptDiagnosticsExtractor {
|
||||
});
|
||||
}
|
||||
|
||||
public doAllGetDiagnostics() {
|
||||
public doAllGetDiagnostics(): void {
|
||||
const timePrinterInstance = ts.ArkTSLinterTimePrinter.getInstance();
|
||||
this.nonStrictProgram.getSemanticDiagnostics();
|
||||
timePrinterInstance.appendTime(ts.TimePhase.NON_STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS);
|
||||
|
@ -851,7 +851,7 @@ export class TypeScriptLinter {
|
||||
return false;
|
||||
}
|
||||
|
||||
const checkDiagnostic = (val: Diagnostic) => {
|
||||
const checkDiagnostic = (val: Diagnostic): boolean => {
|
||||
const checkInRange = filters[val.code];
|
||||
if (!checkInRange) {
|
||||
return true;
|
||||
@ -1974,10 +1974,10 @@ export class TypeScriptLinter {
|
||||
let rangesToFilter: { begin: number, end: number }[] = [];
|
||||
if (nonFilteringRanges.length !== 0) {
|
||||
let rangesSize = nonFilteringRanges.length;
|
||||
rangesToFilter.push({ begin: callExpr.arguments.pos, end: nonFilteringRanges[0].begin })
|
||||
rangesToFilter.push({ begin: nonFilteringRanges[rangesSize - 1].end, end: callExpr.arguments.end })
|
||||
rangesToFilter.push({ begin: callExpr.arguments.pos, end: nonFilteringRanges[0].begin });
|
||||
rangesToFilter.push({ begin: nonFilteringRanges[rangesSize - 1].end, end: callExpr.arguments.end });
|
||||
for (let i = 0; i < rangesSize - 1; i++) {
|
||||
rangesToFilter.push({ begin: nonFilteringRanges[i].end, end: nonFilteringRanges[i + 1].begin })
|
||||
rangesToFilter.push({ begin: nonFilteringRanges[i].end, end: nonFilteringRanges[i + 1].begin });
|
||||
}
|
||||
} else {
|
||||
rangesToFilter.push({ begin: callExpr.arguments.pos, end: callExpr.arguments.end })
|
||||
@ -1997,9 +1997,9 @@ export class TypeScriptLinter {
|
||||
this.libraryTypeCallDiagnosticChecker
|
||||
);
|
||||
|
||||
for (const msgChain of diagnosticMessages) {
|
||||
diagnosticMessages.forEach(msgChain => {
|
||||
TypeScriptLinter.filteredDiagnosticMessages.push(msgChain);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private handleNewExpression(node: Node): void {
|
||||
|
@ -478,7 +478,7 @@ export function isGenericArrayType(tsType: Type): tsType is TypeReference {
|
||||
export function isReadonlyArrayType(tsType: Type): boolean {
|
||||
return (
|
||||
isTypeReference(tsType) && tsType.typeArguments?.length === 1 && tsType.target.typeParameters?.length === 1 &&
|
||||
(tsType.getSymbol()?.getName() === "ReadonlyArray")
|
||||
(tsType.getSymbol()?.getName() === 'ReadonlyArray')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
namespace ts {
|
||||
|
||||
export enum TimePhase {
|
||||
START= "start",
|
||||
GET_PROGRAM= "getProgram(not ArkTSLinter)",
|
||||
UPDATE_ERROR_FILE= "updateErrorFile",
|
||||
INIT= "init",
|
||||
STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS= "strictProgramGetSemanticDiagnostics",
|
||||
NON_STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS= "nonStrictProgramGetSemanticDiagnostics",
|
||||
NON_STRICT_PROGRAM_GET_SYNTACTIC_DIAGNOSTICS= "nonStrictProgramGetSyntacticDiagnostics",
|
||||
GET_TSC_DIAGNOSTICS= "getTscDiagnostics",
|
||||
EMIT_BUILD_INFO= "emitBuildInfo",
|
||||
LINT= "lint"
|
||||
START = 'start',
|
||||
GET_PROGRAM = 'getProgram(not ArkTSLinter)',
|
||||
UPDATE_ERROR_FILE = 'updateErrorFile',
|
||||
INIT = 'init',
|
||||
STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS = 'strictProgramGetSemanticDiagnostics',
|
||||
NON_STRICT_PROGRAM_GET_SEMANTIC_DIAGNOSTICS = 'nonStrictProgramGetSemanticDiagnostics',
|
||||
NON_STRICT_PROGRAM_GET_SYNTACTIC_DIAGNOSTICS = 'nonStrictProgramGetSyntacticDiagnostics',
|
||||
GET_TSC_DIAGNOSTICS = 'getTscDiagnostics',
|
||||
EMIT_BUILD_INFO = 'emitBuildInfo',
|
||||
LINT = 'lint'
|
||||
}
|
||||
|
||||
export class ArkTSLinterTimePrinter {
|
||||
private static instance?: ArkTSLinterTimePrinter
|
||||
private static instance?: ArkTSLinterTimePrinter;
|
||||
private arkTSTimePrintSwitch: boolean;
|
||||
private timeMap = new Map<string, number>();
|
||||
private constructor(ArkTSTimePrintSwitch: boolean = false) {
|
||||
@ -23,20 +23,20 @@ export class ArkTSLinterTimePrinter {
|
||||
|
||||
public static getInstance(): ArkTSLinterTimePrinter {
|
||||
if (!ArkTSLinterTimePrinter.instance) {
|
||||
ArkTSLinterTimePrinter.instance = new ArkTSLinterTimePrinter()
|
||||
ArkTSLinterTimePrinter.instance = new ArkTSLinterTimePrinter();
|
||||
}
|
||||
return ArkTSLinterTimePrinter.instance
|
||||
return ArkTSLinterTimePrinter.instance;
|
||||
}
|
||||
|
||||
public static destroyInstance() {
|
||||
public static destroyInstance(): void {
|
||||
ArkTSLinterTimePrinter.instance = undefined;
|
||||
}
|
||||
|
||||
public setArkTSTimePrintSwitch(arkTSTimePrintSwitch: boolean) {
|
||||
this.arkTSTimePrintSwitch = arkTSTimePrintSwitch
|
||||
public setArkTSTimePrintSwitch(arkTSTimePrintSwitch: boolean): void {
|
||||
this.arkTSTimePrintSwitch = arkTSTimePrintSwitch;
|
||||
}
|
||||
|
||||
public appendTime(key: string) {
|
||||
public appendTime(key: string): void {
|
||||
if (this.arkTSTimePrintSwitch) {
|
||||
this.timeMap.set(key, Date.now());
|
||||
}
|
||||
@ -44,15 +44,17 @@ export class ArkTSLinterTimePrinter {
|
||||
|
||||
private formatMapAsTable(map: Map<number>): string {
|
||||
if (!map.has(TimePhase.START)) {
|
||||
return "ArkTSLinterTimePrinter: START phase is not exist!";
|
||||
return 'ArkTSLinterTimePrinter: START phase is not exist!';
|
||||
}
|
||||
let maxKeyLength = 0, lastVal = 0, sum = 0;
|
||||
let maxKeyLength = 0;
|
||||
let lastVal = 0;
|
||||
let sum = 0;
|
||||
let printMap = new Map(map);
|
||||
printMap.forEach((value, key) => {
|
||||
maxKeyLength = Math.max(maxKeyLength, key.toString().length);
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
let relativeVal = value - lastVal;
|
||||
if (key != TimePhase.GET_PROGRAM) {
|
||||
if (key !== TimePhase.GET_PROGRAM) {
|
||||
sum += relativeVal;
|
||||
}
|
||||
printMap.set(key, relativeVal / 1000.0);
|
||||
@ -63,7 +65,7 @@ export class ArkTSLinterTimePrinter {
|
||||
|
||||
let table = '';
|
||||
printMap.forEach((value, key) => {
|
||||
if (key != TimePhase.START) {
|
||||
if (key !== TimePhase.START) {
|
||||
const paddedKey = key.toString().padEnd(maxKeyLength, ' ');
|
||||
table += `${paddedKey} | ${value.toString()}\n`;
|
||||
}
|
||||
@ -74,7 +76,7 @@ export class ArkTSLinterTimePrinter {
|
||||
return `${header}${separator}${table}`;
|
||||
}
|
||||
|
||||
public printTimes() {
|
||||
public printTimes(): void {
|
||||
if (this.arkTSTimePrintSwitch) {
|
||||
const formattedMap = this.formatMapAsTable(this.timeMap);
|
||||
console.log(formattedMap);
|
||||
|
Loading…
Reference in New Issue
Block a user