@lcap/nasl 3.3.0-alpha.2 → 3.3.0-alpha.3

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.
Files changed (152) hide show
  1. package/out/automate/upgrader/2.20.js.map +1 -1
  2. package/out/bak/translator.js +52 -1
  3. package/out/bak/translator.js.map +1 -1
  4. package/out/breakpoint/shared/utils.js +0 -2
  5. package/out/breakpoint/shared/utils.js.map +1 -1
  6. package/out/common/Command.d.ts +1 -0
  7. package/out/common/Command.js +9 -1
  8. package/out/common/Command.js.map +1 -1
  9. package/out/concepts/BindAttribute__.d.ts +2 -0
  10. package/out/concepts/BindAttribute__.js +77 -2
  11. package/out/concepts/BindAttribute__.js.map +1 -1
  12. package/out/concepts/BindEvent__.d.ts +2 -1
  13. package/out/concepts/BindEvent__.js +43 -36
  14. package/out/concepts/BindEvent__.js.map +1 -1
  15. package/out/concepts/CallLogic__.js +67 -10
  16. package/out/concepts/CallLogic__.js.map +1 -1
  17. package/out/concepts/CallQueryComponent__.d.ts +1 -1
  18. package/out/concepts/Connection__.js +9 -10
  19. package/out/concepts/Connection__.js.map +1 -1
  20. package/out/concepts/ForEachStatement__.js +25 -35
  21. package/out/concepts/ForEachStatement__.js.map +1 -1
  22. package/out/concepts/Logic__.js +1 -0
  23. package/out/concepts/Logic__.js.map +1 -1
  24. package/out/concepts/MemberExpression__.d.ts +1 -0
  25. package/out/concepts/MemberExpression__.js +115 -0
  26. package/out/concepts/MemberExpression__.js.map +1 -1
  27. package/out/concepts/Module__.d.ts +1 -1
  28. package/out/concepts/Module__.js +34 -35
  29. package/out/concepts/Module__.js.map +1 -1
  30. package/out/concepts/TypeAnnotation__.d.ts +4 -3
  31. package/out/concepts/TypeAnnotation__.js +114 -73
  32. package/out/concepts/TypeAnnotation__.js.map +1 -1
  33. package/out/concepts/ValidationRule__.d.ts +14 -14
  34. package/out/concepts/ValidationRule__.js +29 -25
  35. package/out/concepts/ValidationRule__.js.map +1 -1
  36. package/out/concepts/ViewElement__.d.ts +88 -87
  37. package/out/concepts/ViewElement__.js +268 -204
  38. package/out/concepts/ViewElement__.js.map +1 -1
  39. package/out/concepts/View__.d.ts +6 -0
  40. package/out/concepts/View__.js +252 -9
  41. package/out/concepts/View__.js.map +1 -1
  42. package/out/concepts/basics/stdlib/nasl.browser.js +1 -0
  43. package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
  44. package/out/concepts/basics/stdlib/nasl.event.js +2 -0
  45. package/out/concepts/basics/stdlib/nasl.event.js.map +1 -1
  46. package/out/generator/genBundleFiles.js +90 -1
  47. package/out/generator/genBundleFiles.js.map +1 -1
  48. package/out/generator/genReleaseBody.js +1 -1
  49. package/out/generator/genReleaseBody.js.map +1 -1
  50. package/out/generator/permission.js +3 -3
  51. package/out/generator/permission.js.map +1 -1
  52. package/out/natural/genNaturalTS.js +7 -3
  53. package/out/natural/genNaturalTS.js.map +1 -1
  54. package/out/natural/transformTSCode.d.ts +1 -1
  55. package/out/natural/transformTSCode.js +115 -141
  56. package/out/natural/transformTSCode.js.map +1 -1
  57. package/out/server/extendBaseNode.js +69 -44
  58. package/out/server/extendBaseNode.js.map +1 -1
  59. package/out/server/formatTsUtils.js +72 -63
  60. package/out/server/formatTsUtils.js.map +1 -1
  61. package/out/server/getLogics.js +20 -23
  62. package/out/server/getLogics.js.map +1 -1
  63. package/out/server/getMemberIdentifier.d.ts +1 -0
  64. package/out/server/getMemberIdentifier.js +149 -1
  65. package/out/server/getMemberIdentifier.js.map +1 -1
  66. package/out/server/naslServer.d.ts +3 -3
  67. package/out/server/naslServer.js +182 -132
  68. package/out/server/naslServer.js.map +1 -1
  69. package/out/server/translator.js +43 -33
  70. package/out/server/translator.js.map +1 -1
  71. package/out/service/defaultErrorMessage.json +6 -6
  72. package/out/service/storage/init.js +16 -0
  73. package/out/service/storage/init.js.map +1 -1
  74. package/out/templator/genCreateBlock.js +5 -3
  75. package/out/templator/genCreateBlock.js.map +1 -1
  76. package/out/templator/genCurdEditMultipleKeyBlock.js +12 -8
  77. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  78. package/out/templator/genCurdMultipleKeyBlock.js +8 -7
  79. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  80. package/out/templator/genEditTableBlock.d.ts +1 -1
  81. package/out/templator/genEditTableBlock.js +12 -6
  82. package/out/templator/genEditTableBlock.js.map +1 -1
  83. package/out/templator/genEnumSelectBlock.js +2 -2
  84. package/out/templator/genEnumSelectBlock.js.map +1 -1
  85. package/out/templator/genGetBlock.js +1 -1
  86. package/out/templator/genGetBlock.js.map +1 -1
  87. package/out/templator/genGridViewBlock.d.ts +2 -2
  88. package/out/templator/genGridViewBlock.js +20 -7
  89. package/out/templator/genGridViewBlock.js.map +1 -1
  90. package/out/templator/genListViewBlock.d.ts +2 -2
  91. package/out/templator/genListViewBlock.js +13 -5
  92. package/out/templator/genListViewBlock.js.map +1 -1
  93. package/out/templator/genSelectBlock.d.ts +2 -2
  94. package/out/templator/genSelectBlock.js +8 -6
  95. package/out/templator/genSelectBlock.js.map +1 -1
  96. package/out/templator/genTableBlock.d.ts +1 -1
  97. package/out/templator/genTableBlock.js +10 -5
  98. package/out/templator/genTableBlock.js.map +1 -1
  99. package/out/templator/genUpdateBlock.js +5 -3
  100. package/out/templator/genUpdateBlock.js.map +1 -1
  101. package/package.json +2 -1
  102. package/sandbox/stdlib/nasl.auth.ts +40 -44
  103. package/sandbox/stdlib/nasl.core.ts +8 -1
  104. package/sandbox/stdlib/nasl.http.ts +22 -22
  105. package/sandbox-natural/stdlib/nasl.util.ts +74 -15
  106. package/src/automate/upgrader/2.20.js +17 -13
  107. package/src/bak/translator.js +50 -1
  108. package/src/breakpoint/shared/utils.ts +0 -2
  109. package/src/common/Command.ts +8 -0
  110. package/src/concepts/BindAttribute__.ts +67 -2
  111. package/src/concepts/BindEvent__.ts +43 -63
  112. package/src/concepts/CallLogic__.ts +66 -10
  113. package/src/concepts/Connection__.ts +14 -20
  114. package/src/concepts/ForEachStatement__.ts +32 -43
  115. package/src/concepts/Logic__.ts +1 -0
  116. package/src/concepts/MemberExpression__.ts +109 -1
  117. package/src/concepts/Module__.ts +41 -58
  118. package/src/concepts/TypeAnnotation__.ts +142 -122
  119. package/src/concepts/ValidationRule__.ts +553 -523
  120. package/src/concepts/ViewElement__.ts +2445 -2498
  121. package/src/concepts/View__.ts +256 -8
  122. package/src/concepts/basics/stdlib/nasl.browser.ts +1 -0
  123. package/src/concepts/basics/stdlib/nasl.event.ts +2 -0
  124. package/src/generator/genBundleFiles.ts +91 -1
  125. package/src/generator/genReleaseBody.ts +1 -1
  126. package/src/generator/permission.ts +3 -3
  127. package/src/natural/genNaturalTS.ts +8 -4
  128. package/src/natural/transformTSCode.ts +139 -151
  129. package/src/server/extendBaseNode.ts +71 -45
  130. package/src/server/formatTsUtils.ts +64 -64
  131. package/src/server/getLogics.ts +23 -30
  132. package/src/server/getMemberIdentifier.ts +143 -0
  133. package/src/server/naslServer.ts +174 -148
  134. package/src/server/translator.ts +40 -39
  135. package/src/service/defaultErrorMessage.json +6 -6
  136. package/src/service/storage/init.ts +17 -0
  137. package/src/templator/genCreateBlock.ts +5 -3
  138. package/src/templator/genCurdEditMultipleKeyBlock.ts +12 -8
  139. package/src/templator/genCurdMultipleKeyBlock.ts +8 -7
  140. package/src/templator/genEditTableBlock.ts +12 -7
  141. package/src/templator/genEnumSelectBlock.ts +2 -2
  142. package/src/templator/genGetBlock.ts +6 -6
  143. package/src/templator/genGridViewBlock.ts +22 -9
  144. package/src/templator/genListViewBlock.ts +14 -5
  145. package/src/templator/genSelectBlock.ts +8 -6
  146. package/src/templator/genTableBlock.ts +10 -9
  147. package/src/templator/genUpdateBlock.ts +5 -3
  148. package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +11 -0
  149. package/test/concepts/validation-rule/__snapshots__/toJS.spec.ts.snap +10 -0
  150. package/test/concepts/validation-rule/fixtures/argument-without-keyword.json +34 -0
  151. package/test/concepts/validation-rule/fixtures/empty-rule.json +9 -0
  152. package/test/concepts/validation-rule/validation-rule.spec.ts +15 -0
@@ -34,28 +34,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34
34
  var ViewElement_1;
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.ViewElement = void 0;
37
+ const translator_1 = require("../translator");
38
+ const concepts_1 = require("../concepts");
37
39
  const babelParser = __importStar(require("@babel/parser"));
38
40
  const json5 = __importStar(require("json5"));
39
41
  const compiler = __importStar(require("vue-template-compiler"));
40
- const translator_1 = require("../translator");
41
- const concepts_1 = require("../concepts");
42
42
  const LogicItem__1 = require("./LogicItem__");
43
+ const Logic__1 = require("./Logic__");
43
44
  const config_1 = require("../config");
44
45
  const MemberExpression__1 = __importDefault(require("./MemberExpression__"));
45
46
  const Identifier__1 = __importDefault(require("./Identifier__"));
46
47
  const utils_1 = require("../utils");
47
- const decorators_1 = require("../decorators");
48
- const utils = __importStar(require("../utils"));
49
- const BaseNode_1 = __importDefault(require("../common/BaseNode"));
50
- const classMap_1 = __importDefault(require("../common/classMap"));
51
- const BindAttribute__1 = __importDefault(require("./BindAttribute__"));
52
- const BindEvent__1 = __importDefault(require("./BindEvent__"));
53
- const BindDirective__1 = __importDefault(require("./BindDirective__"));
54
- const BindStyle__1 = __importDefault(require("./BindStyle__"));
55
48
  /**
56
49
  * 自闭合标签
57
50
  */
58
- const selfClosingTag = ['base', 'meta', 'area', 'embed', 'link', 'img', 'input', 'param', 'hr', 'br', 'source', 'track', 'wbr', 'col'];
51
+ const selfClosingTag = [
52
+ 'base',
53
+ 'meta',
54
+ 'area',
55
+ 'embed',
56
+ 'link',
57
+ 'img',
58
+ 'input',
59
+ 'param',
60
+ 'hr',
61
+ 'br',
62
+ 'source',
63
+ 'track',
64
+ 'wbr',
65
+ 'col',
66
+ ];
59
67
  function genArgumentMemberExpression(arr) {
60
68
  let expressionNode;
61
69
  const propertyName = arr.pop();
@@ -92,16 +100,14 @@ function transAstNodeToNaslNode(astNode, namespace) {
92
100
  kind: 'Expression',
93
101
  calleeNamespace: 'nasl.util',
94
102
  calleeName,
95
- arguments: astNode.arguments
96
- .map((argument) => ({
103
+ arguments: astNode.arguments.map((argument) => ({
97
104
  concept: 'Argument',
98
105
  name: '',
99
106
  kind: 'Statement',
100
107
  keyword: '',
101
- expression: transAstNodeToNaslNode({ ...argument }),
102
- }))
103
- .filter((item) => item.expression),
104
- typeArguments: astNode.arguments.map((argument) => transAstNodeToNaslTypeNode({ ...argument })).filter((item) => item),
108
+ expression: transAstNodeToNaslNode(Object.assign({}, argument)),
109
+ })).filter((item) => item.expression),
110
+ typeArguments: astNode.arguments.map((argument) => (transAstNodeToNaslTypeNode(Object.assign({}, argument)))).filter((item) => item),
105
111
  };
106
112
  }
