From d5a5cc137b24f9d7a7602c9e549ead83d79df1c8 Mon Sep 17 00:00:00 2001 From: Yenan Date: Tue, 15 Jul 2025 09:53:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=93=BE=E6=94=AF=E6=8C=81st?= =?UTF-8?q?mgmt=E7=99=BD=E5=90=8D=E5=8D=95=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yenan --- BUILD.gn | 1 + compiler/config/stmgmtWhiteList.json | 178 +++++++++++++++++++++ compiler/src/process_struct_componentV2.ts | 6 +- compiler/src/validate_ui_syntax.ts | 37 +++++ 4 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 compiler/config/stmgmtWhiteList.json diff --git a/BUILD.gn b/BUILD.gn index 544f7c32c..559e4d036 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -169,6 +169,7 @@ ets_loader_sources = [ "compiler/tsconfig.esm.json", "compiler/tsconfig.json", "compiler/webpack.config.js", + "compiler/config/stmgmtWhiteList.json" ] ohos_copy("ets_loader") { diff --git a/compiler/config/stmgmtWhiteList.json b/compiler/config/stmgmtWhiteList.json new file mode 100644 index 000000000..243c2ae4f --- /dev/null +++ b/compiler/config/stmgmtWhiteList.json @@ -0,0 +1,178 @@ +{ + "attrs": [ + "isRenderInProgress", + "isInitialRenderDone", + "runReuse_", + "paramsGenerator_", + "watchedProps", + "recycleManager_", + "hasBeenRecycled_", + "preventRecursiveRecycle_", + "delayRecycleNodeRerender", + "delayRecycleNodeRerenderDeep", + "defaultConsume_", + "reconnectConsume_", + "providedVars_", + "dirtyElementIdsNeedsUpdateSynchronously_", + "localStoragebackStore_", + "ownObservedPropertiesStore__", + "obtainOwnObservedProperties", + "localStorage_", + "isViewV2", + "purgeDeleteElmtId", + "purgeVariableDependenciesOnElmtIdOwnFunc", + "debugInfoStateVars", + "initAllowComponentFreeze", + "onInactiveInternal", + "purgeVariableDependenciesOnElmtId", + "initialRender", + "updateRecycleElmtId", + "updateStateVars", + "initialRenderView", + "delayCompleteRerender", + "flushDelayCompleteRerender", + "forceRerenderNode", + "collectElementsNeedToUpdateSynchronously", + "viewPropertyHasChanged", + "uiNodeNeedUpdateV2", + "performDelayedUpdate", + "addProvidedVar", + "findProvidePU__", + "initializeConsume", + "reconnectToConsume", + "disconnectedConsume", + "markElemenDirtyById", + "updateDirtyElements", + "observeComponentCreation", + "observeComponentCreation2", + "getOrCreateRecycleManager", + "getRecycleManager", + "hasRecycleManager", + "initRecycleManager", + "rebuildUpdateFunc", + "observeRecycleComponentCreation", + "stopRecursiveRecycle", + "recycleSelf", + "UpdateLazyForEachElements", + "debugInfoView", + "debugInfoViewInternal", + "debugInfoDirtDescendantElementIds", + "debugInfoDirtDescendantElementIdsInternal", + "mkRepeatAPI", + "reuseOrCreateNewComponent", + "dirtDescendantElementIds", + "monitorIdsDelayedUpdate", + "monitorIdsDelayedUpdateForAddMonitor", + "computedIdsDelayedUpdate", + "recyclePoolV2_", + "resetStateVarsOnReuse", + "freezeRecycledComponent", + "unfreezeReusedComponent", + "getOrCreateRecyclePool", + "getRecyclePool", + "hasRecyclePool", + "cleanupRecycledElmtId", + "resetMonitorsOnReuse", + "resetComputed", + "resetConsumer", + "getViewV2ChildById", + "addDelayedMonitorIdsForAddMonitor", + "addDelayedComputedIds", + "finalizeConstruction", + "inactiveComponents_", + "isReusable_", + "currentlyRenderedElmtIdStack_", + "dirtDescendantElementIds_", + "dirtRetakenElementIds_", + "renderingPaused", + "isDeleting_", + "isCompFreezeAllowed_", + "prebuildFuncQueues", + "propertyChangedFuncQueues", + "extraInfo_", + "isBlockRecycleOrReuse", + "elmtIdsDelayedUpdate_", + "prebuildPhase_", + "isPrebuilding_", + "prebuildingElmtId_", + "nativeViewPartialUpdate", + "createRecycle", + "markNeedUpdate", + "markStatic", + "finishUpdateFunc", + "elmtIdExists", + "isLazyItemRender", + "isFirstRender", + "findChildByIdForPreview", + "resetRecycleCustomNode", + "queryNavDestinationInfo", + "queryNavigationInfo", + "queryRouterPageInfo", + "getUIContext", + "sendStateInfo", + "getDialogController", + "allowReusableV2Descendant", + "scheduleDelayedUpdate", + "elmtIdsDelayedUpdate", + "removeChild", + "isDeleting", + "setDeleting", + "setDeleteStatusRecursively", + "setActiveCount", + "getChildViewV2ForElmtId", + "debugInfoRegisteredElmtIds", + "debugInfoElmtIds", + "dumpStateVars", + "isViewActive", + "dumpReport", + "forceCompleteRerender", + "ClearAllRecyle__PUV2ViewBase__Internal", + "hasNodeUpdateFunc", + "pauseRendering", + "restoreRendering", + "forEachUpdateFunction", + "getNodeById", + "getCurrentlyRenderedElmtId", + "debugInfoViewHierarchy", + "debugInfoUpdateFuncByElmtId", + "debugInfoUpdateFuncByElmtIdInternal", + "debugInfoInactiveComponents", + "findViewInHierarchy", + "onDumpInfo", + "printDFXHeader", + "processOnDumpCommands", + "traverseChildDoRecycleOrReuse", + "processPropertyChangedFuncQueue", + "setPrebuildPhase", + "isNeedBuildPrebuildCmd", + "prebuildComponent", + "isEnablePrebuildInMultiFrame", + "onDumpInspector", + "activeCount", + "childrenWeakrefMap", + "builderNodeWeakrefMap_", + "updateFuncByElmtId", + "shareLocalStorage_", + "parentViewBuildNode", + "enableBuilderNodeConsume", + "elmtId2Repeat_", + "arkThemeScopeManager", + "getChildById", + "setParentBuilderNode__", + "addChildBuilderNode", + "propagateToChildrenToConnected", + "removeChildBuilderNode", + "clearChildBuilderNode", + "propagateToChildrenToDisconnected", + "purgeDeletedElmtIds", + "updateStateVarsOfChildByElmtId", + "createOrGetNode", + "setArkThemeScopeManager", + "onWillApplyThemeInternally", + "onWillApplyTheme", + "onGlobalThemeChanged", + "getShareLocalStorage", + "setShareLocalStorage", + "propagateToChildren" + ] +} \ No newline at end of file diff --git a/compiler/src/process_struct_componentV2.ts b/compiler/src/process_struct_componentV2.ts index 17baf35db..a969dd5fb 100644 --- a/compiler/src/process_struct_componentV2.ts +++ b/compiler/src/process_struct_componentV2.ts @@ -53,7 +53,8 @@ import { isReuseInV2 } from './process_custom_component'; import { judgeBuilderParamAssignedByBuilder } from './process_component_member'; import { componentCollection, - builderParamObjectCollection + builderParamObjectCollection, + validateStmgmtKeywords } from './validate_ui_syntax'; import logMessageCollection from './log_message_collection'; import { globalProgram } from '../main'; @@ -419,6 +420,9 @@ function createInitNode(propName: string, defaultValue: ts.Expression): ts.Expre function parseComponentProperty(node: ts.StructDeclaration, structInfo: StructInfo, log: LogInfo[], sourceFileNode: ts.SourceFile): void { node.members.forEach((member: ts.ClassElement) => { + if (member && member.name && ts.isIdentifier(member.name)) { + validateStmgmtKeywords(member.name.getText(), member.name); + } if (ts.isPropertyDeclaration(member)) { const decorators: readonly ts.Decorator[] = ts.getAllDecorators(member); const modifiers: readonly ts.Modifier[] = ts.getModifiers(member); diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 4543facef..0dd4ef4e0 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -15,6 +15,7 @@ import ts from 'typescript'; import path from 'path'; +import fs from 'fs'; import { INNER_COMPONENT_DECORATORS, @@ -185,12 +186,15 @@ export const useOSFiles: Set = new Set(); export const sourcemapNamesCollection: Map> = new Map(); export const originalImportNamesMap: Map = new Map(); +export let stmgmtWhiteList: Set = new Set(); + export function validateUISyntax(source: string, content: string, filePath: string, fileQuery: string, sourceFile: ts.SourceFile = null): LogInfo[] { let log: LogInfo[] = []; if (process.env.compileMode === 'moduleJson' || path.resolve(filePath) !== path.resolve(projectConfig.projectPath || '', 'app.ets')) { componentCollection = new ComponentCollection(); + readStmgmtWhiteList(); const res: LogInfo[] = checkComponentDecorator(source, filePath, fileQuery, sourceFile); if (res) { log = log.concat(res); @@ -1479,6 +1483,9 @@ function traversalComponentProps(node: ts.StructDeclaration, componentSet: IComp if (node.members) { const currentMethodCollection: Set = new Set(); node.members.forEach(item => { + if (item && item.name && ts.isIdentifier(item.name)) { + validateStmgmtKeywords(item.name.getText(), item.name); + } if (ts.isPropertyDeclaration(item) && ts.isIdentifier(item.name)) { const propertyName: string = item.name.getText(); componentSet.properties.add(propertyName); @@ -1953,6 +1960,35 @@ export function getLocalStorageCollection(componentName: string, collection: Set } } +function readStmgmtWhiteList(): void { + const relPath: string = '../stmgmtWhiteList.json'; + const absolutePath: string = path.join(__dirname, relPath); + if (!fs.existsSync(absolutePath)) { + return; + } + const stats: any = fs.statSync(absolutePath); + if (!stats.isFile()) { + return; + } + const fileContent: any = require(absolutePath); + if (fileContent) { + stmgmtWhiteList = new Set(fileContent.attrs ?? []); + } +} + +export function validateStmgmtKeywords(itemName: string, memberNode: ts.Identifier): void { + const message: string = `Methods, properties and accessors in structures decorated by '@Component'` + + ` and '@ComponentV2' cannot have name as '${itemName}'.`; + if (stmgmtWhiteList && stmgmtWhiteList.has(itemName)) { + transformLog.errors.push({ + message: message, + pos: memberNode.getStart(), + type: LogType.ERROR, + code: '10905361' + }); + } +} + export function resetValidateUiSyntax(): void { observedClassCollection.clear(); enumCollection.clear(); @@ -1971,4 +2007,5 @@ export function resetValidateUiSyntax(): void { useOSFiles.clear(); sourcemapNamesCollection.clear(); originalImportNamesMap.clear(); + stmgmtWhiteList.clear(); } -- Gitee