[JS IR BE] Minor fixes
* Global scope * Top-level properties * Refactoring
This commit is contained in:
committed by
Roman Artemev
parent
d6d0a7d804
commit
601f29b781
+1
-1
@@ -30,7 +30,7 @@ class IrDeclarationToJsTransformer : BaseIrElementToJsNodeTransformer<JsStatemen
|
||||
JsUnaryOperator.VOID,
|
||||
JsIntLiteral(1)
|
||||
)
|
||||
return jsAssignment(JsNameRef(fieldName, JsThisRef()), initExpression).makeStmt()
|
||||
return JsVars(JsVars.JsVar(fieldName, initExpression))
|
||||
}
|
||||
|
||||
override fun visitVariable(declaration: IrVariable, context: JsGenerationContext): JsStatement {
|
||||
|
||||
+7
-7
@@ -20,22 +20,22 @@ class IrModuleToJsTransformer(val backendContext: JsIrBackendContext) : BaseIrEl
|
||||
}
|
||||
|
||||
// sort member forwarding code
|
||||
addPostDeclarations(rootContext)
|
||||
program.globalBlock.statements += addPostDeclarations(rootContext.staticContext.classModels)
|
||||
|
||||
return program
|
||||
}
|
||||
|
||||
|
||||
private fun addPostDeclarations(context: JsGenerationContext) {
|
||||
val staticContext = context.staticContext
|
||||
val program = context.currentScope.program
|
||||
val block = program.globalBlock
|
||||
private fun addPostDeclarations(classModels: Map<JsName, JsClassModel>): List<JsStatement> {
|
||||
|
||||
val statements = mutableListOf<JsStatement>()
|
||||
val visited = mutableSetOf<JsName>()
|
||||
|
||||
for (name in staticContext.classModels.keys) {
|
||||
addPostDeclaration(name, visited, block.statements, staticContext.classModels)
|
||||
for (name in classModels.keys) {
|
||||
addPostDeclaration(name, visited, statements, classModels)
|
||||
}
|
||||
|
||||
return statements
|
||||
}
|
||||
|
||||
private fun addPostDeclaration(name: JsName, visited: MutableSet<JsName>, statements: MutableList<JsStatement>, classModels: Map<JsName, JsClassModel>) {
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
|
||||
private val baseClass = irClass.superClasses.firstOrNull { !it.owner.isInterface }
|
||||
private val baseClassName = baseClass?.let { context.getNameForSymbol(it) }
|
||||
private val classPrototypeRef = prototypeOf(classNameRef)
|
||||
private val classBlock = JsBlock()
|
||||
private val classBlock = JsGlobalBlock()
|
||||
private val classModel = JsClassModel(className, baseClassName)
|
||||
|
||||
fun generate(): JsStatement {
|
||||
@@ -73,7 +73,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
|
||||
val memberName = context.getNameForSymbol(declaration.symbol)
|
||||
val memberRef = JsNameRef(memberName, classPrototypeRef)
|
||||
|
||||
translatedFunction?.let { return jsAssignment(memberRef, it).makeStmt() }
|
||||
translatedFunction?.let { return jsAssignment(memberRef, it.apply { name = null }).makeStmt() }
|
||||
|
||||
// do not generate code like
|
||||
// interface I { foo() = "OK" }
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.js.backend.ast.*
|
||||
|
||||
class JsGenerationContext {
|
||||
fun newDeclaration(scope: JsScope, func: IrFunction? = null): JsGenerationContext {
|
||||
return JsGenerationContext(this, JsBlock(), scope, func)
|
||||
return JsGenerationContext(this, if (func != null) JsBlock() else JsGlobalBlock(), scope, func)
|
||||
}
|
||||
|
||||
val currentBlock: JsBlock
|
||||
|
||||
Reference in New Issue
Block a user