1/* 2 * Copyright (c) 2025 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 16function foo(f: () => int): int { 17 return f() 18} 19 20// AstNodes inside the trailing lambda are cloned - check that Clone works correctly 21let test1 = foo() { 22 let res = 0 23 a: for (let i = 0; i < 5; i++) { 24 b: for (let j = 0; j < 5; j++) { 25 if (j > i) 26 break a 27 res++ 28 } 29 } 30 return res 31} 32 33let test2 = foo() { 34 let res = 0 35 a: for (let i = 0; i < 5; i++) { 36 b: for (let j = 0; j < 5; j++) { 37 if (j > i) 38 break b 39 res++ 40 } 41 } 42 return res 43} 44 45let test3 = foo() { 46 let res = 0 47 a: for (let i = 0; i < 5; i++) { 48 b: for (let j = 0; j < 5; j++) { 49 if (j > i) 50 continue a 51 res++ 52 } 53 res += 1000 54 } 55 return res 56} 57 58let test4 = foo() { 59 let res = 0 60 a: for (let i = 0; i < 5; i++) { 61 b: for (let j = 0; j < 5; j++) { 62 if (j > i) 63 continue b 64 res++ 65 } 66 res += 1000 67 } 68 return res 69} 70 71 72function main(): void { 73 assertEQ(test1, 1) 74 assertEQ(test2, 15) 75 assertEQ(test3, 1015) 76 assertEQ(test4, 5015) 77} 78