diff --git a/compiler/src/process_component_class.ts b/compiler/src/process_component_class.ts index 281c76b6c..c54b8d40b 100644 --- a/compiler/src/process_component_class.ts +++ b/compiler/src/process_component_class.ts @@ -240,6 +240,7 @@ function processMembers(members: ts.NodeArray, parentComponentN processPropertyUnchanged(result, purgeVariableDepStatements); } } + staticBlock(item, newMembers); if (ts.isMethodDeclaration(item) && item.name) { updateItem = processComponentMethod(item, context, log, buildCount); @@ -274,6 +275,12 @@ function processMembers(members: ts.NodeArray, parentComponentN return newMembers; } +function staticBlock(item: ts.ClassElement, newMembers: ts.ClassElement[]): void { + if (ts.isClassStaticBlockDeclaration(item) && item.body && ts.isBlock(item.body)) { + newMembers.push(item); + } +} + export function decoratorAssignParams(decoratorNode: readonly ts.Decorator[], context: ts.TransformationContext, creezeParam: FreezeParamType): boolean { if (decoratorNode && Array.isArray(decoratorNode) && decoratorNode.length) { diff --git a/compiler/test/utForPartialUpdate/logicMethod/staticCode.ts b/compiler/test/utForPartialUpdate/logicMethod/staticCode.ts new file mode 100644 index 000000000..335e7e28b --- /dev/null +++ b/compiler/test/utForPartialUpdate/logicMethod/staticCode.ts @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 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. + */ + +exports.source = ` +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + static message1 = 'Hello World'; + static message2 = 'Hello World'; + static { + this.message2 = 'Hi World'; + } + build() { + RelativeContainer() { + Text(this.message) + } + .height('100%') + .width('100%') + } +} +`; + +exports.expectResult = +`"use strict"; +var _a; +if (!("finalizeConstruction" in ViewPU.prototype)) { + Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { }); +} +class Index extends ViewPU { + constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { + super(parent, __localStorage, elmtId, extraInfo); + if (typeof paramsLambda === "function") { + this.paramsGenerator_ = paramsLambda; + } + this.__message = new ObservedPropertySimplePU('Hello World', this, "message"); + this.setInitiallyProvidedValue(params); + this.finalizeConstruction(); + } + setInitiallyProvidedValue(params) { + if (params.message !== undefined) { + this.message = params.message; + } + } + updateStateVars(params) { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__message.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__message.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get message() { + return this.__message.get(); + } + set message(newValue) { + this.__message.set(newValue); + } + initialRender() { + this.observeComponentCreation2((elmtId, isInitialRender) => { + RelativeContainer.create(); + RelativeContainer.height('100%'); + RelativeContainer.width('100%'); + }, RelativeContainer); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Text.create(this.message); + }, Text); + Text.pop(); + RelativeContainer.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} +_a = Index; +Index.message1 = 'Hello World'; +Index.message2 = 'Hello World'; +(() => { + _a.message2 = 'Hi World'; +})(); +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new Index(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); +`;