107ac75b1Sopenharmony_ci/* 207ac75b1Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 307ac75b1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 407ac75b1Sopenharmony_ci * you may not use this file except in compliance with the License. 507ac75b1Sopenharmony_ci * You may obtain a copy of the License at 607ac75b1Sopenharmony_ci * 707ac75b1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 807ac75b1Sopenharmony_ci * 907ac75b1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1007ac75b1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1107ac75b1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1207ac75b1Sopenharmony_ci * See the License for the specific language governing permissions and 1307ac75b1Sopenharmony_ci * limitations under the License. 1407ac75b1Sopenharmony_ci */ 1507ac75b1Sopenharmony_ci 1607ac75b1Sopenharmony_ciimport ts from 'typescript'; 1707ac75b1Sopenharmony_ciimport fs from 'fs'; 1807ac75b1Sopenharmony_ciimport path from 'path'; 1907ac75b1Sopenharmony_ciimport JSON5 from 'json5'; 2007ac75b1Sopenharmony_ci 2107ac75b1Sopenharmony_ciimport { 2207ac75b1Sopenharmony_ci EXTNAME_ETS, 2307ac75b1Sopenharmony_ci EXTNAME_TS, 2407ac75b1Sopenharmony_ci INDEX_ETS, 2507ac75b1Sopenharmony_ci INDEX_TS, 2607ac75b1Sopenharmony_ci CUSTOM_COMPONENT_DEFAULT, 2707ac75b1Sopenharmony_ci CUSTOM_DECORATOR_NAME, 2807ac75b1Sopenharmony_ci COMPONENT_DECORATOR_ENTRY, 2907ac75b1Sopenharmony_ci COMPONENT_BUILDER_DECORATOR, 3007ac75b1Sopenharmony_ci DECORATOR_REUSEABLE 3107ac75b1Sopenharmony_ci} from './pre_define'; 3207ac75b1Sopenharmony_ciimport { 3307ac75b1Sopenharmony_ci propertyCollection, 3407ac75b1Sopenharmony_ci linkCollection, 3507ac75b1Sopenharmony_ci componentCollection, 3607ac75b1Sopenharmony_ci preprocessExtend, 3707ac75b1Sopenharmony_ci preprocessNewExtend, 3807ac75b1Sopenharmony_ci processSystemApi, 3907ac75b1Sopenharmony_ci propCollection, 4007ac75b1Sopenharmony_ci isObservedClass, 4107ac75b1Sopenharmony_ci isCustomDialogClass, 4207ac75b1Sopenharmony_ci observedClassCollection, 4307ac75b1Sopenharmony_ci enumCollection, 4407ac75b1Sopenharmony_ci getComponentSet, 4507ac75b1Sopenharmony_ci IComponentSet, 4607ac75b1Sopenharmony_ci builderParamObjectCollection, 4707ac75b1Sopenharmony_ci stateCollection, 4807ac75b1Sopenharmony_ci regularCollection, 4907ac75b1Sopenharmony_ci storagePropCollection, 5007ac75b1Sopenharmony_ci storageLinkCollection, 5107ac75b1Sopenharmony_ci provideCollection, 5207ac75b1Sopenharmony_ci consumeCollection, 5307ac75b1Sopenharmony_ci objectLinkCollection, 5407ac75b1Sopenharmony_ci localStorageLinkCollection, 5507ac75b1Sopenharmony_ci localStoragePropCollection, 5607ac75b1Sopenharmony_ci builderParamInitialization, 5707ac75b1Sopenharmony_ci propInitialization, 5807ac75b1Sopenharmony_ci regularInitialization, 5907ac75b1Sopenharmony_ci stateInitialization, 6007ac75b1Sopenharmony_ci provideInitialization, 6107ac75b1Sopenharmony_ci privateCollection 6207ac75b1Sopenharmony_ci} from './validate_ui_syntax'; 6307ac75b1Sopenharmony_ciimport { 6407ac75b1Sopenharmony_ci getExtensionIfUnfullySpecifiedFilepath, 6507ac75b1Sopenharmony_ci hasDecorator, 6607ac75b1Sopenharmony_ci LogInfo, 6707ac75b1Sopenharmony_ci LogType, 6807ac75b1Sopenharmony_ci storedFileInfo 6907ac75b1Sopenharmony_ci} from './utils'; 7007ac75b1Sopenharmony_ciimport { 7107ac75b1Sopenharmony_ci projectConfig, 7207ac75b1Sopenharmony_ci sdkConfigs, 7307ac75b1Sopenharmony_ci sdkConfigPrefix, 7407ac75b1Sopenharmony_ci globalProgram 7507ac75b1Sopenharmony_ci} from '../main'; 7607ac75b1Sopenharmony_ciimport { 7707ac75b1Sopenharmony_ci CUSTOM_BUILDER_METHOD, 7807ac75b1Sopenharmony_ci INNER_COMPONENT_NAMES, 7907ac75b1Sopenharmony_ci GLOBAL_CUSTOM_BUILDER_METHOD 8007ac75b1Sopenharmony_ci} from './component_map'; 8107ac75b1Sopenharmony_ciimport { 8207ac75b1Sopenharmony_ci type ResolveModuleInfo, 8307ac75b1Sopenharmony_ci SOURCE_FILES 8407ac75b1Sopenharmony_ci} from './ets_checker'; 8507ac75b1Sopenharmony_ciimport { 8607ac75b1Sopenharmony_ci getRealModulePath, 8707ac75b1Sopenharmony_ci validateModuleSpecifier 8807ac75b1Sopenharmony_ci} from './fast_build/system_api/api_check_utils'; 8907ac75b1Sopenharmony_ciimport processStructComponentV2, { StructInfo } from './process_struct_componentV2'; 9007ac75b1Sopenharmony_ci 9107ac75b1Sopenharmony_ciconst IMPORT_FILE_ASTCACHE: Map<string, ts.SourceFile> = 9207ac75b1Sopenharmony_ci process.env.watchMode === 'true' ? new Map() : (SOURCE_FILES || new Map()); 9307ac75b1Sopenharmony_ci 9407ac75b1Sopenharmony_ciexport default function processImport(node: ts.ImportDeclaration | ts.ImportEqualsDeclaration | 9507ac75b1Sopenharmony_ci ts.ExportDeclaration, pagesDir: string, log: LogInfo[], asName: Map<string, string> = new Map(), 9607ac75b1Sopenharmony_ci isEntryPage: boolean = true, pathCollection: Set<string> = new Set()): void { 9707ac75b1Sopenharmony_ci let filePath: string; 9807ac75b1Sopenharmony_ci let defaultName: string; 9907ac75b1Sopenharmony_ci if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) { 10007ac75b1Sopenharmony_ci filePath = node.moduleSpecifier.getText().replace(/'|"/g, ''); 10107ac75b1Sopenharmony_ci if (ts.isImportDeclaration(node) && node.importClause && node.importClause.name && 10207ac75b1Sopenharmony_ci ts.isIdentifier(node.importClause.name)) { 10307ac75b1Sopenharmony_ci defaultName = node.importClause.name.escapedText.toString(); 10407ac75b1Sopenharmony_ci if (isEntryPage) { 10507ac75b1Sopenharmony_ci asName.set(defaultName, defaultName); 10607ac75b1Sopenharmony_ci } 10707ac75b1Sopenharmony_ci } 10807ac75b1Sopenharmony_ci if (ts.isImportDeclaration(node) && node.importClause && node.importClause.namedBindings && 10907ac75b1Sopenharmony_ci ts.isNamedImports(node.importClause.namedBindings) && 11007ac75b1Sopenharmony_ci node.importClause.namedBindings.elements && isEntryPage) { 11107ac75b1Sopenharmony_ci validateModuleSpecifier(node.moduleSpecifier, log); 11207ac75b1Sopenharmony_ci node.importClause.namedBindings.elements.forEach(item => { 11307ac75b1Sopenharmony_ci if (item.name && ts.isIdentifier(item.name)) { 11407ac75b1Sopenharmony_ci validateModuleName(item.name, log); 11507ac75b1Sopenharmony_ci if (item.propertyName && ts.isIdentifier(item.propertyName) && asName) { 11607ac75b1Sopenharmony_ci asName.set(item.propertyName.escapedText.toString(), item.name.escapedText.toString()); 11707ac75b1Sopenharmony_ci } else { 11807ac75b1Sopenharmony_ci asName.set(item.name.escapedText.toString(), item.name.escapedText.toString()); 11907ac75b1Sopenharmony_ci } 12007ac75b1Sopenharmony_ci } 12107ac75b1Sopenharmony_ci }); 12207ac75b1Sopenharmony_ci } 12307ac75b1Sopenharmony_ci } else { 12407ac75b1Sopenharmony_ci if (node.moduleReference && ts.isExternalModuleReference(node.moduleReference) && 12507ac75b1Sopenharmony_ci node.moduleReference.expression && ts.isStringLiteral(node.moduleReference.expression)) { 12607ac75b1Sopenharmony_ci filePath = node.moduleReference.expression.text; 12707ac75b1Sopenharmony_ci defaultName = node.name.escapedText.toString(); 12807ac75b1Sopenharmony_ci if (isEntryPage) { 12907ac75b1Sopenharmony_ci asName.set(defaultName, defaultName); 13007ac75b1Sopenharmony_ci } 13107ac75b1Sopenharmony_ci } 13207ac75b1Sopenharmony_ci } 13307ac75b1Sopenharmony_ci 13407ac75b1Sopenharmony_ci try { 13507ac75b1Sopenharmony_ci const fileResolvePath: string = getFileFullPath(filePath, pagesDir); 13607ac75b1Sopenharmony_ci if (fs.existsSync(fileResolvePath) && fs.statSync(fileResolvePath).isFile() && 13707ac75b1Sopenharmony_ci !pathCollection.has(fileResolvePath)) { 13807ac75b1Sopenharmony_ci let sourceFile: ts.SourceFile; 13907ac75b1Sopenharmony_ci pathCollection.add(fileResolvePath); 14007ac75b1Sopenharmony_ci if (IMPORT_FILE_ASTCACHE.has(fileResolvePath)) { 14107ac75b1Sopenharmony_ci sourceFile = IMPORT_FILE_ASTCACHE.get(fileResolvePath); 14207ac75b1Sopenharmony_ci } else { 14307ac75b1Sopenharmony_ci sourceFile = generateSourceFileAST(fileResolvePath, filePath); 14407ac75b1Sopenharmony_ci IMPORT_FILE_ASTCACHE[fileResolvePath] = sourceFile; 14507ac75b1Sopenharmony_ci } 14607ac75b1Sopenharmony_ci visitAllNode(sourceFile, sourceFile, defaultName, asName, path.dirname(fileResolvePath), log, 14707ac75b1Sopenharmony_ci new Set(), new Set(), new Set(), new Map(), pathCollection, fileResolvePath, /\.d\.ets$/.test(fileResolvePath)); 14807ac75b1Sopenharmony_ci } 14907ac75b1Sopenharmony_ci } catch (e) { 15007ac75b1Sopenharmony_ci // ignore 15107ac75b1Sopenharmony_ci } 15207ac75b1Sopenharmony_ci} 15307ac75b1Sopenharmony_ci 15407ac75b1Sopenharmony_cifunction generateSourceFileAST(fileResolvePath: string, filePath: string): ts.SourceFile { 15507ac75b1Sopenharmony_ci const originContent: string = fs.readFileSync(fileResolvePath, { encoding: 'utf-8' }); 15607ac75b1Sopenharmony_ci const content: string = path.extname(fileResolvePath) === EXTNAME_ETS ? 15707ac75b1Sopenharmony_ci preprocessNewExtend(preprocessExtend(processSystemApi(originContent))) : originContent; 15807ac75b1Sopenharmony_ci return ts.createSourceFile(fileResolvePath, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.ETS); 15907ac75b1Sopenharmony_ci} 16007ac75b1Sopenharmony_ci 16107ac75b1Sopenharmony_citype structDecoratorResult = { 16207ac75b1Sopenharmony_ci hasRecycle: boolean 16307ac75b1Sopenharmony_ci}; 16407ac75b1Sopenharmony_ci 16507ac75b1Sopenharmony_ciconst MODIFIER_LENGTH: number = 2; 16607ac75b1Sopenharmony_ci 16707ac75b1Sopenharmony_cifunction visitAllNode(node: ts.Node, sourceFile: ts.SourceFile, defaultNameFromParent: string, 16807ac75b1Sopenharmony_ci asNameFromParent: Map<string, string>, pagesDir: string, log: LogInfo[], entryCollection: Set<string>, 16907ac75b1Sopenharmony_ci exportCollection: Set<string>, defaultCollection: Set<string>, asExportCollection: Map<string, string>, 17007ac75b1Sopenharmony_ci pathCollection: Set<string>, fileResolvePath: string, isDETS: boolean): void { 17107ac75b1Sopenharmony_ci if (isObservedClass(node)) { 17207ac75b1Sopenharmony_ci collectSpecialFunctionNode(node as ts.ClassDeclaration, asNameFromParent, defaultNameFromParent, defaultCollection, 17307ac75b1Sopenharmony_ci asExportCollection, observedClassCollection); 17407ac75b1Sopenharmony_ci // @ts-ignore 17507ac75b1Sopenharmony_ci observedClassCollection.add(node.name.getText()); 17607ac75b1Sopenharmony_ci } 17707ac75b1Sopenharmony_ci if (isCustomDialogClass(node)) { 17807ac75b1Sopenharmony_ci collectSpecialFunctionNode(node as ts.StructDeclaration, asNameFromParent, defaultNameFromParent, defaultCollection, 17907ac75b1Sopenharmony_ci asExportCollection, componentCollection.customDialogs); 18007ac75b1Sopenharmony_ci // @ts-ignore 18107ac75b1Sopenharmony_ci componentCollection.customDialogs.add(node.name.getText()); 18207ac75b1Sopenharmony_ci } 18307ac75b1Sopenharmony_ci if (ts.isEnumDeclaration(node) && node.name) { 18407ac75b1Sopenharmony_ci enumCollection.add(node.name.getText()); 18507ac75b1Sopenharmony_ci } 18607ac75b1Sopenharmony_ci const structDecorator: structDecoratorResult = { hasRecycle: false }; 18707ac75b1Sopenharmony_ci if (ts.isStructDeclaration(node) && ts.isIdentifier(node.name) && isCustomComponent(node, structDecorator)) { 18807ac75b1Sopenharmony_ci addDependencies(node, defaultNameFromParent, asNameFromParent, isDETS, structDecorator); 18907ac75b1Sopenharmony_ci isExportEntry(node, log, entryCollection, exportCollection, defaultCollection, fileResolvePath, sourceFile); 19007ac75b1Sopenharmony_ci if (asExportCollection.has(node.name.getText())) { 19107ac75b1Sopenharmony_ci componentCollection.customComponents.add(asExportCollection.get(node.name.getText())); 19207ac75b1Sopenharmony_ci if (isDETS) { 19307ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().compFromDETS.add(asExportCollection.get(node.name.getText())); 19407ac75b1Sopenharmony_ci } 19507ac75b1Sopenharmony_ci if (structDecorator.hasRecycle) { 19607ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().recycleComponents.add(asExportCollection.get(node.name.getText())); 19707ac75b1Sopenharmony_ci } 19807ac75b1Sopenharmony_ci } 19907ac75b1Sopenharmony_ci const modifiers: readonly ts.Modifier[] = 20007ac75b1Sopenharmony_ci ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined; 20107ac75b1Sopenharmony_ci if (modifiers && modifiers.length >= MODIFIER_LENGTH && modifiers[0] && 20207ac75b1Sopenharmony_ci modifiers[0].kind === ts.SyntaxKind.ExportKeyword && modifiers[1] && 20307ac75b1Sopenharmony_ci modifiers[1].kind === ts.SyntaxKind.DefaultKeyword) { 20407ac75b1Sopenharmony_ci if (!defaultNameFromParent && hasCollection(node.name)) { 20507ac75b1Sopenharmony_ci addDefaultExport(node, isDETS, structDecorator); 20607ac75b1Sopenharmony_ci } else if (defaultNameFromParent && asNameFromParent.has(defaultNameFromParent)) { 20707ac75b1Sopenharmony_ci componentCollection.customComponents.add(asNameFromParent.get(defaultNameFromParent)); 20807ac75b1Sopenharmony_ci if (isDETS) { 20907ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().compFromDETS.add(asNameFromParent.get(defaultNameFromParent)); 21007ac75b1Sopenharmony_ci } 21107ac75b1Sopenharmony_ci if (structDecorator.hasRecycle) { 21207ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().recycleComponents.add(asNameFromParent.get(defaultNameFromParent)); 21307ac75b1Sopenharmony_ci } 21407ac75b1Sopenharmony_ci } 21507ac75b1Sopenharmony_ci } 21607ac75b1Sopenharmony_ci if (defaultCollection.has(node.name.getText())) { 21707ac75b1Sopenharmony_ci componentCollection.customComponents.add(CUSTOM_COMPONENT_DEFAULT); 21807ac75b1Sopenharmony_ci if (isDETS) { 21907ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().compFromDETS.add(CUSTOM_COMPONENT_DEFAULT); 22007ac75b1Sopenharmony_ci } 22107ac75b1Sopenharmony_ci if (structDecorator.hasRecycle) { 22207ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().recycleComponents.add(CUSTOM_COMPONENT_DEFAULT); 22307ac75b1Sopenharmony_ci } 22407ac75b1Sopenharmony_ci } 22507ac75b1Sopenharmony_ci } 22607ac75b1Sopenharmony_ci if (ts.isFunctionDeclaration(node) && hasDecorator(node, COMPONENT_BUILDER_DECORATOR)) { 22707ac75b1Sopenharmony_ci collectSpecialFunctionNode(node, asNameFromParent, defaultNameFromParent, defaultCollection, 22807ac75b1Sopenharmony_ci asExportCollection, CUSTOM_BUILDER_METHOD); 22907ac75b1Sopenharmony_ci collectSpecialFunctionNode(node, asNameFromParent, defaultNameFromParent, defaultCollection, 23007ac75b1Sopenharmony_ci asExportCollection, GLOBAL_CUSTOM_BUILDER_METHOD); 23107ac75b1Sopenharmony_ci } 23207ac75b1Sopenharmony_ci if (ts.isExportAssignment(node) && node.expression && ts.isIdentifier(node.expression) && 23307ac75b1Sopenharmony_ci hasCollection(node.expression)) { 23407ac75b1Sopenharmony_ci if (defaultNameFromParent) { 23507ac75b1Sopenharmony_ci const propertiesName: string = node.expression.escapedText.toString(); 23607ac75b1Sopenharmony_ci setDependencies(defaultNameFromParent, undefined, linkCollection.get(propertiesName), 23707ac75b1Sopenharmony_ci propertyCollection.get(propertiesName), propCollection.get(propertiesName), 23807ac75b1Sopenharmony_ci builderParamObjectCollection.get(propertiesName), stateCollection.get(propertiesName), 23907ac75b1Sopenharmony_ci regularCollection.get(propertiesName), storagePropCollection.get(propertiesName), 24007ac75b1Sopenharmony_ci storageLinkCollection.get(propertiesName), provideCollection.get(propertiesName), 24107ac75b1Sopenharmony_ci consumeCollection.get(propertiesName), objectLinkCollection.get(propertiesName), 24207ac75b1Sopenharmony_ci localStorageLinkCollection.get(propertiesName), localStoragePropCollection.get(propertiesName), 24307ac75b1Sopenharmony_ci builderParamInitialization.get(propertiesName), propInitialization.get(propertiesName), isDETS, 24407ac75b1Sopenharmony_ci structDecorator); 24507ac75b1Sopenharmony_ci } 24607ac75b1Sopenharmony_ci addDefaultExport(node, isDETS, structDecorator); 24707ac75b1Sopenharmony_ci } 24807ac75b1Sopenharmony_ci if (ts.isExportAssignment(node) && node.expression && ts.isIdentifier(node.expression)) { 24907ac75b1Sopenharmony_ci if (defaultNameFromParent) { 25007ac75b1Sopenharmony_ci asNameFromParent.set(node.expression.getText(), asNameFromParent.get(defaultNameFromParent)); 25107ac75b1Sopenharmony_ci } 25207ac75b1Sopenharmony_ci defaultCollection.add(node.expression.getText()); 25307ac75b1Sopenharmony_ci } 25407ac75b1Sopenharmony_ci if (ts.isExportDeclaration(node) && node.exportClause && 25507ac75b1Sopenharmony_ci ts.isNamedExports(node.exportClause) && node.exportClause.elements) { 25607ac75b1Sopenharmony_ci node.exportClause.elements.forEach(item => { 25707ac75b1Sopenharmony_ci if (process.env.watchMode === 'true') { 25807ac75b1Sopenharmony_ci exportCollection.add((item.propertyName ? item.propertyName : item.name).escapedText.toString()); 25907ac75b1Sopenharmony_ci } 26007ac75b1Sopenharmony_ci if (item.name && ts.isIdentifier(item.name)) { 26107ac75b1Sopenharmony_ci if (!item.propertyName) { 26207ac75b1Sopenharmony_ci asExportCollection.set(item.name.escapedText.toString(), item.name.escapedText.toString()); 26307ac75b1Sopenharmony_ci } else if (item.propertyName && ts.isIdentifier(item.propertyName)) { 26407ac75b1Sopenharmony_ci validateModuleName(item.name, log, sourceFile, fileResolvePath); 26507ac75b1Sopenharmony_ci if (hasCollection(item.propertyName)) { 26607ac75b1Sopenharmony_ci let asExportName: string = item.name.escapedText.toString(); 26707ac75b1Sopenharmony_ci const asExportPropertyName: string = item.propertyName.escapedText.toString(); 26807ac75b1Sopenharmony_ci if (asNameFromParent.has(asExportName)) { 26907ac75b1Sopenharmony_ci asExportName = asNameFromParent.get(asExportName); 27007ac75b1Sopenharmony_ci } 27107ac75b1Sopenharmony_ci setDependencies(asExportName, undefined, linkCollection.get(asExportPropertyName), 27207ac75b1Sopenharmony_ci propertyCollection.get(asExportPropertyName), 27307ac75b1Sopenharmony_ci propCollection.get(asExportPropertyName), 27407ac75b1Sopenharmony_ci builderParamObjectCollection.get(asExportPropertyName), 27507ac75b1Sopenharmony_ci stateCollection.get(asExportPropertyName), regularCollection.get(asExportPropertyName), 27607ac75b1Sopenharmony_ci storagePropCollection.get(asExportPropertyName), storageLinkCollection.get(asExportPropertyName), 27707ac75b1Sopenharmony_ci provideCollection.get(asExportPropertyName), consumeCollection.get(asExportPropertyName), 27807ac75b1Sopenharmony_ci objectLinkCollection.get(asExportPropertyName), localStorageLinkCollection.get(asExportPropertyName), 27907ac75b1Sopenharmony_ci localStoragePropCollection.get(asExportPropertyName), builderParamInitialization.get(asExportPropertyName), 28007ac75b1Sopenharmony_ci propInitialization.get(asExportPropertyName), isDETS, structDecorator); 28107ac75b1Sopenharmony_ci } 28207ac75b1Sopenharmony_ci asExportCollection.set(item.propertyName.escapedText.toString(), item.name.escapedText.toString()); 28307ac75b1Sopenharmony_ci } 28407ac75b1Sopenharmony_ci } 28507ac75b1Sopenharmony_ci if (item.name && ts.isIdentifier(item.name) && asNameFromParent.has(item.name.escapedText.toString()) && 28607ac75b1Sopenharmony_ci item.propertyName && ts.isIdentifier(item.propertyName)) { 28707ac75b1Sopenharmony_ci asNameFromParent.set(item.propertyName.escapedText.toString(), 28807ac75b1Sopenharmony_ci asNameFromParent.get(item.name.escapedText.toString())); 28907ac75b1Sopenharmony_ci } 29007ac75b1Sopenharmony_ci }); 29107ac75b1Sopenharmony_ci } 29207ac75b1Sopenharmony_ci if (ts.isExportDeclaration(node) && node.moduleSpecifier && 29307ac75b1Sopenharmony_ci ts.isStringLiteral(node.moduleSpecifier)) { 29407ac75b1Sopenharmony_ci if (process.env.watchMode === 'true' && node.exportClause && ts.isNamedExports(node.exportClause) && 29507ac75b1Sopenharmony_ci node.exportClause.elements) { 29607ac75b1Sopenharmony_ci node.exportClause.elements.forEach(item => { 29707ac75b1Sopenharmony_ci exportCollection.add((item.propertyName ? item.propertyName : item.name).escapedText.toString()); 29807ac75b1Sopenharmony_ci if (item.propertyName && ts.isIdentifier(item.propertyName) && item.name && 29907ac75b1Sopenharmony_ci ts.isIdentifier(item.name) && asNameFromParent.has(item.name.escapedText.toString())) { 30007ac75b1Sopenharmony_ci asNameFromParent.set(item.propertyName.escapedText.toString(), 30107ac75b1Sopenharmony_ci asNameFromParent.get(item.name.escapedText.toString())); 30207ac75b1Sopenharmony_ci defaultCollection.add(item.name.escapedText.toString()); 30307ac75b1Sopenharmony_ci } 30407ac75b1Sopenharmony_ci }); 30507ac75b1Sopenharmony_ci } 30607ac75b1Sopenharmony_ci processImport(node, pagesDir, log, asNameFromParent, true, new Set(pathCollection)); 30707ac75b1Sopenharmony_ci } 30807ac75b1Sopenharmony_ci if (ts.isImportDeclaration(node)) { 30907ac75b1Sopenharmony_ci if (node.importClause && node.importClause.name && ts.isIdentifier(node.importClause.name) && 31007ac75b1Sopenharmony_ci asNameFromParent.has(node.importClause.name.getText())) { 31107ac75b1Sopenharmony_ci processImport(node, pagesDir, log, asNameFromParent, false, new Set(pathCollection)); 31207ac75b1Sopenharmony_ci } else if (node.importClause && node.importClause.namedBindings && 31307ac75b1Sopenharmony_ci ts.isNamedImports(node.importClause.namedBindings) && node.importClause.namedBindings.elements) { 31407ac75b1Sopenharmony_ci let nested: boolean = false; 31507ac75b1Sopenharmony_ci node.importClause.namedBindings.elements.forEach(item => { 31607ac75b1Sopenharmony_ci if (item.name && ts.isIdentifier(item.name) && asNameFromParent.has(item.name.escapedText.toString())) { 31707ac75b1Sopenharmony_ci nested = true; 31807ac75b1Sopenharmony_ci if (item.propertyName && ts.isIdentifier(item.propertyName)) { 31907ac75b1Sopenharmony_ci asNameFromParent.set(item.propertyName.escapedText.toString(), 32007ac75b1Sopenharmony_ci asNameFromParent.get(item.name.escapedText.toString())); 32107ac75b1Sopenharmony_ci } 32207ac75b1Sopenharmony_ci } 32307ac75b1Sopenharmony_ci }); 32407ac75b1Sopenharmony_ci if (nested) { 32507ac75b1Sopenharmony_ci processImport(node, pagesDir, log, asNameFromParent, false, new Set(pathCollection)); 32607ac75b1Sopenharmony_ci } 32707ac75b1Sopenharmony_ci } 32807ac75b1Sopenharmony_ci } 32907ac75b1Sopenharmony_ci node.getChildren().reverse().forEach((item: ts.Node) => visitAllNode(item, sourceFile, 33007ac75b1Sopenharmony_ci defaultNameFromParent, asNameFromParent, pagesDir, log, entryCollection, exportCollection, 33107ac75b1Sopenharmony_ci defaultCollection, asExportCollection, pathCollection, fileResolvePath, isDETS)); 33207ac75b1Sopenharmony_ci} 33307ac75b1Sopenharmony_ci 33407ac75b1Sopenharmony_cifunction collectSpecialFunctionNode(node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.StructDeclaration, 33507ac75b1Sopenharmony_ci asNameFromParent: Map<string, string>, defaultNameFromParent: string, defaultCollection: Set<string>, 33607ac75b1Sopenharmony_ci asExportCollection: Map<string, string>, collection: Set<string>): void { 33707ac75b1Sopenharmony_ci const name: string = node.name.getText(); 33807ac75b1Sopenharmony_ci const modifiers: readonly ts.Modifier[] = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined; 33907ac75b1Sopenharmony_ci if (asNameFromParent.has(name)) { 34007ac75b1Sopenharmony_ci collection.add(asNameFromParent.get(name)); 34107ac75b1Sopenharmony_ci } else if (modifiers && modifiers.length >= 1 && modifiers[0] && 34207ac75b1Sopenharmony_ci modifiers[0].kind === ts.SyntaxKind.ExportKeyword) { 34307ac75b1Sopenharmony_ci if (modifiers.length === 1) { 34407ac75b1Sopenharmony_ci collection.add(name); 34507ac75b1Sopenharmony_ci } else if (modifiers.length >= MODIFIER_LENGTH && modifiers[1] && modifiers[1].kind === 34607ac75b1Sopenharmony_ci ts.SyntaxKind.DefaultKeyword) { 34707ac75b1Sopenharmony_ci collection.add(CUSTOM_COMPONENT_DEFAULT); 34807ac75b1Sopenharmony_ci if (defaultNameFromParent && asNameFromParent.has(defaultNameFromParent)) { 34907ac75b1Sopenharmony_ci collection.add(asNameFromParent.get(defaultNameFromParent)); 35007ac75b1Sopenharmony_ci } 35107ac75b1Sopenharmony_ci } 35207ac75b1Sopenharmony_ci } else if (defaultCollection.has(name)) { 35307ac75b1Sopenharmony_ci collection.add(CUSTOM_COMPONENT_DEFAULT); 35407ac75b1Sopenharmony_ci } else if (asExportCollection.has(name)) { 35507ac75b1Sopenharmony_ci collection.add(asExportCollection.get(name)); 35607ac75b1Sopenharmony_ci } 35707ac75b1Sopenharmony_ci} 35807ac75b1Sopenharmony_ci 35907ac75b1Sopenharmony_cifunction isExportEntry(node: ts.StructDeclaration, log: LogInfo[], entryCollection: Set<string>, 36007ac75b1Sopenharmony_ci exportCollection: Set<string>, defaultCollection: Set<string>, fileResolvePath: string, 36107ac75b1Sopenharmony_ci sourceFile: ts.SourceFile): void { 36207ac75b1Sopenharmony_ci const decorators: readonly ts.Decorator[] = ts.getAllDecorators(node); 36307ac75b1Sopenharmony_ci if (process.env.watchMode === 'true' && node && decorators) { 36407ac75b1Sopenharmony_ci let existExport: boolean = false; 36507ac75b1Sopenharmony_ci let existEntry: boolean = false; 36607ac75b1Sopenharmony_ci const modifiers: readonly ts.Modifier[] = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined; 36707ac75b1Sopenharmony_ci if (modifiers) { 36807ac75b1Sopenharmony_ci for (let i = 0; i < modifiers.length; i++) { 36907ac75b1Sopenharmony_ci if (modifiers[i].kind === ts.SyntaxKind.ExportKeyword) { 37007ac75b1Sopenharmony_ci existExport = true; 37107ac75b1Sopenharmony_ci break; 37207ac75b1Sopenharmony_ci } 37307ac75b1Sopenharmony_ci } 37407ac75b1Sopenharmony_ci } 37507ac75b1Sopenharmony_ci for (let i = 0; i < decorators.length; i++) { 37607ac75b1Sopenharmony_ci if (decorators[i].getText() === COMPONENT_DECORATOR_ENTRY) { 37707ac75b1Sopenharmony_ci entryCollection.add(node.name.escapedText.toString()); 37807ac75b1Sopenharmony_ci existEntry = true; 37907ac75b1Sopenharmony_ci break; 38007ac75b1Sopenharmony_ci } 38107ac75b1Sopenharmony_ci } 38207ac75b1Sopenharmony_ci } 38307ac75b1Sopenharmony_ci} 38407ac75b1Sopenharmony_ci 38507ac75b1Sopenharmony_cifunction addDependencies(node: ts.StructDeclaration, defaultNameFromParent: string, 38607ac75b1Sopenharmony_ci asNameFromParent: Map<string, string>, isDETS: boolean, structDecorator: structDecoratorResult): void { 38707ac75b1Sopenharmony_ci const componentName: string = node.name.getText(); 38807ac75b1Sopenharmony_ci const ComponentSet: IComponentSet = getComponentSet(node, false); 38907ac75b1Sopenharmony_ci const modifiers: readonly ts.Modifier[] = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined; 39007ac75b1Sopenharmony_ci if (defaultNameFromParent && modifiers && modifiers.length >= MODIFIER_LENGTH && modifiers[0] && 39107ac75b1Sopenharmony_ci modifiers[1] && modifiers[0].kind === ts.SyntaxKind.ExportKeyword && 39207ac75b1Sopenharmony_ci modifiers[1].kind === ts.SyntaxKind.DefaultKeyword) { 39307ac75b1Sopenharmony_ci setDependencies(defaultNameFromParent, undefined, ComponentSet.links, ComponentSet.properties, 39407ac75b1Sopenharmony_ci ComponentSet.props, ComponentSet.builderParams, ComponentSet.states, ComponentSet.regulars, 39507ac75b1Sopenharmony_ci ComponentSet.storageProps, ComponentSet.storageLinks, ComponentSet.provides, 39607ac75b1Sopenharmony_ci ComponentSet.consumes, ComponentSet.objectLinks, ComponentSet.localStorageLink, 39707ac75b1Sopenharmony_ci ComponentSet.localStorageProp, ComponentSet.builderParamData, ComponentSet.propData, isDETS, 39807ac75b1Sopenharmony_ci structDecorator); 39907ac75b1Sopenharmony_ci } else if (asNameFromParent.has(componentName)) { 40007ac75b1Sopenharmony_ci setDependencies(asNameFromParent.get(componentName), undefined, ComponentSet.links, ComponentSet.properties, 40107ac75b1Sopenharmony_ci ComponentSet.props, ComponentSet.builderParams, ComponentSet.states, ComponentSet.regulars, 40207ac75b1Sopenharmony_ci ComponentSet.storageProps, ComponentSet.storageLinks, ComponentSet.provides, 40307ac75b1Sopenharmony_ci ComponentSet.consumes, ComponentSet.objectLinks, ComponentSet.localStorageLink, 40407ac75b1Sopenharmony_ci ComponentSet.localStorageProp, ComponentSet.builderParamData, ComponentSet.propData, isDETS, 40507ac75b1Sopenharmony_ci structDecorator); 40607ac75b1Sopenharmony_ci } else { 40707ac75b1Sopenharmony_ci setDependencies(componentName, undefined, ComponentSet.links, ComponentSet.properties, ComponentSet.props, 40807ac75b1Sopenharmony_ci ComponentSet.builderParams, ComponentSet.states, ComponentSet.regulars, 40907ac75b1Sopenharmony_ci ComponentSet.storageProps, ComponentSet.storageLinks, ComponentSet.provides, 41007ac75b1Sopenharmony_ci ComponentSet.consumes, ComponentSet.objectLinks, ComponentSet.localStorageLink, 41107ac75b1Sopenharmony_ci ComponentSet.localStorageProp, ComponentSet.builderParamData, ComponentSet.propData, isDETS, 41207ac75b1Sopenharmony_ci structDecorator); 41307ac75b1Sopenharmony_ci } 41407ac75b1Sopenharmony_ci} 41507ac75b1Sopenharmony_ci 41607ac75b1Sopenharmony_cifunction addDefaultExport(node: ts.StructDeclaration | ts.ExportAssignment, isDETS: boolean, 41707ac75b1Sopenharmony_ci structDecorator: structDecoratorResult): void { 41807ac75b1Sopenharmony_ci let name: string; 41907ac75b1Sopenharmony_ci if (ts.isStructDeclaration(node) && node.name && ts.isIdentifier(node.name)) { 42007ac75b1Sopenharmony_ci name = node.name.escapedText.toString(); 42107ac75b1Sopenharmony_ci } else if (ts.isExportAssignment(node) && node.expression && ts.isIdentifier(node.expression)) { 42207ac75b1Sopenharmony_ci name = node.expression.escapedText.toString(); 42307ac75b1Sopenharmony_ci } else { 42407ac75b1Sopenharmony_ci return; 42507ac75b1Sopenharmony_ci } 42607ac75b1Sopenharmony_ci setDependencies(CUSTOM_COMPONENT_DEFAULT, undefined, 42707ac75b1Sopenharmony_ci linkCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 42807ac75b1Sopenharmony_ci new Set([...linkCollection.get(CUSTOM_COMPONENT_DEFAULT), ...linkCollection.get(name)]) : 42907ac75b1Sopenharmony_ci linkCollection.get(name), 43007ac75b1Sopenharmony_ci propertyCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 43107ac75b1Sopenharmony_ci new Set([...propertyCollection.get(CUSTOM_COMPONENT_DEFAULT), 43207ac75b1Sopenharmony_ci ...propertyCollection.get(name)]) : propertyCollection.get(name), 43307ac75b1Sopenharmony_ci propCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 43407ac75b1Sopenharmony_ci new Set([...propCollection.get(CUSTOM_COMPONENT_DEFAULT), ...propCollection.get(name)]) : 43507ac75b1Sopenharmony_ci propCollection.get(name), 43607ac75b1Sopenharmony_ci builderParamObjectCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 43707ac75b1Sopenharmony_ci new Set([...builderParamObjectCollection.get(CUSTOM_COMPONENT_DEFAULT), 43807ac75b1Sopenharmony_ci ...builderParamObjectCollection.get(name)]) : builderParamObjectCollection.get(name), 43907ac75b1Sopenharmony_ci stateCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 44007ac75b1Sopenharmony_ci new Set([...stateCollection.get(CUSTOM_COMPONENT_DEFAULT), 44107ac75b1Sopenharmony_ci ...stateCollection.get(name)]) : stateCollection.get(name), 44207ac75b1Sopenharmony_ci regularCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 44307ac75b1Sopenharmony_ci new Set([...regularCollection.get(CUSTOM_COMPONENT_DEFAULT), 44407ac75b1Sopenharmony_ci ...regularCollection.get(name)]) : regularCollection.get(name), 44507ac75b1Sopenharmony_ci storagePropCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 44607ac75b1Sopenharmony_ci new Set([...storagePropCollection.get(CUSTOM_COMPONENT_DEFAULT), 44707ac75b1Sopenharmony_ci ...storagePropCollection.get(name)]) : storagePropCollection.get(name), 44807ac75b1Sopenharmony_ci storageLinkCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 44907ac75b1Sopenharmony_ci new Set([...storageLinkCollection.get(CUSTOM_COMPONENT_DEFAULT), 45007ac75b1Sopenharmony_ci ...storageLinkCollection.get(name)]) : storageLinkCollection.get(name), 45107ac75b1Sopenharmony_ci provideCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 45207ac75b1Sopenharmony_ci new Set([...provideCollection.get(CUSTOM_COMPONENT_DEFAULT), 45307ac75b1Sopenharmony_ci ...provideCollection.get(name)]) : provideCollection.get(name), 45407ac75b1Sopenharmony_ci consumeCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 45507ac75b1Sopenharmony_ci new Set([...consumeCollection.get(CUSTOM_COMPONENT_DEFAULT), 45607ac75b1Sopenharmony_ci ...consumeCollection.get(name)]) : consumeCollection.get(name), 45707ac75b1Sopenharmony_ci objectLinkCollection.has(CUSTOM_COMPONENT_DEFAULT) ? 45807ac75b1Sopenharmony_ci new Set([...objectLinkCollection.get(CUSTOM_COMPONENT_DEFAULT), 45907ac75b1Sopenharmony_ci ...objectLinkCollection.get(name)]) : objectLinkCollection.get(name), 46007ac75b1Sopenharmony_ci getNewLocalStorageMap(localStorageLinkCollection, name), 46107ac75b1Sopenharmony_ci getNewLocalStorageMap(localStoragePropCollection, name), 46207ac75b1Sopenharmony_ci builderParamInitialization.has(CUSTOM_COMPONENT_DEFAULT) ? 46307ac75b1Sopenharmony_ci new Set([...builderParamInitialization.get(CUSTOM_COMPONENT_DEFAULT), 46407ac75b1Sopenharmony_ci ...builderParamInitialization.get(name)]) : builderParamInitialization.get(name), 46507ac75b1Sopenharmony_ci propInitialization.has(CUSTOM_COMPONENT_DEFAULT) ? 46607ac75b1Sopenharmony_ci new Set([...propInitialization.get(CUSTOM_COMPONENT_DEFAULT), 46707ac75b1Sopenharmony_ci ...propInitialization.get(name)]) : propInitialization.get(name), isDETS, 46807ac75b1Sopenharmony_ci structDecorator 46907ac75b1Sopenharmony_ci ); 47007ac75b1Sopenharmony_ci} 47107ac75b1Sopenharmony_ci 47207ac75b1Sopenharmony_cifunction getNewLocalStorageMap(collection: Map<string, Map<string, Set<string>>>, name: string) 47307ac75b1Sopenharmony_ci : Map<string, Set<string>> { 47407ac75b1Sopenharmony_ci let localStorageLinkMap: Map<string, Set<string>> = new Map(); 47507ac75b1Sopenharmony_ci if (collection.has(CUSTOM_COMPONENT_DEFAULT)) { 47607ac75b1Sopenharmony_ci const tempSet: Set<string> = new Set(); 47707ac75b1Sopenharmony_ci if (collection.get(CUSTOM_COMPONENT_DEFAULT)) { 47807ac75b1Sopenharmony_ci for (const key of collection.get(CUSTOM_COMPONENT_DEFAULT).keys()) { 47907ac75b1Sopenharmony_ci tempSet.add(key); 48007ac75b1Sopenharmony_ci } 48107ac75b1Sopenharmony_ci } 48207ac75b1Sopenharmony_ci if (collection.get(name)) { 48307ac75b1Sopenharmony_ci for (const key of collection.get(name).keys()) { 48407ac75b1Sopenharmony_ci tempSet.add(key); 48507ac75b1Sopenharmony_ci } 48607ac75b1Sopenharmony_ci } 48707ac75b1Sopenharmony_ci localStorageLinkMap.set(name, tempSet); 48807ac75b1Sopenharmony_ci } else { 48907ac75b1Sopenharmony_ci localStorageLinkMap = collection.get(name); 49007ac75b1Sopenharmony_ci } 49107ac75b1Sopenharmony_ci return localStorageLinkMap; 49207ac75b1Sopenharmony_ci} 49307ac75b1Sopenharmony_ci 49407ac75b1Sopenharmony_cifunction setDependencies(component: string, asComponentName: string, linkArray: Set<string>, propertyArray: Set<string>, 49507ac75b1Sopenharmony_ci propArray: Set<string>, builderParamArray: Set<string>, stateArray: Set<string>, 49607ac75b1Sopenharmony_ci regularArray: Set<string>, storagePropsArray: Set<string>, storageLinksArray: Set<string>, 49707ac75b1Sopenharmony_ci providesArray: Set<string>, consumesArray: Set<string>, objectLinksArray: Set<string>, 49807ac75b1Sopenharmony_ci localStorageLinkMap: Map<string, Set<string>>, localStoragePropMap: Map<string, Set<string>>, 49907ac75b1Sopenharmony_ci builderParamData: Set<string>, propData: Set<string>, isDETS: boolean, 50007ac75b1Sopenharmony_ci structDecorator: structDecoratorResult): void { 50107ac75b1Sopenharmony_ci if (asComponentName) { 50207ac75b1Sopenharmony_ci linkCollection.set(asComponentName, linkArray); 50307ac75b1Sopenharmony_ci storedFileInfo.overallLinkCollection.set(asComponentName, linkArray); 50407ac75b1Sopenharmony_ci } else if (!asComponentName && component) { 50507ac75b1Sopenharmony_ci linkCollection.set(component, linkArray); 50607ac75b1Sopenharmony_ci if (projectConfig.compileMode === 'esmodule' && process.env.compileTool === 'rollup') { 50707ac75b1Sopenharmony_ci storedFileInfo.overallLinkCollection.set(component, linkArray); 50807ac75b1Sopenharmony_ci } 50907ac75b1Sopenharmony_ci } 51007ac75b1Sopenharmony_ci propertyCollection.set(component, propertyArray); 51107ac75b1Sopenharmony_ci if (!propCollection.get(component)) { 51207ac75b1Sopenharmony_ci propCollection.set(component, propArray); 51307ac75b1Sopenharmony_ci } 51407ac75b1Sopenharmony_ci if (asComponentName) { 51507ac75b1Sopenharmony_ci storedFileInfo.overallBuilderParamCollection.set(asComponentName, builderParamArray); 51607ac75b1Sopenharmony_ci } else if (!asComponentName && component && projectConfig.compileMode === 'esmodule' && 51707ac75b1Sopenharmony_ci process.env.compileTool === 'rollup') { 51807ac75b1Sopenharmony_ci storedFileInfo.overallBuilderParamCollection.set(component, builderParamArray); 51907ac75b1Sopenharmony_ci } 52007ac75b1Sopenharmony_ci builderParamObjectCollection.set(component, builderParamArray); 52107ac75b1Sopenharmony_ci componentCollection.customComponents.add(component); 52207ac75b1Sopenharmony_ci if (isDETS) { 52307ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().compFromDETS.add(component); 52407ac75b1Sopenharmony_ci } 52507ac75b1Sopenharmony_ci if (structDecorator.hasRecycle) { 52607ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().recycleComponents.add(component); 52707ac75b1Sopenharmony_ci } 52807ac75b1Sopenharmony_ci stateCollection.set(component, stateArray); 52907ac75b1Sopenharmony_ci regularCollection.set(component, regularArray); 53007ac75b1Sopenharmony_ci storagePropCollection.set(component, storagePropsArray); 53107ac75b1Sopenharmony_ci storageLinkCollection.set(component, storageLinksArray); 53207ac75b1Sopenharmony_ci provideCollection.set(component, providesArray); 53307ac75b1Sopenharmony_ci consumeCollection.set(component, consumesArray); 53407ac75b1Sopenharmony_ci if (asComponentName) { 53507ac75b1Sopenharmony_ci storedFileInfo.overallObjectLinkCollection.set(asComponentName, objectLinksArray); 53607ac75b1Sopenharmony_ci } else if (!asComponentName && component && projectConfig.compileMode === 'esmodule' && 53707ac75b1Sopenharmony_ci process.env.compileTool === 'rollup') { 53807ac75b1Sopenharmony_ci storedFileInfo.overallObjectLinkCollection.set(component, objectLinksArray); 53907ac75b1Sopenharmony_ci } 54007ac75b1Sopenharmony_ci objectLinkCollection.set(component, objectLinksArray); 54107ac75b1Sopenharmony_ci localStorageLinkCollection.set(component, localStorageLinkMap); 54207ac75b1Sopenharmony_ci localStoragePropCollection.set(component, localStoragePropMap); 54307ac75b1Sopenharmony_ci if (!builderParamInitialization.get(component)) { 54407ac75b1Sopenharmony_ci builderParamInitialization.set(component, builderParamData); 54507ac75b1Sopenharmony_ci } 54607ac75b1Sopenharmony_ci if (!propInitialization.get(component)) { 54707ac75b1Sopenharmony_ci propInitialization.set(component, propData); 54807ac75b1Sopenharmony_ci } 54907ac75b1Sopenharmony_ci} 55007ac75b1Sopenharmony_ci 55107ac75b1Sopenharmony_cifunction hasCollection(node: ts.Identifier): boolean { 55207ac75b1Sopenharmony_ci const name: string = node.escapedText.toString(); 55307ac75b1Sopenharmony_ci return linkCollection.has(name) || 55407ac75b1Sopenharmony_ci propCollection.has(name) || 55507ac75b1Sopenharmony_ci propertyCollection.has(name) || 55607ac75b1Sopenharmony_ci builderParamObjectCollection.has(name) || 55707ac75b1Sopenharmony_ci stateCollection.has(name) || 55807ac75b1Sopenharmony_ci regularCollection.has(name) || 55907ac75b1Sopenharmony_ci storagePropCollection.has(name) || 56007ac75b1Sopenharmony_ci storageLinkCollection.has(name) || 56107ac75b1Sopenharmony_ci provideCollection.has(name) || 56207ac75b1Sopenharmony_ci consumeCollection.has(name) || 56307ac75b1Sopenharmony_ci objectLinkCollection.has(name) || 56407ac75b1Sopenharmony_ci localStorageLinkCollection.has(name) || 56507ac75b1Sopenharmony_ci localStoragePropCollection.has(name); 56607ac75b1Sopenharmony_ci} 56707ac75b1Sopenharmony_ci 56807ac75b1Sopenharmony_cifunction isModule(filePath: string): boolean { 56907ac75b1Sopenharmony_ci return !/^(\.|\.\.)?\//.test(filePath) || filePath.indexOf(projectConfig.packageDir) > -1; 57007ac75b1Sopenharmony_ci} 57107ac75b1Sopenharmony_ci 57207ac75b1Sopenharmony_cifunction isCustomComponent(node: ts.StructDeclaration, structDecorator: structDecoratorResult): boolean { 57307ac75b1Sopenharmony_ci let isComponent: boolean = false; 57407ac75b1Sopenharmony_ci const decorators: readonly ts.Decorator[] = ts.getAllDecorators(node); 57507ac75b1Sopenharmony_ci if (decorators && decorators.length) { 57607ac75b1Sopenharmony_ci for (let i = 0; i < decorators.length; ++i) { 57707ac75b1Sopenharmony_ci const decoratorName: ts.Expression = decorators[i].expression; 57807ac75b1Sopenharmony_ci if (ts.isIdentifier(decoratorName) || ts.isCallExpression(decoratorName)) { 57907ac75b1Sopenharmony_ci let name: string = ''; 58007ac75b1Sopenharmony_ci if (ts.isCallExpression(decoratorName) && ts.isIdentifier(decoratorName.expression)) { 58107ac75b1Sopenharmony_ci name = decoratorName.expression.escapedText.toString(); 58207ac75b1Sopenharmony_ci } else if (ts.isIdentifier(decoratorName)) { 58307ac75b1Sopenharmony_ci name = decoratorName.escapedText.toString(); 58407ac75b1Sopenharmony_ci } 58507ac75b1Sopenharmony_ci if (CUSTOM_DECORATOR_NAME.has(name)) { 58607ac75b1Sopenharmony_ci isComponent = true; 58707ac75b1Sopenharmony_ci } 58807ac75b1Sopenharmony_ci if (name === DECORATOR_REUSEABLE) { 58907ac75b1Sopenharmony_ci structDecorator.hasRecycle = true; 59007ac75b1Sopenharmony_ci } 59107ac75b1Sopenharmony_ci } 59207ac75b1Sopenharmony_ci } 59307ac75b1Sopenharmony_ci } 59407ac75b1Sopenharmony_ci return isComponent; 59507ac75b1Sopenharmony_ci} 59607ac75b1Sopenharmony_ci 59707ac75b1Sopenharmony_cilet packageJsonEntry: string = ''; 59807ac75b1Sopenharmony_ci 59907ac75b1Sopenharmony_cifunction isPackageJsonEntry(filePath: string): boolean { 60007ac75b1Sopenharmony_ci const packageJsonPath: string = path.join(filePath, projectConfig.packageJson); 60107ac75b1Sopenharmony_ci if (fs.existsSync(packageJsonPath)) { 60207ac75b1Sopenharmony_ci let entryTypes: string; 60307ac75b1Sopenharmony_ci let entryMain: string; 60407ac75b1Sopenharmony_ci try { 60507ac75b1Sopenharmony_ci const packageJson: Object = 60607ac75b1Sopenharmony_ci (projectConfig.packageManagerType === 'npm' ? JSON : JSON5).parse(fs.readFileSync(packageJsonPath).toString()); 60707ac75b1Sopenharmony_ci entryTypes = packageJson.types; 60807ac75b1Sopenharmony_ci entryMain = packageJson.main; 60907ac75b1Sopenharmony_ci } catch (e) { 61007ac75b1Sopenharmony_ci return false; 61107ac75b1Sopenharmony_ci } 61207ac75b1Sopenharmony_ci if (entryExist(filePath, entryTypes)) { 61307ac75b1Sopenharmony_ci packageJsonEntry = path.resolve(filePath, entryTypes); 61407ac75b1Sopenharmony_ci return true; 61507ac75b1Sopenharmony_ci } else if (entryExist(filePath, entryMain)) { 61607ac75b1Sopenharmony_ci packageJsonEntry = path.resolve(filePath, entryMain); 61707ac75b1Sopenharmony_ci return true; 61807ac75b1Sopenharmony_ci } 61907ac75b1Sopenharmony_ci } 62007ac75b1Sopenharmony_ci return false; 62107ac75b1Sopenharmony_ci} 62207ac75b1Sopenharmony_ci 62307ac75b1Sopenharmony_cifunction entryExist(filePath: string, entry: string): boolean { 62407ac75b1Sopenharmony_ci return typeof entry === 'string' && fs.existsSync(path.resolve(filePath, entry)) && 62507ac75b1Sopenharmony_ci fs.statSync(path.resolve(filePath, entry)).isFile(); 62607ac75b1Sopenharmony_ci} 62707ac75b1Sopenharmony_ci 62807ac75b1Sopenharmony_cifunction getModuleFilePath(filePath: string): string { 62907ac75b1Sopenharmony_ci if (filePath && path.extname(filePath) !== EXTNAME_ETS && isModule(filePath)) { 63007ac75b1Sopenharmony_ci filePath += EXTNAME_ETS; 63107ac75b1Sopenharmony_ci } 63207ac75b1Sopenharmony_ci return filePath; 63307ac75b1Sopenharmony_ci} 63407ac75b1Sopenharmony_ci 63507ac75b1Sopenharmony_cifunction getFileResolvePath(fileResolvePath: string, pagesDir: string, filePath: string, 63607ac75b1Sopenharmony_ci projectPath: string): string { 63707ac75b1Sopenharmony_ci const moduleFilePath: string = getModuleFilePath(filePath); 63807ac75b1Sopenharmony_ci const defaultModule: string = path.join(projectPath, moduleFilePath); 63907ac75b1Sopenharmony_ci if (fs.existsSync(defaultModule)) { 64007ac75b1Sopenharmony_ci return defaultModule; 64107ac75b1Sopenharmony_ci } 64207ac75b1Sopenharmony_ci let entryModule: string; 64307ac75b1Sopenharmony_ci let etsModule: string; 64407ac75b1Sopenharmony_ci if (new RegExp(`^@(${sdkConfigPrefix})\\.`).test(filePath.trim())) { 64507ac75b1Sopenharmony_ci for (let i = 0; i < sdkConfigs.length; i++) { 64607ac75b1Sopenharmony_ci const resolveModuleInfo: ResolveModuleInfo = getRealModulePath(sdkConfigs[i].apiPath, filePath, ['.d.ts', '.d.ets']); 64707ac75b1Sopenharmony_ci const systemModule: string = resolveModuleInfo.modulePath; 64807ac75b1Sopenharmony_ci if (fs.existsSync(systemModule)) { 64907ac75b1Sopenharmony_ci return systemModule; 65007ac75b1Sopenharmony_ci } 65107ac75b1Sopenharmony_ci } 65207ac75b1Sopenharmony_ci } 65307ac75b1Sopenharmony_ci if (!projectConfig.aceModuleJsonPath) { 65407ac75b1Sopenharmony_ci entryModule = path.join(projectPath, '../../../../../', moduleFilePath); 65507ac75b1Sopenharmony_ci etsModule = path.join(projectPath, '../../', moduleFilePath); 65607ac75b1Sopenharmony_ci } else { 65707ac75b1Sopenharmony_ci entryModule = path.join(projectPath, '../../../../', moduleFilePath); 65807ac75b1Sopenharmony_ci etsModule = path.join(projectPath, '../', moduleFilePath); 65907ac75b1Sopenharmony_ci } 66007ac75b1Sopenharmony_ci if (fs.existsSync(entryModule)) { 66107ac75b1Sopenharmony_ci return entryModule; 66207ac75b1Sopenharmony_ci } 66307ac75b1Sopenharmony_ci if (fs.existsSync(etsModule)) { 66407ac75b1Sopenharmony_ci return etsModule; 66507ac75b1Sopenharmony_ci } 66607ac75b1Sopenharmony_ci let curPageDir: string = pagesDir; 66707ac75b1Sopenharmony_ci while (!fs.existsSync(fileResolvePath)) { 66807ac75b1Sopenharmony_ci if (filePath.indexOf(projectConfig.packageDir) > -1 && /^(\.|\.\.)\//.test(filePath)) { 66907ac75b1Sopenharmony_ci fileResolvePath = path.join(curPageDir, filePath); 67007ac75b1Sopenharmony_ci } else { 67107ac75b1Sopenharmony_ci fileResolvePath = path.join(curPageDir, projectConfig.packageDir, filePath); 67207ac75b1Sopenharmony_ci } 67307ac75b1Sopenharmony_ci if (fs.existsSync(fileResolvePath + EXTNAME_ETS)) { 67407ac75b1Sopenharmony_ci fileResolvePath = fileResolvePath + EXTNAME_ETS; 67507ac75b1Sopenharmony_ci } else if (isPackageJsonEntry(fileResolvePath)) { 67607ac75b1Sopenharmony_ci fileResolvePath = packageJsonEntry; 67707ac75b1Sopenharmony_ci if (fs.statSync(fileResolvePath).isDirectory()) { 67807ac75b1Sopenharmony_ci if (fs.existsSync(path.join(fileResolvePath, INDEX_ETS))) { 67907ac75b1Sopenharmony_ci fileResolvePath = path.join(fileResolvePath, INDEX_ETS); 68007ac75b1Sopenharmony_ci } else if (fs.existsSync(path.join(fileResolvePath, INDEX_TS))) { 68107ac75b1Sopenharmony_ci fileResolvePath = path.join(fileResolvePath, INDEX_TS); 68207ac75b1Sopenharmony_ci } 68307ac75b1Sopenharmony_ci } 68407ac75b1Sopenharmony_ci } else if (fs.existsSync(path.join(fileResolvePath, INDEX_ETS))) { 68507ac75b1Sopenharmony_ci fileResolvePath = path.join(fileResolvePath, INDEX_ETS); 68607ac75b1Sopenharmony_ci } else if (fs.existsSync(path.join(fileResolvePath, INDEX_TS))) { 68707ac75b1Sopenharmony_ci fileResolvePath = path.join(fileResolvePath, INDEX_TS); 68807ac75b1Sopenharmony_ci } 68907ac75b1Sopenharmony_ci if (curPageDir === path.parse(curPageDir).root) { 69007ac75b1Sopenharmony_ci break; 69107ac75b1Sopenharmony_ci } 69207ac75b1Sopenharmony_ci curPageDir = path.dirname(curPageDir); 69307ac75b1Sopenharmony_ci } 69407ac75b1Sopenharmony_ci return fileResolvePath; 69507ac75b1Sopenharmony_ci} 69607ac75b1Sopenharmony_ci 69707ac75b1Sopenharmony_cifunction getFileFullPath(filePath: string, pagesDir: string): string { 69807ac75b1Sopenharmony_ci if (filePath && path.extname(filePath) !== EXTNAME_ETS && path.extname(filePath) !== EXTNAME_TS && 69907ac75b1Sopenharmony_ci !isModule(filePath)) { 70007ac75b1Sopenharmony_ci const dirIndexEtsPath: string = path.resolve(path.resolve(pagesDir, filePath), INDEX_ETS); 70107ac75b1Sopenharmony_ci const dirIndexTsPath: string = path.resolve(path.resolve(pagesDir, filePath), INDEX_TS); 70207ac75b1Sopenharmony_ci if (/^(\.|\.\.)\//.test(filePath) && !fs.existsSync(path.resolve(pagesDir, filePath + EXTNAME_ETS)) && 70307ac75b1Sopenharmony_ci fs.existsSync(dirIndexEtsPath)) { 70407ac75b1Sopenharmony_ci filePath = dirIndexEtsPath; 70507ac75b1Sopenharmony_ci } else if (/^(\.|\.\.)\//.test(filePath) && !fs.existsSync(path.resolve(pagesDir, filePath + EXTNAME_TS)) && 70607ac75b1Sopenharmony_ci fs.existsSync(dirIndexTsPath)) { 70707ac75b1Sopenharmony_ci filePath = dirIndexTsPath; 70807ac75b1Sopenharmony_ci } else { 70907ac75b1Sopenharmony_ci filePath += getExtensionIfUnfullySpecifiedFilepath(path.resolve(pagesDir, filePath)); 71007ac75b1Sopenharmony_ci } 71107ac75b1Sopenharmony_ci } 71207ac75b1Sopenharmony_ci 71307ac75b1Sopenharmony_ci let fileResolvePath: string; 71407ac75b1Sopenharmony_ci if (/^(\.|\.\.)\//.test(filePath) && filePath.indexOf(projectConfig.packageDir) < 0) { 71507ac75b1Sopenharmony_ci fileResolvePath = path.resolve(pagesDir, filePath); 71607ac75b1Sopenharmony_ci } else if (/^\//.test(filePath) && filePath.indexOf(projectConfig.packageDir) < 0 || 71707ac75b1Sopenharmony_ci fs.existsSync(filePath) && fs.statSync(filePath).isFile()) { 71807ac75b1Sopenharmony_ci fileResolvePath = filePath; 71907ac75b1Sopenharmony_ci } else { 72007ac75b1Sopenharmony_ci fileResolvePath = getFileResolvePath(fileResolvePath, pagesDir, filePath, projectConfig.projectPath); 72107ac75b1Sopenharmony_ci } 72207ac75b1Sopenharmony_ci 72307ac75b1Sopenharmony_ci return fileResolvePath; 72407ac75b1Sopenharmony_ci} 72507ac75b1Sopenharmony_ci 72607ac75b1Sopenharmony_cifunction validateModuleName(moduleNode: ts.Identifier, log: LogInfo[], sourceFile?: ts.SourceFile, 72707ac75b1Sopenharmony_ci fileResolvePath?: string): void { 72807ac75b1Sopenharmony_ci const moduleName: string = moduleNode.escapedText.toString(); 72907ac75b1Sopenharmony_ci if (INNER_COMPONENT_NAMES.has(moduleName)) { 73007ac75b1Sopenharmony_ci const error: LogInfo = { 73107ac75b1Sopenharmony_ci type: LogType.ERROR, 73207ac75b1Sopenharmony_ci message: `The module name '${moduleName}' can not be the same as the inner component name.`, 73307ac75b1Sopenharmony_ci pos: moduleNode.getStart() 73407ac75b1Sopenharmony_ci }; 73507ac75b1Sopenharmony_ci if (sourceFile && fileResolvePath) { 73607ac75b1Sopenharmony_ci const posOfNode: ts.LineAndCharacter = sourceFile.getLineAndCharacterOfPosition(moduleNode.getStart()); 73707ac75b1Sopenharmony_ci const line: number = posOfNode.line + 1; 73807ac75b1Sopenharmony_ci const column: number = posOfNode.character + 1; 73907ac75b1Sopenharmony_ci Object.assign(error, { 74007ac75b1Sopenharmony_ci fileName: fileResolvePath, 74107ac75b1Sopenharmony_ci line: line, 74207ac75b1Sopenharmony_ci column: column 74307ac75b1Sopenharmony_ci }); 74407ac75b1Sopenharmony_ci } 74507ac75b1Sopenharmony_ci log.push(error); 74607ac75b1Sopenharmony_ci } 74707ac75b1Sopenharmony_ci} 74807ac75b1Sopenharmony_ci 74907ac75b1Sopenharmony_ciinterface PageInfo { 75007ac75b1Sopenharmony_ci pageFile: string; 75107ac75b1Sopenharmony_ci setChildOnce: boolean; 75207ac75b1Sopenharmony_ci} 75307ac75b1Sopenharmony_ci 75407ac75b1Sopenharmony_ciexport function processImportModule(node: ts.ImportDeclaration, pageFile: string, log: LogInfo[]): void { 75507ac75b1Sopenharmony_ci let importSymbol: ts.Symbol; 75607ac75b1Sopenharmony_ci let realSymbol: ts.Symbol; 75707ac75b1Sopenharmony_ci let originNode: ts.Node; 75807ac75b1Sopenharmony_ci const pageInfo: PageInfo = { pageFile: pageFile, setChildOnce: false }; 75907ac75b1Sopenharmony_ci validateModuleSpecifier(node.moduleSpecifier, log); 76007ac75b1Sopenharmony_ci 76107ac75b1Sopenharmony_ci // import xxx from 'xxx' 76207ac75b1Sopenharmony_ci if (node.importClause && node.importClause.name && ts.isIdentifier(node.importClause.name)) { 76307ac75b1Sopenharmony_ci getDefinedNode(importSymbol, realSymbol, originNode, node.importClause.name, pageInfo); 76407ac75b1Sopenharmony_ci } 76507ac75b1Sopenharmony_ci 76607ac75b1Sopenharmony_ci // import {xxx} from 'xxx' 76707ac75b1Sopenharmony_ci if (node.importClause && node.importClause.namedBindings && 76807ac75b1Sopenharmony_ci ts.isNamedImports(node.importClause.namedBindings) && 76907ac75b1Sopenharmony_ci node.importClause.namedBindings.elements) { 77007ac75b1Sopenharmony_ci node.importClause.namedBindings.elements.forEach((importSpecifier: ts.ImportSpecifier) => { 77107ac75b1Sopenharmony_ci if (ts.isImportSpecifier(importSpecifier) && importSpecifier.name && ts.isIdentifier(importSpecifier.name)) { 77207ac75b1Sopenharmony_ci getDefinedNode(importSymbol, realSymbol, originNode, importSpecifier.name, pageInfo); 77307ac75b1Sopenharmony_ci } 77407ac75b1Sopenharmony_ci }); 77507ac75b1Sopenharmony_ci } 77607ac75b1Sopenharmony_ci 77707ac75b1Sopenharmony_ci // import * as xxx from 'xxx' 77807ac75b1Sopenharmony_ci if (node.importClause && node.importClause.namedBindings && 77907ac75b1Sopenharmony_ci ts.isNamespaceImport(node.importClause.namedBindings) && node.importClause.namedBindings.name && 78007ac75b1Sopenharmony_ci ts.isIdentifier(node.importClause.namedBindings.name)) { 78107ac75b1Sopenharmony_ci storedFileInfo.isAsPageImport = true; 78207ac75b1Sopenharmony_ci getDefinedNode(importSymbol, realSymbol, originNode, node.importClause.namedBindings.name, pageInfo); 78307ac75b1Sopenharmony_ci } 78407ac75b1Sopenharmony_ci} 78507ac75b1Sopenharmony_ci 78607ac75b1Sopenharmony_cifunction getDefinedNode(importSymbol: ts.Symbol, realSymbol: ts.Symbol, originNode: ts.Node, 78707ac75b1Sopenharmony_ci usedNode: ts.Identifier, pageInfo: PageInfo): void { 78807ac75b1Sopenharmony_ci importSymbol = globalProgram.checker.getSymbolAtLocation(usedNode); 78907ac75b1Sopenharmony_ci if (importSymbol) { 79007ac75b1Sopenharmony_ci realSymbol = globalProgram.checker.getAliasedSymbol(importSymbol); 79107ac75b1Sopenharmony_ci } else { 79207ac75b1Sopenharmony_ci realSymbol = null; 79307ac75b1Sopenharmony_ci } 79407ac75b1Sopenharmony_ci if (realSymbol && realSymbol.declarations) { 79507ac75b1Sopenharmony_ci originNode = realSymbol.declarations[0]; 79607ac75b1Sopenharmony_ci } else { 79707ac75b1Sopenharmony_ci originNode = null; 79807ac75b1Sopenharmony_ci } 79907ac75b1Sopenharmony_ci if (originNode) { 80007ac75b1Sopenharmony_ci if (ts.isSourceFile(originNode) && realSymbol.escapedName) { 80107ac75b1Sopenharmony_ci const escapedName: string = realSymbol.escapedName.toString().replace(/^("|')/, '').replace(/("|')$/, ''); 80207ac75b1Sopenharmony_ci if (fs.existsSync(escapedName + '.ets') || fs.existsSync(escapedName + '.ts') && 80307ac75b1Sopenharmony_ci realSymbol.exports && realSymbol.exports instanceof Map) { 80407ac75b1Sopenharmony_ci getIntegrationNodeInfo(originNode, usedNode, realSymbol.exports, pageInfo); 80507ac75b1Sopenharmony_ci return; 80607ac75b1Sopenharmony_ci } 80707ac75b1Sopenharmony_ci } 80807ac75b1Sopenharmony_ci processImportNode(originNode, usedNode, false, null, pageInfo); 80907ac75b1Sopenharmony_ci } 81007ac75b1Sopenharmony_ci} 81107ac75b1Sopenharmony_ci 81207ac75b1Sopenharmony_cifunction getIntegrationNodeInfo(originNode: ts.Node, usedNode: ts.Identifier, exportsMap: ts.SymbolTable, 81307ac75b1Sopenharmony_ci pageInfo: PageInfo): void { 81407ac75b1Sopenharmony_ci for (const usedSymbol of exportsMap) { 81507ac75b1Sopenharmony_ci try { 81607ac75b1Sopenharmony_ci originNode = globalProgram.checker.getAliasedSymbol(usedSymbol[1]).declarations[0]; 81707ac75b1Sopenharmony_ci } catch (e) { 81807ac75b1Sopenharmony_ci if (usedSymbol[1] && usedSymbol[1].declarations) { 81907ac75b1Sopenharmony_ci for (let i = 0; i < usedSymbol[1].declarations.length; i++) { 82007ac75b1Sopenharmony_ci originNode = usedSymbol[1].declarations[i]; 82107ac75b1Sopenharmony_ci exportAllManage(originNode, usedNode, pageInfo); 82207ac75b1Sopenharmony_ci } 82307ac75b1Sopenharmony_ci } 82407ac75b1Sopenharmony_ci } 82507ac75b1Sopenharmony_ci processImportNode(originNode, usedNode, true, usedSymbol[0], pageInfo); 82607ac75b1Sopenharmony_ci } 82707ac75b1Sopenharmony_ci} 82807ac75b1Sopenharmony_ci 82907ac75b1Sopenharmony_ci// export * from 'xxx'; 83007ac75b1Sopenharmony_cifunction exportAllManage(originNode: ts.Node, usedNode: ts.Identifier, pageInfo: PageInfo): void { 83107ac75b1Sopenharmony_ci let exportOriginNode: ts.Node; 83207ac75b1Sopenharmony_ci if (!originNode.exportClause && originNode.moduleSpecifier && ts.isStringLiteral(originNode.moduleSpecifier)) { 83307ac75b1Sopenharmony_ci const exportSymbol: ts.Symbol = globalProgram.checker.getSymbolAtLocation(originNode.moduleSpecifier); 83407ac75b1Sopenharmony_ci if (exportSymbol && exportSymbol.declarations) { 83507ac75b1Sopenharmony_ci exportOriginNode = exportSymbol.declarations[0]; 83607ac75b1Sopenharmony_ci } else { 83707ac75b1Sopenharmony_ci exportOriginNode = null; 83807ac75b1Sopenharmony_ci } 83907ac75b1Sopenharmony_ci if (exportOriginNode) { 84007ac75b1Sopenharmony_ci if (ts.isSourceFile(exportOriginNode) && exportSymbol.escapedName) { 84107ac75b1Sopenharmony_ci const escapedName: string = exportSymbol.escapedName.toString().replace(/^("|')/, '').replace(/("|')$/, ''); 84207ac75b1Sopenharmony_ci if (fs.existsSync(escapedName + '.ets') || fs.existsSync(escapedName + '.ts') && 84307ac75b1Sopenharmony_ci exportSymbol.exports && exportSymbol.exports instanceof Map) { 84407ac75b1Sopenharmony_ci getIntegrationNodeInfo(originNode, usedNode, exportSymbol.exports, pageInfo); 84507ac75b1Sopenharmony_ci return; 84607ac75b1Sopenharmony_ci } 84707ac75b1Sopenharmony_ci } 84807ac75b1Sopenharmony_ci } 84907ac75b1Sopenharmony_ci } 85007ac75b1Sopenharmony_ci} 85107ac75b1Sopenharmony_ci 85207ac75b1Sopenharmony_cifunction processImportNode(originNode: ts.Node, usedNode: ts.Identifier, importIntegration: boolean, 85307ac75b1Sopenharmony_ci usedPropName: string, pageInfo: PageInfo): void { 85407ac75b1Sopenharmony_ci const structDecorator: structDecoratorResult = { hasRecycle: false }; 85507ac75b1Sopenharmony_ci let name: string; 85607ac75b1Sopenharmony_ci let asComponentName: string; 85707ac75b1Sopenharmony_ci if (importIntegration) { 85807ac75b1Sopenharmony_ci if (storedFileInfo.isAsPageImport) { 85907ac75b1Sopenharmony_ci asComponentName = usedNode.escapedText.toString() + '.' + usedPropName; 86007ac75b1Sopenharmony_ci } 86107ac75b1Sopenharmony_ci name = usedPropName; 86207ac75b1Sopenharmony_ci } else { 86307ac75b1Sopenharmony_ci name = usedNode.escapedText.toString(); 86407ac75b1Sopenharmony_ci } 86507ac75b1Sopenharmony_ci let needCollection: boolean = true; 86607ac75b1Sopenharmony_ci const originFile: string = originNode.getSourceFile() ? originNode.getSourceFile().fileName : undefined; 86707ac75b1Sopenharmony_ci if (ts.isStructDeclaration(originNode) && ts.isIdentifier(originNode.name)) { 86807ac75b1Sopenharmony_ci parseComponentInImportNode(originNode, name, asComponentName, structDecorator, originFile); 86907ac75b1Sopenharmony_ci } else if (isObservedClass(originNode)) { 87007ac75b1Sopenharmony_ci observedClassCollection.add(name); 87107ac75b1Sopenharmony_ci } else if (ts.isFunctionDeclaration(originNode) && hasDecorator(originNode, COMPONENT_BUILDER_DECORATOR)) { 87207ac75b1Sopenharmony_ci CUSTOM_BUILDER_METHOD.add(name); 87307ac75b1Sopenharmony_ci GLOBAL_CUSTOM_BUILDER_METHOD.add(name); 87407ac75b1Sopenharmony_ci } else if (ts.isEnumDeclaration(originNode) && originNode.name) { 87507ac75b1Sopenharmony_ci enumCollection.add(name); 87607ac75b1Sopenharmony_ci } else { 87707ac75b1Sopenharmony_ci needCollection = false; 87807ac75b1Sopenharmony_ci } 87907ac75b1Sopenharmony_ci if (needCollection && pageInfo.pageFile && !pageInfo.setChildOnce && originFile) { 88007ac75b1Sopenharmony_ci const childFile: string = path.resolve(getRealPath(originFile) || originFile); 88107ac75b1Sopenharmony_ci storedFileInfo.transformCacheFiles[pageInfo.pageFile].children.push({ 88207ac75b1Sopenharmony_ci fileName: childFile, 88307ac75b1Sopenharmony_ci mtimeMs: fs.existsSync(childFile) ? fs.statSync(childFile).mtimeMs : 0 88407ac75b1Sopenharmony_ci }); 88507ac75b1Sopenharmony_ci pageInfo.setChildOnce = true; 88607ac75b1Sopenharmony_ci } 88707ac75b1Sopenharmony_ci} 88807ac75b1Sopenharmony_ci 88907ac75b1Sopenharmony_cifunction getRealPath(filePath: string): string { 89007ac75b1Sopenharmony_ci try { 89107ac75b1Sopenharmony_ci const newPath: string = fs.realpathSync.native(filePath); 89207ac75b1Sopenharmony_ci return newPath; 89307ac75b1Sopenharmony_ci } catch (err) { 89407ac75b1Sopenharmony_ci return undefined; 89507ac75b1Sopenharmony_ci } 89607ac75b1Sopenharmony_ci} 89707ac75b1Sopenharmony_ci 89807ac75b1Sopenharmony_cifunction setComponentCollectionInfo(name: string, componentSet: IComponentSet, isDETS: boolean, 89907ac75b1Sopenharmony_ci structDecorator: structDecoratorResult, asComponentName: string): void { 90007ac75b1Sopenharmony_ci setDependencies(name, asComponentName, componentSet.links, componentSet.properties, 90107ac75b1Sopenharmony_ci componentSet.props, componentSet.builderParams, componentSet.states, componentSet.regulars, 90207ac75b1Sopenharmony_ci componentSet.storageProps, componentSet.storageLinks, componentSet.provides, 90307ac75b1Sopenharmony_ci componentSet.consumes, componentSet.objectLinks, componentSet.localStorageLink, 90407ac75b1Sopenharmony_ci componentSet.localStorageProp, componentSet.builderParamData, componentSet.propData, isDETS, 90507ac75b1Sopenharmony_ci structDecorator); 90607ac75b1Sopenharmony_ci regularInitialization.set(name, componentSet.regularInit); 90707ac75b1Sopenharmony_ci stateInitialization.set(name, componentSet.stateInit); 90807ac75b1Sopenharmony_ci provideInitialization.set(name, componentSet.provideInit); 90907ac75b1Sopenharmony_ci privateCollection.set(name, componentSet.privateCollection); 91007ac75b1Sopenharmony_ci if (asComponentName) { 91107ac75b1Sopenharmony_ci const asComponentNameStructInfo: StructInfo = 91207ac75b1Sopenharmony_ci processStructComponentV2.getOrCreateStructInfo(asComponentName); 91307ac75b1Sopenharmony_ci asComponentNameStructInfo.updatePropsDecoratorsV1.push( 91407ac75b1Sopenharmony_ci ...componentSet.states, ...componentSet.props, 91507ac75b1Sopenharmony_ci ...componentSet.provides, ...componentSet.objectLinks 91607ac75b1Sopenharmony_ci ); 91707ac75b1Sopenharmony_ci asComponentNameStructInfo.linkDecoratorsV1.push(...componentSet.links); 91807ac75b1Sopenharmony_ci return; 91907ac75b1Sopenharmony_ci } 92007ac75b1Sopenharmony_ci const nameStructInfo: StructInfo = processStructComponentV2.getOrCreateStructInfo(name); 92107ac75b1Sopenharmony_ci nameStructInfo.updatePropsDecoratorsV1.push( 92207ac75b1Sopenharmony_ci ...componentSet.states, ...componentSet.props, 92307ac75b1Sopenharmony_ci ...componentSet.provides, ...componentSet.objectLinks 92407ac75b1Sopenharmony_ci ); 92507ac75b1Sopenharmony_ci nameStructInfo.linkDecoratorsV1.push(...componentSet.links); 92607ac75b1Sopenharmony_ci} 92707ac75b1Sopenharmony_ci 92807ac75b1Sopenharmony_cifunction parseComponentInImportNode(originNode: ts.StructDeclaration, name: string, 92907ac75b1Sopenharmony_ci asComponentName: string, structDecorator: structDecoratorResult, originFile: string): void { 93007ac75b1Sopenharmony_ci componentCollection.customComponents.add(name); 93107ac75b1Sopenharmony_ci const structInfo: StructInfo = asComponentName ? 93207ac75b1Sopenharmony_ci processStructComponentV2.getOrCreateStructInfo(asComponentName) : 93307ac75b1Sopenharmony_ci processStructComponentV2.getOrCreateStructInfo(name); 93407ac75b1Sopenharmony_ci if (isComponentV2(originNode)) { 93507ac75b1Sopenharmony_ci parseComponentV2InImportNode(originNode, name, originFile, structInfo); 93607ac75b1Sopenharmony_ci return; 93707ac75b1Sopenharmony_ci } 93807ac75b1Sopenharmony_ci if (isCustomDialogClass(originNode)) { 93907ac75b1Sopenharmony_ci structInfo.isCustomDialog = true; 94007ac75b1Sopenharmony_ci componentCollection.customDialogs.add(name); 94107ac75b1Sopenharmony_ci } 94207ac75b1Sopenharmony_ci if (isCustomComponent(originNode, structDecorator)) { 94307ac75b1Sopenharmony_ci structInfo.isComponentV1 = true; 94407ac75b1Sopenharmony_ci let isDETS: boolean = false; 94507ac75b1Sopenharmony_ci const componentSet: IComponentSet = getComponentSet(originNode, false); 94607ac75b1Sopenharmony_ci while (originNode) { 94707ac75b1Sopenharmony_ci if (ts.isSourceFile(originNode) && /\.d\.ets$/.test(originNode.fileName)) { 94807ac75b1Sopenharmony_ci isDETS = true; 94907ac75b1Sopenharmony_ci } 95007ac75b1Sopenharmony_ci originNode = originNode.parent; 95107ac75b1Sopenharmony_ci } 95207ac75b1Sopenharmony_ci setComponentCollectionInfo(name, componentSet, isDETS, structDecorator, asComponentName); 95307ac75b1Sopenharmony_ci } 95407ac75b1Sopenharmony_ci} 95507ac75b1Sopenharmony_ci 95607ac75b1Sopenharmony_cifunction parseComponentV2InImportNode(node: ts.StructDeclaration, name: string, originFile: string, 95707ac75b1Sopenharmony_ci structInfo: StructInfo): void { 95807ac75b1Sopenharmony_ci structInfo.isComponentV2 = true; 95907ac75b1Sopenharmony_ci const isDETS: boolean = originFile && /\.d\.ets$/.test(originFile); 96007ac75b1Sopenharmony_ci if (isDETS) { 96107ac75b1Sopenharmony_ci storedFileInfo.getCurrentArkTsFile().compFromDETS.add(name); 96207ac75b1Sopenharmony_ci } 96307ac75b1Sopenharmony_ci processStructComponentV2.parseComponentProperty(node, structInfo, null, null); 96407ac75b1Sopenharmony_ci} 96507ac75b1Sopenharmony_ci 96607ac75b1Sopenharmony_cifunction isComponentV2(node: ts.StructDeclaration): boolean { 96707ac75b1Sopenharmony_ci const decorators: readonly ts.Decorator[] = ts.getAllDecorators(node); 96807ac75b1Sopenharmony_ci return decorators.some((item: ts.Decorator) => { 96907ac75b1Sopenharmony_ci const name: string = item.getText().replace(/\([^\(\)]*\)/, '').replace('@', '').trim(); 97007ac75b1Sopenharmony_ci return name === 'ComponentV2'; 97107ac75b1Sopenharmony_ci }); 97207ac75b1Sopenharmony_ci} 973