JS: prevent IDL2K from generating delegated constructor calls
This commit is contained in:
@@ -133,8 +133,6 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(superClasses.size <= 1) { "Type ${iface.name} should have one or zero super classes but found ${superClasses.map { it.name }}" }
|
assert(superClasses.size <= 1) { "Type ${iface.name} should have one or zero super classes but found ${superClasses.map { it.name }}" }
|
||||||
val superClass = superClasses.singleOrNull()
|
|
||||||
val superConstructor = superClass?.findConstructors()?.firstOrNull() ?: EMPTY_CONSTRUCTOR
|
|
||||||
|
|
||||||
val declaredConstructors = iface.findConstructors()
|
val declaredConstructors = iface.findConstructors()
|
||||||
val entityKind = resolveDefinitionKind(repository, iface, declaredConstructors)
|
val entityKind = resolveDefinitionKind(repository, iface, declaredConstructors)
|
||||||
@@ -149,23 +147,14 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT
|
|||||||
|
|
||||||
val primaryConstructorWithCall = primaryConstructor?.let { constructor ->
|
val primaryConstructorWithCall = primaryConstructor?.let { constructor ->
|
||||||
val constructorAsFunction = generateConstructorAsFunction(repository, constructor)
|
val constructorAsFunction = generateConstructorAsFunction(repository, constructor)
|
||||||
val superCall = when {
|
|
||||||
superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, superClass.name, superConstructor)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstructorWithSuperTypeCall(constructorAsFunction, constructor, superCall)
|
ConstructorWithSuperTypeCall(constructorAsFunction, constructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
val secondaryConstructorsWithCall = secondaryConstructors.map { secondaryConstructor ->
|
val secondaryConstructorsWithCall = secondaryConstructors.map { secondaryConstructor ->
|
||||||
val constructorAsFunction = generateConstructorAsFunction(repository, secondaryConstructor)
|
val constructorAsFunction = generateConstructorAsFunction(repository, secondaryConstructor)
|
||||||
val initCall = when {
|
|
||||||
primaryConstructorWithCall != null -> superOrPrimaryConstructorCall(constructorAsFunction, "this", primaryConstructorWithCall.constructorAttribute)
|
|
||||||
superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, "super", superConstructor)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstructorWithSuperTypeCall(constructorAsFunction, secondaryConstructor, initCall)
|
ConstructorWithSuperTypeCall(constructorAsFunction, secondaryConstructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
return GenerateTraitOrClass(iface.name, iface.namespace, entityKind, (iface.superTypes + extensions.map { it.name }).distinct(),
|
return GenerateTraitOrClass(iface.name, iface.namespace, entityKind, (iface.superTypes + extensions.map { it.name }).distinct(),
|
||||||
@@ -184,15 +173,6 @@ fun generateConstructorAsFunction(repository: Repository, constructor: ExtendedA
|
|||||||
functionName = "constructor",
|
functionName = "constructor",
|
||||||
nativeGetterOrSetter = NativeGetterOrSetter.NONE)
|
nativeGetterOrSetter = NativeGetterOrSetter.NONE)
|
||||||
|
|
||||||
fun superOrPrimaryConstructorCall(constructorAsFunction: GenerateFunction, superClassName: String, superOrPrimaryConstructor: ExtendedAttribute): GenerateFunctionCall {
|
|
||||||
val constructorArgumentNames = constructorAsFunction.arguments.map { it.name }.toSet()
|
|
||||||
return GenerateFunctionCall(
|
|
||||||
name = superClassName,
|
|
||||||
arguments = superOrPrimaryConstructor.arguments.map { arg ->
|
|
||||||
if (arg.name in constructorArgumentNames) arg.name else "noImpl"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mapUnionType(it: UnionType) = GenerateTraitOrClass(
|
fun mapUnionType(it: UnionType) = GenerateTraitOrClass(
|
||||||
name = it.name,
|
name = it.name,
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ data class GenerateFunction(
|
|||||||
val override: Boolean
|
val override: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ConstructorWithSuperTypeCall(val constructor: GenerateFunction, val constructorAttribute: ExtendedAttribute, val initTypeCall: GenerateFunctionCall?)
|
data class ConstructorWithSuperTypeCall(val constructor: GenerateFunction, val constructorAttribute: ExtendedAttribute)
|
||||||
data class GenerateTraitOrClass(
|
data class GenerateTraitOrClass(
|
||||||
val name: String,
|
val name: String,
|
||||||
val namespace: String,
|
val namespace: String,
|
||||||
|
|||||||
@@ -156,10 +156,8 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
|
|||||||
}
|
}
|
||||||
|
|
||||||
val superTypesExclude = inheritanceExclude[iface.name] ?: emptySet()
|
val superTypesExclude = inheritanceExclude[iface.name] ?: emptySet()
|
||||||
val superCallName = primary?.initTypeCall?.name
|
|
||||||
val superTypesWithCalls =
|
val superTypesWithCalls =
|
||||||
(primary?.initTypeCall?.let { listOf(renderCall(it)) } ?: emptyList()) +
|
iface.superTypes.filter { it in allSuperTypesNames }.filter { it !in superTypesExclude } +
|
||||||
iface.superTypes.filter { it != superCallName && it in allSuperTypesNames }.filter { it !in superTypesExclude } +
|
|
||||||
(typeNamesToUnions[iface.name] ?: emptyList())
|
(typeNamesToUnions[iface.name] ?: emptyList())
|
||||||
|
|
||||||
if (superTypesWithCalls.isNotEmpty()) {
|
if (superTypesWithCalls.isNotEmpty()) {
|
||||||
@@ -173,11 +171,6 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
|
|||||||
append("constructor")
|
append("constructor")
|
||||||
renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keys), false)
|
renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keys), false)
|
||||||
|
|
||||||
if (secondary.initTypeCall != null) {
|
|
||||||
append(" : ")
|
|
||||||
append(renderCall(secondary.initTypeCall))
|
|
||||||
}
|
|
||||||
|
|
||||||
appendln()
|
appendln()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user