From f4d088a8863d41b97109ef97c12e56fe34ccc78e Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Tue, 14 Nov 2023 18:16:28 +0100 Subject: [PATCH] [K/JS] Don't add nested classes generated by plugins into ExportModel for interfaces ^KT-63184 Fixed --- .../ir/backend/js/export/ExportModelGenerator.kt | 1 + .../interfaces-in-exported-file/interfaces.d.ts | 5 +++++ .../interfaces-in-exported-file/interfaces.kt | 10 ++++++++++ .../typescript-export/interfaces/interfaces.d.ts | 5 +++++ .../typescript-export/interfaces/interfaces.kt | 10 ++++++++++ 5 files changed, 31 insertions(+) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt index b355eea783b..ac89f96e6d1 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt @@ -323,6 +323,7 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac members.addIfNotNull(exportProperty(candidate)?.withAttributesFor(candidate)) is IrClass -> { + if (klass.isInterface) continue val ec = exportClass(candidate)?.withAttributesFor(candidate) if (ec is ExportedClass) { nestedClasses.add(ec) diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts index 7a8cadd01cc..2da9c13373a 100644 --- a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts @@ -31,5 +31,10 @@ declare namespace JS_TESTS { } function processInterface(test: foo.TestInterface): string; function processOptionalInterface(a: foo.OptionalFieldsInterface): string; + interface InterfaceWithCompanion { + readonly __doNotUseOrImplementIt: { + readonly "foo.InterfaceWithCompanion": unique symbol; + }; + } } } \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt index f4bf253711a..b7289819a34 100644 --- a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt @@ -45,4 +45,14 @@ external interface OptionalFieldsInterface { fun processOptionalInterface(a: OptionalFieldsInterface): String { return "${a.required}${a.notRequired ?: "unknown"}" +} + +// KT-63184 + +interface InterfaceWithCompanion { + // Emulate added by plugin companion like kotlinx.serialization does + @Suppress("WRONG_EXPORTED_DECLARATION") + companion object { + fun foo() = "String" + } } \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces/interfaces.d.ts b/js/js.translator/testData/typescript-export/interfaces/interfaces.d.ts index 7a8cadd01cc..2da9c13373a 100644 --- a/js/js.translator/testData/typescript-export/interfaces/interfaces.d.ts +++ b/js/js.translator/testData/typescript-export/interfaces/interfaces.d.ts @@ -31,5 +31,10 @@ declare namespace JS_TESTS { } function processInterface(test: foo.TestInterface): string; function processOptionalInterface(a: foo.OptionalFieldsInterface): string; + interface InterfaceWithCompanion { + readonly __doNotUseOrImplementIt: { + readonly "foo.InterfaceWithCompanion": unique symbol; + }; + } } } \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces/interfaces.kt b/js/js.translator/testData/typescript-export/interfaces/interfaces.kt index caf5f7d364f..e63b1288391 100644 --- a/js/js.translator/testData/typescript-export/interfaces/interfaces.kt +++ b/js/js.translator/testData/typescript-export/interfaces/interfaces.kt @@ -41,4 +41,14 @@ external interface OptionalFieldsInterface { @JsExport fun processOptionalInterface(a: OptionalFieldsInterface): String { return "${a.required}${a.notRequired ?: "unknown"}" +} + +// KT-63184 +@JsExport +interface InterfaceWithCompanion { + // Emulate added by plugin companion like kotlinx.serialization does + @Suppress("WRONG_EXPORTED_DECLARATION") + companion object { + fun foo() = "String" + } } \ No newline at end of file