diff --git a/compiler/test/data/typescript/stdlib/arrayWithoutParam.d.kt b/compiler/test/data/typescript/stdlib/arrayWithoutParam.d.kt new file mode 100644 index 000000000..5f901efae --- /dev/null +++ b/compiler/test/data/typescript/stdlib/arrayWithoutParam.d.kt @@ -0,0 +1,18 @@ +// [test] arrayWithoutParam.kt +@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS") + +import kotlin.js.* +import org.khronos.webgl.* +import org.w3c.dom.* +import org.w3c.dom.events.* +import org.w3c.dom.parsing.* +import org.w3c.dom.svg.* +import org.w3c.dom.url.* +import org.w3c.fetch.* +import org.w3c.files.* +import org.w3c.notifications.* +import org.w3c.performance.* +import org.w3c.workers.* +import org.w3c.xhr.* + +typealias Table = Array \ No newline at end of file diff --git a/compiler/test/data/typescript/stdlib/arrayWithoutParam.d.ts b/compiler/test/data/typescript/stdlib/arrayWithoutParam.d.ts new file mode 100644 index 000000000..f044902f0 --- /dev/null +++ b/compiler/test/data/typescript/stdlib/arrayWithoutParam.d.ts @@ -0,0 +1,5 @@ +declare class Table extends Array { + constructor(); + toString(): string; + static version: string; +} \ No newline at end of file diff --git a/model-lowerings/src/org/jetbrains/dukat/commonLowerings/substituteTsStdLibEntities.kt b/model-lowerings/src/org/jetbrains/dukat/commonLowerings/substituteTsStdLibEntities.kt index 8c4b1d42c..a433fbbc0 100644 --- a/model-lowerings/src/org/jetbrains/dukat/commonLowerings/substituteTsStdLibEntities.kt +++ b/model-lowerings/src/org/jetbrains/dukat/commonLowerings/substituteTsStdLibEntities.kt @@ -19,10 +19,11 @@ import org.jetbrains.dukat.model.commonLowerings.ModelLowering import org.jetbrains.dukat.model.commonLowerings.ModelWithOwnerTypeLowering import org.jetbrains.dukat.ownerContext.NodeOwner import org.jetbrains.dukat.stdlib.TSLIBROOT +import org.jetbrains.dukat.stdlib.isKotlinStdlibPrefixed import org.jetbrains.dukat.stdlib.isTsStdlibPrefixed private fun TypeValueModel.isLibReference(): Boolean { - return fqName?.isTsStdlibPrefixed() == true + return fqName?.isTsStdlibPrefixed() == true || fqName?.isKotlinStdlibPrefixed() == true } private fun HeritageModel.isLibReference(): Boolean { diff --git a/typescript/ts-converter/src/AstConverter.ts b/typescript/ts-converter/src/AstConverter.ts index c2d0c896a..a9b792720 100644 --- a/typescript/ts-converter/src/AstConverter.ts +++ b/typescript/ts-converter/src/AstConverter.ts @@ -468,7 +468,7 @@ export class AstConverter { let symbol = this.typeChecker.getSymbolAtLocation(type.typeName); let typeReference: ReferenceEntity | null = null; - let declaration = this.getFirstDeclaration(symbol); + let declaration = this.getFirstDeclaration(symbol, params.length); if (declaration) { if (ts.isTypeParameterDeclaration(declaration)) { @@ -617,6 +617,12 @@ export class AstConverter { member.type ? this.convertType(member.type) : this.createTypeDeclaration("Unit"), this.convertTypeParams(member.typeParameters) ) + } else if (ts.isConstructSignatureDeclaration(member)) { + return this.astFactory.createConstructSignatureDeclaration( + this.convertParameterDeclarations(member.parameters), + member.type ? this.convertType(member.type) : this.createTypeDeclaration("Unit"), + this.convertTypeParams(member.typeParameters) + ) } return null; @@ -740,15 +746,18 @@ export class AstConverter { return this.astFactory.createQualifiedNameEntity(convertedExpression, name); } - private getFirstDeclaration(symbol: ts.Symbol | null): ts.Declaration | null { + private getFirstDeclaration(symbol: ts.Symbol | null, typeParamsNum: number): ts.Declaration | null { if (symbol == null) { return null; } if (Array.isArray(symbol.declarations)) { return symbol.declarations.find(decl => !ts.isModuleDeclaration(decl) && - !ts.isVariableDeclaration(decl) && !ts.isPropertyDeclaration(decl) && !ts.isPropertySignature(decl) && - !ts.isFunctionLike(decl)) + !ts.isPropertyDeclaration(decl) && !ts.isPropertySignature(decl) && + !ts.isFunctionLike(decl) && !(ts.isInterfaceDeclaration(decl) && decl.typeParameters && decl.typeParameters.filter( + param => !param.default + ).length > typeParamsNum) + ) } return null; @@ -781,7 +790,7 @@ export class AstConverter { } let symbol = this.typeChecker.getSymbolAtLocation(type.expression); - let declaration = this.getFirstDeclaration(symbol); + let declaration = this.getFirstDeclaration(symbol, typeArguments.length); // class can implement itself, but in overwhelming majority of cases this was not the intention of the declaration author - see https://stackoverflow.com/questions/62418219/class-implementing-itself-instead-of-inheriting-an-eponymous-interface-in-outer if (declaration != parent) { diff --git a/typescript/ts-converter/src/Dependency.ts b/typescript/ts-converter/src/Dependency.ts index 1560f202c..ee3ad67ff 100644 --- a/typescript/ts-converter/src/Dependency.ts +++ b/typescript/ts-converter/src/Dependency.ts @@ -45,7 +45,7 @@ export class TranslateSubsetOfSymbolsDependency implements Dependency { symbols.forEach(node => { let parent = node.parent; while (parent) { - if (ts.isModuleDeclaration(parent)) { + if (ts.isModuleDeclaration(parent) || ts.isVariableStatement(parent)) { parentUids.add(parent); } parent = parent.parent; @@ -78,7 +78,7 @@ export class TranslateSubsetOfSymbolsDependency implements Dependency { return true; } - if (ts.isModuleDeclaration(node) && this.parentUids.has(node)) { + if ((ts.isModuleDeclaration(node) || ts.isVariableStatement(node)) && this.parentUids.has(node)) { return true; } diff --git a/typescript/ts-converter/src/DependencyBuilder.ts b/typescript/ts-converter/src/DependencyBuilder.ts index 965624fa3..cf20bc90f 100644 --- a/typescript/ts-converter/src/DependencyBuilder.ts +++ b/typescript/ts-converter/src/DependencyBuilder.ts @@ -71,7 +71,7 @@ export class DependencyBuilder { for (let declaration of declarations) { if (this.checkedReferences.has(declaration)) { - return; + continue; } this.checkedReferences.add(declaration); let sourceFile = declaration.getSourceFile(); @@ -103,7 +103,7 @@ export class DependencyBuilder { this.checkReferences(node.type) } else if (ts.isHeritageClause(node)) { for (let type of node.types) { - this.checkReferences(type); + this.checkReferences(type.expression); } } else if (ts.isExportDeclaration(node)) { if (node.exportClause) { diff --git a/typescript/ts-converter/src/ExportContext.ts b/typescript/ts-converter/src/ExportContext.ts index a5f499b84..93ec26339 100644 --- a/typescript/ts-converter/src/ExportContext.ts +++ b/typescript/ts-converter/src/ExportContext.ts @@ -14,7 +14,7 @@ function resolveName(node: ts.Node): string | null { return null; } -export function resolveDeclarations(node: ts.Identifier, typeChecker: ts.TypeChecker): Array { +export function resolveDeclarations(node: ts.Node, typeChecker: ts.TypeChecker): Array { let symbolAtLocation = typeChecker.getSymbolAtLocation(node); if (symbolAtLocation) { diff --git a/typescript/ts-converter/src/ast/AstFactory.ts b/typescript/ts-converter/src/ast/AstFactory.ts index f3f52619c..4e213f8ee 100644 --- a/typescript/ts-converter/src/ast/AstFactory.ts +++ b/typescript/ts-converter/src/ast/AstFactory.ts @@ -33,6 +33,7 @@ import { CaseDeclarationProto, ClassDeclarationProto, ConstructorDeclarationProto, + ConstructSignatureDeclarationProto, ContinueStatementDeclarationProto, DefinitionInfoDeclarationProto, EnumDeclarationProto, @@ -143,6 +144,17 @@ export class AstFactory { return memberProto; } + createConstructSignatureDeclaration(parameters: Array, type: TypeDeclaration, typeParams: Array): MemberDeclaration { + let callSignature = new ConstructSignatureDeclarationProto(); + callSignature.setParametersList(parameters); + callSignature.setType(type); + callSignature.setTypeparametersList(typeParams); + + let memberProto = new MemberDeclarationProto(); + memberProto.setConstructsignature(callSignature); + return memberProto; + } + createClassDeclaration(name: NameEntity, members: Array, typeParams: Array, parentEntities: Array, modifiers: Array, definitions: Array, uid: string): ClassDeclaration { let classDeclaration = new ClassDeclarationProto(); classDeclaration.setName(name); diff --git a/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/DeclarationLowering.kt b/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/DeclarationLowering.kt index 2e22351b1..db8aa9d07 100644 --- a/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/DeclarationLowering.kt +++ b/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/DeclarationLowering.kt @@ -7,6 +7,7 @@ import org.jetbrains.dukat.ownerContext.wrap import org.jetbrains.dukat.tsmodel.CallSignatureDeclaration import org.jetbrains.dukat.tsmodel.ClassDeclaration import org.jetbrains.dukat.tsmodel.ClassLikeDeclaration +import org.jetbrains.dukat.tsmodel.ConstructSignatureDeclaration import org.jetbrains.dukat.tsmodel.ConstructorDeclaration import org.jetbrains.dukat.tsmodel.Declaration import org.jetbrains.dukat.tsmodel.FunctionDeclaration @@ -68,6 +69,16 @@ interface DeclarationLowering : TopLevelDeclarationLowering, DeclarationStatemen ) } + fun lowerConstructSignatureDeclaration(declaration: ConstructSignatureDeclaration, owner: NodeOwner?): ConstructSignatureDeclaration { + return declaration.copy( + type = lowerParameterValue(declaration.type, owner.wrap(declaration)), + parameters = declaration.parameters.map { parameter -> lowerParameterDeclaration(parameter, owner.wrap(declaration)) }, + typeParameters = declaration.typeParameters.map { typeParameter -> + typeParameter.copy(constraints = typeParameter.constraints.map { constraint -> lowerParameterValue(constraint, owner.wrap(declaration)) }) + } + ) + } + fun lowerIndexSignatureDeclaration(declaration: IndexSignatureDeclaration, owner: NodeOwner?): IndexSignatureDeclaration { return declaration.copy( parameters = declaration.parameters.map { indexType -> lowerParameterDeclaration(indexType, owner.wrap(declaration)) }, @@ -84,6 +95,7 @@ interface DeclarationLowering : TopLevelDeclarationLowering, DeclarationStatemen is MethodSignatureDeclaration -> lowerMethodSignatureDeclaration(declaration, newOwner) is MethodDeclaration -> lowerMethodDeclaration(declaration, newOwner) is CallSignatureDeclaration -> lowerCallSignatureDeclaration(declaration, newOwner) + is ConstructSignatureDeclaration -> lowerConstructSignatureDeclaration(declaration, newOwner) is IndexSignatureDeclaration -> lowerIndexSignatureDeclaration(declaration, newOwner) else -> { logger.debug("[${this}] skipping ${declaration}") diff --git a/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/ProcessConstructorInterfaces.kt b/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/ProcessConstructorInterfaces.kt new file mode 100644 index 000000000..9120063cf --- /dev/null +++ b/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/ProcessConstructorInterfaces.kt @@ -0,0 +1,102 @@ +package org.jetbrains.dukat.tsLowerings + +import org.jetbrains.dukat.astCommon.IdentifierEntity +import org.jetbrains.dukat.ownerContext.NodeOwner +import org.jetbrains.dukat.tsmodel.ClassLikeDeclaration +import org.jetbrains.dukat.tsmodel.ConstructSignatureDeclaration +import org.jetbrains.dukat.tsmodel.HeritageClauseDeclaration +import org.jetbrains.dukat.tsmodel.InterfaceDeclaration +import org.jetbrains.dukat.tsmodel.ModuleDeclaration +import org.jetbrains.dukat.tsmodel.ParameterOwnerDeclaration +import org.jetbrains.dukat.tsmodel.SourceSetDeclaration +import org.jetbrains.dukat.tsmodel.VariableDeclaration +import org.jetbrains.dukat.tsmodel.types.ParameterValueDeclaration +import org.jetbrains.dukat.tsmodel.types.TypeDeclaration + +private class ReplaceTypesLowering(private val typesToReplace: Map, private val depth: Int) : DeclarationLowering { + private val newTypesToReplace = mutableMapOf() + + private fun findNewType(type: ParameterValueDeclaration): ParameterValueDeclaration? { + if (type is TypeDeclaration && type.typeReference != null) { + val uid = type.typeReference!!.uid + if (typesToReplace.containsKey(uid)) { + return typesToReplace.getValue(uid) + } + } + return null + } + + override fun lowerParameterValue( + declaration: ParameterValueDeclaration, + owner: NodeOwner? + ): ParameterValueDeclaration { + return findNewType(declaration) ?: declaration + } + + override fun lowerHeritageClause( + heritageClause: HeritageClauseDeclaration, + owner: NodeOwner? + ): HeritageClauseDeclaration { + val reference = heritageClause.typeReference + if (reference != null && typesToReplace.containsKey(reference.uid)) { + val newType = typesToReplace.getValue(reference.uid) + if (newType is TypeDeclaration) { + return heritageClause.copy(name = newType.value, typeArguments = newType.params, typeReference = newType.typeReference) + } + } + return heritageClause + } + + override fun lowerVariableDeclaration(declaration: VariableDeclaration, owner: NodeOwner?): VariableDeclaration { + val newType = findNewType(declaration.type) + if (newType != null) { + newTypesToReplace[declaration.uid] = newType + return declaration.copy(type = newType) + } + return declaration + } + + override fun lower(source: SourceSetDeclaration): SourceSetDeclaration { + val newSource = super.lower(source) + return if (depth == 0) { + ReplaceTypesLowering(newTypesToReplace, depth + 1).lower(newSource) + } else { + newSource + } + } +} + +private class ProcessConstructorInterfacesLowering : DeclarationLowering { + + private val typesToReplace = mutableMapOf() + + private fun determineCommonReturnType(constructors: List): ParameterValueDeclaration? { + return constructors[0].type + } + + override fun lowerInterfaceDeclaration( + declaration: InterfaceDeclaration, + owner: NodeOwner? + ): InterfaceDeclaration { + val constructSignatures = declaration.members.filterIsInstance() + if (constructSignatures.isEmpty()) { + return declaration + } + val commonReturnType = determineCommonReturnType(constructSignatures) + if (commonReturnType is TypeDeclaration && commonReturnType.value == IdentifierEntity("Array")) { + typesToReplace[declaration.uid] = commonReturnType + } + return declaration + } + + override fun lower(source: SourceSetDeclaration): SourceSetDeclaration { + val newSource = super.lower(source) + return ReplaceTypesLowering(typesToReplace, 0).lower(newSource) + } +} + +class ProcessConstructorInterfaces : TsLowering { + override fun lower(source: SourceSetDeclaration): SourceSetDeclaration { + return ProcessConstructorInterfacesLowering().lower(source) + } +} \ No newline at end of file diff --git a/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/specifyUnionType.kt b/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/specifyUnionType.kt index 63aab1503..c2041f3c4 100644 --- a/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/specifyUnionType.kt +++ b/typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/specifyUnionType.kt @@ -16,6 +16,7 @@ import org.jetbrains.dukat.tsmodel.GeneratedInterfaceReferenceDeclaration import org.jetbrains.dukat.tsmodel.ImportEqualsDeclaration import org.jetbrains.dukat.tsmodel.InterfaceDeclaration import org.jetbrains.dukat.tsmodel.CallableMemberDeclaration +import org.jetbrains.dukat.tsmodel.ConstructSignatureDeclaration import org.jetbrains.dukat.tsmodel.MethodDeclaration import org.jetbrains.dukat.tsmodel.MethodSignatureDeclaration import org.jetbrains.dukat.tsmodel.ModuleDeclaration @@ -66,6 +67,7 @@ private fun CallableMemberDeclaration.copyWithParams(params: List copy(parameters = params) is IndexSignatureDeclaration -> copy(parameters = params) is MethodDeclaration -> copy(parameters = params) + is ConstructSignatureDeclaration -> copy(parameters = params) else -> raiseConcern("can not update params for ${this}") { this } } } diff --git a/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceModels.kt b/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceModels.kt index fe20b0c73..4e66c5c3f 100644 --- a/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceModels.kt +++ b/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceModels.kt @@ -245,14 +245,14 @@ internal class DocumentConverter( typeResolved.value == aliasName } - private fun ReferenceEntity.getFqName(): NameEntity? { - return uidToNameMapper[uid]?.fqName + private fun ReferenceEntity?.getFqName(ownerName: NameEntity): NameEntity? { + return this?.let { uidToNameMapper[uid]?.fqName } ?: if (KotlinStdlibEntities.contains(ownerName)) { + KLIBROOT.appendLeft(ownerName) + } else null } private fun TypeDeclaration.getFqName(): NameEntity? { - return typeReference?.getFqName() ?: if (KotlinStdlibEntities.contains(value)) { - KLIBROOT.appendLeft(value) - } else null + return typeReference.getFqName(value) } private fun ClassLikeDeclaration.processMembers(): Members { @@ -272,7 +272,7 @@ internal class DocumentConverter( private fun HeritageClauseDeclaration.convertToModel(): HeritageModel { val isNamedImport = typeReference?.origin == ReferenceOriginDeclaration.NAMED_IMPORT if (isNamedImport) { - typeReference?.getFqName()?.let { resolvedName -> + typeReference.getFqName(name)?.let { resolvedName -> imports.add(ImportModel(resolvedName, name.rightMost())) } } @@ -280,7 +280,7 @@ internal class DocumentConverter( val fqName = if (isNamedImport) { name } else { - typeReference?.getFqName() + typeReference.getFqName(name) } return HeritageModel( value = TypeValueModel(name, emptyList(), null, fqName), @@ -407,7 +407,7 @@ internal class DocumentConverter( name, typeParams, meta?.processMeta(), - typeReference?.getFqName(), + typeReference.getFqName(name), nullable ) diff --git a/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceNodes.kt b/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceNodes.kt index 00aa73f5d..d8611705b 100644 --- a/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceNodes.kt +++ b/typescript/ts-model-introduction/src/org/jetbrains/dukat/nodeIntroduction/introduceNodes.kt @@ -6,6 +6,7 @@ import org.jetbrains.dukat.astCommon.TopLevelEntity import org.jetbrains.dukat.panic.raiseConcern import org.jetbrains.dukat.tsmodel.CallSignatureDeclaration import org.jetbrains.dukat.tsmodel.ClassDeclaration +import org.jetbrains.dukat.tsmodel.ConstructSignatureDeclaration import org.jetbrains.dukat.tsmodel.ConstructorDeclaration import org.jetbrains.dukat.tsmodel.EnumDeclaration import org.jetbrains.dukat.tsmodel.FunctionDeclaration @@ -34,6 +35,7 @@ fun convertMemberDeclaration(declaration: MemberEntity, inDeclaredDeclaration: B is PropertyDeclaration -> convertPropertyDeclaration(declaration, inDeclaredDeclaration) is IndexSignatureDeclaration -> declaration is ConstructorDeclaration -> declaration + is ConstructSignatureDeclaration -> null else -> raiseConcern("unknown member declaration ${declaration::class.java}") { null } } } diff --git a/typescript/ts-model-proto/src/tsdeclarations.proto b/typescript/ts-model-proto/src/tsdeclarations.proto index ef87bfbbc..9db29f34b 100644 --- a/typescript/ts-model-proto/src/tsdeclarations.proto +++ b/typescript/ts-model-proto/src/tsdeclarations.proto @@ -97,6 +97,12 @@ message CallSignatureDeclarationProto { repeated TypeParameterDeclarationProto typeParameters = 3; } +message ConstructSignatureDeclarationProto { + repeated ParameterDeclarationProto parameters = 1; + ParameterValueDeclarationProto type = 2; + repeated TypeParameterDeclarationProto typeParameters = 3; +} + message ConstructorDeclarationProto { repeated ParameterDeclarationProto parameters = 1; repeated TypeParameterDeclarationProto typeParameters = 2; @@ -178,6 +184,7 @@ message MemberDeclarationProto { MethodSignatureDeclarationProto methodSignature = 4; PropertyDeclarationProto property = 5; MethodDeclarationProto method = 6; + ConstructSignatureDeclarationProto constructSignature = 7; } } diff --git a/typescript/ts-model/src/org/jetbrains/dukat/tsmodel/ConstructSignatureDeclaration.kt b/typescript/ts-model/src/org/jetbrains/dukat/tsmodel/ConstructSignatureDeclaration.kt new file mode 100644 index 000000000..28346fd8f --- /dev/null +++ b/typescript/ts-model/src/org/jetbrains/dukat/tsmodel/ConstructSignatureDeclaration.kt @@ -0,0 +1,9 @@ +package org.jetbrains.dukat.tsmodel + +import org.jetbrains.dukat.tsmodel.types.ParameterValueDeclaration + +data class ConstructSignatureDeclaration( + override val parameters: List, + override val type: ParameterValueDeclaration, + override val typeParameters: List +) : CallableMemberDeclaration, ParameterOwnerDeclaration, FunctionLikeDeclaration \ No newline at end of file diff --git a/typescript/ts-model/src/org/jetbrains/dukat/tsmodel/factory/convertProtobuf.kt b/typescript/ts-model/src/org/jetbrains/dukat/tsmodel/factory/convertProtobuf.kt index d6eaf29c7..bae606342 100644 --- a/typescript/ts-model/src/org/jetbrains/dukat/tsmodel/factory/convertProtobuf.kt +++ b/typescript/ts-model/src/org/jetbrains/dukat/tsmodel/factory/convertProtobuf.kt @@ -11,6 +11,7 @@ import org.jetbrains.dukat.tsmodel.BreakStatementDeclaration import org.jetbrains.dukat.tsmodel.CallSignatureDeclaration import org.jetbrains.dukat.tsmodel.CaseDeclaration import org.jetbrains.dukat.tsmodel.ClassDeclaration +import org.jetbrains.dukat.tsmodel.ConstructSignatureDeclaration import org.jetbrains.dukat.tsmodel.ConstructorDeclaration import org.jetbrains.dukat.tsmodel.ContinueStatementDeclaration import org.jetbrains.dukat.tsmodel.DefinitionInfoDeclaration @@ -112,6 +113,7 @@ import org.jetbrains.dukat.tsmodelproto.CallSignatureDeclarationProto import org.jetbrains.dukat.tsmodelproto.CaseDeclarationProto import org.jetbrains.dukat.tsmodelproto.ClassDeclarationProto import org.jetbrains.dukat.tsmodelproto.ConditionalExpressionDeclarationProto +import org.jetbrains.dukat.tsmodelproto.ConstructSignatureDeclarationProto import org.jetbrains.dukat.tsmodelproto.ConstructorDeclarationProto import org.jetbrains.dukat.tsmodelproto.ContinueStatementDeclarationProto import org.jetbrains.dukat.tsmodelproto.DefinitionInfoDeclarationProto @@ -509,6 +511,14 @@ fun CallSignatureDeclarationProto.convert(): CallSignatureDeclaration { ) } +fun ConstructSignatureDeclarationProto.convert(): ConstructSignatureDeclaration { + return ConstructSignatureDeclaration( + parametersList.map { it.convert() }, + type.convert(), + typeParametersList.map { it.convert() } + ) +} + fun MemberDeclarationProto.convert(): MemberDeclaration { return when { hasConstructorDeclaration() -> constructorDeclaration.convert() @@ -517,6 +527,7 @@ fun MemberDeclarationProto.convert(): MemberDeclaration { hasIndexSignature() -> indexSignature.convert() hasCallSignature() -> callSignature.convert() hasMethod() -> method.convert() + hasConstructSignature() -> constructSignature.convert() else -> throw Exception("unknown MemberEntityProto: ${this}") } } diff --git a/typescript/ts-translator/src/org/jetbrains/dukat/ts/translator/TypescriptLowerer.kt b/typescript/ts-translator/src/org/jetbrains/dukat/ts/translator/TypescriptLowerer.kt index 42565a1fc..e84441e54 100644 --- a/typescript/ts-translator/src/org/jetbrains/dukat/ts/translator/TypescriptLowerer.kt +++ b/typescript/ts-translator/src/org/jetbrains/dukat/ts/translator/TypescriptLowerer.kt @@ -56,6 +56,7 @@ import org.jetbrains.dukat.tsLowerings.SpecifyUnionType import org.jetbrains.dukat.tsLowerings.lower import org.jetbrains.dukat.tsmodel.SourceSetDeclaration import org.jetbrains.dukat.nodeIntroduction.introduceModels +import org.jetbrains.dukat.tsLowerings.ProcessConstructorInterfaces import org.jetbrains.dukat.tsLowerings.ProcessOptionalMethods open class TypescriptLowerer( @@ -69,6 +70,7 @@ open class TypescriptLowerer( IntroduceMissingConstructors(), AddPackageName(packageName), RemoveThisParameters(), + ProcessConstructorInterfaces(), MergeModules(), MergeClassLikes(), IntroduceSyntheticExportModifiers(),