@lcap/nasl 4.3.0-rc.5 → 4.4.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/out/generator/annotation/full.d.ts.map +1 -1
  2. package/out/generator/annotation/full.js +0 -32
  3. package/out/generator/annotation/full.js.map +1 -1
  4. package/out/generator/genBundleFiles.d.ts +3 -2
  5. package/out/generator/genBundleFiles.d.ts.map +1 -1
  6. package/out/generator/genBundleFiles.js +178 -140
  7. package/out/generator/genBundleFiles.js.map +1 -1
  8. package/out/generator/genSimpleBundleFile.d.ts +19 -0
  9. package/out/generator/genSimpleBundleFile.d.ts.map +1 -0
  10. package/out/generator/genSimpleBundleFile.js +114 -0
  11. package/out/generator/genSimpleBundleFile.js.map +1 -0
  12. package/out/generator/index.d.ts +1 -0
  13. package/out/generator/index.d.ts.map +1 -1
  14. package/out/generator/index.js +1 -0
  15. package/out/generator/index.js.map +1 -1
  16. package/out/generator/qiankun.d.ts +1 -1
  17. package/out/generator/qiankun.d.ts.map +1 -1
  18. package/out/generator/qiankun.js +4 -1
  19. package/out/generator/qiankun.js.map +1 -1
  20. package/out/generator/release-body/data.d.ts.map +1 -1
  21. package/out/generator/release-body/data.js +34 -1
  22. package/out/generator/release-body/data.js.map +1 -1
  23. package/out/generator/release-body/utils.d.ts +2 -6
  24. package/out/generator/release-body/utils.d.ts.map +1 -1
  25. package/out/generator/release-body/utils.js +101 -3
  26. package/out/generator/release-body/utils.js.map +1 -1
  27. package/out/generator/templates/chunk.d.ts +11 -0
  28. package/out/generator/templates/chunk.d.ts.map +1 -0
  29. package/out/generator/templates/chunk.js +29 -0
  30. package/out/generator/templates/chunk.js.map +1 -0
  31. package/out/generator/templates/runtime.d.ts +7 -0
  32. package/out/generator/templates/runtime.d.ts.map +1 -0
  33. package/out/generator/templates/runtime.js +409 -0
  34. package/out/generator/templates/runtime.js.map +1 -0
  35. package/out/generator/ui-library-declaration/basic.d.ts.map +1 -1
  36. package/out/generator/ui-library-declaration/basic.js +5 -5
  37. package/out/generator/ui-library-declaration/basic.js.map +1 -1
  38. package/out/generator/ui-library-declaration/dependency.d.ts.map +1 -1
  39. package/out/generator/ui-library-declaration/dependency.js +3 -3
  40. package/out/generator/ui-library-declaration/dependency.js.map +1 -1
  41. package/out/index.d.ts +1 -0
  42. package/out/index.d.ts.map +1 -1
  43. package/out/index.js +1 -0
  44. package/out/index.js.map +1 -1
  45. package/out/manager/diagnostic.d.ts.map +1 -1
  46. package/out/manager/diagnostic.js +0 -1
  47. package/out/manager/diagnostic.js.map +1 -1
  48. package/out/natural/getContext/nasl2Files.d.ts +15 -0
  49. package/out/natural/getContext/nasl2Files.d.ts.map +1 -0
  50. package/out/natural/getContext/nasl2Files.js +75 -0
  51. package/out/natural/getContext/nasl2Files.js.map +1 -0
  52. package/out/natural/index.d.ts +5 -1
  53. package/out/natural/index.d.ts.map +1 -1
  54. package/out/natural/index.js +7 -1
  55. package/out/natural/index.js.map +1 -1
  56. package/out/natural/parseNaturalTS.d.ts +6 -8
  57. package/out/natural/parseNaturalTS.d.ts.map +1 -1
  58. package/out/natural/parseNaturalTS.js +205 -54
  59. package/out/natural/parseNaturalTS.js.map +1 -1
  60. package/out/natural/parseNaturalTSXView.d.ts +7 -0
  61. package/out/natural/parseNaturalTSXView.d.ts.map +1 -0
  62. package/out/natural/parseNaturalTSXView.js +722 -0
  63. package/out/natural/parseNaturalTSXView.js.map +1 -0
  64. package/out/natural/transform2BatchActions.d.ts +96 -0
  65. package/out/natural/transform2BatchActions.d.ts.map +1 -0
  66. package/out/natural/transform2BatchActions.js +387 -0
  67. package/out/natural/transform2BatchActions.js.map +1 -0
  68. package/out/natural/transformTS2UI.d.ts.map +1 -1
  69. package/out/natural/transformTS2UI.js +16 -25
  70. package/out/natural/transformTS2UI.js.map +1 -1
  71. package/out/natural/transformTSCode.d.ts +2 -2
  72. package/out/natural/transformTSCode.d.ts.map +1 -1
  73. package/out/natural/transformTSCode.js +19 -11
  74. package/out/natural/transformTSCode.js.map +1 -1
  75. package/out/natural/transforms/transform2Entity.d.ts +2 -2
  76. package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
  77. package/out/natural/transforms/transform2Entity.js +31 -7
  78. package/out/natural/transforms/transform2Entity.js.map +1 -1
  79. package/out/natural/transforms/transform2Enum.d.ts +2 -2
  80. package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
  81. package/out/natural/transforms/transform2Enum.js +20 -4
  82. package/out/natural/transforms/transform2Enum.js.map +1 -1
  83. package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +2 -2
  84. package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
  85. package/out/natural/transforms/transform2GlobalLogicDeclaration.js +4 -4
  86. package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
  87. package/out/natural/transforms/transform2Logic.d.ts +4 -2
  88. package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
  89. package/out/natural/transforms/transform2Logic.js +46 -8
  90. package/out/natural/transforms/transform2Logic.js.map +1 -1
  91. package/out/natural/transforms/transform2LogicItem.d.ts +65 -30
  92. package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
  93. package/out/natural/transforms/transform2LogicItem.js +502 -222
  94. package/out/natural/transforms/transform2LogicItem.js.map +1 -1
  95. package/out/natural/transforms/transform2MetadataType.d.ts +3 -0
  96. package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -0
  97. package/out/natural/transforms/transform2MetadataType.js +14 -0
  98. package/out/natural/transforms/transform2MetadataType.js.map +1 -0
  99. package/out/natural/transforms/transform2Structure.d.ts +2 -2
  100. package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
  101. package/out/natural/transforms/transform2Structure.js +5 -5
  102. package/out/natural/transforms/transform2Structure.js.map +1 -1
  103. package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -2
  104. package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
  105. package/out/natural/transforms/transform2TypeAnnotation.js +10 -14
  106. package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
  107. package/out/natural/transforms/transform2ValidationRule.d.ts +3 -0
  108. package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -0
  109. package/out/natural/transforms/transform2ValidationRule.js +24 -0
  110. package/out/natural/transforms/transform2ValidationRule.js.map +1 -0
  111. package/out/natural/transforms/transform2Variable.d.ts +3 -2
  112. package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
  113. package/out/natural/transforms/transform2Variable.js +30 -6
  114. package/out/natural/transforms/transform2Variable.js.map +1 -1
  115. package/out/natural/transforms/transformThemeAndStyle.d.ts +24 -0
  116. package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -0
  117. package/out/natural/transforms/transformThemeAndStyle.js +269 -0
  118. package/out/natural/transforms/transformThemeAndStyle.js.map +1 -0
  119. package/out/natural/transforms/utils.d.ts +37 -3
  120. package/out/natural/transforms/utils.d.ts.map +1 -1
  121. package/out/natural/transforms/utils.js +95 -13
  122. package/out/natural/transforms/utils.js.map +1 -1
  123. package/out/server/OQL/oql-cache.js +1 -1
  124. package/out/server/OQL/oql-cache.js.map +1 -1
  125. package/out/server/OQL/sqlCategory.json +410 -0
  126. package/out/server/OQL/sqlFunctions.json +695 -7
  127. package/out/server/OQL/utils.d.ts +1 -0
  128. package/out/server/OQL/utils.d.ts.map +1 -1
  129. package/out/server/OQL/utils.js +1 -0
  130. package/out/server/OQL/utils.js.map +1 -1
  131. package/out/server/index.d.ts +1 -0
  132. package/out/server/index.d.ts.map +1 -1
  133. package/out/server/index.js +1 -0
  134. package/out/server/index.js.map +1 -1
  135. package/out/server/naslServer.d.ts +5 -2
  136. package/out/server/naslServer.d.ts.map +1 -1
  137. package/out/server/naslServer.js +62 -34
  138. package/out/server/naslServer.js.map +1 -1
  139. package/out/service/initial/form-designer.d.ts +1 -1
  140. package/out/service/initial/form-designer.d.ts.map +1 -1
  141. package/out/service/initial/form-designer.js +4 -1
  142. package/out/service/initial/form-designer.js.map +1 -1
  143. package/out/service/initial/processV2.d.ts +1 -1
  144. package/out/service/initial/processV2.d.ts.map +1 -1
  145. package/out/service/initial/processV2.js +4 -1
  146. package/out/service/initial/processV2.js.map +1 -1
  147. package/out/service/initial/types.d.ts +1 -0
  148. package/out/service/initial/types.d.ts.map +1 -1
  149. package/out/service/storage/api.d.ts +9 -0
  150. package/out/service/storage/api.js +8 -0
  151. package/out/service/storage/api.js.map +1 -1
  152. package/out/service/storage/service.d.ts +3 -0
  153. package/out/service/storage/service.d.ts.map +1 -1
  154. package/out/service/storage/service.js +11 -0
  155. package/out/service/storage/service.js.map +1 -1
  156. package/out/service/storage/specTools.d.ts +34 -0
  157. package/out/service/storage/specTools.d.ts.map +1 -0
  158. package/out/service/storage/specTools.js +52 -0
  159. package/out/service/storage/specTools.js.map +1 -0
  160. package/out/utils/json-schema-to-nasl-type.d.ts +37 -0
  161. package/out/utils/json-schema-to-nasl-type.d.ts.map +1 -0
  162. package/out/utils/json-schema-to-nasl-type.js +195 -0
  163. package/out/utils/json-schema-to-nasl-type.js.map +1 -0
  164. package/package.json +12 -10
  165. package/sandbox/stdlib/nasl.oql.ts +1 -0
  166. package/out/generator/ui-library-declaration/utils.d.ts +0 -3
  167. package/out/generator/ui-library-declaration/utils.d.ts.map +0 -1
  168. package/out/generator/ui-library-declaration/utils.js +0 -20
  169. package/out/generator/ui-library-declaration/utils.js.map +0 -1
  170. package/out/natural/transforms/registerTransform.d.ts +0 -8
  171. package/out/natural/transforms/registerTransform.d.ts.map +0 -1
  172. package/out/natural/transforms/registerTransform.js +0 -24
  173. package/out/natural/transforms/registerTransform.js.map +0 -1
