Change DCE a bit to touch less declarations
This commit is contained in:
@@ -78,16 +78,9 @@ private fun removeUselessDeclarations(module: IrModuleFragment, usefulDeclaratio
|
|||||||
process(declaration)
|
process(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructor(declaration: IrConstructor) {
|
|
||||||
if (declaration !in usefulDeclarations) {
|
|
||||||
// Keep the constructor declaration without body in order to declare the JS constructor function
|
|
||||||
declaration.body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, emptyList())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun process(container: IrDeclarationContainer) {
|
private fun process(container: IrDeclarationContainer) {
|
||||||
container.declarations.transformFlat { member ->
|
container.declarations.transformFlat { member ->
|
||||||
if (member !in usefulDeclarations && member !is IrConstructor) {
|
if (member !in usefulDeclarations) {
|
||||||
emptyList()
|
emptyList()
|
||||||
} else {
|
} else {
|
||||||
member.acceptVoid(this)
|
member.acceptVoid(this)
|
||||||
|
|||||||
+10
@@ -33,6 +33,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
|
|||||||
fun generate(): JsStatement {
|
fun generate(): JsStatement {
|
||||||
assert(!irClass.descriptor.isExpect)
|
assert(!irClass.descriptor.isExpect)
|
||||||
|
|
||||||
|
maybeGeneratePrimaryConstructor()
|
||||||
val transformer = IrDeclarationToJsTransformer()
|
val transformer = IrDeclarationToJsTransformer()
|
||||||
|
|
||||||
// Properties might be lowered out of classes
|
// Properties might be lowered out of classes
|
||||||
@@ -142,6 +143,15 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun maybeGeneratePrimaryConstructor() {
|
||||||
|
if (!irClass.declarations.any { it is IrConstructor }) {
|
||||||
|
val func = JsFunction(emptyScope, JsBlock(), "Ctor for ${irClass.name}")
|
||||||
|
func.name = className
|
||||||
|
classBlock.statements += func.makeStmt()
|
||||||
|
classModel.preDeclarationBlock.statements += generateInheritanceCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun generateInheritanceCode(): List<JsStatement> {
|
private fun generateInheritanceCode(): List<JsStatement> {
|
||||||
if (baseClass == null || baseClass.isAny()) {
|
if (baseClass == null || baseClass.isAny()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
|
|||||||
Reference in New Issue
Block a user