From fdf5636fc54008e7de6e80bd25347306dead6653 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Thu, 28 Dec 2023 17:41:09 +0800 Subject: [PATCH] Revert "fix parallal synchronous problem" Issue: https://gitee.com/openharmony/third_party_typescript/issues/I8S55V Signed-off-by: xucheng46 Change-Id: I8ddf99de835b839362557ef5f3f560c685103d9e --- compiler/src/do_arkTS_linter.ts | 60 +++++++++++---------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/compiler/src/do_arkTS_linter.ts b/compiler/src/do_arkTS_linter.ts index f2009efa9..6fd146fc2 100644 --- a/compiler/src/do_arkTS_linter.ts +++ b/compiler/src/do_arkTS_linter.ts @@ -36,9 +36,7 @@ const spaceNumBeforeJsonLine = 2; const sleepInterval = 100; const filteredDiagnosticCode = -2; let worker: Worker | undefined = undefined; -let tsDiagnostics: ArkTSDiagnostic[] | undefined = undefined; -let strictArkTSDiagnostics: Map | undefined = undefined; -let processArkTSLinterDiagnostic = (): void => {}; +let tsDiagnostics: ArkTSDiagnostic[] = []; interface OutputInfo { categoryInfo: string | undefined; @@ -243,23 +241,6 @@ export function doArkTSLinterParallel(arkTSVersion: ArkTSVersion, arkTSMode: Ark didArkTSLinter = true; - let processArkTSLinterDiagnostic = (): void => { - let diagnostics: ArkTSDiagnostic[] = filterStaticDiagnostics(); - removeOutputFile(); - if (diagnostics.length === 0) { - arkTSLinterDiagnosticProcessed = true; - return; - } - if (arkTSMode === ArkTSLinterMode.COMPATIBLE_MODE) { - processArkTSLinterReportAsWarning(diagnostics, printDiagnostic, shouldWriteFile); - } else { - processArkTSLinterReportAsError(diagnostics, printDiagnostic); - } - arkTSDiagnostics = diagnostics; - cacheFilePath = cacheFile; - arkTSLinterDiagnosticProcessed = true; - }; - const workerData = { workerData: { arkTSVersion: arkTSVersion, @@ -273,18 +254,23 @@ export function doArkTSLinterParallel(arkTSVersion: ArkTSVersion, arkTSMode: Ark }; worker = new Worker(path.resolve(__dirname, './do_arkTS_linter_parallel.js'), workerData); worker.on('message', (strictDiagnostics: Map) => { - strictArkTSDiagnostics = strictDiagnostics; - if (tsDiagnostics !== undefined) { - processArkTSLinterDiagnostic(); - cleanProcessArkTSLinterDiagnostic(); + let diagnostics: ArkTSDiagnostic[] = filterStaticDiagnostics(strictDiagnostics); + removeOutputFile(); + if (diagnostics.length === 0) { + arkTSLinterDiagnosticProcessed = true; + return; + } + if (arkTSMode === ArkTSLinterMode.COMPATIBLE_MODE) { + processArkTSLinterReportAsWarning(diagnostics, printDiagnostic, shouldWriteFile); + } else { + processArkTSLinterReportAsError(diagnostics, printDiagnostic); } + arkTSDiagnostics = diagnostics; + cacheFilePath = cacheFile; + arkTSLinterDiagnosticProcessed = true; }); } -function cleanProcessArkTSLinterDiagnostic(): void { - processArkTSLinterDiagnostic = (): void => {}; -} - export function updateFileCache(): void { if (!didArkTSLinter) { return; @@ -313,10 +299,6 @@ export async function waitArkTSLinterFinished(): Promise { if (worker === undefined) { return; } - if ((!arkTSLinterDiagnosticProcessed) && tsDiagnostics && strictArkTSDiagnostics) { - processArkTSLinterDiagnostic(); - cleanProcessArkTSLinterDiagnostic(); - } let sleep = async (time): Promise => { return new Promise(r => setTimeout(r, time)); }; @@ -329,10 +311,6 @@ export async function waitArkTSLinterFinished(): Promise { export function sendtsDiagnostic(allDiagnostics: ts.Diagnostic[]):void { tsDiagnostics = processDiagnosticsToArkTSDiagnosticInfo(allDiagnostics.filter(diag=>diag.file.scriptKind === ts.ScriptKind.ETS)); - if (strictArkTSDiagnostics !== undefined) { - processArkTSLinterDiagnostic(); - cleanProcessArkTSLinterDiagnostic(); - } } export function processDiagnosticsToArkTSDiagnosticInfo(diagnostics: ts.Diagnostic[]): ArkTSDiagnostic[] { @@ -357,12 +335,13 @@ export function processDiagnosticsToArkTSDiagnosticInfo(diagnostics: ts.Diagnost return diagnosticsInfo; } -function filterStaticDiagnostics(): ArkTSDiagnostic[] { +function filterStaticDiagnostics( + strictDiagnostics: Map): ArkTSDiagnostic[] { tsDiagnostics.forEach(diag => { if (!diag.fileName) { return; } - strictArkTSDiagnostics.get(diag.fileName)?.strictDiagnostics.forEach( + strictDiagnostics.get(diag.fileName)?.strictDiagnostics.forEach( strictDiag => { if (strictDiag.code === diag.code && strictDiag.start === diag.start && strictDiag.length === diag.length) { strictDiag.code = filteredDiagnosticCode; @@ -373,7 +352,7 @@ function filterStaticDiagnostics(): ArkTSDiagnostic[] { }); let resultDiagnostics: ArkTSDiagnostic[] = []; - strictArkTSDiagnostics.forEach( + strictDiagnostics.forEach( (value) => { value.strictDiagnostics.forEach( diagnostic => { @@ -387,7 +366,6 @@ function filterStaticDiagnostics(): ArkTSDiagnostic[] { } ); - tsDiagnostics = undefined; - strictArkTSDiagnostics = undefined; + tsDiagnostics = []; return resultDiagnostics; } -- Gitee