chore: use CompositeBlock instead of GlobalBlock.
This commit is contained in:
@@ -97,7 +97,7 @@ private fun mergeStdlibParts(outputFile: File, wrapperFile: File, baseDir: File,
|
||||
}
|
||||
|
||||
private fun List<JsStatement>.createInsertionPlace(): JsBlock {
|
||||
val block = JsGlobalBlock()
|
||||
val block = JsCompositeBlock()
|
||||
|
||||
val visitor = object : JsVisitorWithContextImpl() {
|
||||
override fun visit(x: JsExpressionStatement, ctx: JsContext<in JsStatement>): Boolean {
|
||||
|
||||
@@ -172,8 +172,8 @@ class IrToJs(
|
||||
it.accept(IrFileToJsTransformer(), staticContext).statements
|
||||
}
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
processClassModels(staticContext.classModels, preDeclarationBlock, postDeclarationBlock)
|
||||
|
||||
val statements = mutableListOf<JsStatement>()
|
||||
@@ -421,7 +421,7 @@ private val IrModuleFragment.jsModuleName: String
|
||||
get() = name.asString().dropWhile { it == '<' }.dropLastWhile { it == '>' }
|
||||
|
||||
private fun List<JsStatement>.toJsCodeString(): String =
|
||||
JsGlobalBlock().also { it.statements += this }.toString()
|
||||
JsCompositeBlock().also { it.statements += this }.toString()
|
||||
|
||||
enum class JsGenerationGranularity {
|
||||
WHOLE_PROGRAM,
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ class IrDeclarationToJsTransformer : BaseIrElementToJsNodeTransformer<JsStatemen
|
||||
}
|
||||
|
||||
override fun visitScript(irScript: IrScript, context: JsGenerationContext): JsStatement {
|
||||
return JsGlobalBlock().apply {
|
||||
return JsCompositeBlock().apply {
|
||||
irScript.statements.forEach {
|
||||
statements +=
|
||||
if (it is IrDeclaration) it.accept(this@IrDeclarationToJsTransformer, context)
|
||||
|
||||
+1
-2
@@ -50,7 +50,7 @@ class IrElementToJsStatementTransformer : BaseIrElementToJsNodeTransformer<JsSta
|
||||
if (label != null) {
|
||||
JsLabel(label, JsBlock(wrappedStatements))
|
||||
} else {
|
||||
JsVirtualBlock(wrappedStatements)
|
||||
JsCompositeBlock(wrappedStatements)
|
||||
}
|
||||
} else {
|
||||
JsBlock(statements)
|
||||
@@ -67,7 +67,6 @@ class IrElementToJsStatementTransformer : BaseIrElementToJsNodeTransformer<JsSta
|
||||
}
|
||||
|
||||
override fun visitComposite(expression: IrComposite, context: JsGenerationContext): JsStatement {
|
||||
// TODO introduce JsCompositeBlock?
|
||||
return JsBlock(expression.statements.map { it.accept(this, context) })
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -8,9 +8,8 @@ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.JsStaticContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsCompositeBlock
|
||||
|
||||
class IrFileToJsTransformer(private val useBareParameterNames: Boolean = false) : BaseIrElementToJsNodeTransformer<JsBlock, JsStaticContext> {
|
||||
override fun visitFile(declaration: IrFile, data: JsStaticContext): JsBlock {
|
||||
@@ -20,7 +19,7 @@ class IrFileToJsTransformer(private val useBareParameterNames: Boolean = false)
|
||||
staticContext = data,
|
||||
useBareParameterNames = useBareParameterNames
|
||||
)
|
||||
val block = JsGlobalBlock()
|
||||
val block = JsCompositeBlock()
|
||||
|
||||
declaration.declarations.forEach {
|
||||
block.statements.add(it.accept(IrDeclarationToJsTransformer(), fileContext))
|
||||
|
||||
+2
-2
@@ -293,8 +293,8 @@ class IrModuleToJsTransformer(
|
||||
private fun generateModuleBody(modules: Iterable<IrModuleFragment>, staticContext: JsStaticContext): List<JsStatement> {
|
||||
val statements = mutableListOf<JsStatement>()
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
|
||||
statements.addWithComment("block: pre-declaration", preDeclarationBlock)
|
||||
|
||||
|
||||
+5
-5
@@ -34,7 +34,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
|
||||
if (baseClass != null && !baseClass.isAny()) baseClass.getClassRef(context) else null
|
||||
}
|
||||
private val classPrototypeRef = prototypeOf(classNameRef)
|
||||
private val classBlock = JsGlobalBlock()
|
||||
private val classBlock = JsCompositeBlock()
|
||||
private val classModel = JsIrClassModel(irClass)
|
||||
|
||||
private val es6mode = context.staticContext.backendContext.es6mode
|
||||
@@ -434,11 +434,11 @@ private val IrClassifierSymbol.isEffectivelyExternal get() = (owner as? IrDeclar
|
||||
class JsIrClassModel(val klass: IrClass) {
|
||||
val superClasses = klass.superTypes.map { it.classifierOrFail as IrClassSymbol }
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
}
|
||||
|
||||
class JsIrIcClassModel(val superClasses: List<JsName>) {
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
}
|
||||
+4
-4
@@ -10,18 +10,18 @@ import org.jetbrains.kotlin.js.backend.ast.*
|
||||
|
||||
class JsIrProgramFragment(val packageFqn: String) {
|
||||
val nameBindings = mutableMapOf<String, JsName>()
|
||||
val declarations = JsGlobalBlock()
|
||||
val exports = JsGlobalBlock()
|
||||
val declarations = JsCompositeBlock()
|
||||
val exports = JsCompositeBlock()
|
||||
val importedModules = mutableListOf<JsImportedModule>()
|
||||
val imports = mutableMapOf<String, JsExpression>()
|
||||
var dts: String? = null
|
||||
val classes = mutableMapOf<JsName, JsIrIcClassModel>()
|
||||
val initializers = JsGlobalBlock()
|
||||
val initializers = JsCompositeBlock()
|
||||
var mainFunction: JsStatement? = null
|
||||
var testFunInvocation: JsStatement? = null
|
||||
var suiteFn: JsName? = null
|
||||
val definitions = mutableSetOf<String>()
|
||||
val polyfills = JsGlobalBlock()
|
||||
val polyfills = JsCompositeBlock()
|
||||
}
|
||||
|
||||
class JsIrModule(
|
||||
|
||||
+4
-4
@@ -161,14 +161,14 @@ class Merger(
|
||||
|
||||
val moduleBody = mutableListOf<JsStatement>()
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val polyfillDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
val polyfillDeclarationBlock = JsCompositeBlock()
|
||||
|
||||
moduleBody.addWithComment("block: pre-declaration", preDeclarationBlock)
|
||||
|
||||
val classModels = mutableMapOf<JsName, JsIrIcClassModel>()
|
||||
val initializerBlock = JsGlobalBlock()
|
||||
val initializerBlock = JsCompositeBlock()
|
||||
|
||||
fragments.forEach {
|
||||
moduleBody += it.declarations.statements
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsIntrinsicTransfo
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsIrClassModel
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsCompositeBlock
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class JsStaticContext(
|
||||
val classModels = mutableMapOf<IrClassSymbol, JsIrClassModel>()
|
||||
val coroutineImplDeclaration = backendContext.ir.symbols.coroutineImpl.owner
|
||||
|
||||
val initializerBlock = JsGlobalBlock()
|
||||
val initializerBlock = JsCompositeBlock()
|
||||
|
||||
val genSourcemaps = backendContext.configuration.getBoolean(JSConfigurationKeys.SOURCE_MAP)
|
||||
}
|
||||
|
||||
+6
-6
@@ -51,16 +51,16 @@ class JsIrAstDeserializer : JsAstDeserializerBase() {
|
||||
}
|
||||
|
||||
if (proto.hasDeclarationBlock()) {
|
||||
fragment.declarations.statements += deserializeGlobalBlock(proto.declarationBlock).statements
|
||||
fragment.declarations.statements += deserializeCompositeBlock(proto.declarationBlock).statements
|
||||
}
|
||||
if (proto.hasInitializerBlock()) {
|
||||
fragment.initializers.statements += deserializeGlobalBlock(proto.initializerBlock).statements
|
||||
fragment.initializers.statements += deserializeCompositeBlock(proto.initializerBlock).statements
|
||||
}
|
||||
if (proto.hasExportBlock()) {
|
||||
fragment.exports.statements += deserializeGlobalBlock(proto.exportBlock).statements
|
||||
fragment.exports.statements += deserializeCompositeBlock(proto.exportBlock).statements
|
||||
}
|
||||
if (proto.hasPolyfills()) {
|
||||
fragment.polyfills.statements += deserializeGlobalBlock(proto.polyfills).statements
|
||||
fragment.polyfills.statements += deserializeCompositeBlock(proto.polyfills).statements
|
||||
}
|
||||
|
||||
proto.nameBindingList.associateTo(fragment.nameBindings) { nameBindingProto ->
|
||||
@@ -90,10 +90,10 @@ class JsIrAstDeserializer : JsAstDeserializerBase() {
|
||||
private fun deserialize(proto: IrClassModel): Pair<JsName, JsIrIcClassModel> {
|
||||
return deserializeName(proto.nameId) to JsIrIcClassModel(proto.superClassesList.map { deserializeName(it) }).apply {
|
||||
if (proto.hasPreDeclarationBlock()) {
|
||||
preDeclarationBlock.statements += deserializeGlobalBlock(proto.preDeclarationBlock).statements
|
||||
preDeclarationBlock.statements += deserializeCompositeBlock(proto.preDeclarationBlock).statements
|
||||
}
|
||||
if (proto.hasPostDeclarationBlock()) {
|
||||
postDeclarationBlock.statements += deserializeGlobalBlock(proto.postDeclarationBlock).statements
|
||||
postDeclarationBlock.statements += deserializeCompositeBlock(proto.postDeclarationBlock).statements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user