• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 = `
17@Entry
18@Component
19struct MyComponent {
20    private test: string = 'Hello'
21    build() {
22        Column() {
23        if (this.test === 'Hello') {
24            Text(this.test)
25        }
26
27        if (this.test === 'Hello') {
28            Text(this.test)
29            Button()
30            .width(20)
31            .height(20)
32        } else if (this.test === 'World') {
33            Text('World')
34        } else if (this.test === 'Hello World') {
35            Text(this.test)
36            Text('World')
37        }
38        else {
39
40        }
41
42        if (this.test === 'Hello') Text(this.test)
43        else if (this.test === '') Button()
44                                    .width(20)
45                                    .height(20)
46
47        if (this.test === 'Hello') {
48            Text(this.test)
49        }
50
51        Text(this.test)
52        Button()
53            .width(20)
54            .height(20)
55
56        if (true) {
57            if (this.test === 'Hello') {
58            if (1) {
59                Text(this.test)
60            }
61            } else {
62            if (0) {
63                Button()
64                .width(20)
65                .height(20)
66            } else if (1) {
67
68            }
69            }
70        }
71
72        if (this.test !== 'Hello') if (this.test !== 'World') Button()
73                                                                .width(20)
74                                                                .height(20)
75        }.width(100)
76    }
77}`
78
79exports.expectResult =
80`"use strict";
81class MyComponent extends View {
82    constructor(compilerAssignedUniqueChildId, parent, params) {
83        super(compilerAssignedUniqueChildId, parent);
84        this.test = 'Hello';
85        this.updateWithValueParams(params);
86    }
87    updateWithValueParams(params) {
88        if (params.test !== undefined) {
89            this.test = params.test;
90        }
91    }
92    aboutToBeDeleted() {
93        SubscriberManager.Get().delete(this.id());
94    }
95    render() {
96        Column.create();
97        Column.width(100);
98        If.create();
99        if (this.test === 'Hello') {
100            If.branchId(0);
101            Text.create(this.test);
102            Text.pop();
103        }
104        If.pop();
105        If.create();
106        if (this.test === 'Hello') {
107            If.branchId(0);
108            Text.create(this.test);
109            Text.pop();
110            Button.createWithLabel();
111            Button.width(20);
112            Button.height(20);
113            Button.pop();
114        }
115        else if (this.test === 'World') {
116            If.branchId(1);
117            Text.create('World');
118            Text.pop();
119        }
120        else if (this.test === 'Hello World') {
121            If.branchId(2);
122            Text.create(this.test);
123            Text.pop();
124            Text.create('World');
125            Text.pop();
126        }
127        else {
128            If.branchId(3);
129        }
130        If.pop();
131        If.create();
132        if (this.test === 'Hello') {
133            If.branchId(0);
134            Text.create(this.test);
135            Text.pop();
136        }
137        else if (this.test === '') {
138            If.branchId(1);
139            Button.createWithLabel();
140            Button.width(20);
141            Button.height(20);
142            Button.pop();
143        }
144        If.pop();
145        If.create();
146        if (this.test === 'Hello') {
147            If.branchId(0);
148            Text.create(this.test);
149            Text.pop();
150        }
151        If.pop();
152        Text.create(this.test);
153        Text.pop();
154        Button.createWithLabel();
155        Button.width(20);
156        Button.height(20);
157        Button.pop();
158        If.create();
159        if (true) {
160            If.branchId(0);
161            If.create();
162            if (this.test === 'Hello') {
163                If.branchId(0);
164                If.create();
165                if (1) {
166                    If.branchId(0);
167                    Text.create(this.test);
168                    Text.pop();
169                }
170                If.pop();
171            }
172            else {
173                If.branchId(1);
174                If.create();
175                if (0) {
176                    If.branchId(0);
177                    Button.createWithLabel();
178                    Button.width(20);
179                    Button.height(20);
180                    Button.pop();
181                }
182                else if (1) {
183                    If.branchId(1);
184                }
185                If.pop();
186            }
187            If.pop();
188        }
189        If.pop();
190        If.create();
191        if (this.test !== 'Hello') {
192            If.create();
193            If.branchId(0);
194            if (this.test !== 'World') {
195                If.branchId(0);
196                Button.createWithLabel();
197                Button.width(20);
198                Button.height(20);
199                Button.pop();
200            }
201            If.pop();
202        }
203        If.pop();
204        Column.pop();
205    }
206}
207loadDocument(new MyComponent("1", undefined, {}));
208`
209