use of org.jetbrains.kotlin.js.translate.utils.mutator.AssignToExpressionMutator in project kotlin by JetBrains.
the class Translation method translateAsExpression.
@NotNull
public static JsExpression translateAsExpression(@NotNull KtExpression expression, @NotNull TranslationContext context, @NotNull JsBlock block) {
JsNode jsNode = translateExpression(expression, context, block);
if (jsNode instanceof JsExpression) {
KotlinType expressionType = context.bindingContext().getType(expression);
return unboxIfNeeded((JsExpression) jsNode, expressionType != null && KotlinBuiltIns.isCharOrNullableChar(expressionType));
}
assert jsNode instanceof JsStatement : "Unexpected node of type: " + jsNode.getClass().toString();
if (BindingContextUtilsKt.isUsedAsExpression(expression, context.bindingContext())) {
TemporaryVariable result = context.declareTemporary(null);
AssignToExpressionMutator saveResultToTemporaryMutator = new AssignToExpressionMutator(result.reference());
block.getStatements().add(mutateLastExpression(jsNode, saveResultToTemporaryMutator));
return result.reference();
}
block.getStatements().add(convertToStatement(jsNode));
return JsLiteral.NULL;
}
Aggregations