Gratuitous string concatenation occurs when escaped curly braces are present

未关闭
#21 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript
领域
frontend

调研方向

首先追踪受 #7 修复影响的 parser 和 DOMly content-block 处理;该 issue 未指定具体文件或测试。使用提供的带有 escaped braces 的模板和编译后的输出作为回归用例,并考虑建议的两个实现方向。完成的标准是生成的函数避免不必要的字符串拼接,同时保留 escaped braces 和插值数据。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
JavaScript
星标
54
派生
9
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

lazd/DOMly 的其他 Issue

查看 lazd/DOMly 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。