From 34580532485aad29f09d90b68fc91ba8ab468e4d Mon Sep 17 00:00:00 2001 From: zhangchen168 Date: Tue, 13 Sep 2022 20:35:58 +0800 Subject: [PATCH] Fix the constructor overload and declare passing in class 1:Support the constructor overload and declare passing in class 2:Fix declaration and implementation of the constructor 3:Add two test cases and expectations: es2panda/test/parser/ts/test-cyclic-module-import.ts es2panda/test/parser/ts/test-cyclic-module-import-expected.txt es2panda/test/parser/ts/test-type-with-specieal-constructor.ts es2panda/test/parser/ts/test-type-with-specieal-constructor-expected.txt Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5R25C Test: test262,parser tests Change-Id: I78c25befba939a2141b6ee45b2df4ce57bbb417f Signed-off-by: zhangchen168 --- es2panda/parser/parserImpl.cpp | 17 +- .../ts/test-class-constructor1-expected.txt | 2 +- .../ts/test-class-constructor2-expected.txt | 2 +- .../ts/test-class-constructor4-expected.txt | 126 +-- .../ts/test-cyclic-module-import-expected.txt | 715 ++++++++++++++++++ .../parser/ts/test-cyclic-module-import.ts | 36 + ...ype-with-specieal-constructor-expected.txt | 416 ++++++++++ .../ts/test-type-with-specieal-constructor.ts | 32 + 8 files changed, 1217 insertions(+), 129 deletions(-) create mode 100644 es2panda/test/parser/ts/test-cyclic-module-import-expected.txt create mode 100644 es2panda/test/parser/ts/test-cyclic-module-import.ts create mode 100644 es2panda/test/parser/ts/test-type-with-specieal-constructor-expected.txt create mode 100644 es2panda/test/parser/ts/test-type-with-specieal-constructor.ts diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 5d45e3e3ca..664faf665e 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -2657,6 +2657,7 @@ ir::Identifier *ParserImpl::SetIdentNodeInClassDefinition() ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool idRequired, bool isDeclare, bool isAbstract) { + isDeclare = isDeclare | (context_.Status() & ParserStatus::IN_AMBIENT_CONTEXT); lexer::SourcePosition startLoc = lexer_->GetToken().Start(); lexer_->NextToken(); @@ -2758,6 +2759,8 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i ir::MethodDefinition *ctor = nullptr; ArenaVector properties(Allocator()->Adapter()); ArenaVector indexSignatures(Allocator()->Adapter()); + bool hasConstructorFuncBody = false; + bool isCtorContinuousDefined = true; while (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { @@ -2772,13 +2775,18 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i } if (IsConstructor(property)) { - if (!isDeclare && ctor) { + if (!isDeclare && !isCtorContinuousDefined) { + ThrowSyntaxError("Constructor implementation is missing.", property->Start()); + } + + if (hasConstructorFuncBody) { ThrowSyntaxError("Multiple constructor implementations are not allowed.", property->Start()); } ctor = property->AsMethodDefinition(); + hasConstructorFuncBody = ctor->Value()->Function()->Body() != nullptr; continue; } - + isCtorContinuousDefined = ctor == nullptr; properties.push_back(property); } @@ -2788,9 +2796,14 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i if (ctor == nullptr) { ctor = CreateImplicitConstructor(hasSuperClass, isDeclare); ctor->SetRange({startLoc, classBodyEndLoc}); + hasConstructorFuncBody = !isDeclare; } lexer_->NextToken(); + if (!isDeclare && !hasConstructorFuncBody) { + ThrowSyntaxError("Constructor implementation is missing.", ctor->Start()); + } + auto *classDefinition = AllocNode( classCtx.GetScope(), identNode, typeParamDecl, superTypeParams, std::move(implements), ctor, superClass, std::move(properties), std::move(indexSignatures), isDeclare, isAbstract); diff --git a/es2panda/test/parser/ts/test-class-constructor1-expected.txt b/es2panda/test/parser/ts/test-class-constructor1-expected.txt index b8dc6e627c..0c9cd3e40c 100644 --- a/es2panda/test/parser/ts/test-class-constructor1-expected.txt +++ b/es2panda/test/parser/ts/test-class-constructor1-expected.txt @@ -1 +1 @@ -SyntaxError: Multiple constructor implementations are not allowed. [test-class-constructor1.ts:20:5] +SyntaxError: Constructor implementation is missing. [test-class-constructor1.ts:20:5] diff --git a/es2panda/test/parser/ts/test-class-constructor2-expected.txt b/es2panda/test/parser/ts/test-class-constructor2-expected.txt index 3c80b2dbf2..e2a756d71f 100644 --- a/es2panda/test/parser/ts/test-class-constructor2-expected.txt +++ b/es2panda/test/parser/ts/test-class-constructor2-expected.txt @@ -1 +1 @@ -SyntaxError: Multiple constructor implementations are not allowed. [test-class-constructor2.ts:19:5] +SyntaxError: Constructor implementation is missing. [test-class-constructor2.ts:21:5] diff --git a/es2panda/test/parser/ts/test-class-constructor4-expected.txt b/es2panda/test/parser/ts/test-class-constructor4-expected.txt index 1d1294954f..e1214afcca 100644 --- a/es2panda/test/parser/ts/test-class-constructor4-expected.txt +++ b/es2panda/test/parser/ts/test-class-constructor4-expected.txt @@ -1,125 +1 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 7 - }, - "end": { - "line": 17, - "column": 10 - } - } - }, - "superClass": null, - "implements": [], - "constructor": { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "constructor", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 5 - }, - "end": { - "line": 18, - "column": 16 - } - } - }, - "kind": "constructor", - "static": false, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": null, - "generator": false, - "async": false, - "expression": false, - "params": [], - "loc": { - "start": { - "line": 18, - "column": 16 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 16 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 5 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "body": [], - "indexSignatures": [], - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 19, - "column": 2 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 1 - }, - "end": { - "line": 19, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 19, - "column": 2 - } - } -} +SyntaxError: Constructor implementation is missing. [test-class-constructor4.ts:18:5] diff --git a/es2panda/test/parser/ts/test-cyclic-module-import-expected.txt b/es2panda/test/parser/ts/test-cyclic-module-import-expected.txt new file mode 100644 index 0000000000..5979c2c1cb --- /dev/null +++ b/es2panda/test/parser/ts/test-cyclic-module-import-expected.txt @@ -0,0 +1,715 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSModuleDeclaration", + "id": { + "type": "StringLiteral", + "value": "ModuleSub", + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [ + { + "type": "TSImportEqualsDeclaration", + "id": { + "type": "Identifier", + "name": "TargetModule", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "moduleReference": { + "type": "TSExternalModuleReference", + "expression": { + "type": "StringLiteral", + "value": "TargetModule", + "loc": { + "start": { + "line": 19, + "column": 35 + }, + "end": { + "line": 19, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + "isExport": false, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 51 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ModuleSub", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "loc": { + "start": { + "line": 24, + "column": 20 + }, + "end": { + "line": 24, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 20 + }, + "end": { + "line": 24, + "column": 23 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 23 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "StaticVar", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 21, + "column": 34 + }, + "end": { + "line": 21, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "InsVar", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 22 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 22 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "TargetModule", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 20 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 25, + "column": 6 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 25, + "column": 6 + } + } + }, + { + "type": "TSExportAssignment", + "declaration": { + "type": "Identifier", + "name": "ModuleSub", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 14 + }, + "end": { + "line": 26, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 28 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "declare": true, + "global": false, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 29, + "column": 8 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "StringLiteral", + "value": "TargetModule", + "loc": { + "start": { + "line": 29, + "column": 16 + }, + "end": { + "line": 29, + "column": 30 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [ + { + "type": "TSImportEqualsDeclaration", + "id": { + "type": "Identifier", + "name": "ModuleSub", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 21 + } + } + }, + "moduleReference": { + "type": "TSExternalModuleReference", + "expression": { + "type": "StringLiteral", + "value": "ModuleSub", + "loc": { + "start": { + "line": 30, + "column": 32 + }, + "end": { + "line": 30, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 24 + }, + "end": { + "line": 30, + "column": 44 + } + } + }, + "isExport": false, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 45 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "TargetModule", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 11 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 9 + }, + "end": { + "line": 33, + "column": 20 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 33, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 33, + "column": 23 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 9 + }, + "end": { + "line": 33, + "column": 23 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "moduleSub", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 16 + }, + "end": { + "line": 32, + "column": 25 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "ModuleSub", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 27 + }, + "end": { + "line": 32, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 27 + }, + "end": { + "line": 32, + "column": 36 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 9 + }, + "end": { + "line": 32, + "column": 25 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 31, + "column": 24 + }, + "end": { + "line": 34, + "column": 6 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 34, + "column": 6 + } + } + }, + { + "type": "TSExportAssignment", + "declaration": { + "type": "Identifier", + "name": "TargetModule", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 35, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "declare": true, + "global": false, + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 37, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 37, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-cyclic-module-import.ts b/es2panda/test/parser/ts/test-cyclic-module-import.ts new file mode 100644 index 0000000000..6068088306 --- /dev/null +++ b/es2panda/test/parser/ts/test-cyclic-module-import.ts @@ -0,0 +1,36 @@ +/* + * 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. + */ + + +// @declaration: true +declare module "ModuleSub" { + import TargetModule = require('TargetModule'); + class ModuleSub { + public static StaticVar: number; + public InsVar: number; + public main: TargetModule; + constructor(); + } + export = ModuleSub; +} + +declare module "TargetModule" { + import ModuleSub = require('ModuleSub'); + class TargetModule { + public moduleSub: ModuleSub; + constructor(); + } + export = TargetModule; +} diff --git a/es2panda/test/parser/ts/test-type-with-specieal-constructor-expected.txt b/es2panda/test/parser/ts/test-type-with-specieal-constructor-expected.txt new file mode 100644 index 0000000000..a7d4bcf372 --- /dev/null +++ b/es2panda/test/parser/ts/test-type-with-specieal-constructor-expected.txt @@ -0,0 +1,416 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ClassExample", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 16 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 18 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 20 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 16 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "body": [], + "indexSignatures": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "TSModuleDeclaration", + "id": { + "type": "Identifier", + "name": "ns", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 19 + }, + "end": { + "line": 26, + "column": 21 + } + } + }, + "body": { + "type": "TSModuleBlock", + "body": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 11 + }, + "end": { + "line": 27, + "column": 12 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 20 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 30, + "column": 23 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 20 + }, + "end": { + "line": 30, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 20 + }, + "end": { + "line": 30, + "column": 31 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 31 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 10 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 29, + "column": 11 + }, + "end": { + "line": 29, + "column": 17 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 10 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 31, + "column": 6 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 31, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 22 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "declare": true, + "global": false, + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 32, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 32, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test-type-with-specieal-constructor.ts b/es2panda/test/parser/ts/test-type-with-specieal-constructor.ts new file mode 100644 index 0000000000..2000dd2a79 --- /dev/null +++ b/es2panda/test/parser/ts/test-type-with-specieal-constructor.ts @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +class ClassExample { + constructor(a: 'hello'); + constructor(a: 'bye'); + constructor(a: string); + constructor(a) { + return a; + } +} + +declare namespace ns { + class A { + constructor(); + a:string; + constructor(x:number); + } +} \ No newline at end of file -- Gitee