@lcap/nasl 3.7.3-beta.1 → 3.8.0-beta.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.
Files changed (370) hide show
  1. package/.mocharc.js +0 -1
  2. package/out/automate/engine/utils.js +6 -1
  3. package/out/automate/engine/utils.js.map +1 -1
  4. package/out/bak/translator.js +37 -0
  5. package/out/bak/translator.js.map +1 -1
  6. package/out/breakpoint/shared/utils.d.ts +1 -0
  7. package/out/breakpoint/shared/utils.js +1 -1
  8. package/out/breakpoint/shared/utils.js.map +1 -1
  9. package/out/common/BaseNode.d.ts +11 -0
  10. package/out/common/BaseNode.js +101 -5
  11. package/out/common/BaseNode.js.map +1 -1
  12. package/out/concepts/Annotatable__.d.ts +109 -0
  13. package/out/concepts/Annotatable__.js +161 -0
  14. package/out/concepts/Annotatable__.js.map +1 -0
  15. package/out/concepts/AnnotationProperty__.d.ts +48 -0
  16. package/out/concepts/AnnotationProperty__.js +74 -0
  17. package/out/concepts/AnnotationProperty__.js.map +1 -0
  18. package/out/concepts/Annotation__.d.ts +128 -0
  19. package/out/concepts/Annotation__.js +248 -0
  20. package/out/concepts/Annotation__.js.map +1 -0
  21. package/out/concepts/App__.d.ts +14 -26
  22. package/out/concepts/App__.js +50 -20
  23. package/out/concepts/App__.js.map +1 -1
  24. package/out/concepts/ApplyAnnotation__.d.ts +87 -0
  25. package/out/concepts/ApplyAnnotation__.js +140 -0
  26. package/out/concepts/ApplyAnnotation__.js.map +1 -0
  27. package/out/concepts/Argument__.d.ts +19 -0
  28. package/out/concepts/Argument__.js +126 -0
  29. package/out/concepts/Argument__.js.map +1 -1
  30. package/out/concepts/AssigneeV2__.d.ts +169 -0
  31. package/out/concepts/AssigneeV2__.js +176 -1
  32. package/out/concepts/AssigneeV2__.js.map +1 -1
  33. package/out/concepts/AuthLogicForCallInterface__.js +1 -1
  34. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  35. package/out/concepts/AuthLogic__.js +1 -1
  36. package/out/concepts/AuthLogic__.js.map +1 -1
  37. package/out/concepts/BooleanLiteral__.d.ts +1 -0
  38. package/out/concepts/BooleanLiteral__.js +9 -0
  39. package/out/concepts/BooleanLiteral__.js.map +1 -1
  40. package/out/concepts/BusinessLogic__.js +1 -1
  41. package/out/concepts/BusinessLogic__.js.map +1 -1
  42. package/out/concepts/CallFunction__.js +1 -1
  43. package/out/concepts/CallFunction__.js.map +1 -1
  44. package/out/concepts/CallLogic__.d.ts +15 -0
  45. package/out/concepts/CallLogic__.js +149 -17
  46. package/out/concepts/CallLogic__.js.map +1 -1
  47. package/out/concepts/ConnectorLogic__.js +1 -1
  48. package/out/concepts/ConnectorLogic__.js.map +1 -1
  49. package/out/concepts/DatabaseTypeAnnotation__.d.ts +0 -2
  50. package/out/concepts/DatabaseTypeAnnotation__.js +0 -20
  51. package/out/concepts/DatabaseTypeAnnotation__.js.map +1 -1
  52. package/out/concepts/DepartmentManagerV2__.d.ts +29 -0
  53. package/out/concepts/DepartmentManagerV2__.js +56 -0
  54. package/out/concepts/DepartmentManagerV2__.js.map +1 -0
  55. package/out/concepts/DepartmentV2__.d.ts +33 -0
  56. package/out/concepts/DepartmentV2__.js +63 -0
  57. package/out/concepts/DepartmentV2__.js.map +1 -0
  58. package/out/concepts/DirectManagerV2__.d.ts +25 -0
  59. package/out/concepts/DirectManagerV2__.js +53 -0
  60. package/out/concepts/DirectManagerV2__.js.map +1 -0
  61. package/out/concepts/End__.js +9 -1
  62. package/out/concepts/End__.js.map +1 -1
  63. package/out/concepts/EntityProperty__.js +0 -2
  64. package/out/concepts/EntityProperty__.js.map +1 -1
  65. package/out/concepts/Entity__.d.ts +2 -2
  66. package/out/concepts/Entity__.js +4 -7
  67. package/out/concepts/Entity__.js.map +1 -1
  68. package/out/concepts/EnumItem__.d.ts +1 -12
  69. package/out/concepts/EnumItem__.js +17 -49
  70. package/out/concepts/EnumItem__.js.map +1 -1
  71. package/out/concepts/EnumSelectSetter__.d.ts +4 -0
  72. package/out/concepts/EnumSelectSetter__.js +7 -0
  73. package/out/concepts/EnumSelectSetter__.js.map +1 -1
  74. package/out/concepts/Enum__.js +1 -4
  75. package/out/concepts/Enum__.js.map +1 -1
  76. package/out/concepts/ForEachStatement__.js +1 -1
  77. package/out/concepts/ForEachStatement__.js.map +1 -1
  78. package/out/concepts/FrontendLibrary__.d.ts +52 -48
  79. package/out/concepts/FrontendLibrary__.js +45 -36
  80. package/out/concepts/FrontendLibrary__.js.map +1 -1
  81. package/out/concepts/FrontendType__.d.ts +4 -0
  82. package/out/concepts/FrontendType__.js +7 -0
  83. package/out/concepts/FrontendType__.js.map +1 -1
  84. package/out/concepts/Frontend__.d.ts +2 -0
  85. package/out/concepts/Frontend__.js +21 -2
  86. package/out/concepts/Frontend__.js.map +1 -1
  87. package/out/concepts/HistoryProcessV2__.js +4 -1
  88. package/out/concepts/HistoryProcessV2__.js.map +1 -1
  89. package/out/concepts/I18nInfo__.d.ts +0 -1
  90. package/out/concepts/I18nInfo__.js +0 -7
  91. package/out/concepts/I18nInfo__.js.map +1 -1
  92. package/out/concepts/Identifier__.d.ts +2 -0
  93. package/out/concepts/Identifier__.js +31 -0
  94. package/out/concepts/Identifier__.js.map +1 -1
  95. package/out/concepts/IfStatement__.js +2 -2
  96. package/out/concepts/IfStatement__.js.map +1 -1
  97. package/out/concepts/Interface__.js +1 -4
  98. package/out/concepts/Interface__.js.map +1 -1
  99. package/out/concepts/LogicItem__.d.ts +1 -1
  100. package/out/concepts/LogicItem__.js.map +1 -1
  101. package/out/concepts/Logic__.d.ts +16 -1
  102. package/out/concepts/Logic__.js +133 -15
  103. package/out/concepts/Logic__.js.map +1 -1
  104. package/out/concepts/ManagerV2__.d.ts +34 -0
  105. package/out/concepts/ManagerV2__.js +61 -0
  106. package/out/concepts/ManagerV2__.js.map +1 -0
  107. package/out/concepts/MatchCase__.d.ts +2 -2
  108. package/out/concepts/MatchCase__.js +7 -7
  109. package/out/concepts/MatchCase__.js.map +1 -1
  110. package/out/concepts/MemberExpression__.js +1 -0
  111. package/out/concepts/MemberExpression__.js.map +1 -1
  112. package/out/concepts/Module__.d.ts +88 -0
  113. package/out/concepts/Module__.js +85 -0
  114. package/out/concepts/Module__.js.map +1 -1
  115. package/out/concepts/OperatePermissionV2__.d.ts +1 -1
  116. package/out/concepts/OperatePermissionV2__.js.map +1 -1
  117. package/out/concepts/Param__.d.ts +4 -0
  118. package/out/concepts/Param__.js +13 -21
  119. package/out/concepts/Param__.js.map +1 -1
  120. package/out/concepts/ProcessElementV2__.d.ts +6 -1
  121. package/out/concepts/ProcessElementV2__.js +20 -0
  122. package/out/concepts/ProcessElementV2__.js.map +1 -1
  123. package/out/concepts/ProcessElement__.d.ts +7 -0
  124. package/out/concepts/ProcessElement__.js +47 -0
  125. package/out/concepts/ProcessElement__.js.map +1 -1
  126. package/out/concepts/ProcessV2__.d.ts +1 -34
  127. package/out/concepts/ProcessV2__.js +3 -70
  128. package/out/concepts/ProcessV2__.js.map +1 -1
  129. package/out/concepts/QueryFromExpression__.js +2 -2
  130. package/out/concepts/QueryFromExpression__.js.map +1 -1
  131. package/out/concepts/QueryJoinExpression__.js +2 -2
  132. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  133. package/out/concepts/StaticString__.d.ts +0 -4
  134. package/out/concepts/StaticString__.js +0 -11
  135. package/out/concepts/StaticString__.js.map +1 -1
  136. package/out/concepts/StructureProperty__.d.ts +1 -0
  137. package/out/concepts/StructureProperty__.js +14 -5
  138. package/out/concepts/StructureProperty__.js.map +1 -1
  139. package/out/concepts/Structure__.d.ts +4 -0
  140. package/out/concepts/Structure__.js +6 -9
  141. package/out/concepts/Structure__.js.map +1 -1
  142. package/out/concepts/SubLogic__.d.ts +418 -0
  143. package/out/concepts/SubLogic__.js +992 -0
  144. package/out/concepts/SubLogic__.js.map +1 -0
  145. package/out/concepts/Theme__.d.ts +9 -0
  146. package/out/concepts/Theme__.js +10 -0
  147. package/out/concepts/Theme__.js.map +1 -1
  148. package/out/concepts/Transactional__.d.ts +0 -1
  149. package/out/concepts/Transactional__.js +0 -7
  150. package/out/concepts/Transactional__.js.map +1 -1
  151. package/out/concepts/TypeAnnotation__.js +18 -0
  152. package/out/concepts/TypeAnnotation__.js.map +1 -1
  153. package/out/concepts/TypeParam__.d.ts +1 -0
  154. package/out/concepts/TypeParam__.js.map +1 -1
  155. package/out/concepts/ValidationRule__.d.ts +6 -1
  156. package/out/concepts/ValidationRule__.js +6 -1
  157. package/out/concepts/ValidationRule__.js.map +1 -1
  158. package/out/concepts/ViewElement__.d.ts +8 -2
  159. package/out/concepts/ViewElement__.js +213 -32
  160. package/out/concepts/ViewElement__.js.map +1 -1
  161. package/out/concepts/View__.d.ts +10 -2
  162. package/out/concepts/View__.js +129 -17
  163. package/out/concepts/View__.js.map +1 -1
  164. package/out/concepts/basics/stdlib/nasl.processV2.d.ts +2 -0
  165. package/out/concepts/basics/stdlib/nasl.processV2.js +50 -4
  166. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  167. package/out/concepts/basics/types/index.d.ts +1 -1
  168. package/out/concepts/basics/types/index.js +2 -1
  169. package/out/concepts/basics/types/index.js.map +1 -1
  170. package/out/concepts/index__.d.ts +9 -0
  171. package/out/concepts/index__.js +9 -0
  172. package/out/concepts/index__.js.map +1 -1
  173. package/out/concepts/utils/asserts.d.ts +409 -0
  174. package/out/concepts/utils/asserts.js +564 -14
  175. package/out/concepts/utils/asserts.js.map +1 -1
  176. package/out/concepts/utils/types.d.ts +33 -2
  177. package/out/generator/genBundleFiles.d.ts +13 -9
  178. package/out/generator/genBundleFiles.js +383 -63
  179. package/out/generator/genBundleFiles.js.map +1 -1
  180. package/out/generator/genMetaData.js +2 -0
  181. package/out/generator/genMetaData.js.map +1 -1
  182. package/out/generator/release-body/body.js +1 -0
  183. package/out/generator/release-body/body.js.map +1 -1
  184. package/out/generator/release-body/utils.d.ts +15 -7
  185. package/out/generator/release-body/utils.js +50 -7
  186. package/out/generator/release-body/utils.js.map +1 -1
  187. package/out/natural/genNaturalTS.js +2 -4
  188. package/out/natural/genNaturalTS.js.map +1 -1
  189. package/out/natural/getContext/index.js +0 -2
  190. package/out/natural/getContext/index.js.map +1 -1
  191. package/out/natural/transformTS2UI.js.map +1 -1
  192. package/out/natural/transformTSCode.d.ts +1 -1
  193. package/out/natural/transformTSCode.js.map +1 -1
  194. package/out/server/extendBaseNode.js +9 -0
  195. package/out/server/extendBaseNode.js.map +1 -1
  196. package/out/server/getLogics.js +10 -6
  197. package/out/server/getLogics.js.map +1 -1
  198. package/out/server/getMemberIdentifier.js +6 -0
  199. package/out/server/getMemberIdentifier.js.map +1 -1
  200. package/out/server/getProcessesV2.d.ts +3 -2
  201. package/out/server/getProcessesV2.js +15 -6
  202. package/out/server/getProcessesV2.js.map +1 -1
  203. package/out/server/naslServer.d.ts +5 -1
  204. package/out/server/naslServer.js +120 -30
  205. package/out/server/naslServer.js.map +1 -1
  206. package/out/server/translator.js +4 -0
  207. package/out/server/translator.js.map +1 -1
  208. package/out/service/storage/init.d.ts +2 -1
  209. package/out/service/storage/init.js +28 -71
  210. package/out/service/storage/init.js.map +1 -1
  211. package/out/templator/genCreateBlock.d.ts +6 -2
  212. package/out/templator/genCreateBlock.js +25 -8
  213. package/out/templator/genCreateBlock.js.map +1 -1
  214. package/out/templator/genCurdEditMultipleKeyBlock.d.ts +22 -0
  215. package/out/templator/genCurdEditMultipleKeyBlock.js +60 -1
  216. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  217. package/out/templator/genCurdMultipleKeyBlock.d.ts +13 -3
  218. package/out/templator/genCurdMultipleKeyBlock.js +29 -23
  219. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  220. package/out/templator/genGetBlock.d.ts +1 -1
  221. package/out/templator/genGetBlock.js +3 -2
  222. package/out/templator/genGetBlock.js.map +1 -1
  223. package/out/templator/genListViewBlock.d.ts +1 -1
  224. package/out/templator/genListViewBlock.js +3 -2
  225. package/out/templator/genListViewBlock.js.map +1 -1
  226. package/out/templator/genSelectBlock.d.ts +1 -1
  227. package/out/templator/genSelectBlock.js +3 -2
  228. package/out/templator/genSelectBlock.js.map +1 -1
  229. package/out/templator/genTableBlock.d.ts +9 -4
  230. package/out/templator/genTableBlock.js +31 -17
  231. package/out/templator/genTableBlock.js.map +1 -1
  232. package/out/templator/genUpdateBlock.d.ts +2 -2
  233. package/out/templator/genUpdateBlock.js +11 -11
  234. package/out/templator/genUpdateBlock.js.map +1 -1
  235. package/out/translator/types.d.ts +0 -4
  236. package/out/translator/utils.d.ts +0 -1
  237. package/out/translator/utils.js +1 -6
  238. package/out/translator/utils.js.map +1 -1
  239. package/out/utils/delay/index.d.ts +0 -0
  240. package/out/utils/delay/index.js +1 -0
  241. package/out/utils/delay/index.js.map +1 -0
  242. package/out/utils/env.d.ts +0 -4
  243. package/out/utils/env.js +3 -6
  244. package/out/utils/env.js.map +1 -1
  245. package/out/utils/index.d.ts +3 -2
  246. package/out/utils/index.js +18 -14
  247. package/out/utils/index.js.map +1 -1
  248. package/out/utils/time-slicing/controller.js.map +1 -1
  249. package/out/utils/types.d.ts +0 -17
  250. package/package.json +27 -20
  251. package/sandbox/stdlib/extension.component.ts +29 -0
  252. package/sandbox/stdlib/nasl.process.ts +17 -0
  253. package/sandbox/stdlib/nasl.processV2.ts +10 -5
  254. package/sandbox/stdlib/nasl.util.ts +3 -1
  255. package/src/automate/engine/utils.js +7 -2
  256. package/src/bak/translator.js +42 -1
  257. package/src/breakpoint/shared/utils.ts +2 -1
  258. package/src/common/BaseNode.ts +117 -5
  259. package/src/concepts/Annotatable__.ts +263 -0
  260. package/src/concepts/AnnotationProperty__.ts +102 -0
  261. package/src/concepts/Annotation__.ts +344 -0
  262. package/src/concepts/App__.ts +917 -26
  263. package/src/concepts/ApplyAnnotation__.ts +198 -0
  264. package/src/concepts/Argument__.ts +145 -1
  265. package/src/concepts/AssigneeV2__.ts +387 -1
  266. package/src/concepts/AuthLogicForCallInterface__.ts +1 -1
  267. package/src/concepts/AuthLogic__.ts +1 -1
  268. package/src/concepts/BooleanLiteral__.ts +9 -1
  269. package/src/concepts/BusinessLogic__.ts +1 -1
  270. package/src/concepts/CallFunction__.ts +1 -1
  271. package/src/concepts/CallLogic__.ts +153 -16
  272. package/src/concepts/ConnectorLogic__.ts +1 -1
  273. package/src/concepts/DatabaseTypeAnnotation__.ts +0 -11
  274. package/src/concepts/DepartmentManagerV2__.ts +70 -0
  275. package/src/concepts/DepartmentV2__.ts +75 -0
  276. package/src/concepts/DirectManagerV2__.ts +65 -0
  277. package/src/concepts/End__.ts +10 -1
  278. package/src/concepts/EntityProperty__.ts +0 -5
  279. package/src/concepts/Entity__.ts +5 -9
  280. package/src/concepts/EnumItem__.ts +16 -65
  281. package/src/concepts/EnumSelectSetter__.ts +6 -0
  282. package/src/concepts/Enum__.ts +1 -6
  283. package/src/concepts/ForEachStatement__.ts +1 -1
  284. package/src/concepts/FrontendLibrary__.ts +88 -80
  285. package/src/concepts/FrontendType__.ts +6 -0
  286. package/src/concepts/Frontend__.ts +26 -3
  287. package/src/concepts/HistoryProcessV2__.ts +5 -0
  288. package/src/concepts/I18nInfo__.ts +0 -5
  289. package/src/concepts/Identifier__.ts +32 -0
  290. package/src/concepts/IfStatement__.ts +2 -2
  291. package/src/concepts/Interface__.ts +1 -6
  292. package/src/concepts/LogicItem__.ts +1 -0
  293. package/src/concepts/Logic__.ts +140 -17
  294. package/src/concepts/ManagerV2__.ts +78 -0
  295. package/src/concepts/MatchCase__.ts +9 -8
  296. package/src/concepts/MemberExpression__.ts +1 -0
  297. package/src/concepts/Module__.ts +194 -0
  298. package/src/concepts/OperatePermissionV2__.ts +1 -1
  299. package/src/concepts/Param__.ts +17 -20
  300. package/src/concepts/ProcessElementV2__.ts +23 -0
  301. package/src/concepts/ProcessElement__.ts +18 -0
  302. package/src/concepts/ProcessV2__.ts +4 -70
  303. package/src/concepts/QueryFromExpression__.ts +2 -2
  304. package/src/concepts/QueryJoinExpression__.ts +2 -2
  305. package/src/concepts/StaticString__.ts +0 -13
  306. package/src/concepts/StructureProperty__.ts +16 -7
  307. package/src/concepts/Structure__.ts +10 -11
  308. package/src/concepts/SubLogic__.ts +1516 -0
  309. package/src/concepts/Theme__.ts +9 -0
  310. package/src/concepts/Transactional__.ts +0 -5
  311. package/src/concepts/TriggerLauncher__.ts +1 -1
  312. package/src/concepts/TypeAnnotation__.ts +17 -0
  313. package/src/concepts/TypeParam__.ts +3 -0
  314. package/src/concepts/ValidationRule__.ts +6 -1
  315. package/src/concepts/ViewElement__.ts +224 -34
  316. package/src/concepts/View__.ts +135 -22
  317. package/src/concepts/basics/stdlib/nasl.processV2.ts +56 -3
  318. package/src/concepts/basics/types/index.ts +1 -1
  319. package/src/concepts/index__.ts +9 -0
  320. package/src/concepts/utils/asserts.ts +595 -0
  321. package/src/concepts/utils/types.ts +53 -0
  322. package/src/generator/genBundleFiles.ts +408 -68
  323. package/src/generator/genMetaData.ts +3 -0
  324. package/src/generator/release-body/body.ts +1 -0
  325. package/src/generator/release-body/utils.ts +159 -55
  326. package/src/natural/genNaturalTS.ts +3 -5
  327. package/src/natural/getContext/index.ts +0 -2
  328. package/src/natural/transformTS2UI.ts +5 -2
  329. package/src/natural/transformTSCode.ts +2 -2
  330. package/src/server/extendBaseNode.ts +11 -2
  331. package/src/server/getLogics.ts +9 -7
  332. package/src/server/getMemberIdentifier.ts +7 -0
  333. package/src/server/getProcessesV2.ts +16 -6
  334. package/src/server/naslServer.ts +133 -30
  335. package/src/server/translator.ts +4 -0
  336. package/src/service/storage/init.ts +52 -97
  337. package/src/templator/genCreateBlock.ts +35 -14
  338. package/src/templator/genCurdEditMultipleKeyBlock.ts +65 -1
  339. package/src/templator/genCurdMultipleKeyBlock.ts +42 -23
  340. package/src/templator/genGetBlock.ts +4 -3
  341. package/src/templator/genListViewBlock.ts +3 -3
  342. package/src/templator/genSelectBlock.ts +4 -2
  343. package/src/templator/genTableBlock.ts +32 -17
  344. package/src/templator/genUpdateBlock.ts +21 -18
  345. package/src/translator/types.ts +0 -4
  346. package/src/translator/utils.ts +0 -6
  347. package/src/utils/delay/index.ts +0 -0
  348. package/src/utils/env.ts +4 -5
  349. package/src/utils/index.ts +16 -4
  350. package/src/utils/time-slicing/controller.ts +1 -0
  351. package/src/utils/types.ts +0 -20
  352. package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +2 -1
  353. package/ts-worker/bundle.js +1 -1
  354. package/ts-worker/src/index.js +1 -0
  355. package/out/utils/language-cache/constant.d.ts +0 -18
  356. package/out/utils/language-cache/constant.js +0 -35
  357. package/out/utils/language-cache/constant.js.map +0 -1
  358. package/out/utils/language-cache/index.d.ts +0 -2
  359. package/out/utils/language-cache/index.js +0 -19
  360. package/out/utils/language-cache/index.js.map +0 -1
  361. package/out/utils/language-cache/nasl.d.ts +0 -10
  362. package/out/utils/language-cache/nasl.js +0 -98
  363. package/out/utils/language-cache/nasl.js.map +0 -1
  364. package/out/utils/language-cache/types.d.ts +0 -44
  365. package/out/utils/language-cache/types.js +0 -4
  366. package/out/utils/language-cache/types.js.map +0 -1
  367. package/src/utils/language-cache/constant.ts +0 -37
  368. package/src/utils/language-cache/index.ts +0 -2
  369. package/src/utils/language-cache/nasl.ts +0 -83
  370. package/src/utils/language-cache/types.ts +0 -48
