@tarojs/shared 4.0.7-alpha.0 → 4.0.7-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,6 +50,7 @@ export declare const events: {
50
50
  export declare class BaseTemplate {
51
51
  protected _baseLevel: number;
52
52
  protected _isUseXS: boolean;
53
+ protected _isUseCompileMode: boolean;
53
54
  protected exportExpr: string;
54
55
  protected isSupportRecursive: boolean;
55
56
  protected miniComponents: Components;
@@ -73,6 +74,8 @@ export declare class BaseTemplate {
73
74
  componentsAlias: any;
74
75
  set baseLevel(lv: number);
75
76
  get baseLevel(): number;
77
+ set isUseCompileMode(isUse: boolean);
78
+ get isUseCompileMode(): boolean;
76
79
  set isUseXS(isUse: boolean);
77
80
  get isUseXS(): boolean;
78
81
  private buildAttribute;
@@ -103,7 +106,7 @@ export declare class BaseTemplate {
103
106
  mergeComponents(ctx: any, patch: Record<string, Record<string, string>>): void;
104
107
  mergeThirdPartyComponents(patch: Record<string, Record<string, string>>): void;
105
108
  protected buildXSTmplName(): string;
106
- protected buildXSTepFocus(n: string): string;
109
+ protected buildXSTepFocus(nn: string): string;
107
110
  protected buildXSTmpExtra(): string;
108
111
  }
109
112
  export declare class RecursiveTemplate extends BaseTemplate {
package/dist/template.js CHANGED
@@ -326,34 +326,6 @@ const nestElements = new Map([
326
326
  ['swiper-item', 4],
327
327
  ]);
328
328
 
329
- function isString(o) {
330
- return typeof o === 'string';
331
- }
332
- function isFunction(o) {
333
- return typeof o === 'function';
334
- }
335
- function isNumber(o) {
336
- return typeof o === 'number';
337
- }
338
- function isBooleanStringLiteral(o) {
339
- return o === 'true' || o === 'false';
340
- }
341
-
342
- // 字符串简写
343
- exports.Shortcuts = void 0;
344
- (function (Shortcuts) {
345
- Shortcuts["Container"] = "container";
346
- Shortcuts["Childnodes"] = "c";
347
- Shortcuts["Text"] = "v";
348
- Shortcuts["NodeType"] = "nt";
349
- Shortcuts["NodeName"] = "n";
350
- // Attrtibutes
351
- Shortcuts["Style"] = "st";
352
- Shortcuts["Class"] = "l";
353
- Shortcuts["Src"] = "src";
354
- Shortcuts["Sid"] = "s";
355
- })(exports.Shortcuts || (exports.Shortcuts = {}));
356
-
357
329
  var PLATFORM_TYPE;
358
330
  (function (PLATFORM_TYPE) {
359
331
  PLATFORM_TYPE["MINI"] = "mini";
@@ -362,6 +334,7 @@ var PLATFORM_TYPE;
362
334
  PLATFORM_TYPE["HARMONY"] = "harmony";
363
335
  PLATFORM_TYPE["QUICK"] = "quickapp";
364
336
  })(PLATFORM_TYPE || (PLATFORM_TYPE = {}));
337
+ const COMPILE_MODE_IDENTIFIER_PREFIX = 'f';
365
338
  ({
366
339
  h5: {
367
340
  type: PLATFORM_TYPE.WEB
@@ -380,6 +353,34 @@ var PLATFORM_TYPE;
380
353
  },
381
354
  });
382
355
 
356
+ function isString(o) {
357
+ return typeof o === 'string';
358
+ }
359
+ function isFunction(o) {
360
+ return typeof o === 'function';
361
+ }
362
+ function isNumber(o) {
363
+ return typeof o === 'number';
364
+ }
365
+ function isBooleanStringLiteral(o) {
366
+ return o === 'true' || o === 'false';
367
+ }
368
+
369
+ // 字符串简写
370
+ exports.Shortcuts = void 0;
371
+ (function (Shortcuts) {
372
+ Shortcuts["Container"] = "container";
373
+ Shortcuts["Childnodes"] = "cn";
374
+ Shortcuts["Text"] = "v";
375
+ Shortcuts["NodeType"] = "nt";
376
+ Shortcuts["NodeName"] = "nn";
377
+ // Attrtibutes
378
+ Shortcuts["Sid"] = "sid";
379
+ Shortcuts["Style"] = "st";
380
+ Shortcuts["Class"] = "cl";
381
+ Shortcuts["Src"] = "src";
382
+ })(exports.Shortcuts || (exports.Shortcuts = {}));
383
+
383
384
  class Events {
384
385
  constructor(opts) {
385
386
  var _a;
@@ -744,7 +745,7 @@ function indent(str, size) {
744
745
  */
745
746
  const styles = {
746
747
  style: `i.${"st" /* Shortcuts.Style */}`,
747
- class: `i.${"l" /* Shortcuts.Class */}`
748
+ class: `i.${"cl" /* Shortcuts.Class */}`
748
749
  };
749
750
  const events = {
750
751
  bindtap: 'eh'
@@ -764,6 +765,7 @@ class BaseTemplate {
764
765
  constructor() {
765
766
  this._baseLevel = 0;
766
767
  this._isUseXS = true;
768
+ this._isUseCompileMode = false;
767
769
  this.exportExpr = 'module.exports =';
768
770
  this.thirdPartyPatcher = {};
769
771
  this.supportXS = false;
@@ -784,24 +786,24 @@ class BaseTemplate {
784
786
  };
785
787
  this.buildBaseComponentTemplate = (ext) => {
786
788
  const data = !this.isSupportRecursive && this.isUseXS
787
- ? this.dataKeymap(`i:i,c:1,l:xs.f('',i.${"n" /* Shortcuts.NodeName */})`)
789
+ ? this.dataKeymap(`i:i,c:1,l:xs.f('',i.${"nn" /* Shortcuts.NodeName */})`)
788
790
  : this.isSupportRecursive
789
791
  ? this.dataKeymap('i:i')
790
792
  : this.dataKeymap('i:i,c:1');
791
793
  // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
792
794
  return `<import src="./base${ext}" />
793
- ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + i.${"n" /* Shortcuts.NodeName */}}}" data="{{${data}}}" />`;
795
+ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + i.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" />`;
794
796
  };
795
797
  this.buildCustomComponentTemplate = (ext) => {
796
798
  const Adapter = this.Adapter;
797
799
  const data = !this.isSupportRecursive && this.isUseXS
798
- ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"n" /* Shortcuts.NodeName */})`)}`
800
+ ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
799
801
  : this.isSupportRecursive
800
802
  ? this.dataKeymap('i:item')
801
803
  : this.dataKeymap('i:item,c:1');
802
804
  // 此处需要重新引入 xs 函数,否则会出现 ws.f() 在 comp.wxml 和 custom-wrapper.wxml 中永远返回 undefined 的问题 #14599
803
805
  return `<import src="./base${ext}" />
804
- ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${Adapter.for}="{{i.${"c" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"s" /* Shortcuts.Sid */}" />
806
+ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}" />
805
807
  `;
806
808
  };
807
809
  this.buildXScript = () => {
@@ -810,7 +812,7 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
810
812
  b: function (a, b) {
811
813
  return a === undefined ? b : a
812
814
  },
813
- c: ${this.buildXSTepFocus("n" /* Shortcuts.NodeName */)},
815
+ c: ${this.buildXSTepFocus("nn" /* Shortcuts.NodeName */)},
814
816
  e: function (n) {
815
817
  return 'tmpl_' + n + '_${"container" /* Shortcuts.Container */}'
816
818
  },
@@ -824,6 +826,12 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
824
826
  get baseLevel() {
825
827
  return this._baseLevel;
826
828
  }
829
+ set isUseCompileMode(isUse) {
830
+ this._isUseCompileMode = isUse;
831
+ }
832
+ get isUseCompileMode() {
833
+ return this._isUseCompileMode;
834
+ }
827
835
  set isUseXS(isUse) {
828
836
  this._isUseXS = this.supportXS && isUse;
829
837
  }
@@ -938,17 +946,17 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
938
946
  buildBaseTemplate() {
939
947
  const Adapter = this.Adapter;
940
948
  const data = !this.isSupportRecursive && this.isUseXS
941
- ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"n" /* Shortcuts.NodeName */})`)}`
949
+ ? `${this.dataKeymap(`i:item,c:1,l:xs.f('',item.${"nn" /* Shortcuts.NodeName */})`)}`
942
950
  : this.isSupportRecursive
943
951
  ? this.dataKeymap('i:item')
944
952
  : this.dataKeymap('i:item,c:1');
945
953
  const xs = this.isUseXS
946
954
  ? (this.isSupportRecursive
947
- ? `xs.a(0, item.${"n" /* Shortcuts.NodeName */})`
948
- : `xs.a(0, item.${"n" /* Shortcuts.NodeName */}, '')`)
949
- : `'tmpl_0_' + item.${"n" /* Shortcuts.NodeName */}`;
955
+ ? `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`
956
+ : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */}, '')`)
957
+ : `'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}`;
950
958
  return `${this.buildXsImportTemplate()}<template name="taro_tmpl">
951
- <template is="{{${xs}}}" data="{{${data}}}" ${Adapter.for}="{{root.${"c" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"s" /* Shortcuts.Sid */}" />
959
+ <template is="{{${xs}}}" data="{{${data}}}" ${Adapter.for}="{{root.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}" />
952
960
  </template>
953
961
  `;
954
962
  }
@@ -975,7 +983,7 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
975
983
  return str + ` bind${value}="eh"`;
976
984
  }
977
985
  else if (attr === 'class') {
978
- return str + ` class="{{i.${"l" /* Shortcuts.Class */}}}"`;
986
+ return str + ` class="{{i.${"cl" /* Shortcuts.Class */}}}"`;
979
987
  }
980
988
  else if (attr === 'style') {
981
989
  return str + ` style="{{i.${"st" /* Shortcuts.Style */}}}"`;
@@ -996,10 +1004,10 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
996
1004
  : this.buildStandardComponentTemplate(comp, level);
997
1005
  }
998
1006
  getChildrenTemplate(level) {
999
- const { isSupportRecursive, isUseXS, Adapter } = this;
1007
+ const { isSupportRecursive, isUseXS, Adapter, isUseCompileMode = true } = this;
1000
1008
  const isLastRecursiveComp = !isSupportRecursive && level + 1 === this.baseLevel;
1001
1009
  const isUnRecursiveXs = !this.isSupportRecursive && isUseXS;
1002
- const forAttribute = `${Adapter.for}="{{i.${"c" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"s" /* Shortcuts.Sid */}"`;
1010
+ const forAttribute = `${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="${"sid" /* Shortcuts.Sid */}"`;
1003
1011
  if (isLastRecursiveComp) {
1004
1012
  const data = isUnRecursiveXs
1005
1013
  ? `${this.dataKeymap('i:item,c:c,l:l')}`
@@ -1014,18 +1022,20 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
1014
1022
  const data = isUnRecursiveXs
1015
1023
  // TODO: 此处直接 c+1,不是最优解,变量 c 的作用是监测组件嵌套的层级是否大于 baselevel
1016
1024
  // 但目前的监测方法用于所有组件嵌套的总和,应该分开组件计算,单个组件嵌套层级大于 baselevel 时,再进入 comp 组件中进行新的嵌套
1017
- ? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"n" /* Shortcuts.NodeName */})`)}`
1025
+ ? `${this.dataKeymap(`i:item,c:c+1,l:xs.f(l,item.${"nn" /* Shortcuts.NodeName */})`)}`
1018
1026
  : this.isSupportRecursive
1019
1027
  ? `${this.dataKeymap('i:item')}`
1020
1028
  : `${this.dataKeymap('i:item,c:c+1')}`;
1021
1029
  const xs = !this.isSupportRecursive
1022
- ? `xs.a(c, item.${"n" /* Shortcuts.NodeName */}, l)`
1023
- : `xs.a(0, item.${"n" /* Shortcuts.NodeName */})`;
1030
+ ? `xs.a(c, item.${"nn" /* Shortcuts.NodeName */}, l)`
1031
+ : `xs.a(0, item.${"nn" /* Shortcuts.NodeName */})`;
1024
1032
  return isUseXS
1025
1033
  ? `<template is="{{${xs}}}" data="{{${data}}}" ${forAttribute} />`
1026
1034
  : isSupportRecursive
1027
- ? `<template is="{{'tmpl_0_' + item.${"n" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`
1028
- : `<template is="{{'tmpl_' + c + '_' + item.${"n" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`;
1035
+ ? `<template is="{{'tmpl_0_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`
1036
+ : isUseCompileMode
1037
+ ? `<template is="{{'tmpl_' + (item.${"nn" /* Shortcuts.NodeName */}[0]==='${COMPILE_MODE_IDENTIFIER_PREFIX}' ? 0 : c) + '_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`
1038
+ : `<template is="{{'tmpl_' + c + '_' + item.${"nn" /* Shortcuts.NodeName */}}}" data="{{${data}}}" ${forAttribute} />`;
1029
1039
  }
1030
1040
  }
1031
1041
  getChildren(comp, level) {
@@ -1060,11 +1070,11 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
1060
1070
  </template>
1061
1071
 
1062
1072
  <template name="tmpl_${level}_${nodeAlias}_focus">
1063
- <${nodeName} ${this.buildAttribute(comp.attributes, nodeName)} id="{{i.uid||i.${"s" /* Shortcuts.Sid */}}}" data-${"s" /* Shortcuts.Sid */}="{{i.${"s" /* Shortcuts.Sid */}}}">${children}</${nodeName}>
1073
+ <${nodeName} ${this.buildAttribute(comp.attributes, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
1064
1074
  </template>
1065
1075
 
1066
1076
  <template name="tmpl_${level}_${nodeAlias}_blur">
1067
- <${nodeName} ${this.buildAttribute(attrs, nodeName)} id="{{i.uid||i.${"s" /* Shortcuts.Sid */}}}" data-${"s" /* Shortcuts.Sid */}="{{i.${"s" /* Shortcuts.Sid */}}}">${children}</${nodeName}>
1077
+ <${nodeName} ${this.buildAttribute(attrs, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
1068
1078
  </template>
1069
1079
  `;
1070
1080
  if (isFunction(this.modifyTemplateResult)) {
@@ -1100,7 +1110,7 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
1100
1110
  }
1101
1111
  let res = `
1102
1112
  <template name="tmpl_${level}_${nodeAlias}">
1103
- <${nodeName} ${this.buildAttribute(comp.attributes, comp.nodeName)} id="{{i.uid||i.${"s" /* Shortcuts.Sid */}}}" data-${"s" /* Shortcuts.Sid */}="{{i.${"s" /* Shortcuts.Sid */}}}">${children}</${nodeName}>
1113
+ <${nodeName} ${this.buildAttribute(comp.attributes, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
1104
1114
  </template>
1105
1115
  `;
1106
1116
  if (isFunction(this.modifyTemplateResult)) {
@@ -1123,7 +1133,7 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
1123
1133
  if (compName === 'custom-wrapper') {
1124
1134
  template += `
1125
1135
  <template name="tmpl_${level}_${compName}">
1126
- <${compName} i="{{i}}" l="{{l}}" id="{{i.uid||i.${"s" /* Shortcuts.Sid */}}}" data-${"s" /* Shortcuts.Sid */}="{{i.${"s" /* Shortcuts.Sid */}}}">
1136
+ <${compName} i="{{i}}" ${!isSupportRecursive && isUseXS ? 'l="{{l}}"' : ''} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
1127
1137
  </${compName}>
1128
1138
  </template>
1129
1139
  `;
@@ -1142,7 +1152,7 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
1142
1152
  `;
1143
1153
  template += `
1144
1154
  <template name="tmpl_${level}_${compName}">
1145
- <${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.${"s" /* Shortcuts.Sid */}}}" data-${"s" /* Shortcuts.Sid */}="{{i.${"s" /* Shortcuts.Sid */}}}">${children}</${compName}>
1155
+ <${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${compName}>
1146
1156
  </template>
1147
1157
  `;
1148
1158
  }
@@ -1151,7 +1161,7 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
1151
1161
  }
1152
1162
  // 最后一层的 comp 需要引用 container 进行重新的模版循环,其他情况不需要 container
1153
1163
  buildContainerTemplate(level) {
1154
- const tmpl = `<block ${this.Adapter.if}="{{i.${"n" /* Shortcuts.NodeName */} === '${this.componentsAlias['#text']._num}'}}">
1164
+ const tmpl = `<block ${this.Adapter.if}="{{i.nn === '${this.componentsAlias['#text']._num}'}}">
1155
1165
  <template is="tmpl_0_${this.componentsAlias['#text']._num}" data="{{${this.dataKeymap('i:i')}}}" />
1156
1166
  </block>
1157
1167
  <block ${this.Adapter.else}>
@@ -1189,10 +1199,10 @@ ${this.buildXsImportTemplate()}<template is="{{'tmpl_0_' + item.${"n" /* Shortcu
1189
1199
  return 'tmpl_' + l + '_' + n
1190
1200
  }`;
1191
1201
  }
1192
- buildXSTepFocus(n) {
1202
+ buildXSTepFocus(nn) {
1193
1203
  return `function(i, prefix) {
1194
1204
  var s = i.focus !== undefined ? 'focus' : 'blur'
1195
- return prefix + i.${n} + '_' + s
1205
+ return prefix + i.${nn} + '_' + s
1196
1206
  }`;
1197
1207
  }
1198
1208
  buildXSTmpExtra() {