@lcap/nasl 2.20.0-beta.2 → 2.20.0

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 (323) hide show
  1. package/out/automate/engine/index.d.ts +1 -1
  2. package/out/automate/engine/index.js +2 -3
  3. package/out/automate/engine/index.js.map +1 -1
  4. package/out/automate/engine/uniqueName.d.ts +1 -1
  5. package/out/automate/engine/uniqueName.js +2 -2
  6. package/out/automate/engine/uniqueName.js.map +1 -1
  7. package/out/automate/engine/utils.js +4 -1
  8. package/out/automate/engine/utils.js.map +1 -1
  9. package/out/automate/template/myProcess.d.ts +1 -1
  10. package/out/automate/template/myProcess.js +2 -2
  11. package/out/automate/template/myProcess.js.map +1 -1
  12. package/out/bak/translator.js +14 -22
  13. package/out/bak/translator.js.map +1 -1
  14. package/out/common/BaseNode.js +4 -1
  15. package/out/common/BaseNode.js.map +1 -1
  16. package/out/common/Command.d.ts +1 -0
  17. package/out/common/Command.js +5 -1
  18. package/out/common/Command.js.map +1 -1
  19. package/out/concepts/App__.d.ts +4 -0
  20. package/out/concepts/App__.js +30 -6
  21. package/out/concepts/App__.js.map +1 -1
  22. package/out/concepts/Assignee__.js +4 -3
  23. package/out/concepts/Assignee__.js.map +1 -1
  24. package/out/concepts/BatchAssignment__.js +3 -3
  25. package/out/concepts/BatchAssignment__.js.map +1 -1
  26. package/out/concepts/BindAttribute__.d.ts +7 -0
  27. package/out/concepts/BindAttribute__.js +270 -39
  28. package/out/concepts/BindAttribute__.js.map +1 -1
  29. package/out/concepts/BindDirective__.d.ts +7 -0
  30. package/out/concepts/BindDirective__.js +215 -17
  31. package/out/concepts/BindDirective__.js.map +1 -1
  32. package/out/concepts/BindStyle__.d.ts +7 -0
  33. package/out/concepts/BindStyle__.js +194 -4
  34. package/out/concepts/BindStyle__.js.map +1 -1
  35. package/out/concepts/CallFunction__.js +22 -8
  36. package/out/concepts/CallFunction__.js.map +1 -1
  37. package/out/concepts/CallInterface__.js +3 -2
  38. package/out/concepts/CallInterface__.js.map +1 -1
  39. package/out/concepts/CallLogic__.d.ts +3 -0
  40. package/out/concepts/CallLogic__.js +78 -89
  41. package/out/concepts/CallLogic__.js.map +1 -1
  42. package/out/concepts/CallQueryComponent__.js +20 -3
  43. package/out/concepts/CallQueryComponent__.js.map +1 -1
  44. package/out/concepts/ConfigGroup__.d.ts +1 -0
  45. package/out/concepts/ConfigGroup__.js +13 -0
  46. package/out/concepts/ConfigGroup__.js.map +1 -1
  47. package/out/concepts/ConfigProperty__.d.ts +19 -0
  48. package/out/concepts/ConfigProperty__.js +61 -0
  49. package/out/concepts/ConfigProperty__.js.map +1 -1
  50. package/out/concepts/Configuration__.d.ts +1 -0
  51. package/out/concepts/Configuration__.js +13 -0
  52. package/out/concepts/Configuration__.js.map +1 -1
  53. package/out/concepts/DataSource__.js.map +1 -1
  54. package/out/concepts/Destination__.d.ts +1 -0
  55. package/out/concepts/Destination__.js +61 -7
  56. package/out/concepts/Destination__.js.map +1 -1
  57. package/out/concepts/EntityProperty__.js +9 -1
  58. package/out/concepts/EntityProperty__.js.map +1 -1
  59. package/out/concepts/EnumItem__.d.ts +5 -5
  60. package/out/concepts/EnumItem__.js +6 -6
  61. package/out/concepts/Enum__.d.ts +20 -19
  62. package/out/concepts/Enum__.js +28 -1
  63. package/out/concepts/Enum__.js.map +1 -1
  64. package/out/concepts/ExternalDestination__.d.ts +1 -0
  65. package/out/concepts/ExternalDestination__.js +21 -3
  66. package/out/concepts/ExternalDestination__.js.map +1 -1
  67. package/out/concepts/ForEachStatement__.js +2 -0
  68. package/out/concepts/ForEachStatement__.js.map +1 -1
  69. package/out/concepts/Frontend__.d.ts +2 -1
  70. package/out/concepts/Frontend__.js.map +1 -1
  71. package/out/concepts/Identifier__.js +16 -5
  72. package/out/concepts/Identifier__.js.map +1 -1
  73. package/out/concepts/InterfaceParam__.js +9 -1
  74. package/out/concepts/InterfaceParam__.js.map +1 -1
  75. package/out/concepts/JSBlock__.js +5 -1
  76. package/out/concepts/JSBlock__.js.map +1 -1
  77. package/out/concepts/Logic__.d.ts +79 -79
  78. package/out/concepts/Logic__.js +16 -3
  79. package/out/concepts/Logic__.js.map +1 -1
  80. package/out/concepts/Match__.d.ts +0 -3
  81. package/out/concepts/Match__.js +11 -66
  82. package/out/concepts/Match__.js.map +1 -1
  83. package/out/concepts/MemberExpression__.js +9 -0
  84. package/out/concepts/MemberExpression__.js.map +1 -1
  85. package/out/concepts/Module__.d.ts +16 -0
  86. package/out/concepts/Module__.js +43 -0
  87. package/out/concepts/Module__.js.map +1 -1
  88. package/out/concepts/NewComposite__.d.ts +2 -4
  89. package/out/concepts/NewComposite__.js +91 -126
  90. package/out/concepts/NewComposite__.js.map +1 -1
  91. package/out/concepts/NewList__.d.ts +1 -0
  92. package/out/concepts/NewList__.js +22 -2
  93. package/out/concepts/NewList__.js.map +1 -1
  94. package/out/concepts/NewMap__.d.ts +1 -0
  95. package/out/concepts/NewMap__.js +43 -11
  96. package/out/concepts/NewMap__.js.map +1 -1
  97. package/out/concepts/OqlQueryComponent__.js +40 -12
  98. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  99. package/out/concepts/Param__.js +10 -2
  100. package/out/concepts/Param__.js.map +1 -1
  101. package/out/concepts/ProcessElement__.js +2 -1
  102. package/out/concepts/ProcessElement__.js.map +1 -1
  103. package/out/concepts/ProcessOutcome__.js +1 -1
  104. package/out/concepts/ProcessOutcome__.js.map +1 -1
  105. package/out/concepts/ProcessOutcomes__.js +1 -1
  106. package/out/concepts/ProcessOutcomes__.js.map +1 -1
  107. package/out/concepts/Process__.js +1 -0
  108. package/out/concepts/Process__.js.map +1 -1
  109. package/out/concepts/Return__.js +10 -2
  110. package/out/concepts/Return__.js.map +1 -1
  111. package/out/concepts/StringInterpolation__.js +14 -2
  112. package/out/concepts/StringInterpolation__.js.map +1 -1
  113. package/out/concepts/StringLiteral__.js +6 -6
  114. package/out/concepts/StringLiteral__.js.map +1 -1
  115. package/out/concepts/StructureProperty__.js +9 -1
  116. package/out/concepts/StructureProperty__.js.map +1 -1
  117. package/out/concepts/TypeAnnotation__.d.ts +6 -3
  118. package/out/concepts/TypeAnnotation__.js +67 -13
  119. package/out/concepts/TypeAnnotation__.js.map +1 -1
  120. package/out/concepts/ValidationRule__.d.ts +1 -0
  121. package/out/concepts/ValidationRule__.js +53 -0
  122. package/out/concepts/ValidationRule__.js.map +1 -1
  123. package/out/concepts/Variable__.js +9 -1
  124. package/out/concepts/Variable__.js.map +1 -1
  125. package/out/concepts/ViewElement__.js +17 -1
  126. package/out/concepts/ViewElement__.js.map +1 -1
  127. package/out/concepts/View__.d.ts +1 -3
  128. package/out/concepts/View__.js +22 -11
  129. package/out/concepts/View__.js.map +1 -1
  130. package/out/concepts/basics/stdlib/nasl.collection.js +6 -1
  131. package/out/concepts/basics/stdlib/nasl.collection.js.map +1 -1
  132. package/out/concepts/basics/stdlib/nasl.configuration.js +3 -0
  133. package/out/concepts/basics/stdlib/nasl.configuration.js.map +1 -1
  134. package/out/concepts/basics/stdlib/nasl.core.d.ts +2 -0
  135. package/out/concepts/basics/stdlib/nasl.core.js +34 -0
  136. package/out/concepts/basics/stdlib/nasl.core.js.map +1 -1
  137. package/out/concepts/basics/stdlib/nasl.util.js +4 -2
  138. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  139. package/out/concepts/basics/types/index.d.ts +1 -0
  140. package/out/concepts/basics/types/index.js +3 -1
  141. package/out/concepts/basics/types/index.js.map +1 -1
  142. package/out/concepts/index__.d.ts +0 -1
  143. package/out/concepts/index__.js +0 -1
  144. package/out/concepts/index__.js.map +1 -1
  145. package/out/enums/KEYWORDS.js +8 -0
  146. package/out/enums/KEYWORDS.js.map +1 -1
  147. package/out/generator/genBundleFiles.js +24 -5
  148. package/out/generator/genBundleFiles.js.map +1 -1
  149. package/out/generator/genReleaseBody.d.ts +2 -3
  150. package/out/generator/genReleaseBody.js +97 -23
  151. package/out/generator/genReleaseBody.js.map +1 -1
  152. package/out/generator/permission.d.ts +2 -10
  153. package/out/generator/permission.js +27 -14
  154. package/out/generator/permission.js.map +1 -1
  155. package/out/server/entity2LogicNamespace.js +2 -20
  156. package/out/server/entity2LogicNamespace.js.map +1 -1
  157. package/out/server/extendBaseNode.js +16 -5
  158. package/out/server/extendBaseNode.js.map +1 -1
  159. package/out/server/formatTsUtils.d.ts +2 -1
  160. package/out/server/formatTsUtils.js +40 -10
  161. package/out/server/formatTsUtils.js.map +1 -1
  162. package/out/server/getLogics.d.ts +2 -2
  163. package/out/server/getLogics.js +3 -3
  164. package/out/server/getLogics.js.map +1 -1
  165. package/out/server/getMemberIdentifier.d.ts +1 -0
  166. package/out/server/getMemberIdentifier.js +27 -1
  167. package/out/server/getMemberIdentifier.js.map +1 -1
  168. package/out/server/index.js +1 -0
  169. package/out/server/index.js.map +1 -1
  170. package/out/server/naslServer.d.ts +7 -1
  171. package/out/server/naslServer.js +519 -46
  172. package/out/server/naslServer.js.map +1 -1
  173. package/out/server/translator.js +109 -33
  174. package/out/server/translator.js.map +1 -1
  175. package/out/service/storage/init.js +21 -1
  176. package/out/service/storage/init.js.map +1 -1
  177. package/out/templator/genCreateBlock.js +1 -3
  178. package/out/templator/genCreateBlock.js.map +1 -1
  179. package/out/templator/genCurdEditMultipleKeyBlock.js +1 -3
  180. package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
  181. package/out/templator/genCurdMultipleKeyBlock.js +2 -4
  182. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  183. package/out/templator/genGetBlock.js +1 -1
  184. package/out/templator/genGetBlock.js.map +1 -1
  185. package/out/templator/genGridViewBlock.js +2 -2
  186. package/out/templator/genGridViewBlock.js.map +1 -1
  187. package/out/templator/genListViewBlock.js +7 -1
  188. package/out/templator/genListViewBlock.js.map +1 -1
  189. package/out/templator/genSelectBlock.js +1 -1
  190. package/out/templator/genSelectBlock.js.map +1 -1
  191. package/out/templator/genTableBlock.js +2 -2
  192. package/out/templator/genTableBlock.js.map +1 -1
  193. package/out/templator/genUpdateBlock.js +2 -3
  194. package/out/templator/genUpdateBlock.js.map +1 -1
  195. package/out/utils/traverse.js +8 -2
  196. package/out/utils/traverse.js.map +1 -1
  197. package/package.json +2 -2
  198. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  199. package/sandbox/stdlib/dist/nasl.util.js +0 -0
  200. package/sandbox/stdlib/nasl.collection.ts +1 -0
  201. package/sandbox/stdlib/nasl.core.ts +34 -0
  202. package/sandbox/stdlib/nasl.oql.ts +71 -15
  203. package/sandbox/stdlib/nasl.util.ts +9 -3
  204. package/src/automate/engine/dist/index.dev.js +517 -0
  205. package/src/automate/engine/index.js +2 -3
  206. package/src/automate/engine/uniqueName.js +2 -2
  207. package/src/automate/engine/utils.js +4 -2
  208. package/src/automate/template/myProcess.js +2 -2
  209. package/src/bak/translator.js +16 -25
  210. package/src/common/BaseNode.ts +3 -1
  211. package/src/common/Command.ts +4 -0
  212. package/src/common/dist/BaseNode.js +1101 -0
  213. package/src/concepts/App__.ts +36 -7
  214. package/src/concepts/Assignee__.ts +4 -3
  215. package/src/concepts/BatchAssignment__.ts +3 -3
  216. package/src/concepts/BindAttribute__.ts +299 -38
  217. package/src/concepts/BindDirective__.ts +204 -31
  218. package/src/concepts/BindStyle__.ts +187 -24
  219. package/src/concepts/CallFunction__.ts +55 -10
  220. package/src/concepts/CallInterface__.ts +3 -2
  221. package/src/concepts/CallLogic__.ts +110 -90
  222. package/src/concepts/CallQueryComponent__.ts +18 -3
  223. package/src/concepts/ConfigGroup__.ts +17 -4
  224. package/src/concepts/ConfigProperty__.ts +70 -4
  225. package/src/concepts/Configuration__.ts +14 -5
  226. package/src/concepts/DataSource__.ts +4 -1
  227. package/src/concepts/Destination__.ts +61 -7
  228. package/src/concepts/EntityProperty__.ts +7 -1
  229. package/src/concepts/EnumItem__.ts +6 -6
  230. package/src/concepts/Enum__.ts +22 -19
  231. package/src/concepts/ExternalDestination__.ts +28 -8
  232. package/src/concepts/ForEachStatement__.ts +2 -0
  233. package/src/concepts/Frontend__.ts +2 -1
  234. package/src/concepts/Identifier__.ts +16 -5
  235. package/src/concepts/InterfaceParam__.ts +7 -1
  236. package/src/concepts/JSBlock__.ts +3 -2
  237. package/src/concepts/Logic__.ts +95 -83
  238. package/src/concepts/Match__.ts +31 -67
  239. package/src/concepts/MemberExpression__.ts +6 -0
  240. package/src/concepts/Module__.ts +57 -0
  241. package/src/concepts/NewComposite__.ts +95 -140
  242. package/src/concepts/NewList__.ts +23 -2
  243. package/src/concepts/NewMap__.ts +48 -24
  244. package/src/concepts/OqlQueryComponent__.ts +40 -20
  245. package/src/concepts/Param__.ts +178 -176
  246. package/src/concepts/ProcessElement__.ts +2 -1
  247. package/src/concepts/ProcessOutcome__.ts +1 -1
  248. package/src/concepts/ProcessOutcomes__.ts +1 -1
  249. package/src/concepts/Process__.ts +1 -0
  250. package/src/concepts/Return__.ts +8 -2
  251. package/src/concepts/StringInterpolation__.ts +19 -7
  252. package/src/concepts/StringLiteral__.ts +7 -6
  253. package/src/concepts/StructureProperty__.ts +7 -1
  254. package/src/concepts/TypeAnnotation__.ts +101 -14
  255. package/src/concepts/ValidationRule__.ts +58 -9
  256. package/src/concepts/Variable__.ts +11 -1
  257. package/src/concepts/ViewElement__.ts +39 -2
  258. package/src/concepts/View__.ts +26 -14
  259. package/src/concepts/basics/stdlib/dist/nasl.util.js +1602 -0
  260. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
  261. package/src/concepts/basics/stdlib/nasl.collection.ts +6 -1
  262. package/src/concepts/basics/stdlib/nasl.configuration.ts +3 -0
  263. package/src/concepts/basics/stdlib/nasl.core.ts +33 -2
  264. package/src/concepts/basics/stdlib/nasl.util.ts +4 -2
  265. package/src/concepts/basics/types/index.ts +1 -0
  266. package/src/concepts/dist/BindAttribute__.js +795 -0
  267. package/src/concepts/dist/BindEvent__.js +732 -0
  268. package/src/concepts/dist/CallFunction__.js +527 -0
  269. package/src/concepts/dist/CallLogic__.js +932 -0
  270. package/src/concepts/dist/Destination__.js +708 -0
  271. package/src/concepts/dist/ExternalDestination__.js +298 -0
  272. package/src/concepts/dist/Identifier__.js +311 -0
  273. package/src/concepts/dist/StringInterpolation__.js +231 -0
  274. package/src/concepts/dist/TypeAnnotation__.js +834 -0
  275. package/src/concepts/dist/ViewElement__.js +1692 -0
  276. package/src/concepts/dist/View__.js +1601 -0
  277. package/src/concepts/index__.ts +0 -1
  278. package/src/enums/KEYWORDS.ts +8 -0
  279. package/src/generator/dist/genBundleFiles.js +261 -0
  280. package/src/generator/dist/genMetaData.js +245 -0
  281. package/src/generator/dist/permission.js +405 -0
  282. package/src/generator/genBundleFiles.ts +24 -5
  283. package/src/generator/genReleaseBody.ts +75 -30
  284. package/src/generator/permission.ts +31 -15
  285. package/src/server/entity2LogicNamespace.ts +2 -20
  286. package/src/server/extendBaseNode.ts +15 -5
  287. package/src/server/formatTsUtils.ts +41 -10
  288. package/src/server/getLogics.ts +4 -4
  289. package/src/server/getMemberIdentifier.ts +27 -1
  290. package/src/server/index.ts +2 -0
  291. package/src/server/naslServer.ts +520 -48
  292. package/src/server/translator.ts +96 -34
  293. package/src/service/storage/dist/init.js +579 -0
  294. package/src/service/storage/init.ts +22 -2
  295. package/src/templator/dist/genEditTableBlock.js +204 -0
  296. package/src/templator/dist/genGridViewBlock.js +265 -0
  297. package/src/templator/dist/genListViewBlock.js +84 -0
  298. package/src/templator/dist/genTableBlock.js +209 -0
  299. package/src/templator/dist/utils.js +527 -0
  300. package/src/templator/genCreateBlock.ts +1 -3
  301. package/src/templator/genCurdEditMultipleKeyBlock.ts +1 -3
  302. package/src/templator/genCurdMultipleKeyBlock.ts +2 -4
  303. package/src/templator/genGetBlock.ts +1 -1
  304. package/src/templator/genGridViewBlock.ts +3 -4
  305. package/src/templator/genListViewBlock.ts +9 -3
  306. package/src/templator/genSelectBlock.ts +1 -1
  307. package/src/templator/genTableBlock.ts +3 -3
  308. package/src/templator/genUpdateBlock.ts +2 -3
  309. package/src/utils/traverse.ts +10 -2
  310. package/ts-worker/lib/tsserver.js +10 -2
  311. package/ts-worker/package.json +1 -0
  312. package/ts-worker/webpack.config.js +11 -2
  313. package/out/concepts/ConstructArgument__.d.ts +0 -40
  314. package/out/concepts/ConstructArgument__.js +0 -108
  315. package/out/concepts/ConstructArgument__.js.map +0 -1
  316. package/out/concepts/Construct__.d.ts +0 -189
  317. package/out/concepts/Construct__.js +0 -340
  318. package/out/concepts/Construct__.js.map +0 -1
  319. package/out/templator/sql-parser/index.d.ts +0 -1
  320. package/out/templator/sql-parser/index.js +0 -228
  321. package/out/templator/sql-parser/index.js.map +0 -1
  322. package/out/templator/sql-parser/parser.js +0 -26664
  323. package/out/templator/sql-parser/parser.js.map +0 -1