@@ -0,0 +1,1516 @@
1
+ import type BaseNode from '../common/BaseNode';
2
+ import {
3
+ wrapForEachToGenerator as wrapForEach,
4
+ wrapIteratorToGenerator as wrapIterator,
5
+ runGeneratorSync as runSync,
6
+ returnOrigin,
7
+ } from '../utils/time-slicing';
8
+ import { invokeCommand } from '../common';
9
+ import {
10
+ TranslatorState,
11
+ shiftState,
12
+ withSourceMap,
13
+ indent,
14
+ createCompilerState,
15
+ embeddedTSEmitter,
16
+ withSourceMapGenerator,
17
+ withGenerator,
18
+ TranslatorGenerator,
19
+ } from '../translator';
20
+ import type App from './App__';
21
+ import type Namespace from './Namespace__';
22
+ import type CallQueryComponent from './CallQueryComponent__';
23
+ import type ForEachStatement from './ForEachStatement__';
24
+ import type Assignment from './Assignment__';
25
+ import type Identifier from './Identifier__';
26
+ import type BindEvent from './BindEvent__';
27
+ import type BatchAssignment from './BatchAssignment__';
28
+ import type OqlQueryComponent from './OqlQueryComponent__';
29
+ import type Match from './Match__';
30
+ import type MatchCase from './MatchCase__';
31
+ import type TypeAnnotation from './TypeAnnotation__';
32
+ import type CallInterface from './CallInterface__';
33
+ import type CallLogic from './CallLogic__';
34
+ import { CUSTOM_CONNECTOR_EDITABLE_SUFFIX } from './basics/constants';
35
+ import type Interface from './Interface__';
36
+ import type BusinessComponent from './BusinessComponent__';
37
+ import type AnonymousFunction from './AnonymousFunction__';
38
+
39
+ import type Module from './Module__';
40
+ import type Connector from './Connector__';
41
+ import type View from './View__';
42
+ import type Frontend from './Frontend__';
43
+ import type ProcessElement from './ProcessElement__';
44
+ import type Process from './Process__';
45
+ import type CallFunction from './CallFunction__';
46
+ import ProcessElementV2 from './ProcessElementV2__';
47
+ import ProcessV2 from './ProcessV2__';
48
+ import type Logic from './Logic__';
49
+
50
+ //================================================================================
51
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
52
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
53
+ //================================================================================
54
+ import { EventPayload, Params } from '../common/EventEmitter';
55
+ import { concept, excludedInJSON, property, getConceptConstructor } from '../decorators';
56
+
57
+ import * as utils from '../utils';
58
+ import { createUUID } from '../utils/create';
59
+ import * as types from './utils/types';
60
+ import * as asserts from './utils/asserts';
61
+
62
+ import Param from './Param__';
63
+ import Return from './Return__';
64
+ import Variable from './Variable__';
65
+ import LogicItem from './LogicItem__';
66
+
67
+ /**
68
+ * 子逻辑
69
+ */
70
+ @concept('子逻辑')
71
+ export class SubLogic extends LogicItem {
72
+ /** 类名 */
73
+ static readonly ConceptName: string = 'SubLogic';
74
+ /**
75
+ * 是否为抽象类
76
+ * 抽象类不能产生 concept: string
77
+ */
78
+ static isAbstract: boolean = false;
79
+ /** 继承链 */
80
+ static readonly inheritanceChain: string[] = ['LogicItem', 'BaseNode'];
81
+
82
+ /**
83
+ * 产品概念
84
+ */
85
+ @property('concept')
86
+ // @ts-ignore
87
+ readonly concept!: 'SubLogic';
88
+ /**
89
+ * 逻辑名称
90
+ */
91
+ @property()
92
+ name: string = '';
93
+
94
+ /**
95
+ * 输入参数列表
96
+ */
97
+ @property({
98
+ objectRef: 'Param',
99
+ isArray: true,
100
+ defaultValue: [],
101
+ })
102
+ params: Array<Param> = [];
103
+
104
+ /**
105
+ * 输出参数列表
106
+ */
107
+ @property({
108
+ objectRef: 'Return',
109
+ isArray: true,
110
+ defaultValue: [],
111
+ })
112
+ returns: Array<Return> = [];
113
+
114
+ /**
115
+ * 变量列表
116
+ */
117
+ @property({
118
+ objectRef: 'Variable',
119
+ isArray: true,
120
+ defaultValue: [],
121
+ })
122
+ variables: Array<Variable> = [];
123
+
124
+ /**
125
+ * 逻辑项列表
126
+ */
127
+ @property({
128
+ objectRef: 'LogicItem',
129
+ isArray: true,
130
+ defaultValue: [],
131
+ })
132
+ body: Array<LogicItem> = [];
133
+
134
+ /**
135
+ * 逻辑项列表
136
+ */
137
+ @property({
138
+ objectRef: 'LogicItem',
139
+ isArray: true,
140
+ defaultValue: [],
141
+ })
142
+ playground: Array<LogicItem> = [];
143
+
144
+ /**
145
+ * @param source 需要合并的部分参数
146
+ */
147
+ constructor(source?: Partial<SubLogic>) {
148
+ source = Object.assign({}, SubLogic.getDefaultOptions(), source);
149
+ super(source);
150
+ super.subConstructor(source);
151
+ }
152
+
153
+ static from(source: any, parentNode?: any, parentKey?: string): SubLogic {
154
+ return super.from(source, parentNode, parentKey) as SubLogic;
155
+ }
156
+
157
+ /**
158
+ * 设置逻辑名称
159
+ */
160
+ setName(name: string) {
161
+ const object = {
162
+ name,
163
+ };
164
+ this.update({
165
+ ...object,
166
+ field: 'name',
167
+ });
168
+ }
169
+
170
+ getParamUniqueName(name = 'param1') {
171
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
172
+ }
173
+
174
+ /**
175
+ * 插入输入参数
176
+ * @internal
177
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
178
+ */
179
+ _insertParamAt(name: string, index: number): Param;
180
+
181
+ /**
182
+ * 插入输入参数
183
+ * @internal
184
+ * @param paramOptions 输入参数参数
185
+ */
186
+ _insertParamAt(paramOptions: Partial<Param>, index: number): Param;
187
+
188
+ /**
189
+ * 插入输入参数
190
+ * @internal
191
+ * @param param 已有的输入参数实例
192
+ */
193
+ _insertParamAt(param: Param, index: number): Param;
194
+
195
+ _insertParamAt(options: string | Partial<Param> | Param, index: number) {
196
+ const paramOptions: any = {};
197
+ const relationOptions = { parentNode: this, parentKey: 'params' };
198
+ const Param = getConceptConstructor('Param');
199
+ let param: Param;
200
+ if (!options) {
201
+ param = Param.from(
202
+ {
203
+ ...paramOptions,
204
+ name: this.getParamUniqueName(),
205
+ },
206
+ this,
207
+ 'params',
208
+ );
209
+ } else if (typeof options === 'string') {
210
+ param = Param.from(
211
+ {
212
+ ...paramOptions,
213
+ name: options,
214
+ },
215
+ this,
216
+ 'params',
217
+ );
218
+ } else if (asserts.isParam(options)) {
219
+ options.ensureDelete(); // 同一实例不支持多处存在
220
+ param = options;
221
+ Object.assign(param, relationOptions);
222
+ } else {
223
+ param = Param.from(
224
+ {
225
+ ...paramOptions,
226
+ ...options,
227
+ },
228
+ this,
229
+ 'params',
230
+ );
231
+ }
232
+ this.params.splice(index, 0, param);
233
+ return param;
234
+ }
235
+
236
+ /**
237
+ * 插入输入参数
238
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
239
+ */
240
+ insertParamAt(name: string, index: number): Param;
241
+
242
+ /**
243
+ * 插入输入参数
244
+ * @param paramOptions 输入参数参数
245
+ */
246
+ insertParamAt(paramOptions: Partial<Param>, index: number): Param;
247
+
248
+ /**
249
+ * 插入输入参数
250
+ * @param param 已有的输入参数实例
251
+ */
252
+ insertParamAt(param: Param, index: number): Param;
253
+
254
+ insertParamAt(options: string | Partial<Param> | Param, index: number) {
255
+ const node = this._insertParamAt(options as any, index);
256
+ node.create({
257
+ index,
258
+ parentNode: this,
259
+ parentKey: 'params',
260
+ });
261
+ return node;
262
+ }
263
+
264
+ /**
265
+ * 添加输入参数
266
+ * @internal
267
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
268
+ */
269
+ _addParam(name?: string): Param;
270
+
271
+ /**
272
+ * 添加输入参数
273
+ * @internal
274
+ * @param paramOptions 输入参数参数
275
+ */
276
+ _addParam(paramOptions: Partial<Param>): Param;
277
+
278
+ /**
279
+ * 添加输入参数
280
+ * @internal
281
+ * @param param 已有的输入参数实例
282
+ */
283
+ _addParam(param: Param): Param;
284
+
285
+ _addParam(options?: string | Partial<Param> | Param) {
286
+ const index = this.params.length;
287
+ return this._insertParamAt(options as any, index);
288
+ }
289
+
290
+ /**
291
+ * 添加输入参数
292
+ * @internal
293
+ * @param name 输入参数名称,如果不填会自动生成一个唯一名称
294
+ */
295
+ addParam(name?: string): Param;
296
+
297
+ /**
298
+ * 添加输入参数
299
+ * @param paramOptions 输入参数参数
300
+ */
301
+ addParam(paramOptions: Partial<Param>): Param;
302
+
303
+ /**
304
+ * 添加输入参数
305
+ * @param param 已有的输入参数实例
306
+ */
307
+ addParam(param: Param): Param;
308
+
309
+ addParam(options?: string | Partial<Param> | Param) {
310
+ const node = this._addParam(options as any);
311
+ const index = this.params.indexOf(node);
312
+ node.create({
313
+ index,
314
+ parentNode: this,
315
+ parentKey: 'params',
316
+ });
317
+ return node;
318
+ }
319
+
320
+ getReturnUniqueName(name = 'result') {
321
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
322
+ }
323
+
324
+ /**
325
+ * 插入输出参数
326
+ * @internal
327
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
328
+ */
329
+ _insertReturnAt(name: string, index: number): Return;
330
+
331
+ /**
332
+ * 插入输出参数
333
+ * @internal
334
+ * @param retOptions 输出参数参数
335
+ */
336
+ _insertReturnAt(retOptions: Partial<Return>, index: number): Return;
337
+
338
+ /**
339
+ * 插入输出参数
340
+ * @internal
341
+ * @param ret 已有的输出参数实例
342
+ */
343
+ _insertReturnAt(ret: Return, index: number): Return;
344
+
345
+ _insertReturnAt(options: string | Partial<Return> | Return, index: number) {
346
+ const retOptions: any = {};
347
+ const relationOptions = { parentNode: this, parentKey: 'returns' };
348
+ const Return = getConceptConstructor('Return');
349
+ let ret: Return;
350
+ if (!options) {
351
+ ret = Return.from(
352
+ {
353
+ ...retOptions,
354
+ name: this.getReturnUniqueName(),
355
+ },
356
+ this,
357
+ 'returns',
358
+ );
359
+ } else if (typeof options === 'string') {
360
+ ret = Return.from(
361
+ {
362
+ ...retOptions,
363
+ name: options,
364
+ },
365
+ this,
366
+ 'returns',
367
+ );
368
+ } else if (asserts.isReturn(options)) {
369
+ options.ensureDelete(); // 同一实例不支持多处存在
370
+ ret = options;
371
+ Object.assign(ret, relationOptions);
372
+ } else {
373
+ ret = Return.from(
374
+ {
375
+ ...retOptions,
376
+ ...options,
377
+ },
378
+ this,
379
+ 'returns',
380
+ );
381
+ }
382
+ this.returns.splice(index, 0, ret);
383
+ return ret;
384
+ }
385
+
386
+ /**
387
+ * 插入输出参数
388
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
389
+ */
390
+ insertReturnAt(name: string, index: number): Return;
391
+
392
+ /**
393
+ * 插入输出参数
394
+ * @param retOptions 输出参数参数
395
+ */
396
+ insertReturnAt(retOptions: Partial<Return>, index: number): Return;
397
+
398
+ /**
399
+ * 插入输出参数
400
+ * @param ret 已有的输出参数实例
401
+ */
402
+ insertReturnAt(ret: Return, index: number): Return;
403
+
404
+ insertReturnAt(options: string | Partial<Return> | Return, index: number) {
405
+ const node = this._insertReturnAt(options as any, index);
406
+ node.create({
407
+ index,
408
+ parentNode: this,
409
+ parentKey: 'returns',
410
+ });
411
+ return node;
412
+ }
413
+
414
+ /**
415
+ * 添加输出参数
416
+ * @internal
417
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
418
+ */
419
+ _addReturn(name?: string): Return;
420
+
421
+ /**
422
+ * 添加输出参数
423
+ * @internal
424
+ * @param retOptions 输出参数参数
425
+ */
426
+ _addReturn(retOptions: Partial<Return>): Return;
427
+
428
+ /**
429
+ * 添加输出参数
430
+ * @internal
431
+ * @param ret 已有的输出参数实例
432
+ */
433
+ _addReturn(ret: Return): Return;
434
+
435
+ _addReturn(options?: string | Partial<Return> | Return) {
436
+ const index = this.returns.length;
437
+ return this._insertReturnAt(options as any, index);
438
+ }
439
+
440
+ /**
441
+ * 添加输出参数
442
+ * @internal
443
+ * @param name 输出参数名称,如果不填会自动生成一个唯一名称
444
+ */
445
+ addReturn(name?: string): Return;
446
+
447
+ /**
448
+ * 添加输出参数
449
+ * @param retOptions 输出参数参数
450
+ */
451
+ addReturn(retOptions: Partial<Return>): Return;
452
+
453
+ /**
454
+ * 添加输出参数
455
+ * @param ret 已有的输出参数实例
456
+ */
457
+ addReturn(ret: Return): Return;
458
+
459
+ addReturn(options?: string | Partial<Return> | Return) {
460
+ const node = this._addReturn(options as any);
461
+ const index = this.returns.indexOf(node);
462
+ node.create({
463
+ index,
464
+ parentNode: this,
465
+ parentKey: 'returns',
466
+ });
467
+ return node;
468
+ }
469
+
470
+ getVariableUniqueName(name = 'variable1') {
471
+ return utils.unique(name, this.getVarExistingNames(), undefined, false);
472
+ }
473
+
474
+ /**
475
+ * 插入变量
476
+ * @internal
477
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
478
+ */
479
+ _insertVariableAt(name: string, index: number): Variable;
480
+
481
+ /**
482
+ * 插入变量
483
+ * @internal
484
+ * @param variableOptions 变量参数
485
+ */
486
+ _insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
487
+
488
+ /**
489
+ * 插入变量
490
+ * @internal
491
+ * @param variable 已有的变量实例
492
+ */
493
+ _insertVariableAt(variable: Variable, index: number): Variable;
494
+
495
+ _insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
496
+ const variableOptions: any = {};
497
+ const relationOptions = { parentNode: this, parentKey: 'variables' };
498
+ const Variable = getConceptConstructor('Variable');
499
+ let variable: Variable;
500
+ if (!options) {
501
+ variable = Variable.from(
502
+ {
503
+ ...variableOptions,
504
+ name: this.getVariableUniqueName(),
505
+ },
506
+ this,
507
+ 'variables',
508
+ );
509
+ } else if (typeof options === 'string') {
510
+ variable = Variable.from(
511
+ {
512
+ ...variableOptions,
513
+ name: options,
514
+ },
515
+ this,
516
+ 'variables',
517
+ );
518
+ } else if (asserts.isVariable(options)) {
519
+ options.ensureDelete(); // 同一实例不支持多处存在
520
+ variable = options;
521
+ Object.assign(variable, relationOptions);
522
+ } else {
523
+ variable = Variable.from(
524
+ {
525
+ ...variableOptions,
526
+ ...options,
527
+ },
528
+ this,
529
+ 'variables',
530
+ );
531
+ }
532
+ this.variables.splice(index, 0, variable);
533
+ return variable;
534
+ }
535
+
536
+ /**
537
+ * 插入变量
538
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
539
+ */
540
+ insertVariableAt(name: string, index: number): Variable;
541
+
542
+ /**
543
+ * 插入变量
544
+ * @param variableOptions 变量参数
545
+ */
546
+ insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
547
+
548
+ /**
549
+ * 插入变量
550
+ * @param variable 已有的变量实例
551
+ */
552
+ insertVariableAt(variable: Variable, index: number): Variable;
553
+
554
+ insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
555
+ const node = this._insertVariableAt(options as any, index);
556
+ node.create({
557
+ index,
558
+ parentNode: this,
559
+ parentKey: 'variables',
560
+ });
561
+ return node;
562
+ }
563
+
564
+ /**
565
+ * 添加变量
566
+ * @internal
567
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
568
+ */
569
+ _addVariable(name?: string): Variable;
570
+
571
+ /**
572
+ * 添加变量
573
+ * @internal
574
+ * @param variableOptions 变量参数
575
+ */
576
+ _addVariable(variableOptions: Partial<Variable>): Variable;
577
+
578
+ /**
579
+ * 添加变量
580
+ * @internal
581
+ * @param variable 已有的变量实例
582
+ */
583
+ _addVariable(variable: Variable): Variable;
584
+
585
+ _addVariable(options?: string | Partial<Variable> | Variable) {
586
+ const index = this.variables.length;
587
+ return this._insertVariableAt(options as any, index);
588
+ }
589
+
590
+ /**
591
+ * 添加变量
592
+ * @internal
593
+ * @param name 变量名称,如果不填会自动生成一个唯一名称
594
+ */
595
+ addVariable(name?: string): Variable;
596
+
597
+ /**
598
+ * 添加变量
599
+ * @param variableOptions 变量参数
600
+ */
601
+ addVariable(variableOptions: Partial<Variable>): Variable;
602
+
603
+ /**
604
+ * 添加变量
605
+ * @param variable 已有的变量实例
606
+ */
607
+ addVariable(variable: Variable): Variable;
608
+
609
+ addVariable(options?: string | Partial<Variable> | Variable) {
610
+ const node = this._addVariable(options as any);
611
+ const index = this.variables.indexOf(node);
612
+ node.create({
613
+ index,
614
+ parentNode: this,
615
+ parentKey: 'variables',
616
+ });
617
+ return node;
618
+ }
619
+
620
+ /**
621
+ * 插入逻辑项
622
+ * @internal
623
+ * @param logicItemOptions 逻辑项参数
624
+ */
625
+ _insertItemInBodyAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
626
+
627
+ /**
628
+ * 插入逻辑项
629
+ * @internal
630
+ * @param logicItem 已有的逻辑项实例
631
+ */
632
+ _insertItemInBodyAt(logicItem: LogicItem, index: number): LogicItem;
633
+
634
+ _insertItemInBodyAt(options: Partial<LogicItem> | LogicItem, index: number) {
635
+ const logicItemOptions: any = {};
636
+ const relationOptions = { parentNode: this, parentKey: 'body' };
637
+ const LogicItem = getConceptConstructor('LogicItem');
638
+ let logicItem: LogicItem;
639
+ if (asserts.isLogicItem(options)) {
640
+ options.ensureDelete(); // 同一实例不支持多处存在
641
+ logicItem = options;
642
+ Object.assign(logicItem, relationOptions);
643
+ } else {
644
+ logicItem = LogicItem.from(
645
+ {
646
+ ...logicItemOptions,
647
+ ...options,
648
+ },
649
+ this,
650
+ 'body',
651
+ );
652
+ }
653
+ this.body.splice(index, 0, logicItem);
654
+ return logicItem;
655
+ }
656
+
657
+ /**
658
+ * 插入逻辑项
659
+ * @param logicItemOptions 逻辑项参数
660
+ */
661
+ insertItemInBodyAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
662
+
663
+ /**
664
+ * 插入逻辑项
665
+ * @param logicItem 已有的逻辑项实例
666
+ */
667
+ insertItemInBodyAt(logicItem: LogicItem, index: number): LogicItem;
668
+
669
+ insertItemInBodyAt(options: Partial<LogicItem> | LogicItem, index: number) {
670
+ const node = this._insertItemInBodyAt(options as any, index);
671
+ node.create({
672
+ index,
673
+ parentNode: this,
674
+ parentKey: 'body',
675
+ });
676
+ return node;
677
+ }
678
+
679
+ /**
680
+ * 添加逻辑项
681
+ * @internal
682
+ * @param logicItemOptions 逻辑项参数
683
+ */
684
+ _addItemInBody(logicItemOptions: Partial<LogicItem>): LogicItem;
685
+
686
+ /**
687
+ * 添加逻辑项
688
+ * @internal
689
+ * @param logicItem 已有的逻辑项实例
690
+ */
691
+ _addItemInBody(logicItem: LogicItem): LogicItem;
692
+
693
+ _addItemInBody(options?: Partial<LogicItem> | LogicItem) {
694
+ const index = this.body.length;
695
+ return this._insertItemInBodyAt(options as any, index);
696
+ }
697
+
698
+ /**
699
+ * 添加逻辑项
700
+ * @param logicItemOptions 逻辑项参数
701
+ */
702
+ addItemInBody(logicItemOptions: Partial<LogicItem>): LogicItem;
703
+
704
+ /**
705
+ * 添加逻辑项
706
+ * @param logicItem 已有的逻辑项实例
707
+ */
708
+ addItemInBody(logicItem: LogicItem): LogicItem;
709
+
710
+ addItemInBody(options?: Partial<LogicItem> | LogicItem) {
711
+ const node = this._addItemInBody(options as any);
712
+ const index = this.body.indexOf(node);
713
+ node.create({
714
+ index,
715
+ parentNode: this,
716
+ parentKey: 'body',
717
+ });
718
+ return node;
719
+ }
720
+
721
+ /**
722
+ * 插入逻辑项
723
+ * @internal
724
+ * @param logicItemOptions 逻辑项参数
725
+ */
726
+ _insertItemInPlaygroundAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
727
+
728
+ /**
729
+ * 插入逻辑项
730
+ * @internal
731
+ * @param logicItem 已有的逻辑项实例
732
+ */
733
+ _insertItemInPlaygroundAt(logicItem: LogicItem, index: number): LogicItem;
734
+
735
+ _insertItemInPlaygroundAt(options: Partial<LogicItem> | LogicItem, index: number) {
736
+ const logicItemOptions: any = {};
737
+ const relationOptions = { parentNode: this, parentKey: 'playground' };
738
+ const LogicItem = getConceptConstructor('LogicItem');
739
+ let logicItem: LogicItem;
740
+ if (asserts.isLogicItem(options)) {
741
+ options.ensureDelete(); // 同一实例不支持多处存在
742
+ logicItem = options;
743
+ Object.assign(logicItem, relationOptions);
744
+ } else {
745
+ logicItem = LogicItem.from(
746
+ {
747
+ ...logicItemOptions,
748
+ ...options,
749
+ },
750
+ this,
751
+ 'playground',
752
+ );
753
+ }
754
+ this.playground.splice(index, 0, logicItem);
755
+ return logicItem;
756
+ }
757
+
758
+ /**
759
+ * 插入逻辑项
760
+ * @param logicItemOptions 逻辑项参数
761
+ */
762
+ insertItemInPlaygroundAt(logicItemOptions: Partial<LogicItem>, index: number): LogicItem;
763
+
764
+ /**
765
+ * 插入逻辑项
766
+ * @param logicItem 已有的逻辑项实例
767
+ */
768
+ insertItemInPlaygroundAt(logicItem: LogicItem, index: number): LogicItem;
769
+
770
+ insertItemInPlaygroundAt(options: Partial<LogicItem> | LogicItem, index: number) {
771
+ const node = this._insertItemInPlaygroundAt(options as any, index);
772
+ node.create({
773
+ index,
774
+ parentNode: this,
775
+ parentKey: 'playground',
776
+ });
777
+ return node;
778
+ }
779
+
780
+ /**
781
+ * 添加逻辑项
782
+ * @internal
783
+ * @param logicItemOptions 逻辑项参数
784
+ */
785
+ _addItemInPlayground(logicItemOptions: Partial<LogicItem>): LogicItem;
786
+
787
+ /**
788
+ * 添加逻辑项
789
+ * @internal
790
+ * @param logicItem 已有的逻辑项实例
791
+ */
792
+ _addItemInPlayground(logicItem: LogicItem): LogicItem;
793
+
794
+ _addItemInPlayground(options?: Partial<LogicItem> | LogicItem) {
795
+ const index = this.playground.length;
796
+ return this._insertItemInPlaygroundAt(options as any, index);
797
+ }
798
+
799
+ /**
800
+ * 添加逻辑项
801
+ * @param logicItemOptions 逻辑项参数
802
+ */
803
+ addItemInPlayground(logicItemOptions: Partial<LogicItem>): LogicItem;
804
+
805
+ /**
806
+ * 添加逻辑项
807
+ * @param logicItem 已有的逻辑项实例
808
+ */
809
+ addItemInPlayground(logicItem: LogicItem): LogicItem;
810
+
811
+ addItemInPlayground(options?: Partial<LogicItem> | LogicItem) {
812
+ const node = this._addItemInPlayground(options as any);
813
+ const index = this.playground.indexOf(node);
814
+ node.create({
815
+ index,
816
+ parentNode: this,
817
+ parentKey: 'playground',
818
+ });
819
+ return node;
820
+ }
821
+
822
+ /**
823
+ * 删除输入参数
824
+ * @param name 输入参数名称
825
+ */
826
+ removeParam(name: string): void;
827
+
828
+ /**
829
+ * 删除输入参数
830
+ * @param param 已有的输入参数实例
831
+ */
832
+ removeParam(param: Param): void;
833
+
834
+ removeParam(options: string | Param) {
835
+ let param: Param;
836
+ if (typeof options === 'string') {
837
+ param = (this.params as Param[]).find((item) => item.name === options);
838
+ if (!param) {
839
+ throw new Error('找不到输入参数 ' + options);
840
+ }
841
+ } else {
842
+ param = options;
843
+ }
844
+ return param.delete();
845
+ }
846
+
847
+ /**
848
+ * 删除输出参数
849
+ * @param name 输出参数名称
850
+ */
851
+ removeReturn(name: string): void;
852
+
853
+ /**
854
+ * 删除输出参数
855
+ * @param ret 已有的输出参数实例
856
+ */
857
+ removeReturn(ret: Return): void;
858
+
859
+ removeReturn(options: string | Return) {
860
+ let ret: Return;
861
+ if (typeof options === 'string') {
862
+ ret = (this.returns as Return[]).find((item) => item.name === options);
863
+ if (!ret) {
864
+ throw new Error('找不到输出参数 ' + options);
865
+ }
866
+ } else {
867
+ ret = options;
868
+ }
869
+ return ret.delete();
870
+ }
871
+
872
+ /**
873
+ * 删除变量
874
+ * @param name 变量名称
875
+ */
876
+ removeVariable(name: string): void;
877
+
878
+ /**
879
+ * 删除变量
880
+ * @param variable 已有的变量实例
881
+ */
882
+ removeVariable(variable: Variable): void;
883
+
884
+ removeVariable(options: string | Variable) {
885
+ let variable: Variable;
886
+ if (typeof options === 'string') {
887
+ variable = (this.variables as Variable[]).find((item) => item.name === options);
888
+ if (!variable) {
889
+ throw new Error('找不到变量 ' + options);
890
+ }
891
+ } else {
892
+ variable = options;
893
+ }
894
+ return variable.delete();
895
+ }
896
+
897
+ /**
898
+ * 删除逻辑项
899
+ * @param logicItem 已有的逻辑项实例
900
+ */
901
+ removeItemInBody(logicItem: LogicItem): void;
902
+
903
+ removeItemInBody(options: LogicItem) {
904
+ let logicItem: LogicItem = options;
905
+ return logicItem.delete();
906
+ }
907
+
908
+ /**
909
+ * 删除逻辑项
910
+ * @param logicItem 已有的逻辑项实例
911
+ */
912
+ removeItemInPlayground(logicItem: LogicItem): void;
913
+
914
+ removeItemInPlayground(options: LogicItem) {
915
+ let logicItem: LogicItem = options;
916
+ return logicItem.delete();
917
+ }
918
+
919
+ //================================================================================
920
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
921
+ // 自动生成的代码已结束。下面可以手动编写。
922
+ //================================================================================
923
+
924
+ completionChildren: Array<SubLogic> = [];
925
+
926
+ getVarExistingNames(excludedList: Array<Param> = []) {
927
+ const excludedSet = new Set(excludedList);
928
+ return [...this.params].filter((item) => !excludedSet.has(item)).map((item) => item.name);
929
+ }
930
+
931
+ toJSContent(code: string, state?: TranslatorState): string {
932
+ // params
933
+ if (Array.isArray(this.params)) {
934
+ this.params.forEach((param) => {
935
+ code += `${indent((state?.tabSize || 0) + 1)}`;
936
+ code += param.toJS(state);
937
+ code += ';\n';
938
+ });
939
+ }
940
+ // variables
941
+ if (Array.isArray(this.variables)) {
942
+ this.variables.forEach((variable) => {
943
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
944
+ code += variable.toJS(state);
945
+ code += ';\n';
946
+ });
947
+ }
948
+
949
+ // returns
950
+ if (Array.isArray(this.returns)) {
951
+ this.returns.forEach((ret) => {
952
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
953
+ code += ret.toJS(state);
954
+ code += ';\n';
955
+ });
956
+ }
957
+ if (Array.isArray(this.body)) {
958
+ this.body.forEach((item) => {
959
+ code += item.toJS && item.toJS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
960
+ code += '\n';
961
+ });
962
+ }
963
+
964
+ return code;
965
+ }
966
+
967
+ toJS(state?: TranslatorState, type?: string): string {
968
+ let code = '';
969
+ code += `async (`;
970
+
971
+ if (this.params?.length) {
972
+ this.params.forEach((param, index) => {
973
+ code += param.name;
974
+ if (index !== this.params.length - 1) code += ', ';
975
+ });
976
+ }
977
+ code += ') => {\n';
978
+
979
+ code = this.toJSContent(code, state);
980
+ code += `${indent(state?.tabSize || 0)}}\n`;
981
+ return code;
982
+ }
983
+
984
+ public static getDefaultOptions(): Partial<{
985
+ body: Array<any>;
986
+ params: Array<any>;
987
+ returns: Array<any>;
988
+ }> {
989
+ return {
990
+ body: [
991
+ {
992
+ concept: 'Start',
993
+ label: '开始',
994
+ kind: 'Statement',
995
+ type: 'Start',
996
+ },
997
+ {
998
+ concept: 'End',
999
+ label: '结束',
1000
+ kind: 'Statement',
1001
+ type: 'End',
1002
+ },
1003
+ ],
1004
+ };
1005
+ }
1006
+
1007
+ *getRightCode(code: string, assignment: Assignment | BatchAssignment | CallFunction, rightNode: any) {
1008
+ code = code.replaceAll('\n', ' ');
1009
+ // 赋值语句的右侧或者集合内置函数的参数
1010
+ if (
1011
+ (asserts.isAssignment(assignment) && !assignment.right) ||
1012
+ (asserts.isCallFunction(assignment) &&
1013
+ ((assignment.isDerivableList && !assignment.itemOfCollection) ||
1014
+ (assignment.isDerivableMap && !(assignment.keyOfCollection && assignment.itemOfCollection))))
1015
+ ) {
1016
+ return code;
1017
+ }
1018
+
1019
+ // 调用接口,参数替换成 null
1020
+ if (asserts.isCallInterface(rightNode)) {
1021
+ const { _interface } = rightNode.getModuleInterface();
1022
+ return _interface
1023
+ ? `${rightNode.tsCalleeKey}(${(_interface as unknown as Interface).params.map(() => 'null').join(',')})`
1024
+ : null;
1025
+ }
1026
+
1027
+ // 调用服务端逻辑,参数替换成 null
1028
+ if (asserts.isCallLogic(rightNode) && rightNode.calleeNamespace === 'app.logics') {
1029
+ const calleeName = rightNode?.calleeName;
1030
+ const calleeLogic = this.app.logics.find((l) => l.name === calleeName);
1031
+ return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
1032
+ }
1033
+
1034
+ // ForEachStatement 内部变量需要替换处理,如 item、index
1035
+ const forEachStatement = assignment.getAncestor('ForEachStatement') as ForEachStatement;
1036
+ if (forEachStatement) {
1037
+ code = yield* this.handleForEachCode(code, forEachStatement);
1038
+ }
1039
+ // 可迭代的集合
1040
+ const callFunction = assignment.getAncestor('CallFunction') as CallFunction;
1041
+ if (callFunction && callFunction.isLoopCollection) {
1042
+ const anonymousFunction = assignment.getAncestor('AnonymousFunction') as AnonymousFunction;
1043
+ code = yield* this.handleCollectionCode(code, anonymousFunction, callFunction);
1044
+ }
1045
+ // Match 需要针对分支缩小类型范围
1046
+ const matchCase = assignment.getAncestor('MatchCase') as MatchCase;
1047
+ if (matchCase) {
1048
+ code = yield* this.handleMatchCaseCode(code, matchCase);
1049
+ }
1050
+ return code;
1051
+ }
1052
+
1053
+ *handleForEachCode(code: string, forEachStatement: ForEachStatement): Generator<any, string, any> {
1054
+ const { item, index, each } = forEachStatement;
1055
+ if (code.includes(item.name)) {
1056
+ const eachTSCode = each ? yield* each.toEmbeddedTS() : '__IDENTIFIER__';
1057
+ code = this.handleReplaceCode(
1058
+ code,
1059
+ item.name,
1060
+ eachTSCode === '__IDENTIFIER__' ? eachTSCode : `${eachTSCode}.__get(0)`,
1061
+ );
1062
+ }
1063
+ if (code.includes(index.name)) {
1064
+ code = this.handleReplaceCode(code, index.name, 'new nasl.core.Long(0)');
1065
+ }
1066
+
1067
+ const parentForEachStatement = forEachStatement.getAncestor('ForEachStatement') as ForEachStatement;
1068
+ if (parentForEachStatement) {
1069
+ code = yield* this.handleForEachCode(code, parentForEachStatement);
1070
+ }
1071
+ return code;
1072
+ }
1073
+
1074
+ *handleCollectionCode(
1075
+ code: string,
1076
+ anonymousFunction: AnonymousFunction,
1077
+ callFunction: CallFunction,
1078
+ ): Generator<any, string, any> {
1079
+ const { collection } = callFunction;
1080
+ const self = this;
1081
+ yield* wrapForEach(anonymousFunction.params, function* warpForEachGenerator(param, index) {
1082
+ if (code.includes(param?.name)) {
1083
+ const collectionTSCode = collection ? yield* collection.toEmbeddedTS() : '__IDENTIFIER__';
1084
+ code = self.handleReplaceCode(
1085
+ code,
1086
+ param.name,
1087
+ collectionTSCode === '__IDENTIFIER__'
1088
+ ? collectionTSCode
1089
+ : callFunction.isLoopMap && index === 0
1090
+ ? `${collectionTSCode}.__getKey(0)`
1091
+ : `${collectionTSCode}.__get(0)`,
1092
+ );
1093
+ }
1094
+ });
1095
+ const parentForEachStatement = callFunction.getAncestor('ForEachStatement') as ForEachStatement;
1096
+ if (parentForEachStatement) {
1097
+ code = yield* this.handleForEachCode(code, parentForEachStatement);
1098
+ }
1099
+ const parentCallFunction = callFunction.getAncestor('CallFunction') as CallFunction;
1100
+ if (parentCallFunction?.isLoopCollection) {
1101
+ const parentAnonymousFunction = callFunction.getAncestor('AnonymousFunction') as AnonymousFunction;
1102
+ code = yield* this.handleCollectionCode(code, parentAnonymousFunction, parentCallFunction);
1103
+ }
1104
+ return code;
1105
+ }
1106
+
1107
+ handleReplaceCode(code: string, variable: string, replaceCode: string) {
1108
+ return code.replace(/\S+/g, ($1) => {
1109
+ if ($1 === `${variable},`) return `${replaceCode},`;
1110
+ if ($1 === variable) return replaceCode;
1111
+
1112
+ let fnCode = $1;
1113
+ if ($1.startsWith(`${variable}.`)) fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
1114
+ if ($1.startsWith(`${variable},`)) fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
1115
+ if ($1.includes(`(${variable},`)) fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
1116
+ if ($1.includes(`(${variable}.`)) fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
1117
+ if ($1.includes(`(${variable})`)) fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
1118
+ if ($1.includes(`,${variable},`)) fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
1119
+ if ($1.includes(`,${variable}.`)) fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
1120
+ if ($1.includes(`,${variable})`)) fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
1121
+ if ($1.includes(`...[${variable}.`)) fnCode = $1.replaceAll(`...[${variable}.`, `...[${replaceCode}.`);
1122
+ return fnCode;
1123
+ });
1124
+ }
1125
+
1126
+ *handleMatchCaseCode(code: string, matchCase: MatchCase): Generator<any, string, any> {
1127
+ const match = matchCase.getAncestor('Match') as Match;
1128
+ const expressionTsCode = yield* match.expression.toEmbeddedTS();
1129
+ if (code.includes(expressionTsCode)) {
1130
+ let typeCode = '';
1131
+ yield* wrapForEach(matchCase.patterns, function* wrapForEach(pattern, index) {
1132
+ if (asserts.isTypeAnnotation(pattern)) {
1133
+ if (index === 0) {
1134
+ typeCode += yield* pattern.toEmbeddedTS();
1135
+ } else {
1136
+ typeCode += '|';
1137
+ typeCode += yield* pattern.toEmbeddedTS();
1138
+ }
1139
+ }
1140
+ });
1141
+ if (typeCode) {
1142
+ code = this.handleReplaceCode(code, expressionTsCode, `(${expressionTsCode} as ${typeCode})`);
1143
+ }
1144
+ }
1145
+ const parentMatchCase = match.getAncestor('MatchCase') as MatchCase;
1146
+ if (parentMatchCase) {
1147
+ code = yield* this.handleMatchCaseCode(code, parentMatchCase);
1148
+ }
1149
+ return code;
1150
+ }
1151
+
1152
+ @withSourceMapGenerator
1153
+ *toEmbeddedTS(state = createCompilerState(), prefix?: string, hideDefaultValue?: boolean): TranslatorGenerator {
1154
+ const self = this;
1155
+ // 获取所有子节点用于树上填充
1156
+ self.getSubLogics()
1157
+
1158
+ // 如果传了不要前缀那就为空, 要不用传进来的,要是都没有就默认导出
1159
+ let code = '';
1160
+ // 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
1161
+ const IDENTIFIERMAP = new Set<Variable | Return>();
1162
+
1163
+ code += `function ${self.tsName}`;
1164
+
1165
+ code += '(';
1166
+ // 有参数长度
1167
+ if (self.params.length) {
1168
+ yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
1169
+ code += yield* param.toEmbeddedTS(shiftState(state, code));
1170
+ if (index !== self.params.length - 1) code += ', ';
1171
+ });
1172
+ }
1173
+ code += ')';
1174
+ const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
1175
+ const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
1176
+ yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
1177
+ if (
1178
+ el &&
1179
+ // 批量赋值
1180
+ (asserts.isBatchAssignment(el) ||
1181
+ // 赋值
1182
+ (asserts.isAssignment(el) && el.left?.name) ||
1183
+ // 内置函数对集合类型的推导
1184
+ (asserts.isCallFunction(el) && el.derivablecollection?.name))
1185
+ ) {
1186
+ if (asserts.isAssignment(el)) {
1187
+ const advanceVar = self.variables?.find(
1188
+ (variable) => !variable.typeAnnotation && el.left?.name === variable.name,
1189
+ );
1190
+ if (advanceVar && !advanceMap.get(advanceVar)) {
1191
+ advanceMap.set(advanceVar, el);
1192
+ }
1193
+ const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
1194
+ if (advanceRn && !advanceMap.get(advanceRn)) {
1195
+ advanceMap.set(advanceRn, el);
1196
+ }
1197
+ } else if (asserts.isCallFunction(el)) {
1198
+ // 需要被推导的集合
1199
+ const expression = el.derivablecollection;
1200
+ // 宽泛意义上的变量(变量+出参)
1201
+ const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
1202
+ return !variable.typeAnnotation && expression?.name === variable.name;
1203
+ });
1204
+ if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
1205
+ callFunctionAdvanceMap.set(advanceVar, el);
1206
+ }
1207
+ } else if (asserts.isBatchAssignment(el)) {
1208
+ yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
1209
+ const leftCode =
1210
+ leftIndex.length === 1
1211
+ ? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
1212
+ : yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1213
+ returnOrigin('');
1214
+ const advanceVar = self.variables?.find(
1215
+ (variable) => !variable.typeAnnotation && leftCode === variable.name,
1216
+ );
1217
+ if (advanceVar && !advanceMap.get(advanceVar)) {
1218
+ advanceMap.set(advanceVar, el);
1219
+ }
1220
+ const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
1221
+ if (advanceRn && !advanceMap.get(advanceRn)) {
1222
+ advanceMap.set(advanceRn, el);
1223
+ }
1224
+ });
1225
+ }
1226
+ }
1227
+ });
1228
+
1229
+ // 兼容 return 没有类型情况
1230
+ if (self.returns.length && self.returns[0].typeAnnotation) {
1231
+ code += ': ';
1232
+ code += yield* self.returns[0].typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1233
+ returnOrigin('');
1234
+ }
1235
+ code += '{\n';
1236
+
1237
+ for (const variable of self.variables) {
1238
+ const ts = yield* variable.defaultValue?.toEmbeddedTS?.() ?? utils.returnOrigin('');
1239
+ if (['__IDENTIFIER__', '__IDENTIFIER__()'].includes(ts)) {
1240
+ IDENTIFIERMAP.add(variable);
1241
+ }
1242
+ if (!advanceMap.get(variable) && !callFunctionAdvanceMap.get(variable)) {
1243
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1244
+ code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
1245
+ code += ';\n';
1246
+ }
1247
+ }
1248
+
1249
+ for (const ret of self.returns) {
1250
+ const ts = yield* ret.defaultValue?.toEmbeddedTS?.() ?? returnOrigin('');
1251
+ if (['__IDENTIFIER__', '__IDENTIFIER__()'].includes(ts)) {
1252
+ IDENTIFIERMAP.add(ret);
1253
+ }
1254
+ if (!advanceMap.get(ret) && !callFunctionAdvanceMap.get(ret)) {
1255
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1256
+ code += yield* ret.toEmbeddedTS(shiftState(state, code, { inline: true }));
1257
+ code += ';\n';
1258
+ }
1259
+ }
1260
+
1261
+ // 变量提升
1262
+ state.isVariableHost = true;
1263
+
1264
+ yield* wrapIterator(advanceMap.entries(), function* warpForEachGenerator([node, assignment]) {
1265
+ // 有默认值的用默认值来推导类型, 但是如果是__IDENTIFIER__或者__IDENTIFIER__(),就不需要默认值来推导了
1266
+ if (node.defaultValue?.expression && !IDENTIFIERMAP.has(node)) {
1267
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1268
+ code += yield* node.toEmbeddedTS(shiftState(state, code, { inline: true }));
1269
+ return;
1270
+ }
1271
+ code += `${indent((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
1272
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1273
+ code += yield* node.toEmbeddedTS(shiftState(state, code, { inline: true }));
1274
+ if (asserts.isBatchAssignment(assignment)) {
1275
+ yield* wrapForEach(assignment.assignmentLines, function* warpForEachGenerator({ leftIndex, rightIndex }) {
1276
+ const leftCode =
1277
+ leftIndex.length === 1
1278
+ ? yield* assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
1279
+ : yield* assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1280
+ returnOrigin('');
1281
+ if (leftCode === node.name) {
1282
+ const rightNode: any =
1283
+ rightIndex.length === 1
1284
+ ? assignment.rights[rightIndex[0]]?.expression
1285
+ : assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
1286
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
1287
+ if (rightNode?.typeAnnotation && !(asserts.isCallQueryComponent(rightNode) && !rightNode.isAutoInfer())) {
1288
+ if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'anonymousStructure') {
1289
+ code += '= ';
1290
+ code += (yield* rightNode.getInitCode(shiftState(state, code, { inline: true }))) || 'null';
1291
+ } else if (rightNode.concept === 'NewComposite' && rightNode.typeAnnotation?.typeKind === 'generic') {
1292
+ code += '= ';
1293
+ code += (yield* rightNode.getNewCompositeCode(shiftState(state, code, { inline: true }))) || 'null';
1294
+ } else {
1295
+ code += ': ';
1296
+ code += yield* rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1297
+ returnOrigin('null');
1298
+ }
1299
+ } else {
1300
+ code += ' = ';
1301
+ const rightCode = yield* rightNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1302
+ returnOrigin('');
1303
+ code += yield* self.getRightCode(rightCode, assignment, rightNode);
1304
+ }
1305
+ }
1306
+ });
1307
+ } else if (
1308
+ ['NewList', 'NewMap'].includes((assignment as Assignment).right?.concept) &&
1309
+ !((assignment as Assignment).right as any)?.typeAnnotation
1310
+ ) {
1311
+ const rightNode: any = (assignment as Assignment).right;
1312
+ code += ' = ';
1313
+ code += yield* rightNode.getInitCode(shiftState(state, code, { inline: true }));
1314
+ } else if (
1315
+ (assignment as Assignment).right?.concept === 'NewComposite' &&
1316
+ ((assignment as Assignment).right as any)?.typeAnnotation?.typeKind === 'anonymousStructure'
1317
+ ) {
1318
+ const rightNode: any = (assignment as Assignment).right;
1319
+ code += ' = ';
1320
+ code += yield* rightNode.getInitCode(shiftState(state, code, { inline: true }));
1321
+ } else if (
1322
+ (assignment as Assignment).right?.concept === 'NewComposite' &&
1323
+ ((assignment as Assignment).right as any)?.typeAnnotation?.typeKind === 'generic'
1324
+ ) {
1325
+ const rightNode: any = (assignment as Assignment).right;
1326
+ code += ' = ';
1327
+ code += yield* rightNode.getNewCompositeCode(shiftState(state, code, { inline: true }));
1328
+ } else {
1329
+ const rightNode: any = (assignment as Assignment).right;
1330
+ // 当右边有明确类型时,直接使用其类型。旧版本数据查询不能直接使用其 typeAnnotation
1331
+ if (rightNode?.typeAnnotation && !(asserts.isCallQueryComponent(rightNode) && !rightNode.isAutoInfer())) {
1332
+ code += ': ';
1333
+ code += yield* rightNode.typeAnnotation?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1334
+ returnOrigin('null');
1335
+ } else {
1336
+ code += ' = ';
1337
+ let rightCode = '';
1338
+ // 因为右侧枚举要赋值就得new 一下;
1339
+ if (
1340
+ rightNode &&
1341
+ asserts.isIdentifier(rightNode) &&
1342
+ rightNode.namespace &&
1343
+ rightNode.namespace.endsWith('enums')
1344
+ ) {
1345
+ rightCode += 'new ';
1346
+ }
1347
+ rightCode +=
1348
+ rightNode && rightNode.toEmbeddedTS
1349
+ ? yield* rightNode.toEmbeddedTS(shiftState(state, code, { inline: true }))
1350
+ : '__RIGHT__';
1351
+ code += yield* self.getRightCode(rightCode, assignment, rightNode);
1352
+ }
1353
+ }
1354
+ code += ';\n';
1355
+ });
1356
+
1357
+ yield* wrapIterator(callFunctionAdvanceMap.entries(), function* warpForEachGenerator([node, assignment]) {
1358
+ //
1359
+ if (advanceMap.get(node)) {
1360
+ return;
1361
+ }
1362
+ // 有默认值的用默认值来推导类型, 但是如果是__IDENTIFIER__或者__IDENTIFIER__(),就不需要默认值来推导了
1363
+ if (node.defaultValue?.expression && !IDENTIFIERMAP.has(node)) {
1364
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1365
+ code += yield* node.toEmbeddedTS(shiftState(state, code, { inline: true }));
1366
+ return;
1367
+ }
1368
+ code += `${indent((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
1369
+ yield* wrapForEach(
1370
+ [
1371
+ {
1372
+ key: 'key',
1373
+ node: assignment.keyOfCollection,
1374
+ },
1375
+ {
1376
+ key: 'item',
1377
+ node: assignment.itemOfCollection,
1378
+ },
1379
+ ],
1380
+ function* warpForEachGenerator({ key, node: itemNode }) {
1381
+ if (itemNode) {
1382
+ code += `const __${key}_${node?.name} = `;
1383
+ const itemCode = yield* itemNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
1384
+ returnOrigin('');
1385
+ code += yield* self.getRightCode(itemCode, assignment, itemNode);
1386
+ code += ';\n';
1387
+ }
1388
+ },
1389
+ );
1390
+ code += `${indent((state?.tabSize || 0) + 1)}let `;
1391
+ code += yield* node.toEmbeddedTS(shiftState(state, code, { inline: true }));
1392
+ const nodeName = node?.name;
1393
+ const keyNode = (assignment as CallFunction).keyOfCollection;
1394
+ const itemNode = (assignment as CallFunction).itemOfCollection;
1395
+ if ((assignment as CallFunction).isDerivableMap && keyNode && itemNode) {
1396
+ code += `: nasl.collection.Map<typeof __key_${nodeName}, typeof __item_${nodeName}>`;
1397
+ } else if ((assignment as CallFunction).isDerivableList && itemNode) {
1398
+ code += `: nasl.collection.List<typeof __item_${nodeName}>;`;
1399
+ }
1400
+ code += ';\n';
1401
+ });
1402
+
1403
+ // 变量提升结束
1404
+ delete state.isVariableHost;
1405
+
1406
+ // 参数的默认值是__IDENTIFIER__或者__IDENTIFIER__()时不赋默认值,但是需要ts翻译出来进行报错校验
1407
+ if (!hideDefaultValue) {
1408
+ for (const node of IDENTIFIERMAP.values()) {
1409
+ code += yield* node.defaultValue.toEmbeddedTS(shiftState(state, code, { inline: true }));
1410
+ code += '; ';
1411
+ }
1412
+ code += '\n';
1413
+ }
1414
+
1415
+ if (!this.body.length && this.returns.length) {
1416
+ code += `${indent((state?.tabSize || 0) + 1)}return ${this.returns[0].name};\n`;
1417
+ } else {
1418
+ // 如果长度小于2 并且不是虚拟节点就 加 报错,
1419
+ if (self.body.length <= 2 && !asserts.isNamespace(self.parentNode)) {
1420
+ if (self.body.length && self.body[0].concept === 'JavaLogic') {
1421
+ code += '';
1422
+ } else {
1423
+ code += indent((state?.tabSize || 0) + 1);
1424
+ code += 'const __LogicEmpty: any = null;';
1425
+ }
1426
+ }
1427
+ yield* wrapForEach(self.body, function* warpForEachGenerator(item) {
1428
+ code += yield* item.toEmbeddedTS?.(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 })) ??
1429
+ returnOrigin('');
1430
+ code += ';\n';
1431
+ });
1432
+ }
1433
+ // 在body渲染完成之后把其余的节点放到下面
1434
+ yield* wrapForEach(self.playground, function* warpForEachGenerator(item) {
1435
+ code += yield* item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1436
+ code += ';\n';
1437
+ });
1438
+
1439
+ if (!hideDefaultValue) {
1440
+ function* setPlaygroundCode(arr: Variable[] | Param[] | Return[], name: string) {
1441
+ if (arr.length) {
1442
+ code += `${indent((state?.tabSize || 0) + 1)}/* -----以下是 ${name} 的默认值草稿------ */\n`;
1443
+ }
1444
+
1445
+ for (const item1 of arr) {
1446
+ for (const item of item1.defaultValue?.playground ?? []) {
1447
+ code += yield* item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
1448
+ code += ';\n';
1449
+ }
1450
+ }
1451
+ }
1452
+
1453
+ yield* setPlaygroundCode(self.variables, 'variables');
1454
+ yield* setPlaygroundCode(self.returns, 'returns');
1455
+ yield* setPlaygroundCode(self.params, 'params');
1456
+ }
1457
+
1458
+ code += `${indent(state?.tabSize || 0)}}`;
1459
+ if (prefix === 'inObject') {
1460
+ code += `,`;
1461
+ }
1462
+ code += '\n';
1463
+ return code;
1464
+ }
1465
+ async saveStructureOfCallQueryComponents(root?: BaseNode | Logic) {
1466
+ if (!root) root = this;
1467
+ const set = new Set();
1468
+ utils.traverse(
1469
+ ({ node }) => {
1470
+ if (asserts.isCallQueryComponent(node)) {
1471
+ set.add(node);
1472
+ }
1473
+ },
1474
+ { node: root },
1475
+ {
1476
+ mode: 'anyObject',
1477
+ excludedKeySet: new Set(['parentNode', '__assignment__']),
1478
+ },
1479
+ );
1480
+ for (const node of set) {
1481
+ (<CallQueryComponent>node).saveStructure();
1482
+ }
1483
+ }
1484
+
1485
+ subLogics: SubLogic[] = [];
1486
+
1487
+ getSubLogics() {
1488
+ const subLogics = this.findNaslNodeByBFS((node: BaseNode) => {
1489
+ if (asserts.isSubLogic(node)) {
1490
+ return true;
1491
+ }
1492
+ });
1493
+ this.subLogics = subLogics as SubLogic[];
1494
+ }
1495
+
1496
+ genActionListener($event: EventPayload): void {
1497
+ super.genActionListener($event);
1498
+ invokeCommand('logic.update', this);
1499
+ }
1500
+
1501
+ // 用于展示的名称
1502
+ get __name__() {
1503
+ const callLogic = this.getAncestor('CallLogic') as CallLogic;
1504
+ return `${callLogic?.calleeName || ''}_${this.name}`;
1505
+ }
1506
+ //================================================================================
1507
+ // 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
1508
+ // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
1509
+ //================================================================================
1510
+ }
1511
+
1512
+ export default SubLogic;
1513
+ //================================================================================
1514
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1515
+ // 自动生成的代码已结束。下面可以手动编写。
1516
+ //================================================================================