Make element composition on class attributes type check correctly. They were being transpiled to the type checker as
{if $class}class="{$class}"{/if}
which makes it seem like it was optional. This ends up working in the desugaring, but we need to let the type-checker allow this.
GITHUB_BREAKING_CHANGES=n/a
@@ -40,6 +40,7 @@ import com.google.template.soy.shared.internal.BuiltinMethod;
import com.google.template.soy.soytree.HtmlAttributeNode;
import com.google.template.soy.soytree.HtmlOpenTagNode;
import com.google.template.soy.soytree.HtmlTagNode;
+import com.google.template.soy.soytree.IfCondNode;
import com.google.template.soy.soytree.PrintNode;
import com.google.template.soy.soytree.SoyFileNode;
import com.google.template.soy.soytree.SoyNode;
@@ -302,7 +303,11 @@ final class ResolveExpressionTypesCrossTemplatePass implements CompilerFileSetPa
}
if (Parameter.isValidAttrName(name)) {
String paramName = Parameter.attrToParamName(name);
- if (attr.getParent() instanceof HtmlOpenTagNode && !addAttr.apply(paramName)) {
+ // This is a synthetically created IfCond Node created by somethin akin to @class="Hello"
+ if (((attr.getParent() instanceof IfCondNode
+ && !attr.getParent().getSourceLocation().isKnown())
+ || attr.getParent() instanceof HtmlOpenTagNode)
+ && !addAttr.apply(paramName)) {
errorReporter.report(loc, DUPLICATE_PARAM, name);
return;
} else if (!hasAllAttributes) {
