diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 723076cab39745eeec2bb27a5122e6c8040458ef..deb1e99bd52003bb0c47a6cd1c81aabdf9fde312 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -2538,7 +2538,8 @@ ArenaVector ParserImpl::ParseDecorators() (context_.Status() & ParserStatus::IN_CLASS_BODY) == 0 && lexer_->GetToken().Type() != lexer::TokenType::KEYW_EXPORT && !(lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && - lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE)) { + (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE || + lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_ABSTRACT))) { ThrowSyntaxError("Decorators are not valid here.", decorators.front()->Start()); } diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index e8f67909e36dec0a196f52e9ea5f1b01461ae326..2575e9e569d9e49bbf56916e412e8d2a8df7eb94 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -2505,7 +2505,9 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: } if (!decorators.empty() && lexer_->GetToken().Type() != lexer::TokenType::KEYW_CLASS && - (context_.Status() & ParserStatus::IN_CLASS_BODY) == 0) { + (context_.Status() & ParserStatus::IN_CLASS_BODY) == 0 && + !(lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && + (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_ABSTRACT))) { ThrowSyntaxError("Decorators are not valid here.", decorators.front()->Start()); } diff --git a/es2panda/parser/transformer/transformer.cpp b/es2panda/parser/transformer/transformer.cpp index d1c8b5f08b21c29e7d29c5abd46d91d1ca908e48..457c1a2c2c8b674549248fa26cc6603b83efd0b7 100644 --- a/es2panda/parser/transformer/transformer.cpp +++ b/es2panda/parser/transformer/transformer.cpp @@ -281,6 +281,9 @@ ir::UpdateNodes Transformer::VisitTSNode(ir::AstNode *childNode) } case ir::AstNodeType::CLASS_DECLARATION: { auto *node = childNode->AsClassDeclaration(); + if (node->Definition()->Declare()) { + return node; + } DuringClass duringClass(&classList_, node->Definition()->GetName()); node = VisitTSNodes(node)->AsClassDeclaration(); auto res = VisitClassDeclaration(node); diff --git a/es2panda/test/compiler/ts/cases/conformance/decorators/test-ts-decorators-14-expected.txt b/es2panda/test/compiler/ts/cases/conformance/decorators/test-ts-decorators-14-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..516badf46f7780c75e790b67b1a47d2b8102f2b4 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/decorators/test-ts-decorators-14-expected.txt @@ -0,0 +1,2 @@ +test decorators +test decorators diff --git a/es2panda/test/compiler/ts/cases/conformance/decorators/test-ts-decorators-14.ts b/es2panda/test/compiler/ts/cases/conformance/decorators/test-ts-decorators-14.ts new file mode 100644 index 0000000000000000000000000000000000000000..b572e23ed46dba8893d36d8cd9ef3b4fd1669864 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/decorators/test-ts-decorators-14.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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. + */ + + +function f(constructor: Function) { print("test decorators"); } + +@f +class C1 { } + +@f +abstract class C2 { } diff --git a/es2panda/test/compiler/ts/projects/ts_test_decorators/ts-test-decorators-export-exec-expected.txt b/es2panda/test/compiler/ts/projects/ts_test_decorators/ts-test-decorators-export-exec-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..58c7af63cb40d4f84a637a4f0317a4132a5479ee --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_test_decorators/ts-test-decorators-export-exec-expected.txt @@ -0,0 +1 @@ +test decorators diff --git a/es2panda/test/compiler/ts/projects/ts_test_decorators/ts-test-decorators-export-exec.ts b/es2panda/test/compiler/ts/projects/ts_test_decorators/ts-test-decorators-export-exec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d4789692e7956efced5a6333f9c27ebe6c722f24 --- /dev/null +++ b/es2panda/test/compiler/ts/projects/ts_test_decorators/ts-test-decorators-export-exec.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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. + */ + + +function f(constructor: Function) { print("test decorators"); } + +@f +export declare class C1 { } + +@f +export abstract class C2 { } + +@f +export abstract declare class C3 { } + +@f +export declare abstract class C4 { }