Skip to content

Gratuitous string concatenation occurs when escaped curly braces are present #21

Description

@lazd

The output is less than ideal when \{ and \} are present -- there is additional string concatenation going on in the compiled function that is pretty ugly:

Template:

\{\{Outer with data\}\} {{data.name}}

<code>
  \{\{Nested\}\}
</code>

<code>
  \{\{Nested with data\}\} {{data.name}}
</code>

Output:

(function anonymous(data_0) {
  var frag = document.createDocumentFragment();
  var data = data_0;
  var el0 = document.createTextNode("{"+"{"+"Outer with data"+"}"+"}"+" "+data_0["name"]+"\n\n");
  frag.appendChild(el0);
  var el1 = document.createElement("code");
  el1.textContent = "\n  "+"{"+"{"+"Nested"+"}"+"}"+"\n";
  frag.appendChild(el1);
  var el2 = document.createTextNode("\n\n");
  frag.appendChild(el2);
  var el3 = document.createElement("code");
  el3.textContent = "\n  "+"{"+"{"+"Nested with data"+"}"+"}"+" "+data_0["name"]+"\n";
  frag.appendChild(el3);
  return frag;
})

The parser could be modified to concatenate the braces into an existing content block instead of creating a new one, or DOMly could be fixed to combine content blocks into a single string instead of concatenating multiple strings.

This is due to the fixes for #7. @cif

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions