1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16exports.source = ` 17import * as AllComponent from './test/pages/NamespaceComponent' 18import TsModule from './test/pages/TsModule' 19 20@Entry 21@Component 22struct ImportTest { 23 @State myState1: any = new TsModule(1).method() 24 @State myState2: number = 0 25 @State myState3: boolean = false 26 @State myState4: string = 'ImportTest' 27 28 build() { 29 Column() { 30 AllComponent.NamespaceComponent1({ 31 NamespaceComponent1Link1: $myState1, 32 NamespaceComponent1Link2: $myState2, 33 NamespaceComponent1Link3: $myState3, 34 NamespaceComponent1Link4: $myState4, 35 myVar: 100, 36 myVar2: 80 37 }) 38 AllComponent.NamespaceComponent1({ 39 NamespaceComponent1Link1: $myState1, 40 NamespaceComponent1Link2: $myState2, 41 NamespaceComponent1Link3: $myState3, 42 NamespaceComponent1Link4: $myState4, 43 myVar: 100, 44 myVar2: 80 45 }) 46 .width(100) 47 AllComponent.default({ 48 NamespaceComponent3Link1: $myState1, 49 NamespaceComponent3Link2: $myState2, 50 NamespaceComponent3Link3: $myState3, 51 NamespaceComponent3Link4: $myState4, 52 myVar: 100, 53 myVar2: 80 54 }) 55 AllComponent.default({ 56 NamespaceComponent3Link1: $myState1, 57 NamespaceComponent3Link2: $myState2, 58 NamespaceComponent3Link3: $myState3, 59 NamespaceComponent3Link4: $myState4, 60 myVar: 100, 61 myVar2: 80 62 }) 63 .height(200) 64 } 65 } 66} 67` 68 69exports.expectResult = 70`"use strict"; 71var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 72 if (k2 === undefined) k2 = k; 73 var desc = Object.getOwnPropertyDescriptor(m, k); 74 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { 75 desc = { enumerable: true, get: function() { return m[k]; } }; 76 } 77 Object.defineProperty(o, k2, desc); 78}) : (function(o, m, k, k2) { 79 if (k2 === undefined) k2 = k; 80 o[k2] = m[k]; 81})); 82var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 83 Object.defineProperty(o, "default", { enumerable: true, value: v }); 84}) : function(o, v) { 85 o["default"] = v; 86}); 87var __importStar = (this && this.__importStar) || function (mod) { 88 if (mod && mod.__esModule) return mod; 89 var result = {}; 90 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 91 __setModuleDefault(result, mod); 92 return result; 93}; 94var __importDefault = (this && this.__importDefault) || function (mod) { 95 return (mod && mod.__esModule) ? mod : { "default": mod }; 96}; 97Object.defineProperty(exports, "__esModule", { value: true }); 98const AllComponent = __importStar(require("./test/pages/NamespaceComponent")); 99const TsModule_1 = __importDefault(require("./test/pages/TsModule")); 100class ImportTest extends ViewPU { 101 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 102 super(parent, __localStorage, elmtId, extraInfo); 103 if (typeof paramsLambda === "function") { 104 this.paramsGenerator_ = paramsLambda; 105 } 106 this.__myState1 = new ObservedPropertyObjectPU(new TsModule_1.default(1).method(), this, "myState1"); 107 this.__myState2 = new ObservedPropertySimplePU(0, this, "myState2"); 108 this.__myState3 = new ObservedPropertySimplePU(false, this, "myState3"); 109 this.__myState4 = new ObservedPropertySimplePU('ImportTest', this, "myState4"); 110 this.setInitiallyProvidedValue(params); 111 } 112 setInitiallyProvidedValue(params) { 113 if (params.myState1 !== undefined) { 114 this.myState1 = params.myState1; 115 } 116 if (params.myState2 !== undefined) { 117 this.myState2 = params.myState2; 118 } 119 if (params.myState3 !== undefined) { 120 this.myState3 = params.myState3; 121 } 122 if (params.myState4 !== undefined) { 123 this.myState4 = params.myState4; 124 } 125 } 126 updateStateVars(params) { 127 } 128 purgeVariableDependenciesOnElmtId(rmElmtId) { 129 this.__myState1.purgeDependencyOnElmtId(rmElmtId); 130 this.__myState2.purgeDependencyOnElmtId(rmElmtId); 131 this.__myState3.purgeDependencyOnElmtId(rmElmtId); 132 this.__myState4.purgeDependencyOnElmtId(rmElmtId); 133 } 134 aboutToBeDeleted() { 135 this.__myState1.aboutToBeDeleted(); 136 this.__myState2.aboutToBeDeleted(); 137 this.__myState3.aboutToBeDeleted(); 138 this.__myState4.aboutToBeDeleted(); 139 SubscriberManager.Get().delete(this.id__()); 140 this.aboutToBeDeletedInternal(); 141 } 142 get myState1() { 143 return this.__myState1.get(); 144 } 145 set myState1(newValue) { 146 this.__myState1.set(newValue); 147 } 148 get myState2() { 149 return this.__myState2.get(); 150 } 151 set myState2(newValue) { 152 this.__myState2.set(newValue); 153 } 154 get myState3() { 155 return this.__myState3.get(); 156 } 157 set myState3(newValue) { 158 this.__myState3.set(newValue); 159 } 160 get myState4() { 161 return this.__myState4.get(); 162 } 163 set myState4(newValue) { 164 this.__myState4.set(newValue); 165 } 166 initialRender() { 167 this.observeComponentCreation2((elmtId, isInitialRender) => { 168 Column.create(); 169 }, Column); 170 { 171 this.observeComponentCreation2((elmtId, isInitialRender) => { 172 if (isInitialRender) { 173 let componentCall = new AllComponent.NamespaceComponent1(this, { 174 NamespaceComponent1Link1: this.__myState1, 175 NamespaceComponent1Link2: this.__myState2, 176 NamespaceComponent1Link3: this.__myState3, 177 NamespaceComponent1Link4: this.__myState4, 178 myVar: 100, 179 myVar2: 80 180 }, undefined, elmtId, () => { }, { page: "importAllEts.ets", line: 15 }); 181 ViewPU.create(componentCall); 182 let paramsLambda = () => { 183 return { 184 NamespaceComponent1Link1: this.myState1, 185 NamespaceComponent1Link2: this.myState2, 186 NamespaceComponent1Link3: this.myState3, 187 NamespaceComponent1Link4: this.myState4, 188 myVar: 100, 189 myVar2: 80 190 }; 191 }; 192 componentCall.paramsGenerator_ = paramsLambda; 193 } 194 else { 195 this.updateStateVarsOfChildByElmtId(elmtId, {}); 196 } 197 }, { name: "NamespaceComponent1" }); 198 } 199 this.observeComponentCreation2((elmtId, isInitialRender) => { 200 __Common__.create(); 201 __Common__.width(100); 202 }, __Common__); 203 { 204 this.observeComponentCreation2((elmtId, isInitialRender) => { 205 if (isInitialRender) { 206 let componentCall = new AllComponent.NamespaceComponent1(this, { 207 NamespaceComponent1Link1: this.__myState1, 208 NamespaceComponent1Link2: this.__myState2, 209 NamespaceComponent1Link3: this.__myState3, 210 NamespaceComponent1Link4: this.__myState4, 211 myVar: 100, 212 myVar2: 80 213 }, undefined, elmtId, () => { }, { page: "importAllEts.ets", line: 23 }); 214 ViewPU.create(componentCall); 215 let paramsLambda = () => { 216 return { 217 NamespaceComponent1Link1: this.myState1, 218 NamespaceComponent1Link2: this.myState2, 219 NamespaceComponent1Link3: this.myState3, 220 NamespaceComponent1Link4: this.myState4, 221 myVar: 100, 222 myVar2: 80 223 }; 224 }; 225 componentCall.paramsGenerator_ = paramsLambda; 226 } 227 else { 228 this.updateStateVarsOfChildByElmtId(elmtId, {}); 229 } 230 }, { name: "NamespaceComponent1" }); 231 } 232 __Common__.pop(); 233 { 234 this.observeComponentCreation2((elmtId, isInitialRender) => { 235 if (isInitialRender) { 236 let componentCall = new AllComponent.default(this, { 237 NamespaceComponent3Link1: this.__myState1, 238 NamespaceComponent3Link2: this.__myState2, 239 NamespaceComponent3Link3: this.__myState3, 240 NamespaceComponent3Link4: this.__myState4, 241 myVar: 100, 242 myVar2: 80 243 }, undefined, elmtId, () => { }, { page: "importAllEts.ets", line: 32 }); 244 ViewPU.create(componentCall); 245 let paramsLambda = () => { 246 return { 247 NamespaceComponent3Link1: this.myState1, 248 NamespaceComponent3Link2: this.myState2, 249 NamespaceComponent3Link3: this.myState3, 250 NamespaceComponent3Link4: this.myState4, 251 myVar: 100, 252 myVar2: 80 253 }; 254 }; 255 componentCall.paramsGenerator_ = paramsLambda; 256 } 257 else { 258 this.updateStateVarsOfChildByElmtId(elmtId, {}); 259 } 260 }, { name: "default" }); 261 } 262 this.observeComponentCreation2((elmtId, isInitialRender) => { 263 __Common__.create(); 264 __Common__.height(200); 265 }, __Common__); 266 { 267 this.observeComponentCreation2((elmtId, isInitialRender) => { 268 if (isInitialRender) { 269 let componentCall = new AllComponent.default(this, { 270 NamespaceComponent3Link1: this.__myState1, 271 NamespaceComponent3Link2: this.__myState2, 272 NamespaceComponent3Link3: this.__myState3, 273 NamespaceComponent3Link4: this.__myState4, 274 myVar: 100, 275 myVar2: 80 276 }, undefined, elmtId, () => { }, { page: "importAllEts.ets", line: 40 }); 277 ViewPU.create(componentCall); 278 let paramsLambda = () => { 279 return { 280 NamespaceComponent3Link1: this.myState1, 281 NamespaceComponent3Link2: this.myState2, 282 NamespaceComponent3Link3: this.myState3, 283 NamespaceComponent3Link4: this.myState4, 284 myVar: 100, 285 myVar2: 80 286 }; 287 }; 288 componentCall.paramsGenerator_ = paramsLambda; 289 } 290 else { 291 this.updateStateVarsOfChildByElmtId(elmtId, {}); 292 } 293 }, { name: "default" }); 294 } 295 __Common__.pop(); 296 Column.pop(); 297 } 298 rerender() { 299 this.updateDirtyElements(); 300 } 301} 302ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); 303loadDocument(new ImportTest(undefined, {})); 304ViewStackProcessor.StopGetAccessRecording(); 305` 306