diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 5d45e3e3ca366620ec82b8cbd4e30753737c1723..664faf665e2e91144e0734ba18d46bac27482a84 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 b8dc6e627c7254bec4347d3f59fb339a63090739..0c9cd3e40cecae0f527cd4979865aa6a3fe06bc4 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 3c80b2dbf28749a30875152598ab84a895299415..e2a756d71f57b38c2657a10b3ee9afec4e58cfae 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 1d1294954f9adb49309c1fa594457ba46e511966..e1214afcca175e91ceed969c960be014a2dd6c00 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 0000000000000000000000000000000000000000..5979c2c1cbb27c755f1c1f04ba8ba39782d7c12e --- /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 0000000000000000000000000000000000000000..6068088306e3aed2d0dc5d20312ed84a6e1c6340 --- /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 0000000000000000000000000000000000000000..a7d4bcf3721334c1ff53dda4aa1d91c06a047c7e --- /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 0000000000000000000000000000000000000000..2000dd2a79e1ca7c3ad57db43b96c186575bc950 --- /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