diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BinaryDigit.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BinaryDigit.ets new file mode 100644 index 0000000000000000000000000000000000000000..f108270a586ff185b3d72d79e90dab5b7c43cf49 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BinaryDigit.ets @@ -0,0 +1,24 @@ +/* + * 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 2.9.2 + * BinaryDigit: + * [0-1] + * ; + */ + +0b0; +0b1; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BinaryIntegerLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BinaryIntegerLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..e3f42e0dc36d899392377076d44f2838efa3cc51 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/BinaryIntegerLiteral.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 2.9.2 + * BinaryIntegerLiteral: + * '0'[bB]( BinaryDigit + * |BinaryDigit(BinaryDigit|'_')* BinaryDigit) + * ; + * + * BinaryDigit: + * [0-1] + * ; + */ + +0b0; +0b11; +0b1_0_1; +0b1_011; +0b11011; +0b111_1; +0b11_11; +0B0; +0B11; +0B1_0_1; +0B1_011; +0B11011; +0B111_1; +0B11_11; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalDigit.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalDigit.ets new file mode 100644 index 0000000000000000000000000000000000000000..332f31326500389b6aa35b07299d3984ed81ccef --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalDigit.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 2.9.2 + * DecimalDigit: + * [0-9] + * ; + */ + +1_0; +1_1; +1_2; +1_3; +1_4; +1_5; +1_6; +1_7; +1_8; +1_9; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalDigitNotNull.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalDigitNotNull.ets new file mode 100644 index 0000000000000000000000000000000000000000..1203d92c8e294a2feeff9bf1d9e140b0a72ba6df --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalDigitNotNull.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 2.9.2 + * DecimalDigitNotNull: + * [1-9] + * ; + */ + +1234; +2234; +3234; +4234; +5234; +6234; +7234; +8234; +9234; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalIntegerLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalIntegerLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a52f474b1dfba541435c095f7d1d888762b8df0 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/DecimalIntegerLiteral.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 2.9.2 + * DecimalIntegerLiteral: + * '0' + * |DecimalDigitNotNull ('_'?DecimalDigit)* + * ; + * + * DecimalDigit: + * [0-9] + * ; + * + * DecimalDigitNotNull: + * [1-9] + * ; + */ + +0; +2; +1_2_4_6; +1_3_89; +2_699; +45_7_3; +235_5; +16_58; +9_25_6; +1234; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/ExponentPart.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/ExponentPart.ets new file mode 100644 index 0000000000000000000000000000000000000000..0de7ddbd21778b0d010bbadf150eec86981d70cf --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/ExponentPart.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 2.9.3 + * ExponentPart: + * [eE][+-]?DecimalIntegerLiteral + * ; + * + * DecimalIntegerLiteral: + * '0' + * |DecimalDigitNotNull ('_'?DecimalDigit)* + * ; + */ + +3e2; +3e+2; +3e-2; +3E2; +3E+2; +3E-2; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/FloatLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/FloatLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c7413cdaa652922bff9aaafb6c6d012b71202aa --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/FloatLiteral.ets @@ -0,0 +1,51 @@ +/* + * 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 2.9.3 + * FloatLiteral: + * DecimalIntegerLiteral'.' FractionalPart? ExponentPart?FloatTypeSuffix? + * |'.'FractionalPart ExponentPart? FloatTypeSuffix? + * | DecimalIntegerLiteral ExponentPart FloatTypeSuffix? + * ; + * + * ExponentPart: + * [eE][+-]?DecimalIntegerLiteral + * ; + * + * FractionalPart: + * DecimalDigit + * | DecimalDigit (DecimalDigit |'_')* DecimalDigit + * ; + * + * FloatTypeSuffix: + * 'f' + * ; + */ + +3.; +63.e+10; +4.4; +22.83E-4; +3.f; +3.33_33f; +66.e8f; +24.6_777E9f; +.3; +.4e6; +.4e6f; +.8f; +3e2; +3e2f; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/FractionalPart.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/FractionalPart.ets new file mode 100644 index 0000000000000000000000000000000000000000..10ff85e3318bf49d24f0db6c8c71abe963050609 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/FractionalPart.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 2.9.3 + * FractionalPart: + * DecimalDigit + * | DecimalDigit (DecimalDigit |'_')* DecimalDigit + * ; + * + * DecimalDigit: + * [0-9] + * ; + */ + +3.3; +4.68; +4.6_6_8; +4.6_648; +4.63648; +4.636_8; +4.63_48; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/HexDigit.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/HexDigit.ets new file mode 100644 index 0000000000000000000000000000000000000000..6bd3e454a2870792452c01b42ecac37d4721cc5a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/HexDigit.ets @@ -0,0 +1,44 @@ +/* + * 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 2.9.2 + * HexDigit: + * [0-9a-fA-F] + * ; + */ + +0x0; +0x1; +0x2; +0x3; +0x4; +0x5; +0x6; +0x7; +0x8; +0x9; +0xa; +0xb; +0xc; +0xd; +0xe; +0xf; +0xA; +0xB; +0xC; +0xD; +0xE; +0xF; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/HexIntegerLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/HexIntegerLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..8eb4829da1398d68dd2a8144f442cdd8776b2a5a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/HexIntegerLiteral.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 2.9.2 + * HexIntegerLiteral: + * '0'[xX] (HexDigit + * |HexDigit (HexDigit|'_')* HexDigit + * ) + * ; + * + * HexDigit: + * [0-9a-fA-F] + * ; + */ + +0xF; +0xAa; +0xA_8_a; +0xA_8da; +0xA38da; +0xA38_a; +0xA3_da; +0XF; +0XAa; +0XA_8_a; +0XA_8da; +0XA38da; +0XA38_a; +0XA3_da; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Identifier.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Identifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..5026ff6bfbb8a4b93075bc207e8600760bd38458 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Identifier.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 2.6 + * Identifier: + * IdentifierStart IdentifierPart* + * ; + * + * IdentifierStart: + * UnicodeIDStart + * |'$' + * |'_' + * |'\\'EscapeSequence + * ; + * + * IdentifierPart: + * UnicodeIDContinue + * |'$' + * |ZWNJ + * |ZWJ + * |'\\'EscapeSequence + * ; + */ + +let $ = 1; +let $__$ = 1; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IdentifierPart.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IdentifierPart.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd2454f88c02ca3f0ab0e2ef4c72bddcf2f07dcb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IdentifierPart.ets @@ -0,0 +1,54 @@ +/* + * 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 2.6 + * IdentifierPart: + * UnicodeIDContinue + * |'$' + * |ZWNJ + * |ZWJ + * |'\\'EscapeSequence + * ; + * + * UnicodeIDContinue + * :UnicodeIDStart + * |UnicodeDigit + * |'\u200C' + * |'\u200D' + * ; + * + * EscapeSequence: + * ['"bfnrtv0\\] + * | 'x' HexDigit HexDigit + * | 'u' HexDigit HexDigit HexDigit HexDigit + * | 'u' '{' HexDigit+ '}' + * | ~[1-9xu\r\n] + * ; + * + * ZWJ: + * '\u200C' + * ; + * + * ZWNJ: + * '\u200D' + * ; + */ + +let aVar = 2; +let a$ = 2; +let a\u200C = 2; +let a\u200D = 2; +let a\u0061 = 2; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IdentifierStart.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IdentifierStart.ets new file mode 100644 index 0000000000000000000000000000000000000000..56a176784ce9570c4df53c54954b30c08058f4d4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IdentifierStart.ets @@ -0,0 +1,43 @@ +/* + * 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 2.6 + * IdentifierStart: + * UnicodeIDStart + * |'$' + * |'_' + * |'\\'EscapeSequence + * ; + * + * UnicodeIDStart + * :Letter + * |['$'] + * |'\\'UnicodeEscapeSequence + * ; + * + * EscapeSequence: + * ['"bfnrtv0\\] + * | 'x' HexDigit HexDigit + * | 'u' HexDigit HexDigit HexDigit HexDigit + * | 'u' '{' HexDigit+ '}' + * | ~[1-9xu\r\n] + * ; + */ + +let myVar = 1; +let $Var = 1; +let _Var = 1; +let \u0062Var = 1; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IntegerLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IntegerLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9de23eaff521b46e384764f3e697f5eaa27a4a3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/IntegerLiteral.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 2.9.2 + * IntegerLiteral: + * DecimalIntegerLiteral + * |HexIntegerLiteral + * |OctalIntegerLiteral + * |BinaryIntegerLiteral + * ; + */ + +153; +0xBAD3; +0o777; +0b101; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Letter.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Letter.ets new file mode 100644 index 0000000000000000000000000000000000000000..a547ee71e69f80018e93476f2485da32063ac163 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Letter.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 2.6 + * Letter + * :UNICODE_CLASS_LU + * |UNICODE_CLASS_LL + * |UNICODE_CLASS_LT + * |UNICODE_CLASS_LM + * |UNICODE_CLASS_LO + * ; + */ + +let Abc = 4; +let abc = 4; +let Ljbc = 4; +let ʰbc = 4; +let 诶bc = 4; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Literal.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Literal.ets new file mode 100644 index 0000000000000000000000000000000000000000..20fbe41de5832900434662914f556214137d049e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/Literal.ets @@ -0,0 +1,48 @@ +/* + * 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 2.9 + * Literal: + * IntegerLiteral + * |FloatLiteral + * |BigIntLiteral + * |BooleanLiteral + * |StringLiteral + * |MultilineStringLiteral + * |NullLiteral + * |UndefinedLiteral + * |CharLiteral + * ; + * + * NullLiteral: + * 'null' + * ; + * + * UndefinedLiteral: + * 'undefined' + * ; + */ + +42; +3.14159; +1234567890123456789012345678901234567890n; +true; +"Hello, ArkTS!"; +`This is a +multi-line string literal.`; +null; +undefined; +'A'; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/OctalDigit.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/OctalDigit.ets new file mode 100644 index 0000000000000000000000000000000000000000..453fcebacc978162e04d83074e3f7ae7f1a8b6bf --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/OctalDigit.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 2.9.2 + * OctalDigit: + * [0-7] + * ; + */ + +0o0; +0o1; +0o2; +0o3; +0o4; +0o5; +0o6; +0O7; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/OctalIntegerLiteral.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/OctalIntegerLiteral.ets new file mode 100644 index 0000000000000000000000000000000000000000..45ae3b7a959defd575261b5e0b04e0c5e0763423 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/OctalIntegerLiteral.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 2.9.2 + * OctalIntegerLiteral: + * '0'[oO]( OctalDigit + * |OctalDigit(OctalDigit|'_')* OctalDigit) + * ; + * + * OctalDigit: + * [0-7] + * ; + */ + +0o1; +0o13; +0o1_6_7; +0o1_647; +0o13647; +0o136_7; +0o13_47; +0O1; +0O13; +0O1_6_7; +0O1_647; +0O13647; +0O136_7; +0O13_47; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeEscapeSequence.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeEscapeSequence.ets new file mode 100644 index 0000000000000000000000000000000000000000..e4d44b6ca63803df35e559c9568425a065087acc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeEscapeSequence.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 2.6 + * UnicodeEscapeSequence: + * 'u' HexDigit HexDigit HexDigit HexDigit + * |'u''{' HexDigit HexDigit+ '}' + * ; + * + * HexDigit: + * [0-9a-fA-F] + * ; + */ + +let \u00E9Var = 1; +let \u{EF}Var = 1; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeIDContinue.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeIDContinue.ets new file mode 100644 index 0000000000000000000000000000000000000000..1997fedaa9192eec192d29fec0b1332860d925c3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeIDContinue.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 2.6 + * UnicodeIDContinue + * :UnicodeIDStart + * |UnicodeDigit + * |'\u200C' + * |'\u200D' + * ; + * + * UnicodeIDStart + * :Letter + * |['$'] + * |'\\'UnicodeEscapeSequence + * ; + * + * UnicodeDigit + * :UNICODE_CLASS_ND + * ; + */ + +let $$ = 3; +let $\u0967 = 3; +let $\u200C = 3; +let $\u200D = 3; diff --git a/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeIDStart.ets b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeIDStart.ets new file mode 100644 index 0000000000000000000000000000000000000000..8900011e299d45010c9b7bfd5daf8763f0650087 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/2_lexical_elements/UnicodeIDStart.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 2.6 + * UnicodeIDStart + * :Letter + * |['$'] + * |'\\'UnicodeEscapeSequence + * ; + * + * Letter + * :UNICODE_CLASS_LU + * |UNICODE_CLASS_LL + * |UNICODE_CLASS_LT + * |UNICODE_CLASS_LM + * |UNICODE_CLASS_LO + * ; + * + * UnicodeEscapeSequence: + * 'u' HexDigitHexDigitHexDigitHexDigit + * |'u''{'HexDigitHexDigit+'}' + * ; + */ + +let myVar = 1; +let $Var = 1; +let \u00E9Var = 1; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/additiveExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/additiveExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d1c4aafd72b023e3b428679169fdf15fb482195 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/additiveExpression.ets @@ -0,0 +1,25 @@ +/* + * 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.22 + * additiveExpression: + * expression '+' expression + * | expression '-' expression + * ; + */ + +6 + 7; +7 - 6; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/as.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/as.ets new file mode 100644 index 0000000000000000000000000000000000000000..192c0b368e930dc417ca646c08324e423680065c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/as.ets @@ -0,0 +1,26 @@ +/* + * 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.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/7_expressions/assignmentExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/assignmentExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..fcff30f2fee1728690bf96177d1291299ae27597 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/assignmentExpression.ets @@ -0,0 +1,51 @@ +/* + * 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.29 + * assignmentExpression: + * lhsExpression assignmentOperator rhsExpression + * ; + * + * assignmentOperator: + * '=' + * | '+=' | '-=' | '*=' | '=' | '%=' + * | '<<=' | '>>=' | '>>>=' + * | '&=' | '|=' | '^=' + * ; + * + * lhsExpression: + * expression + * ; + * + * rhsExpression: + * expression + * ; + */ + +let a7 = 5; +let b7 = 3; +let c7 = -5; +a7 = 3; +a7 += b7; +a7 -= b7; +a7 *= b7; +a7 /= b7; +a7 %= b7; +a7 <<= b7; +a7 >>= b7; +c7 >>>= b7; +a7 |= b7; +a7 ^= b7; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/bitwiseAndLogicalExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/bitwiseAndLogicalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..f98a1c33a09d3cbbf9d7d5418f63023f0ba4976e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/bitwiseAndLogicalExpression.ets @@ -0,0 +1,27 @@ +/* + * 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.26 + * bitwiseAndLogicalExpression: + * expression '&' expression + * | expression '^' expression + * | expression '|' expression + * ; + */ + +5 & 3; +5 ^ 3; +5 | 3; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalAndExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalAndExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..c861a0a439f66f6d134088a79925ca205476cadc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalAndExpression.ets @@ -0,0 +1,23 @@ +/* + * 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.27 + * conditionalAndExpression: + * expression '&&' expression + * ; + */ + +true && true; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..fbf78092e8cbbcee9f04dcd52f88811d1eca4226 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalExpression.ets @@ -0,0 +1,23 @@ +/* + * 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.30 + * conditionalExpression: + * expression '?' expression ':' expression + * ; + */ + +(7 > 5) ? 7 : 5; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalOrExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalOrExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..84c7a1b875dff289cc9a69826f6157e784f4bbac --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/conditionalOrExpression.ets @@ -0,0 +1,23 @@ +/* + * 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.28 + * conditionalOrExpression: + * expression '||' expression + * ; + */ + +true || false; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/ensureNotNullishExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ensureNotNullishExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..487e8bce65d52272ce6b0109b64148224415531f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/ensureNotNullishExpression.ets @@ -0,0 +1,24 @@ +/* + * 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.18 + * ensureNotNullishExpression: + * expression '!' + * ; + */ + +let value: number[] = [1]; +value!.length; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/equalityExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/equalityExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..69f0b780c43d4624660b1d6867089eb8e9ba8e8d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/equalityExpression.ets @@ -0,0 +1,26 @@ +/* + * 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.25 + * equalityExpression: + * expression ('==' | '===' | '!=' | '!==') expression + * ; + */ + +5 == 5; +null === undefined; +5 != 6; +null !== undefined; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/instanceof.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/instanceof.ets new file mode 100644 index 0000000000000000000000000000000000000000..f322a3e76d4276c167fa4a42160c04baee78398d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/instanceof.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.16 + * instanceOfExpression: + * expression 'instanceof' type + * ; + */ + +// 父类 Animal +class Animal { +} + +// 子类 Dog +class Dog extends Animal { +} + +// 创建 Animal 和 Dog 的实例 +let animal: Animal = new Animal(); +let dog : Dog = new Dog(); +animal instanceof Animal; +dog instanceof Dog; +dog instanceof Animal; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/multiplicativeExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/multiplicativeExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..d5017292a5083702cb62e7af0eb3224d1b058be4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/multiplicativeExpression.ets @@ -0,0 +1,27 @@ +/* + * 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.21 + * multiplicativeExpression: + * expression '*' expression + * | expression '/' expression + * | expression '%' expression + * ; + */ + +5 * 10; +10 / 5; +10 % 3; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/nullishCoalescingExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/nullishCoalescingExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f41a5dbbb0e6c20330a0f960077b882f24d7f13 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/nullishCoalescingExpression.ets @@ -0,0 +1,23 @@ +/* + * 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.19 + * nullishCoalescingExpression: + * expression '??' expression + * ; + */ + +null ?? 42; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/relationalExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/relationalExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..b418e875993d00fac9afaa8490d5037c36f1f718 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/relationalExpression.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.24 + * relationalExpression: + * expression '<' expression + * | expression '>' expression + * | expression '<=' expression + * | expression '>=' expression + * ; + */ + +5 < 10; +10 > 5; +5 + 10 <= 15; +10 + 15 >= 5; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/shiftExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/shiftExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..f8db8cf8319d41a5a14fc6644109a73077caf4ea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/shiftExpression.ets @@ -0,0 +1,27 @@ +/* + * 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.23 + * shiftExpression: + * expression '<<' expression + * | expression '>>' expression + * | expression '>>>' expression + * ; + */ + +16 << 2; +16 >> 2; +16 >>> 2; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/stringInterPolation.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/stringInterPolation.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4e7e8724dbfc6d3f7ea0bba7d58fc5574901f67 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/stringInterPolation.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.31 + * stringInterpolation: + * ' ` ' (BacktickCharacter | embeddedExpression)* ' ` ' + * ; + * + * BacktickCharacter: + * ~['\\\r\n] + * | '\\' EscapeSequence + * | LineContinuation + * ; + * + * embeddedExpression: + * '${' expression '}' + * ; + */ + +let name = "Alice"; +let age = 30; +``; +`This is a broken backslash: \\`; +`Hello, my name is ${name} and I am ${age} years old.`; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/typeof.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/typeof.ets new file mode 100644 index 0000000000000000000000000000000000000000..154a8307e4d37961053c5f055d7ed2fb4af3fa85 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/typeof.ets @@ -0,0 +1,24 @@ +/* + * 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.17 + * typeOfExpression: + * 'typeof' expression + * ; + */ + +let num = 42; +typeof num; diff --git a/ets2panda/test/ast/compiler/ets/spec/7_expressions/unaryExpression.ets b/ets2panda/test/ast/compiler/ets/spec/7_expressions/unaryExpression.ets new file mode 100644 index 0000000000000000000000000000000000000000..f66f841a4061c2b585430674c6a6e96696325dc4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/7_expressions/unaryExpression.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.20 + * unaryExpression: + * expression '++' + * | expression '--' + * | '++' expression + * | '--' expression + * | '+' expression + * | '-' expression + * | '~' expression + * | '!' expression + * ; + */ + +let a = 5; +a++; +a--; +++a; +--a; ++5; +-5; +~1; +!1; diff --git a/ets2panda/test/ast/compiler/ets/spec/8_statements/CatchClauses.ets b/ets2panda/test/ast/compiler/ets/spec/8_statements/CatchClauses.ets new file mode 100644 index 0000000000000000000000000000000000000000..70195c8374d501f85c420dcd5bea5cd4754c0647 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/8_statements/CatchClauses.ets @@ -0,0 +1,67 @@ +/* + * 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 8.15 + * catchClauses: + * typedCatchClause* catchClause? + * ; + * + * catchClause: + * 'catch' '(' identifier ')' block + * ; + * + * typedCatchClause: + * 'catch' '(' identifier ':' typeReference ')' block + * ; + */ + +function processOne(a: number): number { + try { + const res = checkInput(a); + return res; + } catch (error: Error) { + return 0; + } +} + +function processTwo(a: number): number { + try { + const res = checkInput(a); + return res; + } catch (error: Error) { + return 0; + } catch (error) { + return -1; + } +} + +function processThree(a: number): number { + try { + const res = checkInput(a); + return res; + } catch (error) { + return -1; + } +} + +function checkInput(input: number): number { + if (input < 0) { + throw new Error(); + } else if (input == 0) { + throw new Error("input is 0"); + } + return input; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/8_statements/ThrowStatement.ets b/ets2panda/test/ast/compiler/ets/spec/8_statements/ThrowStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..44a92bcf091729fa5850453ba859329acad71dfa --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/8_statements/ThrowStatement.ets @@ -0,0 +1,23 @@ +/* + * 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 8.14 + * throwStatement: + * 'throw' expression + * ; + */ + +throw new Error(); diff --git a/ets2panda/test/ast/compiler/ets/spec/8_statements/TryStatement.ets b/ets2panda/test/ast/compiler/ets/spec/8_statements/TryStatement.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d43e6ead64f7bbc7ed5cdc0efdc6337c5633cc8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/8_statements/TryStatement.ets @@ -0,0 +1,66 @@ +/* + * 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 8.15 + * tryStatement: + * 'try' block catchClauses finallyClause? + * ; + * + * catchClauses: + * typedCatchClause* catchClause? + * ; + * + * finallyClause: + * 'finally' block + * ; + * + * CHAPTER 8.15.2 + * finallyClause: + * 'finally' block + * ; + */ + +function processOne(a: number): number { + const r = new SomeResource(); + try { + const res = checkInput(a); + return res; + } catch (error) { + return -1; + } finally { + r.close(); + } +} + +function processTwo(a: number): number { + try { + const res = checkInput(a); + return res; + } catch (error) { + return -1; + } +} + +function checkInput(input: number): number { + if (input < 0) { + throw new Error(); + } + return input; +} + +class SomeResource { + close() {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/AccessModifier.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/AccessModifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6316ac8809970c043c98d9f74066481e4b6d0e9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/AccessModifier.ets @@ -0,0 +1,44 @@ +/* + * 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 9.4 + * accessModifier: + * 'private' + * | 'internal' + * | 'protected' + * | 'public' + * ; + * + * CHAPTER 9.2 + * classBodyDeclaration: + * annotationUsage? + * accessModifier? + * ( constructorDeclaration + * | classFieldDeclaration + * | classMethodDeclaration + * | classAccessorDeclaration + * ) + * ; + */ + +class ExampleClass { + private secret: string = 'This is a secret'; + internal constructor() {} + protected protectedMethod(): void {} + public get revealSecret(): string { + return this.secret; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/AccessorModifier.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/AccessorModifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ec9be7a8ac3dd5200dcf0ef9af4ff721c72b9c8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/AccessorModifier.ets @@ -0,0 +1,58 @@ +/* + * 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 9.7 + * accessorModifier: + * 'abstract' + * | 'static' + * | 'final' + * | 'override' + * ; + * + * classAccessorDeclaration: + * accessorModifier* + * ('get' identifier'('')'returnType block? + * |'set' identifier'('parameter')' block? + * ) + * ; + */ + +abstract class AbstractExample { + abstract get noReturnBlock(): number +} + +class StaticExample { + static get staticGetMethod(): number { + return 0; + } +} + +class FinalExample { + final get finalGetMethod(): number { + return 0; + } +} + +class Test { + test(x: number, y: number): number { + return x + y; + } +} +class OverrideExample extends Test { + override test(x: number, y: number): number { + return x - y; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassAccessorDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassAccessorDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..25bcf68378d905def8459170acd62b8a037abb3f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassAccessorDeclaration.ets @@ -0,0 +1,70 @@ +/* + * 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 9.7 + * classAccessorDeclaration: + * accessorModifier* + * ('get' identifier'('')'returnType block? + * |'set' identifier'('parameter')' block? + * ) + * ; + * + * accessorModifier: + * 'abstract' + * | 'static' + * | 'final' + * | 'override' + * ; + */ + +class Test { + get getMethod(): number { + return 0; + } +} +class ExampleClass1 extends Test { + override final get getMethod(): number { + return 1; + } +} + +abstract class ExampleClass2 { + abstract get getMethod(): number +} + +class ExampleClass3 { + get getMethod(): number { + return 0; + } +} + +class ExampleClass4 { + static staticValue: number = 9; + static set setMethod(newValue: number) { + ExampleClass4.staticValue = newValue; + } +} + +abstract class ExampleClass5 { + abstract set noBlock(index: number) +} + +class ExampleClass6 { + staticValue: number = 9; + set setMethod(newValue: number) { + this.staticValue = newValue; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassBody.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassBody.ets new file mode 100644 index 0000000000000000000000000000000000000000..0118671fbde4e0f7a1ac30eb2c60ce989de09409 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassBody.ets @@ -0,0 +1,95 @@ +/* + * 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 9.2 + * classBody: + * '{' + * classBodyDeclaration* classInitializer? classBodyDeclaration* + * '}' + * ; + * + * CHAPTER 9.1 + * classDeclaration: + * classModifier? 'class' identifier typeParameters? + * classExtendsClause? implementsClause? classBody + * ; + * + * CHAPTER 9.2 + * classBodyDeclaration: + * annotationUsage? + * accessModifier? + * ( constructorDeclaration + * | classFieldDeclaration + * | classMethodDeclaration + * | classAccessorDeclaration + * ) + * + * CHAPTER 9.8 + * classInitializer: + * initializerBlock + * ; + */ + +class ExampleClass1 { + static initialized = false; + static initializerBlock() { + if (!ExampleClass1.initialized) { + ExampleClass1.initialized = true; + } + } +} + +class ExampleClass2 { + constructor() {} + static initialized = false; + static initializerBlock() { + if (!ExampleClass2.initialized) { + ExampleClass2.initialized = true; + } + } +} + +class ExampleClass3 { + static initialized = false; + static initializerBlock() { + if (!ExampleClass3.initialized) { + ExampleClass3.initialized = true; + } + } + method(): void {} +} + +class ExampleClass4 { + constructor() { } + static initialized = false; + static initializerBlock() { + if (!ExampleClass4.initialized) { + ExampleClass4.initialized = true; + } + } + method(): void {} +} + +class ExampleClass5 {} + +class ExampleClass6 { + constructor() {} +} + +class ExampleClass7 { + constructor() {} + method(): void {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassBodyDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassBodyDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..6be377eabbfd8481c9122eaf5e5d06d9d3a4e732 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassBodyDeclaration.ets @@ -0,0 +1,158 @@ +/* + * 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 9.2 + * classBodyDeclaration: + * annotationUsage? + * accessModifier? + * ( constructorDeclaration + * | classFieldDeclaration + * | classMethodDeclaration + * | classAccessorDeclaration + * ) + * ; + * + * CHAPTER 9.4 + * accessModifier: + * 'private' + * | 'internal' + * | 'protected' + * | 'public' + * ; + * + * CHAPTER 9.9 + * constructorDeclaration: + * 'native'? 'constructor' parameters throwMark? constructorBody? + * ; + * + * CHAPTER 9.5 + * classFieldDeclaration: + * fieldModifier* variableDeclaration + * ; + * + * CHAPTER 9.6 + * classMethodDeclaration: + * methodModifier* identifier typeParameters? signature block? + * ; + * + * CHAPTER 9.7 + * classAccessorDeclaration: + * accessorModifier* + * ('get' identifier'('')'returnType block? + * |'set' identifier'('parameter')' block? + * ) + * ; + */ + +class ExampleClass1 { + constructor() {} +} + +class ExampleClass2 { + static field: string = "This is a static field"; +} + +class ExampleClass3 { + method(): void {} +} + +class ExampleClass4 { + get accessor(): number { + return 0; + } +} + +@interface ClassPreamble { + revision: number; +} + +class MyClass1 { + @ClassPreamble({ + revision: 2 + }) + static field: string = "This is a field"; +} + +class MyClass2 { + @ClassPreamble({ + revision: 2 + }) + constructor() {} +} + +class MyClass3 { + @ClassPreamble({ + revision: 2 + }) + method(): void {} +} + +class MyClass4 { + @ClassPreamble({ + revision: 2 + }) + get accessor(): number { + return 0; + } +} + +class X1 { + public constructor() {} +} + +class X2 { + public field: string = "This is a field"; +} + +class X3 { + public method(): void {} +} + +class X4 { + public get accessor(): number { + return 0; + } +} + +class Y1 { + @ClassPreamble({ + revision: 2 + }) + public constructor() {} +} + +class Y2 { + @ClassPreamble({ + revision: 2 + }) + static field: string = "This is a field"; +} + +class Y3 { + @ClassPreamble({ + revision: 2 + }) + public method(): void {} +} + +class Y4 { + @ClassPreamble({ + revision: 2 + }) + public get accessor(): number { + return 0; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassDeclarations.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassDeclarations.ets new file mode 100644 index 0000000000000000000000000000000000000000..0063e73a904b09a311bc06c34f08dbe046df32ea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassDeclarations.ets @@ -0,0 +1,100 @@ +/* + * 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 9.1 + * classDeclaration: + * classModifier? 'class' identifier typeParameters? + * classExtendsClause? implementsClause? classBody + * ; + * + * classModifier: + * 'abstract'|'final' + * ; + * + * CHAPTER 5.1 + * typeParameters: + * '<' typeParameterList '>' + * ; + * + * CHAPTER 9.1.3 + * classExtendsClause: + * 'extends' typeReference + * ; + * + * CHAPTER 9.1.4 + * implementsClause: + * 'implements' interfaceTypeList + * ; + * + * CHAPTER 9.2 + * classBody: + * '{' + * classBodyDeclaration* classInitializer? classBodyDeclaration* + * '}' + * ; + */ + +interface I1 { + foo() {} +} + +class EmptyClass {} + +abstract class X1 {} + +class X2 {} + +class X3 extends X1 {} + +class X4 implements I1 { + foo() {} +} + +abstract class B1 {} + +abstract class B2 extends X1 {} + +abstract class B3 implements I1 { + foo() {} +} + +class C1 extends X1 {} + +class C2 implements I1 { + foo() {} +} + +class C3 extends X1 implements I1 { + foo() {} +} + +abstract class D1 extends X1 {} + +abstract class D2 implements I1 { + foo() {} +} + +class D3 extends X1 implements I1 { + foo() {} +} + +abstract class D4 extends X1 implements I1 { + foo() {} +} + +abstract class E1 extends X1 implements I1 { + foo() {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassFieldDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassFieldDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..c21993dd889f4a0b5c7f437c76e32a3484915d0e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassFieldDeclaration.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 9.5 + * classFieldDeclaration: + * fieldModifier* variableDeclaration + * ; + * + * fieldModifier: + * 'static' | 'readonly' + * ; + */ + +class ExampleClass1 { + static readonly staticReadOnlyField: string = "This is a static readonly field"; +} + +class ExampleClass2 { + instanceCount: number = 0; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassMethodDeclaration.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassMethodDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..f3881ba21346b8f9ecaafd8376d93f7ddace9e85 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassMethodDeclaration.ets @@ -0,0 +1,70 @@ +/* + * 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 9.6 + * classMethodDeclaration: + * methodModifier* identifier typeParameters? signature block? + * ; + * + * methodModifier: + * 'abstract' + * | 'static' + * | 'final' + * | 'override' + * | 'native' + * | 'async' + * ; + */ + +class ExampleClass1 { + method(): void {} +} + +class ExampleClass2 { + static method(): void {} +} + +class ExampleClass3 { + genericMethod(param1: T, param2: U): void {} +} + +class ExampleClass4 { + add(a: number, b: number): number { + return a + b; + } +} + +class C1 { + static genericMethod(param1: T, param2: U): void {} +} + +class C2 { + static add(a: number, b: number): number { + return a + b; + } +} + +class C3 { + method(a: T, b: U): number { + return 0; + } +} + +class C4 { + static method(a: T, b: U): number { + return 0; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassModifier.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassModifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e3a4371ccdce838bf87d718fe141cc4c65b3083 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ClassModifier.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 9.1 + * classDeclaration: + * classModifier? 'class' identifier typeParameters? + * classExtendsClause? implementsClause? classBody + * ; + * + * classModifier: + * 'abstract'|'final' + * ; + */ + +abstract class X1 {} + +final class X2 {} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/FieldModifier.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/FieldModifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..224d8a9e7c9c019182cc2a88d06655d47987a276 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/FieldModifier.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 9.5 + * fieldModifier: + * 'static' | 'readonly' + * ; + * + * classFieldDeclaration: + * fieldModifier* variableDeclaration + * ; + */ + +class ExampleClass1 { + readonly creationDate: Date; + + constructor() { + this.creationDate = new Date(); + } +} + +class ExampleClass2 { + static instanceCount: number = 0; +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ImplementsClause.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ImplementsClause.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e5f1562bf0d6f46017bd6af112028de1e300bff --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ImplementsClause.ets @@ -0,0 +1,48 @@ +/* + * 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 9.1.4 + * implementsClause: + * 'implements' interfaceTypeList + * ; + * + * interfaceTypeList: + * typeReference (','typeReference)* + * ; + * + * CHAPTER 9.1 + * classDeclaration: + * classModifier? 'class' identifier typeParameters? + * classExtendsClause? implementsClause? classBody + * ; + */ + +interface I1 { + foo() {} +} + +interface I2 { + test() {} +} + +class C1 implements I1 { + foo() {} +} + +class C2 implements I1, I2 { + foo() {} + test() {} +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/MethodModifier.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/MethodModifier.ets new file mode 100644 index 0000000000000000000000000000000000000000..2476ed5ecd06a212f223d45d52feb54fef2e3099 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/MethodModifier.ets @@ -0,0 +1,63 @@ +/* + * 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 9.6 + * methodModifier: + * 'abstract' + * | 'static' + * | 'final' + * | 'override' + * | 'native' + * | 'async' + * ; + * + * classMethodDeclaration: + * methodModifier* identifier typeParameters? signature block? + * ; + */ + +class StaticClass { + static staticMethod(): void {} +} + +abstract class AbstractClass { + abstract abstractMethod(): void +} + +class FinalClass { + final finalMethod(): void {} +} + +class Test { + test(x: number, y: number): number { + return x + y; + } +} +class OverrideClass extends Test { + override test(x: number, y: number): number { + return x - y; + } +} + +class NativeClass { + native nativeMethod(): void +} + +class AsyncClass { + async asyncMethod(): Promise { + return 'AsyncMethod result'; + } +} diff --git a/ets2panda/test/ast/compiler/ets/spec/9_classes/ReturnType.ets b/ets2panda/test/ast/compiler/ets/spec/9_classes/ReturnType.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e9930b778d0765dea0dfb4bc711a02d4407c99d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/spec/9_classes/ReturnType.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 9.6.9 + * returnType: + * ':' (type | 'this') + * ; + */ + +class ExampleClass1 { + test(x: number, y: number): number { + return x + y; + } +} + +class ExampleClass2 { + foo(): this { + return this + } +} diff --git a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt index 303bff6cd20d4f5577e84212a168342d08e65e23..54daafe843a27473bc0686c5ccbffe78ff8e540c 100644 --- a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt +++ b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt @@ -1,3 +1,6 @@ +# Issue: #IBT4SW +ast/compiler/ets/spec/7_expressions/stringInterPolation.ets + # Issue: #19440 ast/parser/ets/iterator_override_next.ets diff --git a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt index 47504eb9510fca0b29fcd1a769683f9400c7574a..cbee3b64dd3136d03e494b422b378f174c245398 100644 --- a/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt +++ b/ets2panda/test/test-lists/srcdumper/srcdumper-ets-ignored.txt @@ -1,3 +1,17 @@ +# FailKind.SRC_DUMPER_FAIL (Issue: #IBT4SW) +ast/compiler/ets/spec/7_expressions/additiveExpression.ets +ast/compiler/ets/spec/7_expressions/bitwiseAndLogicalExpression.ets +ast/compiler/ets/spec/7_expressions/equalityExpression.ets +ast/compiler/ets/spec/7_expressions/instanceof.ets +ast/compiler/ets/spec/7_expressions/multiplicativeExpression.ets +ast/compiler/ets/spec/7_expressions/relationalExpression.ets +ast/compiler/ets/spec/7_expressions/shiftExpression.ets +ast/compiler/ets/spec/7_expressions/typeof.ets +ast/compiler/ets/spec/7_expressions/unaryExpression.ets + +# FailKind.INVALID_JSON (Issue: #IBT4SW) +ast/compiler/ets/spec/7_expressions/stringInterPolation.ets + # FailKind.INVALID_JSON (Issue #20457) runtime/ets/StringTemplate1.ets runtime/ets/StringTemplate2.ets