From 560287c035962d42d0d910793162217768f60a50 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Mon, 21 Nov 2022 09:30:14 +0000 Subject: [PATCH] Fix the parse problem when declare class has the same name with function Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I6MJX6 Test: parser tests, compiler tests, tsc tests, test262 Signed-off-by: xucheng46 Change-Id: Id9b8b7ad6572bae09c5e142eae0c1e236aedb42f --- es2panda/binder/binder.cpp | 4 +- es2panda/binder/declaration.h | 51 +- es2panda/binder/scope.cpp | 16 +- es2panda/binder/scope.h | 31 + es2panda/parser/parserImpl.h | 1 + es2panda/parser/statementParser.cpp | 32 +- .../ts/test-class-definiton23-expected.txt | 1067 +++++++++++++++++ .../test/parser/ts/test-class-definiton23.ts | 33 + .../ts/test-class-definiton24-expected.txt | 561 +++++++++ .../test/parser/ts/test-class-definiton24.ts | 25 + .../ts/test-class-definiton25-expected.txt | 1067 +++++++++++++++++ .../test/parser/ts/test-class-definiton25.ts | 33 + es2panda/test/test_tsc_ignore_list.txt | 3 - 13 files changed, 2892 insertions(+), 32 deletions(-) create mode 100644 es2panda/test/parser/ts/test-class-definiton23-expected.txt create mode 100644 es2panda/test/parser/ts/test-class-definiton23.ts create mode 100644 es2panda/test/parser/ts/test-class-definiton24-expected.txt create mode 100644 es2panda/test/parser/ts/test-class-definiton24.ts create mode 100644 es2panda/test/parser/ts/test-class-definiton25-expected.txt create mode 100644 es2panda/test/parser/ts/test-class-definiton25.ts diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index f7dd8b5d56..8289504ecc 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -412,7 +412,9 @@ void Binder::BuildClassDefinition(ir::ClassDefinition *classDef) ASSERT(!className.Empty()); ScopeFindResult res = scope_->Find(className); - ASSERT(res.variable && res.variable->Declaration()->IsClassDecl()); + ASSERT(res.variable && (res.variable->Declaration()->IsClassDecl() || + (res.variable->Declaration()->IsFunctionDecl() && + res.variable->Declaration()->AsFunctionDecl()->GetDeclClass() != nullptr))); res.variable->AddFlag(VariableFlags::INITIALIZED); } diff --git a/es2panda/binder/declaration.h b/es2panda/binder/declaration.h index e1b1ad05b7..88e468b475 100644 --- a/es2panda/binder/declaration.h +++ b/es2panda/binder/declaration.h @@ -193,20 +193,6 @@ public: } }; -class FunctionDecl : public MultiDecl { -public: - explicit FunctionDecl(ArenaAllocator *allocator, util::StringView name, const ir::AstNode *node) - : MultiDecl(allocator, name) - { - node_ = node; - } - - DeclType Type() const override - { - return DeclType::FUNC; - } -}; - class TypeParameterDecl : public Decl { public: explicit TypeParameterDecl(util::StringView name, const ir::AstNode *node); @@ -302,12 +288,47 @@ public: class ClassDecl : public Decl { public: - explicit ClassDecl(util::StringView name) : Decl(name) {} + explicit ClassDecl(util::StringView name, bool declare) : Decl(name), declare_(declare) {} DeclType Type() const override { return DeclType::CLASS; } + + bool IsDeclare() const + { + return declare_; + } + +private: + bool declare_; +}; + +class FunctionDecl : public MultiDecl { +public: + explicit FunctionDecl(ArenaAllocator *allocator, util::StringView name, const ir::AstNode *node) + : MultiDecl(allocator, name) + { + node_ = node; + } + + DeclType Type() const override + { + return DeclType::FUNC; + } + + void SetDeclClass(ClassDecl *declClass) + { + declClass_ = declClass; + } + + ClassDecl *GetDeclClass() + { + return declClass_; + } + +private: + ClassDecl *declClass_ {nullptr}; }; class ParameterDecl : public Decl { diff --git a/es2panda/binder/scope.cpp b/es2panda/binder/scope.cpp index 17ba3df8e8..73cc00a706 100644 --- a/es2panda/binder/scope.cpp +++ b/es2panda/binder/scope.cpp @@ -301,6 +301,9 @@ bool FunctionScope::AddBinding(ArenaAllocator *allocator, Variable *currentVaria case DeclType::FUNC: { return AddFunction(allocator, currentVariable, newDecl, extension); } + case DeclType::CLASS: { + return AddClass(allocator, currentVariable, newDecl); + } case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, newDecl, VariableFlags::ENUM_LITERAL); } @@ -336,6 +339,9 @@ bool GlobalScope::AddBinding(ArenaAllocator *allocator, Variable *currentVariabl case DeclType::FUNC: { return AddFunction(allocator, currentVariable, newDecl, extension); } + case DeclType::CLASS: { + return AddClass(allocator, currentVariable, newDecl); + } case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, newDecl, VariableFlags::ENUM_LITERAL); } @@ -397,12 +403,20 @@ bool ModuleScope::AddBinding(ArenaAllocator *allocator, Variable *currentVariabl } case DeclType::FUNC: { if (currentVariable) { - return false; + auto decl = currentVariable->Declaration(); + if (!decl->IsClassDecl() || !decl->AsClassDecl()->IsDeclare()) { + return false; + } } return newDecl->IsImportOrExportDecl() ? AddFunction(allocator, currentVariable, newDecl, extension) : AddFunction(allocator, currentVariable, newDecl, extension); } + case DeclType::CLASS: { + return newDecl->IsImportOrExportDecl() ? + AddClass(allocator, currentVariable, newDecl) : + AddClass(allocator, currentVariable, newDecl); + } case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, newDecl, VariableFlags::ENUM_LITERAL); } diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index d2bc3419d4..1790828f8f 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -428,6 +428,9 @@ protected: bool AddFunction(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension); + template + bool AddClass(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl); + template bool AddTSBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, VariableFlags flags); @@ -900,6 +903,13 @@ bool VariableScope::AddFunction(ArenaAllocator *allocator, Variable *currentVari return true; } + auto decl = currentVariable->Declaration(); + if (decl->IsClassDecl() && decl->AsClassDecl()->IsDeclare()) { + newDecl->AsFunctionDecl()->SetDeclClass(decl->AsClassDecl()); + bindings_[newDecl->Name()] = allocator->New(newDecl, flags); + return true; + } + if (extension != ScriptExtension::JS) { return false; } @@ -918,6 +928,27 @@ bool VariableScope::AddFunction(ArenaAllocator *allocator, Variable *currentVari return true; } +template +bool VariableScope::AddClass(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl) +{ + ASSERT(newDecl->IsClassDecl()); + + VariableFlags flags = DeclFlagToVariableFlag(newDecl->Flags()); + + if (!currentVariable) { + bindings_.insert({newDecl->Name(), allocator->New(newDecl, flags)}); + return true; + } + + auto decl = currentVariable->Declaration(); + if (newDecl->AsClassDecl()->IsDeclare() && decl->IsFunctionDecl()) { + decl->AsFunctionDecl()->SetDeclClass(newDecl->AsClassDecl()); + return true; + } + + return false; +} + template bool VariableScope::AddTSBinding(ArenaAllocator *allocator, [[maybe_unused]] Variable *currentVariable, Decl *newDecl, VariableFlags flags) diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index de716a4cd7..10c539cd32 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -472,6 +472,7 @@ private: ir::FunctionDeclaration *ParseFunctionDeclaration(bool canBeAnonymous = false, ParserStatus newStatus = ParserStatus::NO_OPTS, bool isDeclare = false); + void AddFunctionToBinder(ir::ScriptFunction *func, ParserStatus newStatus); void CheckOptionalBindingPatternParameter(ir::ScriptFunction *func) const; ir::Statement *ParseExportDeclaration(StatementParsingFlags flags, ArenaVector &&decorators); std::tuple ParseForInOf( diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index e8f67909e3..90d5bbcb19 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -663,7 +663,7 @@ ir::ClassDeclaration *ParserImpl::ParseClassDeclaration(bool idRequired, ArenaVe ASSERT(!className.Empty()); binder::DeclarationFlags flag = isExported ? binder::DeclarationFlags::EXPORT : binder::DeclarationFlags::NONE; - auto *decl = Binder()->AddDecl(location, flag, className); + auto *decl = Binder()->AddDecl(location, flag, className, classDefinition->Declare()); decl->BindNode(classDefinition); @@ -1165,18 +1165,34 @@ ir::FunctionDeclaration *ParserImpl::ParseFunctionDeclaration(bool canBeAnonymou auto *funcDecl = AllocNode(func); funcDecl->SetRange(func->Range()); + AddFunctionToBinder(func, newStatus); + + if (func->IsOverload() && lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + lexer_->NextToken(); + } + + CheckOptionalBindingPatternParameter(func); + + return funcDecl; +} + +void ParserImpl::AddFunctionToBinder(ir::ScriptFunction *func, ParserStatus newStatus) +{ binder::DeclarationFlags declflag = (newStatus & ParserStatus::EXPORT_REACHED) ? binder::DeclarationFlags::EXPORT : binder::DeclarationFlags::NONE; + const ir::Identifier *identNode = func->Id(); + const lexer::SourcePosition &startLoc = func->Start(); + const util::StringView ident = identNode->Name(); if (Extension() == ScriptExtension::TS) { const auto &bindings = Binder()->GetScope()->Bindings(); auto res = bindings.find(ident); + binder::Decl *currentDecl = res == bindings.end() ? nullptr : res->second->Declaration(); binder::FunctionDecl *decl {}; - if (res == bindings.end()) { + if (res == bindings.end() || + (currentDecl->IsClassDecl() && currentDecl->AsClassDecl()->IsDeclare())) { decl = Binder()->AddDecl(identNode->Start(), declflag, Allocator(), ident, func); } else { - binder::Decl *currentDecl = res->second->Declaration(); - if (!currentDecl->IsFunctionDecl()) { Binder()->ThrowRedeclaration(startLoc, currentDecl->Name()); } @@ -1195,14 +1211,6 @@ ir::FunctionDeclaration *ParserImpl::ParseFunctionDeclaration(bool canBeAnonymou } else { Binder()->AddDecl(identNode->Start(), declflag, Allocator(), ident, func); } - - if (func->IsOverload() && lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { - lexer_->NextToken(); - } - - CheckOptionalBindingPatternParameter(func); - - return funcDecl; } void ParserImpl::CheckOptionalBindingPatternParameter(ir::ScriptFunction *func) const diff --git a/es2panda/test/parser/ts/test-class-definiton23-expected.txt b/es2panda/test/parser/ts/test-class-definiton23-expected.txt new file mode 100644 index 0000000000..97233ab8ca --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definiton23-expected.txt @@ -0,0 +1,1067 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSAnyKeyword", + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 22, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 22, + "column": 8 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 27 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "ns", + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [ + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 26, + "column": 14 + }, + "end": { + "line": 26, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSAnyKeyword", + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 27, + "column": 25 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 28, + "column": 19 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 13 + }, + "end": { + "line": 28, + "column": 24 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 13 + }, + "end": { + "line": 28, + "column": 24 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 30, + "column": 22 + }, + "end": { + "line": 30, + "column": 24 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 30, + "column": 29 + }, + "end": { + "line": 30, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 29 + }, + "end": { + "line": 30, + "column": 31 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 31, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 31, + "column": 12 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 31, + "column": 22 + }, + "end": { + "line": 31, + "column": 24 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 31, + "column": 29 + }, + "end": { + "line": 31, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 29 + }, + "end": { + "line": 31, + "column": 31 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 31, + "column": 13 + }, + "end": { + "line": 32, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 13 + }, + "end": { + "line": 32, + "column": 12 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 32, + "column": 19 + }, + "end": { + "line": 32, + "column": 21 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 32, + "column": 24 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 32, + "column": 22 + }, + "end": { + "line": 32, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 32, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 33, + "column": 2 + } + } + }, + "declare": false, + "global": false, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 34, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 34, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-class-definiton23.ts b/es2panda/test/parser/ts/test-class-definiton23.ts new file mode 100644 index 0000000000..ad97bf3934 --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definiton23.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 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 C1() : C1 +function C1() : any {} +declare class C1 {} + +declare function C2() : C2 +declare function C2() : C2 +declare class C2 {} + +namespace ns { + function C1() : C1 + function C1() : any {} + declare class C1 {} + + declare function C2() : C2 + declare function C2() : C2 + declare class C2 {} +} diff --git a/es2panda/test/parser/ts/test-class-definiton24-expected.txt b/es2panda/test/parser/ts/test-class-definiton24-expected.txt new file mode 100644 index 0000000000..3685333522 --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definiton24-expected.txt @@ -0,0 +1,561 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "ns", + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 10 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 24, + "column": 11 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 16 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "declare": true, + "global": false, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 26, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 26, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-class-definiton24.ts b/es2panda/test/parser/ts/test-class-definiton24.ts new file mode 100644 index 0000000000..35d3884aca --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definiton24.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 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. + */ + + +declare namespace ns { + class C1 {} + function C1() : C1 + function C1() : C1 + + function C2() : C2 + function C2() : C2 + class C2 {} +} diff --git a/es2panda/test/parser/ts/test-class-definiton25-expected.txt b/es2panda/test/parser/ts/test-class-definiton25-expected.txt new file mode 100644 index 0000000000..4407dce5a4 --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definiton25-expected.txt @@ -0,0 +1,1067 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSAnyKeyword", + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 27 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 23, + "column": 8 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 25, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 25, + "column": 10 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "ns", + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 26, + "column": 19 + }, + "end": { + "line": 26, + "column": 21 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 26, + "column": 22 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 24 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 28, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 28, + "column": 13 + } + } + }, + { + "type": "FunctionDeclaration", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C1", + "loc": { + "start": { + "line": 28, + "column": 14 + }, + "end": { + "line": 28, + "column": 16 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSAnyKeyword", + "loc": { + "start": { + "line": 28, + "column": 21 + }, + "end": { + "line": 28, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 28, + "column": 25 + }, + "end": { + "line": 28, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 27 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 30, + "column": 19 + }, + "end": { + "line": 30, + "column": 21 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "declare": true, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 30, + "column": 24 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 30, + "column": 22 + }, + "end": { + "line": 30, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 30, + "column": 24 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 31, + "column": 22 + }, + "end": { + "line": 31, + "column": 24 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 31, + "column": 29 + }, + "end": { + "line": 31, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 29 + }, + "end": { + "line": 31, + "column": 31 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 31, + "column": 13 + }, + "end": { + "line": 32, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 13 + }, + "end": { + "line": 32, + "column": 12 + } + } + }, + { + "type": "TSDeclareFunction", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 32, + "column": 22 + }, + "end": { + "line": 32, + "column": 24 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "C2", + "loc": { + "start": { + "line": 32, + "column": 29 + }, + "end": { + "line": 32, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 29 + }, + "end": { + "line": 32, + "column": 31 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 33, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 33, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 33, + "column": 2 + } + } + }, + "declare": false, + "global": false, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 34, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 34, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-class-definiton25.ts b/es2panda/test/parser/ts/test-class-definiton25.ts new file mode 100644 index 0000000000..b97ed7f7df --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definiton25.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 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. + */ + + +declare class C1 {} +function C1() : C1 +function C1() : any {} + +declare class C2 {} +declare function C2() : C2 +declare function C2() : C2 + +namespace ns { + declare class C1 {} + function C1() : C1 + function C1() : any {} + + declare class C2 {} + declare function C2() : C2 + declare function C2() : C2 +} diff --git a/es2panda/test/test_tsc_ignore_list.txt b/es2panda/test/test_tsc_ignore_list.txt index f5bf4b5e1f..3b75aec16b 100644 --- a/es2panda/test/test_tsc_ignore_list.txt +++ b/es2panda/test/test_tsc_ignore_list.txt @@ -1,9 +1,6 @@ -es2panda/test/TypeScript/tests/cases/compiler/ambientClassOverloadForFunction.ts es2panda/test/TypeScript/tests/cases/compiler/bom-utf16be.ts -es2panda/test/TypeScript/tests/cases/compiler/classFunctionMerging.ts es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInType.ts es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInterfaceMembers.ts -es2panda/test/TypeScript/tests/cases/compiler/constructorOverloads5.ts es2panda/test/TypeScript/tests/cases/compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts es2panda/test/TypeScript/tests/cases/compiler/globalIsContextualKeyword.ts es2panda/test/TypeScript/tests/cases/compiler/inferenceErasedSignatures.ts -- Gitee