diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index 45a4da2b44a..f3f2da6130c 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -154,6 +154,9 @@ class K2JSCompilerArguments : CommonCompilerArguments() { @Argument(value = "-Xir-legacy-property-access", description = "Force property access via JS properties (requires -Xir-export-all)") var irLegacyPropertyAccess: Boolean by FreezableVar(false) + @Argument(value = "-Xir-base-class-in-metadata", description = "Write base class into metadata") + var irBaseClassInMetadata: Boolean by FreezableVar(false) + @Argument(value = "-Xir-per-module", description = "Splits generated .js per-module") var irPerModule: Boolean by FreezableVar(false) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index 603482633da..aad04d39c65 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -276,6 +276,7 @@ class K2JsIrCompiler : CLICompiler() { relativeRequirePath = true, propertyLazyInitialization = arguments.irPropertyLazyInitialization, legacyPropertyAccess = arguments.irLegacyPropertyAccess, + baseClassIntoMetadata = arguments.irBaseClassInMetadata, ) val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!! diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index 87d2be490a5..dd6d72ab216 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -48,6 +48,7 @@ class JsIrBackendContext( val dceRuntimeDiagnostic: DceRuntimeDiagnostic? = null, val propertyLazyInitialization: Boolean = false, val legacyPropertyAccess: Boolean = false, + val baseClassIntoMetadata: Boolean = false, ) : JsCommonBackendContext { val fileToInitializationFuns: MutableMap = mutableMapOf() val fileToInitializerPureness: MutableMap = mutableMapOf() diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index 1a84a4949a0..2c2b0fee8a0 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -53,6 +53,7 @@ fun compile( relativeRequirePath: Boolean = false, propertyLazyInitialization: Boolean, legacyPropertyAccess: Boolean = false, + baseClassIntoMetadata: Boolean = false, ): CompilerResult { val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) = loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory, forceAllJs) @@ -74,7 +75,8 @@ fun compile( es6mode = es6mode, dceRuntimeDiagnostic = dceRuntimeDiagnostic, propertyLazyInitialization = propertyLazyInitialization, - legacyPropertyAccess = legacyPropertyAccess + legacyPropertyAccess = legacyPropertyAccess, + baseClassIntoMetadata = baseClassIntoMetadata ) // Load declarations referenced during `context` initialization diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsClassGenerator.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsClassGenerator.kt index 2d154138536..1df2d0b5b2d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsClassGenerator.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsClassGenerator.kt @@ -247,7 +247,12 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo val symbol = it.classifierOrFail as IrClassSymbol val isFunctionType = it.run { isFunctionOrKFunction() || isSuspendFunctionOrKFunction() } // TODO: make sure that there is a test which breaks when isExternal is used here instead of isEffectivelyExternal - if (/*symbol.isInterface && */!it.isAny() && !isFunctionType && !symbol.isEffectivelyExternal) { + val requireInMetadata = if (context.staticContext.backendContext.baseClassIntoMetadata) + !it.isAny() + else + symbol.isInterface + + if (requireInMetadata && !isFunctionType && !symbol.isEffectivelyExternal) { JsNameRef(context.getNameForClass(symbol.owner)) } else null }