protected buildXSTmplName()

in packages/shared/src/miniapp/template.ts [642:681]


  protected buildXSTmplName() {
    const isLoopComps = [
      ...Array.from(this.nestElements.keys()),
      ...Array.from(this.componentConfig.thirdPartyComponents.keys()),
    ];
    const isLoopCompsSet = new Set(isLoopComps);
    const hasMaxComps: string[] = [];
    this.nestElements.forEach((max, comp) => {
      if (max > 1) {
        hasMaxComps.push(comp);
      } else if (max === 1 && isLoopCompsSet.has(comp)) {
        isLoopCompsSet.delete(comp);
      }
    });

    const { componentsAlias } = this;
    const listA = Array.from(isLoopCompsSet).map(item => componentsAlias[item]?._num || item);
    const listB = hasMaxComps.map(item => componentsAlias[item]?._num || item);
    const containerLevel = this.baseLevel - 1;

    return `function (l, n, s) {
    var a = ${JSON.stringify(listA)}
    var b = ${JSON.stringify(listB)}
    if (a.indexOf(n) === -1) {
      l = 0
    }
    if (b.indexOf(n) > -1) {
      var u = s.split(',')
      var depth = 0
      for (var i = 0; i < u.length; i++) {
        if (u[i] === n) depth++
      }
      l = depth
    }
    if (l >= ${containerLevel}) {
      return 'tmpl_${containerLevel}_${Shortcuts.Container}'
    }
    return 'tmpl_' + l + '_' + n
  }`;
  }