Only bind a template literal if parameters are not empty.
GITHUB_BREAKING_CHANGES=N/A
@@ -68,7 +68,7 @@ final class ResolveTemplateFunctionsPass implements CompilerFilePass {
}
private static void convertToBind(FunctionNode fct) {
- ExprNode bindTarget;
+ ExprNode replacementExpr;
VarRefNode varRefNode = (VarRefNode) fct.getNameExpr();
if (varRefNode.hasType() && varRefNode.getType() instanceof ProtoImportType) {
return;
@@ -76,13 +76,14 @@ final class ResolveTemplateFunctionsPass implements CompilerFilePass {
if (varRefNode.hasType() && varRefNode.getType().getKind() == SoyType.Kind.TEMPLATE_TYPE) {
// If the function is a template symbol modify AST like:
// {tmp(...)} -> {template(tmp).bind(...)}
- bindTarget = TemplateLiteralNode.forVarRef(varRefNode);
+ replacementExpr = TemplateLiteralNode.forVarRef(varRefNode);
} else {
// Otherwise modify AST like:
// {$tmp(...)} -> {$tmp.bind(...)}
- bindTarget = varRefNode;
+ replacementExpr = varRefNode;
}
+ if (fct.numParams() > 0) {
// Move original function's parameters into a record() literal.
RecordLiteralNode record =
new RecordLiteralNode(
@@ -92,13 +93,15 @@ final class ResolveTemplateFunctionsPass implements CompilerFilePass {
record.addChildren(fct.getChildren());
// Bind and replace.
- MethodCallNode bind =
+ replacementExpr =
MethodCallNode.newWithPositionalArgs(
- bindTarget,
+ replacementExpr,
ImmutableList.of(record),
Identifier.create("bind", UNKNOWN),
UNKNOWN,
false);
- fct.getParent().replaceChild(fct, bind);
+ }
+
+ fct.getParent().replaceChild(fct, replacementExpr);
}
}
