Search in sources :

Example 1 with AssignToExpressionMutator

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;
}
Also used : TemporaryVariable(org.jetbrains.kotlin.js.translate.context.TemporaryVariable) AssignToExpressionMutator(org.jetbrains.kotlin.js.translate.utils.mutator.AssignToExpressionMutator) KotlinType(org.jetbrains.kotlin.types.KotlinType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 TemporaryVariable (org.jetbrains.kotlin.js.translate.context.TemporaryVariable)1 AssignToExpressionMutator (org.jetbrains.kotlin.js.translate.utils.mutator.AssignToExpressionMutator)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1