@lcap/nasl 3.8.2-beta.8 → 3.8.3-beta.1

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 (223) hide show
  1. package/ai-engineer.config.js +617 -0
  2. package/out/common/BaseNode.js +5 -3
  3. package/out/common/BaseNode.js.map +1 -1
  4. package/out/common/ComponentAPI.d.ts +9 -0
  5. package/out/concepts/AuthLogicForCallInterface__.js +21 -6
  6. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  7. package/out/concepts/BackendVariable__.js +16 -1
  8. package/out/concepts/BackendVariable__.js.map +1 -1
  9. package/out/concepts/BindAttribute__.js +12 -4
  10. package/out/concepts/BindAttribute__.js.map +1 -1
  11. package/out/concepts/BindDirective__.js +1 -1
  12. package/out/concepts/BindDirective__.js.map +1 -1
  13. package/out/concepts/BindStyle__.js +1 -1
  14. package/out/concepts/BindStyle__.js.map +1 -1
  15. package/out/concepts/BusinessComponent__.js +24 -8
  16. package/out/concepts/BusinessComponent__.js.map +1 -1
  17. package/out/concepts/BusinessLogic__.js +21 -6
  18. package/out/concepts/BusinessLogic__.js.map +1 -1
  19. package/out/concepts/CallInterface__.js +2 -1
  20. package/out/concepts/CallInterface__.js.map +1 -1
  21. package/out/concepts/CallLogic__.d.ts +1 -0
  22. package/out/concepts/CallLogic__.js +32 -11
  23. package/out/concepts/CallLogic__.js.map +1 -1
  24. package/out/concepts/CallQueryComponent__.d.ts +1 -0
  25. package/out/concepts/CallQueryComponent__.js +23 -12
  26. package/out/concepts/CallQueryComponent__.js.map +1 -1
  27. package/out/concepts/Destination__.js +11 -8
  28. package/out/concepts/Destination__.js.map +1 -1
  29. package/out/concepts/EntityProperty__.js +3 -2
  30. package/out/concepts/EntityProperty__.js.map +1 -1
  31. package/out/concepts/Entity__.js +1 -1
  32. package/out/concepts/Entity__.js.map +1 -1
  33. package/out/concepts/Interface__.js +1 -1
  34. package/out/concepts/Interface__.js.map +1 -1
  35. package/out/concepts/Logic__.js +49 -17
  36. package/out/concepts/Logic__.js.map +1 -1
  37. package/out/concepts/MemberExpression__.js +19 -13
  38. package/out/concepts/MemberExpression__.js.map +1 -1
  39. package/out/concepts/OqlQueryComponent__.js +37 -12
  40. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  41. package/out/concepts/OverriddenLogic__.js +21 -6
  42. package/out/concepts/OverriddenLogic__.js.map +1 -1
  43. package/out/concepts/Param__.js +5 -4
  44. package/out/concepts/Param__.js.map +1 -1
  45. package/out/concepts/QueryOrderByExpression__.d.ts +0 -1
  46. package/out/concepts/QueryOrderByExpression__.js +0 -1
  47. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  48. package/out/concepts/Structure__.js +5 -7
  49. package/out/concepts/Structure__.js.map +1 -1
  50. package/out/concepts/Variable__.js +5 -0
  51. package/out/concepts/Variable__.js.map +1 -1
  52. package/out/concepts/ViewElement__.d.ts +1 -0
  53. package/out/concepts/ViewElement__.js +17 -7
  54. package/out/concepts/ViewElement__.js.map +1 -1
  55. package/out/concepts/View__.js +70 -14
  56. package/out/concepts/View__.js.map +1 -1
  57. package/out/concepts/basics/stdlib/nasl.processV2.js +78 -0
  58. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  59. package/out/concepts/basics/stdlib/nasl.ui.js +40 -40
  60. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  61. package/out/generator/genBundleFiles.js +1 -1
  62. package/out/generator/genBundleFiles.js.map +1 -1
  63. package/out/generator/release-body/utils.js +1 -1
  64. package/out/natural/genNaturalTS.d.ts +45 -10
  65. package/out/natural/genNaturalTS.js +57 -33
  66. package/out/natural/genNaturalTS.js.map +1 -1
  67. package/out/natural/getContext/getUILib.js +6 -3
  68. package/out/natural/getContext/getUILib.js.map +1 -1
  69. package/out/natural/getContext/index.d.ts +20 -7
  70. package/out/natural/getContext/index.js +143 -23
  71. package/out/natural/getContext/index.js.map +1 -1
  72. package/out/natural/getContext/naslStdlibMap.js +8 -8
  73. package/out/natural/getContext/naslStdlibMap.js.map +1 -1
  74. package/out/natural/tools.d.ts +16 -0
  75. package/out/natural/tools.js +110 -2
  76. package/out/natural/tools.js.map +1 -1
  77. package/out/natural/transformTS2UI.js +361 -304
  78. package/out/natural/transformTS2UI.js.map +1 -1
  79. package/out/natural/transformTSCode.d.ts +3 -5
  80. package/out/natural/transformTSCode.js +30 -1089
  81. package/out/natural/transformTSCode.js.map +1 -1
  82. package/out/natural/transforms/registerTransform.d.ts +7 -0
  83. package/out/natural/transforms/registerTransform.js +24 -0
  84. package/out/natural/transforms/registerTransform.js.map +1 -0
  85. package/out/natural/transforms/transform2LogicItem.d.ts +24 -0
  86. package/out/natural/transforms/transform2LogicItem.js +1240 -0
  87. package/out/natural/transforms/transform2LogicItem.js.map +1 -0
  88. package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -0
  89. package/out/natural/transforms/transform2TypeAnnotation.js +86 -0
  90. package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -0
  91. package/out/natural/transforms/utils.d.ts +8 -0
  92. package/out/natural/transforms/utils.js +59 -0
  93. package/out/natural/transforms/utils.js.map +1 -0
  94. package/out/server/getLogics.js +12 -12
  95. package/out/server/getLogics.js.map +1 -1
  96. package/out/server/getMemberIdentifier.js +11 -17
  97. package/out/server/getMemberIdentifier.js.map +1 -1
  98. package/out/server/naslServer.d.ts +2 -2
  99. package/out/server/naslServer.js +38 -18
  100. package/out/server/naslServer.js.map +1 -1
  101. package/out/server/translator.js +5 -0
  102. package/out/server/translator.js.map +1 -1
  103. package/out/templator/block2nasl/jsx2nasl/index.d.ts +5 -0
  104. package/out/templator/block2nasl/jsx2nasl/index.js +15 -0
  105. package/out/templator/block2nasl/jsx2nasl/index.js.map +1 -0
  106. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts +3 -0
  107. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +213 -0
  108. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -0
  109. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +14 -0
  110. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +201 -0
  111. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -0
  112. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts +4 -0
  113. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js +186 -0
  114. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js.map +1 -0
  115. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts +28 -0
  116. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +336 -0
  117. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -0
  118. package/out/templator/block2nasl/jsx2nasl/utils.d.ts +2 -0
  119. package/out/templator/block2nasl/jsx2nasl/utils.js +26 -0
  120. package/out/templator/block2nasl/jsx2nasl/utils.js.map +1 -0
  121. package/out/templator/block2nasl/transformBlock2Nasl.d.ts +10 -0
  122. package/out/templator/block2nasl/transformBlock2Nasl.js +122 -0
  123. package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -0
  124. package/out/templator/block2nasl/viewMergeBlock.d.ts +9 -0
  125. package/out/templator/block2nasl/viewMergeBlock.js +110 -0
  126. package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
  127. package/out/translator/types.d.ts +2 -0
  128. package/out/translator/utils.js +1 -1
  129. package/out/translator/utils.js.map +1 -1
  130. package/out/utils/index.js +0 -4
  131. package/out/utils/index.js.map +1 -1
  132. package/out/utils/language-cache/constant.d.ts +2 -1
  133. package/out/utils/language-cache/constant.js +1 -0
  134. package/out/utils/language-cache/constant.js.map +1 -1
  135. package/out/utils/language-cache/nasl.d.ts +1 -0
  136. package/out/utils/language-cache/nasl.js +9 -1
  137. package/out/utils/language-cache/nasl.js.map +1 -1
  138. package/package.json +6 -2
  139. package/sandbox/stdlib/nasl.processV2.ts +19 -0
  140. package/sandbox/stdlib/nasl.ui.ts +8 -8
  141. package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
  142. package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
  143. package/sandbox-natural/stdlib/nasl.ui.d.ts +78 -0
  144. package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
  145. package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
  146. package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
  147. package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
  148. package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +49 -43
  149. package/src/common/BaseNode.ts +5 -3
  150. package/src/common/ComponentAPI.ts +7 -0
  151. package/src/concepts/AuthLogicForCallInterface__.ts +23 -6
  152. package/src/concepts/BackendVariable__.ts +16 -1
  153. package/src/concepts/BindAttribute__.ts +18 -13
  154. package/src/concepts/BindDirective__.ts +1 -1
  155. package/src/concepts/BindStyle__.ts +1 -1
  156. package/src/concepts/BusinessComponent__.ts +26 -8
  157. package/src/concepts/BusinessLogic__.ts +23 -6
  158. package/src/concepts/CallInterface__.ts +2 -2
  159. package/src/concepts/CallLogic__.ts +50 -24
  160. package/src/concepts/CallQueryComponent__.ts +26 -12
  161. package/src/concepts/Destination__.ts +14 -12
  162. package/src/concepts/EntityProperty__.ts +5 -5
  163. package/src/concepts/Entity__.ts +1 -1
  164. package/src/concepts/Interface__.ts +1 -1
  165. package/src/concepts/Logic__.ts +62 -33
  166. package/src/concepts/MemberExpression__.ts +20 -13
  167. package/src/concepts/OqlQueryComponent__.ts +29 -5
  168. package/src/concepts/OverriddenLogic__.ts +23 -6
  169. package/src/concepts/Param__.ts +5 -4
  170. package/src/concepts/QueryOrderByExpression__.ts +0 -1
  171. package/src/concepts/Structure__.ts +5 -7
  172. package/src/concepts/Variable__.ts +9 -5
  173. package/src/concepts/ViewElement__.ts +25 -9
  174. package/src/concepts/View__.ts +97 -37
  175. package/src/concepts/basics/stdlib/nasl.processV2.ts +79 -0
  176. package/src/concepts/basics/stdlib/nasl.ui.ts +40 -40
  177. package/src/generator/genBundleFiles.ts +1 -1
  178. package/src/generator/release-body/utils.ts +1 -1
  179. package/src/natural/genNaturalTS.ts +88 -39
  180. package/src/natural/getContext/getUILib.ts +6 -3
  181. package/src/natural/getContext/index.ts +125 -23
  182. package/src/natural/getContext/naslStdlibMap.ts +8 -8
  183. package/src/natural/tools.ts +107 -2
  184. package/src/natural/transformTS2UI.ts +205 -147
  185. package/src/natural/transformTSCode.ts +29 -1055
  186. package/src/natural/transforms/registerTransform.ts +34 -0
  187. package/src/natural/transforms/transform2LogicItem.ts +1335 -0
  188. package/src/natural/transforms/transform2TypeAnnotation.ts +77 -0
  189. package/src/natural/transforms/utils.ts +25 -0
  190. package/src/server/getLogics.ts +12 -12
  191. package/src/server/getMemberIdentifier.ts +14 -14
  192. package/src/server/naslServer.ts +39 -19
  193. package/src/server/translator.ts +5 -0
  194. package/src/templator/block2nasl/jsx2nasl/index.ts +11 -0
  195. package/src/templator/block2nasl/jsx2nasl/transform-expression2nasl.ts +238 -0
  196. package/src/templator/block2nasl/jsx2nasl/transform-func2nasl.ts +241 -0
  197. package/src/templator/block2nasl/jsx2nasl/transform-tstype2nasl.ts +213 -0
  198. package/src/templator/block2nasl/jsx2nasl/transform-tsx2nasl.ts +422 -0
  199. package/src/templator/block2nasl/jsx2nasl/utils.ts +19 -0
  200. package/src/templator/block2nasl/transformBlock2Nasl.ts +99 -0
  201. package/src/templator/block2nasl/viewMergeBlock.ts +149 -0
  202. package/src/translator/types.ts +2 -0
  203. package/src/translator/utils.ts +1 -1
  204. package/src/utils/index.ts +0 -4
  205. package/src/utils/language-cache/constant.ts +1 -0
  206. package/src/utils/language-cache/nasl.ts +6 -0
  207. package/test/concepts/member-expression/__snapshots__/toJS.spec.ts.snap +1 -1
  208. package/test/concepts/member-expression/__snapshots__/toVue.spec.ts.snap +1 -1
  209. package/test/tdd/dataQuery/QueryFieldExpression/case1/ast.json +7 -0
  210. package/test/tdd/dataQuery/QueryFieldExpression/case1/natural.ts.txt +1 -0
  211. package/test/tdd/dataQuery/QueryFieldExpression/case2/ast.json +7 -0
  212. package/test/tdd/dataQuery/QueryFieldExpression/case2/natural.ts.txt +1 -0
  213. package/test/tdd/transform/case1/ast.json +243 -0
  214. package/test/tdd/transform/case1/natural.ts.md +20 -0
  215. package/test/tdd/transform/case2/ast.json +207 -0
  216. package/test/tdd/transform/case2/natural.ts.md +12 -0
  217. package/test/tdd.test.js +10 -0
  218. package/test/tdd.transform.test.js +38 -0
  219. package/test/utils.js +40 -0
  220. package/sandbox-natural/stdlib/nasl.core.ts +0 -36
  221. package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
  222. package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +0 -90
  223. package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