@@ -0,0 +1,722 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.parseNaturalTSXView = exports.transformTSDeclareFunction2View = exports.transform2View = exports.transformJSXElement2ViewElement = exports.transform2Variables = void 0;
27
+ /* eslint-disable global-require */
28
+ /* eslint-disable @typescript-eslint/no-use-before-define */
29
+ const utils_1 = require("./transforms/utils");
30
+ const lodash_1 = require("lodash");
31
+ const babel = __importStar(require("@babel/core"));
32
+ const utils_2 = require("../utils");
33
+ const transform2TypeAnnotation_1 = require("./transforms/transform2TypeAnnotation");
34
+ const transform2LogicItem_1 = require("./transforms/transform2LogicItem");
35
+ const transform2Logic_1 = require("./transforms/transform2Logic");
36
+ const transform2ValidationRule_1 = require("./transforms/transform2ValidationRule");
37
+ const transformThemeAndStyle_1 = require("./transforms/transformThemeAndStyle");
38
+ function transform2Variables(node, options) {
39
+ const variables = [];
40
+ const declList = node?.declarations || [];
41
+ declList.forEach((decl) => {
42
+ const variableName = decl.id.name;
43
+ let typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(decl.id.typeAnnotation?.typeAnnotation, options) || undefined;
44
+ const variable = new utils_1.naslTypes.Variable({
45
+ name: variableName,
46
+ typeAnnotation,
47
+ });
48
+ if (decl.init) {
49
+ variable.defaultValue = new utils_1.naslTypes.DefaultValue({
50
+ expression: (0, transform2LogicItem_1.transform2LogicItem)(decl.init, { ...options, transformType: 'attr', typeAnnotation, isRestricted: true, isInFrontend: true }),
51
+ });
52
+ }
53
+ variables.push(variable);
54
+ });
55
+ return variables;
56
+ }
57
+ exports.transform2Variables = transform2Variables;
58
+ function transform2EventLogics(node, eventName, options) {
59
+ if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
60
+ const logic = (0, transform2Logic_1.transform2Logic)(node, eventName, { ...options, logicType: 'event_logic' });
61
+ logic.params = [];
62
+ return [logic];
63
+ }
64
+ else if (node.type === 'CallExpression') {
65
+ if (node.callee.type === 'Identifier' && node.callee.name === '$all') {
66
+ const args = node.arguments;
67
+ return args.map((node) => {
68
+ if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
69
+ const logic = (0, transform2Logic_1.transform2Logic)(node, eventName, { ...options, logicType: 'event_logic' });
70
+ logic.params = [];
71
+ return logic;
72
+ }
73
+ else {
74
+ return (0, utils_1.throwError)(options, '事件逻辑参数不支持的类型', node.type, node);
75
+ }
76
+ }).filter(Boolean);
77
+ }
78
+ else {
79
+ return (0, utils_1.throwError)(options, '事件逻辑参数不正确', node);
80
+ }
81
+ }
82
+ else if (node.type === 'Identifier' || node.type === 'MemberExpression') {
83
+ return (0, utils_1.throwError)(options, '事件逻辑参数不正确,不支持绑定逻辑,需要直接写在元素中', node);
84
+ }
85
+ else {
86
+ return (0, utils_1.throwError)(options, '事件逻辑参数不正确', node);
87
+ }
88
+ }
89
+ function handleDirectoryItem(directoryItem, nextStatement, view, options, callerName) {
90
+ let definitionItem = null;
91
+ if (nextStatement.type === 'VariableDeclaration') {
92
+ // 处理变量声明
93
+ const variables = transform2Variables(nextStatement, options);
94
+ definitionItem = variables[0];
95
+ }
96
+ else if (nextStatement.type === 'FunctionDeclaration') {
97
+ // 处理函数/逻辑声明
98
+ definitionItem = (0, transform2Logic_1.transform2Logic)(nextStatement, undefined, { ...options, logicType: 'view_logic' });
99
+ }
100
+ else {
101
+ const functionName = callerName || '$Variable';
102
+ (0, utils_1.throwError)(options, `${functionName} 后面必须跟变量声明或函数声明`, nextStatement);
103
+ }
104
+ if (!definitionItem)
105
+ return null;
106
+ const referredConcept = definitionItem.concept;
107
+ const definition = new utils_1.naslTypes.ReferredDefinition({
108
+ referredConcept,
109
+ name: definitionItem.name,
110
+ namespace: '',
111
+ });
112
+ // 将定义添加到目录
113
+ if (!view.directories?.find((dir) => dir.name === directoryItem.name)) {
114
+ directoryItem.definitions = [definition];
115
+ view.addDirectory(directoryItem);
116
+ }
117
+ else {
118
+ const existingDirectory = view.directories.find((dir) => dir.name === directoryItem.name);
119
+ const hasDefinition = existingDirectory?.definitions.find((def) => def.name === definitionItem.name && def.referredConcept === referredConcept);
120
+ if (!hasDefinition) {
121
+ existingDirectory?.definitions.push(definition);
122
+ }
123
+ }
124
+ // 将实际的变量或逻辑添加到视图
125
+ if (referredConcept === 'Variable') {
126
+ view.addVariable(definitionItem);
127
+ }
128
+ else if (referredConcept === 'Logic') {
129
+ view.addLogic(definitionItem);
130
+ }
131
+ return definitionItem;
132
+ }
133
+ function transformJSXElement2ViewElement(node, options) {
134
+ const el = node.openingElement;
135
+ if (el.name.type === 'JSXIdentifier') {
136
+ let tag = (0, lodash_1.kebabCase)(el.name.name);
137
+ if (tag === 'el-form-date-time-picker')
138
+ tag = 'el-form-date-picker';
139
+ if (tag === 'el-form-input-date')
140
+ tag = 'el-form-date-picker';
141
+ if (tag === 'el-form-textarea')
142
+ tag = 'el-form-input';
143
+ if (tag === 'el-form-item')
144
+ tag = 'el-form-input';
145
+ const viewElement = new utils_1.naslTypes.ViewElement({
146
+ tag,
147
+ });
148
+ const attrs = el.attributes;
149
+ let directivePrefix = '$';
150
+ let eventPrefix = 'on';
151
+ let slotPrefix = 'slot';
152
+ function addJSXChild(node, slotTarget = 'default', slotScope = '') {
153
+ if (node.type === 'JSXElement') {
154
+ if (slotTarget === 'default' && !slotScope) {
155
+ const child = transformJSXElement2ViewElement(node, options);
156
+ child && viewElement.children.push(child);
157
+ }
158
+ else {
159
+ const child = transformJSXElement2ViewElement(node, options);
160
+ let templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
161
+ // 确保模板名称也不重复
162
+ while (options.nameMap.has(templateName)) {
163
+ templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
164
+ }
165
+ options.nameMap.set(templateName, true);
166
+ const templateChild = new utils_1.naslTypes.ViewElement({
167
+ tag: 'template',
168
+ name: templateName,
169
+ slotTarget,
170
+ slotScope,
171
+ children: child ? [child] : [],
172
+ });
173
+ if (viewElement.children.some((child) => child.tag === 'template' && child.slotTarget === slotTarget))
174
+ (0, utils_1.throwError)(options, `slot${(0, utils_2.firstUpperCase)(slotTarget)} 不能重复`, node);
175
+ viewElement.children.push(templateChild);
176
+ }
177
+ }
178
+ else if (node.type === 'JSXFragment') {
179
+ const children = node.children;
180
+ if (slotTarget === 'default' && !slotScope) {
181
+ viewElement.children.push(...children.filter((child) => child.type === 'JSXElement').map((child) => transformJSXElement2ViewElement(child, options)).filter(Boolean));
182
+ }
183
+ else {
184
+ let templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
185
+ // 确保模板名称也不重复
186
+ while (options.nameMap.has(templateName)) {
187
+ templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
188
+ }
189
+ options.nameMap.set(templateName, true);
190
+ const templateChild = new utils_1.naslTypes.ViewElement({
191
+ tag: 'template',
192
+ name: templateName,
193
+ slotTarget,
194
+ slotScope,
195
+ children: children.filter((child) => child.type === 'JSXElement').map((child) => transformJSXElement2ViewElement(child, options)).filter(Boolean),
196
+ });
197
+ if (viewElement.children.some((child) => child.tag === 'template' && child.slotTarget === slotTarget))
198
+ (0, utils_1.throwError)(options, `slot${(0, utils_2.firstUpperCase)(slotTarget)} 不能重复`, node);
199
+ viewElement.children.push(templateChild);
200
+ }
201
+ }
202
+ else {
203
+ return (0, utils_1.throwError)(options, '不支持的JSX子元素类型', node);
204
+ }
205
+ }
206
+ function addArrowFunctionJSXChild(node, slotTarget = 'default') {
207
+ const slotScopeName = node.params[0]?.name;
208
+ if (slotScopeName && slotScopeName !== 'current' && !slotScopeName?.startsWith('current')) {
209
+ return (0, utils_1.throwError)(options, `slotScope 需以 current 参数名开头`, node);
210
+ }
211
+ let slotScope = '';
212
+ if (slotScopeName) {
213
+ slotScope = 'current';
214
+ }
215
+ const body = node.body;
216
+ if (body.type === 'JSXElement' || body.type === 'JSXFragment') {
217
+ addJSXChild(body, slotTarget, slotScope);
218
+ }
219
+ else if (body.type === 'ArrayExpression') {
220
+ const elements = body.elements;
221
+ elements.forEach((element) => {
222
+ addJSXChild(element, slotTarget, slotScope);
223
+ });
224
+ }
225
+ else {
226
+ return (0, utils_1.throwError)(options, '不支持的JSX子元素类型', body.type, body);
227
+ }
228
+ }
229
+ attrs.forEach((attr) => {
230
+ if (attr.type === 'JSXAttribute') {
231
+ const attrName = attr.name.name;
232
+ if (!attrName)
233
+ (0, utils_1.throwError)(options, '属性名不能为空', attr);
234
+ if (attrName === 'ref') {
235
+ if (attr.value?.type === 'StringLiteral') {
236
+ const proposedName = attr.value.value;
237
+ if (options.nameMap.has(proposedName)) {
238
+ return (0, utils_1.throwError)(options, `ref 属性值 "${proposedName}" 已存在,不能重复使用`, attr);
239
+ }
240
+ viewElement.name = proposedName;
241
+ options.nameMap.set(proposedName, true);
242
+ }
243
+ else {
244
+ return (0, utils_1.throwError)(options, 'ref 属性值不正确', attr.value);
245
+ }
246
+ }
247
+ else if (attrName === 'style') {
248
+ if (attr.value?.type === 'StringLiteral') {
249
+ viewElement.staticStyle = attr.value.value;
250
+ }
251
+ else {
252
+ return (0, utils_1.throwError)(options, 'style 属性只能用字符串字面量', attr.value);
253
+ }
254
+ }
255
+ else if (attrName === '$extraStyle') {
256
+ if (!attr.value) {
257
+ (0, utils_1.throwError)(options, '$extraStyle 属性只能用字符串字面量', attr);
258
+ }
259
+ else if (attr.value.type === 'StringLiteral') {
260
+ viewElement.cssRules = (0, transformThemeAndStyle_1.transformStyle)(attr.value.value, options);
261
+ }
262
+ else if (attr.value.type === 'JSXExpressionContainer') {
263
+ const templateLiteral = attr.value.expression;
264
+ if (templateLiteral.type === 'TemplateLiteral') {
265
+ if (templateLiteral.expressions.length > 0) {
266
+ return (0, utils_1.throwError)(options, '不支持在 $theme 中使用动态表达式');
267
+ }
268
+ const css = templateLiteral.quasis[0].value.raw;
269
+ viewElement.cssRules = (0, transformThemeAndStyle_1.transformStyle)(css, options);
270
+ }
271
+ else {
272
+ return (0, utils_1.throwError)(options, '$extraStyle 属性只能用字符串字面量', attr.value);
273
+ }
274
+ }
275
+ else {
276
+ return (0, utils_1.throwError)(options, '$extraStyle 属性只能用字符串字面量', attr.value);
277
+ }
278
+ }
279
+ else if (attrName === '$dynamicStyle') {
280
+ if (!attr.value) {
281
+ (0, utils_1.throwError)(options, '$dynamicStyle 属性只能用字符串字面量', attr);
282
+ }
283
+ else if (attr.value.type === 'JSXExpressionContainer') {
284
+ const expression = attr.value.expression;
285
+ if (expression.type === 'ObjectExpression') {
286
+ const properties = expression.properties;
287
+ properties.forEach((property) => {
288
+ if (property.type === 'ObjectProperty') {
289
+ const name = (0, lodash_1.kebabCase)(property.key.name);
290
+ viewElement.bindStyles = viewElement.bindStyles || [];
291
+ viewElement.addBindStyle(new utils_1.naslTypes.BindStyle({
292
+ name,
293
+ expression: (0, transform2LogicItem_1.transform2LogicItem)(property.value, {
294
+ ...options,
295
+ transformType: 'attr',
296
+ isRestricted: true,
297
+ isInFrontend: true,
298
+ }),
299
+ }));
300
+ }
301
+ });
302
+ }
303
+ }
304
+ else {
305
+ return (0, utils_1.throwError)(options, 'style 属性值不正确', attr.value);
306
+ }
307
+ }
308
+ else if (attrName.startsWith(directivePrefix)) {
309
+ const directiveName = attrName.slice(directivePrefix.length);
310
+ const directive = new utils_1.naslTypes.BindDirective({
311
+ name: directiveName,
312
+ });
313
+ if (!attr.value) {
314
+ directive.type = 'static';
315
+ directive.value = 'true';
316
+ }
317
+ else if (attr.value.type === 'StringLiteral') {
318
+ directive.type = 'string';
319
+ directive.value = attr.value.value;
320
+ }
321
+ else if (attr.value.type === 'JSXExpressionContainer') {
322
+ if (attr.value.expression.type === 'BooleanLiteral' || attr.value.expression.type === 'NumericLiteral' || attr.value.expression.type === 'NullLiteral' || attr.value.expression.type === 'StringLiteral') {
323
+ directive.type = 'static';
324
+ directive.value = (0, utils_1.generate)(attr.value.expression).code;
325
+ }
326
+ else {
327
+ directive.type = 'dynamic';
328
+ if (attr.value.expression.type === 'FunctionExpression')
329
+ return (0, utils_1.throwError)(options, '指令不支持传函数表达式', attr);
330
+ directive.expression = (0, transform2LogicItem_1.transform2LogicItem)(attr.value.expression, {
331
+ ...options,
332
+ transformType: 'attr',
333
+ isRestricted: true,
334
+ isInFrontend: true,
335
+ });
336
+ }
337
+ }
338
+ else {
339
+ return (0, utils_1.throwError)(options, '不支持的指令类型', attr.value.type, attr.value);
340
+ }
341
+ if (directiveName !== 'for') {
342
+ viewElement.addBindDirective(directive);
343
+ }
344
+ }
345
+ else if (attrName.startsWith(eventPrefix)) {
346
+ const eventName = (0, utils_2.firstLowerCase)(attrName.slice(eventPrefix.length));
347
+ if (attr.value?.type === 'JSXExpressionContainer') {
348
+ const bindEvent = new utils_1.naslTypes.BindEvent({
349
+ name: eventName,
350
+ logics: transform2EventLogics(attr.value.expression, eventName, options) || [],
351
+ });
352
+ viewElement.addBindEvent(bindEvent);
353
+ }
354
+ else {
355
+ return (0, utils_1.throwError)(options, '事件逻辑参数不正确', attr.value);
356
+ }
357
+ }
358
+ else if (attrName.startsWith(slotPrefix)) {
359
+ const slotTarget = (0, utils_2.firstLowerCase)(attrName.slice(slotPrefix.length));
360
+ if (attr.value?.type === 'JSXExpressionContainer') {
361
+ const expression = attr.value.expression;
362
+ if (expression.type === 'JSXElement' || expression.type === 'JSXFragment') {
363
+ addJSXChild(expression, slotTarget);
364
+ }
365
+ else if (expression.type === 'ArrowFunctionExpression') {
366
+ addArrowFunctionJSXChild(expression, slotTarget);
367
+ }
368
+ else {
369
+ return (0, utils_1.throwError)(options, 'slot 属性值不正确', attr.value);
370
+ }
371
+ }
372
+ }
373
+ else if (attrName === 'rules') {
374
+ const bindAttribute = new utils_1.naslTypes.BindAttribute({
375
+ name: attrName,
376
+ });
377
+ if (attr.value?.type === 'JSXExpressionContainer') {
378
+ if (attr.value.expression.type === 'ArrayExpression') {
379
+ const elements = attr.value.expression.elements;
380
+ bindAttribute.rules = elements.map((node) => (0, transform2ValidationRule_1.transform2ValidationRule)(node, options)).filter(Boolean);
381
+ }
382
+ else if (attr.value.expression.type === 'CallExpression') {
383
+ const callee = (0, utils_1.generate)(attr.value.expression.callee).code;
384
+ if (callee === 'nasl.util.NewList' || callee === 'NewList') {
385
+ const elements = attr.value.expression.arguments[0].elements;
386
+ bindAttribute.rules = elements.map((node) => (0, transform2ValidationRule_1.transform2ValidationRule)(node, options)).filter(Boolean);
387
+ }
388
+ else {
389
+ return (0, utils_1.throwError)(options, 'rules 属性值不正确', attr.value);
390
+ }
391
+ }
392
+ else {
393
+ return (0, utils_1.throwError)(options, 'rules 属性值不正确', attr.value);
394
+ }
395
+ }
396
+ else {
397
+ return (0, utils_1.throwError)(options, 'rules 属性值不正确', attr.value);
398
+ }
399
+ viewElement.addBindAttribute(bindAttribute);
400
+ }
401
+ else {
402
+ const bindAttribute = new utils_1.naslTypes.BindAttribute({
403
+ name: attrName,
404
+ });
405
+ if (!attr.value) {
406
+ bindAttribute.type = 'static';
407
+ bindAttribute.value = 'true';
408
+ }
409
+ else if (attr.value.type === 'StringLiteral') {
410
+ bindAttribute.type = 'string';
411
+ bindAttribute.value = attr.value.value;
412
+ }
413
+ else if (attr.value.type === 'JSXExpressionContainer') {
414
+ if (attr.value.expression.type === 'BooleanLiteral' || attr.value.expression.type === 'NumericLiteral' || attr.value.expression.type === 'NullLiteral' || attr.value.expression.type === 'StringLiteral') {
415
+ bindAttribute.type = 'static';
416
+ bindAttribute.value = (0, utils_1.generate)(attr.value.expression).code;
417
+ }
418
+ else {
419
+ let expr = attr.value.expression;
420
+ if (attrName === 'prop' || attrName.endsWith('Field') || attrName === 'rowKey') {
421
+ if (expr.type === 'ArrowFunctionExpression') {
422
+ bindAttribute.type = 'string';
423
+ const paramName = expr.params[0]?.name || 'item';
424
+ const code = (0, utils_1.generate)(expr.body).code;
425
+ bindAttribute.value = code.replace(new RegExp(`${paramName}\\.`, 'g'), '');
426
+ if (bindAttribute.value === 'item' && code !== 'item.item')
427
+ bindAttribute.value = '';
428
+ viewElement.addBindAttribute(bindAttribute);
429
+ return;
430
+ }
431
+ }
432
+ bindAttribute.type = 'dynamic';
433
+ if (expr.type === 'CallExpression' && expr.callee.type === 'Identifier' && expr.callee.name === '$sync') {
434
+ bindAttribute.sync = true;
435
+ if (expr.arguments.length === 0) {
436
+ return (0, utils_1.throwError)(options, '$sync 的参数不能为空', attr);
437
+ }
438
+ else if (expr.arguments.length > 0) {
439
+ expr = expr.arguments[0];
440
+ if (!expr)
441
+ return (0, utils_1.throwError)(options, '$sync 的参数不能为空', attr);
442
+ }
443
+ }
444
+ if (expr.type === 'FunctionExpression')
445
+ return (0, utils_1.throwError)(options, '属性不支持传函数表达式', attr);
446
+ const expression = (0, transform2LogicItem_1.transform2LogicItem)(expr, {
447
+ ...options,
448
+ transformType: 'attr',
449
+ isRestricted: attrName !== 'dataSource',
450
+ isInFrontend: true,
451
+ });
452
+ if (expression?.concept === 'Destination') {
453
+ bindAttribute.destination = expression;
454
+ }
455
+ else if (expression?.concept === 'ExternalDestination') {
456
+ bindAttribute.externalDestination = expression;
457
+ }
458
+ else {
459
+ bindAttribute.expression = expression;
460
+ }
461
+ }
462
+ }
463
+ else {
464
+ return (0, utils_1.throwError)(options, '不支持的指令类型', attr.value.type, attr.value);
465
+ }
466
+ viewElement.addBindAttribute(bindAttribute);
467
+ }
468
+ }
469
+ else {
470
+ return (0, utils_1.throwError)(options, '不支持的JSX属性类型', attr.type, attr);
471
+ }
472
+ });
473
+ { /* 临时补救 EnumToList 问题 */
474
+ if (viewElement.bindAttrs.some((bindAttr) => bindAttr.name === 'dataSource' && bindAttr.expression?.concept === 'CallFunction' && bindAttr.expression?.calleeName === 'EnumToList')) {
475
+ const index = viewElement.bindAttrs.findIndex((bindAttr) => bindAttr.name === 'valueField');
476
+ ~index && viewElement.bindAttrs.splice(index, 1);
477
+ }
478
+ }
479
+ node.children.forEach((child) => {
480
+ if (child.type === 'JSXElement' || child.type === 'JSXFragment') {
481
+ addJSXChild(child);
482
+ }
483
+ else if (child.type === 'JSXExpressionContainer') {
484
+ const expression = child.expression;
485
+ if (expression.type === 'JSXElement' || expression.type === 'JSXFragment') {
486
+ addJSXChild(expression);
487
+ }
488
+ else if (expression.type === 'ArrowFunctionExpression') {
489
+ addArrowFunctionJSXChild(expression);
490
+ }
491
+ else if (expression.type === 'JSXEmptyExpression') {
492
+ // ignore
493
+ }
494
+ else {
495
+ return (0, utils_1.throwError)(options, '不支持的JSX子元素类型', expression.type, expression);
496
+ }
497
+ }
498
+ else if (child.type === 'JSXText') {
499
+ // ignore
500
+ }
501
+ else {
502
+ return (0, utils_1.throwError)(options, '不支持的JSX子元素类型', child.type, child);
503
+ }
504
+ });
505
+ if (!viewElement.name) {
506
+ let generatedName = viewElement.tag.replace(/-/g, '_') + '_' + (0, utils_2.uuidv4)().slice(0, 5);
507
+ // 确保生成的名称也不重复
508
+ while (options.nameMap.has(generatedName)) {
509
+ generatedName = viewElement.tag.replace(/-/g, '_') + '_' + (0, utils_2.uuidv4)().slice(0, 5);
510
+ }
511
+ viewElement.name = generatedName;
512
+ options.nameMap.set(generatedName, true);
513
+ }
514
+ return viewElement;
515
+ }
516
+ else {
517
+ return (0, utils_1.throwError)(options, '不支持的JSX元素类型', el.name.type, el);
518
+ }
519
+ }
520
+ exports.transformJSXElement2ViewElement = transformJSXElement2ViewElement;
521
+ function transform2View(func, decorator, options) {
522
+ const statements = func.body.body;
523
+ // 为每个视图创建独立的 nameMap
524
+ const nameMap = new Map();
525
+ const view = new utils_1.naslTypes.View({
526
+ name: func.id?.name,
527
+ });
528
+ options.nodeName = view.name;
529
+ const opts = { ...options, nameMap };
530
+ if (decorator) {
531
+ if (decorator.arguments[0].type === 'ObjectExpression') {
532
+ const viewObj = (0, utils_1.pickDecoratorObject)(decorator.arguments[0], new Set([
533
+ 'pageTemplateId',
534
+ 'uuid',
535
+ 'title',
536
+ 'crumb',
537
+ 'auth',
538
+ 'authDescription',
539
+ 'isIndex',
540
+ ]), options);
541
+ Object.assign(view, viewObj);
542
+ view.crumb = new utils_1.naslTypes.StaticString({
543
+ value: viewObj.crumb,
544
+ });
545
+ }
546
+ else {
547
+ return (0, utils_1.throwError)(options, '不支持的装饰器类型', decorator.type, decorator);
548
+ }
549
+ }
550
+ func.params.forEach((param) => {
551
+ if (param.type === 'Identifier') {
552
+ const _param = (0, transform2LogicItem_1.transform2Param)(param, { ...options, transformType: 'attr' });
553
+ _param && view.params.push(_param);
554
+ }
555
+ else if (param.type === 'ObjectPattern') {
556
+ const propertyMap = {};
557
+ param.properties.forEach((property) => {
558
+ if (property.type === 'ObjectProperty') {
559
+ if (property.value.type === 'Identifier') {
560
+ propertyMap[property.value.name] = {
561
+ type: 'AssignmentPattern',
562
+ left: property.value,
563
+ right: undefined,
564
+ };
565
+ }
566
+ else if (property.value.type === 'AssignmentPattern') {
567
+ propertyMap[property.value.left.name] = property.value;
568
+ }
569
+ else {
570
+ return (0, utils_1.throwError)(options, '不支持的参数类型', property.value.type, property.value);
571
+ }
572
+ }
573
+ });
574
+ const type = param.typeAnnotation?.typeAnnotation;
575
+ if (!type)
576
+ return (0, utils_1.throwError)(options, 'param 没有对应的类型', param);
577
+ type.members.forEach((member) => {
578
+ if (member.type === 'TSPropertySignature') {
579
+ const name = member.key.name;
580
+ if (propertyMap[name]) {
581
+ propertyMap[name].left.typeAnnotation = member.typeAnnotation;
582
+ }
583
+ }
584
+ });
585
+ Object.values(propertyMap).forEach((property) => {
586
+ const param = (0, transform2LogicItem_1.transform2Param)(property, { ...options, transformType: 'attr' });
587
+ param && view.params.push(param);
588
+ });
589
+ }
590
+ });
591
+ for (let index = 0; index < statements.length; index++) {
592
+ const statement = statements[index];
593
+ if (statement.type === 'VariableDeclaration') {
594
+ const variables = transform2Variables(statement, { ...options });
595
+ variables.forEach((variable) => {
596
+ view.addVariable(variable);
597
+ });
598
+ }
599
+ else if (statement.type === 'FunctionDeclaration') {
600
+ const logic = (0, transform2Logic_1.transform2Logic)(statement, undefined, { ...options, logicType: 'view_logic' });
601
+ view.addLogic(logic);
602
+ }
603
+ else if (statement.type === 'ExpressionStatement' && statement.expression.type === 'CallExpression') {
604
+ const expression = statement.expression;
605
+ if (expression.callee.type == 'Identifier' && expression.callee.name.startsWith('on')) {
606
+ const eventName = (0, utils_2.firstLowerCase)(expression.callee.name.slice(2));
607
+ const arg = expression.arguments[0];
608
+ const bindEvent = new utils_1.naslTypes.BindEvent({
609
+ name: eventName,
610
+ logics: transform2EventLogics(arg, eventName, { ...options }) || [],
611
+ });
612
+ view.addBindEvent(bindEvent);
613
+ }
614
+ else if (expression.callee.type == 'Identifier' && expression.callee.name.startsWith('$')) {
615
+ if (expression?.arguments[0]?.type === 'ObjectExpression') {
616
+ const { properties } = expression?.arguments[0];
617
+ const directoryNode = properties.find((item) => item.key?.name === 'directory');
618
+ if (directoryNode) {
619
+ const directoryItem = (0, transform2LogicItem_1.transformNode2Directory)(directoryNode);
620
+ if (directoryItem) {
621
+ const nextStatement = statements[index + 1];
622
+ if (nextStatement) {
623
+ const definitionItem = handleDirectoryItem(directoryItem, nextStatement, view, { ...options }, expression.callee.name);
624
+ if (definitionItem) {
625
+ // 跳过下一个语句,因为已经处理过了
626
+ index++;
627
+ }
628
+ }
629
+ }
630
+ else {
631
+ return (0, utils_1.throwError)(options, '不支持的定义类型', directoryNode);
632
+ }
633
+ }
634
+ }
635
+ else {
636
+ return (0, utils_1.throwError)(options, '不支持的表达式', statement);
637
+ }
638
+ }
639
+ else {
640
+ return (0, utils_1.throwError)(options, '不支持的表达式', statement);
641
+ }
642
+ }
643
+ else if (statement.type === 'ReturnStatement') {
644
+ const arg = statement.argument;
645
+ if (arg.type === 'JSXElement') {
646
+ const child = transformJSXElement2ViewElement(arg, opts);
647
+ view.elements = child ? [child] : [];
648
+ }
649
+ else if (arg.type === 'JSXFragment') {
650
+ view.elements = arg.children.filter((child) => child.type === 'JSXElement').map((child) => transformJSXElement2ViewElement(child, opts)).filter(Boolean);
651
+ }
652
+ else {
653
+ return (0, utils_1.throwError)(options, '返回值不正确', arg);
654
+ }
655
+ }
656
+ else {
657
+ return (0, utils_1.throwError)(options, '不支持的表达式', statement);
658
+ }
659
+ }
660
+ return view;
661
+ }
662
+ exports.transform2View = transform2View;
663
+ function transformTSDeclareFunction2View(func, decorator, options) {
664
+ const view = new utils_1.naslTypes.View({
665
+ name: func.id?.name,
666
+ });
667
+ options.nodeName = view.name;
668
+ if (decorator) {
669
+ if (decorator.arguments[0].type === 'ObjectExpression') {
670
+ const viewObj = (0, utils_1.pickDecoratorObject)(decorator.arguments[0], new Set([
671
+ 'pageTemplateId',
672
+ 'uuid',
673
+ 'title',
674
+ 'crumb',
675
+ 'auth',
676
+ 'authDescription',
677
+ 'isIndex',
678
+ ]), options);
679
+ Object.assign(view, viewObj);
680
+ view.crumb = new utils_1.naslTypes.StaticString({
681
+ value: viewObj.crumb,
682
+ });
683
+ }
684
+ else {
685
+ return (0, utils_1.throwError)(options, '不支持的装饰器类型', decorator.type, decorator);
686
+ }
687
+ }
688
+ func.params.forEach((param) => {
689
+ if (param.type === 'Identifier') {
690
+ const _param = (0, transform2LogicItem_1.transform2Param)(param, { ...options, transformType: 'attr' });
691
+ _param && view.params.push(_param);
692
+ }
693
+ });
694
+ return view;
695
+ }
696
+ exports.transformTSDeclareFunction2View = transformTSDeclareFunction2View;
697
+ function parseNaturalTSXView(tsCode, options) {
698
+ const root = babel.parseSync(tsCode, {
699
+ filename: 'result.tsx',
700
+ presets: [require('@babel/preset-typescript')],
701
+ });
702
+ let func;
703
+ let funcIndex = 0;
704
+ let decorator;
705
+ root.program.body.forEach((statement, index) => {
706
+ if (statement.type === 'ExportNamedDeclaration' && statement.declaration.type === 'FunctionDeclaration') {
707
+ func = statement.declaration;
708
+ funcIndex = index;
709
+ }
710
+ else if (statement.type === 'FunctionDeclaration') {
711
+ func = statement;
712
+ funcIndex = index;
713
+ }
714
+ const prevStatement = root.program.body[index - 1];
715
+ if (prevStatement?.type === 'ExpressionStatement' && prevStatement.expression.type === 'CallExpression' && prevStatement.expression.callee.type === 'Identifier' && prevStatement.expression.callee.name === '$View') {
716
+ decorator = prevStatement.expression;
717
+ }
718
+ });
719
+ return transform2View(func, decorator, options);
720
+ }
721
+ exports.parseNaturalTSXView = parseNaturalTSXView;
722
+ //# sourceMappingURL=parseNaturalTSXView.js.map