From 3617c1388cb235c9ed64a098901819e3e51a4145 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Tue, 19 Oct 2021 01:10:35 +0300 Subject: [PATCH] [JS IR] improve the hacky fix --- .../ir/backend/js/utils/JsGenerationContext.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/JsGenerationContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/JsGenerationContext.kt index 943e5f457f5..5445d190abc 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/JsGenerationContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/JsGenerationContext.kt @@ -27,7 +27,8 @@ class JsGenerationContext( val currentFile: IrFile, val currentFunction: IrFunction?, val staticContext: JsStaticContext, - val localNames: LocalNameGenerator? = null + val localNames: LocalNameGenerator? = null, + private val nameCache: MutableMap = mutableMapOf() ): IrNamer by staticContext { fun newFile(file: IrFile, func: IrFunction? = null, localNames: LocalNameGenerator? = null): JsGenerationContext { return JsGenerationContext( @@ -35,9 +36,8 @@ class JsGenerationContext( currentFunction = func, staticContext = staticContext, localNames = localNames, - ).also { - it.nameCache += nameCache - } + nameCache = nameCache, + ) } fun newDeclaration(func: IrFunction? = null, localNames: LocalNameGenerator? = null): JsGenerationContext { @@ -46,13 +46,10 @@ class JsGenerationContext( currentFunction = func, staticContext = staticContext, localNames = localNames, - ).also { - it.nameCache += nameCache - } + nameCache = nameCache, + ) } - private val nameCache = mutableMapOf() - fun getNameForValueDeclaration(declaration: IrDeclarationWithName): JsName { return nameCache.getOrPut(declaration) { val name = localNames!!.variableNames.names[declaration]