From 0c4b48e41051eca2ebc145811a2e1a01099b1cee Mon Sep 17 00:00:00 2001 From: gizembusraturan Date: Tue, 20 May 2025 08:55:05 +0300 Subject: [PATCH] support declare struct Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICF80I Description: It merged into branch 0411, but not into branch 0328 Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran ## --- es2panda/lexer/token/tokenType.h | 3 ++- ets2panda/parser/ETSparser.cpp | 3 ++- .../ets/ambient_struct/declare_struct.d.ets | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/ambient_struct/declare_struct.d.ets diff --git a/es2panda/lexer/token/tokenType.h b/es2panda/lexer/token/tokenType.h index 6fe7fb0f0e..45a23d0ed2 100644 --- a/es2panda/lexer/token/tokenType.h +++ b/es2panda/lexer/token/tokenType.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -142,6 +142,7 @@ enum class TokenType { KEYW_RETURN, KEYW_STRING, KEYW_SUPER, + KEYW_STRUCT, KEYW_SWITCH, KEYW_SYMBOL, KEYW_THIS, diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index b375d27ab1..2a7ea152f1 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2094,7 +2094,8 @@ void ETSParser::CheckDeclare() case lexer::TokenType::KEYW_FINAL: case lexer::TokenType::KEYW_INTERFACE: case lexer::TokenType::KEYW_TYPE: - case lexer::TokenType::KEYW_ASYNC: { + case lexer::TokenType::KEYW_ASYNC: + case lexer::TokenType::KEYW_STRUCT: { return; } default: { diff --git a/ets2panda/test/ast/compiler/ets/ambient_struct/declare_struct.d.ets b/ets2panda/test/ast/compiler/ets/ambient_struct/declare_struct.d.ets new file mode 100644 index 0000000000..820aa91867 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/ambient_struct/declare_struct.d.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +export declare struct Point2D { + x: number; + y: number; +} + +/* @@? 16:16 Error TypeError: Structs are only used to define UI components, it should be translated at 'plugin after parser' phase. */ -- Gitee