@lcap/nasl 3.5.0-beta.3 → 3.5.0-beta.5

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 (289) hide show
  1. package/out/breakpoint/store/core.js +1 -1
  2. package/out/breakpoint/store/core.js.map +1 -1
  3. package/out/common/BaseNode.d.ts +7 -0
  4. package/out/common/BaseNode.js +15 -2
  5. package/out/common/BaseNode.js.map +1 -1
  6. package/out/concepts/AnonymousFunction__.d.ts +1 -0
  7. package/out/concepts/AnonymousFunction__.js +34 -16
  8. package/out/concepts/AnonymousFunction__.js.map +1 -1
  9. package/out/concepts/Argument__.d.ts +1 -0
  10. package/out/concepts/Argument__.js +28 -8
  11. package/out/concepts/Argument__.js.map +1 -1
  12. package/out/concepts/Assignment__.js +5 -7
  13. package/out/concepts/Assignment__.js.map +1 -1
  14. package/out/concepts/BatchAssignment__.js +5 -3
  15. package/out/concepts/BatchAssignment__.js.map +1 -1
  16. package/out/concepts/BinaryExpression__.d.ts +1 -0
  17. package/out/concepts/BinaryExpression__.js +30 -13
  18. package/out/concepts/BinaryExpression__.js.map +1 -1
  19. package/out/concepts/BindAttribute__.js +11 -3
  20. package/out/concepts/BindAttribute__.js.map +1 -1
  21. package/out/concepts/BindDirective__.js +3 -3
  22. package/out/concepts/BindDirective__.js.map +1 -1
  23. package/out/concepts/BindEvent__.js +2 -2
  24. package/out/concepts/BindEvent__.js.map +1 -1
  25. package/out/concepts/BooleanLiteral__.d.ts +1 -0
  26. package/out/concepts/BooleanLiteral__.js +6 -0
  27. package/out/concepts/BooleanLiteral__.js.map +1 -1
  28. package/out/concepts/BusinessComponent__.d.ts +4 -2
  29. package/out/concepts/BusinessComponent__.js +128 -89
  30. package/out/concepts/BusinessComponent__.js.map +1 -1
  31. package/out/concepts/CallConnector__.d.ts +1 -0
  32. package/out/concepts/CallConnector__.js +6 -0
  33. package/out/concepts/CallConnector__.js.map +1 -1
  34. package/out/concepts/CallEvent__.d.ts +4 -0
  35. package/out/concepts/CallEvent__.js +19 -2
  36. package/out/concepts/CallEvent__.js.map +1 -1
  37. package/out/concepts/CallFunction__.d.ts +1 -0
  38. package/out/concepts/CallFunction__.js +62 -8
  39. package/out/concepts/CallFunction__.js.map +1 -1
  40. package/out/concepts/CallInterface__.js +31 -22
  41. package/out/concepts/CallInterface__.js.map +1 -1
  42. package/out/concepts/CallLogic__.js +49 -38
  43. package/out/concepts/CallLogic__.js.map +1 -1
  44. package/out/concepts/CallQueryComponent__.d.ts +2 -0
  45. package/out/concepts/CallQueryComponent__.js +94 -8
  46. package/out/concepts/CallQueryComponent__.js.map +1 -1
  47. package/out/concepts/DefaultValue__.d.ts +1 -0
  48. package/out/concepts/DefaultValue__.js +7 -1
  49. package/out/concepts/DefaultValue__.js.map +1 -1
  50. package/out/concepts/Destination__.d.ts +1 -1
  51. package/out/concepts/Destination__.js +34 -22
  52. package/out/concepts/Destination__.js.map +1 -1
  53. package/out/concepts/EntityProperty__.d.ts +1 -0
  54. package/out/concepts/EntityProperty__.js +26 -2
  55. package/out/concepts/EntityProperty__.js.map +1 -1
  56. package/out/concepts/Entity__.d.ts +1 -0
  57. package/out/concepts/Entity__.js +25 -0
  58. package/out/concepts/Entity__.js.map +1 -1
  59. package/out/concepts/EnumItem__.d.ts +1 -0
  60. package/out/concepts/EnumItem__.js +12 -0
  61. package/out/concepts/EnumItem__.js.map +1 -1
  62. package/out/concepts/Enum__.d.ts +1 -0
  63. package/out/concepts/Enum__.js +16 -2
  64. package/out/concepts/Enum__.js.map +1 -1
  65. package/out/concepts/Event__.d.ts +4 -0
  66. package/out/concepts/Event__.js +12 -0
  67. package/out/concepts/Event__.js.map +1 -1
  68. package/out/concepts/ForEachStatement__.js +10 -16
  69. package/out/concepts/ForEachStatement__.js.map +1 -1
  70. package/out/concepts/FrontendType__.js +1 -0
  71. package/out/concepts/FrontendType__.js.map +1 -1
  72. package/out/concepts/Identifier__.d.ts +2 -0
  73. package/out/concepts/Identifier__.js +21 -0
  74. package/out/concepts/Identifier__.js.map +1 -1
  75. package/out/concepts/JSBlock__.js +1 -1
  76. package/out/concepts/JSBlock__.js.map +1 -1
  77. package/out/concepts/LogicItem__.d.ts +6 -0
  78. package/out/concepts/LogicItem__.js +11 -1
  79. package/out/concepts/LogicItem__.js.map +1 -1
  80. package/out/concepts/Logic__.js +24 -23
  81. package/out/concepts/Logic__.js.map +1 -1
  82. package/out/concepts/MatchCase__.js +5 -5
  83. package/out/concepts/MatchCase__.js.map +1 -1
  84. package/out/concepts/Match__.js +1 -1
  85. package/out/concepts/Match__.js.map +1 -1
  86. package/out/concepts/MemberExpression__.d.ts +1 -0
  87. package/out/concepts/MemberExpression__.js +13 -3
  88. package/out/concepts/MemberExpression__.js.map +1 -1
  89. package/out/concepts/NewComposite__.js +3 -3
  90. package/out/concepts/NewComposite__.js.map +1 -1
  91. package/out/concepts/NewList__.js +4 -4
  92. package/out/concepts/NewList__.js.map +1 -1
  93. package/out/concepts/NewMap__.d.ts +1 -1
  94. package/out/concepts/NewMap__.js +6 -5
  95. package/out/concepts/NewMap__.js.map +1 -1
  96. package/out/concepts/NullLiteral__.d.ts +2 -0
  97. package/out/concepts/NullLiteral__.js +12 -0
  98. package/out/concepts/NullLiteral__.js.map +1 -1
  99. package/out/concepts/NumericLiteral__.d.ts +1 -0
  100. package/out/concepts/NumericLiteral__.js +7 -1
  101. package/out/concepts/NumericLiteral__.js.map +1 -1
  102. package/out/concepts/OqlQueryComponent__.js +4 -2
  103. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  104. package/out/concepts/Param__.d.ts +1 -0
  105. package/out/concepts/Param__.js +41 -0
  106. package/out/concepts/Param__.js.map +1 -1
  107. package/out/concepts/ProcessElement__.js +9 -1
  108. package/out/concepts/ProcessElement__.js.map +1 -1
  109. package/out/concepts/QueryAggregateExpression__.d.ts +2 -0
  110. package/out/concepts/QueryAggregateExpression__.js +16 -0
  111. package/out/concepts/QueryAggregateExpression__.js.map +1 -1
  112. package/out/concepts/QueryFieldExpression__.d.ts +2 -0
  113. package/out/concepts/QueryFieldExpression__.js +33 -0
  114. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  115. package/out/concepts/QueryFromExpression__.d.ts +2 -0
  116. package/out/concepts/QueryFromExpression__.js +27 -0
  117. package/out/concepts/QueryFromExpression__.js.map +1 -1
  118. package/out/concepts/QueryGroupByExpression__.d.ts +2 -0
  119. package/out/concepts/QueryGroupByExpression__.js +13 -1
  120. package/out/concepts/QueryGroupByExpression__.js.map +1 -1
  121. package/out/concepts/QueryJoinExpression__.d.ts +2 -0
  122. package/out/concepts/QueryJoinExpression__.js +37 -0
  123. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  124. package/out/concepts/QueryLimitExpression__.d.ts +2 -0
  125. package/out/concepts/QueryLimitExpression__.js +16 -0
  126. package/out/concepts/QueryLimitExpression__.js.map +1 -1
  127. package/out/concepts/QueryOrderByExpression__.d.ts +2 -0
  128. package/out/concepts/QueryOrderByExpression__.js +22 -0
  129. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  130. package/out/concepts/QuerySelectExpression__.d.ts +3 -0
  131. package/out/concepts/QuerySelectExpression__.js +41 -0
  132. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  133. package/out/concepts/SelectMembers__.d.ts +1 -0
  134. package/out/concepts/SelectMembers__.js +7 -0
  135. package/out/concepts/SelectMembers__.js.map +1 -1
  136. package/out/concepts/SqlQueryComponent__.js +4 -2
  137. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  138. package/out/concepts/StringInterpolation__.d.ts +1 -0
  139. package/out/concepts/StringInterpolation__.js +20 -2
  140. package/out/concepts/StringInterpolation__.js.map +1 -1
  141. package/out/concepts/StringLiteral__.d.ts +1 -0
  142. package/out/concepts/StringLiteral__.js +21 -1
  143. package/out/concepts/StringLiteral__.js.map +1 -1
  144. package/out/concepts/StructureProperty__.d.ts +1 -0
  145. package/out/concepts/StructureProperty__.js +19 -0
  146. package/out/concepts/StructureProperty__.js.map +1 -1
  147. package/out/concepts/Structure__.d.ts +1 -0
  148. package/out/concepts/Structure__.js +22 -7
  149. package/out/concepts/Structure__.js.map +1 -1
  150. package/out/concepts/SwitchCase__.js +1 -1
  151. package/out/concepts/SwitchCase__.js.map +1 -1
  152. package/out/concepts/TypeAnnotation__.d.ts +1 -0
  153. package/out/concepts/TypeAnnotation__.js +42 -1
  154. package/out/concepts/TypeAnnotation__.js.map +1 -1
  155. package/out/concepts/TypeParam__.d.ts +2 -1
  156. package/out/concepts/TypeParam__.js +7 -1
  157. package/out/concepts/TypeParam__.js.map +1 -1
  158. package/out/concepts/Unparsed__.js +1 -1
  159. package/out/concepts/Unparsed__.js.map +1 -1
  160. package/out/concepts/ValidationRule__.js +2 -1
  161. package/out/concepts/ValidationRule__.js.map +1 -1
  162. package/out/concepts/ViewElement__.d.ts +1 -0
  163. package/out/concepts/ViewElement__.js +72 -59
  164. package/out/concepts/ViewElement__.js.map +1 -1
  165. package/out/concepts/View__.d.ts +2 -1
  166. package/out/concepts/View__.js +6 -19
  167. package/out/concepts/View__.js.map +1 -1
  168. package/out/generator/genBundleFiles.d.ts +1 -0
  169. package/out/generator/genBundleFiles.js +4 -1
  170. package/out/generator/genBundleFiles.js.map +1 -1
  171. package/out/natural/genNaturalTS.d.ts +4 -1
  172. package/out/natural/genNaturalTS.js +38 -1
  173. package/out/natural/genNaturalTS.js.map +1 -1
  174. package/out/natural/transformTSCode.js +52 -41
  175. package/out/natural/transformTSCode.js.map +1 -1
  176. package/out/server/formatTsUtils.js +10 -9
  177. package/out/server/formatTsUtils.js.map +1 -1
  178. package/out/server/getFunctions.js +3 -3
  179. package/out/server/getFunctions.js.map +1 -1
  180. package/out/server/getProcesses.js +3 -3
  181. package/out/server/getProcesses.js.map +1 -1
  182. package/out/server/naslServer.js +52 -17
  183. package/out/server/naslServer.js.map +1 -1
  184. package/out/server/translator.js +8 -0
  185. package/out/server/translator.js.map +1 -1
  186. package/out/templator/genCurdEditMultipleKeyBlock.js +1 -1
  187. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  188. package/out/templator/genGetBlock.js +2 -1
  189. package/out/templator/genGetBlock.js.map +1 -1
  190. package/out/templator/genUpdateBlock.js +2 -1
  191. package/out/templator/genUpdateBlock.js.map +1 -1
  192. package/out/templator/utils.js +3 -3
  193. package/out/templator/utils.js.map +1 -1
  194. package/out/translator/types.d.ts +2 -0
  195. package/out/translator/utils.d.ts +2 -1
  196. package/out/translator/utils.js +44 -7
  197. package/out/translator/utils.js.map +1 -1
  198. package/out/utils/string.js +2 -2
  199. package/out/utils/string.js.map +1 -1
  200. package/out/utils/time-slicing/performance.js +3 -3
  201. package/out/utils/time-slicing/performance.js.map +1 -1
  202. package/package.json +2 -2
  203. package/src/breakpoint/store/core.ts +1 -1
  204. package/src/common/BaseNode.ts +17 -3
  205. package/src/concepts/AnonymousFunction__.ts +24 -9
  206. package/src/concepts/Argument__.ts +28 -6
  207. package/src/concepts/Assignment__.ts +5 -7
  208. package/src/concepts/BatchAssignment__.ts +6 -3
  209. package/src/concepts/BinaryExpression__.ts +30 -13
  210. package/src/concepts/BindAttribute__.ts +10 -3
  211. package/src/concepts/BindDirective__.ts +3 -3
  212. package/src/concepts/BindEvent__.ts +2 -2
  213. package/src/concepts/BooleanLiteral__.ts +5 -0
  214. package/src/concepts/BusinessComponent__.ts +144 -100
  215. package/src/concepts/CallConnector__.ts +5 -0
  216. package/src/concepts/CallEvent__.ts +20 -3
  217. package/src/concepts/CallFunction__.ts +54 -8
  218. package/src/concepts/CallInterface__.ts +31 -24
  219. package/src/concepts/CallLogic__.ts +48 -37
  220. package/src/concepts/CallQueryComponent__.ts +101 -8
  221. package/src/concepts/DefaultValue__.ts +6 -1
  222. package/src/concepts/Destination__.ts +32 -22
  223. package/src/concepts/EntityProperty__.ts +30 -2
  224. package/src/concepts/Entity__.ts +29 -0
  225. package/src/concepts/EnumItem__.ts +17 -0
  226. package/src/concepts/Enum__.ts +19 -2
  227. package/src/concepts/Event__.ts +13 -0
  228. package/src/concepts/ForEachStatement__.ts +10 -20
  229. package/src/concepts/FrontendType__.ts +1 -0
  230. package/src/concepts/Identifier__.ts +19 -0
  231. package/src/concepts/JSBlock__.ts +1 -1
  232. package/src/concepts/LogicItem__.ts +13 -1
  233. package/src/concepts/Logic__.ts +24 -24
  234. package/src/concepts/MatchCase__.ts +5 -5
  235. package/src/concepts/Match__.ts +1 -1
  236. package/src/concepts/MemberExpression__.ts +12 -3
  237. package/src/concepts/NewComposite__.ts +7 -9
  238. package/src/concepts/NewList__.ts +4 -4
  239. package/src/concepts/NewMap__.ts +6 -5
  240. package/src/concepts/NullLiteral__.ts +10 -0
  241. package/src/concepts/NumericLiteral__.ts +6 -1
  242. package/src/concepts/OqlQueryComponent__.ts +4 -2
  243. package/src/concepts/Param__.ts +39 -0
  244. package/src/concepts/ProcessElement__.ts +8 -1
  245. package/src/concepts/QueryAggregateExpression__.ts +15 -0
  246. package/src/concepts/QueryFieldExpression__.ts +34 -0
  247. package/src/concepts/QueryFromExpression__.ts +29 -0
  248. package/src/concepts/QueryGroupByExpression__.ts +11 -1
  249. package/src/concepts/QueryJoinExpression__.ts +39 -0
  250. package/src/concepts/QueryLimitExpression__.ts +14 -0
  251. package/src/concepts/QueryOrderByExpression__.ts +23 -0
  252. package/src/concepts/QuerySelectExpression__.ts +55 -0
  253. package/src/concepts/SelectMembers__.ts +7 -0
  254. package/src/concepts/SqlQueryComponent__.ts +4 -2
  255. package/src/concepts/StringInterpolation__.ts +18 -2
  256. package/src/concepts/StringLiteral__.ts +20 -1
  257. package/src/concepts/StructureProperty__.ts +22 -0
  258. package/src/concepts/Structure__.ts +24 -7
  259. package/src/concepts/SwitchCase__.ts +1 -1
  260. package/src/concepts/TypeAnnotation__.ts +37 -1
  261. package/src/concepts/TypeParam__.ts +6 -1
  262. package/src/concepts/Unparsed__.ts +1 -1
  263. package/src/concepts/ValidationRule__.ts +6 -1
  264. package/src/concepts/ViewElement__.ts +74 -58
  265. package/src/concepts/View__.ts +6 -19
  266. package/src/generator/genBundleFiles.ts +6 -1
  267. package/src/natural/genNaturalTS.ts +41 -0
  268. package/src/natural/transformTSCode.ts +50 -42
  269. package/src/server/formatTsUtils.ts +16 -11
  270. package/src/server/getFunctions.ts +3 -3
  271. package/src/server/getProcesses.ts +3 -3
  272. package/src/server/naslServer.ts +56 -18
  273. package/src/server/translator.ts +7 -0
  274. package/src/templator/genCurdEditMultipleKeyBlock.ts +1 -1
  275. package/src/templator/genGetBlock.ts +2 -1
  276. package/src/templator/genUpdateBlock.ts +2 -1
  277. package/src/templator/utils.ts +3 -3
  278. package/src/translator/types.ts +4 -0
  279. package/src/translator/utils.ts +73 -34
  280. package/src/utils/string.ts +2 -2
  281. package/src/utils/time-slicing/performance.ts +3 -3
  282. package/test/concepts/call-interface/__snapshots__/getQuickInfoOffset.spec.ts.snap +3 -3
  283. package/test/concepts/call-interface/__snapshots__/toEmbeddedTS.spec.ts.snap +3 -3
  284. package/test/concepts/view-element/__snapshots__/toEmbeddedTS.spec.ts.snap +199 -0
  285. package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +127 -6
  286. package/test/concepts/view-element/fixtures/table-data-source-calllogic-with-server-validation.json +2074 -0
  287. package/test/concepts/view-element/toVue.spec.ts +0 -1
  288. package/ts-worker/package.json +1 -1
  289. package/ts-worker/src/index.js +1 -0