107
113
  else if (astNode.type === 'MemberExpression') {
@@ -155,15 +161,17 @@ function transAstNodeToNaslNode(astNode, namespace) {
155
161
  if (astNode?.value?.startsWith('__enumTypeAnnotation_')) {
156
162
  return null;
157
163
  }
158
- node = {
159
- concept: 'StringLiteral',
160
- kind: 'Expression',
161
- name: '',
162
- value: astNode.value,
163
- };
164
+ else {
165
+ node = {
166
+ concept: 'StringLiteral',
167
+ kind: 'Expression',
168
+ name: '',
169
+ value: astNode.value,
170
+ };
171
+ }
164
172
  }
165
173
  else if (astNode.type === 'UnaryExpression') {
166
- const { argument } = astNode;
174
+ const argument = astNode.argument;
167
175
  if (argument.type === 'NumericLiteral') {
168
176
  node = {
169
177
  concept: 'NumericLiteral',
@@ -187,6 +195,32 @@ function transAstNodeToNaslNode(astNode, namespace) {
187
195
  value: numberString,
188
196
  };
189
197
  }
198
+ else if (astNode.type === 'ArrowFunctionExpression') {
199
+ if (astNode.body?.callee?.name) {
200
+ astNode.name = astNode.body.callee.name;
201
+ }
202
+ let tempNode = {
203
+ calleeNamespace: 'app.logics',
204
+ concept: 'CallLogic',
205
+ namespace: namespace || '',
206
+ name: astNode.name,
207
+ calleeName: astNode.name,
208
+ kind: 'Expression',
209
+ parentNode: astNode.parentNode,
210
+ parentKey: astNode.parentKey,
211
+ arguments: astNode?.body?.arguments?.map((argument) => ({
212
+ concept: 'Argument',
213
+ name: '',
214
+ kind: 'Statement',
215
+ keyword: '',
216
+ expression: transAstNodeToNaslNode(Object.assign({}, argument)),
217
+ })).filter((item) => item.expression),
218
+ typeArguments: astNode?.body?.arguments?.map((argument) => (transAstNodeToNaslTypeNode(Object.assign({}, argument)))).filter((item) => item)
219
+ };
220
+ node = Logic__1.Logic.from({
221
+ ...tempNode,
222
+ }, undefined, 'logics');
223
+ }
190
224
  else {
191
225
  node = astNode;
192
226
  node.concept = astNode.type;
@@ -209,6 +243,15 @@ function transAstNodeToNaslTypeNode(astNode, namespace) {
209
243
  }
210
244
  return node;
211
245
  }
246
+ const decorators_1 = require("../decorators");
247
+ const utils = __importStar(require("../utils"));
248
+ const BaseNode_1 = __importDefault(require("../common/BaseNode"));
249
+ const classMap_1 = __importDefault(require("../common/classMap"));
250
+ const BindAttribute__1 = __importDefault(require("./BindAttribute__"));
251
+ const BindEvent__1 = __importDefault(require("./BindEvent__"));
252
+ const BindDirective__1 = __importDefault(require("./BindDirective__"));
253
+ const BindStyle__1 = __importDefault(require("./BindStyle__"));
254
+ const View__1 = require("./View__");
212
255
  /**
213
256
  * 页面元素
214
257
  */
@@ -301,8 +344,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
301
344
  * @param source 需要合并的部分参数
302
345
  */
303
346
  constructor(source) {
304
- // @ts-ignore
305
- source = { ...ViewElement_1.getDefaultOptions(), ...source };
347
+ source = Object.assign({}, ViewElement_1.getDefaultOptions(), source);
306
348
  super(source);
307
349
  super.subConstructor(source);
308
350
  }
@@ -652,7 +694,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
652
694
  if (typeof options === 'string') {
653
695
  bindAttribute = this.bindAttrs.find((item) => item.name === options);
654
696
  if (!bindAttribute) {
655
- throw new Error(`找不到元素绑定属性 ${options}`);
697
+ throw new Error('找不到元素绑定属性 ' + options);
656
698
  }
657
699
  }
658
700
  else {
@@ -661,7 +703,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
661
703
  return bindAttribute.delete();
662
704
  }
663
705
  __removeBindAttribute(bindAttribute) {
664
- const { parentKey } = bindAttribute;
706
+ const parentKey = bindAttribute.parentKey;
665
707
  const params = {
666
708
  parentNode: this,
667
709
  parentKey,
@@ -688,7 +730,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
688
730
  if (typeof options === 'string') {
689
731
  bindEvent = this.bindEvents.find((item) => item.name === options);
690
732
  if (!bindEvent) {
691
- throw new Error(`找不到元素绑定事件 ${options}`);
733
+ throw new Error('找不到元素绑定事件 ' + options);
692
734
  }
693
735
  }
694
736
  else {
@@ -697,7 +739,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
697
739
  return bindEvent.delete();
698
740
  }
699
741
  __removeBindEvent(bindEvent) {
700
- const { parentKey } = bindEvent;
742
+ const parentKey = bindEvent.parentKey;
701
743
  const params = {
702
744
  parentNode: this,
703
745
  parentKey,
@@ -724,7 +766,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
724
766
  if (typeof options === 'string') {
725
767
  bindDirective = this.bindDirectives.find((item) => item.name === options);
726
768
  if (!bindDirective) {
727
- throw new Error(`找不到元素指令 ${options}`);
769
+ throw new Error('找不到元素指令 ' + options);
728
770
  }
729
771
  }
730
772
  else {
@@ -733,7 +775,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
733
775
  return bindDirective.delete();
734
776
  }
735
777
  __removeBindDirective(bindDirective) {
736
- const { parentKey } = bindDirective;
778
+ const parentKey = bindDirective.parentKey;
737
779
  const params = {
738
780
  parentNode: this,
739
781
  parentKey,
@@ -760,7 +802,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
760
802
  if (typeof options === 'string') {
761
803
  bindStyle = this.bindStyles.find((item) => item.name === options);
762
804
  if (!bindStyle) {
763
- throw new Error(`找不到元素绑定样式 ${options}`);
805
+ throw new Error('找不到元素绑定样式 ' + options);
764
806
  }
765
807
  }
766
808
  else {
@@ -769,7 +811,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
769
811
  return bindStyle.delete();
770
812
  }
771
813
  __removeBindStyle(bindStyle) {
772
- const { parentKey } = bindStyle;
814
+ const parentKey = bindStyle.parentKey;
773
815
  const params = {
774
816
  parentNode: this,
775
817
  parentKey,
@@ -796,7 +838,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
796
838
  if (typeof options === 'string') {
797
839
  viewElement = this.children.find((item) => item.name === options);
798
840
  if (!viewElement) {
799
- throw new Error(`找不到页面元素 ${options}`);
841
+ throw new Error('找不到页面元素 ' + options);
800
842
  }
801
843
  }
802
844
  else {
@@ -805,7 +847,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
805
847
  return viewElement.delete();
806
848
  }
807
849
  __removeViewElement(viewElement) {
808
- const { parentKey } = viewElement;
850
+ const parentKey = viewElement.parentKey;
809
851
  const params = {
810
852
  parentNode: this,
811
853
  parentKey,
@@ -827,10 +869,10 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
827
869
  }
828
870
  return params;
829
871
  }
830
- //= ===============================================================================
872
+ //================================================================================
831
873
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
832
874
  // 自动生成的代码已结束。下面可以手动编写。
833
- //= ===============================================================================
875
+ //================================================================================
834
876
  /* 主页面有没有权限 */
835
877
  get parentAuth() {
836
878
  const _nameSpace = this.view.getNamespace();
@@ -895,6 +937,14 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
895
937
  else if (this.tag === 'u-table-view-column-dynamic') {
896
938
  code += `${this.name}: nasl.ui.${this.toHump(this.tag)}<any, any>;\n`;
897
939
  }
940
+ else if (Object.keys(View__1.PAGE_COMPONENT_INCLUDE_TAG_MAP).includes(this.tag)) {
941
+ if (this.bindAttrs?.findIndex((attr) => attr.name === 'data-source') > -1) {
942
+ code += `${this.name}: nasl.ui.${this.toHump(this.tag)}<__elements_completionProperty['${this.name}']['dataSource']>;\n`;
943
+ }
944
+ else {
945
+ code += `${this.name}: nasl.ui.${this.toHump(this.tag)}<any>;\n`;
946
+ }
947
+ }
898
948
  else {
899
949
  code += `${this.name}: nasl.ui.${this.toHump(this.tag)}<any>;\n`;
900
950
  }
@@ -905,6 +955,93 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
905
955
  }
906
956
  return code;
907
957
  }
958
+ toEmbeddedTSVariableDefinition(state, variableList) {
959
+ let code = '';
960
+ code += (0, translator_1.indent)((state?.tabSize || 0) + 2);
961
+ code += `${this.name}: {\n`;
962
+ if (Array.isArray(this.bindAttrs)) {
963
+ this.bindAttrs.filter((attr) => View__1.PAGE_COMPONENT_INCLUDE_TAG_MAP[this.tag]?.[attr.name]).forEach((attr) => {
964
+ code += attr.toEmbeddedTSVariableDefinition((0, translator_1.shiftState)(state, code, { inline: true }), variableList, this.name);
965
+ });
966
+ if (['u-select', 'van-pickerson'].includes(this.tag)) {
967
+ code += (0, translator_1.indent)((state?.tabSize || 0) + 3);
968
+ code += `pageNumber: nasl.core.Long\n`;
969
+ }
970
+ else if (['u-list-view', 'u-grid-view', 'u-table-view', 'van-list-view', 'van-grid-view'].includes(this.tag) && this.bindAttrs?.findIndex((attr) => attr.name === 'sorting') === -1) {
971
+ code += (0, translator_1.indent)((state?.tabSize || 0) + 3);
972
+ code += `sorting: {
973
+ field: nasl.core.String
974
+ order: nasl.core.String
975
+ }\n`;
976
+ }
977
+ }
978
+ code += (0, translator_1.indent)((state?.tabSize || 0) + 2);
979
+ code += `}`;
980
+ return code;
981
+ }
982
+ toNaturalTS(state = (0, translator_1.createCompilerState)(), parentLevel) {
983
+ let code = '';
984
+ const levelIndex = parentLevel || 0;
985
+ if (Array.isArray(this.bindEvents)) {
986
+ this.bindEvents.forEach((event) => {
987
+ code += event.toNaturalTS((0, translator_1.shiftState)(state, code, {
988
+ tabSize: state.tabSize,
989
+ }));
990
+ // code += '\n';
991
+ });
992
+ }
993
+ if (Array.isArray(this.children)) {
994
+ if (this.children.find((item) => item.tag === 'template' && item.slotTarget)) {
995
+ // code += indent(state.tabSize + 2);
996
+ const defaultArr = [];
997
+ // 先把插槽翻译了
998
+ this.children.forEach((element) => {
999
+ if (element.tag === 'template') {
1000
+ code += element.toNaturalTS((0, translator_1.shiftState)(state, code, {
1001
+ tabSize: state.tabSize,
1002
+ }), levelIndex);
1003
+ }
1004
+ else {
1005
+ defaultArr.push(element);
1006
+ }
1007
+ });
1008
+ // 翻译其余的子集
1009
+ if (defaultArr.length) {
1010
+ defaultArr.forEach((element) => {
1011
+ code += element.toNaturalTS((0, translator_1.shiftState)(state, code, {
1012
+ tabSize: state.tabSize,
1013
+ }), levelIndex);
1014
+ });
1015
+ }
1016
+ }
1017
+ else {
1018
+ this.children.forEach((element) => {
1019
+ code += element.toNaturalTS((0, translator_1.shiftState)(state, code, {
1020
+ tabSize: state.tabSize,
1021
+ }), levelIndex);
1022
+ });
1023
+ }
1024
+ }
1025
+ return code;
1026
+ }
1027
+ toNaturalTSDefinition(state) {
1028
+ let code = '';
1029
+ if (['u-button', 'u-form', 'u-modal', 'u-table-view', 'u-select', 'u-input', 'u-number-input'].includes(this.tag)) {
1030
+ code += (0, translator_1.indent)(state.tabSize + 1);
1031
+ // 登录组件不翻译
1032
+ // if (this.toHump(this.tag) === 'lcapLogin' || this.staticClass === 'login-form') {
1033
+ // code += `${this.name}: nasl.ui.div;\n`;
1034
+ // } else {
1035
+ code += `${this.name}: nasl.ui.${(0, utils_1.kebab2Camel)(this.tag.replace(/^\w-/, ''))},\n`;
1036
+ // }
1037
+ }
1038
+ if (Array.isArray(this.children)) {
1039
+ this.children.forEach((element) => {
1040
+ code += element.toNaturalTSDefinition((0, translator_1.shiftState)(state, code));
1041
+ });
1042
+ }
1043
+ return code;
1044
+ }
908
1045
  getTypeArgmentsStr(state) {
909
1046
  // 登录组件不翻译
910
1047
  if (this.toHump(this.tag) === 'lcapLogin' || this.staticClass === 'login-form')
@@ -913,7 +1050,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
913
1050
  // formItem的单独处理
914
1051
  if (this.tag === 'u-form-item') {
915
1052
  if (Array.isArray(this.children) && this.children.length) {
916
- const { tag } = this.children[0];
1053
+ const tag = this.children[0].tag;
917
1054
  if (tag === 'u-input') {
918
1055
  code += '<nasl.core.String>';
919
1056
  }
@@ -926,7 +1063,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
926
1063
  }
927
1064
  return code;
928
1065
  }
929
- const { bindAttrs } = this;
1066
+ const bindAttrs = this.bindAttrs;
930
1067
  if (bindAttrs && bindAttrs.length) {
931
1068
  const attr = bindAttrs.find((item) => item.name === 'data-source');
932
1069
  if (attr && attr.expression) {
@@ -943,14 +1080,19 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
943
1080
  getDatasourceTypeCodeStr(state, eleArr) {
944
1081
  let code = '';
945
1082
  (eleArr || []).forEach((element, index) => {
946
- const { bindAttrs } = element;
1083
+ const bindAttrs = element.bindAttrs;
947
1084
  if (bindAttrs && bindAttrs.length) {
948
1085
  const attr = bindAttrs.find((item) => item.name === 'data-source');
949
1086
  if (attr && attr.expression) {
950
- const datasourceName = `datasourceName${index}`;
1087
+ const datasourceName = `datasourceName${element.name}`;
951
1088
  element.__tsDataSourceTypeName = datasourceName;
952
- if (attr.expression instanceof MemberExpression__1.default || attr.expression instanceof Identifier__1.default) {
953
- const value = attr.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code));
1089
+ if (attr.expression instanceof MemberExpression__1.default || attr.expression instanceof Identifier__1.default || attr.expression instanceof concepts_1.CallLogic) {
1090
+ const extraParams = {
1091
+ tabSize: 4,
1092
+ inline: true,
1093
+ noNeedParams: true
1094
+ };
1095
+ let value = attr.expression.toEmbeddedTS((0, translator_1.shiftState)(state, code, attr.expression.concept === 'CallLogic' ? extraParams : {}));
954
1096
  code += `type ${datasourceName} = `;
955
1097
  code += `nasl.ui.GetItemTypeFromDataSource<typeof ${value}>;\n`;
956
1098
  }
@@ -969,18 +1111,20 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
969
1111
  return code;
970
1112
  }
971
1113
  toEmbeddedTS(state, parentLevel) {
972
- const { parentNode, app, tag, staticClass, name, bindDirectives, bindRoles, bindEvents, children } = this;
1114
+ const { parentNode, app, tag, staticClass, name, bindDirectives, bindRoles, bindEvents, children, } = this;
973
1115
  const chineseTsName = (name) => {
974
1116
  let tsName = name;
975
1117
  // 匹配所有特殊字符都转为_
976
1118
  tsName = tsName.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '_');
977
1119
  if (/^\d/.test(tsName)) {
978
- tsName = `$${tsName}`;
1120
+ tsName = '$' + tsName;
979
1121
  }
980
1122
  return tsName;
981
1123
  };
982
1124
  // 过滤模板的登录中的一些翻译,这里只过滤h5表格中的两个列
983
- if ((parentNode.concept === 'ViewElement' && parentNode.tag && this.toHump(parentNode.tag) === 'lcapLogin') || staticClass === 'login-cell') {
1125
+ if (parentNode.concept === 'ViewElement' &&
1126
+ parentNode.tag && this.toHump(parentNode.tag) === 'lcapLogin' ||
1127
+ staticClass === 'login-cell') {
984
1128
  return '';
985
1129
  }
986
1130
  // pc事件翻译
@@ -1000,7 +1144,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1000
1144
  }
1001
1145
  let levelIndex = parentLevel || 0;
1002
1146
  if (tag === 'template' && this.haveScope()) {
1003
- const slotTarget = !this.slotTarget ? 'slotDefault' : `slot${this.toFirstUpper(this.toHump(this.slotTarget))}`;
1147
+ const slotTarget = !this.slotTarget ? 'slotDefault' : 'slot' + this.toFirstUpper(this.toHump(this.slotTarget));
1004
1148
  let code = '';
1005
1149
  code += `${slotTarget}: (current${levelIndex === 0 ? '' : levelIndex})=> {\n`;
1006
1150
  code += this.getDatasourceTypeCodeStr(state, this.children);
@@ -1008,7 +1152,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1008
1152
  code += 'return [';
1009
1153
  this.children.forEach((element) => {
1010
1154
  code += element.toEmbeddedTS((0, translator_1.shiftState)(state, code, {
1011
- tabSize: state?.tabSize || 0,
1155
+ tabSize: (state?.tabSize || 0),
1012
1156
  }), levelIndex);
1013
1157
  });
1014
1158
  code += ']';
@@ -1016,15 +1160,15 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1016
1160
  code += '},\n';
1017
1161
  return code;
1018
1162
  }
1019
- if (tag === 'template') {
1020
- const slotTarget = !this.slotTarget ? 'slotDefault' : `slot${this.toFirstUpper(this.toHump(this.slotTarget))}`;
1163
+ else if (tag === 'template') {
1164
+ const slotTarget = !this.slotTarget ? 'slotDefault' : 'slot' + this.toFirstUpper(this.toHump(this.slotTarget));
1021
1165
  let code = '';
1022
1166
  code += `${slotTarget}: ()=> {\n`;
1023
1167
  code += this.getDatasourceTypeCodeStr(state, this.children);
1024
1168
  code += 'return [';
1025
1169
  this.children.forEach((element) => {
1026
1170
  code += element.toEmbeddedTS((0, translator_1.shiftState)(state, code, {
1027
- tabSize: state?.tabSize || 0,
1171
+ tabSize: (state?.tabSize || 0),
1028
1172
  }), levelIndex);
1029
1173
  });
1030
1174
  code += (0, translator_1.indent)((state?.tabSize || 0) + 2);
@@ -1065,10 +1209,10 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1065
1209
  code += (0, translator_1.indent)((state?.tabSize || 0) + 1);
1066
1210
  if (Array.isArray(this.bindAttrs)) {
1067
1211
  code += `bindAttr: () => [\n`;
1068
- this.bindAttrs.forEach((attr) => (code += `${attr.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: 1 }))},\n`));
1069
- this.bindDirectives.forEach((directive) => (code += `${directive.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: 1 }))},\n`));
1070
- this.bindStyles.forEach((bindStyle) => (code += `${bindStyle.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: 1 }))},\n`));
1071
- code += `${(0, translator_1.indent)((state?.tabSize || 0) + 2)}],\n`;
1212
+ this.bindAttrs.forEach((attr) => code += attr.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: 1 })) + ',\n');
1213
+ this.bindDirectives.forEach((directive) => code += directive.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: 1 })) + ',\n');
1214
+ this.bindStyles.forEach((bindStyle) => code += bindStyle.toEmbeddedTS((0, translator_1.shiftState)(state, code, { tabSize: 1 })) + ',\n');
1215
+ code += (0, translator_1.indent)((state?.tabSize || 0) + 2) + '],\n';
1072
1216
  }
1073
1217
  // 如果子集中有插槽的就
1074
1218
  if (children.find((item) => item.tag === 'template' && item.slotTarget)) {
@@ -1078,7 +1222,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1078
1222
  children.forEach((element) => {
1079
1223
  if (element.tag === 'template') {
1080
1224
  code += element.toEmbeddedTS((0, translator_1.shiftState)(state, code, {
1081
- tabSize: state?.tabSize || 0,
1225
+ tabSize: (state?.tabSize || 0),
1082
1226
  }), levelIndex);
1083
1227
  }
1084
1228
  else {
@@ -1120,7 +1264,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1120
1264
  code += '}\n';
1121
1265
  }
1122
1266
  }
1123
- code += `${(0, translator_1.indent)(state?.tabSize || 0)}})`;
1267
+ code += (0, translator_1.indent)((state?.tabSize || 0)) + '})';
1124
1268
  // 顶层元素是单独的表达式
1125
1269
  if (parentNode.concept === 'View') {
1126
1270
  code += ';\n';
@@ -1130,69 +1274,6 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1130
1274
  }
1131
1275
  return code;
1132
1276
  }
1133
- toNaturalTS(state = (0, translator_1.createCompilerState)(), parentLevel) {
1134
- let code = '';
1135
- const levelIndex = parentLevel || 0;
1136
- if (Array.isArray(this.bindEvents)) {
1137
- this.bindEvents.forEach((event) => {
1138
- code += event.toNaturalTS((0, translator_1.shiftState)(state, code, {
1139
- tabSize: state.tabSize,
1140
- }));
1141
- // code += '\n';
1142
- });
1143
- }
1144
- if (Array.isArray(this.children)) {
1145
- if (this.children.find((item) => item.tag === 'template' && item.slotTarget)) {
1146
- // code += indent(state.tabSize + 2);
1147
- const defaultArr = [];
1148
- // 先把插槽翻译了
1149
- this.children.forEach((element) => {
1150
- if (element.tag === 'template') {
1151
- code += element.toNaturalTS((0, translator_1.shiftState)(state, code, {
1152
- tabSize: state.tabSize,
1153
- }), levelIndex);
1154
- }
1155
- else {
1156
- defaultArr.push(element);
1157
- }
1158
- });
1159
- // 翻译其余的子集
1160
- if (defaultArr.length) {
1161
- defaultArr.forEach((element) => {
1162
- code += element.toNaturalTS((0, translator_1.shiftState)(state, code, {
1163
- tabSize: state.tabSize,
1164
- }), levelIndex);
1165
- });
1166
- }
1167
- }
1168
- else {
1169
- this.children.forEach((element) => {
1170
- code += element.toNaturalTS((0, translator_1.shiftState)(state, code, {
1171
- tabSize: state.tabSize,
1172
- }), levelIndex);
1173
- });
1174
- }
1175
- }
1176
- return code;
1177
- }
1178
- toNaturalTSDefinition(state) {
1179
- let code = '';
1180
- if (['u-button', 'u-form', 'u-modal', 'u-table-view', 'u-select', 'u-input', 'u-number-input'].includes(this.tag)) {
1181
- code += (0, translator_1.indent)(state.tabSize + 1);
1182
- // 登录组件不翻译
1183
- // if (this.toHump(this.tag) === 'lcapLogin' || this.staticClass === 'login-form') {
1184
- // code += `${this.name}: nasl.ui.div;\n`;
1185
- // } else {
1186
- code += `${this.name}: nasl.ui.${(0, utils_1.kebab2Camel)(this.tag.replace(/^\w-/, ''))},\n`;
1187
- // }
1188
- }
1189
- if (Array.isArray(this.children)) {
1190
- this.children.forEach((element) => {
1191
- code += element.toNaturalTSDefinition((0, translator_1.shiftState)(state, code));
1192
- });
1193
- }
1194
- return code;
1195
- }
1196
1277
  _duplicate() {
1197
1278
  const element = ViewElement_1.from(this.toTemplateJSON());
1198
1279
  const nameMap = element.deepRenameElements(this);
@@ -1256,7 +1337,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1256
1337
  name: '',
1257
1338
  kind: 'Statement',
1258
1339
  keyword: func?.params?.[index]?.name ?? '',
1259
- expression: transAstNodeToNaslNode({ ...argument }),
1340
+ expression: transAstNodeToNaslNode(Object.assign({}, argument)),
1260
1341
  }));
1261
1342
  }
1262
1343
  }
@@ -1278,10 +1359,10 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1278
1359
  static _fromASTNode(astNode, context) {
1279
1360
  const view = context?.view;
1280
1361
  // 临时处理组件的 text
1281
- // h5-mock
1282
- if (['u-text', 'van-text', 'u-link', 'u-button', 'u-label', 'u-radio', 'u-checkbox', 'u-navbar-item', 'u-sidebar-item', 'u-menu-item'].includes(astNode.tag) &&
1283
- astNode.children.length === 1 &&
1284
- astNode.children[0].type === 3) {
1362
+ //h5-mock
1363
+ if (['u-text', 'van-text', 'u-link', 'u-button', 'u-label', 'u-radio', 'u-checkbox', 'u-navbar-item', 'u-sidebar-item', 'u-menu-item'].includes(astNode.tag)
1364
+ && astNode.children.length === 1
1365
+ && astNode.children[0].type === 3) {
1285
1366
  astNode.attrs = astNode.attrs || [];
1286
1367
  astNode.attrs.push({
1287
1368
  name: 'text',
@@ -1300,18 +1381,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1300
1381
  delete astNode.scopedSlots;
1301
1382
  }
1302
1383
  // 提示不支持的属性
1303
- [
1304
- 'component',
1305
- 'inlineTemplate',
1306
- 'pre',
1307
- 'ns',
1308
- 'transition',
1309
- 'transitionOnAppear',
1310
- 'transitionMode',
1311
- 'slotName',
1312
- 'classBinding',
1313
- 'styleBinding',
1314
- ].forEach((key) => {
1384
+ ['component', 'inlineTemplate', 'pre', 'ns', 'transition', 'transitionOnAppear', 'transitionMode', 'slotName', 'classBinding', 'styleBinding'].forEach((key) => {
1315
1385
  if (astNode[key])
1316
1386
  console.warn(`[warn] ViewElement NASL unsupports '${key}' field in node `, astNode);
1317
1387
  });
@@ -1363,6 +1433,9 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1363
1433
  if (oldAttr.name === 'rules') {
1364
1434
  source.rules = tmp?.split('|').map((ruleStr) => this._parseValidationRule(ruleStr.trim()));
1365
1435
  }
1436
+ else if (['page-number', 'page-size'].includes(oldAttr.name)) {
1437
+ source.value = Number(source.value);
1438
+ }
1366
1439
  attr = new BindAttribute__1.default(source);
1367
1440
  }
1368
1441
  catch (e) {
@@ -1381,8 +1454,8 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1381
1454
  element.addBindAttribute(attr);
1382
1455
  });
1383
1456
  // compiler 处理:value.sync 时会加上update:value事件,需要过滤
1384
- astNode.events &&
1385
- Object.keys(astNode.events)
1457
+ astNode.events
1458
+ && Object.keys(astNode.events)
1386
1459
  .filter((name) => !name.startsWith('update:'))
1387
1460
  .forEach((name) => {
1388
1461
  const oldEvent = astNode.events[name];
@@ -1416,8 +1489,8 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1416
1489
  }));
1417
1490
  }
1418
1491
  });
1419
- astNode.directives &&
1420
- astNode.directives.forEach((directive) => {
1492
+ astNode.directives
1493
+ && astNode.directives.forEach((directive) => {
1421
1494
  if (directive.name === 'model') {
1422
1495
  const valueAttr = astNode.attrs && astNode.attrs.find((attr) => attr.name === 'value');
1423
1496
  if (!valueAttr) {
@@ -1497,7 +1570,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1497
1570
  preserveWhitespace: false,
1498
1571
  outputSourceRange: true,
1499
1572
  };
1500
- let { ast } = compiler.compile(code, compilerOptions);
1573
+ let ast = compiler.compile(code, compilerOptions).ast;
1501
1574
  if (ast.tag === 'template' && !ast.slotTarget)
1502
1575
  ast = ast.children[0];
1503
1576
  return this._fromASTNode(ast, {
@@ -1528,7 +1601,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1528
1601
  }
1529
1602
  if (apiOfAttr && apiOfAttr['designer-value'] !== undefined) {
1530
1603
  let designerValue = apiOfAttr['designer-value'];
1531
- // 对流程模板拖拽进行特判
1604
+ //对流程模板拖拽进行特判
1532
1605
  element.bindAttrs.forEach((property) => {
1533
1606
  if (property.name === 'repeat' && property.value === '1')
1534
1607
  designerValue = '[{}, {}]';
@@ -1567,7 +1640,8 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1567
1640
  .replace(/\bcurrent\.item\.\b/g, '');
1568
1641
  return `${name}="{{ ${value} }}"`;
1569
1642
  });
1570
- return defaultResult;
1643
+ else
1644
+ return defaultResult;
1571
1645
  }
1572
1646
  return false;
1573
1647
  },
@@ -1587,7 +1661,11 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1587
1661
  }
1588
1662
  if (childEmpty) {
1589
1663
  let addEmpty = true;
1590
- if (['u-grid-view', 'u-list-view', 'van-list-view', 'van-grid-view', 'u-carousel'].includes(el.tag)) {
1664
+ if (['u-grid-view',
1665
+ 'u-list-view',
1666
+ 'van-list-view',
1667
+ 'van-grid-view',
1668
+ 'u-carousel'].includes(el.tag)) {
1591
1669
  const hasDataSource = el.bindAttrs.find((attr) => attr.name === 'data-source');
1592
1670
  addEmpty = !hasDataSource;
1593
1671
  }
@@ -1597,21 +1675,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1597
1675
  if (hasAuto)
1598
1676
  addEmpty = false;
1599
1677
  }
1600
- if ([
1601
- 'u-select',
1602
- 'u-dropdown',
1603
- 'u-panel',
1604
- 'u-toc',
1605
- 'u-toc-item',
1606
- 'u-tree-view-new',
1607
- 'u-tree-view-node-new',
1608
- 'u-tree-select',
1609
- 'u-tree-select-new',
1610
- 'u-anchor',
1611
- 'u-drawer',
1612
- 'u-timeline',
1613
- 'u-tabs',
1614
- ].includes(el.tag)) {
1678
+ if (['u-select', 'u-dropdown', 'u-panel', 'u-toc', 'u-toc-item', 'u-tree-view-new', 'u-tree-view-node-new', 'u-tree-select', 'u-tree-select-new', 'u-anchor', 'u-drawer', 'u-timeline', 'u-tabs'].includes(el.tag)) {
1615
1679
  addEmpty = false;
1616
1680
  }
1617
1681
  const background = (emptySlot && emptySlot['empty-background']) || (hasSupport ? 'add-sub' : '');
@@ -1620,7 +1684,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1620
1684
  }
1621
1685
  if (['u-router-view', 'van-router-view'].includes(el.tag)) {
1622
1686
  const excludes = ['background-color:', 'background:', 'background-image:'];
1623
- if (excludes.some((key) => el.staticStyle && el.staticStyle.includes(key))) {
1687
+ if (excludes.some((key) => (el.staticStyle && el.staticStyle.includes(key)))) {
1624
1688
  parts.push(':designer="false"');
1625
1689
  }
1626
1690
  }
@@ -1635,7 +1699,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1635
1699
  let index = 0;
1636
1700
  while (parent && parent.concept !== 'View') {
1637
1701
  if (parent.slotScope) {
1638
- argsList.push(index === 0 ? 'current' : `current${index}`);
1702
+ argsList.push(index === 0 ? 'current' : 'current' + index);
1639
1703
  index++;
1640
1704
  }
1641
1705
  parent = parent.parentNode;
@@ -1663,7 +1727,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1663
1727
  if (this.slotScope) {
1664
1728
  currentList.unshift(this.slotScope);
1665
1729
  }
1666
- const newOptions = {
1730
+ const newOptions = Object.assign({
1667
1731
  indentStyle: 'space',
1668
1732
  tabSize: 4,
1669
1733
  indentLevel: 0,
@@ -1679,21 +1743,19 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1679
1743
  .filter((item) => item !== undefined)
1680
1744
  .join(', ')}}"`;
1681
1745
  },
1682
- ...options,
1746
+ }, options, {
1683
1747
  currentList,
1684
- };
1748
+ });
1685
1749
  const tabString = ' '.repeat(newOptions.tabSize * newOptions.indentLevel);
1686
1750
  const insideTabString = ' '.repeat(newOptions.tabSize * (newOptions.indentLevel + 1));
1687
1751
  let shouldIndent = true;
1688
- const content = !this.children
1689
- ? ''
1690
- : this.children
1691
- .map((element) => {
1692
- const childOptions = { ...newOptions };
1693
- childOptions.indentLevel++;
1694
- return (shouldIndent ? `\n${insideTabString}` : '') + element?.toVue(childOptions);
1695
- })
1696
- .join('');
1752
+ const content = !this.children ? '' : this.children
1753
+ .map((element) => {
1754
+ const childOptions = Object.assign({}, newOptions);
1755
+ childOptions.indentLevel++;
1756
+ return (shouldIndent ? '\n' + insideTabString : '') + element?.toVue(childOptions);
1757
+ })
1758
+ .join('');
1697
1759
  if (!content.length) {
1698
1760
  shouldIndent = false;
1699
1761
  }
@@ -1709,8 +1771,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1709
1771
  parts.push(`vusion-node-path="${this.nodePath}"`);
1710
1772
  }
1711
1773
  // 模板里解析时候,可能会有多级嵌套的 current,所以当前有多少的长度,当前就是多大的下标
1712
- this.slotTarget &&
1713
- parts.push(`#${this.slotTarget}${this.slotScope ? `="${currentList.length > 1 ? this.slotScope + (currentList.length - 1) : this.slotScope}"` : ''}`);
1774
+ this.slotTarget && parts.push(`#${this.slotTarget}` + (this.slotScope ? `="${currentList.length > 1 ? this.slotScope + (currentList.length - 1) : this.slotScope}"` : ''));
1714
1775
  this.refName && parts.push(`:ref="\`${this.refName}\`"`);
1715
1776
  this.staticClass && parts.push(`class="${this.staticClass}"`);
1716
1777
  this.staticStyle && parts.push(`style="${this.staticStyle}"`);
@@ -1749,13 +1810,13 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1749
1810
  let partsString = '';
1750
1811
  parts.forEach((part) => {
1751
1812
  if (partsLength >= 120 || part.length >= 120) {
1752
- partsString += `\n${tabString}${' '.repeat(3)}`; // ' '.repeat(el.tag.length + 1);
1813
+ partsString += '\n' + tabString + ' '.repeat(3); // ' '.repeat(el.tag.length + 1);
1753
1814
  partsLength = 0;
1754
1815
  }
1755
- partsString += ` ${part}`;
1816
+ partsString += ' ' + part;
1756
1817
  partsLength += part.length;
1757
1818
  });
1758
- let htmlContent = `<${this.tag}${partsString.length ? partsString : ''}>${content}${shouldIndent ? `\n${tabString}` : ''}</${this.tag}>`;
1819
+ let htmlContent = `<${this.tag}${partsString.length ? partsString : ''}>` + content + (shouldIndent ? '\n' + tabString : '') + `</${this.tag}>`;
1759
1820
  if (!content.trim() && selfClosingTag.includes(this.tag)) {
1760
1821
  htmlContent = `<${this.tag}${partsString.length ? partsString : ''} />`;
1761
1822
  }
@@ -1802,7 +1863,7 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1802
1863
  }
1803
1864
  parent = parent.parentNode;
1804
1865
  }
1805
- current = index === 0 ? 'current' : `current${index}`;
1866
+ current = (index === 0 ? 'current' : 'current' + index);
1806
1867
  return current;
1807
1868
  }
1808
1869
  /**
@@ -1811,13 +1872,16 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1811
1872
  * @param doNotRecordLastWidthHeight 是否不记录上一次的宽高
1812
1873
  */
1813
1874
  computeConstraintStyle(positionData, ops = {}) {
1875
+ if (!positionData) {
1876
+ return;
1877
+ }
1814
1878
  const { nodeRect, parentRect, parentBorder } = positionData;
1815
1879
  const staticWidth = nodeRect.width;
1816
1880
  const staticHeight = nodeRect.height;
1817
1881
  const staticLeft = nodeRect.left - parentRect.left - parentBorder.left;
1818
1882
  const staticTop = nodeRect.top - parentRect.top - parentBorder.top;
1819
- const staticRight = parentRect.width - nodeRect.width - staticLeft - parentBorder.right - parentBorder.left;
1820
- const staticBottom = parentRect.height - nodeRect.height - staticTop - parentBorder.bottom - parentBorder.top;
1883
+ const staticRight = (parentRect.width - nodeRect.width - staticLeft - parentBorder.right - parentBorder.left);
1884
+ const staticBottom = (parentRect.height - nodeRect.height - staticTop - parentBorder.bottom - parentBorder.top);
1821
1885
  const styleObj = this.parseStyleToObject(this.staticStyle);
1822
1886
  const constraintX = styleObj['--constraint-x'] || 'left';
1823
1887
  const constraintY = styleObj['--constraint-y'] || 'top';
@@ -1837,12 +1901,12 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1837
1901
  const parentWidth = staticLeft + staticWidth + staticRight;
1838
1902
  const parentHeight = staticTop + staticHeight + staticBottom;
1839
1903
  if (constraintX === 'left') {
1840
- left = `${staticLeft}px`;
1904
+ left = staticLeft + 'px';
1841
1905
  right = '';
1842
1906
  }
1843
1907
  else if (constraintX === 'right') {
1844
1908
  left = '';
1845
- right = `${staticRight}px`;
1909
+ right = staticRight + 'px';
1846
1910
  }
1847
1911
  else if (constraintX === 'center') {
1848
1912
  const offset = staticLeft + staticWidth / 2 - parentWidth / 2;
@@ -1851,24 +1915,24 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1851
1915
  transform = 'translateX(-50%)';
1852
1916
  }
1853
1917
  else if (constraintX === 'scale') {
1854
- left = `${(staticLeft * 100) / parentWidth}%`;
1918
+ left = staticLeft * 100 / parentWidth + '%';
1855
1919
  right = '';
1856
- width = `${(staticWidth * 100) / parentWidth}%`;
1920
+ width = staticWidth * 100 / parentWidth + '%';
1857
1921
  constraintWidthAuto = 1;
1858
1922
  }
1859
1923
  else if (constraintX === 'left-right') {
1860
- left = `${staticLeft}px`;
1861
- right = `${staticRight}px`;
1924
+ left = staticLeft + 'px';
1925
+ right = staticRight + 'px';
1862
1926
  width = 'auto';
1863
1927
  constraintWidthAuto = 1;
1864
1928
  }
1865
1929
  if (constraintY === 'top') {
1866
- top = `${staticTop}px`;
1930
+ top = staticTop + 'px';
1867
1931
  bottom = '';
1868
1932
  }
1869
1933
  else if (constraintY === 'bottom') {
1870
1934
  top = '';
1871
- bottom = `${staticBottom}px`;
1935
+ bottom = staticBottom + 'px';
1872
1936
  }
1873
1937
  else if (constraintY === 'center') {
1874
1938
  const offset = staticTop + staticHeight / 2 - parentHeight / 2;
@@ -1877,14 +1941,14 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1877
1941
  transform = transform ? 'translate(-50%, -50%)' : 'translateY(-50%)';
1878
1942
  }
1879
1943
  else if (constraintY === 'scale') {
1880
- top = `${(staticTop * 100) / parentHeight}%`;
1944
+ top = staticTop * 100 / parentHeight + '%';
1881
1945
  bottom = '';
1882
- height = `${(staticHeight * 100) / parentHeight}%`;
1946
+ height = staticHeight * 100 / parentHeight + '%';
1883
1947
  constraintHeightAuto = 1;
1884
1948
  }
1885
1949
  else if (constraintY === 'top-bottom') {
1886
- top = `${staticTop}px`;
1887
- bottom = `${staticBottom}px`;
1950
+ top = staticTop + 'px';
1951
+ bottom = staticBottom + 'px';
1888
1952
  height = 'auto';
1889
1953
  constraintHeightAuto = 1;
1890
1954
  }
@@ -1933,16 +1997,16 @@ let ViewElement = ViewElement_1 = class ViewElement extends BaseNode_1.default {
1933
1997
  return styleObj;
1934
1998
  }
1935
1999
  stringifyStyleAttr(styleObj) {
1936
- return (Object.keys(styleObj)
2000
+ return Object.keys(styleObj)
1937
2001
  // 空字符串是允许的,因为有时候想要覆盖之前的样式。undefined 则不允许
1938
- .filter((key) => styleObj[key] !== undefined)
2002
+ .filter(key => styleObj[key] !== undefined)
1939
2003
  .map((key) => `${key}:${String(styleObj[key]).trim()};`)
1940
- .join(''));
2004
+ .join('');
1941
2005
  }
1942
2006
  // 批量更新绑定属性
1943
2007
  batchUpdateBindAttrs(attrOptions) {
1944
- const oldBindAttrs = this.bindAttrs.filter((it) => !attrOptions.some((item) => item.name === it.name));
1945
- const newBindAttrs = attrOptions.map((it) => BindAttribute__1.default.from(it, this, 'bindAttrs'));
2008
+ const oldBindAttrs = this.bindAttrs.filter(it => !attrOptions.some(item => item.name === it.name));
2009
+ const newBindAttrs = attrOptions.map(it => BindAttribute__1.default.from(it, this, 'bindAttrs'));
1946
2010
  this.update({
1947
2011
  bindAttrs: [...oldBindAttrs, ...newBindAttrs],
1948
2012
  });
@@ -1995,10 +2059,10 @@ __decorate([
1995
2059
  ], ViewElement.prototype, "children", void 0);
1996
2060
  __decorate([
1997
2061
  (0, translator_1.withSourceMap)()
1998
- ], ViewElement.prototype, "toEmbeddedTS", null);
2062
+ ], ViewElement.prototype, "toNaturalTS", null);
1999
2063
  __decorate([
2000
2064
  (0, translator_1.withSourceMap)()
2001
- ], ViewElement.prototype, "toNaturalTS", null);
2065
+ ], ViewElement.prototype, "toEmbeddedTS", null);
2002
2066
  __decorate([
2003
2067
  (0, decorators_1.excludedInJSON)()
2004
2068
  ], ViewElement.prototype, "computedStyle", void 0);
@@ -2008,8 +2072,8 @@ ViewElement = ViewElement_1 = __decorate([
2008
2072
  exports.ViewElement = ViewElement;
2009
2073
  classMap_1.default.ViewElement = ViewElement;
2010
2074
  exports.default = ViewElement;
2011
- //= ===============================================================================
2075
+ //================================================================================
2012
2076
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
2013
2077
  // 自动生成的代码已结束。下面可以手动编写。
2014
- //= ===============================================================================
2078
+ //================================================================================
2015
2079
  //# sourceMappingURL=ViewElement__.js.map