@@ -0,0 +1,1692 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
27
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
28
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
29
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
30
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
31
+ };
32
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
33
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
34
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
35
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
36
+ r[k] = a[j];
37
+ return r;
38
+ };
39
+ exports.__esModule = true;
40
+ exports.ViewElement = void 0;
41
+ var translator_1 = require("../translator");
42
+ var babelParser = require("@babel/parser");
43
+ var json5 = require("json5");
44
+ var compiler = require("vue-template-compiler");
45
+ var LogicItem__1 = require("./LogicItem__");
46
+ var __1 = require("..");
47
+ var MemberExpression__1 = require("./MemberExpression__");
48
+ var Identifier__1 = require("./Identifier__");
49
+ /**
50
+ * 自闭合标签
51
+ */
52
+ var selfClosingTag = [
53
+ 'base',
54
+ 'meta',
55
+ 'area',
56
+ 'embed',
57
+ 'link',
58
+ 'img',
59
+ 'input',
60
+ 'param',
61
+ 'hr',
62
+ 'br',
63
+ 'source',
64
+ 'track',
65
+ 'wbr',
66
+ 'col',
67
+ ];
68
+ function genArgumentMemberExpression(arr) {
69
+ var expressionNode;
70
+ var propertyName = arr.pop();
71
+ if (arr.length >= 1) {
72
+ expressionNode = {
73
+ concept: 'MemberExpression',
74
+ name: '',
75
+ kind: 'Expression',
76
+ object: genArgumentMemberExpression(arr),
77
+ property: {
78
+ concept: 'Identifier',
79
+ kind: 'Expression',
80
+ name: propertyName
81
+ }
82
+ };
83
+ }
84
+ else {
85
+ return {
86
+ concept: 'Identifier',
87
+ kind: 'Expression',
88
+ name: propertyName
89
+ };
90
+ }
91
+ return expressionNode;
92
+ }
93
+ function transAstNodeToNaslNode(astNode, namespace) {
94
+ var _a, _b, _c, _d, _e;
95
+ var node = null;
96
+ if (astNode.type === 'CallExpression' && astNode.callee.object.name === '$utils') {
97
+ var calleeName = astNode.callee.property.name || astNode.callee.property.value;
98
+ node = {
99
+ concept: 'CallFunction',
100
+ name: '',
101
+ label: '调用内置函数',
102
+ kind: 'Expression',
103
+ calleeNamespace: 'nasl.util',
104
+ calleeName: calleeName,
105
+ arguments: astNode.arguments.map(function (argument) { return ({
106
+ concept: 'Argument',
107
+ name: '',
108
+ kind: 'Statement',
109
+ keyword: '',
110
+ expression: transAstNodeToNaslNode(Object.assign({}, argument))
111
+ }); }).filter(function (item) { return item.expression; }),
112
+ typeArguments: astNode.arguments.map(function (argument) { return (transAstNodeToNaslTypeNode(Object.assign({}, argument))); }).filter(function (item) { return item; })
113
+ };
114
+ }
115
+ else if (astNode.type === 'MemberExpression') {
116
+ if (((_a = astNode.object) === null || _a === void 0 ? void 0 : _a.name) === '$global') {
117
+ if (((_b = astNode.property) === null || _b === void 0 ? void 0 : _b.name) === 'userInfo') {
118
+ // 目前只有权限相关的
119
+ node = transAstNodeToNaslNode(astNode.property, 'nasl.auth');
120
+ }
121
+ else if (((_c = astNode.property) === null || _c === void 0 ? void 0 : _c.name) === 'frontendVariables') {
122
+ node = 'app.frontendVariables';
123
+ }
124
+ }
125
+ else if (((_d = astNode.object) === null || _d === void 0 ? void 0 : _d.name) === 'frontendVariables') {
126
+ node = transAstNodeToNaslNode(astNode.property, 'app.frontendVariables');
127
+ }
128
+ else {
129
+ var object = transAstNodeToNaslNode(astNode.object);
130
+ // object如果返回字符串,则将它当成namespace处理
131
+ if (Object.prototype.toString.call(object) === '[object String]') {
132
+ node = transAstNodeToNaslNode(astNode.property, object);
133
+ }
134
+ else {
135
+ var property_1 = transAstNodeToNaslNode(astNode.property);
136
+ node = {
137
+ concept: 'MemberExpression',
138
+ name: '',
139
+ kind: 'Expression',
140
+ object: object,
141
+ property: property_1
142
+ };
143
+ }
144
+ }
145
+ }
146
+ else if (astNode.type === 'Identifier') {
147
+ node = {
148
+ concept: 'Identifier',
149
+ namespace: namespace || '',
150
+ name: astNode.name,
151
+ kind: 'Expression'
152
+ };
153
+ }
154
+ else if (astNode.type === 'ArrayExpression' || astNode.type === 'ObjectExpression') {
155
+ node = {
156
+ concept: 'Unparsed',
157
+ label: '原子项',
158
+ code: astNode.value
159
+ };
160
+ }
161
+ else if (astNode.type === 'StringLiteral') {
162
+ // 单独特殊处理枚举因为他不是MemberExpression,而是Identifier_
163
+ if ((_e = astNode === null || astNode === void 0 ? void 0 : astNode.value) === null || _e === void 0 ? void 0 : _e.startsWith('__enumTypeAnnotation_')) {
164
+ return null;
165
+ }
166
+ else {
167
+ node = {
168
+ concept: 'StringLiteral',
169
+ kind: 'Expression',
170
+ name: '',
171
+ value: astNode.value
172
+ };
173
+ }
174
+ }
175
+ else if (astNode.type === 'UnaryExpression') {
176
+ node = {
177
+ concept: 'UnaryExpression',
178
+ kind: 'Expression',
179
+ name: '',
180
+ operator: astNode.operator,
181
+ argument: transAstNodeToNaslNode(astNode.argument)
182
+ };
183
+ }
184
+ else {
185
+ node = astNode;
186
+ node.concept = astNode.type;
187
+ }
188
+ return node;
189
+ }
190
+ function transAstNodeToNaslTypeNode(astNode, namespace) {
191
+ var _a, _b;
192
+ var node = null;
193
+ // 单独特殊处理枚举因为他不是MemberExpression,而是Identifier_
194
+ if ((_a = astNode === null || astNode === void 0 ? void 0 : astNode.value) === null || _a === void 0 ? void 0 : _a.startsWith('__enumTypeAnnotation_')) {
195
+ var valueArr = (_b = astNode.value.replace('__enumTypeAnnotation_', '')) === null || _b === void 0 ? void 0 : _b.split('.');
196
+ var name = valueArr.pop();
197
+ var namespace_1 = valueArr.join('.');
198
+ node = {
199
+ concept: 'TypeAnnotation',
200
+ typeNamespace: namespace_1 || '',
201
+ typeName: name || '',
202
+ typeKind: 'reference'
203
+ };
204
+ }
205
+ return node;
206
+ }
207
+ var decorators_1 = require("../decorators");
208
+ var utils = require("../utils");
209
+ var BaseNode_1 = require("../common/BaseNode");
210
+ var classMap_1 = require("../common/classMap");
211
+ var BindAttribute__1 = require("./BindAttribute__");
212
+ var BindEvent__1 = require("./BindEvent__");
213
+ var BindDirective__1 = require("./BindDirective__");
214
+ var BindStyle__1 = require("./BindStyle__");
215
+ /**
216
+ * 页面元素
217
+ */
218
+ var ViewElement = /** @class */ (function (_super) {
219
+ __extends(ViewElement, _super);
220
+ /**
221
+ * @param source 需要合并的部分参数
222
+ */
223
+ function ViewElement(source) {
224
+ var _this = this;
225
+ source = Object.assign({}, ViewElement_1.getDefaultOptions(), source);
226
+ _this = _super.call(this, source) || this;
227
+ /**
228
+ * 产品概念
229
+ */
230
+ _this.concept = 'ViewElement';
231
+ /**
232
+ * 类型
233
+ */
234
+ _this.type = undefined;
235
+ /**
236
+ * 元素标签
237
+ */
238
+ _this.tag = undefined;
239
+ /**
240
+ * 页面元素名称
241
+ */
242
+ _this.name = undefined;
243
+ /**
244
+ * 静态 class 名
245
+ */
246
+ _this.staticClass = undefined;
247
+ /**
248
+ * 静态 style
249
+ */
250
+ _this.staticStyle = undefined;
251
+ /**
252
+ * 权限资源描述
253
+ */
254
+ _this.authDescription = undefined;
255
+ /**
256
+ * 插槽目标
257
+ */
258
+ _this.slotTarget = undefined;
259
+ /**
260
+ * 插槽 scope 表达式
261
+ */
262
+ _this.slotScope = undefined;
263
+ /**
264
+ * 元素绑定属性列表
265
+ */
266
+ _this.bindAttrs = [];
267
+ /**
268
+ * 元素绑定事件列表
269
+ */
270
+ _this.bindEvents = [];
271
+ /**
272
+ * 元素指令列表
273
+ */
274
+ _this.bindDirectives = [];
275
+ /**
276
+ * 绑定的角色
277
+ */
278
+ _this.bindRoles = [];
279
+ /**
280
+ * 元素绑定样式列表
281
+ */
282
+ _this.bindStyles = [];
283
+ /**
284
+ * 子元素列表
285
+ */
286
+ _this.children = [];
287
+ _this.computedStyle = {};
288
+ _super.prototype.subConstructor.call(_this, source);
289
+ return _this;
290
+ }
291
+ ViewElement_1 = ViewElement;
292
+ Object.defineProperty(ViewElement.prototype, "view", {
293
+ /**
294
+ * 祖先 View
295
+ */
296
+ get: function () {
297
+ return this.getAncestor('View');
298
+ },
299
+ enumerable: false,
300
+ configurable: true
301
+ });
302
+ Object.defineProperty(ViewElement.prototype, "module", {
303
+ /**
304
+ * 祖先 Module
305
+ */
306
+ get: function () {
307
+ return this.getAncestor('Module');
308
+ },
309
+ enumerable: false,
310
+ configurable: true
311
+ });
312
+ Object.defineProperty(ViewElement.prototype, "app", {
313
+ /**
314
+ * 祖先 App
315
+ */
316
+ get: function () {
317
+ return this.getAncestor('App');
318
+ },
319
+ enumerable: false,
320
+ configurable: true
321
+ });
322
+ /**
323
+ * 从父级删除该节点
324
+ * @internal
325
+ */
326
+ ViewElement.prototype._delete = function () {
327
+ var _a, _b;
328
+ var params = null;
329
+ if (this.parentNode) {
330
+ params = (_b = (_a = this.parentNode) === null || _a === void 0 ? void 0 : _a.__removeViewElement) === null || _b === void 0 ? void 0 : _b.call(_a, this);
331
+ }
332
+ return params;
333
+ };
334
+ /**
335
+ * 设置页面元素名称
336
+ */
337
+ ViewElement.prototype.setName = function (name) {
338
+ var object = {
339
+ name: name
340
+ };
341
+ this.update(__assign(__assign({}, object), { field: 'name' }));
342
+ };
343
+ /**
344
+ * 设置静态 style
345
+ */
346
+ ViewElement.prototype.setStaticStyle = function (staticStyle) {
347
+ var object = {
348
+ staticStyle: staticStyle
349
+ };
350
+ this.update(__assign({}, object));
351
+ };
352
+ /**
353
+ * 设置权限资源描述
354
+ */
355
+ ViewElement.prototype.setAuthDescription = function (authDescription) {
356
+ var object = {
357
+ authDescription: authDescription
358
+ };
359
+ this.update(__assign({}, object));
360
+ };
361
+ ViewElement.prototype.getBindAttributeExistingNames = function (excludedList) {
362
+ if (excludedList === void 0) { excludedList = []; }
363
+ var excludedSet = new Set(excludedList);
364
+ return (this.bindAttrs || []).filter(function (item) { return !excludedSet.has(item); }).map(function (item) { return item.name; });
365
+ };
366
+ ViewElement.prototype.getBindAttributeUniqueName = function (name) {
367
+ if (name === void 0) { name = 'bindAttribute1'; }
368
+ return utils.unique(name, this.getBindAttributeExistingNames(), undefined, false);
369
+ };
370
+ ViewElement.prototype._insertBindAttributeAt = function (options, index) {
371
+ var bindAttributeOptions = {};
372
+ var relationOptions = { parentNode: this, parentKey: 'bindAttrs' };
373
+ var bindAttribute;
374
+ if (!options) {
375
+ bindAttribute = BindAttribute__1["default"].from(__assign(__assign({}, bindAttributeOptions), { name: this.getBindAttributeUniqueName() }), this, 'bindAttrs');
376
+ }
377
+ else if (typeof options === 'string') {
378
+ bindAttribute = BindAttribute__1["default"].from(__assign(__assign({}, bindAttributeOptions), { name: options }), this, 'bindAttrs');
379
+ }
380
+ else if (options instanceof BindAttribute__1["default"]) {
381
+ options.ensureDelete(); // 同一实例不支持多处存在
382
+ bindAttribute = options;
383
+ Object.assign(bindAttribute, relationOptions);
384
+ }
385
+ else {
386
+ bindAttribute = BindAttribute__1["default"].from(__assign(__assign({}, bindAttributeOptions), options), this, 'bindAttrs');
387
+ }
388
+ this.bindAttrs.splice(index, 0, bindAttribute);
389
+ return bindAttribute;
390
+ };
391
+ ViewElement.prototype.insertBindAttributeAt = function (options, index) {
392
+ var node = this._insertBindAttributeAt(options, index);
393
+ node.create({
394
+ index: index,
395
+ parentNode: this,
396
+ parentKey: 'bindAttrs'
397
+ });
398
+ return node;
399
+ };
400
+ ViewElement.prototype._addBindAttribute = function (options) {
401
+ var index = this.bindAttrs.length;
402
+ return this._insertBindAttributeAt(options, index);
403
+ };
404
+ ViewElement.prototype.addBindAttribute = function (options) {
405
+ var node = this._addBindAttribute(options);
406
+ var index = this.bindAttrs.indexOf(node);
407
+ node.create({
408
+ index: index,
409
+ parentNode: this,
410
+ parentKey: 'bindAttrs'
411
+ });
412
+ return node;
413
+ };
414
+ ViewElement.prototype.getBindEventExistingNames = function (excludedList) {
415
+ if (excludedList === void 0) { excludedList = []; }
416
+ var excludedSet = new Set(excludedList);
417
+ return (this.bindEvents || []).filter(function (item) { return !excludedSet.has(item); }).map(function (item) { return item.name; });
418
+ };
419
+ ViewElement.prototype.getBindEventUniqueName = function (name) {
420
+ if (name === void 0) { name = 'bindEvent1'; }
421
+ return utils.unique(name, this.getBindEventExistingNames(), undefined, false);
422
+ };
423
+ ViewElement.prototype._insertBindEventAt = function (options, index) {
424
+ var bindEventOptions = {};
425
+ var relationOptions = { parentNode: this, parentKey: 'bindEvents' };
426
+ var bindEvent;
427
+ if (!options) {
428
+ bindEvent = BindEvent__1["default"].from(__assign(__assign({}, bindEventOptions), { name: this.getBindEventUniqueName() }), this, 'bindEvents');
429
+ }
430
+ else if (typeof options === 'string') {
431
+ bindEvent = BindEvent__1["default"].from(__assign(__assign({}, bindEventOptions), { name: options }), this, 'bindEvents');
432
+ }
433
+ else if (options instanceof BindEvent__1["default"]) {
434
+ options.ensureDelete(); // 同一实例不支持多处存在
435
+ bindEvent = options;
436
+ Object.assign(bindEvent, relationOptions);
437
+ }
438
+ else {
439
+ bindEvent = BindEvent__1["default"].from(__assign(__assign({}, bindEventOptions), options), this, 'bindEvents');
440
+ }
441
+ this.bindEvents.splice(index, 0, bindEvent);
442
+ return bindEvent;
443
+ };
444
+ ViewElement.prototype.insertBindEventAt = function (options, index) {
445
+ var node = this._insertBindEventAt(options, index);
446
+ node.create({
447
+ index: index,
448
+ parentNode: this,
449
+ parentKey: 'bindEvents'
450
+ });
451
+ return node;
452
+ };
453
+ ViewElement.prototype._addBindEvent = function (options) {
454
+ var index = this.bindEvents.length;
455
+ return this._insertBindEventAt(options, index);
456
+ };
457
+ ViewElement.prototype.addBindEvent = function (options) {
458
+ var node = this._addBindEvent(options);
459
+ var index = this.bindEvents.indexOf(node);
460
+ node.create({
461
+ index: index,
462
+ parentNode: this,
463
+ parentKey: 'bindEvents'
464
+ });
465
+ return node;
466
+ };
467
+ ViewElement.prototype.getBindDirectiveExistingNames = function (excludedList) {
468
+ if (excludedList === void 0) { excludedList = []; }
469
+ var excludedSet = new Set(excludedList);
470
+ return (this.bindDirectives || []).filter(function (item) { return !excludedSet.has(item); }).map(function (item) { return item.name; });
471
+ };
472
+ ViewElement.prototype.getBindDirectiveUniqueName = function (name) {
473
+ if (name === void 0) { name = 'bindDirective1'; }
474
+ return utils.unique(name, this.getBindDirectiveExistingNames(), undefined, false);
475
+ };
476
+ ViewElement.prototype._insertBindDirectiveAt = function (options, index) {
477
+ var bindDirectiveOptions = {};
478
+ var relationOptions = { parentNode: this, parentKey: 'bindDirectives' };
479
+ var bindDirective;
480
+ if (!options) {
481
+ bindDirective = BindDirective__1["default"].from(__assign(__assign({}, bindDirectiveOptions), { name: this.getBindDirectiveUniqueName() }), this, 'bindDirectives');
482
+ }
483
+ else if (typeof options === 'string') {
484
+ bindDirective = BindDirective__1["default"].from(__assign(__assign({}, bindDirectiveOptions), { name: options }), this, 'bindDirectives');
485
+ }
486
+ else if (options instanceof BindDirective__1["default"]) {
487
+ options.ensureDelete(); // 同一实例不支持多处存在
488
+ bindDirective = options;
489
+ Object.assign(bindDirective, relationOptions);
490
+ }
491
+ else {
492
+ bindDirective = BindDirective__1["default"].from(__assign(__assign({}, bindDirectiveOptions), options), this, 'bindDirectives');
493
+ }
494
+ this.bindDirectives.splice(index, 0, bindDirective);
495
+ return bindDirective;
496
+ };
497
+ ViewElement.prototype.insertBindDirectiveAt = function (options, index) {
498
+ var node = this._insertBindDirectiveAt(options, index);
499
+ node.create({
500
+ index: index,
501
+ parentNode: this,
502
+ parentKey: 'bindDirectives'
503
+ });
504
+ return node;
505
+ };
506
+ ViewElement.prototype._addBindDirective = function (options) {
507
+ var index = this.bindDirectives.length;
508
+ return this._insertBindDirectiveAt(options, index);
509
+ };
510
+ ViewElement.prototype.addBindDirective = function (options) {
511
+ var node = this._addBindDirective(options);
512
+ var index = this.bindDirectives.indexOf(node);
513
+ node.create({
514
+ index: index,
515
+ parentNode: this,
516
+ parentKey: 'bindDirectives'
517
+ });
518
+ return node;
519
+ };
520
+ ViewElement.prototype.getBindStyleExistingNames = function (excludedList) {
521
+ if (excludedList === void 0) { excludedList = []; }
522
+ var excludedSet = new Set(excludedList);
523
+ return (this.bindStyles || []).filter(function (item) { return !excludedSet.has(item); }).map(function (item) { return item.name; });
524
+ };
525
+ ViewElement.prototype.getBindStyleUniqueName = function (name) {
526
+ if (name === void 0) { name = 'bindStyle1'; }
527
+ return utils.unique(name, this.getBindStyleExistingNames(), undefined, false);
528
+ };
529
+ ViewElement.prototype._insertBindStyleAt = function (options, index) {
530
+ var bindStyleOptions = {};
531
+ var relationOptions = { parentNode: this, parentKey: 'bindStyles' };
532
+ var bindStyle;
533
+ if (!options) {
534
+ bindStyle = BindStyle__1["default"].from(__assign(__assign({}, bindStyleOptions), { name: this.getBindStyleUniqueName() }), this, 'bindStyles');
535
+ }
536
+ else if (typeof options === 'string') {
537
+ bindStyle = BindStyle__1["default"].from(__assign(__assign({}, bindStyleOptions), { name: options }), this, 'bindStyles');
538
+ }
539
+ else if (options instanceof BindStyle__1["default"]) {
540
+ options.ensureDelete(); // 同一实例不支持多处存在
541
+ bindStyle = options;
542
+ Object.assign(bindStyle, relationOptions);
543
+ }
544
+ else {
545
+ bindStyle = BindStyle__1["default"].from(__assign(__assign({}, bindStyleOptions), options), this, 'bindStyles');
546
+ }
547
+ this.bindStyles.splice(index, 0, bindStyle);
548
+ return bindStyle;
549
+ };
550
+ ViewElement.prototype.insertBindStyleAt = function (options, index) {
551
+ var node = this._insertBindStyleAt(options, index);
552
+ node.create({
553
+ index: index,
554
+ parentNode: this,
555
+ parentKey: 'bindStyles'
556
+ });
557
+ return node;
558
+ };
559
+ ViewElement.prototype._addBindStyle = function (options) {
560
+ var index = this.bindStyles.length;
561
+ return this._insertBindStyleAt(options, index);
562
+ };
563
+ ViewElement.prototype.addBindStyle = function (options) {
564
+ var node = this._addBindStyle(options);
565
+ var index = this.bindStyles.indexOf(node);
566
+ node.create({
567
+ index: index,
568
+ parentNode: this,
569
+ parentKey: 'bindStyles'
570
+ });
571
+ return node;
572
+ };
573
+ ViewElement.prototype._insertViewElementAt = function (options, index) {
574
+ var viewElementOptions = {};
575
+ var relationOptions = { parentNode: this, parentKey: 'children' };
576
+ var viewElement;
577
+ if (!options) {
578
+ viewElement = ViewElement_1.from(__assign(__assign({}, viewElementOptions), { name: this.getViewElementUniqueName() }), this, 'children');
579
+ }
580
+ else if (typeof options === 'string') {
581
+ viewElement = ViewElement_1.from(__assign(__assign({}, viewElementOptions), { name: options }), this, 'children');
582
+ }
583
+ else if (options instanceof ViewElement_1) {
584
+ options.ensureDelete(); // 同一实例不支持多处存在
585
+ viewElement = options;
586
+ Object.assign(viewElement, relationOptions);
587
+ }
588
+ else {
589
+ viewElement = ViewElement_1.from(__assign(__assign({}, viewElementOptions), options), this, 'children');
590
+ }
591
+ this.children.splice(index, 0, viewElement);
592
+ return viewElement;
593
+ };
594
+ ViewElement.prototype.insertViewElementAt = function (options, index) {
595
+ var node = this._insertViewElementAt(options, index);
596
+ node.create({
597
+ index: index,
598
+ parentNode: this,
599
+ parentKey: 'children'
600
+ });
601
+ return node;
602
+ };
603
+ ViewElement.prototype._addViewElement = function (options) {
604
+ var index = this.children.length;
605
+ return this._insertViewElementAt(options, index);
606
+ };
607
+ ViewElement.prototype.addViewElement = function (options) {
608
+ var node = this._addViewElement(options);
609
+ var index = this.children.indexOf(node);
610
+ node.create({
611
+ index: index,
612
+ parentNode: this,
613
+ parentKey: 'children'
614
+ });
615
+ return node;
616
+ };
617
+ ViewElement.prototype.removeBindAttribute = function (options) {
618
+ var bindAttribute;
619
+ if (typeof options === 'string') {
620
+ bindAttribute = this.bindAttrs.find(function (item) { return item.name === options; });
621
+ if (!bindAttribute) {
622
+ throw new Error('找不到元素绑定属性 ' + options);
623
+ }
624
+ }
625
+ else {
626
+ bindAttribute = options;
627
+ }
628
+ return bindAttribute["delete"]();
629
+ };
630
+ ViewElement.prototype.__removeBindAttribute = function (bindAttribute) {
631
+ var parentKey = bindAttribute.parentKey;
632
+ var params = {
633
+ parentNode: this,
634
+ parentKey: parentKey,
635
+ index: -1,
636
+ object: null,
637
+ oldObject: bindAttribute
638
+ };
639
+ if (parentKey) {
640
+ params.parentKey = parentKey;
641
+ if (Array.isArray(this[parentKey])) {
642
+ var index = this[parentKey].indexOf(bindAttribute);
643
+ ~index && this[parentKey].splice(index, 1);
644
+ params.index = index;
645
+ }
646
+ else if (this[parentKey] === bindAttribute) {
647
+ params.index = 0;
648
+ this[parentKey] = undefined;
649
+ }
650
+ }
651
+ return params;
652
+ };
653
+ ViewElement.prototype.removeBindEvent = function (options) {
654
+ var bindEvent;
655
+ if (typeof options === 'string') {
656
+ bindEvent = this.bindEvents.find(function (item) { return item.name === options; });
657
+ if (!bindEvent) {
658
+ throw new Error('找不到元素绑定事件 ' + options);
659
+ }
660
+ }
661
+ else {
662
+ bindEvent = options;
663
+ }
664
+ return bindEvent["delete"]();
665
+ };
666
+ ViewElement.prototype.__removeBindEvent = function (bindEvent) {
667
+ var parentKey = bindEvent.parentKey;
668
+ var params = {
669
+ parentNode: this,
670
+ parentKey: parentKey,
671
+ index: -1,
672
+ object: null,
673
+ oldObject: bindEvent
674
+ };
675
+ if (parentKey) {
676
+ params.parentKey = parentKey;
677
+ if (Array.isArray(this[parentKey])) {
678
+ var index = this[parentKey].indexOf(bindEvent);
679
+ ~index && this[parentKey].splice(index, 1);
680
+ params.index = index;
681
+ }
682
+ else if (this[parentKey] === bindEvent) {
683
+ params.index = 0;
684
+ this[parentKey] = undefined;
685
+ }
686
+ }
687
+ return params;
688
+ };
689
+ ViewElement.prototype.removeBindDirective = function (options) {
690
+ var bindDirective;
691
+ if (typeof options === 'string') {
692
+ bindDirective = this.bindDirectives.find(function (item) { return item.name === options; });
693
+ if (!bindDirective) {
694
+ throw new Error('找不到元素指令 ' + options);
695
+ }
696
+ }
697
+ else {
698
+ bindDirective = options;
699
+ }
700
+ return bindDirective["delete"]();
701
+ };
702
+ ViewElement.prototype.__removeBindDirective = function (bindDirective) {
703
+ var parentKey = bindDirective.parentKey;
704
+ var params = {
705
+ parentNode: this,
706
+ parentKey: parentKey,
707
+ index: -1,
708
+ object: null,
709
+ oldObject: bindDirective
710
+ };
711
+ if (parentKey) {
712
+ params.parentKey = parentKey;
713
+ if (Array.isArray(this[parentKey])) {
714
+ var index = this[parentKey].indexOf(bindDirective);
715
+ ~index && this[parentKey].splice(index, 1);
716
+ params.index = index;
717
+ }
718
+ else if (this[parentKey] === bindDirective) {
719
+ params.index = 0;
720
+ this[parentKey] = undefined;
721
+ }
722
+ }
723
+ return params;
724
+ };
725
+ ViewElement.prototype.removeBindStyle = function (options) {
726
+ var bindStyle;
727
+ if (typeof options === 'string') {
728
+ bindStyle = this.bindStyles.find(function (item) { return item.name === options; });
729
+ if (!bindStyle) {
730
+ throw new Error('找不到元素绑定样式 ' + options);
731
+ }
732
+ }
733
+ else {
734
+ bindStyle = options;
735
+ }
736
+ return bindStyle["delete"]();
737
+ };
738
+ ViewElement.prototype.__removeBindStyle = function (bindStyle) {
739
+ var parentKey = bindStyle.parentKey;
740
+ var params = {
741
+ parentNode: this,
742
+ parentKey: parentKey,
743
+ index: -1,
744
+ object: null,
745
+ oldObject: bindStyle
746
+ };
747
+ if (parentKey) {
748
+ params.parentKey = parentKey;
749
+ if (Array.isArray(this[parentKey])) {
750
+ var index = this[parentKey].indexOf(bindStyle);
751
+ ~index && this[parentKey].splice(index, 1);
752
+ params.index = index;
753
+ }
754
+ else if (this[parentKey] === bindStyle) {
755
+ params.index = 0;
756
+ this[parentKey] = undefined;
757
+ }
758
+ }
759
+ return params;
760
+ };
761
+ ViewElement.prototype.removeViewElement = function (options) {
762
+ var viewElement;
763
+ if (typeof options === 'string') {
764
+ viewElement = this.children.find(function (item) { return item.name === options; });
765
+ if (!viewElement) {
766
+ throw new Error('找不到页面元素 ' + options);
767
+ }
768
+ }
769
+ else {
770
+ viewElement = options;
771
+ }
772
+ return viewElement["delete"]();
773
+ };
774
+ ViewElement.prototype.__removeViewElement = function (viewElement) {
775
+ var parentKey = viewElement.parentKey;
776
+ var params = {
777
+ parentNode: this,
778
+ parentKey: parentKey,
779
+ index: -1,
780
+ object: null,
781
+ oldObject: viewElement
782
+ };
783
+ if (parentKey) {
784
+ params.parentKey = parentKey;
785
+ if (Array.isArray(this[parentKey])) {
786
+ var index = this[parentKey].indexOf(viewElement);
787
+ ~index && this[parentKey].splice(index, 1);
788
+ params.index = index;
789
+ }
790
+ else if (this[parentKey] === viewElement) {
791
+ params.index = 0;
792
+ this[parentKey] = undefined;
793
+ }
794
+ }
795
+ return params;
796
+ };
797
+ Object.defineProperty(ViewElement.prototype, "parentAuth", {
798
+ //================================================================================
799
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
800
+ // 自动生成的代码已结束。下面可以手动编写。
801
+ //================================================================================
802
+ /* 主页面有没有权限 */
803
+ get: function () {
804
+ var _a;
805
+ var _nameSpace = this.view.getNamespace();
806
+ var mainViewName = _nameSpace.split('.')[2];
807
+ return this.view.parentNode.concept === 'App' ? this.view.auth : (_a = this.app.views.find(function (item) { return item.name === mainViewName; })) === null || _a === void 0 ? void 0 : _a.auth;
808
+ },
809
+ enumerable: false,
810
+ configurable: true
811
+ });
812
+ Object.defineProperty(ViewElement.prototype, "authPath", {
813
+ /**
814
+ * 权限领域的资源路径
815
+ */
816
+ get: function () {
817
+ return this.view.path + "/" + this.name;
818
+ },
819
+ enumerable: false,
820
+ configurable: true
821
+ });
822
+ ViewElement.prototype.getViewElementUniqueName = function (name) {
823
+ var _a;
824
+ if (name === void 0) { name = 'viewElement1'; }
825
+ return (_a = this.view) === null || _a === void 0 ? void 0 : _a.getViewElementUniqueName(name);
826
+ };
827
+ ViewElement.from = function (source, parentNode, parentKey) {
828
+ var node = _super.from.call(this, source, parentNode, parentKey);
829
+ if (!node.name) {
830
+ var tagName = node.tag.replace(ViewElement_1.TAG_NAME_PREFIX_REG, '').replace(/-/g, '_');
831
+ node.name = node.getViewElementUniqueName(tagName + "1");
832
+ }
833
+ return node;
834
+ };
835
+ /**
836
+ * 设置组件权限
837
+ */
838
+ ViewElement.prototype.setBindRoles = function (bindRoles) {
839
+ var object = {
840
+ bindRoles: bindRoles
841
+ };
842
+ this.update(__assign({}, object));
843
+ };
844
+ ViewElement.prototype.getBindAttribute = function (name) {
845
+ return this.bindAttrs.find(function (bindAttr) { return bindAttr.name === name; });
846
+ };
847
+ ViewElement.prototype.toHump = function (name) {
848
+ return name.replace(/\-(\w)/g, function (all, letter) { return letter.toUpperCase(); });
849
+ };
850
+ ViewElement.prototype.toFirstUpper = function (name) {
851
+ return name.replace(/^\S/, function (s) { return s.toUpperCase(); });
852
+ };
853
+ ViewElement.prototype.haveScope = function () {
854
+ return Boolean(this.slotScope);
855
+ };
856
+ ViewElement.prototype.toEmbeddedTSDefinition = function (state) {
857
+ var code = '';
858
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
859
+ // 登录组件不翻译
860
+ if (this.toHump(this.tag) === 'lcapLogin' || this.staticClass === 'login-form') {
861
+ code += this.name + ": nasl.ui.div<any>;\n";
862
+ }
863
+ else {
864
+ code += this.name + ": nasl.ui." + this.toHump(this.tag) + "<any>;\n";
865
+ }
866
+ if (Array.isArray(this.children)) {
867
+ this.children.forEach(function (element) {
868
+ code += element.toEmbeddedTSDefinition(translator_1.shiftState(state, code));
869
+ });
870
+ }
871
+ return code;
872
+ };
873
+ ViewElement.prototype.getTypeArgmentsStr = function (state) {
874
+ // 登录组件不翻译
875
+ if (this.toHump(this.tag) === 'lcapLogin' || this.staticClass === 'login-form')
876
+ return '<any>';
877
+ var code = '';
878
+ // formItem的单独处理
879
+ if (this.tag === 'u-form-item') {
880
+ if (Array.isArray(this.children) && this.children.length) {
881
+ var tag = this.children[0].tag;
882
+ if (tag === 'u-input') {
883
+ code += '<nasl.core.String>';
884
+ }
885
+ else if (tag === 'u-input-number') {
886
+ code += '<nasl.core.Integer>';
887
+ }
888
+ else {
889
+ code += '<any>';
890
+ }
891
+ }
892
+ return code;
893
+ }
894
+ var bindAttrs = this.bindAttrs;
895
+ if (bindAttrs && bindAttrs.length) {
896
+ var attr = bindAttrs.find(function (item) { return item.name === 'data-source'; });
897
+ if (attr && attr.expression) {
898
+ code += "<" + this.__tsDataSourceTypeName + ">";
899
+ }
900
+ }
901
+ return code;
902
+ };
903
+ ViewElement.prototype.getDatasourceTypeCodeStr = function (state, eleArr) {
904
+ var code = '';
905
+ (eleArr || []).forEach(function (element, index) {
906
+ var bindAttrs = element.bindAttrs;
907
+ if (bindAttrs && bindAttrs.length) {
908
+ var attr = bindAttrs.find(function (item) { return item.name === 'data-source'; });
909
+ if (attr && attr.expression) {
910
+ var datasourceName = "datasourceName" + index;
911
+ element.__tsDataSourceTypeName = datasourceName;
912
+ if (attr.expression instanceof MemberExpression__1["default"] || attr.expression instanceof Identifier__1["default"]) {
913
+ var value = attr.expression.toEmbeddedTS(translator_1.shiftState(state, code));
914
+ code += "type " + datasourceName + " = ";
915
+ code += "nasl.ui.GetItemTypeFromDataSource<typeof " + value + ">;\n";
916
+ }
917
+ else {
918
+ code += "const __funcName" + index + " = () => { return";
919
+ code += attr.expression.toEmbeddedTS(translator_1.shiftState(state, code));
920
+ code += '};\n';
921
+ code += "type " + datasourceName + " = ";
922
+ code += "nasl.ui.GetItemTypeFromDataSource<ReturnType<typeof __funcName" + index + ">>;\n";
923
+ }
924
+ }
925
+ }
926
+ });
927
+ code += '\n';
928
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
929
+ return code;
930
+ };
931
+ ViewElement.prototype.toEmbeddedTS = function (state, parentLevel) {
932
+ var _this = this;
933
+ // 过滤模板的登录中的一些翻译,这里只过滤h5表格中的两个列
934
+ if (this.parentNode.tag && this.toHump(this.parentNode.tag) === 'lcapLogin' || this.staticClass === 'login-cell')
935
+ return '';
936
+ // pc事件翻译
937
+ if (this.toHump(this.tag) === 'lcapLogin') {
938
+ var code_1 = "new nasl.ui.div({name: __elements." + this.name + ",\n";
939
+ // 事件
940
+ if (Array.isArray(this.bindEvents)) {
941
+ this.bindEvents.forEach(function (event) {
942
+ code_1 += event.toEmbeddedTS(translator_1.shiftState(state, code_1, {
943
+ tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2
944
+ }));
945
+ code_1 += '\n';
946
+ });
947
+ }
948
+ code_1 += "}),\n";
949
+ return code_1;
950
+ }
951
+ var levelIndex = parentLevel || 0;
952
+ if (this.tag === 'template' && this.haveScope()) {
953
+ var slotTarget = !this.slotTarget ? 'slotDefault' : 'slot' + this.toFirstUpper(this.toHump(this.slotTarget));
954
+ var code_2 = '';
955
+ code_2 += slotTarget + ": (current" + (levelIndex === 0 ? '' : levelIndex) + ")=> {\n";
956
+ code_2 += this.getDatasourceTypeCodeStr(state, this.children);
957
+ levelIndex++;
958
+ code_2 += 'return [';
959
+ this.children.forEach(function (element) {
960
+ code_2 += element.toEmbeddedTS(translator_1.shiftState(state, code_2, {
961
+ tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0)
962
+ }), levelIndex);
963
+ });
964
+ code_2 += ']';
965
+ code_2 += '\n';
966
+ code_2 += '},\n';
967
+ return code_2;
968
+ }
969
+ else if (this.tag === 'template') {
970
+ var slotTarget = !this.slotTarget ? 'slotDefault' : 'slot' + this.toFirstUpper(this.toHump(this.slotTarget));
971
+ var code_3 = '';
972
+ code_3 += slotTarget + ": ()=> {\n";
973
+ code_3 += this.getDatasourceTypeCodeStr(state, this.children);
974
+ code_3 += 'return [';
975
+ this.children.forEach(function (element) {
976
+ code_3 += element.toEmbeddedTS(translator_1.shiftState(state, code_3, {
977
+ tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0)
978
+ }));
979
+ });
980
+ code_3 += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
981
+ code_3 += ']';
982
+ code_3 += '\n';
983
+ code_3 += '},\n';
984
+ return code_3;
985
+ }
986
+ function chineseTsName(name) {
987
+ var tsName = name;
988
+ // 匹配所有特殊字符都转为_
989
+ tsName = tsName.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '_');
990
+ if (/^\d/.test(tsName)) {
991
+ tsName = '$' + tsName;
992
+ }
993
+ return tsName;
994
+ }
995
+ // 后面那个name是为了查找引用的时候用的
996
+ var code = "new nasl.ui." + this.toHump(this.tag) + this.getTypeArgmentsStr(state) + "({name: __elements." + this.name + ",\n";
997
+ // 是否开启权限
998
+ var hasAuth = false;
999
+ if (Array.isArray(this.bindDirectives)) {
1000
+ hasAuth = !!this.bindDirectives.filter(function (directive) { return directive.name === 'auth'; }).length;
1001
+ }
1002
+ // 角色
1003
+ if (Array.isArray(this.bindRoles) && this.bindRoles.length) {
1004
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
1005
+ code += 'roles = [\n';
1006
+ this.bindRoles.forEach(function (role) {
1007
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 3);
1008
+ code += _this.app.getNamespace() + ".roles." + chineseTsName(role) + "." + chineseTsName(role) + ",";
1009
+ code += '\n';
1010
+ });
1011
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
1012
+ code += '],\n';
1013
+ }
1014
+ // 事件
1015
+ if (Array.isArray(this.bindEvents)) {
1016
+ this.bindEvents.forEach(function (event) {
1017
+ code += event.toEmbeddedTS(translator_1.shiftState(state, code, {
1018
+ tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2
1019
+ }));
1020
+ code += '\n';
1021
+ });
1022
+ }
1023
+ // 子元素
1024
+ if (Array.isArray(this.children)) {
1025
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
1026
+ if (Array.isArray(this.bindAttrs)) {
1027
+ code += "bindAttr: () => [\n";
1028
+ this.bindAttrs.forEach(function (attr) { return code += attr.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: 1 })) + ',\n'; });
1029
+ this.bindDirectives.forEach(function (directive) { return code += directive.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: 1 })) + ',\n'; });
1030
+ this.bindStyles.forEach(function (bindStyle) { return code += bindStyle.toEmbeddedTS(translator_1.shiftState(state, code, { tabSize: 1 })) + ',\n'; });
1031
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2) + '],\n';
1032
+ }
1033
+ // 如果子集中有插槽的就
1034
+ if (this.children.find(function (item) { return item.tag === 'template' && item.slotTarget; })) {
1035
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
1036
+ var defaultArr_1 = [];
1037
+ // 先把插槽翻译了
1038
+ this.children.forEach(function (element) {
1039
+ if (element.tag === 'template') {
1040
+ code += element.toEmbeddedTS(translator_1.shiftState(state, code, {
1041
+ tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0)
1042
+ }), levelIndex);
1043
+ }
1044
+ else {
1045
+ defaultArr_1.push(element);
1046
+ }
1047
+ });
1048
+ // 翻译其余的子集
1049
+ if (defaultArr_1.length) {
1050
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
1051
+ code += "slotDefault: ()=> {\n";
1052
+ code += this.getDatasourceTypeCodeStr(state, defaultArr_1);
1053
+ code += 'return [';
1054
+ defaultArr_1.forEach(function (element) {
1055
+ code += element.toEmbeddedTS(translator_1.shiftState(state, code, {
1056
+ tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2
1057
+ }), levelIndex);
1058
+ code += '\n';
1059
+ });
1060
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
1061
+ code += ']\n';
1062
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
1063
+ code += '}\n';
1064
+ }
1065
+ }
1066
+ else {
1067
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
1068
+ code += "slotDefault: ()=> {\n";
1069
+ code += this.getDatasourceTypeCodeStr(state, this.children);
1070
+ code += 'return [';
1071
+ this.children.forEach(function (element) {
1072
+ code += element.toEmbeddedTS(translator_1.shiftState(state, code, {
1073
+ tabSize: ((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2
1074
+ }), levelIndex);
1075
+ code += '\n';
1076
+ });
1077
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 2);
1078
+ code += ']\n';
1079
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0) + 1);
1080
+ code += '}\n';
1081
+ }
1082
+ }
1083
+ code += translator_1.indent(((state === null || state === void 0 ? void 0 : state.tabSize) || 0)) + '}),\n';
1084
+ return code;
1085
+ };
1086
+ ViewElement.prototype._duplicate = function () {
1087
+ var element = ViewElement_1.from(this.toTemplateJSON());
1088
+ element.deepRenameElements(this);
1089
+ this.view.existingViewElement.clear();
1090
+ return element;
1091
+ };
1092
+ // 递归遍历组件
1093
+ ViewElement.prototype.traverseChildren = function (cb) {
1094
+ utils.traverse(function (current) {
1095
+ cb(current.node);
1096
+ }, { node: this });
1097
+ };
1098
+ // 递归生成组件名
1099
+ ViewElement.prototype.deepRenameElements = function (node) {
1100
+ return this.traverseChildren(function (ele) {
1101
+ var tagName = ele.tag.replace(ViewElement_1.TAG_NAME_PREFIX_REG, '').replace(/-/g, '_');
1102
+ ele.name = node.getViewElementUniqueName(tagName + "1");
1103
+ });
1104
+ };
1105
+ /**
1106
+ * 解析属性中的表达式
1107
+ * @param value
1108
+ * @param $def 目前 $def 只用来查找 $def.variables 和 $def.structures
1109
+ * @param dataSchema
1110
+ */
1111
+ ViewElement._parseExpression = function (value) {
1112
+ try {
1113
+ var ast = babelParser.parseExpression(value);
1114
+ var node = transAstNodeToNaslNode(ast);
1115
+ return LogicItem__1["default"].from(node, null, null);
1116
+ }
1117
+ catch (e) {
1118
+ return null;
1119
+ }
1120
+ };
1121
+ ViewElement._parseValidationRule = function (value) {
1122
+ var _a, _b, _c, _d, _e;
1123
+ var calleeName = value;
1124
+ var args = [];
1125
+ try {
1126
+ var ast = babelParser.parseExpression(value);
1127
+ if (ast.type === 'CallExpression') {
1128
+ calleeName = ((_b = (_a = ast.callee) === null || _a === void 0 ? void 0 : _a.property) === null || _b === void 0 ? void 0 : _b.name) || ((_d = (_c = ast.callee) === null || _c === void 0 ? void 0 : _c.property) === null || _d === void 0 ? void 0 : _d.value) || ((_e = ast.callee) === null || _e === void 0 ? void 0 : _e.name);
1129
+ calleeName = calleeName.replace(/\(.*/, '');
1130
+ args = ast.arguments.map(function (argument) { return ({
1131
+ concept: 'Argument',
1132
+ name: '',
1133
+ kind: 'Statement',
1134
+ keyword: '',
1135
+ expression: transAstNodeToNaslNode(Object.assign({}, argument))
1136
+ }); });
1137
+ }
1138
+ }
1139
+ catch (error) { }
1140
+ return {
1141
+ concept: 'ValidationRule',
1142
+ name: '',
1143
+ label: '验证规则',
1144
+ kind: 'Expression',
1145
+ calleeNamespace: 'nasl.validation',
1146
+ arguments: args,
1147
+ calleeName: calleeName
1148
+ };
1149
+ };
1150
+ /**
1151
+ * 从 Vue 的 ASTNode 转换成 ASL 元素
1152
+ * @param astNode Vue 的 ASTNode
1153
+ */
1154
+ ViewElement._fromASTNode = function (astNode, context) {
1155
+ var _this = this;
1156
+ var _a, _b, _c;
1157
+ var view = context === null || context === void 0 ? void 0 : context.view;
1158
+ // 临时处理组件的 text
1159
+ //h5-mock
1160
+ if (['u-text', 'van-text', 'u-link', 'u-button', 'u-label', 'u-radio', 'u-checkbox', 'u-navbar-item', 'u-sidebar-item', 'u-menu-item'].includes(astNode.tag)
1161
+ && astNode.children.length === 1
1162
+ && astNode.children[0].type === 3) {
1163
+ astNode.attrs = astNode.attrs || [];
1164
+ astNode.attrs.push({
1165
+ name: 'text',
1166
+ value: JSON.stringify(astNode.children[0].text)
1167
+ });
1168
+ astNode.children = [];
1169
+ }
1170
+ // 将 scopedSlots 合并到 children 中
1171
+ if (astNode.scopedSlots) {
1172
+ astNode.children = astNode.children || [];
1173
+ Object.keys(astNode.scopedSlots).forEach(function (key) {
1174
+ if (!astNode.children.find(function (child) { return key === child.slotTarget; })) {
1175
+ astNode.children.unshift(astNode.scopedSlots[key]);
1176
+ }
1177
+ });
1178
+ delete astNode.scopedSlots;
1179
+ }
1180
+ // 提示不支持的属性
1181
+ ['component', 'inlineTemplate', 'pre', 'ns', 'transition', 'transitionOnAppear', 'transitionMode', 'slotName', 'classBinding', 'styleBinding'].forEach(function (key) {
1182
+ if (astNode[key])
1183
+ console.warn("[warn] ViewElement NASL unsupports '" + key + "' field in node ", astNode);
1184
+ });
1185
+ var element;
1186
+ if (astNode.type === 1) {
1187
+ if (astNode.tag === 'router-view') {
1188
+ if (__1.config.scope === 'h5') {
1189
+ astNode.tag = 'van-router-view';
1190
+ }
1191
+ else {
1192
+ astNode.tag = 'u-router-view';
1193
+ }
1194
+ }
1195
+ var tagName = astNode.tag.replace(ViewElement_1.TAG_NAME_PREFIX_REG, '').replace(/-/g, '_');
1196
+ var newContext_1 = {};
1197
+ if (context) {
1198
+ newContext_1 = __assign({}, context);
1199
+ }
1200
+ element = new ViewElement_1({
1201
+ tag: astNode.tag,
1202
+ name: astNode.attrsMap.ref || view.getViewElementUniqueName(tagName + "1"),
1203
+ staticClass: astNode.attrsMap["class"],
1204
+ staticStyle: astNode.attrsMap.style,
1205
+ slotTarget: astNode.slotTarget && json5.parse(astNode.slotTarget),
1206
+ slotScope: astNode.slotScope === '_empty_' ? '' : astNode.slotScope,
1207
+ children: astNode.children.map(function (item) { return _this._fromASTNode(item, newContext_1); })
1208
+ });
1209
+ (_a = astNode === null || astNode === void 0 ? void 0 : astNode.attrs) === null || _a === void 0 ? void 0 : _a.forEach(function (oldAttr) {
1210
+ var attr;
1211
+ // 获取原始属性
1212
+ var orginAttrCode = ((context === null || context === void 0 ? void 0 : context.code) || '').substr(oldAttr.start, oldAttr.end - oldAttr.start);
1213
+ if (oldAttr.value === '""' && orginAttrCode.trim() === oldAttr.name) {
1214
+ attr = new BindAttribute__1["default"]({
1215
+ type: 'static',
1216
+ name: oldAttr.name,
1217
+ value: 'true'
1218
+ });
1219
+ }
1220
+ else {
1221
+ try {
1222
+ var tmp = json5.parse(oldAttr.value);
1223
+ var source = {
1224
+ type: typeof tmp === 'string' ? 'string' : 'static',
1225
+ name: oldAttr.name,
1226
+ value: typeof tmp === 'string' ? tmp : oldAttr.value
1227
+ };
1228
+ if (oldAttr.name === 'rules') {
1229
+ source.rules = tmp === null || tmp === void 0 ? void 0 : tmp.split('|').map(function (ruleStr) { return _this._parseValidationRule(ruleStr.trim()); });
1230
+ }
1231
+ attr = new BindAttribute__1["default"](source);
1232
+ }
1233
+ catch (e) {
1234
+ var expression = _this._parseExpression(oldAttr.value);
1235
+ attr = new BindAttribute__1["default"]({
1236
+ type: 'dynamic',
1237
+ name: oldAttr.name,
1238
+ value: expression ? '' : oldAttr.value,
1239
+ expression: expression
1240
+ });
1241
+ if (astNode.attrsMap[":" + attr.name + ".sync"]) {
1242
+ attr.sync = true;
1243
+ }
1244
+ }
1245
+ }
1246
+ element.addBindAttribute(attr);
1247
+ });
1248
+ // compiler 处理:value.sync 时会加上update:value事件,需要过滤
1249
+ astNode.events
1250
+ && Object.keys(astNode.events)
1251
+ .filter(function (name) { return !name.startsWith('update:'); })
1252
+ .forEach(function (name) {
1253
+ var _a;
1254
+ var oldEvent = astNode.events[name];
1255
+ var str = oldEvent.value;
1256
+ var calleeName = str.split('(')[0];
1257
+ var matchArr = str.match(/\(([^)]*)\)/) || [];
1258
+ var argsStr = '';
1259
+ if ((matchArr === null || matchArr === void 0 ? void 0 : matchArr.length) >= 2) {
1260
+ argsStr = matchArr[1];
1261
+ }
1262
+ var args = [];
1263
+ var argStrs = argsStr.split(',');
1264
+ args = argStrs
1265
+ .filter(function (argStr) { return !!argStr; })
1266
+ .map(function (argStr) {
1267
+ var keyword = argStr.trim().split('.');
1268
+ return {
1269
+ concept: 'Argument',
1270
+ expression: genArgumentMemberExpression(keyword)
1271
+ };
1272
+ });
1273
+ var viewLogics = ((_a = context === null || context === void 0 ? void 0 : context.definition) === null || _a === void 0 ? void 0 : _a.viewLogics) || [];
1274
+ var currentLogic = viewLogics.find(function (item) { return item.name === calleeName; });
1275
+ if (currentLogic) {
1276
+ element.addBindEvent(new BindEvent__1["default"]({
1277
+ name: name,
1278
+ calleeNamespace: '',
1279
+ calleeName: '',
1280
+ arguments: args,
1281
+ logics: [currentLogic]
1282
+ }));
1283
+ }
1284
+ });
1285
+ astNode.directives
1286
+ && astNode.directives.forEach(function (directive) {
1287
+ if (directive.name === 'model') {
1288
+ var valueAttr = astNode.attrs && astNode.attrs.find(function (attr) { return attr.name === 'value'; });
1289
+ if (!valueAttr) {
1290
+ var expression = _this._parseExpression(directive.value);
1291
+ element.addBindAttribute(new BindAttribute__1["default"]({
1292
+ type: 'dynamic',
1293
+ name: 'value',
1294
+ value: expression ? '' : directive.value,
1295
+ expression: expression,
1296
+ sync: true
1297
+ }));
1298
+ }
1299
+ }
1300
+ else {
1301
+ var expression = _this._parseExpression(directive.value);
1302
+ element.addBindDirective(new BindDirective__1["default"]({
1303
+ type: expression ? 'string' : 'dynamic',
1304
+ name: directive.name,
1305
+ rawName: directive.rawName,
1306
+ value: expression ? '' : directive.value,
1307
+ expression: expression,
1308
+ arg: directive.arg
1309
+ }));
1310
+ }
1311
+ });
1312
+ if (astNode["if"]) {
1313
+ element.addBindDirective(new BindDirective__1["default"]({
1314
+ type: 'dynamic',
1315
+ name: 'if',
1316
+ rawName: 'v-if',
1317
+ value: '',
1318
+ expression: this._parseExpression(astNode["if"])
1319
+ }));
1320
+ }
1321
+ }
1322
+ else if (astNode.type === 2) {
1323
+ var tagName = __1.config.scope === 'h5' ? 'van-text' : 'u-text';
1324
+ var baseName = tagName.replace(ViewElement_1.TAG_NAME_PREFIX_REG, '').replace(/-/g, '_');
1325
+ element = new ViewElement_1({
1326
+ tag: tagName,
1327
+ name: view.getViewElementUniqueName(baseName + "1")
1328
+ });
1329
+ var value = (_b = astNode.text) === null || _b === void 0 ? void 0 : _b.match(/{{(.*?)}}/)[1].trim();
1330
+ var expression = this._parseExpression(value);
1331
+ element.addBindAttribute(new BindAttribute__1["default"]({
1332
+ type: 'dynamic',
1333
+ name: 'text',
1334
+ value: expression ? '' : value,
1335
+ expression: expression
1336
+ }));
1337
+ }
1338
+ else if (astNode.type === 3) {
1339
+ var tagName = __1.config.scope === 'h5' ? 'van-text' : 'u-text';
1340
+ var baseName = tagName.replace(ViewElement_1.TAG_NAME_PREFIX_REG, '').replace(/-/g, '_');
1341
+ element = new ViewElement_1({
1342
+ tag: tagName,
1343
+ name: view.getViewElementUniqueName(baseName + "1")
1344
+ });
1345
+ element.addBindAttribute(new BindAttribute__1["default"]({
1346
+ name: 'text',
1347
+ type: 'string',
1348
+ value: (_c = astNode.text) === null || _c === void 0 ? void 0 : _c.trim()
1349
+ }));
1350
+ }
1351
+ return element;
1352
+ };
1353
+ /**
1354
+ * 解析 Vue 模板
1355
+ * 该方法不会绑定 view 和 parent,如果是添加元素优先使用 fromHTML
1356
+ * @param html Vue 的模板
1357
+ * @TODO 处理多个元素的问题
1358
+ */
1359
+ ViewElement.parse = function (code, context) {
1360
+ code = code || '<div></div>';
1361
+ var compilerOptions = {
1362
+ preserveWhitespace: false,
1363
+ outputSourceRange: true
1364
+ };
1365
+ var ast = compiler.compile(code, compilerOptions).ast;
1366
+ if (ast.tag === 'template' && !ast.slotTarget)
1367
+ ast = ast.children[0];
1368
+ return this._fromASTNode(ast, __assign(__assign({}, context), { code: code }));
1369
+ };
1370
+ /**
1371
+ * 从模板生成规范的 ViewElement 对象
1372
+ */
1373
+ ViewElement.fromHTML = function (html, context) {
1374
+ return this.parse(html, context);
1375
+ };
1376
+ /**
1377
+ * 转换成设计器中使用的 Vue 文件
1378
+ * @param options
1379
+ */
1380
+ ViewElement.prototype.toDesignerVue = function () {
1381
+ return this.toVue({
1382
+ finalCode: false,
1383
+ nodePathAttr: true,
1384
+ attrFormat: function (attr, element, defaultResult) {
1385
+ if (attr.concept === 'BindAttribute' && !['href', 'destination', 'externalDestination', 'download'].includes(attr.name)) {
1386
+ var api = __1.config.allNodesAPI[element.tag];
1387
+ var apiOfAttr_1 = api && api.attrs && api.attrs.find(function (_attr) { return _attr.name === attr.name; });
1388
+ if (['u-form-item', 'u-validator', 'van-field'].includes(element.tag) && attr.name === 'rules') {
1389
+ return attr.name + "=\"\"";
1390
+ }
1391
+ if (apiOfAttr_1 && apiOfAttr_1['designer-value'] !== undefined) {
1392
+ var designerValue_1 = apiOfAttr_1['designer-value'];
1393
+ //对流程模板拖拽进行特判
1394
+ element.bindAttrs.forEach(function (property) {
1395
+ if (property.name === 'repeat' && property.value === '1')
1396
+ designerValue_1 = '[{}, {}]';
1397
+ });
1398
+ if (typeof designerValue_1 === 'string') {
1399
+ designerValue_1 = designerValue_1.replace(/"/g, "'");
1400
+ }
1401
+ try {
1402
+ json5.parse(designerValue_1);
1403
+ return ":" + attr.name + "=\"" + designerValue_1 + "\"";
1404
+ }
1405
+ catch (e) {
1406
+ return attr.name + "=\"" + designerValue_1 + "\"";
1407
+ }
1408
+ }
1409
+ if (attr.type === 'dynamic' && !(element.tag === 'u-cascade-select' && attr.name === 'categories'))
1410
+ return defaultResult.replace(/:?([\w-]+)(?:.*?)="(.*)"/, function (m, name, value) {
1411
+ try {
1412
+ var tempValue = json5.parse(value);
1413
+ if (typeof tempValue === 'boolean' || typeof tempValue === 'number') {
1414
+ // 简单类型走属性
1415
+ return ":" + name + "=\"" + value.replace(/"/g, "'") + "\"";
1416
+ }
1417
+ }
1418
+ catch (e) {
1419
+ if (apiOfAttr_1 && !apiOfAttr_1.type.includes('string'))
1420
+ return '';
1421
+ }
1422
+ value = value
1423
+ .replace(/"/g, "'")
1424
+ .replace(/\$utils\['(.+?)'\]/g, '$1')
1425
+ .replace(/\$refs./g, 'elements.')
1426
+ .replace(/\$global.userInfo/g, 'nasl.auth.userInfo')
1427
+ .replace(/\$global./g, 'nasl.')
1428
+ .replace(/\bscope\.item\.\b/g, '')
1429
+ .replace(/\bcurrent\.item\.\b/g, '');
1430
+ return name + "=\"{{ " + value + " }}\"";
1431
+ });
1432
+ else
1433
+ return defaultResult;
1434
+ }
1435
+ return false;
1436
+ },
1437
+ bindStylesFormat: function (bindStyles, element) { return false; },
1438
+ getExtraParts: function (el) {
1439
+ var parts = [];
1440
+ var api = __1.config.allNodesAPI[el.tag];
1441
+ var emptySlot = api && api.slots && api.slots.find(function (slot) { return slot.name === 'default' && slot['empty-background']; });
1442
+ var hasSupport = api && api.slots && api.slots.some(function (slot) { return slot.support; });
1443
+ if (emptySlot || hasSupport) {
1444
+ // 有些限制的组件如侧边栏分组有title插槽但要限制子元素放入
1445
+ var validChildren = el.children.filter(function (elem) { return !(elem.tag === 'template' && elem.slotTarget !== 'default'); });
1446
+ var childEmpty = !validChildren.length;
1447
+ var defaultSlot = el.children.find(function (elem) { return elem.tag === 'template' && elem.slotTarget === 'default'; });
1448
+ if (defaultSlot) {
1449
+ childEmpty = !defaultSlot.children.length;
1450
+ }
1451
+ if (childEmpty) {
1452
+ var addEmpty = true;
1453
+ if (el.tag === 'u-grid-view' || el.tag === 'u-list-view' || el.tag === 'van-list-view' || el.tag === 'van-grid-view') {
1454
+ var hasDataSource = el.bindAttrs.find(function (attr) { return attr.name === 'data-source'; });
1455
+ addEmpty = !hasDataSource;
1456
+ }
1457
+ if (el.tag === 'u-crumb') {
1458
+ var attrList = el.bindAttrs;
1459
+ var hasAuto = attrList.some(function (attr) { return attr.name === 'auto' && String(attr.value) === 'true'; });
1460
+ if (hasAuto)
1461
+ addEmpty = false;
1462
+ }
1463
+ if (['u-select', 'u-dropdown', 'u-panel', 'u-toc', 'u-toc-item', 'u-tree-view-new', 'u-tree-view-node-new', 'u-tree-select', 'u-tree-select-new', 'u-anchor', 'u-drawer', 'u-timeline', 'u-tabs'].includes(el.tag)) {
1464
+ addEmpty = false;
1465
+ }
1466
+ var background = (emptySlot && emptySlot['empty-background']) || (hasSupport ? 'add-sub' : '');
1467
+ addEmpty && parts.push("vusion-empty-background=\"" + background + "\"");
1468
+ }
1469
+ }
1470
+ if (['u-router-view', 'van-router-view'].includes(el.tag)) {
1471
+ var excludes = ['background-color:', 'background:', 'background-image:'];
1472
+ if (excludes.some(function (key) { return (el.staticStyle && el.staticStyle.includes(key)); })) {
1473
+ parts.push(':designer="false"');
1474
+ }
1475
+ }
1476
+ return parts;
1477
+ }
1478
+ });
1479
+ };
1480
+ /**
1481
+ * 转换成 Vue 的模板格式
1482
+ */
1483
+ ViewElement.prototype.toVue = function (options) {
1484
+ var _this = this;
1485
+ var currentList = [];
1486
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.currentList)) {
1487
+ currentList = __spreadArrays(options === null || options === void 0 ? void 0 : options.currentList);
1488
+ }
1489
+ if (this.slotScope) {
1490
+ currentList.unshift(this.slotScope);
1491
+ }
1492
+ var newOptions = Object.assign({
1493
+ indentStyle: 'space',
1494
+ tabSize: 4,
1495
+ indentLevel: 0,
1496
+ aslIdAttr: false,
1497
+ nodePathAttr: false,
1498
+ getExtraParts: function () { return []; },
1499
+ attrFormat: function (attr, element, defaultResult) { return defaultResult; },
1500
+ bindStylesFormat: function (bindStyles, element) {
1501
+ if (bindStyles.length === 0)
1502
+ return false;
1503
+ return ":style=\"{" + bindStyles
1504
+ .map(function (item) { return item.toVue(); })
1505
+ .filter(function (item) { return item !== undefined; })
1506
+ .join(', ') + "}\"";
1507
+ }
1508
+ }, options, {
1509
+ currentList: currentList
1510
+ });
1511
+ var tabString = ' '.repeat(newOptions.tabSize * newOptions.indentLevel);
1512
+ var insideTabString = ' '.repeat(newOptions.tabSize * (newOptions.indentLevel + 1));
1513
+ var shouldIndent = true;
1514
+ var content = !this.children ? '' : this.children
1515
+ .map(function (element) {
1516
+ var childOptions = Object.assign({}, newOptions);
1517
+ childOptions.indentLevel++;
1518
+ return (shouldIndent ? '\n' + insideTabString : '') + (element === null || element === void 0 ? void 0 : element.toVue(childOptions));
1519
+ })
1520
+ .join('');
1521
+ if (!content.length) {
1522
+ shouldIndent = false;
1523
+ }
1524
+ var parts = [];
1525
+ if (newOptions.aslIdAttr) {
1526
+ if (newOptions.aslIdAttr === true) {
1527
+ newOptions.aslIdAttr = 'asl-id';
1528
+ }
1529
+ parts.push(newOptions.aslIdAttr + "=\"" + this.id + "\"");
1530
+ }
1531
+ if (newOptions.nodePathAttr) {
1532
+ // 注入 asl 的 node-path
1533
+ parts.push("vusion-node-path=\"" + this.nodePath + "\"");
1534
+ }
1535
+ // 模板里解析时候,可能会有多级嵌套的 current,所以当前有多少的长度,当前就是多大的下标
1536
+ this.slotTarget && parts.push("#" + this.slotTarget + (this.slotScope ? "=\"" + (currentList.length > 1 ? this.slotScope + (currentList.length - 1) : this.slotScope) + "\"" : ''));
1537
+ this.name && parts.push("ref=\"" + this.name + "\"");
1538
+ this.staticClass && parts.push("class=\"" + this.staticClass + "\"");
1539
+ this.staticStyle && parts.push("style=\"" + this.staticStyle + "\"");
1540
+ var vIfs = [];
1541
+ [].concat(this.bindAttrs, this.bindDirectives, this.bindEvents).forEach(function (attr) {
1542
+ var result = newOptions.attrFormat(attr, _this, attr === null || attr === void 0 ? void 0 : attr.toVue(newOptions));
1543
+ //// v-auth v-if 都翻译成 v-if
1544
+ //if(attr instanceof BindDirective && ['if', 'auth'].includes(attr.name) && result !== false) {
1545
+ // const expr = result.replace(/v-(if|auth)="(.*)"/, (match, p1, p2) => p2);
1546
+ // if(expr)
1547
+ // vIfs.push(attr.name === 'if' ? expr : `$auth.has(${expr})`);
1548
+ // return;
1549
+ //}
1550
+ result && parts.push(result);
1551
+ });
1552
+ if (vIfs.length === 2)
1553
+ parts.push("v-if=\"(" + vIfs[0] + ") && (" + vIfs[1] + ")\"");
1554
+ else if (vIfs.length === 1)
1555
+ parts.push("v-if=\"" + vIfs[0] + "\"");
1556
+ var bindStyles = newOptions.bindStylesFormat(this.bindStyles, this);
1557
+ if (bindStyles)
1558
+ parts.push(bindStyles);
1559
+ newOptions.getExtraParts(this).forEach(function (part) { return parts.push(part); });
1560
+ if (['u-modal', 'u-drawer'].includes(this.tag)) {
1561
+ this.children.forEach(function (citem) {
1562
+ if (citem.tag === 'template' && !citem.children.length) {
1563
+ parts.push(":is-" + citem.slotTarget + "-slot-empty=true");
1564
+ }
1565
+ });
1566
+ }
1567
+ var partsLength = 0;
1568
+ var partsString = '';
1569
+ parts.forEach(function (part) {
1570
+ if (partsLength >= 120 || part.length >= 120) {
1571
+ partsString += '\n' + tabString + ' '.repeat(3); // ' '.repeat(el.tag.length + 1);
1572
+ partsLength = 0;
1573
+ }
1574
+ partsString += ' ' + part;
1575
+ partsLength += part.length;
1576
+ });
1577
+ var htmlContent = "<" + this.tag + (partsString.length ? partsString : '') + ">" + content + (shouldIndent ? '\n' + tabString : '') + ("</" + this.tag + ">");
1578
+ if (!content.trim() && selfClosingTag.includes(this.tag)) {
1579
+ htmlContent = "<" + this.tag + (partsString.length ? partsString : '') + " />";
1580
+ }
1581
+ return htmlContent;
1582
+ };
1583
+ /**
1584
+ * 从父级删除该节点
1585
+ * @internal
1586
+ */
1587
+ ViewElement.prototype["delete"] = function () {
1588
+ var _this = this;
1589
+ _super.prototype["delete"].call(this);
1590
+ if (this.parentNode) {
1591
+ this.traverseChildren(function (ele) {
1592
+ var _a;
1593
+ (_a = _this.view) === null || _a === void 0 ? void 0 : _a.removeExistingViewElement(ele);
1594
+ });
1595
+ }
1596
+ };
1597
+ ViewElement.prototype.findElementByName = function (name) {
1598
+ return utils.traverse(function (current) {
1599
+ if (current.node.name === name)
1600
+ return current.node;
1601
+ }, { node: this });
1602
+ };
1603
+ ViewElement.prototype.findElementByTag = function (tag) {
1604
+ return utils.traverse(function (current) {
1605
+ if (current.node.tag === tag)
1606
+ return current.node;
1607
+ }, { node: this });
1608
+ };
1609
+ ViewElement.prototype.findElementByAttr = function (name, value) {
1610
+ return utils.traverse(function (current) {
1611
+ if (current.node.bindAttrs.some(function (attr) { return attr.name === name && attr.value === value; }))
1612
+ return current.node;
1613
+ }, { node: this });
1614
+ };
1615
+ ViewElement.prototype.getCurrentName = function () {
1616
+ var current = 'current';
1617
+ var parent = this.parentNode;
1618
+ var index = 0;
1619
+ while (parent && parent.concept !== 'View') {
1620
+ if (parent.slotScope) {
1621
+ index++;
1622
+ }
1623
+ parent = parent.parentNode;
1624
+ }
1625
+ current = (index === 0 ? 'current' : 'current' + index);
1626
+ return current;
1627
+ };
1628
+ var ViewElement_1;
1629
+ ViewElement.TAG_NAME_PREFIX_REG = /^([lieu]|van)[-_]/;
1630
+ __decorate([
1631
+ decorators_1.property()
1632
+ ], ViewElement.prototype, "concept");
1633
+ __decorate([
1634
+ decorators_1.property()
1635
+ ], ViewElement.prototype, "type");
1636
+ __decorate([
1637
+ decorators_1.property()
1638
+ ], ViewElement.prototype, "tag");
1639
+ __decorate([
1640
+ decorators_1.property()
1641
+ ], ViewElement.prototype, "name");
1642
+ __decorate([
1643
+ decorators_1.property()
1644
+ ], ViewElement.prototype, "staticClass");
1645
+ __decorate([
1646
+ decorators_1.property()
1647
+ ], ViewElement.prototype, "staticStyle");
1648
+ __decorate([
1649
+ decorators_1.property()
1650
+ ], ViewElement.prototype, "authDescription");
1651
+ __decorate([
1652
+ decorators_1.property()
1653
+ ], ViewElement.prototype, "slotTarget");
1654
+ __decorate([
1655
+ decorators_1.property()
1656
+ ], ViewElement.prototype, "slotScope");
1657
+ __decorate([
1658
+ decorators_1.property('BindAttribute')
1659
+ ], ViewElement.prototype, "bindAttrs");
1660
+ __decorate([
1661
+ decorators_1.property('BindEvent')
1662
+ ], ViewElement.prototype, "bindEvents");
1663
+ __decorate([
1664
+ decorators_1.property('BindDirective')
1665
+ ], ViewElement.prototype, "bindDirectives");
1666
+ __decorate([
1667
+ decorators_1.property()
1668
+ ], ViewElement.prototype, "bindRoles");
1669
+ __decorate([
1670
+ decorators_1.property('BindStyle')
1671
+ ], ViewElement.prototype, "bindStyles");
1672
+ __decorate([
1673
+ decorators_1.property('ViewElement')
1674
+ ], ViewElement.prototype, "children");
1675
+ __decorate([
1676
+ translator_1.withSourceMap()
1677
+ ], ViewElement.prototype, "toEmbeddedTS");
1678
+ __decorate([
1679
+ decorators_1.excludedInJSON()
1680
+ ], ViewElement.prototype, "computedStyle");
1681
+ ViewElement = ViewElement_1 = __decorate([
1682
+ decorators_1.concept('页面元素')
1683
+ ], ViewElement);
1684
+ return ViewElement;
1685
+ }(BaseNode_1["default"]));
1686
+ exports.ViewElement = ViewElement;
1687
+ classMap_1["default"].ViewElement = ViewElement;
1688
+ exports["default"] = ViewElement;
1689
+ //================================================================================
1690
+ // ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
1691
+ // 自动生成的代码已结束。下面可以手动编写。
1692
+ //================================================================================