Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.

Commit 16ef64d

Browse files
epabstSchahen
authored andcommitted
Fix error "External class constructor cannot have a property parameter" (#118)
1 parent 7e224a5 commit 16ef64d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main/kotlin/ts2kt/TsClassToKt.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ class TsClassToKt(
3434

3535
override fun visitConstructorDeclaration(node: ConstructorDeclaration) {
3636
val paramsOverloads = node.parameters.toKotlinParamsOverloads(typeMapper)
37-
paramsOfConstructors.addAll(paramsOverloads)
37+
val nonVarParamOverloads = paramsOverloads.map { params ->
38+
params.map { param ->
39+
if (param.isVar) {
40+
addVariable(null, param.name.value, param.type.type, isVar = param.isVar)
41+
}
42+
param.copy(isVar = false)
43+
}
44+
}
45+
paramsOfConstructors.addAll(nonVarParamOverloads)
3846

3947
assert(node.body == null, "A constructor in declarations file should not have body, constructor in '${this.name}")
4048
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package withPropertyDeclaration
22

3-
external open class Foo(open var x: Any)
4-
external open class Bar(open var n: Number, open var a: Any)
3+
external open class Foo(x: Any) {
4+
open var x: Any = definedExternally
5+
}
6+
external open class Bar(n: Number, a: Any) {
7+
open var n: Number = definedExternally
8+
open var a: Any = definedExternally
9+
}

0 commit comments

Comments
 (0)