From 7f31db4a266b80f3d27cdd976e26227992f288b9 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Thu, 28 Dec 2023 01:55:40 +0000 Subject: [PATCH 01/19] fix memory leak Signed-off-by: shixiaowei4 Change-Id: I11ca7f015f52a5da51bf25ea1cdec05034203d11 --- compiler/src/ark_utils.ts | 13 +++++--- .../ark_compiler/common/ob_config_resolver.ts | 5 ++++ .../ark_compiler/common/process_ark_config.ts | 30 +++++++++++-------- .../module/module_hotreload_mode.ts | 3 +- .../fast_build/ark_compiler/process_mock.ts | 2 +- .../ark_compiler/rollup-plugin-gen-abc.ts | 4 ++- .../src/fast_build/ark_compiler/transform.ts | 4 +++ compiler/src/fast_build/ark_compiler/utils.ts | 16 +++++++--- compiler/src/process_kit_import.ts | 10 +++++-- compiler/src/utils.ts | 9 ++++-- .../common/process_ark_config.test.ts | 16 +++++----- 11 files changed, 73 insertions(+), 39 deletions(-) diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index 028e969c..2755726a 100644 --- a/compiler/src/ark_utils.ts +++ b/compiler/src/ark_utils.ts @@ -18,7 +18,7 @@ import fs from 'fs'; import type sourceMap from 'source-map'; import { minify, MinifyOutput } from 'terser'; -import { ArkObfuscator, getMapFromJson } from "arkguard" +import { getMapFromJson } from "arkguard" import { OH_MODULES } from './fast_build/ark_compiler/common/ark_define'; import { @@ -58,7 +58,7 @@ import { projectConfig, sdkConfigPrefix } from '../main'; -import { mangleFilePath, MergedConfig } from './fast_build/ark_compiler/common/ob_config_resolver'; +import { mangleFilePath } from './fast_build/ark_compiler/common/ob_config_resolver'; import { getRealModulePath, type ResolveModuleInfo } from './ets_checker'; const red: string = '\u001b[31m'; @@ -365,7 +365,7 @@ export async function writeObfuscatedSourceCode(content: string, filePath: strin let genFileInHar: GeneratedFileInHar = harFilesRecord.get(sourcePath); if (!genFileInHar) { - genFileInHar = {sourcePath: sourcePath}; + genFileInHar = {sourcePath: sourcePath}; } if (!genFileInHar.sourceCachePath) { genFileInHar.sourceCachePath = toUnixPath(filePath); @@ -375,7 +375,6 @@ export async function writeObfuscatedSourceCode(content: string, filePath: strin fs.writeFileSync(filePath, content); } - export async function writeArkguardObfuscatedSourceCode(content: string, filePath: string, logger: any, projectConfig: any, relativeSourceFilePath: string = '', rollupNewSourceMaps: Object = {}, originalFilePath: string): Promise { const arkObfuscator = projectConfig.arkObfuscator; @@ -687,6 +686,12 @@ function checkBundleVersion(bundleVersion: string): boolean { return false; } +export function cleanUpUtilsObjects(): void { + newSourceMaps = {}; + identifierCaches = {}; + packageCollection.clear(); +} + const CONSTANT_STEP_0: number = 0; const CONSTANT_STEP_1: number = 1; const CONSTANT_STEP_2: number = 2; diff --git a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts index 042fb282..f6859dfa 100644 --- a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts +++ b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts @@ -626,6 +626,11 @@ export function writeObfuscationNameCache(projectConfig:any, obfuscationCacheDir if (printNameCache && printNameCache.length > 0) { fs.writeFileSync(printNameCache, writeContent); } + renamePropertyModule.globalMangledTable.clear(); + renamePropertyModule.historyMangledTable.clear(); + renameFileNameModule.globalFileNameMangledTable.clear(); + renameFileNameModule.globalFileNameMangledTable.clear(); + ApiExtractor.mPropertySet.clear(); } export function generateConsumerObConfigFile(obfuscationOptions: any, logger: any) { diff --git a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts index a44dd881..58c4c1b5 100644 --- a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts +++ b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts @@ -23,13 +23,8 @@ import { import { TS2ABC, ESMODULE, - AOT_FULL, - AOT_PARTIAL, - AOT_TYPE, - AOT_PROFILE_SUFFIX, NODE_MODULES, OH_MODULES, - FAIL, OBFUSCATION_TOOL } from './ark_define'; import { isAotMode, isDebug } from '../utils'; @@ -59,20 +54,29 @@ type ArkConfig = { isDebug: boolean; }; -let arkConfig: ArkConfig = {}; export function initArkConfig(projectConfig: any) { let arkRootPath: string = path.join(__dirname, '..', '..', '..', '..', 'bin', 'ark'); if (projectConfig.arkFrontendDir) { arkRootPath = projectConfig.arkFrontendDir; } + let arkConfig: ArkConfig = { + arkRootPath: '', + ts2abcPath: '', + js2abcPath: '', + mergeAbcPath: '', + es2abcPath: '', + aotCompilerPath: '', + nodePath: '', + isDebug: false + }; arkConfig.nodePath = 'node'; if (projectConfig.nodeJs) { arkConfig.nodePath = projectConfig.nodePath; } - processPlatformInfo(arkRootPath); - processCompatibleVersion(projectConfig, arkRootPath); arkConfig.isDebug = isDebug(projectConfig); arkConfig.arkRootPath = arkRootPath; + processPlatformInfo(arkConfig); + processCompatibleVersion(projectConfig, arkConfig); return arkConfig; } @@ -155,7 +159,7 @@ function initObfuscationConfig(projectConfig: any, arkProjectConfig: any, logger } let projectAndLibs: {projectAndLibsReservedProperties: string[]; libExportNames: string[]}; if (mergedObConfig.options.enablePropertyObfuscation || mergedObConfig.options.enableExportObfuscation) { - projectAndLibs = readProjectProperties([projectConfig.modulePath], + projectAndLibs = readProjectProperties([projectConfig.modulePath], { mNameObfuscation: {mReservedProperties: [], mKeepStringProperty: !mergedObConfig.options.enableStringPropertyObfuscation}, mExportObfuscation: mergedObConfig.options.enableExportObfuscation @@ -282,8 +286,8 @@ function initArkGuardConfig(obfuscationCacheDir: string | undefined, logger: any return arkObfuscator; } -function processPlatformInfo(arkRootPath: string): void { - const arkPlatformPath: string = getArkBuildDir(arkRootPath); +function processPlatformInfo(arkConfig: ArkConfig): void { + const arkPlatformPath: string = getArkBuildDir(arkConfig.arkRootPath); if (isWindows()) { arkConfig.es2abcPath = path.join(arkPlatformPath, 'bin', 'es2abc.exe'); arkConfig.ts2abcPath = path.join(arkPlatformPath, 'src', 'index.js'); @@ -302,8 +306,8 @@ function processPlatformInfo(arkRootPath: string): void { } } -function processCompatibleVersion(projectConfig: any, arkRootPath: string) { - const platformPath: string = getArkBuildDir(arkRootPath); +function processCompatibleVersion(projectConfig: object, arkConfig: ArkConfig): void { + const platformPath: string = getArkBuildDir(arkConfig.arkRootPath); if (projectConfig.minPlatformVersion && projectConfig.minPlatformVersion.toString() === '8') { // use ts2abc to compile apps with 'CompatibleSdkVersion' set to 8 arkConfig.ts2abcPath = path.join(platformPath, 'legacy_api8', 'src', 'index.js'); diff --git a/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts index 05cb3f53..e2a914a8 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_hotreload_mode.ts @@ -35,7 +35,6 @@ import { } from '../../../utils'; let isFirstBuild: boolean = true; -let hotReloadSourceMap: Object = {}; export class ModuleHotreloadMode extends ModuleMode { symbolMapFilePath: string; @@ -110,7 +109,6 @@ export class ModuleHotreloadMode extends ModuleMode { mkdirsSync(this.projectConfig.patchAbcPath); } - this.updateSourceMapFromFileList(changedFileList, parentEvent); const outputABCPath: string = path.join(this.projectConfig.patchAbcPath, MODULES_ABC); validateFilePathLength(outputABCPath, this.logger); @@ -122,6 +120,7 @@ export class ModuleHotreloadMode extends ModuleMode { const eventUpdateSourceMapFromFileList = createAndStartEvent(parentEvent, 'update source map from file list'); const relativeProjectPath: string = this.projectConfig.projectPath.slice( this.projectConfig.projectRootPath.length + path.sep.length); + let hotReloadSourceMap: Object = {}; for (const file of fileList) { const sourceMapPath: string = toUnixPath(path.join(relativeProjectPath, file)); validateFilePathLength(sourceMapPath, this.logger); diff --git a/compiler/src/fast_build/ark_compiler/process_mock.ts b/compiler/src/fast_build/ark_compiler/process_mock.ts index d8c48a0e..7e170dec 100644 --- a/compiler/src/fast_build/ark_compiler/process_mock.ts +++ b/compiler/src/fast_build/ark_compiler/process_mock.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import ts, { NodeArray } from 'typescript'; +import ts from 'typescript'; import { projectConfig } from '../../../main'; import { DECORATOR_SUFFIX } from '../../pre_define'; diff --git a/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts b/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts index 6667863a..c4d2f5cb 100644 --- a/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts +++ b/compiler/src/fast_build/ark_compiler/rollup-plugin-gen-abc.ts @@ -20,6 +20,7 @@ import { transformForModule } from './transform'; import { checkArkCompilerCacheInfo, shouldInvalidCache } from './cache'; import { checkIfJsImportingArkts } from './check_import_module'; import { compilerOptions } from '../../ets_checker'; +import { cleanUpObjects } from './utils'; export function genAbc() { return { @@ -40,6 +41,7 @@ export function genAbc() { } }, buildEnd: generateModuleAbc, - generateBundle: generateBundleAbc + generateBundle: generateBundleAbc, + cleanUp: cleanUpObjects }; } diff --git a/compiler/src/fast_build/ark_compiler/transform.ts b/compiler/src/fast_build/ark_compiler/transform.ts index 5e69b119..d266236d 100644 --- a/compiler/src/fast_build/ark_compiler/transform.ts +++ b/compiler/src/fast_build/ark_compiler/transform.ts @@ -94,3 +94,7 @@ function transformJsByBabelPlugin(code: string, parentEvent: any): any { stopEvent(eventTransformByBabel); return transformed; } + +export function cleanSourceMapObject(): void { + newSourceMaps = {}; +} \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/utils.ts b/compiler/src/fast_build/ark_compiler/utils.ts index 6155d93d..f5d0f1dd 100644 --- a/compiler/src/fast_build/ark_compiler/utils.ts +++ b/compiler/src/fast_build/ark_compiler/utils.ts @@ -37,17 +37,18 @@ import { validateFilePathLength, toUnixPath, createAndStartEvent, - stopEvent, - harFilesRecord + stopEvent } from '../../utils'; -import type { GeneratedFileInHar } from '../../utils'; import { tryMangleFileNameAndWriteFile, - writeObfuscatedSourceCode + writeObfuscatedSourceCode, + cleanUpUtilsObjects } from '../../ark_utils'; import { AOT_FULL, AOT_PARTIAL, AOT_TYPE } from '../../pre_define'; import { newSourceMaps } from './transform'; import { hasTsNoCheckOrTsIgnoreFiles, compilingEtsOrTsFiles } from '../../process_kit_import'; +import { cleanSourceMapObject } from './transform'; +import { cleanUpKitImportObjects } from '../../process_kit_import'; export function needAotCompiler(projectConfig: any): boolean { return projectConfig.compileMode === ESMODULE && (projectConfig.anBuildMode === AOT_FULL || @@ -232,6 +233,13 @@ export async function updateSourceMap(originMap: sourceMap.RawSourceMap, newMap: updatedGenerator['_mappings']['_array'] = newMappingList; return JSON.parse(updatedGenerator.toString()); } + +export function cleanUpObjects(): void { + cleanSourceMapObject(); + cleanUpUtilsObjects(); + cleanUpKitImportObjects(); +} + export const utUtils = { writeFileContent } \ No newline at end of file diff --git a/compiler/src/process_kit_import.ts b/compiler/src/process_kit_import.ts index e038c173..9c7a5d2e 100644 --- a/compiler/src/process_kit_import.ts +++ b/compiler/src/process_kit_import.ts @@ -43,7 +43,7 @@ const KIT_PREFIX = '@kit.'; /* * This API is the TSC Transformer for transforming `KitImport` into `OhosImport` -* e.g. +* e.g. * ``` * import { ability, ErrorCode } from '@kit.AbilityKit' * ---> @@ -126,7 +126,7 @@ class SpecificerInfo { private importName: string; private symbol: KitSymbol; private renamed: boolean; - + private originElement: TSspecifier | undefined; constructor(localName: string, importName: string, symbol: KitSymbol, originElement: TSspecifier | undefined) { @@ -304,7 +304,7 @@ class KitInfo { getOhosImportNodes(): TSModuleDeclaration[] { return this.ohosImportNodes; } - + newSpecificerInfo(localName: string, importName: string, originElement: TSspecifier | undefined): void { const symbol: KitSymbol | undefined = this.symbols[importName]; if (symbol) { @@ -503,4 +503,8 @@ function getKitDefs(kitModuleRequest: string) { function trimSourceSuffix(source: string): string { return source.replace(/\.d.[e]?ts$/, ''); +} + +export function cleanUpKitImportObjects(): void { + kitTransformLog.cleanUp(); } \ No newline at end of file diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index 68334457..9ae7a135 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -28,8 +28,6 @@ import { createHash } from 'crypto'; import { AUXILIARY, EXTNAME_ETS, - EXTNAME_CJS, - EXTNAME_MJS, EXTNAME_JS, MAIN, FAIL, @@ -69,7 +67,7 @@ export interface LogInfo { export const repeatLog: Map = new Map(); export class FileLog { - private _sourceFile: ts.SourceFile; + private _sourceFile: ts.SourceFile | undefined; private _errors: LogInfo[] = []; public get sourceFile() { @@ -87,6 +85,11 @@ export class FileLog { public set errors(newValue: LogInfo[]) { this._errors = newValue; } + + public cleanUp(): void { + this._sourceFile = undefined; + this._errors = []; + } } export function emitLogInfo(loader: any, infos: LogInfo[], fastBuild: boolean = false, diff --git a/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts b/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts index c23df930..f7594f09 100644 --- a/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts +++ b/compiler/test/ark_compiler_ut/common/process_ark_config.test.ts @@ -279,12 +279,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-1: test processCompatibleVersion under build debug', function () { this.rollup.build(); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig,); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; }); @@ -292,12 +292,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-2: test processCompatibleVersion under build release', function () { this.rollup.build(RELEASE); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; }); @@ -305,12 +305,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-3: test processCompatibleVersion under preview debug', function () { this.rollup.preview(); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; }); @@ -318,12 +318,12 @@ mocha.describe('test process_ark_config file api', function () { mocha.it('4-4: test processCompatibleVersion under hot reload debug', function () { this.rollup.hotReload(); const arkConfig = initArkConfig(this.rollup.share.projectConfig); - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === undefined).to.be.true; expect(arkConfig.ts2abcPath.indexOf(TS2ABC_PATH) > 0).to.be.true; this.rollup.share.projectConfig.minPlatformVersion = 8; - utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig.arkRootPath); + utProcessArkConfig.processCompatibleVersion(this.rollup.share.projectConfig, arkConfig); expect(this.rollup.share.projectConfig.pandaMode === TS2ABC).to.be.true; expect(arkConfig.ts2abcPath.indexOf(ARKCONFIG_TS2ABC_PATH) > 0).to.be.true; }); -- Gitee From 2ccbd50e107d98bd2d14182af48f0bc60fe21ba9 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Tue, 2 Jan 2024 12:33:47 +0000 Subject: [PATCH 02/19] revert linter parrel Change-Id: Iae5e05e2d1752825a25e81ce3f48376c4b7d6973 --- compiler/src/do_arkTS_linter.ts | 262 ++---------------- compiler/src/do_arkTS_linter_parallel.ts | 93 ------- compiler/src/ets_checker.ts | 54 +--- .../ets_ui/rollup-plugin-ets-checker.ts | 64 ++--- 4 files changed, 64 insertions(+), 409 deletions(-) delete mode 100644 compiler/src/do_arkTS_linter_parallel.ts diff --git a/compiler/src/do_arkTS_linter.ts b/compiler/src/do_arkTS_linter.ts index f2009efa..543900d4 100644 --- a/compiler/src/do_arkTS_linter.ts +++ b/compiler/src/do_arkTS_linter.ts @@ -16,29 +16,16 @@ import fs from 'fs'; import path from 'path'; import * as ts from 'typescript'; -import { - projectConfig, - partialUpdateConfig -} from '../main'; +import { projectConfig } from '../main'; import { toUnixPath } from './utils'; import { resolveModuleNames, - resolveTypeReferenceDirectives, - cache + resolveTypeReferenceDirectives } from './ets_checker' -import {Worker} from 'worker_threads'; -import { logger } from './compile_info'; -const fse = require('fs-extra'); const arkTSDir: string = 'ArkTS'; const arkTSLinterOutputFileName: string = 'ArkTSLinter_output.json'; 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 => {}; interface OutputInfo { categoryInfo: string | undefined; @@ -59,21 +46,7 @@ export enum ArkTSVersion { ArkTS_1_1, } -export type ProcessDiagnosticsFunc = (diagnostics: ts.Diagnostic, isArkTSDiagnostic: boolean) => void; - -export function getArkTSDiagnostics(arkTSVersion: ArkTSVersion, builderProgram: ts.BuilderProgram, - buildInfoWriteFile?: ts.WriteFileCallback): ts.Diagnostic[] { - const compilerHost: ts.CompilerHost = ts.createIncrementalCompilerHost(builderProgram.getProgram().getCompilerOptions()); - compilerHost.resolveModuleNames = resolveModuleNames; - compilerHost.getCurrentDirectory = (): string => process.cwd(); - compilerHost.getDefaultLibFileName = (options): string => ts.getDefaultLibFilePath(options); - compilerHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives; - if (arkTSVersion === ArkTSVersion.ArkTS_1_0) { - return ts.ArkTSLinter_1_0.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); - } else { - return ts.ArkTSLinter_1_1.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); - } -} +export type ProcessDiagnosticsFunc = (diagnostics: ts.Diagnostic) => void; export function doArkTSLinter(arkTSVersion: ArkTSVersion, builderProgram: ts.BuilderProgram, arkTSMode: ArkTSLinterMode, printDiagnostic: ProcessDiagnosticsFunc, @@ -82,10 +55,18 @@ export function doArkTSLinter(arkTSVersion: ArkTSVersion, builderProgram: ts.Bui return []; } - let diagnostics: ts.Diagnostic[] = getArkTSDiagnostics(arkTSVersion, builderProgram, buildInfoWriteFile); + const compilerHost: ts.CompilerHost = ts.createIncrementalCompilerHost(builderProgram.getProgram().getCompilerOptions()); + compilerHost.resolveModuleNames = resolveModuleNames; + compilerHost.getCurrentDirectory = () => process.cwd(); + compilerHost.getDefaultLibFileName = options => ts.getDefaultLibFilePath(options); + compilerHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives; + + let diagnostics: ts.Diagnostic[] = []; - if (printDiagnostic === undefined) { - return diagnostics; + if (arkTSVersion === ArkTSVersion.ArkTS_1_0) { + diagnostics = ts.ArkTSLinter_1_0.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); + } else { + diagnostics = ts.ArkTSLinter_1_1.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); } removeOutputFile(); @@ -104,7 +85,7 @@ export function doArkTSLinter(arkTSVersion: ArkTSVersion, builderProgram: ts.Bui function processArkTSLinterReportAsError(diagnostics: ts.Diagnostic[], printDiagnostic: ProcessDiagnosticsFunc): void { diagnostics.forEach((diagnostic: ts.Diagnostic) => { - printDiagnostic(diagnostic, true); + printDiagnostic(diagnostic); }); printArkTSLinterFAQ(diagnostics, printDiagnostic); } @@ -116,7 +97,7 @@ function processArkTSLinterReportAsWarning(diagnostics: ts.Diagnostic[], printDi diagnostics.forEach((diagnostic: ts.Diagnostic) => { const originalCategory = diagnostic.category; diagnostic.category = ts.DiagnosticCategory.Warning; - printDiagnostic(diagnostic, true); + printDiagnostic(diagnostic); diagnostic.category = originalCategory; }); printArkTSLinterFAQ(diagnostics, printDiagnostic); @@ -133,8 +114,8 @@ function processArkTSLinterReportAsWarning(diagnostics: ts.Diagnostic[], printDi reportsUnnecessary: undefined, reportsDeprecated: undefined }; + printDiagnostic(arkTSDiagnostic); - printDiagnostic(arkTSDiagnostic, false); printArkTSLinterFAQ(diagnostics, printDiagnostic); } @@ -150,27 +131,15 @@ function writeOutputFile(diagnostics: ts.Diagnostic[]): string | undefined { filePath = toUnixPath((path.join(filePath, arkTSLinterOutputFileName))); const outputInfo: OutputInfo[] = []; diagnostics.forEach((diagnostic: ts.Diagnostic) => { - if (diagnostic.file) { - const { line, character }: ts.LineAndCharacter = - diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); - outputInfo.push({ - categoryInfo: diagnostic.category === ts.DiagnosticCategory.Error ? 'Error' : 'Warning', - fileName: diagnostic.file?.fileName, - line: line + 1, - character: character + 1, - messageText: diagnostic.messageText - }); - } else { - const arkTSdiagnostic = diagnostic as ArkTSDiagnostic; - outputInfo.push({ - categoryInfo: arkTSdiagnostic.category === ts.DiagnosticCategory.Error ? 'Error' : 'Warning', - fileName: arkTSdiagnostic.fileName, - line: arkTSdiagnostic.line + 1, - character: arkTSdiagnostic.character + 1, - messageText: arkTSdiagnostic.messageText - }); - - } + const { line, character }: ts.LineAndCharacter = + diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); + outputInfo.push({ + categoryInfo: diagnostic.category === ts.DiagnosticCategory.Error ? 'Error' : 'Warning', + fileName: diagnostic.file?.fileName, + line: line + 1, + character: character + 1, + messageText: diagnostic.messageText + }); }); let output: string | undefined = filePath; try { @@ -212,182 +181,5 @@ function printArkTSLinterFAQ(diagnostics: ts.Diagnostic[], printDiagnostic: Proc reportsUnnecessary: undefined, reportsDeprecated: undefined }; - printDiagnostic(arkTSFAQDiagnostic, false); -} - -export interface ArkTSDiagnostic extends ts.Diagnostic { - fileName: string | undefined; - line: number; - character: number; -} - -let arkTSLinterFinished: boolean = true; -let arkTSLinterDiagnosticProcessed: boolean = true; -let didArkTSLinter: boolean = false; -let arkTSDiagnostics: ArkTSDiagnostic[] = []; -let cacheFilePath: string | null = null; - -export function resetDidArkTSLinter(): void { - didArkTSLinter = false; -} - -export function doArkTSLinterParallel(arkTSVersion: ArkTSVersion, arkTSMode: ArkTSLinterMode, printDiagnostic: ProcessDiagnosticsFunc, - rootFileNames: string[], resolveModulePaths: string[], cacheFile: string, shouldWriteFile: boolean = true): void { - if (arkTSMode === ArkTSLinterMode.NOT_USE) { - arkTSLinterFinished = true; - arkTSLinterDiagnosticProcessed = true; - return; - } - arkTSLinterFinished = false; - arkTSLinterDiagnosticProcessed = false; - - 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, - projectConfig: JSON.parse(JSON.stringify(projectConfig)), - partialUpdateConfig: partialUpdateConfig, - processEnv: JSON.parse(JSON.stringify(process.env)), - rootFileNames: rootFileNames, - resolveModulePaths: resolveModulePaths - }, - env: process.env - }; - worker = new Worker(path.resolve(__dirname, './do_arkTS_linter_parallel.js'), workerData); - worker.on('message', (strictDiagnostics: Map) => { - strictArkTSDiagnostics = strictDiagnostics; - if (tsDiagnostics !== undefined) { - processArkTSLinterDiagnostic(); - cleanProcessArkTSLinterDiagnostic(); - } - }); -} - -function cleanProcessArkTSLinterDiagnostic(): void { - processArkTSLinterDiagnostic = (): void => {}; -} - -export function updateFileCache(): void { - if (!didArkTSLinter) { - return; - } - if (cacheFilePath === null) { - return; - } - if (process.env.watchMode !== 'true' && !projectConfig.xtsMode) { - arkTSDiagnostics.forEach((diagnostic: ArkTSDiagnostic) => { - const fileName = diagnostic.file ? diagnostic.file.fileName : diagnostic.fileName; - if (cache[path.resolve(fileName)]) { - cache[path.resolve(fileName)].error = true; - } - }); - fse.ensureDirSync(projectConfig.cachePath); - fs.writeFileSync(cacheFilePath, JSON.stringify({ - 'runtimeOS': projectConfig.runtimeOS, - 'sdkInfo': projectConfig.sdkInfo, - 'fileList': cache - }, null, spaceNumBeforeJsonLine)); - } - arkTSDiagnostics = undefined; -} - -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)); - }; - while (!(arkTSLinterDiagnosticProcessed)) { - await sleep(sleepInterval); - } - worker.terminate(); - worker = undefined; -} - -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[] { - let diagnosticsInfo: ArkTSDiagnostic[] = []; - for (const diagnostic of diagnostics) { - const { line, character }: ts.LineAndCharacter = - diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); - diagnosticsInfo.push( - { - fileName: diagnostic.file?.fileName, - line: line, - character: character, - category: diagnostic.category, - code: diagnostic.code, - file: undefined, - start: diagnostic.start, - length: diagnostic.length, - messageText: diagnostic.messageText, - } - ); - }; - return diagnosticsInfo; -} - -function filterStaticDiagnostics(): ArkTSDiagnostic[] { - tsDiagnostics.forEach(diag => { - if (!diag.fileName) { - return; - } - strictArkTSDiagnostics.get(diag.fileName)?.strictDiagnostics.forEach( - strictDiag => { - if (strictDiag.code === diag.code && strictDiag.start === diag.start && strictDiag.length === diag.length) { - strictDiag.code = filteredDiagnosticCode; - return; - } - } - ); - }); - - let resultDiagnostics: ArkTSDiagnostic[] = []; - strictArkTSDiagnostics.forEach( - (value) => { - value.strictDiagnostics.forEach( - diagnostic => { - if (diagnostic.code === filteredDiagnosticCode) { - return; - } - resultDiagnostics.push(diagnostic); - } - ); - value.arkTSDiagnostics.forEach(diagnostic => { resultDiagnostics.push(diagnostic); }); - } - ); - - tsDiagnostics = undefined; - strictArkTSDiagnostics = undefined; - return resultDiagnostics; + printDiagnostic(arkTSFAQDiagnostic); } diff --git a/compiler/src/do_arkTS_linter_parallel.ts b/compiler/src/do_arkTS_linter_parallel.ts deleted file mode 100644 index c3ce5dec..00000000 --- a/compiler/src/do_arkTS_linter_parallel.ts +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as ts from 'typescript'; -import path from 'path'; -import { - projectConfig, - partialUpdateConfig -} from '../main'; -import { - compilerOptions, - resolveModuleNames, - resolveTypeReferenceDirectives, - setCompilerOptions, - readDeaclareFiles, - buildInfoWriteFile -} from './ets_checker'; -import type { ArkTSDiagnostic } from './do_arkTS_linter'; -import { - ArkTSVersion, - processDiagnosticsToArkTSDiagnosticInfo -} from './do_arkTS_linter'; -import { parentPort, workerData } from 'worker_threads'; - -const STRICT_TS_BUILD_INFO_SUFFIX = 'inversedArkTsLinter.tsbuildinfo'; - -function init(): void { - Object.assign(partialUpdateConfig, workerData.partialUpdateConfig); - Object.assign(projectConfig, workerData.projectConfig); - Object.assign(process.env, workerData.processEnv); -} - -function createStrictProgram(): ts.BuilderProgram | undefined { - setCompilerOptions(workerData.resolveModulePaths); - Object.assign(compilerOptions, { - 'noImplicitReturns': true, - 'strictFunctionTypes': true, - 'strictNullChecks': true, - 'strictPropertyInitialization': true, - 'allowJs': true, - 'checkJs': true - }); - const compilerHost: ts.CompilerHost = ts.createIncrementalCompilerHost(compilerOptions); - compilerHost.resolveModuleNames = resolveModuleNames; - compilerHost.getCurrentDirectory = (): string => process.cwd(); - compilerHost.getDefaultLibFileName = (options): string => ts.getDefaultLibFilePath(options); - compilerHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives; - const createProgramOptions = { - rootNames: [...workerData.rootFileNames, ...readDeaclareFiles()], - host: compilerHost, - options: compilerOptions, - }; - createProgramOptions.options.tsBuildInfoFile = compilerOptions.tsBuildInfoFile && - path.resolve(projectConfig.cachePath, '..', STRICT_TS_BUILD_INFO_SUFFIX); - const program = ts.createIncrementalProgram(createProgramOptions); - return program; -} - -function doArkTSLinterParallel(): void { - init(); - const strictBuilderProgram = createStrictProgram()!; - let strictDiagnostics: ts.ESMap; - if (workerData.arkTSVersion === ArkTSVersion.ArkTS_1_0) { - strictDiagnostics = ts.ArkTSLinter_1_0.getDiagnosticsFromStrictProgram(strictBuilderProgram, buildInfoWriteFile); - } else { - strictDiagnostics = ts.ArkTSLinter_1_1.getDiagnosticsFromStrictProgram(strictBuilderProgram, buildInfoWriteFile); - } - - let diagnostics = new Map(); - strictDiagnostics.forEach( - (value, key) => { - diagnostics.set(key, { - strictDiagnostics : processDiagnosticsToArkTSDiagnosticInfo(value.strictDiagnostics), - arkTSDiagnostics: processDiagnosticsToArkTSDiagnosticInfo(value.arkTSDiagnostics), - }); - } - ); - parentPort.postMessage(diagnostics); -} - -doArkTSLinterParallel(); \ No newline at end of file diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 1785668c..3d9de32f 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -92,14 +92,7 @@ import { import { isExtendFunction, isOriginalExtend } from './process_ui_syntax'; import { visualTransform } from './process_visual'; import { tsWatchEmitter } from './fast_build/ets_ui/rollup-plugin-ets-checker'; -import { - doArkTSLinter, - doArkTSLinterParallel, - ArkTSLinterMode, - ArkTSDiagnostic, - sendtsDiagnostic, - ArkTSVersion -} from './do_arkTS_linter'; +import { doArkTSLinter, ArkTSLinterMode, ArkTSVersion } from './do_arkTS_linter'; export const SOURCE_FILES: Map = new Map(); @@ -120,7 +113,7 @@ export function readDeaclareFiles(): string[] { return declarationsFileNames; } -export const buildInfoWriteFile: ts.WriteFileCallback = (fileName: string, data: string) => { +const buildInfoWriteFile: ts.WriteFileCallback = (fileName: string, data: string) => { if (fileName.endsWith(TS_BUILD_INFO_SUFFIX)) { let fd: number = fs.openSync(fileName, 'w'); fs.writeSync(fd, data, undefined, 'utf8'); @@ -130,7 +123,7 @@ export const buildInfoWriteFile: ts.WriteFileCallback = (fileName: string, data: export const compilerOptions: ts.CompilerOptions = ts.readConfigFile( path.resolve(__dirname, '../tsconfig.json'), ts.sys.readFile).config.compilerOptions; -export function setCompilerOptions(resolveModulePaths: string[]): void { +function setCompilerOptions(resolveModulePaths: string[]) { const allPath: Array = [ '*' ]; @@ -367,7 +360,6 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r hotReloadSupportFiles.add(fileName); }); } - runArkTSLinterParallel(rootFileNames, resolveModulePaths, cacheFile); languageService = createLanguageService(rootFileNames, resolveModulePaths, compilationTime); } else { cacheFile = path.resolve(projectConfig.cachePath, '../.ts_checker_cache'); @@ -380,7 +372,6 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r cache = {}; } const filterFiles: string[] = filterInput(rootFileNames); - runArkTSLinterParallel(filterFiles, resolveModulePaths, cacheFile); languageService = createLanguageService(filterFiles, resolveModulePaths, compilationTime); } startTimeStatisticsLocation(compilationTime ? compilationTime.createProgramTime : undefined); @@ -389,6 +380,9 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r globalProgram.program = globalProgram.builderProgram.getProgram(); stopTimeStatisticsLocation(compilationTime ? compilationTime.createProgramTime : undefined); + startTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); + runArkTSLinter(parentEvent); + stopTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); collectSourceFilesMap(globalProgram.program); if (process.env.watchMode !== 'true') { processBuildHap(cacheFile, rootFileNames, compilationTime); @@ -400,7 +394,6 @@ function processBuildHap(cacheFile: string, rootFileNames: string[], compilation const allDiagnostics: ts.Diagnostic[] = globalProgram.builderProgram .getSyntacticDiagnostics() .concat(globalProgram.builderProgram.getSemanticDiagnostics()); - sendtsDiagnostic(allDiagnostics); stopTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); globalProgram.builderProgram.emitBuildInfo(buildInfoWriteFile); @@ -465,14 +458,14 @@ function containFormError(message: string): boolean { return false; } -export function printDiagnostic(diagnostic: ts.Diagnostic, isArkTSDiagnostic: boolean = false): void { +export function printDiagnostic(diagnostic: ts.Diagnostic): void { const message: string = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); if (validateError(message)) { if (process.env.watchMode !== 'true' && !projectConfig.xtsMode) { updateErrorFileCache(diagnostic); } - if (containFormError(message) && diagnostic.file && !isCardFile(diagnostic.file.fileName)) { + if (containFormError(message) && !isCardFile(diagnostic.file.fileName)) { return; } @@ -489,12 +482,7 @@ export function printDiagnostic(diagnostic: ts.Diagnostic, isArkTSDiagnostic: bo diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!); logMessage = `ArkTS:${logPrefix} File: ${diagnostic.file.fileName}:${line + 1}:${character + 1}\n ${message}\n`; } else { - if (!isArkTSDiagnostic) { - logMessage = `ArkTS:${logPrefix}: ${message}`; - } else { - const arkTSDiagnostic = diagnostic as ArkTSDiagnostic; - logMessage = `ArkTS:${logPrefix} File: ${arkTSDiagnostic.fileName}:${arkTSDiagnostic.line + 1}:${arkTSDiagnostic.character + 1}\n ${message}\n`; - } + logMessage = `ArkTS:${logPrefix}: ${message}`; } if (diagnostic.category === ts.DiagnosticCategory.Error) { @@ -1102,36 +1090,24 @@ function runArkTSLinter(parentEvent?: any): void { stopEvent(eventRunArkTsLinter); } -function runArkTSLinterParallel(rootFileNames: string[], resolveModulePaths: string[], cacheFile: string): void { - doArkTSLinterParallel( - getArkTSVersion(), - getArkTSLinterMode(), - printArkTSLinterDiagnostic, - rootFileNames, - resolveModulePaths, - cacheFile, - !projectConfig.xtsMode - ); -} - -function printArkTSLinterDiagnostic(diagnostic: ts.Diagnostic, isArkTSDiagnostic: boolean): void { +function printArkTSLinterDiagnostic(diagnostic: ts.Diagnostic): void { if (diagnostic.category === ts.DiagnosticCategory.Error && (isInOhModuleFile(diagnostic) || isInSDK(diagnostic))) { const originalCategory = diagnostic.category; diagnostic.category = ts.DiagnosticCategory.Warning; - printDiagnostic(diagnostic, isArkTSDiagnostic); + printDiagnostic(diagnostic); diagnostic.category = originalCategory; return; } - printDiagnostic(diagnostic, isArkTSDiagnostic); + printDiagnostic(diagnostic); } function isInOhModuleFile(diagnostics: ts.Diagnostic): boolean { - const fileName = diagnostics.file ? diagnostics.file.fileName : (diagnostics as ArkTSDiagnostic).fileName; - return ((fileName.indexOf('/oh_modules/') !== -1) || fileName.indexOf('\\oh_modules\\') !== -1); + return (diagnostics.file !== undefined) && + ((diagnostics.file.fileName.indexOf('/oh_modules/') !== -1) || diagnostics.file.fileName.indexOf('\\oh_modules\\') !== -1); } function isInSDK(diagnostics: ts.Diagnostic): boolean { - const fileName = diagnostics.file ? diagnostics.file.fileName : (diagnostics as ArkTSDiagnostic).fileName; + const fileName = diagnostics.file?.fileName; if (projectConfig.etsLoaderPath === undefined || fileName === undefined) { return false; } diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts index ed63ec87..a15ce3ad 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts @@ -37,12 +37,6 @@ import { CompilationTimeStatistics, getHookEventFactory } from '../../utils'; -import { - waitArkTSLinterFinished, - updateFileCache, - resetDidArkTSLinter, - sendtsDiagnostic -} from '../../do_arkTS_linter'; export let tsWatchEmitter: EventEmitter | undefined = undefined; export let tsWatchEndPromise: Promise; @@ -54,8 +48,14 @@ export function etsChecker() { buildStart() { const hookEventFactory = getHookEventFactory(this.share, 'etsChecker', 'buildStart'); const compilationTime: CompilationTimeStatistics = new CompilationTimeStatistics(this.share, 'etsChecker', 'buildStart'); - resetDidArkTSLinter(); - setTsWatch(); + if (process.env.watchMode === 'true' && process.env.triggerTsWatch === 'true') { + tsWatchEmitter = new EventEmitter(); + tsWatchEndPromise = new Promise(resolve => { + tsWatchEmitter.on(TS_WATCH_END_MSG, () => { + resolve(); + }); + }); + } Object.assign(projectConfig, this.share.projectConfig); Object.assign(this.share.projectConfig, { compileHar: projectConfig.compileHar, @@ -76,48 +76,28 @@ export function etsChecker() { } const eventServiceChecker = createAndStartEvent(hookEventFactory, 'check Ets code syntax'); if (process.env.watchMode === 'true') { - !executedOnce && serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, compilationTime); + !executedOnce && serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, + compilationTime); executedOnce = true; - getAllDiagnostics(compilationTime); + startTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); + globalProgram.program = languageService.getProgram(); + const allDiagnostics: ts.Diagnostic[] = globalProgram.program + .getSyntacticDiagnostics() + .concat(globalProgram.program.getSemanticDiagnostics()) + .concat(globalProgram.program.getDeclarationDiagnostics()); + stopTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); + allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { + printDiagnostic(diagnostic); + }); fastBuildLogger.debug(TS_WATCH_END_MSG); tsWatchEmitter.emit(TS_WATCH_END_MSG); } else { - serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, compilationTime); + serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, + compilationTime); } stopEvent(eventServiceChecker); setChecker(); - }, - beforeBuildEnd: { - order: 'pre', - async handler(): Promise { - await waitArkTSLinterFinished(); - updateFileCache(); - } } }; } -function setTsWatch(): void { - if (process.env.watchMode === 'true' && process.env.triggerTsWatch === 'true') { - tsWatchEmitter = new EventEmitter(); - tsWatchEndPromise = new Promise(resolve => { - tsWatchEmitter.on(TS_WATCH_END_MSG, () => { - resolve(); - }); - }); - } -} - -function getAllDiagnostics(compilationTime: CompilationTimeStatistics): void { - startTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); - globalProgram.program = languageService.getProgram(); - const allDiagnostics: ts.Diagnostic[] = globalProgram.program - .getSyntacticDiagnostics() - .concat(globalProgram.program.getSemanticDiagnostics()) - .concat(globalProgram.program.getDeclarationDiagnostics()); - stopTimeStatisticsLocation(compilationTime ? compilationTime.diagnosticTime : undefined); - allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { - printDiagnostic(diagnostic); - }); - sendtsDiagnostic(allDiagnostics); -} \ No newline at end of file -- Gitee From b91cd926c74c05379514f0e1f70d56cef3fe7ef1 Mon Sep 17 00:00:00 2001 From: wangcaoyu Date: Mon, 25 Dec 2023 14:51:02 +0800 Subject: [PATCH 03/19] =?UTF-8?q?API=E8=8C=83=E5=BC=8F=E6=B7=BB=E5=8A=A0cl?= =?UTF-8?q?eanUp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangcaoyu --- .../src/fast_build/system_api/rollup-plugin-system-api.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts index 9fe86f5f..239c2c53 100644 --- a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts +++ b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts @@ -79,6 +79,10 @@ export function apiTransform() { const allModules: Map> = getAllComponentsOrModules(allFiles, 'module_collection.json'); writeCollectionFile(projectConfig.cachePath, appImportModuleCollection, allModules, 'module_collection.json'); } + }, + cleanUp() { + allFiles.clear(); + appImportModuleCollection.clear(); } }; } -- Gitee From c43ea421fbd7d43da7a7aba9c7cb42c010389f86 Mon Sep 17 00:00:00 2001 From: wangcaoyu Date: Mon, 25 Dec 2023 20:29:43 +0800 Subject: [PATCH 04/19] =?UTF-8?q?api=E8=8C=83=E5=BC=8F=20fix=20transform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangcaoyu --- .../system_api/rollup-plugin-system-api.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts index 239c2c53..dd513aeb 100644 --- a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts +++ b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts @@ -50,16 +50,18 @@ export function apiTransform() { allFiles.add(path.join(id)); }, transform(code: string, id: string) { + if ( projectConfig.compileMode === "esmodule" ) { + return { + code: code + }; + } const magicString = new MagicString(code); if (filter(id)) { - if (projectConfig.compileMode === "esmodule") { - code = processSystemApiAndLibso(code, id, useOSFiles); - hiresStatus = false; - } else { + if (projectConfig.compileMode !== "esmodule") { code = processSystemApi(code, id); code = processLibso(code, id, useOSFiles); hiresStatus = true; - } + } } return { code: code, -- Gitee From a3efdf022e48e298d3f2d36e6f3a392e56b2e2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E5=93=A5?= Date: Mon, 25 Dec 2023 22:36:34 +0800 Subject: [PATCH 05/19] jiangbo91@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit arkui Signed-off-by: 卡哥 --- compiler/src/compile_info.ts | 3 ++ compiler/src/component_map.ts | 10 +++++++ compiler/src/ets_checker.ts | 9 ++++++ .../ets_ui/rollup-plugin-ets-typescript.ts | 28 +++++++++++++++---- compiler/src/process_component_build.ts | 4 +++ compiler/src/process_component_member.ts | 4 +++ compiler/src/process_ui_syntax.ts | 4 +++ compiler/src/utils.ts | 12 ++++++-- compiler/src/validate_ui_syntax.ts | 21 ++++++++++++++ 9 files changed, 88 insertions(+), 7 deletions(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 580efac9..08dd85ee 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -499,3 +499,6 @@ function handleFinishModules(modules, callback) { } } +export function resetCompileInfo() { + props.length = 0; +} \ No newline at end of file diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index b3b5ef5a..e6cc8d05 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -151,3 +151,13 @@ export const CUSTOM_BUILDER_CONSTRUCTORS: Set = new Set(['MenuItem', 'Me } }); })(); + +export function resetComponentMap() { + ID_ATTRS.clear(); + BUILDIN_STYLE_NAMES.clear(); + CUSTOM_BUILDER_METHOD.clear(); + INNER_STYLE_FUNCTION.clear(); + STYLES_ATTRIBUTE.clear(); + INNER_CUSTOM_BUILDER_METHOD.clear(); + GLOBAL_CUSTOM_BUILDER_METHOD.clear(); +} diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 3d9de32f..5f5c7c93 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -1199,4 +1199,13 @@ export function etsStandaloneChecker(entryObj, logger, projectConfig): void { allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { printDiagnostic(diagnostic); }); +} + +export function resetEtsCheck() { + shouldResolvedFiles.clear(); + allResolvedModules.clear(); + resolvedModulesCache.clear(); + dollarCollection.clear(); + decoratorParamsCollection.clear(); + extendCollection.clear(); } \ No newline at end of file diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index ae20ed29..5bc2fce8 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -40,7 +40,8 @@ import { CompilationTimeStatistics, getHookEventFactory, genLoaderOutPathOfHar, - harFilesRecord + harFilesRecord, + resetUtils } from '../../utils'; import { preprocessExtend, @@ -49,12 +50,14 @@ import { propertyCollection, linkCollection, resetComponentCollection, - componentCollection + componentCollection, + resetValidateUiSyntax } from '../../validate_ui_syntax'; import { processUISyntax, resetLog, - transformLog + transformLog, + resetProcessUiSyntax } from '../../process_ui_syntax'; import { projectConfig, @@ -65,17 +68,22 @@ import { appComponentCollection, compilerOptions as etsCheckerCompilerOptions, resolveModuleNames, - resolveTypeReferenceDirectives + resolveTypeReferenceDirectives, + resetEtsCheck } from '../../ets_checker'; import { CUSTOM_BUILDER_METHOD, GLOBAL_CUSTOM_BUILDER_METHOD, - INNER_CUSTOM_BUILDER_METHOD + INNER_CUSTOM_BUILDER_METHOD, + resetComponentMap } from '../../component_map'; import { kitTransformLog, processKitImport } from '../../process_kit_import'; +import { resetCompileInfo } from '../../compile_info'; +import { resetProcessComponentBuild } from '../../process_component_build'; +import { resetProcessComponentMember } from '../../process_component_member'; const filter:any = createFilter(/(? Date: Mon, 25 Dec 2023 22:42:10 +0800 Subject: [PATCH 06/19] fix memory leak Signed-off-by: txdyyangbo --- .../system_api/rollup-plugin-system-api.ts | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts index dd513aeb..3e730ccc 100644 --- a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts +++ b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts @@ -43,30 +43,27 @@ export const appImportModuleCollection: Map> = new Map(); export function apiTransform() { const useOSFiles: Set = new Set(); - let hiresStatus: boolean = true; return { name: 'apiTransform', load(id: string) { allFiles.add(path.join(id)); }, transform(code: string, id: string) { - if ( projectConfig.compileMode === "esmodule" ) { - return { - code: code - }; - } - const magicString = new MagicString(code); if (filter(id)) { - if (projectConfig.compileMode !== "esmodule") { + if (projectConfig.compileMode === "esmodule") { + code = processSystemApiAndLibso(code, id, useOSFiles); + return { + code: code + }; + } else { code = processSystemApi(code, id); code = processLibso(code, id, useOSFiles); - hiresStatus = true; - } + return { + code: code, + map: new MagicString(code).generateMap({ hires: true }) + }; + } } - return { - code: code, - map: magicString.generateMap({ hires: hiresStatus }) - }; }, beforeBuildEnd() { this.share.allComponents = getAllComponentsOrModules(allFiles, 'component_collection.json'); @@ -81,10 +78,6 @@ export function apiTransform() { const allModules: Map> = getAllComponentsOrModules(allFiles, 'module_collection.json'); writeCollectionFile(projectConfig.cachePath, appImportModuleCollection, allModules, 'module_collection.json'); } - }, - cleanUp() { - allFiles.clear(); - appImportModuleCollection.clear(); } }; } -- Gitee From 819df06892a815eeea6f3cf6a2be3cda708c8eb8 Mon Sep 17 00:00:00 2001 From: txdyyangbo Date: Mon, 25 Dec 2023 22:48:54 +0800 Subject: [PATCH 07/19] add cleanUp hook Signed-off-by: txdyyangbo --- .../src/fast_build/system_api/rollup-plugin-system-api.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts index 3e730ccc..2687cf50 100644 --- a/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts +++ b/compiler/src/fast_build/system_api/rollup-plugin-system-api.ts @@ -78,6 +78,11 @@ export function apiTransform() { const allModules: Map> = getAllComponentsOrModules(allFiles, 'module_collection.json'); writeCollectionFile(projectConfig.cachePath, appImportModuleCollection, allModules, 'module_collection.json'); } + }, + cleanUp() { + allFiles.clear(); + appImportModuleCollection.clear(); + useOSFiles.clear(); } }; } -- Gitee From 36ea5e37055f2558ed3ee48db4b504bf551c29c2 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Tue, 2 Jan 2024 12:40:46 +0000 Subject: [PATCH 08/19] Revert "jiangbo91@huawei.com" This reverts commit 555384b0cdda972dd2b599c07ae9852feefda695. --- compiler/src/compile_info.ts | 3 -- compiler/src/component_map.ts | 10 ------- compiler/src/ets_checker.ts | 9 ------ .../ets_ui/rollup-plugin-ets-typescript.ts | 28 ++++--------------- compiler/src/process_component_build.ts | 4 --- compiler/src/process_component_member.ts | 4 --- compiler/src/process_ui_syntax.ts | 4 --- compiler/src/utils.ts | 12 ++------ compiler/src/validate_ui_syntax.ts | 21 -------------- 9 files changed, 7 insertions(+), 88 deletions(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 08dd85ee..580efac9 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -499,6 +499,3 @@ function handleFinishModules(modules, callback) { } } -export function resetCompileInfo() { - props.length = 0; -} \ No newline at end of file diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index e6cc8d05..b3b5ef5a 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -151,13 +151,3 @@ export const CUSTOM_BUILDER_CONSTRUCTORS: Set = new Set(['MenuItem', 'Me } }); })(); - -export function resetComponentMap() { - ID_ATTRS.clear(); - BUILDIN_STYLE_NAMES.clear(); - CUSTOM_BUILDER_METHOD.clear(); - INNER_STYLE_FUNCTION.clear(); - STYLES_ATTRIBUTE.clear(); - INNER_CUSTOM_BUILDER_METHOD.clear(); - GLOBAL_CUSTOM_BUILDER_METHOD.clear(); -} diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 5f5c7c93..3d9de32f 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -1199,13 +1199,4 @@ export function etsStandaloneChecker(entryObj, logger, projectConfig): void { allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { printDiagnostic(diagnostic); }); -} - -export function resetEtsCheck() { - shouldResolvedFiles.clear(); - allResolvedModules.clear(); - resolvedModulesCache.clear(); - dollarCollection.clear(); - decoratorParamsCollection.clear(); - extendCollection.clear(); } \ No newline at end of file diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index 5bc2fce8..ae20ed29 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -40,8 +40,7 @@ import { CompilationTimeStatistics, getHookEventFactory, genLoaderOutPathOfHar, - harFilesRecord, - resetUtils + harFilesRecord } from '../../utils'; import { preprocessExtend, @@ -50,14 +49,12 @@ import { propertyCollection, linkCollection, resetComponentCollection, - componentCollection, - resetValidateUiSyntax + componentCollection } from '../../validate_ui_syntax'; import { processUISyntax, resetLog, - transformLog, - resetProcessUiSyntax + transformLog } from '../../process_ui_syntax'; import { projectConfig, @@ -68,22 +65,17 @@ import { appComponentCollection, compilerOptions as etsCheckerCompilerOptions, resolveModuleNames, - resolveTypeReferenceDirectives, - resetEtsCheck + resolveTypeReferenceDirectives } from '../../ets_checker'; import { CUSTOM_BUILDER_METHOD, GLOBAL_CUSTOM_BUILDER_METHOD, - INNER_CUSTOM_BUILDER_METHOD, - resetComponentMap + INNER_CUSTOM_BUILDER_METHOD } from '../../component_map'; import { kitTransformLog, processKitImport } from '../../process_kit_import'; -import { resetCompileInfo } from '../../compile_info'; -import { resetProcessComponentBuild } from '../../process_component_build'; -import { resetProcessComponentMember } from '../../process_component_member'; const filter:any = createFilter(/(? Date: Wed, 3 Jan 2024 09:58:04 +0000 Subject: [PATCH 09/19] =?UTF-8?q?rollup=20=E5=B8=B8=E9=A9=BB=20global=20in?= =?UTF-8?q?itialization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ifec5698a4612c7a1b82885296afc9b49e795424d --- compiler/main.js | 45 ++++++++++++++++++- compiler/src/compile_info.ts | 3 ++ compiler/src/component_map.ts | 6 +++ compiler/src/ets_checker.ts | 15 ++++++- .../ets_ui/rollup-plugin-ets-typescript.ts | 32 ++++++++++--- compiler/src/process_component_build.ts | 8 +++- compiler/src/process_component_member.ts | 4 ++ compiler/src/process_ui_syntax.ts | 7 ++- compiler/src/utils.ts | 36 ++++++++++++++- compiler/src/validate_ui_syntax.ts | 20 +++++++++ 10 files changed, 163 insertions(+), 13 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 6732940c..3ba5aa41 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -875,6 +875,49 @@ function partialUpdateController(minAPIVersion, metadata = null) { } } +function resetMain() { + globalProgram.builderProgram = null; + globalProgram.program = null; + globalProgram.checker = null; + projectConfig.entryObj = undefined; + projectConfig.cardObj = undefined; + projectConfig.projectPath = undefined; + projectConfig.buildPath = undefined; + projectConfig.aceModuleBuild = undefined + projectConfig.manifestFilePath = undefined; + projectConfig.aceProfilePath = undefined; + projectConfig.aceModuleJsonPath = undefined + projectConfig.hashProjectPath = undefined; + projectConfig.aceBuildJson = undefined; + projectConfig.aceSoPath = undefined; + projectConfig.xtsMode = undefined; + projectConfig.localPropertiesPath = undefined; + projectConfig.projectProfilePath = undefined; + projectConfig.isPreview = undefined; + projectConfig.runtimeOS = undefined; + projectConfig.sdkInfo = undefined; + projectConfig.compileHar = false; + projectConfig.compileShared = false; + projectConfig.splitCommon = false; + projectConfig.checkEntry = undefined; + projectConfig.obfuscateHarType = undefined; + projectConfig.packageDir = 'node_modules'; + projectConfig.packageJson = 'package.json'; + projectConfig.packageManagerType = 'npm'; + projectConfig.cardEntryObj = undefined; + projectConfig.compilerTypes = undefined; + projectConfig.isCrossplatform = undefined; + projectConfig.enableDebugLine = undefined; + projectConfig.bundleType = undefined; + if (projectConfig.isPreview) { + abilityPagesFullPath = []; + } + if (process.env.watchMode !== 'true') { + projectConfig.compileMode = undefined; + projectConfig.cachePath = undefined; + } +} + const globalProgram = { builderProgram: null, program: null, @@ -890,7 +933,7 @@ const partialUpdateConfig = { optimizeComponent: true, arkTSVersion: undefined, }; - +exports.resetMain = resetMain; exports.globalProgram = globalProgram; exports.projectConfig = projectConfig; exports.loadEntryObj = loadEntryObj; diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 580efac9..08dd85ee 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -499,3 +499,6 @@ function handleFinishModules(modules, callback) { } } +export function resetCompileInfo() { + props.length = 0; +} \ No newline at end of file diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index b3b5ef5a..f60f9cd7 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -151,3 +151,9 @@ export const CUSTOM_BUILDER_CONSTRUCTORS: Set = new Set(['MenuItem', 'Me } }); })(); + +export function resetComponentMap() { + ID_ATTRS.clear(); + INNER_STYLE_FUNCTION.clear(); + STYLES_ATTRIBUTE.clear(); +} \ No newline at end of file diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 3d9de32f..c4a9f59e 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -383,7 +383,7 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r startTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); runArkTSLinter(parentEvent); stopTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); - collectSourceFilesMap(globalProgram.program); + // collectSourceFilesMap(globalProgram.program); if (process.env.watchMode !== 'true') { processBuildHap(cacheFile, rootFileNames, compilationTime); } @@ -1199,4 +1199,17 @@ export function etsStandaloneChecker(entryObj, logger, projectConfig): void { allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { printDiagnostic(diagnostic); }); +} + +export function resetEtsCheck() { + shouldResolvedFiles.clear(); + allResolvedModules.clear(); + resolvedModulesCache.clear(); + dollarCollection.clear(); + decoratorParamsCollection.clear(); + extendCollection.clear(); + if (process.env.watchMode !== 'true') { + hotReloadSupportFiles.clear(); + languageService = null; + } } \ No newline at end of file diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index ae20ed29..15c45616 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -40,7 +40,8 @@ import { CompilationTimeStatistics, getHookEventFactory, genLoaderOutPathOfHar, - harFilesRecord + harFilesRecord, + resetUtils } from '../../utils'; import { preprocessExtend, @@ -49,33 +50,41 @@ import { propertyCollection, linkCollection, resetComponentCollection, - componentCollection + componentCollection, + resetValidateUiSyntax } from '../../validate_ui_syntax'; import { processUISyntax, resetLog, - transformLog + transformLog, + resetProcessUiSyntax } from '../../process_ui_syntax'; import { projectConfig, abilityPagesFullPath, - globalProgram + globalProgram, + resetMain } from '../../../main'; import { appComponentCollection, compilerOptions as etsCheckerCompilerOptions, resolveModuleNames, - resolveTypeReferenceDirectives + resolveTypeReferenceDirectives, + resetEtsCheck } from '../../ets_checker'; import { CUSTOM_BUILDER_METHOD, GLOBAL_CUSTOM_BUILDER_METHOD, - INNER_CUSTOM_BUILDER_METHOD + INNER_CUSTOM_BUILDER_METHOD, + resetComponentMap } from '../../component_map'; import { kitTransformLog, processKitImport } from '../../process_kit_import'; +import { resetCompileInfo } from '../../compile_info'; +import { resetProcessComponentBuild } from '../../process_component_build'; +import { resetProcessComponentMember } from '../../process_component_member'; const filter:any = createFilter(/(?, name: string): boolean { - return Array.isArray(forEachParameters) && + return Array.isArray(forEachParameters) && forEachParameters.some((item)=>{ return ts.isIdentifier(item.name) ? item.name.escapedText.toString() === name : false; }); } function isParamFunction(node: ts.ExpressionStatement): boolean { - return node.expression && ts.isCallExpression(node.expression) && + return node.expression && ts.isCallExpression(node.expression) && node.expression.expression && ts.isIdentifier(node.expression.expression); } @@ -3194,3 +3194,7 @@ function checkNonspecificParents(node: ts.ExpressionStatement, name: string, sav } } } + +export function resetProcessComponentBuild() { + sourceNode = undefined; +} \ No newline at end of file diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 72b65f3a..b883a318 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -1269,3 +1269,7 @@ function isObserved(type: ts.Type): boolean { }); } } + +export function resetProcessComponentMember() { + decoratorParamSet.clear(); +} diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index 8a6d1731..d7e6920d 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -134,7 +134,7 @@ import { createCustomComponentNewExpression, createViewCreate } from './process_ import { assignComponentParams } from './process_custom_component'; import { processDecorator } from './fast_build/ark_compiler/process_decorator'; -export const transformLog: FileLog = new FileLog(); +export let transformLog: FileLog = new FileLog(); export let contextGlobal: ts.TransformationContext; export let resourceFileName: string = ''; export const builderTypeParameter: {params: string[]} = {params: []}; @@ -1749,3 +1749,8 @@ export function validatorCard(log: any[], type: number, pos: number, log.push(logInfo); } } + +export function resetProcessUiSyntax() { + contextGlobal = undefined; + transformLog= new FileLog(); +} diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index 9ae7a135..4cc15cc9 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -177,7 +177,8 @@ class ComponentInfo { } } -export const componentInfo: ComponentInfo = new ComponentInfo(); +// export const componentInfo: ComponentInfo = new ComponentInfo(); +export let componentInfo: ComponentInfo = new ComponentInfo(); export function hasDecorator(node: ts.MethodDeclaration | ts.FunctionDeclaration | ts.StructDeclaration | ts.ClassDeclaration, decortorName: string, @@ -865,7 +866,8 @@ class ProcessFileInfo { } } -export const storedFileInfo: ProcessFileInfo = new ProcessFileInfo(); +// export const storedFileInfo: ProcessFileInfo = new ProcessFileInfo(); +export let storedFileInfo: ProcessFileInfo = new ProcessFileInfo(); export interface fileInfo extends tsFileInfo { hasEntry: boolean; // Has @Entry decorator or not @@ -1059,3 +1061,33 @@ interface CompileEvent { stopAsyncEvent(state?: CompileEventState, TIME?: number): void; createSubEvent(name: string): CompileEvent; } + +export function resetUtils() { + repeatLog.clear() + componentInfo = new ComponentInfo(); + harFilesRecord.clear(); + allModifiedFiles.clear(); + storedFileInfo.buildStart = true; + storedFileInfo.wholeFileInfo = {}; // Save ArkTS & TS file's infomation + storedFileInfo.transformedFiles = new Set(); // ArkTS & TS Files which should be transformed in this compilation + storedFileInfo.cachedFiles = []; // ArkTS & TS Files which should not be transformed in this compilation + storedFileInfo.shouldHaveEntry = []; // Which file should have @Entry decorator + storedFileInfo.resourceToFile = {}; // Resource is used by which file + storedFileInfo.lastResourceList = new Set(); + storedFileInfo.shouldInvalidFiles = new Set(); + storedFileInfo.currentArkTsFile; + storedFileInfo.reUseProgram = false; + if (process.env.watchMode !== 'true') { + storedFileInfo.lastResourcesSet = new Set(); + storedFileInfo.resourcesArr = new Set(); + storedFileInfo.resourceTableChanged = false; + storedFileInfo.resourceList = new Set(); // Whole project resource + } + storedFileInfo.transformCacheFiles = {}; + storedFileInfo.processBuilder = false; + storedFileInfo.processGlobalBuilder = false; + storedFileInfo.builderLikeCollection = new Set(); + storedFileInfo.newTsProgram; + storedFileInfo.changeFiles = []; + storedFileInfo.isFirstBuild = true; +} \ No newline at end of file diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 81e4c24e..e19e4de5 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -1423,3 +1423,23 @@ export function getLocalStorageCollection(componentName: string, collection: Set } } } + +export function resetValidateUiSyntax(): void { + observedClassCollection.clear(); + enumCollection.clear(); + classMethodCollection.clear(); + dollarCollection.clear(); + stateCollection.clear(); + regularCollection.clear(); + storagePropCollection.clear(); + storageLinkCollection.clear(); + provideCollection.clear(); + consumeCollection.clear(); + builderParamObjectCollection.clear(); + localStorageLinkCollection.clear(); + localStoragePropCollection.clear(); + isStaticViewCollection.clear(); + useOSFiles.clear(); + sourcemapNamesCollection.clear(); + originalImportNamesMap.clear(); +} \ No newline at end of file -- Gitee From 421dd0fec39a09a4d66f1bcc0fb662973e933ae2 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Wed, 3 Jan 2024 09:59:15 +0000 Subject: [PATCH 10/19] =?UTF-8?q?linter=E5=85=BC=E5=AE=B9=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If587dbd4cc8a3c1d946c690f032c348ffe50e9f6 --- compiler/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/main.js b/compiler/main.js index 3ba5aa41..afa9282d 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -929,7 +929,7 @@ const partialUpdateConfig = { partialUpdateMode: false, builderCheck: true, executeArkTSLinter: true, - standardArkTSLinter: true, + standardArkTSLinter: false, optimizeComponent: true, arkTSVersion: undefined, }; -- Gitee From 04dfd3515bcb4d4b3bad677ed151bd7e459df57c Mon Sep 17 00:00:00 2001 From: lihong Date: Thu, 4 Jan 2024 11:12:18 +0800 Subject: [PATCH 11/19] lihong67@huawei.com reset global variable. Signed-off-by: lihong Change-Id: I4c6dee994536470217306aa686d3437084633c21 --- compiler/main.js | 60 ++++++++++++++++++- compiler/src/compile_info.ts | 3 + compiler/src/component_map.ts | 6 ++ compiler/src/ets_checker.ts | 18 +++++- .../ets_ui/rollup-plugin-ets-typescript.ts | 47 ++++++++++++--- compiler/src/process_component_build.ts | 4 ++ compiler/src/process_component_member.ts | 4 ++ compiler/src/process_ui_syntax.ts | 7 ++- compiler/src/utils.ts | 10 +++- compiler/src/validate_ui_syntax.ts | 20 +++++++ 10 files changed, 164 insertions(+), 15 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 6732940c..65bc8588 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -48,8 +48,8 @@ configure({ }); const logger = getLogger('ETS'); -const staticPreviewPage = process.env.aceStaticPreview; -const aceCompileMode = process.env.aceCompileMode || 'page'; +let staticPreviewPage = process.env.aceStaticPreview; +let aceCompileMode = process.env.aceCompileMode || 'page'; const abilityConfig = { abilityType: process.env.abilityType || 'page', abilityEntryFile: null, @@ -115,6 +115,7 @@ function initProjectConfig(projectConfig) { function loadEntryObj(projectConfig) { let manifest = {}; + initMain(); initProjectConfig(projectConfig); loadBuildJson(); if (process.env.aceManifestPath && aceCompileMode === 'page') { @@ -891,6 +892,60 @@ const partialUpdateConfig = { arkTSVersion: undefined, }; +function resetMain() { + staticPreviewPage = undefined; + aceCompileMode = 'page'; + resetAbilityConfig(); + resetProjectConfig(); + resources.app = {}; + abilityPagesFullPath.length = 0; + aceBuildJson = {}; + resetGlobalProgram(); + partialUpdateConfig.builderCheck = true; +} + +function resetAbilityConfig() { + abilityConfig.abilityType = 'page'; + abilityConfig.abilityEntryFile = null; + abilityConfig.projectAbilityPath = []; + abilityConfig.testRunnerFile = []; +} + +function resetProjectConfig() { + projectConfig.entryObj = {}; + projectConfig.cardObj = {}; + projectConfig.compileHar = false; + projectConfig.compileShared = false; + projectConfig.packageDir = 'node_modules'; + projectConfig.packageJson = 'package.json'; + projectConfig.packageManagerType = 'npm'; + projectConfig.cardEntryObj = {}; + projectConfig.compilerTypes = []; + projectConfig.optLazyForEach = false; + const props = ['projectPath', 'buildPath', 'aceModuleBuild', 'manifestFilePath', 'aceProfilePath', + 'aceModuleJsonPath', 'aceSuperVisualPath', 'hashProjectPath', 'aceBuildJson', 'cachePath', + 'aceSoPath', 'localPropertiesPath', 'projectProfilePath', 'isPreview', 'compileMode', 'runtimeOS', + 'sdkInfo', 'checkEntry', 'obfuscateHarType', 'isCrossplatform', 'enableDebugLine', 'bundleType' + ]; + for (let key in projectConfig) { + if (props.includes(key)) { + projectConfig[key] = undefined; + } + } +} + +function resetGlobalProgram() { + globalProgram.builderProgram = null; + globalProgram.program = null; + globalProgram.checker = null; +} + +function initMain() { + staticPreviewPage = process.env.aceStaticPreview; + aceCompileMode = process.env.aceCompileMode || 'page'; + abilityConfig.abilityType = process.env.abilityType || 'page'; +} + exports.globalProgram = globalProgram; exports.projectConfig = projectConfig; exports.loadEntryObj = loadEntryObj; @@ -914,3 +969,4 @@ exports.extendSdkConfigs = extendSdkConfigs; exports.sdkConfigs = sdkConfigs; exports.sdkConfigPrefix = sdkConfigPrefix; exports.ohosSystemModulePaths = ohosSystemModulePaths; +exports.resetMain = resetMain; diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 580efac9..9ba688b7 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -499,3 +499,6 @@ function handleFinishModules(modules, callback) { } } +export function resetCompileInfo() { + props.length = 0; +} diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index b3b5ef5a..07a6ced0 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -151,3 +151,9 @@ export const CUSTOM_BUILDER_CONSTRUCTORS: Set = new Set(['MenuItem', 'Me } }); })(); + +export function resetComponentMap() { + ID_ATTRS.clear(); + EXTEND_ATTRIBUTE.clear(); + STYLES_ATTRIBUTE.clear(); +} diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 1785668c..32cc5535 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -256,7 +256,7 @@ interface extendInfo { compName: string } -export const files: ts.MapLike<{ version: number }> = {}; +export let files: ts.MapLike<{ version: number }> = {}; function createHash(str: string): string { const hash = crypto.createHash('sha256'); @@ -389,7 +389,6 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r globalProgram.program = globalProgram.builderProgram.getProgram(); stopTimeStatisticsLocation(compilationTime ? compilationTime.createProgramTime : undefined); - collectSourceFilesMap(globalProgram.program); if (process.env.watchMode !== 'true') { processBuildHap(cacheFile, rootFileNames, compilationTime); } @@ -1223,4 +1222,17 @@ export function etsStandaloneChecker(entryObj, logger, projectConfig): void { allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { printDiagnostic(diagnostic); }); -} \ No newline at end of file +} + +export function resetEtsCheck() { + files = {}; + cache = {}; + languageService = null; + allResolvedModules.clear(); + checkerResult.count = 0; + warnCheckerResult.count = 0; + resolvedModulesCache.clear(); + dollarCollection.clear(); + decoratorParamsCollection.clear(); + extendCollection.clear(); +} diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index ae20ed29..6f871fe0 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -40,7 +40,8 @@ import { CompilationTimeStatistics, getHookEventFactory, genLoaderOutPathOfHar, - harFilesRecord + harFilesRecord, + resetUtils } from '../../utils'; import { preprocessExtend, @@ -49,39 +50,47 @@ import { propertyCollection, linkCollection, resetComponentCollection, - componentCollection + componentCollection, + resetValidateUiSyntax } from '../../validate_ui_syntax'; import { processUISyntax, resetLog, - transformLog + transformLog, + resetProcessUiSyntax } from '../../process_ui_syntax'; import { projectConfig, abilityPagesFullPath, - globalProgram + globalProgram, + resetMain } from '../../../main'; import { appComponentCollection, compilerOptions as etsCheckerCompilerOptions, resolveModuleNames, - resolveTypeReferenceDirectives + resolveTypeReferenceDirectives, + resetEtsCheck } from '../../ets_checker'; import { CUSTOM_BUILDER_METHOD, GLOBAL_CUSTOM_BUILDER_METHOD, - INNER_CUSTOM_BUILDER_METHOD + INNER_CUSTOM_BUILDER_METHOD, + resetComponentMap } from '../../component_map'; import { kitTransformLog, processKitImport } from '../../process_kit_import'; +import { resetCompileInfo } from '../../compile_info'; +import { resetProcessComponentBuild } from '../../process_component_build'; +import { resetProcessComponentMember } from '../../process_component_member'; const filter:any = createFilter(/(? Date: Thu, 4 Jan 2024 12:37:57 +0000 Subject: [PATCH 12/19] cleanModuleMode Change-Id: I61fad9c2b1d6b9400a4c9cca9a3c46b2045486b2 --- .../ark_compiler/generate_module_abc.ts | 24 ++++++++++++------- compiler/src/fast_build/ark_compiler/utils.ts | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts index f6cb44ab..49688632 100644 --- a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts +++ b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts @@ -25,6 +25,8 @@ import { stopEvent } from '../../utils'; +let moduleMode: ModuleMode = null; + export async function generateModuleAbc(error) { const hookEventFactory = getHookEventFactory(this.share, 'genAbc', 'buildEnd'); if (error) { @@ -45,17 +47,23 @@ export async function generateModuleAbc(error) { function generateAbc(rollupObject: any, parentEvent: any) { const eventGenerateAbc = createAndStartEvent(parentEvent, 'generate abc'); if (rollupObject.share.projectConfig.watchMode !== 'true') { - const moduleBuildMode: ModuleBuildMode = new ModuleBuildMode(rollupObject); - moduleBuildMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = new ModuleBuildMode(rollupObject); + moduleMode.generateAbc(rollupObject, eventGenerateAbc); } else if (rollupObject.share.arkProjectConfig.hotReload) { - const moduleHotreloadMode: ModuleHotreloadMode = new ModuleHotreloadMode(rollupObject); - moduleHotreloadMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = new ModuleHotreloadMode(rollupObject); + moduleMode.generateAbc(rollupObject, eventGenerateAbc); } else if (rollupObject.share.arkProjectConfig.hotFix) { - const moduleHotfixMode: ModuleHotfixMode = new ModuleHotfixMode(rollupObject); - moduleHotfixMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = new ModuleHotfixMode(rollupObject); + moduleMode.generateAbc(rollupObject, eventGenerateAbc); } else { - const modulePreviewMode: ModulePreviewMode = new ModulePreviewMode(rollupObject); - modulePreviewMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = new ModulePreviewMode(rollupObject); + moduleMode.generateAbc(rollupObject, eventGenerateAbc); } stopEvent(eventGenerateAbc); } + +export function cleanModuleMode() { + moduleMode.triggerAsync = null; + moduleMode.triggerEndSignal = null; + moduleMode = null; +} \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/utils.ts b/compiler/src/fast_build/ark_compiler/utils.ts index f5d0f1dd..93d4bec6 100644 --- a/compiler/src/fast_build/ark_compiler/utils.ts +++ b/compiler/src/fast_build/ark_compiler/utils.ts @@ -49,6 +49,7 @@ import { newSourceMaps } from './transform'; import { hasTsNoCheckOrTsIgnoreFiles, compilingEtsOrTsFiles } from '../../process_kit_import'; import { cleanSourceMapObject } from './transform'; import { cleanUpKitImportObjects } from '../../process_kit_import'; +import { cleanModuleMode } from './process_kit_import'; export function needAotCompiler(projectConfig: any): boolean { return projectConfig.compileMode === ESMODULE && (projectConfig.anBuildMode === AOT_FULL || @@ -238,6 +239,7 @@ export function cleanUpObjects(): void { cleanSourceMapObject(); cleanUpUtilsObjects(); cleanUpKitImportObjects(); + cleanModuleMode(); } export const utUtils = { -- Gitee From d3e7067b168c28ff7240b890ffcaf495c1dfa4e2 Mon Sep 17 00:00:00 2001 From: c00513733 Date: Wed, 20 Dec 2023 11:49:37 +0000 Subject: [PATCH 13/19] Cache language service Signed-off-by: c00513733 Change-Id: I64ec330819b0f4f7c3d87c497f3e153231925e8e --- compiler/src/compile_info.ts | 2 +- compiler/src/do_arkTS_linter.ts | 110 +++++++++++++++--- compiler/src/ets_checker.ts | 83 ++++++++++--- .../ets_ui/rollup-plugin-ets-checker.ts | 2 +- compiler/src/pre_define.ts | 1 + compiler/src/process_component_build.ts | 2 +- 6 files changed, 167 insertions(+), 33 deletions(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 9ba688b7..1a5c07c3 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -70,7 +70,7 @@ configure({ }); export const logger = getLogger('ETS'); -export const props: string[] = []; +// export const props: string[] = []; const checkErrorMessage: Set = new Set([]); interface Info { diff --git a/compiler/src/do_arkTS_linter.ts b/compiler/src/do_arkTS_linter.ts index 543900d4..5a81cbe5 100644 --- a/compiler/src/do_arkTS_linter.ts +++ b/compiler/src/do_arkTS_linter.ts @@ -20,8 +20,10 @@ import { projectConfig } from '../main'; import { toUnixPath } from './utils'; import { resolveModuleNames, - resolveTypeReferenceDirectives -} from './ets_checker' + resolveTypeReferenceDirectives, + fileHashScriptVersion, +} from './ets_checker'; +import { ARKTS_LINTER_BUILD_INFO_SUFFIX } from './pre_define'; const arkTSDir: string = 'ArkTS'; const arkTSLinterOutputFileName: string = 'ArkTSLinter_output.json'; @@ -46,27 +48,29 @@ export enum ArkTSVersion { ArkTS_1_1, } +export interface ArkTSProgram { + builderProgram: ts.BuilderProgram, + wasStrict: boolean +} + export type ProcessDiagnosticsFunc = (diagnostics: ts.Diagnostic) => void; -export function doArkTSLinter(arkTSVersion: ArkTSVersion, builderProgram: ts.BuilderProgram, - arkTSMode: ArkTSLinterMode, printDiagnostic: ProcessDiagnosticsFunc, - shouldWriteFile: boolean = true, buildInfoWriteFile?: ts.WriteFileCallback): ts.Diagnostic[] { +export function doArkTSLinter(arkTSVersion: ArkTSVersion, arkTSMode: ArkTSLinterMode, + builderProgram: ArkTSProgram, reverseStrictProgram: ArkTSProgram, + printDiagnostic: ProcessDiagnosticsFunc, shouldWriteFile: boolean = true, + buildInfoWriteFile?: ts.WriteFileCallback): ts.Diagnostic[] { if (arkTSMode === ArkTSLinterMode.NOT_USE) { return []; } - const compilerHost: ts.CompilerHost = ts.createIncrementalCompilerHost(builderProgram.getProgram().getCompilerOptions()); - compilerHost.resolveModuleNames = resolveModuleNames; - compilerHost.getCurrentDirectory = () => process.cwd(); - compilerHost.getDefaultLibFileName = options => ts.getDefaultLibFilePath(options); - compilerHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives; - let diagnostics: ts.Diagnostic[] = []; if (arkTSVersion === ArkTSVersion.ArkTS_1_0) { - diagnostics = ts.ArkTSLinter_1_0.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); + diagnostics = ts.ArkTSLinter_1_0.runArkTSLinter(builderProgram, reverseStrictProgram, + /*srcFile*/ undefined, buildInfoWriteFile); } else { - diagnostics = ts.ArkTSLinter_1_1.runArkTSLinter(builderProgram, compilerHost, /*srcFile*/ undefined, buildInfoWriteFile); + diagnostics = ts.ArkTSLinter_1_1.runArkTSLinter(builderProgram, reverseStrictProgram, + /*srcFile*/ undefined, buildInfoWriteFile); } removeOutputFile(); @@ -183,3 +187,83 @@ function printArkTSLinterFAQ(diagnostics: ts.Diagnostic[], printDiagnostic: Proc }; printDiagnostic(arkTSFAQDiagnostic); } + +function setCompilerOptions(originProgram: ts.Program, wasStrict: boolean): ts.CompilerOptions { + const compilerOptions: ts.CompilerOptions = { ...originProgram.getCompilerOptions() }; + const inversedOptions = getStrictOptions(wasStrict); + + Object.assign(compilerOptions, inversedOptions); + compilerOptions.allowJs = true; + compilerOptions.checkJs = true; + compilerOptions.tsBuildInfoFile = path.resolve(projectConfig.cachePath, '..', ARKTS_LINTER_BUILD_INFO_SUFFIX); + + return compilerOptions; +} + +export function getReverseStrictBuilderProgram(rollupShareObject: any, originProgram: ts.Program, + wasStrict: boolean): ts.BuilderProgram { + let cacheManagerKey: string = projectConfig.entryModuleName; + let cacheServiceKey: string = 'linter_service'; + let service: ts.LanguageService | undefined = + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).getCache(cacheServiceKey); + if (!service) { + // create language service for linter + const compilerOptions: ts.CompilerOptions = setCompilerOptions(originProgram, wasStrict); + const servicesHost: ts.LanguageServiceHost = { + getScriptFileNames: () => [...originProgram.getRootFileNames()], + getScriptVersion: fileHashScriptVersion, + getScriptSnapshot: fileName => { + if (!fs.existsSync(fileName)) { + return undefined; + } + return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString()); + }, + getCurrentDirectory: () => process.cwd(), + getCompilationSettings: () => compilerOptions, + getDefaultLibFileName: options => ts.getDefaultLibFilePath(options), + fileExists: ts.sys.fileExists, + readFile: ts.sys.readFile, + readDirectory: ts.sys.readDirectory, + resolveModuleNames: resolveModuleNames, + resolveTypeReferenceDirectives: resolveTypeReferenceDirectives, + directoryExists: ts.sys.directoryExists, + getDirectories: ts.sys.getDirectories, + getFileCheckedModuleInfo:(containFilePath: string)=>{ + return { + fileNeedCheck: true, + checkPayload: undefined, + currentFileName: containFilePath, + }; + } + }; + + service = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); + } + + service.updateRootFiles([...originProgram.getRootFileNames()]); + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).setCache(cacheServiceKey, service); + + return service.getBuilderProgram(); +} + +function getStrictOptions(strict = true) { + return { + strictNullChecks: strict, + strictFunctionTypes: strict, + strictPropertyInitialization: strict, + noImplicitReturns: strict, + }; +} + +/** + * Returns true if options were initially strict + */ +export function inverseStrictOptions(compilerOptions: ts.CompilerOptions): boolean { + const strictOptions = getStrictOptions(); + let wasStrict = false; + Object.keys(strictOptions).forEach(x => { + wasStrict = wasStrict || !!compilerOptions[x]; + }); + // wasStrict evaluates true if any of the strict options was set + return wasStrict; +} diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index b74a84b4..968aff42 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -16,8 +16,8 @@ import fs from 'fs'; import path from 'path'; import * as ts from 'typescript'; -const fse = require('fs-extra'); import * as crypto from 'crypto'; +const fse = require('fs-extra'); import { projectConfig, @@ -73,10 +73,7 @@ import { INNER_COMPONENT_NAMES, JS_BIND_COMPONENTS } from './component_map'; -import { - props, - logger -} from './compile_info'; +import { logger } from './compile_info'; import { hasDecorator, isString, @@ -92,9 +89,17 @@ import { import { isExtendFunction, isOriginalExtend } from './process_ui_syntax'; import { visualTransform } from './process_visual'; import { tsWatchEmitter } from './fast_build/ets_ui/rollup-plugin-ets-checker'; -import { doArkTSLinter, ArkTSLinterMode, ArkTSVersion } from './do_arkTS_linter'; +import { + doArkTSLinter, + ArkTSLinterMode, + ArkTSProgram, + ArkTSVersion, + getReverseStrictBuilderProgram, + inverseStrictOptions +} from './do_arkTS_linter'; export const SOURCE_FILES: Map = new Map(); +export var props: string[] = []; function collectSourceFilesMap(program: ts.Program): void { program.getSourceFiles().forEach((sourceFile: ts.SourceFile) => { @@ -257,7 +262,7 @@ function createHash(str: string): string { return hash.digest('hex'); } -const fileHashScriptVersion: (fileName: string) => string = (fileName: string) => { +export const fileHashScriptVersion: (fileName: string) => string = (fileName: string) => { return createHash(fs.readFileSync(fileName).toString()); } @@ -269,7 +274,7 @@ const watchModeScriptVersion: (fileName: string) => string = (fileName: string) } export function createLanguageService(rootFileNames: string[], resolveModulePaths: string[], - compilationTime: CompilationTimeStatistics = null): ts.LanguageService { + compilationTime: CompilationTimeStatistics = null, rollupShareObject?: any): ts.LanguageService { setCompilerOptions(resolveModulePaths); rootFileNames.forEach((fileName: string) => { files[fileName] = {version: 0}; @@ -311,9 +316,35 @@ export function createLanguageService(rootFileNames: string[], resolveModulePath checkPayload: undefined, currentFileName: containFilePath, }; + }, + getProps: () => { + return props; + }, + clearProps: () => { + dollarCollection.clear(); + decoratorParamsCollection.clear(); + extendCollection.clear(); + props = [] } }; - return ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); + + if (process.env.watchMode === 'true') { + return ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); + } + + let cacheManagerKey: string = projectConfig.entryModuleName; + let cacheServiceKey: string = 'service'; + let service: ts.LanguageService | undefined = + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).getCache(cacheServiceKey); + if (!service) { + service = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); + } + + let updateRootFileNames = [...rootFileNames, ...readDeaclareFiles()]; + service.updateRootFiles(updateRootFileNames); + + rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).setCache(cacheServiceKey, service); + return service; } interface CacheFileName { @@ -351,7 +382,7 @@ export const checkerResult: CheckerResult = {count: 0}; export const warnCheckerResult: WarnCheckerResult = {count: 0}; export let languageService: ts.LanguageService = null; export function serviceChecker(rootFileNames: string[], newLogger: any = null, resolveModulePaths: string[] = null, parentEvent?: any, - compilationTime: CompilationTimeStatistics = null): void { + compilationTime: CompilationTimeStatistics = null, rollupShareObject?: any): void { fastBuildLogger = newLogger; let cacheFile: string = null; if (projectConfig.xtsMode || process.env.watchMode === 'true') { @@ -371,15 +402,17 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r } else { cache = {}; } - const filterFiles: string[] = filterInput(rootFileNames); - languageService = createLanguageService(filterFiles, resolveModulePaths, compilationTime); + languageService = createLanguageService(rootFileNames, resolveModulePaths, compilationTime, rollupShareObject); } startTimeStatisticsLocation(compilationTime ? compilationTime.createProgramTime : undefined); - globalProgram.builderProgram = languageService.getBuilderProgram(); globalProgram.program = globalProgram.builderProgram.getProgram(); - + props = languageService.getProps(); stopTimeStatisticsLocation(compilationTime ? compilationTime.createProgramTime : undefined); + startTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); + runArkTSLinter(parentEvent, rollupShareObject); + stopTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); + // collectSourceFilesMap(globalProgram.program); if (process.env.watchMode !== 'true') { processBuildHap(cacheFile, rootFileNames, compilationTime); } @@ -1074,10 +1107,26 @@ export function incrementWatchFile(watchModifiedFiles: string[], }); } -function runArkTSLinter(parentEvent?: any): void { +function runArkTSLinter(parentEvent?: any, rollupShareObject?: any): void { const eventRunArkTsLinter = createAndStartEvent(parentEvent, 'run Arkts linter'); - const arkTSLinterDiagnostics = doArkTSLinter(getArkTSVersion(), globalProgram.builderProgram, getArkTSLinterMode(), - printArkTSLinterDiagnostic, !projectConfig.xtsMode, buildInfoWriteFile); + + let wasStrict: boolean = inverseStrictOptions(globalProgram.program.getCompilerOptions()); + let originProgram: ArkTSProgram = { + builderProgram: globalProgram.builderProgram, + wasStrict: wasStrict + }; + let reverseStrictProgram: ArkTSProgram = { + builderProgram: getReverseStrictBuilderProgram(rollupShareObject, globalProgram.program, wasStrict), + wasStrict: !wasStrict + }; + const arkTSLinterDiagnostics = doArkTSLinter(getArkTSVersion(), + getArkTSLinterMode(), + originProgram, + reverseStrictProgram, + printArkTSLinterDiagnostic, + !projectConfig.xtsMode, + buildInfoWriteFile); + if (process.env.watchMode !== 'true' && !projectConfig.xtsMode) { arkTSLinterDiagnostics.forEach((diagnostic: ts.Diagnostic) => { updateErrorFileCache(diagnostic); diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts index a15ce3ad..e062f8b8 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts @@ -93,7 +93,7 @@ export function etsChecker() { tsWatchEmitter.emit(TS_WATCH_END_MSG); } else { serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, - compilationTime); + compilationTime, this.share); } stopEvent(eventServiceChecker); setChecker(); diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 542e8f0d..39c04bd4 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -577,3 +577,4 @@ export const IS_INITIAL_ITEM = 'isInitialItem'; export const MY_IDS = 'myIds'; export const TS_BUILD_INFO_SUFFIX = '.tsbuildinfo'; +export const ARKTS_LINTER_BUILD_INFO_SUFFIX = 'inversedArkTsLinter.tsbuildinfo'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index bccc5c29..96292eb0 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -175,7 +175,7 @@ import { validatorCard, builderTypeParameter } from './process_ui_syntax'; -import { props } from './compile_info'; +import { props } from './ets_checker'; import { regularCollection } from './validate_ui_syntax'; const checkComponents: Set = new Set([ -- Gitee From 78749d9f1320c223e7c23c164f90bc9273c1150e Mon Sep 17 00:00:00 2001 From: c00513733 Date: Wed, 3 Jan 2024 08:31:19 +0000 Subject: [PATCH 14/19] Update cacheStroe key Signed-off-by: c00513733 Change-Id: I2eeeefa008d1c274115cdf2ffb5c12529bf4747f --- compiler/src/compile_info.ts | 2 +- compiler/src/do_arkTS_linter.ts | 4 ++-- compiler/src/ets_checker.ts | 6 ++++-- compiler/src/utils.ts | 6 ++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 1a5c07c3..c602079a 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -500,5 +500,5 @@ function handleFinishModules(modules, callback) { } export function resetCompileInfo() { - props.length = 0; + // props.length = 0; } diff --git a/compiler/src/do_arkTS_linter.ts b/compiler/src/do_arkTS_linter.ts index 5a81cbe5..578c0bcd 100644 --- a/compiler/src/do_arkTS_linter.ts +++ b/compiler/src/do_arkTS_linter.ts @@ -17,7 +17,7 @@ import fs from 'fs'; import path from 'path'; import * as ts from 'typescript'; import { projectConfig } from '../main'; -import { toUnixPath } from './utils'; +import { toUnixPath, getRollupCacheManagerKey } from './utils'; import { resolveModuleNames, resolveTypeReferenceDirectives, @@ -202,7 +202,7 @@ function setCompilerOptions(originProgram: ts.Program, wasStrict: boolean): ts.C export function getReverseStrictBuilderProgram(rollupShareObject: any, originProgram: ts.Program, wasStrict: boolean): ts.BuilderProgram { - let cacheManagerKey: string = projectConfig.entryModuleName; + let cacheManagerKey: string = getRollupCacheManagerKey(projectConfig); let cacheServiceKey: string = 'linter_service'; let service: ts.LanguageService | undefined = rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).getCache(cacheServiceKey); diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 968aff42..66f9aa2b 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -84,7 +84,8 @@ import { stopTimeStatisticsLocation, resolveModuleNamesTime, CompilationTimeStatistics, - storedFileInfo + storedFileInfo, + getRollupCacheManagerKey } from './utils'; import { isExtendFunction, isOriginalExtend } from './process_ui_syntax'; import { visualTransform } from './process_visual'; @@ -332,7 +333,7 @@ export function createLanguageService(rootFileNames: string[], resolveModulePath return ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); } - let cacheManagerKey: string = projectConfig.entryModuleName; + let cacheManagerKey: string = getRollupCacheManagerKey(projectConfig); let cacheServiceKey: string = 'service'; let service: ts.LanguageService | undefined = rollupShareObject?.cacheStoreManager?.mount(cacheManagerKey).getCache(cacheServiceKey); @@ -1235,6 +1236,7 @@ export function etsStandaloneChecker(entryObj, logger, projectConfig): void { const filterFiles: string[] = filterInput(rootFileNames); languageService = createLanguageService(filterFiles, resolveModulePaths); globalProgram.builderProgram = languageService.getBuilderProgram(); + globalProgram.program = globalProgram.builderProgram.getProgram(); runArkTSLinter(); const allDiagnostics: ts.Diagnostic[] = globalProgram.builderProgram .getSyntacticDiagnostics() diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index 3bc24d24..6de8cd90 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -959,6 +959,12 @@ export function isString(text: unknown): text is string { return typeof text === 'string'; } +export function getRollupCacheManagerKey(projectConfig: object): string { + let keyInfo: string[] = [projectConfig.compileSdkVersion, projectConfig.compatibleSdkVersion, projectConfig.runtimeOS, + projectConfig.etsLoaderPath, projectConfig.entryModuleName, projectConfig.widgetCompile]; + return keyInfo.join('#'); +} + export function getHookEventFactory(share: any, pluginName: string, hookName: string): any { if (typeof share.getHookEventFactory === 'function') { return share.getHookEventFactory(pluginName, hookName); -- Gitee From 198683a32299ef0b24131b986bd1779ffb8b9613 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Fri, 5 Jan 2024 03:50:46 +0000 Subject: [PATCH 15/19] cleanModuleMode Change-Id: Ic2a9f015644c9e57c7d1fba233b94bea042939be --- .../fast_build/ark_compiler/generate_module_abc.ts | 8 +++++--- .../src/fast_build/ark_compiler/module/module_mode.ts | 11 ++++++----- compiler/src/fast_build/ark_compiler/utils.ts | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts index 49688632..863b6214 100644 --- a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts +++ b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts @@ -63,7 +63,9 @@ function generateAbc(rollupObject: any, parentEvent: any) { } export function cleanModuleMode() { - moduleMode.triggerAsync = null; - moduleMode.triggerEndSignal = null; - moduleMode = null; + if (moduleMode) { + moduleMode.triggerAsync = null; + moduleMode.triggerEndSignal = null; + moduleMode = null; + } } \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_mode.ts index c3d5a42f..71dc3438 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -452,11 +452,8 @@ export class ModuleMode extends CommonMode { stopEvent(eventGenDescriptionsForMergedEs2abc); const genAbcCmd: string = this.cmdArgs.join(' '); try { - let eventGenAbc: any; - const child = this.triggerAsync(() => { - eventGenAbc = createAndStartEvent(parentEvent, 'generate merged abc by es2abc (async)', true); - return childProcess.exec(genAbcCmd, { windowsHide: true }); - }); + let eventGenAbc: any = createAndStartEvent(parentEvent, 'generate merged abc by es2abc (async)', true); + const child = this.triggerAsync(createChildProcess, genAbcCmd); child.on('close', (code: any) => { if (code === FAIL) { this.throwArkTsCompilerError('ArkTS:ERROR failed to execute es2abc'); @@ -767,3 +764,7 @@ export class ModuleMode extends CommonMode { }); } } + +function createChildProcess(genAbcCmd: string) { + return childProcess.exec(genAbcCmd, { windowsHide: true }); +} \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/utils.ts b/compiler/src/fast_build/ark_compiler/utils.ts index 93d4bec6..1aac35ee 100644 --- a/compiler/src/fast_build/ark_compiler/utils.ts +++ b/compiler/src/fast_build/ark_compiler/utils.ts @@ -49,7 +49,7 @@ import { newSourceMaps } from './transform'; import { hasTsNoCheckOrTsIgnoreFiles, compilingEtsOrTsFiles } from '../../process_kit_import'; import { cleanSourceMapObject } from './transform'; import { cleanUpKitImportObjects } from '../../process_kit_import'; -import { cleanModuleMode } from './process_kit_import'; +import { cleanModuleMode } from './generate_module_abc'; export function needAotCompiler(projectConfig: any): boolean { return projectConfig.compileMode === ESMODULE && (projectConfig.anBuildMode === AOT_FULL || -- Gitee From 9ce45ce951bf30980143f746ee44d298092d52b4 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Fri, 5 Jan 2024 06:15:40 +0000 Subject: [PATCH 16/19] clear the collection of obfuscation Change-Id: Ib9fea8f19c2521b80143dea936851e93a870891d --- .../ark_compiler/common/ob_config_resolver.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts index f6859dfa..4b183136 100644 --- a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts +++ b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts @@ -626,11 +626,11 @@ export function writeObfuscationNameCache(projectConfig:any, obfuscationCacheDir if (printNameCache && printNameCache.length > 0) { fs.writeFileSync(printNameCache, writeContent); } - renamePropertyModule.globalMangledTable.clear(); - renamePropertyModule.historyMangledTable.clear(); - renameFileNameModule.globalFileNameMangledTable.clear(); - renameFileNameModule.globalFileNameMangledTable.clear(); - ApiExtractor.mPropertySet.clear(); + renamePropertyModule.globalMangledTable?.clear(); + renamePropertyModule.historyMangledTable?.clear(); + renameFileNameModule.globalFileNameMangledTable?.clear(); + renameFileNameModule.globalFileNameMangledTable?.clear(); + ApiExtractor.mPropertySet?.clear(); } export function generateConsumerObConfigFile(obfuscationOptions: any, logger: any) { -- Gitee From f5c1e7cf9800777818930258e65c3e2a4ae7ba91 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Fri, 5 Jan 2024 07:54:45 +0000 Subject: [PATCH 17/19] cleanModuleMode Change-Id: Ide81a530363ba4814c760d0a95dafd0b0554173d --- .../ark_compiler/generate_module_abc.ts | 21 ++++++++++++------- .../ark_compiler/module/module_mode.ts | 11 +++++----- compiler/src/utils.ts | 5 ++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts index 863b6214..79314e9d 100644 --- a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts +++ b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts @@ -14,6 +14,7 @@ */ import { ESMODULE } from './common/ark_define'; +import { ModuleMode } from './module/module_mode'; import { ModuleBuildMode } from './module/module_build_mode'; import { ModuleHotfixMode } from './module/module_hotfix_mode'; import { ModuleHotreloadMode } from './module/module_hotreload_mode'; @@ -47,17 +48,21 @@ export async function generateModuleAbc(error) { function generateAbc(rollupObject: any, parentEvent: any) { const eventGenerateAbc = createAndStartEvent(parentEvent, 'generate abc'); if (rollupObject.share.projectConfig.watchMode !== 'true') { - moduleMode = new ModuleBuildMode(rollupObject); - moduleMode.generateAbc(rollupObject, eventGenerateAbc); + const moduleBuildMode: ModuleBuildMode = new ModuleBuildMode(rollupObject); + moduleBuildMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = moduleBuildMode; } else if (rollupObject.share.arkProjectConfig.hotReload) { - moduleMode = new ModuleHotreloadMode(rollupObject); - moduleMode.generateAbc(rollupObject, eventGenerateAbc); + const moduleHotreloadMode: ModuleHotreloadMode = new ModuleHotreloadMode(rollupObject); + moduleHotreloadMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = moduleHotreloadMode; } else if (rollupObject.share.arkProjectConfig.hotFix) { - moduleMode = new ModuleHotfixMode(rollupObject); - moduleMode.generateAbc(rollupObject, eventGenerateAbc); + const moduleHotfixMode: ModuleHotfixMode = new ModuleHotfixMode(rollupObject); + moduleHotfixMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = moduleHotfixMode; } else { - moduleMode = new ModulePreviewMode(rollupObject); - moduleMode.generateAbc(rollupObject, eventGenerateAbc); + const modulePreviewMode: ModulePreviewMode = new ModulePreviewMode(rollupObject); + modulePreviewMode.generateAbc(rollupObject, eventGenerateAbc); + moduleMode = modulePreviewMode; } stopEvent(eventGenerateAbc); } diff --git a/compiler/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_mode.ts index 71dc3438..a8a06425 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -452,8 +452,11 @@ export class ModuleMode extends CommonMode { stopEvent(eventGenDescriptionsForMergedEs2abc); const genAbcCmd: string = this.cmdArgs.join(' '); try { - let eventGenAbc: any = createAndStartEvent(parentEvent, 'generate merged abc by es2abc (async)', true); - const child = this.triggerAsync(createChildProcess, genAbcCmd); + let eventGenAbc: any; + const child = this.triggerAsync(() => { + eventGenAbc = createAndStartEvent(parentEvent, 'generate merged abc by es2abc (async)', true); + return childProcess.exec(genAbcCmd, { windowsHide: true }); + }); child.on('close', (code: any) => { if (code === FAIL) { this.throwArkTsCompilerError('ArkTS:ERROR failed to execute es2abc'); @@ -763,8 +766,4 @@ export class ModuleMode extends CommonMode { delete sourceMap[key]; }); } -} - -function createChildProcess(genAbcCmd: string) { - return childProcess.exec(genAbcCmd, { windowsHide: true }); } \ No newline at end of file diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index 6de8cd90..85c3b2ed 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -373,13 +373,12 @@ export function isPackageModulesFile(filePath: string, projectConfig: any): bool return true; } if (projectConfig.modulePathMap) { - for (const key in projectConfig.modulePathMap) { - const value: string = projectConfig.modulePathMap[key]; + projectConfig.modulePathMap.forEach((value: string) => { const fakeModulePkgModulesPath: string = toUnixPath(path.resolve(value, packageDir)); if (filePath.indexOf(fakeModulePkgModulesPath) !== -1) { return true; } - } + }) } } -- Gitee From 3c8e79219d1c321869d1a36fa483d3aa3cbec542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E5=93=A5?= Date: Fri, 5 Jan 2024 18:35:05 +0800 Subject: [PATCH 18/19] arkui --- compiler/main.js | 43 ------------------- compiler/src/compile_info.ts | 4 +- compiler/src/ets_checker.ts | 1 - .../ets_ui/rollup-plugin-ets-typescript.ts | 3 -- compiler/src/process_component_build.ts | 3 -- 5 files changed, 2 insertions(+), 52 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index f7472eca..35c1b6db 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -876,49 +876,6 @@ function partialUpdateController(minAPIVersion, metadata = null) { } } -function resetMain() { - globalProgram.builderProgram = null; - globalProgram.program = null; - globalProgram.checker = null; - projectConfig.entryObj = undefined; - projectConfig.cardObj = undefined; - projectConfig.projectPath = undefined; - projectConfig.buildPath = undefined; - projectConfig.aceModuleBuild = undefined - projectConfig.manifestFilePath = undefined; - projectConfig.aceProfilePath = undefined; - projectConfig.aceModuleJsonPath = undefined - projectConfig.hashProjectPath = undefined; - projectConfig.aceBuildJson = undefined; - projectConfig.aceSoPath = undefined; - projectConfig.xtsMode = undefined; - projectConfig.localPropertiesPath = undefined; - projectConfig.projectProfilePath = undefined; - projectConfig.isPreview = undefined; - projectConfig.runtimeOS = undefined; - projectConfig.sdkInfo = undefined; - projectConfig.compileHar = false; - projectConfig.compileShared = false; - projectConfig.splitCommon = false; - projectConfig.checkEntry = undefined; - projectConfig.obfuscateHarType = undefined; - projectConfig.packageDir = 'node_modules'; - projectConfig.packageJson = 'package.json'; - projectConfig.packageManagerType = 'npm'; - projectConfig.cardEntryObj = undefined; - projectConfig.compilerTypes = undefined; - projectConfig.isCrossplatform = undefined; - projectConfig.enableDebugLine = undefined; - projectConfig.bundleType = undefined; - if (projectConfig.isPreview) { - abilityPagesFullPath = []; - } - if (process.env.watchMode !== 'true') { - projectConfig.compileMode = undefined; - projectConfig.cachePath = undefined; - } -} - const globalProgram = { builderProgram: null, program: null, diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index c602079a..9ba688b7 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -70,7 +70,7 @@ configure({ }); export const logger = getLogger('ETS'); -// export const props: string[] = []; +export const props: string[] = []; const checkErrorMessage: Set = new Set([]); interface Info { @@ -500,5 +500,5 @@ function handleFinishModules(modules, callback) { } export function resetCompileInfo() { - // props.length = 0; + props.length = 0; } diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 66f9aa2b..78b02877 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -413,7 +413,6 @@ export function serviceChecker(rootFileNames: string[], newLogger: any = null, r startTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); runArkTSLinter(parentEvent, rollupShareObject); stopTimeStatisticsLocation(compilationTime ? compilationTime.runArkTSLinterTime : undefined); - // collectSourceFilesMap(globalProgram.program); if (process.env.watchMode !== 'true') { processBuildHap(cacheFile, rootFileNames, compilationTime); } diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index 6f871fe0..5d196c01 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -83,7 +83,6 @@ import { processKitImport } from '../../process_kit_import'; import { resetCompileInfo } from '../../compile_info'; -import { resetProcessComponentBuild } from '../../process_component_build'; import { resetProcessComponentMember } from '../../process_component_member'; const filter:any = createFilter(/(? Date: Sat, 6 Jan 2024 07:45:04 +0000 Subject: [PATCH 19/19] fix bug Change-Id: Icaf01d06b8ef907fb5444c9e8cde7888f80d283d --- compiler/src/fast_build/ark_compiler/generate_module_abc.ts | 2 +- compiler/src/utils.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts index 79314e9d..bcbcd0c7 100644 --- a/compiler/src/fast_build/ark_compiler/generate_module_abc.ts +++ b/compiler/src/fast_build/ark_compiler/generate_module_abc.ts @@ -14,7 +14,7 @@ */ import { ESMODULE } from './common/ark_define'; -import { ModuleMode } from './module/module_mode'; +import type { ModuleMode } from './module/module_mode'; import { ModuleBuildMode } from './module/module_build_mode'; import { ModuleHotfixMode } from './module/module_hotfix_mode'; import { ModuleHotreloadMode } from './module/module_hotreload_mode'; diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index 85c3b2ed..6de8cd90 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -373,12 +373,13 @@ export function isPackageModulesFile(filePath: string, projectConfig: any): bool return true; } if (projectConfig.modulePathMap) { - projectConfig.modulePathMap.forEach((value: string) => { + for (const key in projectConfig.modulePathMap) { + const value: string = projectConfig.modulePathMap[key]; const fakeModulePkgModulesPath: string = toUnixPath(path.resolve(value, packageDir)); if (filePath.indexOf(fakeModulePkgModulesPath) !== -1) { return true; } - }) + } } } -- Gitee