From ee2aa6d67f0e0e72e0f20538eb720cedf47b3e58 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Fri, 1 Mar 2024 09:37:00 +0000 Subject: [PATCH] [K/JS] Fix interfaces inside TypeScript definitions if they have only an external interface parent ^KT-64708 Fixed Merge-request: KT-MR-14665 Merged-by: Artem Kobzar --- .../kotlin/ir/backend/js/export/ExportModelGenerator.kt | 2 +- .../interfaces-in-exported-file/interfaces.d.ts | 8 ++++++++ .../interfaces-in-exported-file/interfaces.kt | 8 ++++++++ .../testData/typescript-export/interfaces/interfaces.d.ts | 8 ++++++++ .../testData/typescript-export/interfaces/interfaces.kt | 8 ++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) 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 84c7783ffa9..eeee825ebbe 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 @@ -379,7 +379,7 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac private fun IrClass.shouldContainImplementationOfMagicProperty(superTypes: Iterable): Boolean { return !isExternal && superTypes.any { val superClass = it.classOrNull?.owner ?: return@any false - superClass.isInterface && superClass.isExported(context) || superClass.isJsImplicitExport() + superClass.isInterface && it.shouldAddMagicPropertyOfSuper() || superClass.isJsImplicitExport() } } 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 7c1324ebc4e..c814c106b18 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 @@ -5,6 +5,8 @@ declare namespace JS_TESTS { readonly required: number; readonly notRequired?: Nullable; } + interface ExportedParentInterface { + } } namespace foo { interface TestInterface { @@ -45,5 +47,11 @@ declare namespace JS_TESTS { readonly "foo.InterfaceWithCompanion": unique symbol; }; } + interface ExportedChildInterface extends foo.ExportedParentInterface { + bar(): void; + readonly __doNotUseOrImplementIt: { + readonly "foo.ExportedChildInterface": unique symbol; + }; + } } } 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 5e848f11755..333afe7985b 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 @@ -65,4 +65,12 @@ interface InterfaceWithCompanion { companion object { fun foo() = "String" } +} + + +external interface ExportedParentInterface + + +interface ExportedChildInterface : ExportedParentInterface { + fun bar() } \ 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 7c1324ebc4e..c814c106b18 100644 --- a/js/js.translator/testData/typescript-export/interfaces/interfaces.d.ts +++ b/js/js.translator/testData/typescript-export/interfaces/interfaces.d.ts @@ -5,6 +5,8 @@ declare namespace JS_TESTS { readonly required: number; readonly notRequired?: Nullable; } + interface ExportedParentInterface { + } } namespace foo { interface TestInterface { @@ -45,5 +47,11 @@ declare namespace JS_TESTS { readonly "foo.InterfaceWithCompanion": unique symbol; }; } + interface ExportedChildInterface extends foo.ExportedParentInterface { + bar(): void; + readonly __doNotUseOrImplementIt: { + readonly "foo.ExportedChildInterface": unique symbol; + }; + } } } diff --git a/js/js.translator/testData/typescript-export/interfaces/interfaces.kt b/js/js.translator/testData/typescript-export/interfaces/interfaces.kt index ae5024d4fd4..504a2504d58 100644 --- a/js/js.translator/testData/typescript-export/interfaces/interfaces.kt +++ b/js/js.translator/testData/typescript-export/interfaces/interfaces.kt @@ -61,4 +61,12 @@ interface InterfaceWithCompanion { companion object { fun foo() = "String" } +} + +@JsExport +external interface ExportedParentInterface + +@JsExport +interface ExportedChildInterface : ExportedParentInterface { + fun bar() } \ No newline at end of file