@@ -22,25 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.tryTransformTS2UI = void 0;
30
27
  /* eslint-disable global-require */
31
28
  /* eslint-disable @typescript-eslint/no-use-before-define */
29
+ const utils_1 = require("./transforms/utils");
32
30
  const lodash_1 = require("lodash");
33
31
  const babel = __importStar(require("@babel/core"));
34
- const generator_1 = __importDefault(require("@babel/generator"));
35
- const naslTypes = __importStar(require("../concepts"));
36
- const generator_2 = require("../generator");
37
- const DEBUG = false;
38
- function throwError(message) {
39
- if (DEBUG)
40
- throw new Error(message);
41
- else
42
- console.error(message);
43
- }
32
+ const generator_1 = require("../generator");
33
+ const transform2TypeAnnotation_1 = require("./transforms/transform2TypeAnnotation");
44
34
  function flatMemberExpression(node) {
45
35
  if (node.type === 'MemberExpression')
46
36
  return [...flatMemberExpression(node.object), node.property];
@@ -76,105 +66,40 @@ function flatIfStatement(node) {
76
66
  */
77
67
  function fixLogicNode(node) {
78
68
  if (node?.type === 'CallExpression') {
79
- const calleeName = (0, generator_1.default)(node.callee).code;
69
+ const calleeName = (0, utils_1.generate)(node.callee).code;
80
70
  if (calleeName === 'nasl.util.ForEach') {
81
71
  const callee = flatMemberExpression(node.callee);
82
72
  node.callee = callee[2];
83
73
  }
84
74
  }
85
75
  }
86
- // 处理类型
87
- function transformTypeAnnotation(node) {
88
- if (!node)
89
- return null;
90
- if (node.type === 'TSTypeReference') {
91
- const typeName = node.typeName.name;
92
- const primitiveType = naslTypes.primitiveTypeList.find((ta) => ta.typeName === typeName);
93
- if (node?.typeNamespace) {
94
- return naslTypes.TypeAnnotation.createReference(typeName, {
95
- typeNamespace: node.typeNamespace,
96
- });
97
- }
98
- if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
99
- return naslTypes.TypeAnnotation.createReference(typeName, {
100
- typeNamespace: 'nasl.ui'
101
- });
102
- }
103
- if (typeName === 'Any' || typeName === 'any') {
104
- return undefined;
105
- }
106
- if (typeName === 'Integer') {
107
- return naslTypes.TypeAnnotation.createPrimitive('Long');
108
- }
109
- if (primitiveType) {
110
- return naslTypes.TypeAnnotation.createPrimitive(typeName);
111
- }
112
- if (['List', 'Map', 'Current'].includes(typeName) && node?.typeParameters) {
113
- return naslTypes.TypeAnnotation.createGeneric(typeName, {
114
- typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
115
- });
116
- }
117
- if (node?.typeName?.type === 'TSQualifiedName' && node?.typeParameters) {
118
- const curTypeName = node?.typeName?.right?.name;
119
- return naslTypes.TypeAnnotation.createGeneric(curTypeName, {
120
- typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
121
- });
122
- }
123
- if (!node.typeParameters) {
124
- if (node?.typeName?.type === 'TSQualifiedName') {
125
- const allTypeName = (0, generator_1.default)(node?.typeName?.left)?.code;
126
- // 实体、枚举、结构体
127
- if (/^app.dataSources|.enums|.structures|nasl.ui/.test(allTypeName)) {
128
- const curTypeName = node?.typeName?.right?.name;
129
- return naslTypes.TypeAnnotation.createReference(curTypeName, {
130
- typeNamespace: allTypeName,
131
- });
132
- }
133
- }
134
- return naslTypes.TypeAnnotation.createReference(typeName, {
135
- typeNamespace: null,
136
- });
137
- }
138
- throwError(`Unhandled node ${node.type}`);
139
- }
140
- else if (node.type === 'TSTypeLiteral') {
141
- return naslTypes.TypeAnnotation.createTypeAnonymousStructure(node.members.map((member) => new naslTypes.StructureProperty({
142
- name: member.key.name,
143
- typeAnnotation: transformTypeAnnotation(member.typeAnnotation.typeAnnotation),
144
- })));
145
- }
146
- else if (node.type === 'TSBooleanKeyword') {
147
- return naslTypes.TypeAnnotation.createPrimitive('Boolean');
148
- }
149
- else if (node.type === 'TSStringKeyword') {
150
- return naslTypes.TypeAnnotation.createPrimitive('String');
151
- }
152
- else if (node.type === 'TSNumberKeyword') {
153
- return naslTypes.TypeAnnotation.createPrimitive('Double');
154
- }
155
- else if (node.type === 'TSUnionType') {
156
- const union = naslTypes.TypeAnnotation.createPrimitive('Union');
157
- union.typeArguments = [];
158
- node.types.forEach((curType) => {
159
- union.typeArguments.push(transformTypeAnnotation(curType));
160
- });
161
- return union;
162
- }
163
- else {
164
- throwError(`Unhandled node ${node.type}`);
165
- }
166
- }
167
76
  // 处理参数
168
77
  function transformParam(node) {
169
78
  const typeAnnotation = node.typeAnnotation?.typeAnnotation;
170
79
  const exclude = ['event'];
171
80
  if (exclude.includes(node.name))
172
81
  return null;
173
- return new naslTypes.Param({
82
+ return new utils_1.naslTypes.Param({
174
83
  name: node.name,
175
- typeAnnotation: typeAnnotation ? transformTypeAnnotation(typeAnnotation) : null,
84
+ typeAnnotation: typeAnnotation ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation) : null,
176
85
  });
177
86
  }
87
+ // 处理生命周期函数
88
+ function transformLifecycle(node) {
89
+ const bindEvents = [];
90
+ node.properties.forEach((property) => {
91
+ const eventName = property?.key?.name?.replace(/^on/, '')?.toLowerCase();
92
+ const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
93
+ property.value.elements.forEach((element) => {
94
+ let logicName = element?.id?.name || '';
95
+ logicName = bindEvent.getLogicUniqueName(logicName);
96
+ const curLogic = transformNode2Logic(element, logicName, 'view_logic');
97
+ bindEvent.addLogic(curLogic);
98
+ });
99
+ bindEvents.push(bindEvent);
100
+ });
101
+ return bindEvents;
102
+ }
178
103
  // 处理变量
179
104
  function transformVariableDeclaration(node) {
180
105
  const declList = node?.declarations || [];
@@ -182,14 +107,14 @@ function transformVariableDeclaration(node) {
182
107
  declList?.forEach((decl) => {
183
108
  const variableName = decl.id.name;
184
109
  const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
185
- newNode = new naslTypes.Variable({
110
+ newNode = new utils_1.naslTypes.Variable({
186
111
  name: variableName,
187
- typeAnnotation: varTypeAnnotation && transformTypeAnnotation(varTypeAnnotation),
112
+ typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation),
188
113
  });
189
114
  if (decl.init) {
190
115
  if (decl.init.type !== 'ArrayExpression' && decl.init.type !== 'ObjectExpression') {
191
116
  // 变量值需要默认值还是赋值,在使用的地方处理
192
- newNode.defaultValue = new naslTypes.DefaultValue({
117
+ newNode.defaultValue = new utils_1.naslTypes.DefaultValue({
193
118
  expression: transformNode2Expression(decl.init),
194
119
  });
195
120
  }
@@ -199,7 +124,7 @@ function transformVariableDeclaration(node) {
199
124
  }
200
125
  // 处理 if
201
126
  function pushElseIf(ifNode, switchStatement) {
202
- switchStatement.cases.push(new naslTypes.SwitchCase({
127
+ switchStatement.cases.push(new utils_1.naslTypes.SwitchCase({
203
128
  test: transformNode2Expression(ifNode.test),
204
129
  consequent: !ifNode.consequent ? [] : ifNode.consequent.body.map((item) => transformNode2Expression(item)).filter((item) => !!item),
205
130
  }));
@@ -207,7 +132,7 @@ function pushElseIf(ifNode, switchStatement) {
207
132
  pushElseIf(ifNode.alternate, switchStatement);
208
133
  }
209
134
  else {
210
- switchStatement.cases.push(new naslTypes.SwitchCase({
135
+ switchStatement.cases.push(new utils_1.naslTypes.SwitchCase({
211
136
  test: undefined,
212
137
  consequent: !ifNode?.alternate ? [] : ifNode?.alternate?.body.map((item) => transformNode2Expression(item)).filter((item) => !!item),
213
138
  }));
@@ -222,7 +147,7 @@ function handleBinaryExpression(calleeName, argument) {
222
147
  divide: '/',
223
148
  remainder: '%',
224
149
  };
225
- return new naslTypes.BinaryExpression({
150
+ return new utils_1.naslTypes.BinaryExpression({
226
151
  operator: map?.[calleeName],
227
152
  left: transformNode2Expression(argument?.[0]),
228
153
  right: transformNode2Expression(argument?.[1]),
@@ -231,9 +156,9 @@ function handleBinaryExpression(calleeName, argument) {
231
156
  // 处理数据结构
232
157
  function handleNewExpression(calleeName, node, type) {
233
158
  if (calleeName === 'NewList') {
234
- return new naslTypes.NewList({
235
- typeAnnotation: naslTypes.TypeAnnotation.createGeneric('List', {
236
- typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
159
+ return new utils_1.naslTypes.NewList({
160
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createGeneric('List', {
161
+ typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
237
162
  }),
238
163
  items: node?.arguments?.[0]?.elements?.map((arg) => transformNode2Expression(arg, type)),
239
164
  });
@@ -245,9 +170,9 @@ function handleNewExpression(calleeName, node, type) {
245
170
  keys.push(transformNode2Expression(arg.key));
246
171
  values.push(transformNode2Expression(arg.value));
247
172
  });
248
- return new naslTypes.NewMap({
249
- typeAnnotation: naslTypes.TypeAnnotation.createGeneric('Map', {
250
- typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
173
+ return new utils_1.naslTypes.NewMap({
174
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createGeneric('Map', {
175
+ typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
251
176
  }),
252
177
  keys,
253
178
  values,
@@ -262,23 +187,23 @@ function handleNewExpression(calleeName, node, type) {
262
187
  if (arg.value.type === 'MemberExpression') {
263
188
  const expression = flatMemberExpression(arg.value);
264
189
  const members = flatMembers(transformNode2Expression(arg.value));
265
- rights.push(new naslTypes.SelectMembers({
190
+ rights.push(new utils_1.naslTypes.SelectMembers({
266
191
  expression: transformNode2Expression(expression[0]),
267
192
  members,
268
193
  }));
269
194
  if (arg?.value) {
270
- assignmentLines.push(new naslTypes.AssignmentLine({
195
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
271
196
  leftIndex: [0, index],
272
197
  rightIndex: [index, members.length - 1],
273
198
  }));
274
199
  }
275
200
  }
276
201
  else {
277
- rights.push(new naslTypes.SelectMembers({
202
+ rights.push(new utils_1.naslTypes.SelectMembers({
278
203
  expression: transformNode2Expression(arg.value)
279
204
  }));
280
205
  if (arg?.value) {
281
- assignmentLines.push(new naslTypes.AssignmentLine({
206
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
282
207
  leftIndex: [0, index],
283
208
  rightIndex: [index],
284
209
  }));
@@ -288,10 +213,10 @@ function handleNewExpression(calleeName, node, type) {
288
213
  const parameters = node?.typeParameters?.params?.[0] || {};
289
214
  if (parameters && parameters?.type === 'TSTypeReference' && parameters?.typeName?.type === 'TSQualifiedName') {
290
215
  const { left, right } = parameters?.typeName || {};
291
- const typeNamespace = (0, generator_1.default)(left)?.code;
216
+ const typeNamespace = (0, utils_1.generate)(left)?.code;
292
217
  const typeName = right?.name;
293
- return new naslTypes.NewComposite({
294
- typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
218
+ return new utils_1.naslTypes.NewComposite({
219
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
295
220
  typeNamespace,
296
221
  typeName
297
222
  }),
@@ -301,8 +226,8 @@ function handleNewExpression(calleeName, node, type) {
301
226
  });
302
227
  }
303
228
  const typeName = parameters?.typeName?.name;
304
- return new naslTypes.NewComposite({
305
- typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
229
+ return new utils_1.naslTypes.NewComposite({
230
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
306
231
  typeNamespace: 'app.dataSources.defaultDS.entities',
307
232
  typeName
308
233
  }),
@@ -320,23 +245,23 @@ function handleNewExpression(calleeName, node, type) {
320
245
  if (arg.value.type === 'MemberExpression') {
321
246
  const expression = flatMemberExpression(arg.value);
322
247
  const members = flatMembers(transformNode2Expression(arg.value));
323
- rights.push(new naslTypes.SelectMembers({
248
+ rights.push(new utils_1.naslTypes.SelectMembers({
324
249
  expression: transformNode2Expression(expression[0]),
325
250
  members,
326
251
  }));
327
252
  if (arg?.value) {
328
- assignmentLines.push(new naslTypes.AssignmentLine({
253
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
329
254
  leftIndex: [0, index],
330
255
  rightIndex: [index, members.length - 1],
331
256
  }));
332
257
  }
333
258
  }
334
259
  else {
335
- rights.push(new naslTypes.SelectMembers({
260
+ rights.push(new utils_1.naslTypes.SelectMembers({
336
261
  expression: transformNode2Expression(arg.value)
337
262
  }));
338
263
  if (arg?.value) {
339
- assignmentLines.push(new naslTypes.AssignmentLine({
264
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
340
265
  leftIndex: [0, index],
341
266
  rightIndex: [index],
342
267
  }));
@@ -346,10 +271,10 @@ function handleNewExpression(calleeName, node, type) {
346
271
  const parameters = node?.typeParameters?.params?.[0] || {};
347
272
  if (parameters && parameters?.type === 'TSTypeReference' && parameters?.typeName?.type === 'TSQualifiedName') {
348
273
  const { left, right } = parameters?.typeName || {};
349
- const typeNamespace = (0, generator_1.default)(left)?.code;
274
+ const typeNamespace = (0, utils_1.generate)(left)?.code;
350
275
  const typeName = right?.name;
351
- return new naslTypes.NewComposite({
352
- typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
276
+ return new utils_1.naslTypes.NewComposite({
277
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
353
278
  typeNamespace,
354
279
  typeName
355
280
  }),
@@ -359,8 +284,8 @@ function handleNewExpression(calleeName, node, type) {
359
284
  });
360
285
  }
361
286
  const typeName = parameters?.typeName?.name;
362
- return new naslTypes.NewComposite({
363
- typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
287
+ return new utils_1.naslTypes.NewComposite({
288
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
364
289
  typeNamespace: 'app.structures',
365
290
  typeName
366
291
  }),
@@ -379,35 +304,35 @@ function handleNewExpression(calleeName, node, type) {
379
304
  if (arg.value.type === 'MemberExpression') {
380
305
  const expression = flatMemberExpression(arg.value);
381
306
  const members = flatMembers(transformNode2Expression(arg.value));
382
- rights.push(new naslTypes.SelectMembers({
307
+ rights.push(new utils_1.naslTypes.SelectMembers({
383
308
  expression: transformNode2Expression(expression[0]),
384
309
  members,
385
310
  }));
386
311
  if (arg?.value) {
387
- assignmentLines.push(new naslTypes.AssignmentLine({
312
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
388
313
  leftIndex: [0, index],
389
314
  rightIndex: [index, members.length - 1],
390
315
  }));
391
316
  }
392
317
  }
393
318
  else {
394
- rights.push(new naslTypes.SelectMembers({
319
+ rights.push(new utils_1.naslTypes.SelectMembers({
395
320
  expression: transformNode2Expression(arg.value)
396
321
  }));
397
322
  if (arg?.value) {
398
- assignmentLines.push(new naslTypes.AssignmentLine({
323
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
399
324
  leftIndex: [0, index],
400
325
  rightIndex: [index],
401
326
  }));
402
327
  }
403
328
  }
404
- structureProperties.push(new naslTypes.StructureProperty({
329
+ structureProperties.push(new utils_1.naslTypes.StructureProperty({
405
330
  name: arg?.key?.name,
406
331
  typeAnnotation: null
407
332
  }));
408
333
  });
409
- return new naslTypes.NewComposite({
410
- typeAnnotation: naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
334
+ return new utils_1.naslTypes.NewComposite({
335
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
411
336
  properties,
412
337
  rights,
413
338
  assignmentLines
@@ -415,6 +340,13 @@ function handleNewExpression(calleeName, node, type) {
415
340
  }
416
341
  return node;
417
342
  }
343
+ function fixExpression(arg, type) {
344
+ let expression = transformNode2Expression(arg, type);
345
+ if (expression?.concept === 'Identifier' && expression?.name === 'undefined') {
346
+ expression = undefined;
347
+ }
348
+ return expression;
349
+ }
418
350
  // 处理表达式
419
351
  function transformNode2Expression(node, type) {
420
352
  if (!node)
@@ -429,57 +361,57 @@ function transformNode2Expression(node, type) {
429
361
  }
430
362
  else if (node.type === 'CallExpression') {
431
363
  const callee = flatMemberExpression(node.callee);
432
- const calleeName = (0, generator_1.default)(node.callee).code;
364
+ const calleeName = (0, utils_1.generate)(node.callee).code;
433
365
  // console.log('lemon ~~~ CallExpression', node, callee, calleeName);
434
366
  if (/^\$refs\./.test(calleeName)) {
435
- return new naslTypes.CallLogic({
367
+ return new utils_1.naslTypes.CallLogic({
436
368
  calleeNamespace: `elements.${callee[1].name}.logics`,
437
369
  calleeName: callee[2].name,
438
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
439
- expression: transformNode2Expression(arg, type),
370
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
371
+ expression: fixExpression(arg, type),
440
372
  })),
441
373
  });
442
374
  }
443
375
  if (callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity')) {
444
- const entityName = callee[0].name.replace(/Entity$/, '');
445
- return new naslTypes.CallLogic({
376
+ const entityName = callee[0].name.replace(/Entity/, '');
377
+ return new utils_1.naslTypes.CallLogic({
446
378
  calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
447
379
  calleeName: callee[1].name,
448
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
380
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
449
381
  expression: transformNode2Expression(arg, type),
450
382
  })),
451
383
  });
452
384
  }
453
385
  if (calleeName === 'nasl.util.consoleLog' || calleeName === 'console.log') {
454
- return new naslTypes.CallLogic({
386
+ return new utils_1.naslTypes.CallLogic({
455
387
  calleeNamespace: 'nasl.util',
456
388
  calleeName: 'consoleLog',
457
389
  shortcut: true,
458
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
390
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
459
391
  expression: transformNode2Expression(arg, type),
460
392
  })),
461
393
  });
462
394
  }
463
395
  if (calleeName.startsWith('nasl.logging.')) {
464
- return new naslTypes.CallLogic({
396
+ return new utils_1.naslTypes.CallLogic({
465
397
  calleeNamespace: 'nasl.logging',
466
398
  calleeName: callee[2].name,
467
399
  shortcut: true,
468
- arguments: node.arguments.map((arg) => new naslTypes.Argument({
400
+ arguments: node.arguments.map((arg) => new utils_1.naslTypes.Argument({
469
401
  expression: transformNode2Expression(arg, type),
470
402
  })),
471
403
  });
472
404
  }
473
405
  if (calleeName === 'nasl.util.jsonSerialize' || calleeName === 'nasl.util.jsonDeserialize') {
474
406
  const curCalleeName = node.callee.property.name;
475
- return new naslTypes.CallLogic({
407
+ return new utils_1.naslTypes.CallLogic({
476
408
  calleeNamespace: 'nasl.util',
477
409
  calleeName: curCalleeName,
478
410
  shortcut: true,
479
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
411
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
480
412
  expression: transformNode2Expression(arg, type),
481
413
  })),
482
- typeArguments: node?.typeParameters?.params.map((curType) => transformTypeAnnotation({ ...curType })),
414
+ typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType })),
483
415
  });
484
416
  }
485
417
  ;
@@ -501,15 +433,15 @@ function transformNode2Expression(node, type) {
501
433
  if (['NewList', 'NewMap', 'NewEntity', 'NewStructure', 'NewAnonymousStructure'].includes(curCalleeName)) {
502
434
  return handleNewExpression(curCalleeName, node, type);
503
435
  }
504
- const nodeElement = new naslTypes.CallFunction({
436
+ const nodeElement = new utils_1.naslTypes.CallFunction({
505
437
  calleeNamespace: 'nasl.util',
506
438
  calleeName: curCalleeName,
507
- arguments: argument.map((arg, index) => new naslTypes.Argument({
439
+ arguments: argument.map((arg, index) => new utils_1.naslTypes.Argument({
508
440
  expression: transformNode2Expression(arg, type),
509
441
  keyword: `str${index + 1}`,
510
442
  })),
511
- typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
512
- // typeArguments: node?.typeParameters?.params.map((curType: any) => transformTypeAnnotation({ ...curType, typeNamespace })),
443
+ typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
444
+ // typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
513
445
  });
514
446
  return nodeElement;
515
447
  }
@@ -519,15 +451,26 @@ function transformNode2Expression(node, type) {
519
451
  const nsArr = namespace.split('.').map((item) => item.replace(/_view$/, ''));
520
452
  const pageType = nsArr.shift();
521
453
  const viewName = nsArr.pop();
522
- return new naslTypes.Destination({
454
+ const newArguments = node?.arguments?.slice(1);
455
+ let argument = [];
456
+ if (newArguments?.[0]?.type === 'ObjectExpression') {
457
+ argument = newArguments?.[0]?.properties?.map((property) => new utils_1.naslTypes.Argument({
458
+ keyword: property?.key?.name,
459
+ expression: fixExpression(property?.value, type),
460
+ }));
461
+ }
462
+ else {
463
+ argument = node.arguments.slice(1).map((arg) => new utils_1.naslTypes.Argument({
464
+ expression: fixExpression(arg, type),
465
+ }));
466
+ }
467
+ return new utils_1.naslTypes.Destination({
523
468
  viewNamespace: `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`,
524
469
  viewName,
525
- arguments: node.arguments.slice(1).map((arg) => new naslTypes.Argument({
526
- expression: transformNode2Expression(arg, type),
527
- })),
470
+ arguments: argument,
528
471
  });
529
472
  }
530
- return new naslTypes.CallLogic({
473
+ return new utils_1.naslTypes.CallLogic({
531
474
  calleeNamespace: 'nasl.ui',
532
475
  calleeName: callee[2].name,
533
476
  shortcut: true,
@@ -536,25 +479,25 @@ function transformNode2Expression(node, type) {
536
479
  * @param node
537
480
  * @returns
538
481
  */
539
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
482
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
540
483
  expression: transformNode2Expression(arg, type),
541
484
  })),
542
485
  });
543
486
  }
544
487
  if (calleeName.endsWith('.map')) {
545
- return new naslTypes.CallFunction({
488
+ return new utils_1.naslTypes.CallFunction({
546
489
  calleeNamespace: 'nasl.util',
547
490
  calleeName: 'ListTransform',
548
- arguments: [new naslTypes.Argument({
491
+ arguments: [new utils_1.naslTypes.Argument({
549
492
  expression: transformNode2Expression(node.callee.object, type),
550
- }), ...node?.arguments?.map((arg) => new naslTypes.Argument({
493
+ }), ...node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
551
494
  expression: transformNode2Expression(arg, type),
552
495
  }))],
553
496
  });
554
497
  }
555
498
  if (calleeName === 'PAGINATE') {
556
499
  const newCallee = node?.arguments || [];
557
- return new naslTypes.Paginate({
500
+ return new utils_1.naslTypes.Paginate({
558
501
  list: newCallee?.[0] && transformNode2Expression(newCallee?.[0], type),
559
502
  page: newCallee?.[1] && transformNode2Expression(newCallee?.[1], type),
560
503
  size: newCallee?.[2] && transformNode2Expression(newCallee?.[2], type),
@@ -563,15 +506,15 @@ function transformNode2Expression(node, type) {
563
506
  if (calleeName === 'ForEach') {
564
507
  const newCallee = node.arguments;
565
508
  const arrowFunction = node.arguments[3];
566
- const nodeElement = new naslTypes.ForEachStatement({
509
+ const nodeElement = new utils_1.naslTypes.ForEachStatement({
567
510
  each: transformNode2Expression(newCallee[0], type),
568
511
  start: transformNode2Expression(newCallee[1], type),
569
512
  end: transformNode2Expression(newCallee[2], type),
570
513
  item: transformParam(arrowFunction.params[0]),
571
- index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new naslTypes.Param({
572
- name: 'index', typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Long'),
514
+ index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
515
+ name: 'index', typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
573
516
  }),
574
- body: arrowFunction.body.body.map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
517
+ body: arrowFunction.body.body.map((item) => transformNode2Expression(item)).filter((item) => !!item && item?.concept !== 'Variable'),
575
518
  });
576
519
  return nodeElement;
577
520
  }
@@ -580,15 +523,15 @@ function transformNode2Expression(node, type) {
580
523
  if (curCalleeName === 'forEach') {
581
524
  const newCallee = node.callee.object;
582
525
  const arrowFunction = node.arguments[0];
583
- const nodeElement = new naslTypes.ForEachStatement({
526
+ const nodeElement = new utils_1.naslTypes.ForEachStatement({
584
527
  each: transformNode2Expression(newCallee.callee.object, type),
585
528
  start: transformNode2Expression(newCallee?.arguments?.[0], type),
586
529
  end: transformNode2Expression(newCallee?.arguments?.[1], type),
587
530
  item: transformParam(arrowFunction.params[0]),
588
- index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new naslTypes.Param({
589
- name: 'index', typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Long'),
531
+ index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
532
+ name: 'index', typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
590
533
  }),
591
- body: arrowFunction.body.body.map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
534
+ body: arrowFunction.body.body.map((item) => transformNode2Expression(item)).filter((item) => !!item && item?.concept !== 'Variable'),
592
535
  });
593
536
  return nodeElement;
594
537
  }
@@ -597,89 +540,89 @@ function transformNode2Expression(node, type) {
597
540
  return handleBinaryExpression(calleeName, node?.arguments);
598
541
  }
599
542
  else if (calleeName === 'alert') {
600
- return new naslTypes.CallLogic({
543
+ return new utils_1.naslTypes.CallLogic({
601
544
  calleeNamespace: 'nasl.ui',
602
545
  calleeName: 'showMessage',
603
546
  shortcut: true,
604
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
547
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
605
548
  expression: transformNode2Expression(arg, type),
606
549
  })),
607
550
  });
608
551
  }
609
552
  else if (/^app.dataSources|app.logics/.test(calleeName)) {
610
553
  if (calleeName?.includes('.entities.')) {
611
- const calleeNamespace = (0, generator_1.default)(node?.callee?.object?.object)?.code;
612
- const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
613
- return new naslTypes.CallLogic({
554
+ const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
555
+ const entityName = node?.callee?.object?.property?.name?.replace(/Entity/, '');
556
+ return new utils_1.naslTypes.CallLogic({
614
557
  calleeNamespace: `${calleeNamespace}.${entityName}.logics`,
615
558
  calleeName: node?.callee?.property?.name,
616
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
559
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
617
560
  expression: transformNode2Expression(arg, type),
618
561
  })),
619
562
  });
620
563
  }
621
- return new naslTypes.CallLogic({
622
- calleeNamespace: (0, generator_1.default)(node.callee.object).code,
564
+ return new utils_1.naslTypes.CallLogic({
565
+ calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
623
566
  calleeName: callee[callee.length - 1].name,
624
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
567
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
625
568
  expression: transformNode2Expression(arg, type),
626
569
  })),
627
570
  });
628
571
  }
629
572
  else if (callee.length === 1) {
630
573
  if (calleeName.startsWith('viewLogic_')) {
631
- return new naslTypes.CallLogic({
574
+ return new utils_1.naslTypes.CallLogic({
632
575
  calleeNamespace: '',
633
576
  calleeName: calleeName.slice('viewLogic_'.length),
634
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
577
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
635
578
  expression: transformNode2Expression(arg, type),
636
579
  })),
637
580
  });
638
581
  }
639
582
  if (calleeName === 'FROM') {
640
583
  // TODO
641
- return new naslTypes.CallLogic({
584
+ return new utils_1.naslTypes.CallLogic({
642
585
  calleeNamespace: `app.logics`,
643
586
  calleeName,
644
587
  arguments: [],
645
588
  });
646
589
  }
647
- return new naslTypes.CallLogic({
648
- calleeNamespace: `app.logics`,
590
+ return new utils_1.naslTypes.CallLogic({
591
+ calleeNamespace: ``,
649
592
  calleeName,
650
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
593
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
651
594
  expression: transformNode2Expression(arg, type),
652
595
  })),
653
596
  });
654
597
  }
655
598
  else if (/interfaces/.test(calleeName)) {
656
- return new naslTypes.CallInterface({
657
- calleeNamespace: (0, generator_1.default)(node.callee.object).code,
599
+ return new utils_1.naslTypes.CallInterface({
600
+ calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
658
601
  calleeName: callee[callee.length - 1].name,
659
- arguments: node?.arguments?.map((arg) => arg?.properties?.map((item) => new naslTypes.Argument({
602
+ arguments: node?.arguments?.map((arg) => arg?.properties?.map((item) => new utils_1.naslTypes.Argument({
660
603
  keyword: item?.key?.name,
661
604
  expression: transformNode2Expression(item?.value, type),
662
- }))).flat(),
605
+ })) || []).flat() || [],
663
606
  });
664
607
  }
665
608
  else if (/connector./.test(calleeName)) {
666
- const flatCalleeKey = (0, generator_1.default)(node?.callee)?.code;
609
+ const flatCalleeKey = (0, utils_1.generate)(node?.callee)?.code;
667
610
  const [, calleeConnectionName, calleeNamespace, calleeFunName] = flatCalleeKey?.match(/^(\w+)\.([\w.]+)\.(\w+)$/);
668
- return new naslTypes.CallConnector({
611
+ return new utils_1.naslTypes.CallConnector({
669
612
  calleeConnectionName,
670
613
  calleeNamespace,
671
614
  calleeName: calleeFunName,
672
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
615
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
673
616
  expression: transformNode2Expression(arg, type),
674
617
  })),
675
618
  });
676
619
  }
677
620
  else if (/extensions./.test(calleeName)) {
678
- return new naslTypes.CallLogic({
679
- calleeNamespace: (0, generator_1.default)(node?.callee?.object)?.code,
621
+ return new utils_1.naslTypes.CallLogic({
622
+ calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
680
623
  calleeName: callee?.[callee?.length - 1]?.name,
681
624
  handleError: true,
682
- arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
625
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
683
626
  expression: transformNode2Expression(arg, type),
684
627
  })),
685
628
  });
@@ -688,16 +631,16 @@ function transformNode2Expression(node, type) {
688
631
  // NOTE: 适用于 if else
689
632
  const newCallee = node.callee.body.body;
690
633
  if (newCallee[newCallee.length - 1].argument?.callee?.name === '__MatchExpressionFuntion') {
691
- const match = new naslTypes.Match({
634
+ const match = new utils_1.naslTypes.Match({
692
635
  expression: transformNode2Expression(newCallee[0], type),
693
636
  isExpression: type !== 'logic',
694
- cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new naslTypes.MatchCase({
637
+ cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new utils_1.naslTypes.MatchCase({
695
638
  patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNode2Expression(_case.test, type)),
696
639
  body: _case.consequent.body.filter((item) => item.type !== 'BreakStatement').map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
697
640
  })),
698
641
  });
699
642
  if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
700
- match.cases.push(new naslTypes.MatchCase({
643
+ match.cases.push(new utils_1.naslTypes.MatchCase({
701
644
  patterns: [],
702
645
  body: [],
703
646
  }));
@@ -708,7 +651,7 @@ function transformNode2Expression(node, type) {
708
651
  }
709
652
  if (case_.patterns.length && case_.patterns[0].concept === 'MemberExpression') {
710
653
  case_.isMatchedTypeEnumable = true;
711
- case_.patterns[0] = new naslTypes.MemberExpression({
654
+ case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
712
655
  object: {
713
656
  concept: 'Identifier',
714
657
  name: case_.patterns[0].object.property.name,
@@ -729,15 +672,24 @@ function transformNode2Expression(node, type) {
729
672
  const switchStatement = transformNode2Expression(newCallee[0].body.body[0], type);
730
673
  return switchStatement;
731
674
  }
732
- throwError(`Unhandled ArrowFunctionExpression node ${node.type}`);
675
+ (0, utils_1.throwError)(`Unhandled ArrowFunctionExpression node ${node.type}`);
676
+ }
677
+ else if (/nasl.auth./.test(calleeName)) {
678
+ return new utils_1.naslTypes.CallLogic({
679
+ calleeNamespace: 'nasl.auth',
680
+ calleeName: callee[callee.length - 1].name,
681
+ arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
682
+ expression: transformNode2Expression(arg, type),
683
+ })),
684
+ });
733
685
  }
734
686
  else {
735
- throwError(`Unhandled node ${callee.map((item) => item.name).join('.')} ${node.type}`);
687
+ (0, utils_1.throwError)(`Unhandled node ${callee.map((item) => item.name).join('.')} ${node.type}`);
736
688
  }
737
689
  }
738
690
  else if (node.type === 'IfStatement') {
739
691
  if (node.alternate && node.alternate.type === 'IfStatement') {
740
- const switchStatement = new naslTypes.SwitchStatement({
692
+ const switchStatement = new utils_1.naslTypes.SwitchStatement({
741
693
  cases: [],
742
694
  });
743
695
  pushElseIf(node, switchStatement);
@@ -745,7 +697,7 @@ function transformNode2Expression(node, type) {
745
697
  }
746
698
  let consequentIndex;
747
699
  let alternateIndex;
748
- const naslNode = new naslTypes.IfStatement({
700
+ const naslNode = new utils_1.naslTypes.IfStatement({
749
701
  test: transformNode2Expression(node.test, type),
750
702
  consequent: !node.consequent ? [] : node.consequent.body.map((item, index) => {
751
703
  if (item?.type === 'ReturnStatement') {
@@ -767,30 +719,30 @@ function transformNode2Expression(node, type) {
767
719
  }).filter((item) => !!item),
768
720
  });
769
721
  if (consequentIndex !== undefined) {
770
- naslNode?.consequent?.splice(consequentIndex + 1, 0, new naslTypes.End());
722
+ naslNode?.consequent?.splice(consequentIndex + 1, 0, new utils_1.naslTypes.End());
771
723
  }
772
724
  if (alternateIndex !== undefined) {
773
- naslNode?.alternate?.splice(alternateIndex + 1, 0, new naslTypes.End());
725
+ naslNode?.alternate?.splice(alternateIndex + 1, 0, new utils_1.naslTypes.End());
774
726
  }
775
727
  return naslNode;
776
728
  }
777
729
  else if (node.type === 'WhileStatement') {
778
- return new naslTypes.WhileStatement({
730
+ return new utils_1.naslTypes.WhileStatement({
779
731
  test: transformNode2Expression(node.test, type),
780
732
  body: node.body.body.map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
781
733
  });
782
734
  }
783
735
  else if (node.type === 'SwitchStatement') {
784
- const match = new naslTypes.Match({
736
+ const match = new utils_1.naslTypes.Match({
785
737
  expression: transformNode2Expression(node.discriminant, type),
786
738
  isExpression: type !== 'logic',
787
- cases: node.cases.map((_case) => new naslTypes.MatchCase({
739
+ cases: node.cases.map((_case) => new utils_1.naslTypes.MatchCase({
788
740
  patterns: !_case.test ? [] : [transformNode2Expression(_case.test, type)],
789
741
  body: _case.consequent.filter((item) => item.type !== 'BreakStatement').map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
790
742
  })),
791
743
  });
792
744
  if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
793
- match.cases.push(new naslTypes.MatchCase({
745
+ match.cases.push(new utils_1.naslTypes.MatchCase({
794
746
  patterns: [],
795
747
  body: [],
796
748
  }));
@@ -808,40 +760,59 @@ function transformNode2Expression(node, type) {
808
760
  }
809
761
  else if (node.type === 'MemberExpression') {
810
762
  const callee = flatMemberExpression(node);
811
- const calleeName = (0, generator_1.default)(node)?.code;
763
+ const calleeName = (0, utils_1.generate)(node)?.code;
812
764
  if (calleeName?.includes('app.enums')) {
813
765
  const name = callee?.[3]?.value || callee?.[3]?.name || callee?.[3]?.value;
814
- return new naslTypes.MemberExpression({
815
- object: new naslTypes.Identifier({
766
+ return new utils_1.naslTypes.MemberExpression({
767
+ object: new utils_1.naslTypes.Identifier({
816
768
  namespace: 'app.enums',
817
769
  name: callee?.[2]?.name,
818
770
  }),
819
- property: new naslTypes.Identifier({
771
+ property: new utils_1.naslTypes.Identifier({
820
772
  name: String(name),
821
773
  }),
822
774
  });
823
775
  }
776
+ if (calleeName?.includes('nasl.auth.')) {
777
+ return new utils_1.naslTypes.MemberExpression({
778
+ object: new utils_1.naslTypes.Identifier({
779
+ namespace: 'nasl.auth',
780
+ name: callee?.[2]?.name,
781
+ }),
782
+ property: new utils_1.naslTypes.Identifier({
783
+ name: callee?.[3]?.name,
784
+ }),
785
+ });
786
+ }
787
+ const regex = /^(app\..+?)\.variables\.(.+)$/;
788
+ if (regex.test(calleeName)) {
789
+ const [, namespace, variableName] = calleeName.match(regex);
790
+ return new utils_1.naslTypes.Identifier({
791
+ name: String(variableName),
792
+ namespace: `${namespace}.variables`
793
+ });
794
+ }
824
795
  if (node.property.type === 'NumericLiteral') {
825
- return new naslTypes.CallFunction({
796
+ return new utils_1.naslTypes.CallFunction({
826
797
  calleeNamespace: 'nasl.util',
827
798
  calleeName: 'Get',
828
799
  arguments: [
829
- new naslTypes.Argument({
800
+ new utils_1.naslTypes.Argument({
830
801
  expression: transformNode2Expression(node.object, type),
831
802
  }),
832
- new naslTypes.Argument({
803
+ new utils_1.naslTypes.Argument({
833
804
  expression: transformNode2Expression(node.property, type),
834
805
  }),
835
806
  ],
836
807
  });
837
808
  }
838
- return new naslTypes.MemberExpression({
809
+ return new utils_1.naslTypes.MemberExpression({
839
810
  object: transformNode2Expression(node.object, type),
840
811
  property: transformNode2Expression(node.property, type),
841
812
  });
842
813
  }
843
814
  else if (node.type === 'Identifier') {
844
- return new naslTypes.Identifier({
815
+ return new utils_1.naslTypes.Identifier({
845
816
  name: node.name,
846
817
  });
847
818
  }
@@ -851,16 +822,16 @@ function transformNode2Expression(node, type) {
851
822
  else if (node.type === 'AssignmentExpression') {
852
823
  if (node.operator === '+=' || node.operator === '-=') {
853
824
  if (type === 'logic') {
854
- return new naslTypes.Assignment({
825
+ return new utils_1.naslTypes.Assignment({
855
826
  left: transformNode2Expression(node.left, type),
856
- right: new naslTypes.BinaryExpression({
827
+ right: new utils_1.naslTypes.BinaryExpression({
857
828
  operator: node.operator[0],
858
829
  left: transformNode2Expression(node.left, type),
859
830
  right: transformNode2Expression(node.right, type),
860
831
  }),
861
832
  });
862
833
  }
863
- return new naslTypes.BinaryExpression({
834
+ return new utils_1.naslTypes.BinaryExpression({
864
835
  operator: node.operator[0],
865
836
  left: transformNode2Expression(node.left, type),
866
837
  right: transformNode2Expression(node.right, type),
@@ -869,44 +840,44 @@ function transformNode2Expression(node, type) {
869
840
  if (type !== 'logic') {
870
841
  return transformNode2Expression(node.right, type);
871
842
  }
872
- return new naslTypes.Assignment({
843
+ return new utils_1.naslTypes.Assignment({
873
844
  left: transformNode2Expression(node.left, type),
874
845
  right: transformNode2Expression(node.right, type),
875
846
  });
876
847
  }
877
848
  else if (node.type === 'NewExpression') {
878
- const calleeName = (0, generator_1.default)(node.callee).code;
849
+ const calleeName = (0, utils_1.generate)(node.callee).code;
879
850
  if (['Boolean', 'Integer', 'Double', 'Decimal', 'Long'].includes(calleeName)) {
880
851
  return transformNode2Expression(node.arguments[0], type);
881
852
  }
882
- throwError(`Unhandled node ${node.type}`);
853
+ (0, utils_1.throwError)(`Unhandled node ${node.type}`);
883
854
  }
884
855
  else if (node.type === 'ArrowFunctionExpression') {
885
- return new naslTypes.AnonymousFunction({
856
+ return new utils_1.naslTypes.AnonymousFunction({
886
857
  params: node.params.map((param) => transformParam(param)),
887
858
  body: transformNode2Expression(node.body, type),
888
859
  });
889
860
  }
890
861
  else if (node.type === 'BooleanLiteral') {
891
- return new naslTypes.BooleanLiteral({
862
+ return new utils_1.naslTypes.BooleanLiteral({
892
863
  value: String(node.value),
893
864
  });
894
865
  }
895
866
  else if (node.type === 'StringLiteral') {
896
- return new naslTypes.StringLiteral({
867
+ return new utils_1.naslTypes.StringLiteral({
897
868
  value: node.value,
898
869
  });
899
870
  }
900
871
  else if (node.type === 'NumericLiteral') {
901
- const literal = new naslTypes.NumericLiteral({
872
+ const literal = new utils_1.naslTypes.NumericLiteral({
902
873
  value: String(node.value),
903
- typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Integer'),
874
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
904
875
  });
905
876
  literal.typeAnnotation.typeName = literal.changeType(String(node.value));
906
877
  return literal;
907
878
  }
908
879
  else if (node.type === 'NullLiteral') {
909
- return new naslTypes.NullLiteral();
880
+ return new utils_1.naslTypes.NullLiteral();
910
881
  }
911
882
  else if (node.type === 'TemplateLiteral') {
912
883
  const expressions = [...node.expressions, ...node.quasis.map((element) => ({
@@ -916,7 +887,7 @@ function transformNode2Expression(node, type) {
916
887
  end: element.end,
917
888
  }))];
918
889
  expressions.sort((a, b) => a.start - b.start);
919
- return new naslTypes.StringInterpolation({
890
+ return new utils_1.naslTypes.StringInterpolation({
920
891
  expressions: expressions.map((item) => transformNode2Expression(item, type)),
921
892
  });
922
893
  }
@@ -926,17 +897,17 @@ function transformNode2Expression(node, type) {
926
897
  if (node.operator === '!==')
927
898
  node.operator = '!=';
928
899
  if (['+', '-', '*', '/', '%', '==', '!=', '>', '<', '>=', '<=', '&&', '||', 'startwith', 'endwith', 'like', 'in'].includes(node.operator)) {
929
- return new naslTypes.BinaryExpression({
900
+ return new utils_1.naslTypes.BinaryExpression({
930
901
  operator: node.operator,
931
902
  left: transformNode2Expression(node.left, type),
932
903
  right: transformNode2Expression(node.right, type),
933
904
  });
934
905
  }
935
- throwError(`Unhandled node ${node.type}`);
906
+ (0, utils_1.throwError)(`Unhandled node ${node.type}`);
936
907
  }
937
908
  else if (node.type === 'UnaryExpression') {
938
909
  if (['!'].includes(node.operator)) {
939
- return new naslTypes.UnaryExpression({
910
+ return new utils_1.naslTypes.UnaryExpression({
940
911
  operator: node.operator,
941
912
  argument: transformNode2Expression(node.argument, type),
942
913
  });
@@ -947,18 +918,18 @@ function transformNode2Expression(node, type) {
947
918
  value: -node.argument.value,
948
919
  }, type);
949
920
  }
950
- throwError(`Unhandled node ${node.type}`);
921
+ (0, utils_1.throwError)(`Unhandled node ${node.type}`);
951
922
  }
952
923
  else if (node.type === 'UpdateExpression') {
953
924
  if (node.operator === '++' || node.operator === '--') {
954
- return new naslTypes.Assignment({
925
+ return new utils_1.naslTypes.Assignment({
955
926
  left: transformNode2Expression(node.argument, type),
956
- right: new naslTypes.BinaryExpression({
927
+ right: new utils_1.naslTypes.BinaryExpression({
957
928
  operator: node.operator[0],
958
929
  left: transformNode2Expression(node.argument, type),
959
- right: new naslTypes.NumericLiteral({
930
+ right: new utils_1.naslTypes.NumericLiteral({
960
931
  value: '1',
961
- typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Integer'),
932
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
962
933
  }),
963
934
  }),
964
935
  });
@@ -966,11 +937,11 @@ function transformNode2Expression(node, type) {
966
937
  }
967
938
  else if (node.type === 'ReturnStatement') {
968
939
  if (node?.ends) {
969
- return new naslTypes.End();
940
+ return new utils_1.naslTypes.End();
970
941
  }
971
942
  }
972
943
  else if (node.type === 'EmptyStatement') {
973
- return node.leadingComments && new naslTypes.Comment({
944
+ return node.leadingComments && new utils_1.naslTypes.Comment({
974
945
  value: String(node.leadingComments[0].value),
975
946
  });
976
947
  }
@@ -987,68 +958,95 @@ function transformNode2Expression(node, type) {
987
958
  if (arg.value.type === 'MemberExpression') {
988
959
  const expression = flatMemberExpression(arg.value);
989
960
  const members = flatMembers(transformNode2Expression(arg.value, type));
990
- rights.push(new naslTypes.SelectMembers({
961
+ rights.push(new utils_1.naslTypes.SelectMembers({
991
962
  expression: transformNode2Expression(expression[0]),
992
963
  members,
993
964
  }));
994
965
  if (arg?.value) {
995
- assignmentLines.push(new naslTypes.AssignmentLine({
966
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
996
967
  leftIndex: [0, index],
997
968
  rightIndex: [index, members.length - 1],
998
969
  }));
999
970
  }
1000
971
  }
1001
972
  else {
1002
- rights.push(new naslTypes.SelectMembers({
973
+ rights.push(new utils_1.naslTypes.SelectMembers({
1003
974
  expression: transformNode2Expression(arg?.value, type)
1004
975
  }));
1005
976
  if (arg?.value) {
1006
- assignmentLines.push(new naslTypes.AssignmentLine({
977
+ assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
1007
978
  leftIndex: [0, index],
1008
979
  rightIndex: [index],
1009
980
  }));
1010
981
  }
1011
982
  }
1012
- structureProperties.push(new naslTypes.StructureProperty({
983
+ structureProperties.push(new utils_1.naslTypes.StructureProperty({
1013
984
  name: arg?.key?.name,
1014
985
  typeAnnotation: null
1015
986
  }));
1016
987
  });
1017
- return new naslTypes.NewComposite({
1018
- typeAnnotation: naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
988
+ return new utils_1.naslTypes.NewComposite({
989
+ typeAnnotation: utils_1.naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
1019
990
  properties,
1020
991
  rights,
1021
992
  assignmentLines
1022
993
  });
1023
994
  }
1024
995
  else {
1025
- throwError(`Unhandled node ${node.type}`);
996
+ (0, utils_1.throwError)(`Unhandled node ${node.type}`);
1026
997
  }
1027
998
  }
1028
999
  // 处理逻辑
1029
- function transformNode2Logic(node, name) {
1000
+ function transformNode2Logic(node, name, type) {
1030
1001
  const parameters = node.params;
1031
1002
  const statements = node.body.body;
1032
- const curLogic = new naslTypes.Logic({ name: name ?? node.id.name });
1033
- parameters.forEach((item) => {
1034
- const param = transformParam(item);
1035
- if (param && param.name !== 'event' && !curLogic.params.find((_) => _.name === param.name))
1036
- curLogic.addParam(param);
1037
- });
1038
- statements.forEach((item) => {
1003
+ const curLogic = new utils_1.naslTypes.Logic({ name: name ?? node.id.name });
1004
+ if (type !== 'event_logic') {
1005
+ parameters.forEach((item) => {
1006
+ const param = transformParam(item);
1007
+ if (param && param.name !== 'event' && !curLogic.params.find((_) => _.name === param.name))
1008
+ curLogic.addParam(param);
1009
+ });
1010
+ }
1011
+ statements?.forEach((item) => {
1039
1012
  if (item.type === 'ReturnStatement' && item?.argument) {
1040
- if (!curLogic.returns.length) {
1041
- curLogic.returns.push(new naslTypes.Return({
1042
- name: 'result',
1043
- }));
1013
+ if (type === 'view_logic') {
1014
+ if (item.argument?.type === 'Identifier') {
1015
+ if (!curLogic.returns.length) {
1016
+ const curVariable = curLogic?.variables?.find((it) => it.name === item?.argument?.name);
1017
+ if (curVariable) {
1018
+ curLogic.variables = curLogic?.variables?.filter((it) => it.name !== item?.argument?.name);
1019
+ curLogic.addReturn(curVariable);
1020
+ }
1021
+ }
1022
+ }
1023
+ else {
1024
+ if (!curLogic.returns.length) {
1025
+ curLogic.returns.push(new utils_1.naslTypes.Return({
1026
+ name: 'result',
1027
+ }));
1028
+ }
1029
+ const logicItem = new utils_1.naslTypes.Assignment({
1030
+ left: new utils_1.naslTypes.Identifier({
1031
+ name: curLogic.returns[0].name,
1032
+ }),
1033
+ right: transformNode2Expression(item.argument, 'logic')
1034
+ });
1035
+ curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
1036
+ }
1037
+ }
1038
+ else {
1039
+ if (item.argument?.type !== 'Identifier') {
1040
+ curLogic.addVariable('tempVar');
1041
+ const logicItem = new utils_1.naslTypes.Assignment({
1042
+ left: new utils_1.naslTypes.Identifier({
1043
+ name: 'tempVar',
1044
+ }),
1045
+ right: transformNode2Expression(item.argument, 'logic')
1046
+ });
1047
+ curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
1048
+ }
1044
1049
  }
1045
- const logicItem = new naslTypes.Assignment({
1046
- left: new naslTypes.Identifier({
1047
- name: curLogic.returns[0].name,
1048
- }),
1049
- right: transformNode2Expression(item.argument, 'logic')
1050
- });
1051
- curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
1052
1050
  }
1053
1051
  else {
1054
1052
  let logicItem = transformNode2Expression(item, 'logic');
@@ -1056,8 +1054,8 @@ function transformNode2Logic(node, name) {
1056
1054
  if (logicItem.concept === 'Variable') {
1057
1055
  if (!curLogic.variables.find((_) => _.name === logicItem.name))
1058
1056
  curLogic.addVariable(logicItem);
1059
- logicItem = new naslTypes.Assignment({
1060
- left: new naslTypes.Identifier({ name: logicItem?.name }),
1057
+ logicItem = new utils_1.naslTypes.Assignment({
1058
+ left: new utils_1.naslTypes.Identifier({ name: logicItem?.name }),
1061
1059
  right: logicItem.defaultValue?.expression || '',
1062
1060
  });
1063
1061
  if (logicItem.right)
@@ -1073,6 +1071,8 @@ function transformNode2Logic(node, name) {
1073
1071
  }
1074
1072
  // 处理属性
1075
1073
  function transformNode2Attribute(node) {
1074
+ if (!node?.value || !node?.key)
1075
+ return {};
1076
1076
  let item = {};
1077
1077
  let newNode = {};
1078
1078
  if (['StringLiteral', 'NumericLiteral'].includes(node.value.type)) {
@@ -1087,7 +1087,7 @@ function transformNode2Attribute(node) {
1087
1087
  item = {
1088
1088
  name: node.key.name,
1089
1089
  type: 'string',
1090
- value: (0, generator_1.default)(node.value.body).code,
1090
+ value: (0, utils_1.generate)(node.value.body).code,
1091
1091
  };
1092
1092
  }
1093
1093
  else if (['CallExpression'].includes(node.value.type) && node.value?.callee?.name === 'sync') {
@@ -1098,6 +1098,35 @@ function transformNode2Attribute(node) {
1098
1098
  expression: transformNode2Expression(node.value.arguments[0]),
1099
1099
  };
1100
1100
  }
1101
+ else if (['destination'].includes(node.key.name)) {
1102
+ const namespace = node?.value?.arguments?.[0]?.value;
1103
+ const nsArr = namespace.split('.').map((it) => it.replace(/_view$/, ''));
1104
+ const pageType = nsArr.shift();
1105
+ const viewName = nsArr.pop();
1106
+ const newArguments = node?.value?.arguments?.slice(1);
1107
+ let argument = [];
1108
+ if (newArguments?.[0]?.type === 'ObjectExpression') {
1109
+ argument = newArguments?.[0]?.properties?.map((property) => new utils_1.naslTypes.Argument({
1110
+ keyword: property?.key?.name,
1111
+ expression: fixExpression(property?.value),
1112
+ }));
1113
+ }
1114
+ else {
1115
+ argument = node?.arguments?.slice(1)?.map((arg) => new utils_1.naslTypes.Argument({
1116
+ expression: fixExpression(arg),
1117
+ }));
1118
+ }
1119
+ const destination = new utils_1.naslTypes.Destination({
1120
+ viewNamespace: `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((it) => `.${it}.views`)?.join('')}`,
1121
+ viewName,
1122
+ arguments: argument,
1123
+ });
1124
+ item = {
1125
+ name: node?.key?.name,
1126
+ type: 'dynamic',
1127
+ destination,
1128
+ };
1129
+ }
1101
1130
  else {
1102
1131
  // ['TemplateLiteral', 'BooleanLiteral', 'NullLiteral', 'CallExpression']
1103
1132
  item = {
@@ -1112,7 +1141,7 @@ function transformNode2Attribute(node) {
1112
1141
  if (propertyName === 'tooltip') {
1113
1142
  item.rawName = 'v-tooltip';
1114
1143
  }
1115
- newNode = new naslTypes.BindDirective({ ...item, name: propertyName });
1144
+ newNode = new utils_1.naslTypes.BindDirective({ ...item, name: propertyName });
1116
1145
  }
1117
1146
  else if (['_staticStyle'].includes(node.key.name)) {
1118
1147
  newNode = {
@@ -1124,11 +1153,11 @@ function transformNode2Attribute(node) {
1124
1153
  else if (['_color', '_backgroundColor', '_backgroundImage'].includes(node.key.name)) {
1125
1154
  // 样式属性
1126
1155
  const propertyName = node.key?.name?.replace(/^_/, '').replace(/([A-Z])/g, '-$1').toLowerCase();
1127
- newNode = new naslTypes.BindStyle({ ...item, name: propertyName });
1156
+ newNode = new utils_1.naslTypes.BindStyle({ ...item, name: propertyName });
1128
1157
  }
1129
1158
  else {
1130
1159
  // 组件属性
1131
- newNode = new naslTypes.BindAttribute(item);
1160
+ newNode = new utils_1.naslTypes.BindAttribute(item);
1132
1161
  }
1133
1162
  return newNode;
1134
1163
  }
@@ -1137,7 +1166,7 @@ function transformNode2ViewElement(node, componentName) {
1137
1166
  if (viewNode.type === 'ObjectExpression') {
1138
1167
  const tag = (0, lodash_1.kebabCase)(node?.callee.name);
1139
1168
  const name = componentName?.replace(/-/g, '_');
1140
- const newViewElement = new naslTypes.ViewElement({
1169
+ const newViewElement = new utils_1.naslTypes.ViewElement({
1141
1170
  tag,
1142
1171
  name,
1143
1172
  });
@@ -1145,10 +1174,10 @@ function transformNode2ViewElement(node, componentName) {
1145
1174
  if (prop?.value?.type === 'ArrayExpression' && ['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.elements?.[0]?.type)) {
1146
1175
  // 事件逻辑
1147
1176
  const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
1148
- const bindEvent = new naslTypes.BindEvent({ name: eventName });
1177
+ const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
1149
1178
  prop.value.elements.forEach((element) => {
1150
1179
  const logicName = bindEvent.getLogicUniqueName();
1151
- const curLogic = transformNode2Logic(element, logicName);
1180
+ const curLogic = transformNode2Logic(element, logicName, 'event_logic');
1152
1181
  bindEvent.addLogic(curLogic);
1153
1182
  });
1154
1183
  newViewElement.addBindEvent(bindEvent);
@@ -1156,9 +1185,9 @@ function transformNode2ViewElement(node, componentName) {
1156
1185
  else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.type) && /^on/.test(prop.key.name)) {
1157
1186
  // 事件逻辑
1158
1187
  const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
1159
- const bindEvent = new naslTypes.BindEvent({ name: eventName });
1188
+ const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
1160
1189
  const logicName = bindEvent.getLogicUniqueName();
1161
- bindEvent.addLogic(transformNode2Logic(prop.value, logicName));
1190
+ bindEvent.addLogic(transformNode2Logic(prop.value, logicName, 'event_logic'));
1162
1191
  newViewElement.addBindEvent(bindEvent);
1163
1192
  }
1164
1193
  else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.type) && ['ArrayExpression'].includes(prop.value.body?.type)) {
@@ -1184,7 +1213,7 @@ function transformNode2ViewElement(node, componentName) {
1184
1213
  }
1185
1214
  else {
1186
1215
  const slotScope = prop.value?.params[0]?.name || '';
1187
- const newTemplateElement = new naslTypes.ViewElement({
1216
+ const newTemplateElement = new utils_1.naslTypes.ViewElement({
1188
1217
  tag: 'template',
1189
1218
  slotTarget,
1190
1219
  slotScope,
@@ -1193,13 +1222,13 @@ function transformNode2ViewElement(node, componentName) {
1193
1222
  prop.value.body.elements.forEach((element, index) => {
1194
1223
  // $ref.componentName = new xxx({}) 形式,这种是标准的
1195
1224
  if (element.type === 'AssignmentExpression' && element.right?.type === 'NewExpression') {
1196
- newTemplateElement.name = `template_${(0, generator_2.genHash)(`${slotTarget}_template_${propIndex}_${name}`)}`;
1225
+ newTemplateElement.name = `template_${(0, generator_1.genHash)(`${slotTarget}_template_${propIndex}_${name}`)}`;
1197
1226
  const elementName = element?.left?.property?.name;
1198
1227
  newTemplateElement.addViewElement(transformNode2ViewElement(element.right, elementName));
1199
1228
  }
1200
1229
  // new xxx({}) 形式,这种是没有组件名称,为了兼容,自己建一个
1201
1230
  if (element.type === 'NewExpression') {
1202
- newTemplateElement.name = `template_${(0, generator_2.genHash)(`${slotTarget}_template_${propIndex}_${name}`)}`;
1231
+ newTemplateElement.name = `template_${(0, generator_1.genHash)(`${slotTarget}_template_${propIndex}_${name}`)}`;
1203
1232
  const eleTag = (0, lodash_1.kebabCase)(element?.callee.name);
1204
1233
  const eleName = `${eleTag}_${index}_${newTemplateElement.name}`;
1205
1234
  newTemplateElement.addViewElement(transformNode2ViewElement(element, eleName));
@@ -1235,12 +1264,18 @@ function transformNode2ViewConstruct(node) {
1235
1264
  // console.log("lemon ~ transformNode2ViewConstruct ~ node:", node);
1236
1265
  // 变量声明
1237
1266
  if (node.type === 'VariableDeclaration') {
1267
+ const declList = node?.declarations || [];
1268
+ const declListFirstNodde = declList[0];
1269
+ const variableName = declListFirstNodde?.id?.name;
1270
+ if (variableName === '$lifecycles' && declListFirstNodde.init) {
1271
+ return transformLifecycle(declListFirstNodde.init);
1272
+ }
1238
1273
  return transformVariableDeclaration(node);
1239
1274
  }
1240
1275
  // 页面逻辑
1241
1276
  if (node.type === 'FunctionDeclaration') {
1242
1277
  const logicName = node.id.name.replace(/^viewLogic_/, '');
1243
- return transformNode2Logic(node, logicName);
1278
+ return transformNode2Logic(node, logicName, 'view_logic');
1244
1279
  }
1245
1280
  if (node.type === 'ExpressionStatement') {
1246
1281
  return transformNode2ViewConstruct(node.expression);
@@ -1273,20 +1308,30 @@ function transformNode2ViewConstruct(node) {
1273
1308
  else {
1274
1309
  properties?.[3].value.elements.forEach((element) => {
1275
1310
  let newNode = {};
1311
+ const propertiesMap = ['BindDirective', 'BindStyle', 'BindAttribute'];
1276
1312
  if (properties?.[2].value.value === 'ViewElement') {
1277
1313
  newNode = transformNode2ViewConstruct(element);
1278
1314
  }
1279
- else if (properties?.[2].value.value === 'BindAttribute') {
1315
+ else if (propertiesMap.includes(properties?.[2]?.value?.value)) {
1280
1316
  newNode = transformNode2Attribute({ key: element.left, value: element.right });
1281
1317
  }
1282
- const newNodeBackup = (0, lodash_1.cloneDeep)(newNode);
1283
- newNode.aiParams = {
1284
- action: properties?.[0].value.value,
1285
- selectedNodeName: properties?.[1].value.value,
1286
- concept: properties?.[2].value.value,
1287
- object: newNodeBackup
1288
- };
1289
- newViewElement.push(newNode);
1318
+ else if (properties?.[2]?.value?.value === 'BindEvent') {
1319
+ const eventName = element?.left?.name?.replace(/^on/, '')?.toLowerCase();
1320
+ const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
1321
+ const logicName = bindEvent.getLogicUniqueName();
1322
+ bindEvent.addLogic(transformNode2Logic(element?.right?.elements[0], logicName, 'event_logic'));
1323
+ newNode = bindEvent;
1324
+ }
1325
+ if (newNode) {
1326
+ const newNodeBackup = (0, lodash_1.cloneDeep)(newNode);
1327
+ newNode.aiParams = {
1328
+ action: properties?.[0].value.value,
1329
+ selectedNodeName: properties?.[1].value.value,
1330
+ concept: properties?.[2].value.value,
1331
+ object: newNodeBackup
1332
+ };
1333
+ newViewElement.push(newNode);
1334
+ }
1290
1335
  });
1291
1336
  }
1292
1337
  });
@@ -1306,25 +1351,29 @@ function transformNode2View(node, root) {
1306
1351
  if (currentPositionComment) {
1307
1352
  statements = statements.filter((stat) => stat.start > currentPositionComment.start);
1308
1353
  }
1309
- const view = new naslTypes.View();
1310
- parameters.forEach((item) => {
1354
+ const view = new utils_1.naslTypes.View();
1355
+ parameters?.forEach((item) => {
1311
1356
  const param = transformParam(item);
1357
+ view.params = view.params || [];
1312
1358
  param && view.params.push(param);
1313
1359
  });
1314
1360
  const json = [];
1315
- statements.forEach((item) => {
1361
+ statements?.forEach((item) => {
1316
1362
  const viewItem = transformNode2ViewConstruct(item);
1317
1363
  if (item.type === 'ReturnStatement' && item?.argument?.type === 'CallExpression') {
1318
1364
  const action = item.argument?.callee?.name;
1319
1365
  const selectedNodeName = item.argument.arguments?.[0]?.property?.name;
1320
- const newNodeBackup = (0, lodash_1.cloneDeep)(viewItem);
1321
- viewItem.aiParams = { selectedNodeName, action, concept: 'ViewElement', object: newNodeBackup };
1366
+ if (viewItem) {
1367
+ const newNodeBackup = (0, lodash_1.cloneDeep)(viewItem);
1368
+ viewItem.aiParams = { selectedNodeName, action, concept: 'ViewElement', object: newNodeBackup };
1369
+ }
1322
1370
  }
1323
1371
  if (item.type === 'ReturnStatement' && item?.argument?.type === 'ArrayExpression') {
1324
1372
  viewItem?.forEach((element) => {
1325
1373
  if (element.aiParams)
1326
1374
  json.push(element.aiParams);
1327
- view.addViewElement(element);
1375
+ if (element?.concept === 'ViewElement')
1376
+ view.addViewElement(element);
1328
1377
  });
1329
1378
  }
1330
1379
  if (viewItem?.concept === 'Variable') {
@@ -1340,6 +1389,12 @@ function transformNode2View(node, root) {
1340
1389
  if (viewItem.aiParams)
1341
1390
  json.push(viewItem.aiParams);
1342
1391
  }
1392
+ // 生命周期函数
1393
+ if (item.type === 'VariableDeclaration' && Array.isArray(viewItem) && viewItem[0]?.concept === 'BindEvent') {
1394
+ viewItem.forEach((bindEvent) => {
1395
+ view.addBindEvent(bindEvent);
1396
+ });
1397
+ }
1343
1398
  });
1344
1399
  // console.log("lemon ~ 转换出的 view:", view);
1345
1400
  return { view: view.toJSON(), json };
@@ -1362,22 +1417,24 @@ const transformTS2View = (tsCode) => {
1362
1417
  // console.log("lemon ~ 初始 node", func);
1363
1418
  return transformNode2View(func, root);
1364
1419
  };
1365
- const handleNodeName = (curView, object) => {
1366
- const list = [];
1420
+ const handleNodeName = (curView, object, memory) => {
1421
+ const list = [...memory || []];
1367
1422
  if (object.concept === 'ViewElement') {
1368
1423
  const oldName = object.name;
1369
1424
  const newName = curView?.getViewElementUniqueNameOld(oldName);
1370
1425
  if (oldName !== newName) {
1371
- object.name = `${newName}_${(0, generator_2.genHash)(new Date().getTime() + newName)}`;
1426
+ object.name = `${newName}_${(0, generator_1.genHash)(new Date().getTime() + newName)}`;
1372
1427
  list.push({ oldName, newName: object.name });
1373
1428
  }
1374
1429
  if (object?.children?.length) {
1375
1430
  object.children.forEach((child) => {
1376
- handleNodeName(curView, child);
1431
+ const { list: childList } = handleNodeName(curView, child, list);
1432
+ // 去重并合并
1433
+ list.push(...childList?.filter((item) => !list?.find((it) => it.oldName === item.oldName)));
1377
1434
  });
1378
1435
  }
1379
1436
  }
1380
- return { object, list };
1437
+ return { list };
1381
1438
  };
1382
1439
  function tryTransformTS2UI(tsCode, curView) {
1383
1440
  if (tsCode.includes('```')) {
@@ -1387,7 +1444,7 @@ function tryTransformTS2UI(tsCode, curView) {
1387
1444
  }
1388
1445
  if (!curView)
1389
1446
  return transformTS2View(tsCode);
1390
- const newView = new naslTypes.View(curView);
1447
+ const newView = new utils_1.naslTypes.View(curView);
1391
1448
  const { json } = transformTS2View(tsCode);
1392
1449
  const replaceNameList = [];
1393
1450
  const selectedNodeNames = [];