Skip to content

Commit

Permalink
Fix generation of class companion object
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrishchenko committed Jun 28, 2024
1 parent 6004ccf commit 5695845
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/converter/plugins/convertClassDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const convertClassDeclaration = createSimplePlugin((node, context, render
let companionObject = ""

if (staticMembers.length > 0) {
companionObject = `
companionObject = "\n" + `
companion object {
${staticMembers}${ifPresent(staticInjectedMembers, it => `\n${it}`)}
Expand Down
21 changes: 21 additions & 0 deletions test/functional/base/generated/class/simple.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Generated by Karakum - do not modify it manually!

@file:JsModule("sandbox-base/class/simple")
@file:Suppress(
"NON_EXTERNAL_DECLARATION_IN_INAPPROPRIATE_FILE",
)

package sandbox.base.`class`

external class SimpleClass {
var firstField: String
var secondField: Double
fun firstMethod(firstParam: String, secondParam: Double): Unit
fun secondMethod(firstParam: String, secondParam: Double): Boolean
companion object {
var firstStaticField: String
var secondStaticField: Double
fun firstStaticMethod(firstParam: String, secondParam: Double): Unit
fun secondStaticMethod(firstParam: String, secondParam: Double): Boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package sandbox.base.typeLiteral
external fun useRevalidator(): UseRevalidatorResult

external class MyClass {

companion object {
fun getDerivedStateFromProps(): MyClassGetDerivedStateFromPropsResult
}
Expand Down
13 changes: 13 additions & 0 deletions test/functional/base/lib/class/simple.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class SimpleClass {
static firstStaticField: string;
static secondStaticField: number;

static firstStaticMethod(firstParam: string, secondParam: number): void;
static secondStaticMethod(firstParam: string, secondParam: number): boolean;

firstField: string;
secondField: number;

firstMethod(firstParam: string, secondParam: number): void;
secondMethod(firstParam: string, secondParam: number): boolean;
}

0 comments on commit 5695845

Please sign in to comment.