JS: switch off inlined local declaration deduplication (KT-30877 fixed)

(cherry picked from commit 681e8dd9682afdea822af8e0ad76c9242831e639)
This commit is contained in:
Anton Bannykh
2019-04-05 23:23:54 +03:00
parent 2dee506022
commit 9b5c8bbac9
2 changed files with 12 additions and 32 deletions
@@ -29,8 +29,6 @@ sealed class InliningScope {
protected abstract fun addImport(tag: String, vars: JsVars)
protected open fun addLocalDeclarationBinding(inlineFunctionTag: String, name: JsName, index: Int) {}
protected open fun preprocess(statement: JsStatement) {}
private val publicFunctionCache = mutableMapOf<String, JsFunction>()
@@ -82,26 +80,16 @@ sealed class InliningScope {
}
}
val localDeclarations = mutableListOf<JsName>()
copiedStatements.asSequence()
.flatMap { node -> collectDefinedNamesInAllScopes(node).asSequence() }
.filter { name -> !newReplacements.containsKey(name) }
.forEach { name ->
val alias = JsScope.declareTemporaryName(name.ident)
alias.copyMetadataFrom(name)
localDeclarations += alias
val replacement = JsAstUtils.pureFqn(alias, null)
newReplacements[name] = replacement
}
// Add local declarations to the name bindings in order to correctly rename usages of the same imported local declaraions
definition.tag?.let { tag ->
localDeclarations.forEachIndexed { index, name ->
addLocalDeclarationBinding(tag, name, index)
}
}
// Apply renaming and restore the static ref links
JsBlock(copiedStatements).let {
replaceNames(it, newReplacements)
@@ -189,10 +177,6 @@ class ImportIntoFragmentInliningScope private constructor(
addNameBinding(name, tag)
}
override fun addLocalDeclarationBinding(inlineFunctionTag: String, name: JsName, index: Int) {
addNameBinding(name, "\$local:$inlineFunctionTag:$index")
}
override fun addInlinedDeclaration(tag: String?, declaration: JsStatement) {
if (tag != null) {
fragment.inlinedLocalDeclarations.computeIfAbsent(tag) { JsGlobalBlock() }.statements.add(declaration)
@@ -190,7 +190,7 @@ class Merger(
return rootNode
}
private val importedFunctionWrappers = mutableMapOf<String, JsGlobalBlock>()
private val additionalFakeOverrides = mutableListOf<JsStatement>()
private fun mergeNames() {
for (fragment in fragments) {
@@ -204,15 +204,23 @@ class Merger(
}
}
fragment.inlinedLocalDeclarations.forEach { (_, imports) ->
imports.statements.forEach { s ->
if (s.isFakeOverrideAssignment()) {
additionalFakeOverrides += s
} else {
declarationBlock.statements += s
}
}
}
declarationBlock.statements += fragment.declarationBlock
initializerBlock.statements += fragment.initializerBlock
fragment.tryUpdateTests()
fragment.tryUpdateMain()
addExportStatements(fragment)
fragment.inlinedLocalDeclarations.forEach { (tag, imports) ->
importedFunctionWrappers.putIfAbsent(tag, imports)
}
classes += fragment.classes
}
@@ -241,18 +249,6 @@ class Merger(
this += importBlock.statements
addClassPrototypes(this)
// TODO better placing?
val additionalFakeOverrides = mutableListOf<JsStatement>()
importedFunctionWrappers.values.forEach { block ->
block.statements.forEach { s ->
if (s.isFakeOverrideAssignment()) {
additionalFakeOverrides += s
} else {
this += s
}
}
}
this += declarationBlock.statements
this += exportBlock.statements
addClassPostDeclarations(this)