segabor / closure-templates

A client- and server-side templating system that helps you dynamically build reusable HTML and UI elements
Apache License 2.0
0 stars 0 forks source link

Broken enforced output append optimization #3

Open segabor opened 6 years ago

segabor commented 6 years ago

The following template code

  {for $name in $names}
    {call .helloName}
      {param name: $name /}
    {/call}
    {if not isLast($name)}
      <br>  // break after every line except the last
    {/if}
  {/for}

compiles to

output.extend(helloName(["name": nameData30], ijData).description+(! (nameIndex30 == nameList30.endIndex-1)) ? "<br>")

Swift code generation was derived from the Python compiler that enforces inlining output appends. First this looks pretty awful, second it's probably inefficient. Let's rewrite the compiler to generate a more readable code like

output.append(helloName(["name": nameData30], ijData).description)
if nameIndex30 != nameList30.endIndex {
  output.append("<br>")
}