[JS IR] Add flag with writing base class to metadata

This commit is contained in:
Ilya Goncharov
2021-05-11 12:04:40 +03:00
committed by TeamCityServer
parent 228c6879f5
commit 18cb8a1b9b
5 changed files with 14 additions and 2 deletions
@@ -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)
@@ -276,6 +276,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
relativeRequirePath = true,
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
legacyPropertyAccess = arguments.irLegacyPropertyAccess,
baseClassIntoMetadata = arguments.irBaseClassInMetadata,
)
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
@@ -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<IrFile, IrSimpleFunction?> = mutableMapOf()
val fileToInitializerPureness: MutableMap<IrFile, Boolean> = mutableMapOf()
@@ -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
@@ -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
}