@@ -1035,10 +1035,6 @@ export class BusinessComponent extends BaseNode {
1035
1035
  return node;
1036
1036
  }
1037
1037
 
1038
- getLogicExistingNames(excludedList: Array<BusinessLogic> = []) {
1039
- const excludedSet = new Set(excludedList);
1040
- return ((this.logics as BusinessLogic[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
1041
- }
1042
1038
  getLogicUniqueName(name = 'logic1') {
1043
1039
  return utils.unique(name, this.getLogicExistingNames(), undefined, false);
1044
1040
  }
@@ -1675,6 +1671,28 @@ export class BusinessComponent extends BaseNode {
1675
1671
  // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1676
1672
  // 自动生成的代码已结束。下面可以手动编写。
1677
1673
  //================================================================================
1674
+ getLogicExistingNames(excludedList: Array<Logic> = []) {
1675
+ const excludedSet = new Set(excludedList);
1676
+ const varList: any[] = [];
1677
+ if (Array.isArray(this.params)) {
1678
+ varList.push(...this.params);
1679
+ }
1680
+ if (Array.isArray(this.variables)) {
1681
+ varList.push(...this.variables);
1682
+ }
1683
+ if (Array.isArray(this.logics)) {
1684
+ varList.push(...this.logics);
1685
+ }
1686
+ if (Array.isArray(this.bindEvents)) {
1687
+ this.bindEvents.forEach((bindEvent) => {
1688
+ if (Array.isArray(bindEvent.logics)) {
1689
+ varList.push(...bindEvent.logics);
1690
+ }
1691
+ });
1692
+ }
1693
+ return varList.filter((item) => !excludedSet.has(item)).map((item) => item.name);
1694
+ }
1695
+
1678
1696
  static getDefaultOptions() {
1679
1697
  return {
1680
1698
  title: '业务组件',
@@ -1813,6 +1831,23 @@ export class BusinessComponent extends BaseNode {
1813
1831
  });
1814
1832
  }
1815
1833
 
1834
+ collectExistingBusinessComponent() {
1835
+ const excludedSet = new Set();
1836
+ // 先把自身加进去
1837
+ excludedSet.add(this);
1838
+ this.elements.forEach((element) => {
1839
+ const set = element.collectExistingBusinessComponent();
1840
+ if (set.size) {
1841
+ set.forEach(value => {
1842
+ if (!excludedSet.has(value)) {
1843
+ excludedSet.add(value);
1844
+ }
1845
+ });
1846
+ }
1847
+ });
1848
+ return excludedSet;
1849
+ }
1850
+
1816
1851
  // 获取当前业务组件的所有组件的名字
1817
1852
  getViewElementExistingNames(excludedList: Array<ViewElement> = []) {
1818
1853
  if (!this.existingViewElement.size) {
@@ -1875,14 +1910,17 @@ export class BusinessComponent extends BaseNode {
1875
1910
  }
1876
1911
  }
1877
1912
 
1878
- mergeBlock({ code, nodePath, position, cb }: { code: string; nodePath: string; position: string; cb?: Function }) {
1913
+ mergeBlock({ code, nodePath, position, slotTarget, cb }: { code: string; nodePath: string; position: string; slotTarget?: string; cb?: Function }) {
1879
1914
  const ViewElement = getConceptConstructor('ViewElement');
1880
1915
  const Logic = getConceptConstructor('Logic');
1881
1916
  const ParamWithGroup = getConceptConstructor('ParamWithGroup');
1882
1917
  const Variable = getConceptConstructor('Variable');
1883
1918
  const BindEvent = getConceptConstructor('BindEvent');
1884
1919
  const Structure = getConceptConstructor('Structure');
1885
- const template = utils.sliceTagContent(code, 'template');
1920
+ let template = utils.sliceTagContent(code, 'template');
1921
+ if (slotTarget) {
1922
+ template = `<template #${slotTarget}>${template}</template>`;
1923
+ }
1886
1924
  let targetNode = (this.getAncestor('App') as App)?.findNodeByPath(nodePath);
1887
1925
  let parentNode = position === 'append' ? targetNode : targetNode.parentNode;
1888
1926
  const definitionStr = utils.sliceTagContent(code, 'definition') || '{}';
@@ -2242,100 +2280,12 @@ export class BusinessComponent extends BaseNode {
2242
2280
  // 获取虚拟logic的参数和内容
2243
2281
  // 用作展示和tots查找引用
2244
2282
  self.getElementLogicRoot();
2245
- let code = `export class ${self.tsName} extends nasl.ui.VueComponent {\n`;
2246
- // 需要类型推导的局部变量/返回值需要调整申明顺序
2247
- code += `constructor(
2248
- options?: {
2249
- [propname: string]: any,
2250
- bindAttr?: {
2251
- __NASLIF?: nasl.core.Boolean,
2252
- `;
2253
- if (Array.isArray(self.params)) {
2254
- yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
2255
- code += `${param.name}?: `;
2256
- code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
2257
- code += ',\n';
2258
- });
2259
- }
2260
- code += `
2261
- },
2262
- slotDefault?: () => Array<any>,
2263
- }) {
2264
- super();\n`;
2265
-
2266
- // 绑定事件
2267
- if (Array.isArray(self.bindEvents)) {
2268
- yield* wrapForEach(self.bindEvents, function* warpForEachGenerator(event) {
2269
- code += yield* event.toEmbeddedTS(
2270
- shiftState(state, code, {
2271
- tabSize: state?.tabSize || 0,
2272
- }),
2273
- true,
2274
- );
2275
- code += '\n';
2276
- });
2277
- }
2278
- code += `\n}`;
2279
- // 自定义事件的定义
2280
- if (Array.isArray(self.events) && self.events.length) {
2281
- code += indent((state?.tabSize || 0) + 1);
2282
- yield* wrapForEach(self.events, function* warpForEachGenerator(event) {
2283
- code += yield* event.toEmbeddedTS(
2284
- shiftState(state, code, {
2285
- tabSize: (state?.tabSize || 0) + 2,
2286
- }),
2287
- );
2288
- code += '\n';
2289
- });
2290
- code += indent((state?.tabSize || 0) + 1);
2291
- }
2292
- // 逻辑
2293
- if (Array.isArray(self.logics) && self.logics.length) {
2294
- code += indent((state?.tabSize || 0) + 1);
2295
- yield* wrapForEach(self.logics, function* warpForEachGenerator(logic) {
2296
- code += yield* logic.toEmbeddedTS(
2297
- shiftState(state, code, {
2298
- tabSize: (state?.tabSize || 0) + 2,
2299
- }),
2300
- 'noExport',
2301
- );
2302
- code += '\n';
2303
- });
2304
- code += indent((state?.tabSize || 0) + 1);
2305
- }
2306
- // render函数
2307
- code += `\n${indent((state?.tabSize || 0) + 1)}`;
2308
- code += `__render(`;
2309
- code += `){\n`;
2310
- code += indent(state?.tabSize || 0);
2311
- // elements 元素
2312
- if (Array.isArray(self.elements)) {
2313
- // 生成嵌套式的内容
2314
- yield* wrapForEach(self.elements, function* warpForEachGenerator(element) {
2315
- code += yield* element.toEmbeddedTS(
2316
- shiftState(state, code, {
2317
- tabSize: (state?.tabSize || 0) + 3,
2318
- }),
2319
- );
2320
- code += '\n';
2321
- });
2322
- }
2323
- code += `\n${indent((state?.tabSize || 0) + 1)}}\n`;
2324
- if (Array.isArray(self.params)) {
2325
- code += `${indent((state?.tabSize || 0) + 1)}$destination(options: {`;
2326
- yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
2327
- code += `${param.name}?: `;
2328
- code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
2329
- code += ', ';
2330
- });
2331
- // 锚点
2332
- code += `_anchor?: nasl.core.String`;
2333
- code += '}){}\n';
2334
- }
2335
- code += `${indent(state?.tabSize || 0)}}\n`;
2336
2283
 
2284
+ /**
2285
+ * 这部分需要先执行
2286
+ **/
2337
2287
  // elements类型声明定义
2338
- code += `interface __elements {\n`;
2288
+ let code = `interface __elements {\n`;
2339
2289
  // 生成所有的name和类型定义
2340
2290
  yield* wrapForEach(self.elements, function* warpForEachGenerator(element) {
2341
2291
  code += yield* element.toEmbeddedTSDefinition(
@@ -2407,7 +2357,7 @@ export class BusinessComponent extends BaseNode {
2407
2357
  const IDENTIFIERMAP = new Set<Variable>();
2408
2358
  if (Array.isArray(self.params)) {
2409
2359
  yield* wrapForEach(self.params, function* warpForEachGenerator(param) {
2410
- code += `let ${indent((state?.tabSize || 0) + 1)}`;
2360
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
2411
2361
  code += yield* param.toEmbeddedTS(shiftState(state, code, { inline: true }));
2412
2362
  code += ';\n';
2413
2363
  });
@@ -2419,7 +2369,7 @@ export class BusinessComponent extends BaseNode {
2419
2369
  IDENTIFIERMAP.add(variable);
2420
2370
  }
2421
2371
  if (!advanceMap.get(variable)) {
2422
- code += `let ${indent((state?.tabSize || 0) + 1)}`;
2372
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
2423
2373
  code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
2424
2374
  code += ';\n';
2425
2375
  }
@@ -2486,6 +2436,7 @@ export class BusinessComponent extends BaseNode {
2486
2436
  code += '\n';
2487
2437
  code += `${indent((state?.tabSize || 0) + 2)}return\n`;
2488
2438
 
2439
+
2489
2440
  function* setPlaygroundCode(arr: Variable[] | ParamWithGroup[], name: string) {
2490
2441
  if (arr.length) {
2491
2442
  code += `${indent((state?.tabSize || 0) + 1)}/* -----以下是 ${name} 的默认值草稿------ */\n`;
@@ -2501,6 +2452,99 @@ export class BusinessComponent extends BaseNode {
2501
2452
  yield* setPlaygroundCode(self.variables, 'variables');
2502
2453
  yield* setPlaygroundCode(self.params, 'params');
2503
2454
 
2455
+ code += `${indent(state?.tabSize || 0)}}\n`;
2456
+
2457
+ code += `export class ${self.tsName} extends nasl.ui.VueComponent {\n`;
2458
+
2459
+ // 需要类型推导的局部变量/返回值需要调整申明顺序
2460
+ code += `constructor(
2461
+ options?: {
2462
+ [propname: string]: any,
2463
+ bindAttr?: {
2464
+ __NASLIF?: nasl.core.Boolean,
2465
+ `;
2466
+ if (Array.isArray(self.params)) {
2467
+ yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
2468
+ code += `${param.name}?: `;
2469
+ code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
2470
+ code += ',\n';
2471
+ });
2472
+ }
2473
+ code += `
2474
+ },
2475
+ slotDefault?: () => Array<any>,
2476
+ }) {
2477
+ super();\n`;
2478
+
2479
+ // 绑定事件
2480
+ if (Array.isArray(self.bindEvents)) {
2481
+ yield* wrapForEach(self.bindEvents, function* warpForEachGenerator(event) {
2482
+ code += yield* event.toEmbeddedTS(
2483
+ shiftState(state, code, {
2484
+ tabSize: state?.tabSize || 0,
2485
+ }),
2486
+ true,
2487
+ );
2488
+ code += '\n';
2489
+ });
2490
+ }
2491
+ code += `\n}`;
2492
+ // 自定义事件的定义
2493
+ if (Array.isArray(self.events) && self.events.length) {
2494
+ code += indent((state?.tabSize || 0) + 1);
2495
+ yield* wrapForEach(self.events, function* warpForEachGenerator(event) {
2496
+ code += yield* event.toEmbeddedTS(
2497
+ shiftState(state, code, {
2498
+ tabSize: (state?.tabSize || 0) + 2,
2499
+ }),
2500
+ );
2501
+ code += '\n';
2502
+ });
2503
+ code += indent((state?.tabSize || 0) + 1);
2504
+ }
2505
+ // 逻辑
2506
+ if (Array.isArray(self.logics) && self.logics.length) {
2507
+ code += indent((state?.tabSize || 0) + 1);
2508
+ yield* wrapForEach(self.logics, function* warpForEachGenerator(logic) {
2509
+ code += yield* logic.toEmbeddedTS(
2510
+ shiftState(state, code, {
2511
+ tabSize: (state?.tabSize || 0) + 2,
2512
+ }),
2513
+ 'noExport',
2514
+ );
2515
+ code += '\n';
2516
+ });
2517
+ code += indent((state?.tabSize || 0) + 1);
2518
+ }
2519
+ // render函数
2520
+ code += `\n${indent((state?.tabSize || 0) + 1)}`;
2521
+ code += `__render(`;
2522
+ code += `){\n`;
2523
+ code += indent(state?.tabSize || 0);
2524
+ // elements 元素
2525
+ if (Array.isArray(self.elements)) {
2526
+ // 生成嵌套式的内容
2527
+ yield* wrapForEach(self.elements, function* warpForEachGenerator(element) {
2528
+ code += yield* element.toEmbeddedTS(
2529
+ shiftState(state, code, {
2530
+ tabSize: (state?.tabSize || 0) + 3,
2531
+ }),
2532
+ );
2533
+ code += '\n';
2534
+ });
2535
+ }
2536
+ code += `\n${indent((state?.tabSize || 0) + 1)}}\n`;
2537
+ if (Array.isArray(self.params)) {
2538
+ code += `${indent((state?.tabSize || 0) + 1)}$destination(options: {`;
2539
+ yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
2540
+ code += `${param.name}?: `;
2541
+ code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
2542
+ code += ', ';
2543
+ });
2544
+ // 锚点
2545
+ code += `_anchor?: nasl.core.String`;
2546
+ code += '}){}\n';
2547
+ }
2504
2548
  code += `${indent((state?.tabSize || 0) + 1)}}\n`;
2505
2549
  return code;
2506
2550
  }
@@ -279,6 +279,11 @@ export class CallConnector extends CallLogic {
279
279
  }
280
280
  return code;
281
281
  }
282
+
283
+ @withSourceMap()
284
+ toNaturalTS(state?: TranslatorState): string {
285
+ return '';
286
+ }
282
287
  //================================================================================
283
288
  // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
284
289
  // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
@@ -82,6 +82,18 @@ export class CallEvent extends LogicItem {
82
82
  return super.from(source, parentNode, parentKey) as CallEvent;
83
83
  }
84
84
 
85
+ /**
86
+ * 设置calleeName
87
+ */
88
+ setCalleeName(calleeName: string) {
89
+ const object = {
90
+ calleeName,
91
+ };
92
+ this.update({
93
+ ...object,
94
+ });
95
+ }
96
+
85
97
  /**
86
98
  * 插入实际参数
87
99
  * @internal
@@ -291,7 +303,7 @@ export class CallEvent extends LogicItem {
291
303
  *toEmbeddedTS(state = createCompilerState()): TranslatorGenerator {
292
304
  const self = this;
293
305
  const { calleeName, completeArguments, arguments: eventArgs } = self;
294
- let code = `this.${calleeName}(`;
306
+ let code = `(this as ${this.businessComponent.name}).${calleeName ?? '__IDENTIFIER__'}(`;
295
307
  if (completeArguments?.length) {
296
308
  yield* wrapForEach(completeArguments, function* warpForEachGenerator(arg, index) {
297
309
  // 取到是不是必填放入参数中
@@ -309,9 +321,14 @@ export class CallEvent extends LogicItem {
309
321
  let code = '';
310
322
  code += `this.$emit('${this.calleeName}', {\n`;
311
323
  if (Array.isArray(completeArguments) && completeArguments.length) {
324
+ const eventNode = this.getCallNode();
325
+ const eventParams = eventNode?.params;
312
326
  completeArguments.forEach((arg, index) => {
313
- const argStr = arg?.toJS(shiftState(state, code));
314
-
327
+ let argStr = arg?.toJS(shiftState(state, code));
328
+ const paramDefaultValue = eventParams?.[index]?.defaultValue?.toJS?.();
329
+ if (paramDefaultValue) {
330
+ argStr = `${argStr} !== undefined ? ${argStr} : ${paramDefaultValue}`;
331
+ }
315
332
  code += `${arg.keyword}: ${argStr}`;
316
333
  if (index !== completeArguments?.length - 1) {
317
334
  code += ', ';
@@ -563,12 +563,12 @@ export class CallFunction extends LogicItem {
563
563
  }
564
564
 
565
565
  setCallee(func: Function) {
566
- const calleeNamespace = func.getNamespace();
567
- const calleeName = func.name;
566
+ const calleeNamespace = func?.getNamespace?.();
567
+ const calleeName = func?.name;
568
568
  const Argument = getConceptConstructor('Argument');
569
569
  const TypeAnnotation = getConceptConstructor('TypeAnnotation');
570
570
  const BaseNode = getBaseNode();
571
- const params = func.params.map((param) => {
571
+ const params = func?.params?.map?.((param) => {
572
572
  const relationOptions = { parentNode: this, parentKey: 'arguments' };
573
573
  const argument = Argument.from(
574
574
  {
@@ -696,7 +696,53 @@ export class CallFunction extends LogicItem {
696
696
  if (this.arguments.length <= 3) {
697
697
  code += '(';
698
698
  this.arguments.forEach((arg, index) => {
699
- code += arg.toNaturalTS(shiftState(state, code, { tabSize: 0 }));
699
+ if (!arg) {
700
+ code += '__IDENTIFIER__';
701
+ } else {
702
+ code += arg.toNaturalTS(shiftState(state, code, { inline: true }));
703
+ }
704
+ if (index !== this.arguments.length - 1) code += ', ';
705
+ });
706
+ if (this?.typeArguments?.[0]?.typeKind === 'reference') {
707
+ if (this.arguments?.length > 0) code += ', ';
708
+ code += `{ typeNamespace: '${this.typeArguments[0].typeNamespace}' }`;
709
+ }
710
+ code += `)`;
711
+ } else {
712
+ code += '(\n';
713
+ this.arguments.forEach((arg, index) => {
714
+ if (!arg) {
715
+ code += '__IDENTIFIER__';
716
+ } else {
717
+ code += arg.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
718
+ }
719
+ if (index !== this.arguments.length - 1) {
720
+ code += ',\n';
721
+ } else if (this?.typeArguments?.[0]?.typeKind === 'reference') {
722
+ code += `,\n{ typeNamespace: '${this.typeArguments[0].typeNamespace}' }`;
723
+ } else {
724
+ code += '\n';
725
+ }
726
+ });
727
+ code += `${indent(state.tabSize)})`;
728
+ }
729
+ return code;
730
+ }
731
+
732
+ @withSourceMap()
733
+ toTextualNASL(state = createCompilerState()): string {
734
+ let code = '';
735
+ code = this.calleeKey;
736
+ if (Array.isArray(this.typeArguments) && this.typeArguments.length) {
737
+ // 如果有内容
738
+ const typeAnnotation = this.typeArguments[0];
739
+ code += `<`;
740
+ code += `${typeAnnotation.toTextualNASL(shiftState(state, code, { tabSize: 0 }))}>`;
741
+ }
742
+ if (this.arguments.length <= 3) {
743
+ code += '(';
744
+ this.arguments.forEach((arg, index) => {
745
+ code += arg.toTextualNASL(shiftState(state, code, { inline: true }));
700
746
  if (index !== this.arguments.length - 1) code += ', ';
701
747
  });
702
748
  if (this?.typeArguments?.[0]?.typeKind === 'reference') {
@@ -707,7 +753,7 @@ export class CallFunction extends LogicItem {
707
753
  } else {
708
754
  code += '(\n';
709
755
  this.arguments.forEach((arg, index) => {
710
- code += arg.toNaturalTS(shiftState(state, code, { tabSize: state.tabSize + 1 }));
756
+ code += arg.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
711
757
  if (index !== this.arguments.length - 1) {
712
758
  code += ',\n';
713
759
  } else if (this?.typeArguments?.[0]?.typeKind === 'reference') {
@@ -723,10 +769,10 @@ export class CallFunction extends LogicItem {
723
769
 
724
770
  checkParamNameOfAnonymousFunction() {
725
771
  const fns = this.arguments
726
- .map((arg) => arg.expression)
727
- .filter((exp) => asserts.isAnonymousFunction(exp)) as unknown as AnonymousFunction[];
772
+ ?.map((arg) => arg.expression)
773
+ ?.filter((exp) => asserts.isAnonymousFunction(exp)) as unknown as AnonymousFunction[];
728
774
 
729
- fns.forEach((fn) => {
775
+ fns?.forEach?.((fn) => {
730
776
  fn.checkParamName();
731
777
  });
732
778
  }
@@ -295,10 +295,10 @@ export class CallInterface extends LogicItem {
295
295
  shouldDeleteStructures.push(stru);
296
296
  }
297
297
  });
298
- shouldDeleteStructures.forEach((s: Structure) => s.delete());
298
+ shouldDeleteStructures?.forEach?.((s: Structure) => s.delete());
299
299
  } else {
300
- const shouldDeleteStructures = oldItf.getRefStructures(parentModule.structures);
301
- shouldDeleteStructures.forEach((s: Structure) => s.delete());
300
+ const shouldDeleteStructures = oldItf.getRefStructures(parentModule?.structures);
301
+ shouldDeleteStructures?.forEach?.((s: Structure) => s.delete());
302
302
  }
303
303
  oldItf.delete();
304
304
  oldItf.afterDelete();
@@ -497,31 +497,35 @@ export class CallInterface extends LogicItem {
497
497
  let code = `${tsCalleeKey}(`;
498
498
 
499
499
  if (completeArguments?.length) {
500
- code += '{';
500
+ code += '{ ';
501
501
  completeArguments?.forEach((arg, index) => {
502
- code += arg?.toNaturalTS(shiftState(state, code), arg.paramRequired, true);
502
+ if (!arg) {
503
+ code += '__IDENTIFIER__: undefined';
504
+ } else {
505
+ code += arg.toNaturalTS(shiftState(state, code), arg.paramRequired, true);
506
+ }
503
507
  if (index !== this.arguments?.length - 1) code += ', ';
504
508
  });
505
- code += '}';
509
+ code += ' }';
506
510
  }
507
511
  code += ')';
508
- if (
509
- parentNode.concept !== 'Argument' &&
510
- parentKey !== 'test' &&
511
- parentKey !== 'patterns' &&
512
- parentKey !== 'returnExpression' &&
513
- parentNode.concept !== 'Assignment' &&
514
- parentNode.concept !== 'ForEachStatement' &&
515
- parentNode.concept !== 'SelectMembers' &&
516
- parentNode.concept !== 'UnaryExpression' &&
517
- parentNode.concept !== 'BinaryExpression' &&
518
- parentNode.concept !== 'MemberExpression' &&
519
- parentNode.concept !== 'StringInterpolation' &&
520
- !['NewMap', 'NewList'].includes(parentNode.concept)
521
- ) {
522
- code += ';';
523
- }
524
- code += '\n';
512
+ // if (
513
+ // parentNode.concept !== 'Argument' &&
514
+ // parentKey !== 'test' &&
515
+ // parentKey !== 'patterns' &&
516
+ // parentKey !== 'returnExpression' &&
517
+ // parentNode.concept !== 'Assignment' &&
518
+ // parentNode.concept !== 'ForEachStatement' &&
519
+ // parentNode.concept !== 'SelectMembers' &&
520
+ // parentNode.concept !== 'UnaryExpression' &&
521
+ // parentNode.concept !== 'BinaryExpression' &&
522
+ // parentNode.concept !== 'MemberExpression' &&
523
+ // parentNode.concept !== 'StringInterpolation' &&
524
+ // !['NewMap', 'NewList'].includes(parentNode.concept)
525
+ // ) {
526
+ // code += ';';
527
+ // }
528
+ // code += '\n';
525
529
  return code;
526
530
  }
527
531
 
@@ -720,10 +724,13 @@ export class CallInterface extends LogicItem {
720
724
  }
721
725
  if (this.arguments?.length) {
722
726
  this.arguments.forEach((arg) => {
727
+ if (!arg)
728
+ return;
729
+
723
730
  const idx = logicParam.findIndex((params) => arg.keyword === params.name);
724
731
  const param = logicParam[idx];
725
732
 
726
- arg.paramRequired = Boolean(!param?.defaultValue?.expression);
733
+ arg.paramRequired = param?.required;
727
734
  arg.paramTypeAnnotation = undefined;
728
735
  arg.paramDefaultValue = undefined;
729
736
  // 取到是不是必填放入参数中