diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_annotationDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_annotationDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..61dc59403704452345e410b511988f2556db180d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_annotationDeclaration.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 18.1 + * annotationDeclaration: + * '@interface' identifier '{' annotationField* '}' + * ; + */ + +@interface a { + value: number[] = [10]; +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_annotationUsage.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_annotationUsage.ets new file mode 100644 index 0000000000000000000000000000000000000000..4479421bfb3a1a16bd8e18660fd0d6997aa59ef3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_annotationUsage.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 18.2 + * annotationUsage: + * 'at' qualifiedName annotationValues? + * ; + */ + +@interface DetailedAnnotation { + authorName: string[]; + creationDate: string[]; +} +@DetailedAnnotation({ + authorName: ["张三"], + creationDate: ["2025-03-19"] +}) +class DocumentedClass {}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_assignmentExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_assignmentExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..23ed5d07cb0f3638952b945bbb31646e5db00063 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_assignmentExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.29 + * assignmentExpression: + * lhsExpression assignmentOperator rhsExpression + * ; + */ + +let a = [5, 6]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf7d6b81bbacb395eb06a1df52921de6c3a0bc71 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_awaitExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +function foo(): Promise { + return new Promise((resolve, reject) => { + resolve([1, 2]); + }); +} +const res = await foo(); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..a54fae73c0863451fadb1a1b3f952a8d68e27ae0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_classInitializer.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class ExampleClass1 { + static initialized = [1, 2]; + static initializerBlock() { + if (ExampleClass1.initialized == [1, 2]) { + ExampleClass1.initialized = [1, 2, 3]; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_conditionalExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_conditionalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..75a85575cc33ba8ff09c6f998f7618193eceaaa0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_conditionalExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.30 + * conditionalExpression: + * expression '?' expression ':' expression + * ; + */ + +(7 > 5) ? [7] : [5]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_constantExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_constantExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..f82e71dbd87a01050cedb6c0755b69862520b2f8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_constantExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.33 + * constantExpression: + * expression + * ; + */ + +const a = [3, 14]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_ensureNotNullishExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_ensureNotNullishExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba4badc95f3a68b87c92fdb5d095dc6696ecf4a6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_ensureNotNullishExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.18 + * ensureNotNullishExpression: + * expression '!' + * ; + */ + +[1, 2]!; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_equalityExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_equalityExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..5cde11e37bb766895f0ecf1917b483dbae527e56 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_equalityExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.25 + * equalityExpression: + * expression ('==' | '===' | '!=' | '!==') expression + * ; + */ + +[5] == [5]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_fieldAccessExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_fieldAccessExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..eaf96c623bff3f6c8c7324fe6b47655e1e15a26d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_fieldAccessExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.9 + * fieldAccessExpression: + * objectReference ('.' | '?.') identifier + * ; + */ + +class Person1 { + name: number[] = [1, 2]; +} + +let person = new Person1(); +person.name = [1, 2]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_forOfStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_forOfStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..47e030946d3712ee76f63acb96b19de1a682d934 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_forOfStatement.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + */ + +let arr = [1, 2, 3]; +let item: number = 1; +for (item of arr) { + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_forStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_forStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..ec782fd0cbc70dedef4437bb021c4774a4af4c19 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_forStatement.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + */ + +let a = [1, 2]; +let i: number = 1; +for (; i < 10; i++) { + if (a == [1, 2]) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_functionCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_functionCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..b289ec26cff3d5ac8cb9ea418ccdb616c2bd199e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_functionCallExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.11 + * functionCallExpression: + * expression ('?.' | typeArguments)? arguments block? + * ; + */ + +function func1(x: number[]): number { + return 0; +} + +func1([1, 2]); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_ifStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_ifStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..f45e1116bd93c75754b2bb680f6c2f95d988ef2b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_ifStatement.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + */ + +let i = [1, 2]; +if (i == [1, 2]) { + console.log("true"); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_indexingExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_indexingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..71d80c99573a2551030d0a3bf3b4d0423b3c93a9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_indexingExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.12 + * indexingExpression: + * expression ('?.')? '[' expression ']' + * ; + */ + +let numbers = [1, 2, 3, 4, 5]; +numbers[0]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca0b1792eef26410a118aa3f0017b3299f806860 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_initializerBlock.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static initializerBlock() { + let a = [1, 2] ; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_lambdaExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_lambdaExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..f66fb232b3ce1dd1d8a095ff660ee57037a1ca95 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_lambdaExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.32 + * lambdaExpression: + * annotationUsage? ('async'|typeParameters)? lambdaSignature '=>' lambdaBody + * ; + */ + +(): number[] => { return [1, 2] } diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..157f92e0a7f8b179fd6e3cc437f30bd630468660 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_lambdaExpressionWithReceiver.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} +let result4 = (this: A): number[] => { return [0, 1]; }; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_loopStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_loopStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..00cf9dc32f95d24fb0c6ee4adb0df50a482e3589 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_loopStatement.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + */ + +let i = [1, 2]; +while(i == [1, 2]) { + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_methodCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_methodCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..a29fe4e6a1913a26525d06fa775c4d8fcca93aea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_methodCallExpression.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.10 + * methodCallExpression: + * objectReference ('.' | '?.') identifier typeArguments? arguments block? + * ; + */ + +class Person2 { + name: number[] = [1, 2]; + setName(name: number[]): void { + this.name = name; + } +} + +let person = new Person2(); +person.setName([1, 2]); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..33d29f1b168f359634730c3d9012400dd9ebef72 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_namespaceDeclaration.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace NS1 { + let a: number[] = [1, 2]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..60b5071b8c4580bc532f4ec5b78f8c933cd1a14b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_newArrayInstance.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +let a = new string[3]; +a[0] = "a"; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_newExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_newExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..880348835e490cff6ecd57ae2659408b22b6bde7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_newExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.14 + * newExpression: + * newClassInstance + * | newArrayInstance + * ; + */ + +class D { + constructor(p: number[]) {} +} + +new D([5, 6]); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_nullishCoalescingExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_nullishCoalescingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..2000671b9cf67583d43d838446cdb78d1073f08f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_nullishCoalescingExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.19 + * nullishCoalescingExpression: + * expression '??' expression + * ; + */ + +null ?? [42, 43]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_objectLiteral.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_objectLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..cf5d454c9ef93c035e49004eaefd9ab5389ad7e9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_objectLiteral.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + */ + +class Person { + name: string[] = ["a", "b"] + age: number = 0 +} +let b : Person = {name: ["Bob", "White"], age: 25} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_parenthesizedExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_parenthesizedExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..646cedc08782be053ca256bdc25d8d033b16423d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_parenthesizedExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.7 + * parenthesizedExpression: + * '(' expression ')' + * ; + */ + +let arr1: number[] = ([1, 2, 3]); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_recordLiteral.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_recordLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..792614a00914edebf1ed2e6c80c129e7b5c1870e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_recordLiteral.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + */ + +let map: Record = { + "John": [25, 2], + "Mary": [21, 4], +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..d6b6d06027e579c5f5e8803c7e21d523afe5ce38 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_returnStatement.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function a() { + return [1, 2]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee470ce9e8c6e8860ef497f03a5cdf81e667c54d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_separateModuleDeclaration.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +let a: string[] = ['1', '2']; +console.info('a: ' + a); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_spreadExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_spreadExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..8dce17ea0ef96c952bd8c67bf986977631a9c863 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_spreadExpression.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.6 + * spreadExpression: + * '...' expression + * ; + */ + +let array1 = [1, 2, 3]; +let array2 = [4, 5]; +let array3 = [...array1, ...array2]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_statement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_statement.ets new file mode 100644 index 0000000000000000000000000000000000000000..b35b8bb9bf639d266f60fef0c944ebf301615a27 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_statement.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throw Statement + * | tryStatement + * ; + */ + +let x = [10]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_stringInterpolation.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_stringInterpolation.ets new file mode 100644 index 0000000000000000000000000000000000000000..52156e78fe38c13e31c1c22b722342d10b2f95de --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_stringInterpolation.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.31 + * stringInterpolation: + * ' ` ' (BacktickCharacter | embeddedExpression)* ' ` ' + * ; + */ + +let name = ['Alice']; +`Hello, my name is ${name}.`; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_thisExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_thisExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..37ec0b2440848afd5ace0b2f48275b7688a16a62 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_thisExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.8 + * thisExpression: + * 'this' + * ; + */ + +class ThisExample { + public field: number[]; + constructor() { + this.field = [1, 2]; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ddcc53fcbe573bf036a9f1637e2603c2d58085b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_throwStatement.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +throw new Error("error" + [1]); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..6fb1227d04f5e3b4598091c5c08de53a32469b3a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_topDeclaration.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +export let x: string[], y: string[]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..f967810c5a98459428846d3aa4dd38f196d4a5dd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_topLevelStatements.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement * + * ; + */ + +let a: number[] = [56, 58]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca3bf822593cb5a93bff1b0a38eda55d183c9dbf --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_trailingLambdaCall.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + methodTwo(arg: T, callback: (result: T) => void): void { + const result = arg; + callback(result); + } +} +let a = new A(); +a.methodTwo(["Hi"]) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..981d14e4054e541b79784e6fed9f6d0797a232b4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_tryStatement.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processOne(a: number[]): number[] { + try { + const res = [1]; + return res; + } catch (error) { + return [-1]; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_typeOfExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_typeOfExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..c50e5c0b368c471fcce442140e76f8395cd0bf8f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_typeOfExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.17 + * typeOfExpression: + * 'typeof' expression + * ; + */ + +let s: string[] = ['a', 'b']; +typeof s; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_unaryExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_unaryExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bda751b9c0bbeb39f1b921b8d34176dd1d53c6f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_unaryExpression.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 7.20 + * unaryExpression: + * expression '++' + * | expression '--' + * | '++' expression + * | '--' expression + * | '+' expression + * | '-' expression + * | '~' expression + * | '!' expression + * ; + */ + +![3, 5]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_whileStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_whileStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..383a810daf2465711bea4b58b5f7e5e1331d20c2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/arrayLiteral/arrayLiteral_whileStatement.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.4 + * arrayLiteral: + * '[' expressionSequence? ']' + * ; + * + * CHAPTER 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + */ + +let i = [1, 2]; +while(i == [1, 2]) { + i == [1, 2, 3]; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_additiveExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_additiveExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..00c596b9575706f5ba1e02fbcd34f7e968124686 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_additiveExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.22 + * additiveExpression: + * expression '+' expression + * | expression '-' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +a.s + 4; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_assignmentExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_assignmentExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..d0197ebbca745c87d04f4734d5c85d52e1ad0c7f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_assignmentExpression.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.29 + * assignmentExpression: + * lhsExpression assignmentOperator rhsExpression + * ; + */ + +class S { + s: number = 0; +} +let a: S = {s: 5}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..4eea22fa5ef27604bee327a6e1f64a29818dfb78 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_awaitExpression.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +class S { + s: number = 0; +} + +function foo(): Promise { + return new Promise((resolve, reject) => { + let a: S = {s: 5}; + resolve(a); + }); +} +const res = await foo(); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_bitwiseAndLogicalExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_bitwiseAndLogicalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..54c94e63fba0db727905f2b663f206aa647c59b8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_bitwiseAndLogicalExpression.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.26 + * bitwiseAndLogicalExpression: + * expression '&' expression + * | expression '^' expression + * | expression '|' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +let b = new S; +a.s & b.s; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_castExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_castExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5e23a29177a7541f31c27292c4ac284c825841b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_castExpression.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.15 + * castExpression: + * expression 'as' type + * ; + */ + +class X {} +let x1 : X = new X(); +let ob : Object = x1 as Object; +let x2 : X = ob as X; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..7140be5d4041b2f08e5fc3108a4ff5069b72977e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_classInitializer.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class ExampleClass1 { + static initialized = false; + static initializerBlock() { + if (!ExampleClass1.initialized) { + ExampleClass1.initialized = true; + } + } +} +let a = new ExampleClass1; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalAndExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalAndExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..e468e23996bbc8944a45d93b9e0ccdfb031b346a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalAndExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.27 + * conditionalAndExpression: + * expression '&&' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +let b = new S; +a && b; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b50bc2a58bf5954e70d8c9c70abed2c1ea5828f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.30 + * conditionalExpression: + * expression '?' expression ':' expression + * ; + */ + +class S { + s: number = 0; +} +let a: S = {s: 7}; +let b: S = {s: 5}; +(7 > 5) ? a : b; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalOrExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalOrExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..a72ecd068384eb9e18eca5392a503a3d6ff2f117 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_conditionalOrExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.28 + * conditionalOrExpression: + * expression '||' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +let b = new S; +a || b; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_constantExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_constantExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..315164552bf5cf865f0cfb13535cacfaf7248db7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_constantExpression.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.33 + * constantExpression: + * expression + * ; + */ + +class S { + s: string = ''; +} +const a: S = {s: 'Alice'}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_ensureNotNullishExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_ensureNotNullishExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..179cef640adb1913ab3e787835647257d8c360ed --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_ensureNotNullishExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.18 + * ensureNotNullishExpression: + * expression '!' + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +a!; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_equalityExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_equalityExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..911cb0c0e7387972b83acffc1c86aee27b0689e4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_equalityExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.25 + * equalityExpression: + * expression ('==' | '===' | '!=' | '!==') expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +let b = new S; +a == b; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_fieldAccessExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_fieldAccessExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..27004741c518ae653d366e360179449ce923fb51 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_fieldAccessExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.9 + * fieldAccessExpression: + * objectReference ('.' | '?.') identifier + * ; + */ + +class Person1 { + name: string = 'Alice'; +} + +let person = new Person1(); +person.name = 'Bob'; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..747ef7ec1c71b591e19afb2e1d6d4210a22adaee --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_finallyClause.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +class A { + s: number = 0; +} + +function processOne() { + try { + } catch (error) { + } finally { + let x: A = {s: 5}; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_forOfStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_forOfStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..57cfed9f33a6779710eac52cab75fd034cde63e1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_forOfStatement.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.9 + * forOfStatement: + * 'for' '(' forVariable 'of' expression ')' statement + * ; + */ + +class A { + aa: number[] = []; +} +class B { + bb: number = 0; +} +let a: A = {aa: [1, 5]}; +let b: B = {bb: 10}; +for (const num of a.aa) { + b.bb = num; + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_forStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_forStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..45232c731bbcf95b7606e570b386fc35fa75636d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_forStatement.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + */ + +class S { + s: number = 0; +} +let a: S = {s: 5}; +let b: S = {s: 10}; +let i: number = 1; +for (; i < 10 && a != b; i++) { + if (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_functionCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_functionCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..54b5805c817413c9af9ed57f55f18560ddf62ec6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_functionCallExpression.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.11 + * functionCallExpression: + * expression ('?.' | typeArguments)? arguments block? + * ; + */ + +class Person2 { + name: string = 'Alice'; +} +function func1(x: Person2): number { + return 0; +} +let person = new Person2(); +func1(person); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..5081dfe4880c023c4d01a036eba3249bc5e7f1cf --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_functionTypeWithReceiver.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter(','ftParameterList)?')'ftReturnType + * ; + */ + +class A { + s: number = 0; +} +type F = (a: A) => void; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_ifStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_ifStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..5691ac96f21703f6de3a2a4b9c80815ae8c96a2e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_ifStatement.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + */ + +class S { + s: string = ''; +} +let a: S = {s: 'Alice'}; +if (a) { + console.log("true"); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_indexingExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_indexingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..1dbf7e274cdb98530920f6913ce5c047df703cba --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_indexingExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.12 + * indexingExpression: + * expression ('?.')? '[' expression ']' + * ; + */ + +class S { + s: number[] = []; +} +let a: S = {s: [1, 2, 3, 4, 5]}; +let b = a.s[0]; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..efdfdb03526d60b8b871425963eb6758e926aedf --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_initializerBlock.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class S { + s: number = 0; +} +class Test { + static initializerBlock() { + let a: S = {s: 56}; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_instanceOfExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_instanceOfExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..01c388eef74424662ee93120237a55c544d54f25 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_instanceOfExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.16 + * instanceOfExpression: + * expression 'instanceof' type + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +a instanceof S; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_lambdaExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_lambdaExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..e4b07c4a7bea75fccfe2941ea15288f0712ae469 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_lambdaExpression.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.32 + * lambdaExpression: + * annotationUsage? ('async'|typeParameters)? lambdaSignature '=>' lambdaBody + * ; + */ + +class S { + s: string = ''; +} +let result = async (): Promise => { + let a: S = {s: 'Alice'}; + return a; +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..f33434bd3b403f3e54f67b98584caa27eebae28d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_lambdaExpressionWithReceiver.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} +let result4 = (a: A): A => { return a; }; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_loopStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_loopStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..1aba6ddc309589c274353ad6490cef9958206d3d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_loopStatement.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + */ + +class S { + s: string = ''; +} +let a: S = {s: 'Alice'}; +while(a) { + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_methodCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_methodCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2cf29bbcc4c18a6f8328caa969c8cf2a9a95588 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_methodCallExpression.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.10 + * methodCallExpression: + * objectReference ('.' | '?.') identifier typeArguments? arguments block? + * ; + */ + +class Person2 { + name: string = 'Alice'; + setName(name: string): void { + this.name = name; + } +} + +let person = new Person2(); +person.setName('Bob'); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_multiplicativeExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_multiplicativeExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a53c00be351041a71a2c7f502670a14600a37e8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_multiplicativeExpression.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.21 + * multiplicativeExpression: + * expression '*' expression + * | expression '/' expression + * | expression '%' expressionc + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +a.s * 4; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..bad78753e0574851b4c1f3ee7c7f66a9f7735ba5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_namespaceDeclaration.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +class S { + s: number = 0; +} +namespace NS1 { + let a: S = {s: 1}; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ffc9a395d4f2349395d923a00fe9a9edd15d884 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_newArrayInstance.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +class S { + s: number[] = []; +} +let a: S = {s: new number[1]}; +a.s[0] = 1; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_newExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_newExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff0b1884bae1cc6216b28023f9017e040dd5bedd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_newExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.14 + * newExpression: + * newClassInstance + * | newArrayInstance + * ; + */ + +class D { + constructor(p: number) {} +} + +let d = new D(5); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_nullishCoalescingExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_nullishCoalescingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..eec040081b838dbeaf78afe1949abf36cbf0a3f7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_nullishCoalescingExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.19 + * nullishCoalescingExpression: + * expression '??' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +null ?? a; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_parenthesizedExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_parenthesizedExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..385a9a0118005c569d2c7b5e06963c962192fef9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_parenthesizedExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.7 + * parenthesizedExpression: + * '(' expression ')' + * ; + */ + +class Person { + name: string = "" + age: number = 0 +} +let b : Person = {name: "a", age: (8 + 10)} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_recordLiteral.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_recordLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..be031891d03a3f6a10b7ad41a1a2d030bc98ccfd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_recordLiteral.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + */ + +class Person { + name: string = "" +} + +let s: Record = {"John": {name: "John"}}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_relationalExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_relationalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..4a74cd0937cd7f1d68a20e4b95f96a55063dc873 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_relationalExpression.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.24 + * relationalExpression: + * expression '<' expression + * | expression '>' expression + * | expression '<=' expression + * | expression '>=' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +a.s < 10; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fabab8939e06fff896833d0f6307853370325bd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_returnStatement.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +class S { + s: number = 0; +} +function A(S1: S) { + let a: S = {s: 5}; + return a; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..39982c014a0b62eff459a096d0329810aaf2a88e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_separateModuleDeclaration.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +class S { + s: number = 0; +} +let a: S = {s: 5}; +console.info('a: ' + a); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_shiftExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_shiftExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee3c951ea44878eef08e57b44bec74f417c3c343 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_shiftExpression.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.23 + * shiftExpression: + * expression '<<' expression + * | expression '>>' expression + * | expression '>>>' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +a.s << 10; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_spreadExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_spreadExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..586f39de57c279bcb421be9513aa3c7cb7bbd67c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_spreadExpression.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.6 + * spreadExpression: + * '...' expression + * ; + */ + +class Person { + name: number[] = []; + age: number = 0; +} +let array1: number[] = [1, 2, 3]; +let array2: number[] = [4, 5]; +let b : Person = {name: [...array1, ...array2], age: 25} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_statement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_statement.ets new file mode 100644 index 0000000000000000000000000000000000000000..7617ec2413f85a973f4b2a56bb9d3c34926f9793 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_statement.ets @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throw Statement + * | tryStatement + * ; + */ + +class S { + s: string = ''; +} +let a: S = {s: 'Alice'}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_stringInterpolation.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_stringInterpolation.ets new file mode 100644 index 0000000000000000000000000000000000000000..8f4db6325fe5e276e9e91f36d1cebbba2124ae89 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_stringInterpolation.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.31 + * stringInterpolation: + * ' ` ' (BacktickCharacter | embeddedExpression)* ' ` ' + * ; + */ + +class S { + s: string = ''; +} +let a: S = {s: 'Alice'}; +`Hello, my name is ${a}.`; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_switchStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_switchStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..2de3e547004687ec632afbe5524ecc771483fa3c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_switchStatement.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.13 + * switchStatement: + * (identifier ':')? 'switch' '(' expression ')' switchBlock + * ; + */ + +class S { + s: int = 0; +} +let x: S = {s: 5}; +switch (x.s) { + case 5: break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_thisExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_thisExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..14abd71cee949d2a009f3868dedcf921a5b49b3f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_thisExpression.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.8 + * thisExpression: + * 'this' + * ; + */ + +class ThisExample { + public field: number; + constructor() { + this.field = 1; + } +} +let b : ThisExample = {field: 8} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f7a0f24b3794ec9c2adca8533999f2faa9189c4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_throwStatement.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +class S { + s: number = 0; +} +let x: S = {s: 5}; +throw new Error("error" + x); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ba121f1c23a7be926e140da2d666b1fe13daf73 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_topDeclaration.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +class S { + s: number = 0; +} +export let a: S = {s: 5}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..5988351b233de3b69b642eeebffed696364e86a6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_topLevelStatements.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement * + * ; + */ + +class S { + s: number = 0; +} +let a: S = {s: 56}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..0bdc229b893caccd5513150ae67eda4f8c06ca46 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_trailingLambdaCall.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + methodTwo(arg: T, callback: (result: T) => void): void { + const result = arg; + callback(result); + } +} +class B {} +let a = new A(); +let b = new B(); +a.methodTwo(b) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..805a29ae58d535491207fcdadb08ab5c1e7109c1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_tryStatement.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +class S { + s: number = 0; +} + +function processOne(a: number): number { + try { + let x: S = {s: 5}; + return x.s; + } catch (error) { + return -1; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_typeOfExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_typeOfExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..fadc748981023836562d29a9e625bc02457e0ca2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_typeOfExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.17 + * typeOfExpression: + * 'typeof' expression + * ; + */ + +class S { + s: number = 0; +} +let a: S = {s: 5}; +typeof a; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_unaryExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_unaryExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..590e503dd2a0861a1818c7e180f60d24f9af119d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_unaryExpression.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 7.20 + * unaryExpression: + * expression '++' + * | expression '--' + * | '++' expression + * | '--' expression + * | '+' expression + * | '-' expression + * | '~' expression + * | '!' expression + * ; + */ + +class S { + s: number = 0; +} +let a = new S; +!a; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_whileStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_whileStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..70c8f96d2881f4f829186c551ca02f43da22bdbd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/objectLiteral/objectLiteral_whileStatement.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5 + * objectLiteral: + * '{' valueSequence? '}' + * ; + * + * CHAPTER 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + */ + +class S { + s: string = ''; +} +let a: S = {s: 'Alice'}; +while(a) { + a = {s: '1'}; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_assignmentExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_assignmentExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..5303085a9236b5f52a246a5b06d0ae9d5c8a0dfd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_assignmentExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.29 + * assignmentExpression: + * lhsExpression assignmentOperator rhsExpression + * ; + */ + +let s: Record = {"John": 1}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_awaitExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_awaitExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e064ad60868b57f0d1c12dc4268d2f6e585c97b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_awaitExpression.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 17.16.2 + * awaitExpression: + * 'await' expression + * ; + */ + +function foo(): Promise> { + return new Promise>((resolve, reject) => { + let s: Record = {"John": 1}; + resolve(s); + }); +} +const res = await foo(); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_castExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_castExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..6286d4e56be688e2e8765827f69308983314453e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_castExpression.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.15 + * castExpression: + * expression 'as' type + * ; + */ + +class X { + name: Record = { + "John": 1, + "Mary": 2, + }; +} + +let x1 : X = {name: {"John": 1}}; +let ob : Object = x1 as Object; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_classInitializer.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_classInitializer.ets new file mode 100644 index 0000000000000000000000000000000000000000..eace300cb1d58499b6e4b52033aa96d3335230ad --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_classInitializer.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class ExampleClass1 { + static s1: Record = {"John": 1, "Mary": 21}; + static s2: Record = {"John": 1}; + static initializerBlock() { + if (ExampleClass1.s1 == ExampleClass1.s2) { + ExampleClass1.s1 = {"John": 1}; + } + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalAndExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalAndExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd40aa6c1fbff6a6733ac06449dc973b3b9813f8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalAndExpression.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.27 + * conditionalAndExpression: + * expression '&&' expression + * ; + */ + +let s: Record = {"John": 1}; +let s1: Record = {"John": 1}; +s && s1; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9909e0a7712e7ca63080c707860528cfae826e8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalExpression.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.30 + * conditionalExpression: + * expression '?' expression ':' expression + * ; + */ + +let s: Record = {"John": 1}; +let s1: Record = {"Amy": 12}; +(7 > 5) ? s : s1; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalOrExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalOrExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..3b03bf8f065703f49cf679160ea8846821069607 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_conditionalOrExpression.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.28 + * conditionalOrExpression: + * expression '||' expression + * ; + */ + +let s: Record = {"John": 1}; +let s1: Record = {"John": 1}; +s || s1; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_constantExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_constantExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b62c4b2a0eb3a8f61bedad9bc7c12b5b55d085c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_constantExpression.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.33 + * constantExpression: + * expression + * ; + */ + +const s: Record = {"John": 1}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_ensureNotNullishExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_ensureNotNullishExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9c9b91795b89ec42847b2d162e5b5eebc6ba47b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_ensureNotNullishExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.18 + * ensureNotNullishExpression: + * expression '!' + * ; + */ + +let s: Record = {"John": 1}; +s!; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_equalityExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_equalityExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..489e738c892c11380afdccc77cb136c2a68aee64 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_equalityExpression.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.25 + * equalityExpression: + * expression ('==' | '===' | '!=' | '!==') expression + * ; + */ + +let s: Record = {"John": 1}; +let s1: Record = {"John": 1}; +s == s1; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_fieldAccessExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_fieldAccessExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e738724ed7dac7991489ac81418310caeaa5e86 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_fieldAccessExpression.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.9 + * fieldAccessExpression: + * objectReference ('.' | '?.') identifier + * ; + */ + +class Person1 { + name: Record = { + "John": 1, + "Mary": 2, + }; +} + +let person = new Person1(); +person.name = { + "John": 1, + "Mary": 2, +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_finallyClause.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_finallyClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6bf4ee3d5d38b60b029464e2eb23e9e2e23734f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_finallyClause.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +function processOne() { + try { + } catch (error) { + } finally { + let s1: Record = {"John": 1, "Mary": 21}; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_forStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_forStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..5beb446c9c58e4031ec953ec6ad3466da6c84d2f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_forStatement.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.8 + * forStatement: + * 'for' '(' forInit? ';' forContinue? ';' forUpdate? ')' statement + * ; + */ + +let s1: Record = {"John": 1}; +let i: number = 1; +for (; i < 10 && s1; i++) { + if (true) { + break; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_functionCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_functionCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..7662bebc4e4a2b9b94d1064c9b1402a0691d64ee --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_functionCallExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.11 + * functionCallExpression: + * expression ('?.' | typeArguments)? arguments block? + * ; + */ + +function func1(x: Record): number { + return 0; +} + +func1({"John": 1}); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_functionTypeWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_functionTypeWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..528964c2eedb3e88bed6b3a4cd3b34a3f10ea061 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_functionTypeWithReceiver.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 17.12.4 + * functionTypeWithReceiver: + * '(' receiverParameter(','ftParameterList)?')'ftReturnType + * ; + */ + +type F = (a: Record) => void; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_ifStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_ifStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..896ab6d06832e32357abcec445e34c015bf8bf43 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_ifStatement.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.5 + * ifStatement: + * 'if' '(' expression ')' thenStatement + * ('else' elseStatement)? + * ; + */ + +let s1: Record = {"John": 1}; +let s2: Record = {"John": 2}; +if (s1 == s2) { + console.log("s1 == s2"); +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_indexingExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_indexingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..95678262f58cbd8ae3a823f39d796e5e4d38f97e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_indexingExpression.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.12 + * indexingExpression: + * expression ('?.')? '[' expression ']' + * ; + */ + +let a = [1, 2, 3, 4, 5]; +let map: Record = { + "John": a[0], + "Mary": a[1], +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_initializerBlock.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_initializerBlock.ets new file mode 100644 index 0000000000000000000000000000000000000000..fa909d3824f1d2d3756f49dd3873d0dfd4e99782 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_initializerBlock.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 15.10 + * initializerBlock: + * 'static' block + * ; + */ + +class Test { + static initializerBlock() { + let sum: Record = {"John": 1, "Mary": 21}; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_instanceOfExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_instanceOfExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..10def05220e8d3b24fe2879bdeeeba846fed253b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_instanceOfExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.16 + * instanceOfExpression: + * expression 'instanceof' type + * ; + */ + +let a: Record = {"John": 1}; +a instanceof object; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_lambdaExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_lambdaExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..d592090ee7f7727c3e53a3900416ce78987ef81d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_lambdaExpression.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.32 + * lambdaExpression: + * annotationUsage? ('async'|typeParameters)? lambdaSignature '=>' lambdaBody + * ; + */ + +let result = async (x: number, y: number, z?: number): Promise => { + let s: Record = {"John": 1}; + return s; +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_lambdaExpressionWithReceiver.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_lambdaExpressionWithReceiver.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ae883e6116fa995e8ba215cb21d9235406f3647 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_lambdaExpressionWithReceiver.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 17.12.5 + * lambdaExpressionWithReceiver: + * annotationUsage? typeParameters? + * '(' receiverParameter (',' lambdaParameterList)? ')' + * returnType? throwMark? '=>' lambdaBody + * ; + */ + +class A {} +let result4 = (this: A): Record => { + let a: Record = {"John": 1, "Mary": 21}; + return a; +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_loopStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_loopStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca9d4138a3a996fbd248cfe191150bb7fac5081c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_loopStatement.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.6 + * loopStatement: + * (identifier ':')? + * whileStatement + * | doStatement + * | forStatement + * | forOfStatement + * ; + */ + +let s1: Record = {"John": 1}; +let s2: Record = {"John": 2}; +while(s1 == s2) { + break; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_methodCallExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_methodCallExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e7497d223374be95603d17d0bec3b4b1b2070a2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_methodCallExpression.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.10 + * methodCallExpression: + * objectReference ('.' | '?.') identifier typeArguments? arguments block? + * ; + */ + +class Person2 { + name: Record = { + "John": 1, + "Mary": 2, + }; + setName(name: Record): void { + this.name = name; + } +} + +let person = new Person2(); +person.setName({ + "John": 1, + "Mary": 2, +}); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_namespaceDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_namespaceDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..823891950806d3a1009275927f0ed30e55342702 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_namespaceDeclaration.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 13.8 + * namespaceDeclaration: + * 'namespace' qualifiedName + * '{' topDeclaration* initializerBlock? topDeclaration* '}' + * ; + */ + +namespace NS1 { + let a: Record = {"John": 1, "Mary": 21}; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_newArrayInstance.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_newArrayInstance.ets new file mode 100644 index 0000000000000000000000000000000000000000..94928529c5b3dbfc3d22c406e24d6c5624ff455c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_newArrayInstance.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 17.3 + * newArrayInstance: + * 'new' arrayElementType dimensionExpression+ (arrayElement)? + * ; + */ + +let a = new Record[1]; +a[0] = {"John": 1, "Mary": 21}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_newExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_newExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb816878037d9dbd4242586b2ee90aed89c7ebb0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_newExpression.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.14 + * newExpression: + * newClassInstance + * | newArrayInstance + * ; + */ + +class D { + constructor(p: Record) {} +} + +new D({"John": 1}); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_nullishCoalescingExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_nullishCoalescingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..0366abb8a5932b85e95b86f511ec2a4900e50f02 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_nullishCoalescingExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.19 + * nullishCoalescingExpression: + * expression '??' expression + * ; + */ + +let s: Record = {"John": 1}; +null ?? s; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_parenthesizedExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_parenthesizedExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..ab0aa15a0d959ccfcb3c2f617dd1edc9937736dd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_parenthesizedExpression.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.7 + * parenthesizedExpression: + * '(' expression ')' + * ; + */ + +let map: Record = { + "John": (5 + 3), + "Mary": (1 + 3), +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_returnStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_returnStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..1dfbc6cf67b31bdaf7778cdeb41bfe717f357b01 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_returnStatement.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.12 + * returnStatement: + * 'return' expression? + * ; + */ + +function add() { + let s1: Record = {"John": 1, "Mary": 21}; + return s1; +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_separateModuleDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_separateModuleDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..30968df46d87f01845800c92c128cd8123566ab3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_separateModuleDeclaration.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 13.1 + * separateModuleDeclaration: + * importDirective* (topDeclaration | topLevelStatements | exportDirective)* + * ; + */ + +let a: Record = {"John": 1, "Mary": 21}; +console.info('a: ' + a); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_spreadExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_spreadExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..192d2447fff7749d41ade8c7ba3ad9a77d42bd1d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_spreadExpression.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.6 + * spreadExpression: + * '...' expression + * ; + */ + +let array1 = [1, 2, 3]; +let array2 = [4, 5]; +let array3 = [...array1, ...array2]; +let map: Record = { + "John": array3, + "Mary": array2, +}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_statement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_statement.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9839214d29cbd647b2b756e5283d5a7728a2f63 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_statement.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8 + * statement: + * expressionStatement + * | block + * | localDeclaration + * | ifStatement + * | loopStatement + * | breakStatement + * | continueStatement + * | returnStatement + * | switchStatement + * | throw Statement + * | tryStatement + * ; + */ + +let s: Record = {"John": 1}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_stringInterpolation.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_stringInterpolation.ets new file mode 100644 index 0000000000000000000000000000000000000000..8aa9e3c41a69e6c624409028d1801846c7459e03 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_stringInterpolation.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.31 + * stringInterpolation: + * ' ` ' (BacktickCharacter | embeddedExpression)* ' ` ' + * ; + */ + +let s: Record = {"John": 1}; +`Hello, my name is ${s}.`; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_thisExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_thisExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..19b7ea1dd90e25cd56fc15f4e3edb361e2b4e547 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_thisExpression.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.8 + * thisExpression: + * 'this' + * ; + */ + +class ThisExample { + public map: Record = { + "John": 1, + "Mary": 2, + }; + constructor() { + this.map = { + "John": 3, + "Mary": 4, + }; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_throwStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_throwStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..fc3bb413301c3773e909d9ab1c2d3c97cdbe9998 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_throwStatement.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +let s1: Record = {"John": 1, "Mary": 21}; +throw new Error("error" + s1); diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_topDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_topDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..bc05303de09f578b111de4cf0bd40af8ad63322b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_topDeclaration.ets @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 13.7 + * topDeclaration: + * ('export' 'default'?)? + * annotationUsage? + * ( typeDeclaration + * | variableDeclarations + * | constantDeclarations + * | functionDeclaration + * | functionWithReceiverDeclaration + * | accessorWithReceiverDeclaration + * | namespaceDeclaration + * ) + * ; + */ + +export let a: Record = {"John": 1, "Mary": 21}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_topLevelStatements.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_topLevelStatements.ets new file mode 100644 index 0000000000000000000000000000000000000000..063b5e60133dcd8dc1a16a6ef661007c7788dd9b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_topLevelStatements.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 13.10 + * topLevelStatements: + * statement * + * ; + */ + +let a: Record = {"John": 1, "Mary": 21}; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_trailingLambdaCall.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_trailingLambdaCall.ets new file mode 100644 index 0000000000000000000000000000000000000000..37f396bf32f6e61c39abb0bcff001bcdde46bfbb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_trailingLambdaCall.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 17.13 + * trailingLambdaCall: + * ( objectReference '.' identifier typeArguments? + * | expression ('?.' | typeArguments)? + * ) + * arguments block + * ; + */ + +class A { + methodTwo(arg: T, callback: (result: T) => void): void { + const result = arg; + callback(result); + } +} +let a = new A(); +a.methodTwo>({"John": 1, "Mary": 21}) {} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_tryStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_tryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..e4d9b92b471bb56e077817490402f52068d117ec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_tryStatement.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + */ + +function processOne(): Record { + try { + let s1: Record = {"John": 1, "Mary": 21}; + const res = s1; + return res; + } catch (error) { + return {"John": 1}; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_typeOfExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_typeOfExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..5be0a2d89fb93f74cea8963a7490c9668690f1c7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_typeOfExpression.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.17 + * typeOfExpression: + * 'typeof' expression + * ; + */ + +let s: Record = {"John": 1}; +typeof s; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_unaryExpression.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_unaryExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca601a3302567ab6c0da89bf3b0c26743a904504 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_unaryExpression.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 7.20 + * unaryExpression: + * expression '++' + * | expression '--' + * | '++' expression + * | '--' expression + * | '+' expression + * | '-' expression + * | '~' expression + * | '!' expression + * ; + */ + +let s: Record = {"John": 1}; +!s; diff --git a/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_whileStatement.ets b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_whileStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f519d73ef1346894136e66a517382c85d2e1696 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec_orthogonality/7_expressions/recordLiteral/recordLiteral_whileStatement.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * CHAPTER 7.5.3 + * recordLiteral: + * '{' keyValueSequence? '}' + * ; + * + * CHAPTER 8.7 + * whileStatement: + * 'while' '(' expression ')' statement + * ; + */ + +let s1: Record = {"John": 1}; +let s2: Record = {"John": 2}; +while(s1 !== s2) { + s1 = s2; +}