1
1
package ts2kt
2
2
3
+ import converter.replaceTypeParameters
3
4
import ts2kt.kotlin.ast.*
4
5
import typescriptServices.ts.ImportEqualsDeclaration
5
6
import typescriptServices.ts.Symbol
@@ -14,8 +15,13 @@ abstract class TypeScriptToKotlinBase(
14
15
open val defaultAnnotations: List <KtAnnotation > = listOf ()
15
16
16
17
open fun addVariable (symbol : Symbol ? , name : String , type : KtType , extendsType : KtType ? = null, typeParams : List <KtTypeParam >? = null, isVar : Boolean = true, needsNoImpl : Boolean = true, additionalAnnotations : List <KtAnnotation > = listOf(), isOverride : Boolean = false) {
18
+ val (typeParamsToKeep, typeParamsToReplace) = (typeParams ? : emptyList()).partition {
19
+ typeParam -> extendsType?.typeArgs?.any { it.qualifiedName.name == typeParam.name } ? : false
20
+ }
21
+ val substitution = typeParamsToReplace.map { it.name.value to (it.upperBound ? : KtType (ANY )).copy(comment = it.name.value) }.toMap()
22
+
17
23
val annotations = defaultAnnotations + additionalAnnotations
18
- addDeclaration(symbol, KtVariable (KtName (name), KtTypeAnnotation (type) , extendsType?.let { KtHeritageType (it) }, annotations, typeParams , isVar = isVar, needsNoImpl = needsNoImpl, isInInterface = isInterface, isOverride = isOverride, hasOpenModifier = hasMembersOpenModifier))
24
+ addDeclaration(symbol, KtVariable (KtName (name), KtTypeAnnotation (type.replaceTypeParameters(substitution)) , extendsType?.let { KtHeritageType (it) }, annotations, typeParamsToKeep , isVar = isVar, needsNoImpl = needsNoImpl, isInInterface = isInterface, isOverride = isOverride, hasOpenModifier = hasMembersOpenModifier))
19
25
}
20
26
21
27
open fun addFunction (symbol : Symbol ? , name : String , callSignature : KtCallSignature , extendsType : KtType ? = null, needsNoImpl : Boolean = true, additionalAnnotations : List <KtAnnotation > = listOf(), isOverride : Boolean = false, isOperator : Boolean = false) {
0 commit comments