Don't call toString for simple number literal and string
Cherry-picked https://github.com/develar/kotlin/commit/e93f2d6f52fe640f6523416377b3ff9be67f76dc
This commit is contained in:
+15
-5
@@ -19,15 +19,16 @@ package org.jetbrains.k2js.translate.expression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsInvocation;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||
import com.google.dart.compiler.util.AstUtil;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNumberLiteral;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.sum;
|
||||
|
||||
|
||||
@@ -82,9 +83,18 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
assert entryExpression != null :
|
||||
"JetStringTemplateEntryWithExpression must have not null entry expression.";
|
||||
JsExpression translatedExpression = Translation.translateAsExpression(entryExpression, context());
|
||||
JsNameRef toString = AstUtil.newQualifiedNameRef("toString");
|
||||
setQualifier(toString, translatedExpression);
|
||||
append(new JsInvocation(toString));
|
||||
if (translatedExpression instanceof JsNumberLiteral) {
|
||||
append(context().program().getStringLiteral(translatedExpression.toString()));
|
||||
}
|
||||
else {
|
||||
Name typeName = JsDescriptorUtils.getNameIfStandardType(entryExpression, context());
|
||||
if (typeName != null && typeName.getName().equals("String")) {
|
||||
append(translatedExpression);
|
||||
return;
|
||||
}
|
||||
|
||||
append(new JsInvocation(new JsNameRef("toString", translatedExpression)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user