Skip to content

[Feature]运行时转编译时 #2

@GrinZero

Description

@GrinZero

目前的render方法中部分内容完全可以在编译时处理完:

// 第一阶段添加id的这部分
    const usageDomSet = new Set<string>();
    template.replace(/{{(.*?)}}/g, (_, _key, start) => {
      const dom = findDomStr(start, template);
      usageDomSet.add(dom);
      return _;
    });
    usageDomSet.forEach((dom) => {
      let id = "";
      if (dom.indexOf("id=") === -1) {
        id = getRandomID();
        const newDom = dom.replace(">", ` id="${id}">`);
        template = template.replace(dom, newDom);
      }
    });

同时,replace本身是具体性能损耗的,考虑编译时直接收集好数据,不要重复replace

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