feat: add limited support of comments inside js call.

This commit is contained in:
Artem Kobzar
2022-04-07 15:32:03 +02:00
committed by teamcity
parent 6e30ce2763
commit 45e3c94a8b
20 changed files with 890 additions and 20 deletions
@@ -163,7 +163,7 @@ private class JsCodeOutlineTransformer(
}
// Building JS Ast function
val lastStatement = jsStatements.last()
val lastStatement = jsStatements.findLast { it !is JsSingleLineComment && it !is JsMultiLineComment }
val newStatements = jsStatements.toMutableList()
when (lastStatement) {
is JsReturn -> {
@@ -31,14 +31,14 @@ class JsCallTransformer(private val jsOrJsFuncCall: IrCall, private val context:
0 -> JsEmpty
1 -> newStatements.single().withSource(jsOrJsFuncCall, context)
// TODO: use transparent block (e.g. JsCompositeBlock)
else -> JsBlock(newStatements)
else -> JsGlobalBlock().apply { statements += newStatements }
}
}
fun generateExpression(): JsExpression {
if (statements.isEmpty()) return JsPrefixOperation(JsUnaryOperator.VOID, JsIntLiteral(3)) // TODO: report warning or even error
val lastStatement = statements.last()
val lastStatement = statements.findLast { it !is JsSingleLineComment && it !is JsMultiLineComment }
val lastExpression = when (lastStatement) {
is JsReturn -> lastStatement.expression
is JsExpressionStatement -> lastStatement.expression