@lcap/nasl 4.1.0-beta.9 → 4.1.0-creator.10
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.
- package/out/generator/genBundleFiles.d.ts +1 -0
- package/out/generator/genBundleFiles.d.ts.map +1 -1
- package/out/generator/genBundleFiles.js +21 -96
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genSimpleBundleFile.d.ts +19 -0
- package/out/generator/genSimpleBundleFile.d.ts.map +1 -0
- package/out/generator/genSimpleBundleFile.js +114 -0
- package/out/generator/genSimpleBundleFile.js.map +1 -0
- package/out/generator/index.d.ts +1 -0
- package/out/generator/index.d.ts.map +1 -1
- package/out/generator/index.js +1 -0
- package/out/generator/index.js.map +1 -1
- package/out/generator/permission.d.ts.map +1 -1
- package/out/generator/permission.js +70 -34
- package/out/generator/permission.js.map +1 -1
- package/out/generator/release-body/body.d.ts.map +1 -1
- package/out/generator/release-body/body.js +3 -4
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/utils.d.ts +7 -3
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +7 -5
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/out/natural/index.d.ts +2 -0
- package/out/natural/index.d.ts.map +1 -1
- package/out/natural/index.js +4 -0
- package/out/natural/index.js.map +1 -1
- package/out/natural/parseNaturalTS.d.ts +5 -8
- package/out/natural/parseNaturalTS.d.ts.map +1 -1
- package/out/natural/parseNaturalTS.js +211 -50
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +18 -0
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -0
- package/out/natural/parseNaturalTSXView.js +641 -0
- package/out/natural/parseNaturalTSXView.js.map +1 -0
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +15 -17
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts.map +1 -1
- package/out/natural/transformTSCode.js +4 -4
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/transform2Entity.d.ts +3 -1
- package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
- package/out/natural/transforms/transform2Entity.js +31 -7
- package/out/natural/transforms/transform2Entity.js.map +1 -1
- package/out/natural/transforms/transform2Enum.d.ts +3 -1
- package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
- package/out/natural/transforms/transform2Enum.js +19 -3
- package/out/natural/transforms/transform2Enum.js.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +3 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js +3 -3
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
- package/out/natural/transforms/transform2Logic.d.ts +9 -1
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +44 -7
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +61 -29
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +438 -199
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +5 -0
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -0
- package/out/natural/transforms/transform2MetadataType.js +14 -0
- package/out/natural/transforms/transform2MetadataType.js.map +1 -0
- package/out/natural/transforms/transform2Structure.d.ts +3 -1
- package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
- package/out/natural/transforms/transform2Structure.js +4 -4
- package/out/natural/transforms/transform2Structure.js.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +3 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.js +10 -11
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts +5 -0
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -0
- package/out/natural/transforms/transform2ValidationRule.js +24 -0
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -0
- package/out/natural/transforms/transform2Variable.d.ts +6 -1
- package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
- package/out/natural/transforms/transform2Variable.js +30 -6
- package/out/natural/transforms/transform2Variable.js.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.d.ts +28 -0
- package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -0
- package/out/natural/transforms/transformThemeAndStyle.js +269 -0
- package/out/natural/transforms/transformThemeAndStyle.js.map +1 -0
- package/out/natural/transforms/utils.d.ts +22 -3
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +80 -12
- package/out/natural/transforms/utils.js.map +1 -1
- package/out/server/OQL/sqlCategory.json +410 -0
- package/out/server/OQL/sqlFunctions.json +695 -7
- package/out/server/client/nasl-server-client.d.ts +7 -0
- package/out/server/client/nasl-server-client.d.ts.map +1 -0
- package/out/server/client/nasl-server-client.js +9 -0
- package/out/server/client/nasl-server-client.js.map +1 -0
- package/out/server/extendBaseNode.d.ts.map +1 -1
- package/out/server/extendBaseNode.js +18 -9
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/findReference.d.ts.map +1 -1
- package/out/server/findReference.js +4 -0
- package/out/server/findReference.js.map +1 -1
- package/out/server/index.d.ts +1 -0
- package/out/server/index.d.ts.map +1 -1
- package/out/server/index.js +1 -0
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +10 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +119 -62
- package/out/server/naslServer.js.map +1 -1
- package/out/service/initial/form-designer.d.ts +1 -1
- package/out/service/initial/form-designer.d.ts.map +1 -1
- package/out/service/initial/form-designer.js +4 -1
- package/out/service/initial/form-designer.js.map +1 -1
- package/out/service/initial/processV2.d.ts +1 -1
- package/out/service/initial/processV2.d.ts.map +1 -1
- package/out/service/initial/processV2.js +4 -1
- package/out/service/initial/processV2.js.map +1 -1
- package/out/service/initial/types.d.ts +1 -0
- package/out/service/initial/types.d.ts.map +1 -1
- package/out/service/storage/api.d.ts +16 -7
- package/out/service/storage/api.js +6 -0
- package/out/service/storage/api.js.map +1 -1
- package/out/service/storage/cache/index.d.ts +3 -15
- package/out/service/storage/cache/index.d.ts.map +1 -1
- package/out/service/storage/cache/index.js +14 -299
- package/out/service/storage/cache/index.js.map +1 -1
- package/out/service/storage/cache/split.d.ts +0 -21
- package/out/service/storage/cache/split.d.ts.map +1 -1
- package/out/service/storage/cache/split.js +24 -33
- package/out/service/storage/cache/split.js.map +1 -1
- package/out/service/storage/init.d.ts +9 -0
- package/out/service/storage/init.d.ts.map +1 -1
- package/out/service/storage/init.js +61 -90
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/service.js +1 -1
- package/out/service/storage/service.js.map +1 -1
- package/package.json +15 -13
- package/out/natural/transforms/registerTransform.d.ts +0 -8
- package/out/natural/transforms/registerTransform.d.ts.map +0 -1
- package/out/natural/transforms/registerTransform.js +0 -24
- package/out/natural/transforms/registerTransform.js.map +0 -1
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.transform2LogicItem = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = exports.
|
|
6
|
+
exports.transformCall2Interface = exports.transformAlert2ShowMessage = exports.transformForEach2ForEachStatement = exports.transformForOf2ForEachStatement = exports.transform2ForEachStatement = exports.transformMap2ListTransform = exports.transform2UIFunction = exports.transformCall2CallFunction = exports.transform2CallFunction = exports.transform2CallOtherNASLLogic = exports.transform2CallEventLogic = exports.transformCall2JSONFunctions = exports.transformCall2Logging = exports.transformCall2ConsoleLog = exports.transformCall2CallDataSourceLogic = exports.transformCall2CallEntityLogic = exports.transformCall2CallViewElementLogic = exports.transformCallFunctionExpression2Match = exports.transformMemberExpression = exports.transformNewExpression = exports.transform2PartialNewComposite = exports.transform2Comment = exports.transform2StringInterpolation = exports.transformReturnStatement2AssignmentOrEnd = exports.transform2NullLiteral = exports.transform2NumericLiteral = exports.transform2DirectiveLiteral = exports.transform2StringLiteral = exports.transform2BooleanLiteral = exports.transformUpdateExpression2Assignment = exports.transform2Assignment = exports.transform2AnonymousFunction = exports.transformIdentifier = exports.transformSwitchStatement2Match = exports.transform2WhileStatement = exports.transform2Break = exports.transform2Continue = exports.transform2IfStatement = exports.transform2BinaryExpression = exports.transform2VariadicExpression = exports.transformCallExpressionToBinaryExpression = exports.transform2Param = exports.fixLogicNode = exports.flatIfStatementForMatch = exports.flatMatchPatternsExpression = exports.getSelectMembers = exports.unflatMemberExpression = exports.flatMemberExpression = exports.fixExpression = exports.TransformManager = void 0;
|
|
7
|
+
exports.transform2LogicItem = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = exports.transformCall2Extension = exports.transformCall2Connector = void 0;
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const transform2TypeAnnotation_1 = require("./transform2TypeAnnotation");
|
|
10
10
|
const utils_2 = require("../../utils");
|
|
@@ -24,7 +24,7 @@ class TransformManager {
|
|
|
24
24
|
apply(node, options) {
|
|
25
25
|
if (node.type === 'CallExpression') {
|
|
26
26
|
if (node.callee.type === 'CallExpression')
|
|
27
|
-
(0, utils_1.throwError)(
|
|
27
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持连续调用!', node.callee);
|
|
28
28
|
const callee = flatMemberExpression(node.callee);
|
|
29
29
|
if (callee[0]
|
|
30
30
|
&& callee[0].type === 'CallExpression'
|
|
@@ -36,9 +36,8 @@ class TransformManager {
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
for (const calleeItem of callee) {
|
|
39
|
-
if (calleeItem.type !== 'Identifier') {
|
|
40
|
-
|
|
41
|
-
(0, utils_1.throwError)(`不支持连续调用!${calleeName}`);
|
|
39
|
+
if (calleeItem.type !== 'Identifier' && !(calleeItem.type === 'FunctionExpression' && calleeItem.id?.name === 'match')) {
|
|
40
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持连续调用!', node.callee);
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
@@ -48,7 +47,7 @@ class TransformManager {
|
|
|
48
47
|
return transform(node, calleeName, callee, options);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
(0, utils_1.throwError)(
|
|
50
|
+
return (0, utils_1.throwError)(options?.parsingId, `不支持的节点类型 ${callee.map((item) => item.name).join('.')}`, node.type, node);
|
|
52
51
|
}
|
|
53
52
|
else {
|
|
54
53
|
for (const [type, transform] of this.transforms) {
|
|
@@ -56,7 +55,7 @@ class TransformManager {
|
|
|
56
55
|
return transform(node, options);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
(0, utils_1.throwError)(
|
|
58
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的节点类型', node.type, node);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
}
|
|
@@ -78,7 +77,10 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
78
77
|
statements = [...node?.body?.directives, ...node?.body?.body];
|
|
79
78
|
}
|
|
80
79
|
parameters.forEach((node) => {
|
|
81
|
-
const param = transform2Param(node);
|
|
80
|
+
const param = transform2Param(node, options);
|
|
81
|
+
if (param && !param?.typeAnnotation) {
|
|
82
|
+
param.typeAnnotation = null;
|
|
83
|
+
}
|
|
82
84
|
param && logic.addParam(param);
|
|
83
85
|
});
|
|
84
86
|
const newStatements = [];
|
|
@@ -122,9 +124,9 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
122
124
|
}
|
|
123
125
|
return logic;
|
|
124
126
|
}
|
|
125
|
-
function assertAssignmentRightIsNotAnonymousFunction(expression) {
|
|
127
|
+
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
126
128
|
if (expression?.concept === 'AnonymousFunction')
|
|
127
|
-
(0, utils_1.throwError)('Anonymous function is not allowed in assignment');
|
|
129
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function is not allowed in assignment');
|
|
128
130
|
return expression;
|
|
129
131
|
}
|
|
130
132
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -232,16 +234,29 @@ function flatMatchPatternsExpression(node) {
|
|
|
232
234
|
}
|
|
233
235
|
return [node];
|
|
234
236
|
}
|
|
237
|
+
else if (node.concept === 'VariadicExpression') {
|
|
238
|
+
if (node.operator === '||') {
|
|
239
|
+
return node.expressions
|
|
240
|
+
?.filter((item) => item?.concept === 'BinaryExpression' && item?.right?.concept === 'StringLiteral')
|
|
241
|
+
?.map((item) => new utils_1.naslTypes.StringLiteral({ value: item?.right?.value })) || [node];
|
|
242
|
+
}
|
|
243
|
+
return [node];
|
|
244
|
+
}
|
|
235
245
|
return [node];
|
|
236
246
|
}
|
|
237
247
|
exports.flatMatchPatternsExpression = flatMatchPatternsExpression;
|
|
238
|
-
function
|
|
248
|
+
function flatIfStatementForMatch(node) {
|
|
239
249
|
if (node.alternate.type === 'IfStatement') {
|
|
240
|
-
return [...
|
|
250
|
+
return [node, ...flatIfStatementForMatch(node.alternate)];
|
|
241
251
|
}
|
|
242
|
-
return [node
|
|
252
|
+
return [node, {
|
|
253
|
+
type: 'IfStatement',
|
|
254
|
+
test: null,
|
|
255
|
+
consequent: node.alternate,
|
|
256
|
+
alternate: node.alternate,
|
|
257
|
+
}];
|
|
243
258
|
}
|
|
244
|
-
exports.
|
|
259
|
+
exports.flatIfStatementForMatch = flatIfStatementForMatch;
|
|
245
260
|
/**
|
|
246
261
|
* 这个函数是修复 AI 翻译出错的情况,与正常的 transform 做个区分
|
|
247
262
|
* @param node
|
|
@@ -257,7 +272,7 @@ function fixLogicNode(node) {
|
|
|
257
272
|
}
|
|
258
273
|
}
|
|
259
274
|
exports.fixLogicNode = fixLogicNode;
|
|
260
|
-
function transform2Param(node) {
|
|
275
|
+
function transform2Param(node, options) {
|
|
261
276
|
const exclude = ['event'];
|
|
262
277
|
if (node.type === 'ObjectProperty') {
|
|
263
278
|
const typeAnnotation = node?.value?.name ? utils_1.naslTypes.TypeAnnotation.createPrimitive((node?.value).name) : null;
|
|
@@ -269,7 +284,7 @@ function transform2Param(node) {
|
|
|
269
284
|
name,
|
|
270
285
|
typeAnnotation,
|
|
271
286
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
272
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
287
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
273
288
|
}),
|
|
274
289
|
});
|
|
275
290
|
}
|
|
@@ -281,9 +296,9 @@ function transform2Param(node) {
|
|
|
281
296
|
let defaultValueExpression = node.optional ? { type: 'NullLiteral' } : undefined;
|
|
282
297
|
return new utils_1.naslTypes.Param({
|
|
283
298
|
name,
|
|
284
|
-
typeAnnotation: typeAnnotation
|
|
299
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
285
300
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
286
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
301
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
287
302
|
}),
|
|
288
303
|
});
|
|
289
304
|
}
|
|
@@ -296,9 +311,9 @@ function transform2Param(node) {
|
|
|
296
311
|
return new utils_1.naslTypes.Param({
|
|
297
312
|
name,
|
|
298
313
|
required: !node.optional,
|
|
299
|
-
typeAnnotation: typeAnnotation
|
|
314
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
300
315
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
301
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
316
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
302
317
|
}),
|
|
303
318
|
});
|
|
304
319
|
}
|
|
@@ -319,14 +334,14 @@ function transform2Param(node) {
|
|
|
319
334
|
return null;
|
|
320
335
|
return new utils_1.naslTypes.Param({
|
|
321
336
|
name,
|
|
322
|
-
typeAnnotation: typeAnnotation
|
|
337
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
323
338
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
324
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
339
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
325
340
|
}),
|
|
326
341
|
});
|
|
327
342
|
}
|
|
328
343
|
else {
|
|
329
|
-
(0, utils_1.throwError)(
|
|
344
|
+
return (0, utils_1.throwError)(options?.parsingId, '在输入参数中不支持节点类型', node);
|
|
330
345
|
}
|
|
331
346
|
}
|
|
332
347
|
exports.transform2Param = transform2Param;
|
|
@@ -345,6 +360,16 @@ function transformCallExpressionToBinaryExpression(node, calleeName, callee, opt
|
|
|
345
360
|
IN: 'in',
|
|
346
361
|
IS_NULL: 'isNull',
|
|
347
362
|
};
|
|
363
|
+
const limitMap = ['STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'];
|
|
364
|
+
if (limitMap.includes(calleeName) && options.transformType === 'logic' && !options.inCallQueryComponentField) {
|
|
365
|
+
return (0, utils_1.throwError)(options?.parsingId, `${calleeName} 仅支持在数据查询中使用`, node);
|
|
366
|
+
}
|
|
367
|
+
if (calleeName === 'IS_NULL') {
|
|
368
|
+
return new utils_1.naslTypes.UnaryExpression({
|
|
369
|
+
operator: 'isNull',
|
|
370
|
+
argument: transformNodeFunction(argument?.[0], options),
|
|
371
|
+
});
|
|
372
|
+
}
|
|
348
373
|
return new utils_1.naslTypes.BinaryExpression({
|
|
349
374
|
operator: map[calleeName],
|
|
350
375
|
left: transformNodeFunction(argument?.[0], options),
|
|
@@ -424,11 +449,21 @@ function transform2BinaryExpression(node, options) {
|
|
|
424
449
|
right: transformNodeFunction(node.right, options),
|
|
425
450
|
});
|
|
426
451
|
}
|
|
427
|
-
(0, utils_1.throwError)(
|
|
452
|
+
return (0, utils_1.throwError)(options?.parsingId, '在二元表达式中不支持节点类型', node.type, node);
|
|
428
453
|
}
|
|
429
454
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
455
|
+
function transformDefaultExpression(node, options) {
|
|
456
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
457
|
+
return transformNodeFunction(node.left, options);
|
|
458
|
+
}
|
|
430
459
|
function transformConditionalExpression(node, options) {
|
|
431
460
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
461
|
+
if (options?.inCallQueryComponentField) {
|
|
462
|
+
const expr = (0, utils_1.generate)(node.test)?.code;
|
|
463
|
+
const then_expr = (0, utils_1.generate)(node.consequent)?.code;
|
|
464
|
+
const else_expr = (0, utils_1.generate)(node.alternate)?.code;
|
|
465
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
466
|
+
}
|
|
432
467
|
const test = transformNodeFunction(node.test, options);
|
|
433
468
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
434
469
|
const alternate = transformNodeFunction(node.alternate, options);
|
|
@@ -451,12 +486,12 @@ function transformConditionalExpression(node, options) {
|
|
|
451
486
|
cases: [
|
|
452
487
|
new utils_1.naslTypes.MatchCase({
|
|
453
488
|
patterns: [new utils_1.naslTypes.BooleanLiteral({ value: 'true' })],
|
|
454
|
-
body: [consequent],
|
|
489
|
+
body: consequent ? [consequent] : [],
|
|
455
490
|
isMatchedTypeEnumable: true,
|
|
456
491
|
}),
|
|
457
492
|
new utils_1.naslTypes.MatchCase({
|
|
458
|
-
patterns: [
|
|
459
|
-
body: [alternate],
|
|
493
|
+
patterns: [],
|
|
494
|
+
body: alternate ? [alternate] : [],
|
|
460
495
|
}),
|
|
461
496
|
],
|
|
462
497
|
});
|
|
@@ -467,17 +502,34 @@ function transformArrayExpression(node, options) {
|
|
|
467
502
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
468
503
|
return new utils_1.naslTypes.NewList({
|
|
469
504
|
typeAnnotation,
|
|
470
|
-
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })),
|
|
505
|
+
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })).filter(Boolean),
|
|
471
506
|
});
|
|
472
507
|
}
|
|
473
508
|
function transform2NewAnonymousStructure(node, options) {
|
|
509
|
+
for (let i = 0; i < node.properties.length; i++) {
|
|
510
|
+
const item = node.properties[i];
|
|
511
|
+
const itemValue = item?.value;
|
|
512
|
+
if (itemValue.type === 'NullLiteral') {
|
|
513
|
+
const currentType = options?.typeAnnotation?.properties?.[i];
|
|
514
|
+
if (currentType?.typeAnnotation) {
|
|
515
|
+
item.naslType = currentType.typeAnnotation;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
return (0, utils_1.throwError)(options?.parsingId, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
else if (itemValue.type === 'TSAsExpression') {
|
|
522
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation, options);
|
|
523
|
+
item.naslType = typeAnnotation;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
474
526
|
const newComposite = transform2PartialNewComposite(node, options);
|
|
475
527
|
const newProperties = node.properties.filter((prop) => prop.type === 'ObjectProperty' && prop.value.type !== 'ConditionalExpression');
|
|
476
528
|
const structureProperties = [];
|
|
477
529
|
newProperties.forEach((arg, index) => {
|
|
478
530
|
structureProperties.push(new utils_1.naslTypes.StructureProperty({
|
|
479
531
|
name: arg.key.name,
|
|
480
|
-
typeAnnotation: null
|
|
532
|
+
typeAnnotation: arg.naslType || null,
|
|
481
533
|
}));
|
|
482
534
|
});
|
|
483
535
|
newComposite.typeAnnotation = utils_1.naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties);
|
|
@@ -500,15 +552,15 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
500
552
|
}
|
|
501
553
|
else {
|
|
502
554
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('List', {
|
|
503
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
555
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
504
556
|
});
|
|
505
557
|
}
|
|
506
558
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
507
|
-
(0, utils_1.throwError)(
|
|
559
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewList 中不允许出现非数组表达式', node);
|
|
508
560
|
}
|
|
509
561
|
return new utils_1.naslTypes.NewList({
|
|
510
562
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
511
|
-
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)),
|
|
563
|
+
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)).filter(Boolean),
|
|
512
564
|
});
|
|
513
565
|
}
|
|
514
566
|
if (calleeName === 'NewMap') {
|
|
@@ -524,7 +576,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
524
576
|
}
|
|
525
577
|
else {
|
|
526
578
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
527
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
579
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
528
580
|
});
|
|
529
581
|
}
|
|
530
582
|
return new utils_1.naslTypes.NewMap({
|
|
@@ -537,13 +589,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
537
589
|
const typeParam = node.typeParameters?.params[0];
|
|
538
590
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
539
591
|
if (!typeNamespaceAndName)
|
|
540
|
-
(0, utils_1.throwError)(
|
|
592
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewEntity 中必须指定类型', node);
|
|
541
593
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
542
594
|
}
|
|
543
595
|
if (calleeName === 'NewAnonymousStructure') {
|
|
544
596
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
545
597
|
}
|
|
546
|
-
(0, utils_1.throwError)(
|
|
598
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
547
599
|
}
|
|
548
600
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
549
601
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -608,7 +660,7 @@ function transform2ArrayPattern(decl, options) {
|
|
|
608
660
|
if (options.transformType === 'logic') {
|
|
609
661
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
610
662
|
name: element.name,
|
|
611
|
-
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation),
|
|
663
|
+
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined,
|
|
612
664
|
}));
|
|
613
665
|
}
|
|
614
666
|
}
|
|
@@ -640,7 +692,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
640
692
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
641
693
|
const declList = node?.declarations || [];
|
|
642
694
|
let newNode;
|
|
643
|
-
declList
|
|
695
|
+
declList.forEach((decl) => {
|
|
644
696
|
const variableName = decl.id.name;
|
|
645
697
|
const isArrayPattern = decl.id?.type === 'ArrayPattern';
|
|
646
698
|
if (isArrayPattern && decl.init) {
|
|
@@ -651,7 +703,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
651
703
|
let typeAnnotation;
|
|
652
704
|
if (options.transformType === 'logic' && ![...options.logic.variables, ...options.logic.returns].some((variable) => variable.name === variableName)) {
|
|
653
705
|
const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
|
|
654
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
706
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
655
707
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
656
708
|
name: variableName,
|
|
657
709
|
typeAnnotation,
|
|
@@ -660,14 +712,14 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
660
712
|
if (decl.init) {
|
|
661
713
|
const calleeName = (0, utils_1.generate)(decl?.init?.callee).code;
|
|
662
714
|
const varTypeAnnotation = decl?.id?.typeAnnotation?.typeAnnotation;
|
|
663
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
715
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
664
716
|
if (calleeName === 'nasl.oql.query' && varTypeAnnotation) {
|
|
665
717
|
decl.init.typeAnnotations = varTypeAnnotation;
|
|
666
718
|
}
|
|
667
719
|
options.typeAnnotation = typeAnnotation;
|
|
668
720
|
newNode = new utils_1.naslTypes.Assignment({
|
|
669
721
|
left: transformNodeFunction(decl.id, options),
|
|
670
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation })),
|
|
722
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation }), options) || undefined,
|
|
671
723
|
});
|
|
672
724
|
}
|
|
673
725
|
});
|
|
@@ -777,6 +829,16 @@ function transformIdentifier(node, options) {
|
|
|
777
829
|
if (placeholderMap.includes(node.name)) {
|
|
778
830
|
return new utils_1.naslTypes.Identifier({});
|
|
779
831
|
}
|
|
832
|
+
if (node.name === '$self') {
|
|
833
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
834
|
+
object: new utils_1.naslTypes.Identifier({
|
|
835
|
+
name: 'elements',
|
|
836
|
+
}),
|
|
837
|
+
property: new utils_1.naslTypes.Identifier({
|
|
838
|
+
name: '$ce',
|
|
839
|
+
}),
|
|
840
|
+
});
|
|
841
|
+
}
|
|
780
842
|
return new utils_1.naslTypes.Identifier({
|
|
781
843
|
name: node.name,
|
|
782
844
|
});
|
|
@@ -786,6 +848,10 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
786
848
|
let expression = node.value;
|
|
787
849
|
let asNameNode = node.key;
|
|
788
850
|
if (expression.type === 'Identifier') {
|
|
851
|
+
const isSameName = (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name;
|
|
852
|
+
if (!isSameName) {
|
|
853
|
+
return (0, utils_1.throwError)(options?.parsingId, `字段名需为 ${(0, utils_2.firstLowerCase)(expression.name)}, 目前为: ${asNameNode.name}, 相关代码如下`, node);
|
|
854
|
+
}
|
|
789
855
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
790
856
|
isDotStar: true,
|
|
791
857
|
asName: (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name ? undefined : asNameNode.name,
|
|
@@ -805,7 +871,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
805
871
|
// @TODO
|
|
806
872
|
}
|
|
807
873
|
else {
|
|
808
|
-
(0, utils_1.throwError)(
|
|
874
|
+
return (0, utils_1.throwError)(options?.parsingId, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
809
875
|
}
|
|
810
876
|
}
|
|
811
877
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -814,10 +880,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
814
880
|
const arg = callExpression.arguments[0];
|
|
815
881
|
if (arg.type !== 'MemberExpression') {
|
|
816
882
|
const code = (0, utils_1.generate)(arg).code;
|
|
817
|
-
(0, utils_1.throwError)(`聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
883
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
818
884
|
}
|
|
819
885
|
if (callExpression.arguments?.length > 1) {
|
|
820
|
-
(0, utils_1.throwError)(`聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
886
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
821
887
|
}
|
|
822
888
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
823
889
|
asName: asNameNode.name,
|
|
@@ -827,10 +893,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
827
893
|
}
|
|
828
894
|
function transform2AnonymousFunction(node, options) {
|
|
829
895
|
if (node.body.type === 'BlockStatement')
|
|
830
|
-
(0, utils_1.throwError)('Anonymous function with block statement is not supported');
|
|
896
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function with block statement is not supported', node);
|
|
831
897
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
832
898
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
833
|
-
params: node.params.map((param) => transform2Param(param)),
|
|
899
|
+
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
834
900
|
body: transformNodeFunction(node.body, options),
|
|
835
901
|
});
|
|
836
902
|
}
|
|
@@ -859,7 +925,7 @@ function transform2Assignment(node, options) {
|
|
|
859
925
|
}
|
|
860
926
|
return new utils_1.naslTypes.Assignment({
|
|
861
927
|
left: transformNodeFunction(node.left, options),
|
|
862
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options)),
|
|
928
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options), options) || undefined,
|
|
863
929
|
});
|
|
864
930
|
}
|
|
865
931
|
exports.transform2Assignment = transform2Assignment;
|
|
@@ -905,10 +971,11 @@ function transform2NumericLiteral(node, options) {
|
|
|
905
971
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
906
972
|
});
|
|
907
973
|
literal.typeAnnotation.typeName = literal.changeType(value);
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
974
|
+
// 新版本依赖自转换
|
|
975
|
+
// if (options.typeAnnotation && ['Integer', 'Long', 'Decimal'].includes(options.typeAnnotation.typeName)) {
|
|
976
|
+
// literal.typeAnnotation = options.typeAnnotation;
|
|
977
|
+
// delete options.typeAnnotation;
|
|
978
|
+
// }
|
|
912
979
|
return literal;
|
|
913
980
|
}
|
|
914
981
|
exports.transform2NumericLiteral = transform2NumericLiteral;
|
|
@@ -936,15 +1003,15 @@ function transformReturnStatement2AssignmentOrEnd(node, options) {
|
|
|
936
1003
|
}
|
|
937
1004
|
}
|
|
938
1005
|
if (!logic.returns.length) {
|
|
939
|
-
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation) : undefined;
|
|
1006
|
+
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation, options) || undefined : undefined;
|
|
940
1007
|
logic.returns.push(new utils_1.naslTypes.Return({
|
|
941
1008
|
name: 'result',
|
|
942
1009
|
typeAnnotation
|
|
943
1010
|
}));
|
|
944
1011
|
}
|
|
945
1012
|
const leftName = logic.returns[0].name;
|
|
946
|
-
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options));
|
|
947
|
-
if (right.concept === 'Identifier' && right.name === leftName) {
|
|
1013
|
+
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options), options) || undefined;
|
|
1014
|
+
if (right && right.concept === 'Identifier' && right.name === leftName) {
|
|
948
1015
|
return new utils_1.naslTypes.End();
|
|
949
1016
|
}
|
|
950
1017
|
else {
|
|
@@ -994,7 +1061,7 @@ function transform2PartialNewComposite(node, options) {
|
|
|
994
1061
|
const rights = [];
|
|
995
1062
|
const structureProperties = [];
|
|
996
1063
|
const assignmentLines = [];
|
|
997
|
-
const newProperties = (node?.properties || node?.arguments?.[0]?.properties)
|
|
1064
|
+
const newProperties = (node?.properties || node?.arguments?.[0]?.properties);
|
|
998
1065
|
let idx = 0;
|
|
999
1066
|
newProperties?.forEach((arg, index) => {
|
|
1000
1067
|
properties.push(transformNodeFunction(arg.key, options));
|
|
@@ -1087,8 +1154,7 @@ function transformNewExpression(node, options) {
|
|
|
1087
1154
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1088
1155
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1089
1156
|
}
|
|
1090
|
-
|
|
1091
|
-
(0, utils_1.throwError)(`Unhandled node ${node.type}: ${errCode}`);
|
|
1157
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
1092
1158
|
}
|
|
1093
1159
|
exports.transformNewExpression = transformNewExpression;
|
|
1094
1160
|
function transformMemberExpression(node, options) {
|
|
@@ -1125,18 +1191,31 @@ function transformMemberExpression(node, options) {
|
|
|
1125
1191
|
});
|
|
1126
1192
|
}
|
|
1127
1193
|
if (calleeName?.startsWith('$refs.')) {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1194
|
+
if (callee[0].type === 'CallExpression') {
|
|
1195
|
+
const callExpression = callee[0];
|
|
1196
|
+
const callCallee = flatMemberExpression(callExpression.callee);
|
|
1197
|
+
const callCalleeName = (0, utils_1.generate)(callExpression)?.code;
|
|
1198
|
+
let callResult = transformCall2CallViewElementLogic(callExpression, callCalleeName, callCallee, options);
|
|
1199
|
+
const remainingCallee = callee.slice(1);
|
|
1200
|
+
if (remainingCallee.length > 0 && callResult) {
|
|
1201
|
+
return unflatMemberExpression(remainingCallee, options, callResult);
|
|
1202
|
+
}
|
|
1203
|
+
return callResult;
|
|
1204
|
+
}
|
|
1205
|
+
else {
|
|
1206
|
+
const componentName = callee?.[1]?.name;
|
|
1207
|
+
const propertyName = callee?.[2]?.name;
|
|
1208
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
1209
|
+
object: new utils_1.naslTypes.Identifier({
|
|
1210
|
+
namespace: `elements.${componentName}.property`,
|
|
1211
|
+
name: componentName,
|
|
1212
|
+
}),
|
|
1213
|
+
property: new utils_1.naslTypes.Identifier({
|
|
1214
|
+
namespace: propertyName,
|
|
1215
|
+
name: propertyName,
|
|
1216
|
+
}),
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1140
1219
|
}
|
|
1141
1220
|
const regex = /^(app\..+?)\.variables\.(.+)$/;
|
|
1142
1221
|
if (regex.test(calleeName)) {
|
|
@@ -1191,12 +1270,88 @@ function transformMemberExpression(node, options) {
|
|
|
1191
1270
|
});
|
|
1192
1271
|
}
|
|
1193
1272
|
exports.transformMemberExpression = transformMemberExpression;
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1273
|
+
/**
|
|
1274
|
+
* @example (function match(_value) {
|
|
1275
|
+
if (_value === true) {
|
|
1276
|
+
return 'green'
|
|
1277
|
+
} else {
|
|
1278
|
+
return 'red'
|
|
1279
|
+
}
|
|
1280
|
+
})(nasl.util.Convert<Boolean>(enabled))
|
|
1281
|
+
*/
|
|
1282
|
+
function transformCallFunctionExpression2Match(node, calleeName, callee, options) {
|
|
1283
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1284
|
+
const arg = node.arguments[0];
|
|
1285
|
+
const ifStatement = node.callee.body.body[0];
|
|
1286
|
+
if (ifStatement.type !== 'IfStatement') {
|
|
1287
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1288
|
+
}
|
|
1289
|
+
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1290
|
+
const match = new utils_1.naslTypes.Match({
|
|
1291
|
+
expression: transformNodeFunction(arg, options),
|
|
1292
|
+
isExpression: true,
|
|
1293
|
+
cases: flatedIfStatements.map((_case) => {
|
|
1294
|
+
let argument;
|
|
1295
|
+
if (_case.consequent.type === 'BlockStatement') {
|
|
1296
|
+
if (_case.consequent.body.length === 1 && _case.consequent.body[0].type === 'ReturnStatement') {
|
|
1297
|
+
argument = _case.consequent.body[0].argument;
|
|
1298
|
+
}
|
|
1299
|
+
else {
|
|
1300
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
else {
|
|
1304
|
+
if (_case.consequent.type === 'ReturnStatement') {
|
|
1305
|
+
argument = _case.consequent.argument;
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1308
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
const bodyNode = transformNodeFunction(argument, options);
|
|
1312
|
+
return new utils_1.naslTypes.MatchCase({
|
|
1313
|
+
isMatchedTypeEnumable: false,
|
|
1314
|
+
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1315
|
+
body: bodyNode ? [bodyNode] : [],
|
|
1316
|
+
});
|
|
1317
|
+
}).filter(Boolean),
|
|
1318
|
+
});
|
|
1319
|
+
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1320
|
+
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1321
|
+
isMatchedTypeEnumable: false,
|
|
1322
|
+
patterns: [],
|
|
1323
|
+
body: [],
|
|
1324
|
+
}));
|
|
1325
|
+
}
|
|
1326
|
+
match.cases.forEach((case_) => {
|
|
1327
|
+
if (case_.patterns.length) {
|
|
1328
|
+
if (case_.patterns[0].concept === 'BooleanLiteral' || case_.patterns[0].concept === 'StringLiteral') {
|
|
1329
|
+
case_.isMatchedTypeEnumable = true;
|
|
1330
|
+
}
|
|
1331
|
+
if (case_.patterns[0].concept === 'MemberExpression') {
|
|
1332
|
+
case_.isMatchedTypeEnumable = true;
|
|
1333
|
+
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1334
|
+
object: {
|
|
1335
|
+
concept: 'Identifier',
|
|
1336
|
+
name: case_.patterns[0].object.property.name,
|
|
1337
|
+
folded: false,
|
|
1338
|
+
namespace: 'app.enums'
|
|
1339
|
+
},
|
|
1340
|
+
property: {
|
|
1341
|
+
concept: 'Identifier',
|
|
1342
|
+
name: case_.patterns[0].property.value,
|
|
1343
|
+
folded: false,
|
|
1344
|
+
},
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
});
|
|
1349
|
+
return match;
|
|
1197
1350
|
}
|
|
1198
|
-
exports.
|
|
1351
|
+
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1199
1352
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1353
|
+
if (options?.isRestricted)
|
|
1354
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1200
1355
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1201
1356
|
const componentName = callee?.[1]?.name;
|
|
1202
1357
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1231,6 +1386,8 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1231
1386
|
}
|
|
1232
1387
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1233
1388
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1389
|
+
if (options?.isRestricted)
|
|
1390
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1234
1391
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1235
1392
|
// console.log('callee', callee);
|
|
1236
1393
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1243,6 +1400,8 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1243
1400
|
}
|
|
1244
1401
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1245
1402
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1403
|
+
if (options?.isRestricted)
|
|
1404
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1246
1405
|
if (calleeName?.includes('.entities.')) {
|
|
1247
1406
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1248
1407
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1301,6 +1460,10 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1301
1460
|
}
|
|
1302
1461
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1303
1462
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1463
|
+
if (options?.isInFrontend)
|
|
1464
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在前端使用', node);
|
|
1465
|
+
if (options?.isRestricted)
|
|
1466
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1304
1467
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1305
1468
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1306
1469
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1310,11 +1473,13 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1310
1473
|
return new utils_1.naslTypes.OqlQueryComponent({
|
|
1311
1474
|
dataSource: 'app.dataSources.defaultDS',
|
|
1312
1475
|
code,
|
|
1313
|
-
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations)
|
|
1476
|
+
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations, options) || undefined,
|
|
1314
1477
|
});
|
|
1315
1478
|
}
|
|
1316
1479
|
}
|
|
1317
1480
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1481
|
+
if (options?.isRestricted)
|
|
1482
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1318
1483
|
return new utils_1.naslTypes.CallLogic({
|
|
1319
1484
|
calleeNamespace: 'nasl.logging',
|
|
1320
1485
|
calleeName: 'INFO',
|
|
@@ -1326,6 +1491,8 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1326
1491
|
}
|
|
1327
1492
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1328
1493
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1494
|
+
if (options?.isRestricted)
|
|
1495
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1329
1496
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1330
1497
|
expression: arg?.name === "undefined" ?
|
|
1331
1498
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1357,10 +1524,32 @@ function transformCall2JSONFunctions(node, calleeName, callee, options) {
|
|
|
1357
1524
|
keyword: 'arg',
|
|
1358
1525
|
}),
|
|
1359
1526
|
],
|
|
1360
|
-
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType })),
|
|
1527
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1361
1528
|
});
|
|
1362
1529
|
}
|
|
1363
1530
|
exports.transformCall2JSONFunctions = transformCall2JSONFunctions;
|
|
1531
|
+
function transform2CallEventLogic(node, calleeName, callee, options) {
|
|
1532
|
+
const lastName = callee[callee.length - 1].name;
|
|
1533
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1534
|
+
calleeNamespace: 'nasl.event',
|
|
1535
|
+
calleeName: lastName,
|
|
1536
|
+
shortcut: true,
|
|
1537
|
+
arguments: [],
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
exports.transform2CallEventLogic = transform2CallEventLogic;
|
|
1541
|
+
function transform2CallOtherNASLLogic(node, calleeName, callee, options) {
|
|
1542
|
+
const arr = calleeName.split('.');
|
|
1543
|
+
const lastName = arr.pop();
|
|
1544
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1545
|
+
calleeNamespace: arr.join('.'),
|
|
1546
|
+
calleeName: lastName,
|
|
1547
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
1548
|
+
expression: fixExpression(arg, options),
|
|
1549
|
+
})),
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
exports.transform2CallOtherNASLLogic = transform2CallOtherNASLLogic;
|
|
1364
1553
|
function transform2CallFunction(node, calleeName, argument, options) {
|
|
1365
1554
|
calleeName = utils_1.replaceCallFunctionMap?.[calleeName] || calleeName;
|
|
1366
1555
|
const func = server_1.default ? server_1.default.getBuildInFunction(calleeName) : null;
|
|
@@ -1374,8 +1563,13 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1374
1563
|
keyword: func && func?.params[index]?.name || `param${index + 1}`,
|
|
1375
1564
|
});
|
|
1376
1565
|
});
|
|
1377
|
-
let newTypeArguments = node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation);
|
|
1378
|
-
if (calleeName === 'ListRepeat') {
|
|
1566
|
+
let newTypeArguments = node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean);
|
|
1567
|
+
// if (calleeName === 'ListRepeat') {
|
|
1568
|
+
// newTypeArguments = [
|
|
1569
|
+
// new naslTypes.TypeAnnotation()
|
|
1570
|
+
// ];
|
|
1571
|
+
// }
|
|
1572
|
+
if (calleeName === 'Convert' && !newTypeArguments) {
|
|
1379
1573
|
newTypeArguments = [
|
|
1380
1574
|
new utils_1.naslTypes.TypeAnnotation()
|
|
1381
1575
|
];
|
|
@@ -1408,7 +1602,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1408
1602
|
const content = np?.toNaturalTS();
|
|
1409
1603
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1410
1604
|
if (!np && !p?.defaultExpression) {
|
|
1411
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1605
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1412
1606
|
}
|
|
1413
1607
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1414
1608
|
if (idx === 1) {
|
|
@@ -1441,7 +1635,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1441
1635
|
});
|
|
1442
1636
|
}
|
|
1443
1637
|
else {
|
|
1444
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1638
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}不存在`, node.callee, node);
|
|
1445
1639
|
}
|
|
1446
1640
|
if (!func.params?.length) {
|
|
1447
1641
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1463,7 +1657,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1463
1657
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1464
1658
|
const excludes = ['HasValue', 'ListSort'];
|
|
1465
1659
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1466
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1660
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1467
1661
|
}
|
|
1468
1662
|
else {
|
|
1469
1663
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1480,19 +1674,22 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1480
1674
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1481
1675
|
});
|
|
1482
1676
|
if (calleeName === 'ListSort') {
|
|
1483
|
-
|
|
1677
|
+
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1678
|
+
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1484
1679
|
}
|
|
1485
1680
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1486
|
-
(0, utils_1.throwError)(
|
|
1681
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1487
1682
|
}
|
|
1488
1683
|
return nodeElement;
|
|
1489
1684
|
}
|
|
1490
1685
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1491
1686
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1492
1687
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1493
|
-
(0, utils_1.throwError)(`数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}
|
|
1688
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`, node.callee, node);
|
|
1494
1689
|
}
|
|
1495
1690
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1691
|
+
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
1692
|
+
const func = server_1.default ? server_1.default?.getSqlFunction('mysql', calleeName) : null;
|
|
1496
1693
|
let addArguments = [];
|
|
1497
1694
|
if (specFunList.includes(calleeName)) {
|
|
1498
1695
|
const value = calleeName === 'COUNTD' ? 'DISTINCT' : 'ALL';
|
|
@@ -1505,20 +1702,20 @@ function transform2SqlFunction(node, calleeName, argument, options) {
|
|
|
1505
1702
|
}
|
|
1506
1703
|
const newArguments = argument.map((arg, index) => new utils_1.naslTypes.Argument({
|
|
1507
1704
|
expression: fixExpression(arg, options),
|
|
1508
|
-
keyword:
|
|
1705
|
+
keyword: func?.params[index]?.name || `param${index + 1}`,
|
|
1509
1706
|
}));
|
|
1510
1707
|
const nodeElement = new utils_1.naslTypes.CallFunction({
|
|
1511
1708
|
calleeNamespace: 'nasl.sqlFunction',
|
|
1512
1709
|
calleeName: utils_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1513
1710
|
arguments: [...addArguments, ...newArguments],
|
|
1514
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
1711
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1515
1712
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1516
1713
|
});
|
|
1517
1714
|
return nodeElement;
|
|
1518
1715
|
}
|
|
1519
1716
|
function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
1520
1717
|
let curCalleeName;
|
|
1521
|
-
if (callee.length
|
|
1718
|
+
if (callee.length >= 3)
|
|
1522
1719
|
curCalleeName = callee[callee.length - 1].name;
|
|
1523
1720
|
else {
|
|
1524
1721
|
let _callee = callee[0].callee;
|
|
@@ -1526,11 +1723,10 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1526
1723
|
_callee = _callee.callee;
|
|
1527
1724
|
curCalleeName = _callee.property.name;
|
|
1528
1725
|
}
|
|
1529
|
-
const argument = callee.length
|
|
1530
|
-
if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1531
|
-
|
|
1532
|
-
}
|
|
1533
|
-
;
|
|
1726
|
+
const argument = callee.length >= 3 ? node.arguments : callee[0].arguments;
|
|
1727
|
+
// if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1728
|
+
// return transformCallExpressionToBinaryExpression(node, curCalleeName, callee, options);
|
|
1729
|
+
// };
|
|
1534
1730
|
if (['NewList', 'NewMap', 'NewEntity', 'NewStructure', 'NewAnonymousStructure'].includes(curCalleeName)) {
|
|
1535
1731
|
return transform2NewExpression(curCalleeName, node, options);
|
|
1536
1732
|
}
|
|
@@ -1539,10 +1735,31 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1539
1735
|
exports.transformCall2CallFunction = transformCall2CallFunction;
|
|
1540
1736
|
function transform2UIFunction(node, calleeName, callee, options) {
|
|
1541
1737
|
if (callee[2].name === 'destination') {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1738
|
+
let namespaceNode = node.arguments[0];
|
|
1739
|
+
let namespace = '';
|
|
1740
|
+
if (namespaceNode.type === 'TemplateLiteral') {
|
|
1741
|
+
namespace = namespaceNode.quasis[0]?.value?.cooked;
|
|
1742
|
+
}
|
|
1743
|
+
else if (namespaceNode.type === 'StringLiteral') {
|
|
1744
|
+
namespace = namespaceNode.value;
|
|
1745
|
+
}
|
|
1746
|
+
else {
|
|
1747
|
+
namespace = (0, utils_1.generate)(namespaceNode).code;
|
|
1748
|
+
}
|
|
1749
|
+
let nsArr;
|
|
1750
|
+
let viewNamespace = '';
|
|
1751
|
+
let viewName = '';
|
|
1752
|
+
if (namespace.startsWith('app.frontendTypes.')) {
|
|
1753
|
+
nsArr = namespace.split('.');
|
|
1754
|
+
viewName = nsArr.pop();
|
|
1755
|
+
viewNamespace = nsArr.join('.');
|
|
1756
|
+
}
|
|
1757
|
+
else {
|
|
1758
|
+
nsArr = namespace.split('.').map((item) => item.replace(/_view$/, ''));
|
|
1759
|
+
const pageType = nsArr.shift();
|
|
1760
|
+
viewName = nsArr.pop();
|
|
1761
|
+
viewNamespace = `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`;
|
|
1762
|
+
}
|
|
1546
1763
|
const newArguments = node?.arguments?.slice(1);
|
|
1547
1764
|
let argument = [];
|
|
1548
1765
|
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
@@ -1558,7 +1775,7 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1558
1775
|
}));
|
|
1559
1776
|
}
|
|
1560
1777
|
return new utils_1.naslTypes.Destination({
|
|
1561
|
-
viewNamespace
|
|
1778
|
+
viewNamespace,
|
|
1562
1779
|
viewName,
|
|
1563
1780
|
arguments: argument,
|
|
1564
1781
|
});
|
|
@@ -1568,6 +1785,11 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1568
1785
|
link: fixExpression(node?.arguments[0], options),
|
|
1569
1786
|
});
|
|
1570
1787
|
}
|
|
1788
|
+
if (options?.isRestricted)
|
|
1789
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1790
|
+
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1791
|
+
return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1792
|
+
}
|
|
1571
1793
|
return new utils_1.naslTypes.CallLogic({
|
|
1572
1794
|
calleeNamespace: 'nasl.ui',
|
|
1573
1795
|
calleeName: callee[2].name,
|
|
@@ -1604,11 +1826,11 @@ function transform2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1604
1826
|
each: transformNodeFunction(newCallee[0], options),
|
|
1605
1827
|
start: transformNodeFunction(newCallee[1], options),
|
|
1606
1828
|
end: newCallee[2]?.name === '__IDENTIFIER__' ? undefined : transformNodeFunction(newCallee[2], options),
|
|
1607
|
-
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0]) : new utils_1.naslTypes.Param({
|
|
1829
|
+
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0], options) || undefined : new utils_1.naslTypes.Param({
|
|
1608
1830
|
name: 'item',
|
|
1609
1831
|
typeAnnotation: undefined,
|
|
1610
1832
|
}),
|
|
1611
|
-
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1833
|
+
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1612
1834
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 4)}`,
|
|
1613
1835
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1614
1836
|
}),
|
|
@@ -1635,8 +1857,8 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1635
1857
|
let endNode;
|
|
1636
1858
|
if (node?.right?.type === 'CallExpression') {
|
|
1637
1859
|
const rightNode = node?.right;
|
|
1638
|
-
const calleeName =
|
|
1639
|
-
const hasListEntries =
|
|
1860
|
+
const calleeName = (0, utils_1.generate)(rightNode.callee).code;
|
|
1861
|
+
const hasListEntries = ['ListEntries', 'nasl.util.ListEntries'].includes(calleeName);
|
|
1640
1862
|
const areaArguments = rightNode?.arguments;
|
|
1641
1863
|
eachNode = hasListEntries ? areaArguments?.[0] : rightNode;
|
|
1642
1864
|
startNode = hasListEntries ? areaArguments?.[1] : undefined;
|
|
@@ -1652,11 +1874,11 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1652
1874
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1653
1875
|
}),
|
|
1654
1876
|
end: endNode?.name === '__IDENTIFIER__' ? undefined : endNode ? transformNodeFunction(endNode, options) : undefined,
|
|
1655
|
-
item: itemNode ? transform2Param(itemNode) : new utils_1.naslTypes.Param({
|
|
1877
|
+
item: itemNode ? transform2Param(itemNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1656
1878
|
name: 'item',
|
|
1657
1879
|
typeAnnotation: undefined,
|
|
1658
1880
|
}),
|
|
1659
|
-
index: indexNode ? transform2Param(indexNode) : new utils_1.naslTypes.Param({
|
|
1881
|
+
index: indexNode ? transform2Param(indexNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1660
1882
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1661
1883
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1662
1884
|
}),
|
|
@@ -1676,8 +1898,8 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1676
1898
|
value: '0',
|
|
1677
1899
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1678
1900
|
}),
|
|
1679
|
-
item: transform2Param(arrowFunction.params[0]),
|
|
1680
|
-
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1901
|
+
item: transform2Param(arrowFunction.params[0], options) || undefined,
|
|
1902
|
+
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1681
1903
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1682
1904
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1683
1905
|
}),
|
|
@@ -1687,6 +1909,11 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1687
1909
|
}
|
|
1688
1910
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1689
1911
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1912
|
+
if (options?.isRestricted)
|
|
1913
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1914
|
+
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1915
|
+
return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1916
|
+
}
|
|
1690
1917
|
return new utils_1.naslTypes.CallLogic({
|
|
1691
1918
|
calleeNamespace: 'nasl.ui',
|
|
1692
1919
|
calleeName: 'showMessage',
|
|
@@ -1698,6 +1925,8 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1698
1925
|
}
|
|
1699
1926
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1700
1927
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1928
|
+
if (options?.isRestricted)
|
|
1929
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1701
1930
|
return new utils_1.naslTypes.CallInterface({
|
|
1702
1931
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1703
1932
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1709,13 +1938,15 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1709
1938
|
}
|
|
1710
1939
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1711
1940
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1941
|
+
if (options?.isRestricted)
|
|
1942
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1712
1943
|
let calleeConnectionName = undefined;
|
|
1713
1944
|
let calleeNamespace = undefined;
|
|
1714
1945
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1715
1946
|
if (callee.length === 5) {
|
|
1716
1947
|
const connectArg = callee[2].arguments[0];
|
|
1717
1948
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1718
|
-
(0, utils_1.throwError)(
|
|
1949
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1719
1950
|
}
|
|
1720
1951
|
calleeConnectionName = connectArg.value;
|
|
1721
1952
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -1730,7 +1961,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1730
1961
|
calleeNamespace = calleeNamespacePrefix;
|
|
1731
1962
|
}
|
|
1732
1963
|
else {
|
|
1733
|
-
(0, utils_1.throwError)(`调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}
|
|
1964
|
+
return (0, utils_1.throwError)(options?.parsingId, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1734
1965
|
}
|
|
1735
1966
|
return new utils_1.naslTypes.CallConnector({
|
|
1736
1967
|
calleeConnectionName,
|
|
@@ -1743,6 +1974,8 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1743
1974
|
}
|
|
1744
1975
|
exports.transformCall2Connector = transformCall2Connector;
|
|
1745
1976
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
1977
|
+
if (options?.isRestricted)
|
|
1978
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1746
1979
|
return new utils_1.naslTypes.CallLogic({
|
|
1747
1980
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
1748
1981
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -1752,70 +1985,26 @@ function transformCall2Extension(node, calleeName, callee, options) {
|
|
|
1752
1985
|
});
|
|
1753
1986
|
}
|
|
1754
1987
|
exports.transformCall2Extension = transformCall2Extension;
|
|
1755
|
-
function transformArrowFunction2Match(node, calleeName, callee, options) {
|
|
1756
|
-
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1757
|
-
// NOTE: 适用于 if else
|
|
1758
|
-
const newCallee = node.callee.body.body;
|
|
1759
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__MatchExpressionFunction') {
|
|
1760
|
-
const match = new utils_1.naslTypes.Match({
|
|
1761
|
-
expression: fixExpression(newCallee[0], options),
|
|
1762
|
-
isExpression: options.transformType !== 'logic',
|
|
1763
|
-
cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new utils_1.naslTypes.MatchCase({
|
|
1764
|
-
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1765
|
-
body: transformBlockBody(_case.consequent.body.filter((item) => item.type !== 'BreakStatement'), options),
|
|
1766
|
-
})),
|
|
1767
|
-
});
|
|
1768
|
-
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1769
|
-
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1770
|
-
patterns: [],
|
|
1771
|
-
body: [],
|
|
1772
|
-
}));
|
|
1773
|
-
}
|
|
1774
|
-
match.cases.forEach((case_) => {
|
|
1775
|
-
if (case_.body.length && (case_.body[0].concept === 'BooleanLiteral' || case_.body[0].concept === 'StringLiteral')) {
|
|
1776
|
-
case_.isMatchedTypeEnumable = true;
|
|
1777
|
-
}
|
|
1778
|
-
if (case_.patterns.length && case_.patterns[0].concept === 'MemberExpression') {
|
|
1779
|
-
case_.isMatchedTypeEnumable = true;
|
|
1780
|
-
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1781
|
-
object: {
|
|
1782
|
-
concept: 'Identifier',
|
|
1783
|
-
name: case_.patterns[0].object.property.name,
|
|
1784
|
-
folded: false,
|
|
1785
|
-
namespace: 'app.enums'
|
|
1786
|
-
},
|
|
1787
|
-
property: {
|
|
1788
|
-
concept: 'Identifier',
|
|
1789
|
-
name: case_.patterns[0].property.value,
|
|
1790
|
-
folded: false,
|
|
1791
|
-
},
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
});
|
|
1795
|
-
return match;
|
|
1796
|
-
}
|
|
1797
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__SwitchExpressionFuntion') {
|
|
1798
|
-
const switchStatement = transformNodeFunction(newCallee[0].body.body[0], options);
|
|
1799
|
-
return switchStatement;
|
|
1800
|
-
}
|
|
1801
|
-
(0, utils_1.throwError)(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
1802
|
-
}
|
|
1803
|
-
exports.transformArrowFunction2Match = transformArrowFunction2Match;
|
|
1804
1988
|
function transformTSAsExpression(node, options) {
|
|
1805
1989
|
if (node.expression.type === 'NumericLiteral') {
|
|
1806
|
-
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation) });
|
|
1990
|
+
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined });
|
|
1807
1991
|
}
|
|
1808
1992
|
else if (node.expression.type === 'ArrayExpression') {
|
|
1809
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation);
|
|
1993
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
1810
1994
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
1811
|
-
(0, utils_1.throwError)(`列表 as 必须为 List
|
|
1995
|
+
return (0, utils_1.throwError)(options?.parsingId, `列表 as 必须为 List 类型`, node);
|
|
1812
1996
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
1813
1997
|
}
|
|
1998
|
+
else if (node.expression.type === 'NullLiteral') {
|
|
1999
|
+
return transform2NullLiteral(node.expression, options);
|
|
2000
|
+
}
|
|
1814
2001
|
else {
|
|
1815
|
-
(0, utils_1.throwError)(
|
|
2002
|
+
return (0, utils_1.throwError)(options?.parsingId, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
1816
2003
|
}
|
|
1817
2004
|
}
|
|
1818
2005
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
2006
|
+
if (options?.isRestricted)
|
|
2007
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
1819
2008
|
return new utils_1.naslTypes.CallLogic({
|
|
1820
2009
|
calleeNamespace: '',
|
|
1821
2010
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -1826,11 +2015,13 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
1826
2015
|
}
|
|
1827
2016
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
1828
2017
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
2018
|
+
if (options?.isRestricted)
|
|
2019
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1829
2020
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
1830
2021
|
// 未带前缀,补一下
|
|
1831
2022
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
1832
2023
|
}
|
|
1833
|
-
else if (
|
|
2024
|
+
else if (server_1.default.getSqlFunction('mysql', calleeName) || calleeName === 'COUNTD') {
|
|
1834
2025
|
return transform2SqlFunction(node, calleeName, node?.arguments || [], options);
|
|
1835
2026
|
}
|
|
1836
2027
|
let newCalleeName = calleeName?.includes('__IDENTIFIER__') ? undefined : calleeName;
|
|
@@ -1850,6 +2041,8 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
1850
2041
|
}
|
|
1851
2042
|
exports.transformCall2Logic = transformCall2Logic;
|
|
1852
2043
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
2044
|
+
if (options?.isRestricted)
|
|
2045
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1853
2046
|
return new utils_1.naslTypes.CallLogic({
|
|
1854
2047
|
calleeNamespace: `nasl.auth`,
|
|
1855
2048
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1874,10 +2067,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1874
2067
|
const calleeName = node.callee.name;
|
|
1875
2068
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
1876
2069
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
1877
|
-
(0, utils_1.throwError)('FROM should have a ArrowFunctionExpression as the second argument');
|
|
2070
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
1878
2071
|
const arrowFunctionExpression = node.arguments[1];
|
|
1879
2072
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
1880
|
-
(0, utils_1.throwError)('FROM should have a CallExpression as the body of ArrowFunctionExpression');
|
|
2073
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
1881
2074
|
const body = arrowFunctionExpression.body;
|
|
1882
2075
|
const callExpressions = flatChainCallExpression(body);
|
|
1883
2076
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -1887,13 +2080,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1887
2080
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
1888
2081
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
1889
2082
|
`;
|
|
1890
|
-
(0, utils_1.throwError)(error);
|
|
2083
|
+
return (0, utils_1.throwError)(options?.parsingId, error, node);
|
|
1891
2084
|
}
|
|
1892
2085
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
1893
2086
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
1894
2087
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
1895
2088
|
if (errorOrder) {
|
|
1896
|
-
(0, utils_1.throwError)('调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。',
|
|
2089
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
1897
2090
|
}
|
|
1898
2091
|
const result = [{
|
|
1899
2092
|
calleeName: calleeName,
|
|
@@ -1905,7 +2098,7 @@ FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); /
|
|
|
1905
2098
|
result[0].arguments[2] = item.arguments[0];
|
|
1906
2099
|
}
|
|
1907
2100
|
else if (['INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(item.callee.name)) {
|
|
1908
|
-
result.push(...flatCallQueryComponentChainNode(item, options));
|
|
2101
|
+
result.push(...(flatCallQueryComponentChainNode(item, options) || []));
|
|
1909
2102
|
}
|
|
1910
2103
|
else {
|
|
1911
2104
|
result.push({
|
|
@@ -1938,33 +2131,39 @@ function flatOnExpressions(node) {
|
|
|
1938
2131
|
return [node];
|
|
1939
2132
|
}
|
|
1940
2133
|
}
|
|
1941
|
-
function transformMemberExpression2Entity(node, node2) {
|
|
2134
|
+
function transformMemberExpression2Entity(node, node2, options) {
|
|
1942
2135
|
const entityPath = flatMemberExpression(node);
|
|
1943
2136
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
1944
2137
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
1945
2138
|
if (!entityNamespace?.includes('.entities')) {
|
|
1946
|
-
(0, utils_1.throwError)(`${entityNamespace}.${entityName}
|
|
2139
|
+
return (0, utils_1.throwError)(options?.parsingId, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
1947
2140
|
}
|
|
1948
2141
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
1949
2142
|
if (asName) {
|
|
1950
|
-
(0, utils_1.throwError)(`FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2143
|
+
return (0, utils_1.throwError)(options?.parsingId, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
1951
2144
|
}
|
|
1952
2145
|
return { entityNamespace, entityName, asName };
|
|
1953
2146
|
}
|
|
1954
2147
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2148
|
+
if (options?.isInFrontend)
|
|
2149
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在前端使用', node);
|
|
2150
|
+
if (options?.isRestricted)
|
|
2151
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
1955
2152
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1956
2153
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
1957
2154
|
if (code?.includes('nasl.util')) {
|
|
1958
|
-
(0, utils_1.throwError)('数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理');
|
|
2155
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
1959
2156
|
}
|
|
1960
2157
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
1961
|
-
(0, utils_1.throwError)('缺少 SELECT 或 AGGR_SELECT 语句');
|
|
2158
|
+
return (0, utils_1.throwError)(options?.parsingId, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
1962
2159
|
}
|
|
1963
2160
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
1964
|
-
|
|
2161
|
+
if (!flatted)
|
|
2162
|
+
return;
|
|
2163
|
+
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
1965
2164
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
1966
2165
|
if (!isOrderCorrect) {
|
|
1967
|
-
(0, utils_1.throwError)('调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。',
|
|
2166
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
1968
2167
|
}
|
|
1969
2168
|
let from;
|
|
1970
2169
|
let where;
|
|
@@ -1977,11 +2176,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
1977
2176
|
let hasErrorTSScopeColumn = false;
|
|
1978
2177
|
let useResultItem = false;
|
|
1979
2178
|
// 这里只是一个示例,具体的逻辑需要根据flatted的内容来构建
|
|
1980
|
-
flatted.forEach((item) => {
|
|
2179
|
+
flatted && flatted.forEach((item) => {
|
|
1981
2180
|
// console.log(item.calleeName)
|
|
1982
2181
|
switch (item.calleeName) {
|
|
1983
2182
|
case 'FROM':
|
|
1984
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2183
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2184
|
+
if (!entity)
|
|
2185
|
+
return;
|
|
1985
2186
|
const entityName = entity.asName || entity.entityName;
|
|
1986
2187
|
entityAsNames.push(entityName);
|
|
1987
2188
|
from = new utils_1.naslTypes.QueryFromExpression({
|
|
@@ -1993,11 +2194,15 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
1993
2194
|
case 'LEFT_JOIN':
|
|
1994
2195
|
case 'RIGHT_JOIN':
|
|
1995
2196
|
case 'OUTER_JOIN':
|
|
1996
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2197
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2198
|
+
if (!entity)
|
|
2199
|
+
break;
|
|
1997
2200
|
entityAsNames.push(entity.asName || entity.entityName);
|
|
1998
2201
|
const rawJoinType = item.calleeName.slice(0, -5);
|
|
1999
2202
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2000
2203
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2204
|
+
if (!from)
|
|
2205
|
+
return; // throwError(options?.parsingId, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2001
2206
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2002
2207
|
...entity,
|
|
2003
2208
|
joinType,
|
|
@@ -2014,27 +2219,50 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2014
2219
|
break;
|
|
2015
2220
|
case 'AGGR_SELECT':
|
|
2016
2221
|
if (groupBy?.length) {
|
|
2017
|
-
(0, utils_1.throwError)('存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2222
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2018
2223
|
}
|
|
2019
2224
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2020
2225
|
distinct: false,
|
|
2021
2226
|
star: true,
|
|
2022
2227
|
selectElements: [new utils_1.naslTypes.QueryFieldExpression({
|
|
2023
2228
|
isDotStar: true,
|
|
2024
|
-
entityAsName: from
|
|
2229
|
+
entityAsName: from?.entityName,
|
|
2025
2230
|
propertyName: '',
|
|
2026
2231
|
})],
|
|
2027
2232
|
});
|
|
2028
|
-
item.arguments[0].
|
|
2029
|
-
|
|
2030
|
-
|
|
2233
|
+
if (item.arguments[0].type === 'ObjectExpression') {
|
|
2234
|
+
item.arguments[0].properties?.forEach((arg) => {
|
|
2235
|
+
if (arg?.value.type === 'CallExpression') {
|
|
2236
|
+
let selectElements = transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2237
|
+
if (selectElements) {
|
|
2238
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2239
|
+
select.setSelectElements(newSelectElements);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
else {
|
|
2243
|
+
return (0, utils_1.throwError)(options?.parsingId, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2244
|
+
}
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
else if (item.arguments[0].type === 'CallExpression') { // 只有一个的简写:AGGR_SELECT(SUM(Entity1.age))
|
|
2248
|
+
const selectElements = transform2QueryAggregateExpression({
|
|
2249
|
+
type: 'ObjectProperty',
|
|
2250
|
+
key: {
|
|
2251
|
+
type: 'Identifier',
|
|
2252
|
+
name: 'resultItem',
|
|
2253
|
+
},
|
|
2254
|
+
value: item.arguments[0],
|
|
2255
|
+
computed: false,
|
|
2256
|
+
shorthand: false,
|
|
2257
|
+
}, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2258
|
+
if (selectElements) {
|
|
2031
2259
|
const newSelectElements = [...select.selectElements, selectElements];
|
|
2032
2260
|
select.setSelectElements(newSelectElements);
|
|
2033
2261
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
}
|
|
2262
|
+
}
|
|
2263
|
+
else {
|
|
2264
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2265
|
+
}
|
|
2038
2266
|
break;
|
|
2039
2267
|
case 'SELECT':
|
|
2040
2268
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
@@ -2042,7 +2270,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2042
2270
|
star: true,
|
|
2043
2271
|
selectElements: groupBy?.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2044
2272
|
isDotStar: true,
|
|
2045
|
-
entityAsName: from
|
|
2273
|
+
entityAsName: from?.entityName,
|
|
2046
2274
|
propertyName: '',
|
|
2047
2275
|
})] : [],
|
|
2048
2276
|
});
|
|
@@ -2053,17 +2281,17 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2053
2281
|
}
|
|
2054
2282
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2055
2283
|
if (groupBy?.length) {
|
|
2056
|
-
(0, utils_1.throwError)('存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2284
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2057
2285
|
}
|
|
2058
2286
|
const originName = arg.key?.name || '';
|
|
2059
2287
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2060
2288
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2061
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}
|
|
2289
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2062
2290
|
}
|
|
2063
2291
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2064
2292
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2065
2293
|
if (!entityAsNames.includes(entityName)) {
|
|
2066
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}
|
|
2294
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2067
2295
|
}
|
|
2068
2296
|
selectElements = arg.value.properties?.map((property) => {
|
|
2069
2297
|
const columnAsName = property.key?.name;
|
|
@@ -2071,7 +2299,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2071
2299
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2072
2300
|
if (columnAsName !== columnPropertyName) {
|
|
2073
2301
|
// eg: comment: Topic_Comment.comment_stu
|
|
2074
|
-
(0, utils_1.throwError)(`SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}
|
|
2302
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2075
2303
|
}
|
|
2076
2304
|
selectElement.isDotStar = false;
|
|
2077
2305
|
return selectElement;
|
|
@@ -2081,6 +2309,9 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2081
2309
|
if (arg.value.type === 'MemberExpression') {
|
|
2082
2310
|
hasErrorTSScopeColumn = true;
|
|
2083
2311
|
}
|
|
2312
|
+
if (arg.type === 'ObjectProperty' && select?.selectElements?.find(item => item?.concept === 'QueryFieldExpression' && item.entityAsName === arg.value?.name)) {
|
|
2313
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 禁止在一次查询中对同一实体设置多个别名,请修改`, node);
|
|
2314
|
+
}
|
|
2084
2315
|
selectElements = [transform2SelectQueryFieldExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2085
2316
|
}
|
|
2086
2317
|
const selectElement = selectElements?.[0];
|
|
@@ -2106,7 +2337,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2106
2337
|
}
|
|
2107
2338
|
}
|
|
2108
2339
|
else {
|
|
2109
|
-
(0, utils_1.throwError)('HAVING 不符合规范,请使用箭头函数');
|
|
2340
|
+
return (0, utils_1.throwError)(options?.parsingId, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2110
2341
|
}
|
|
2111
2342
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2112
2343
|
break;
|
|
@@ -2115,13 +2346,16 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2115
2346
|
let restOptionParams = { entityAsNames };
|
|
2116
2347
|
if (orderNode?.length === 1 && orderNode?.[0]?.type === 'ArrowFunctionExpression') {
|
|
2117
2348
|
const params = orderNode?.[0]?.params;
|
|
2349
|
+
if (orderNode?.[0]?.body?.type !== 'ArrayExpression') {
|
|
2350
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数,并返回数组', orderNode, node);
|
|
2351
|
+
}
|
|
2118
2352
|
orderNode = orderNode?.[0]?.body?.elements;
|
|
2119
2353
|
if (params?.length && params?.[0]?.name) {
|
|
2120
2354
|
restOptionParams = { inOqlIdentifierNamespace: params?.[0]?.name, entityAsNames };
|
|
2121
2355
|
}
|
|
2122
2356
|
}
|
|
2123
2357
|
else {
|
|
2124
|
-
(0, utils_1.throwError)('ORDER_BY
|
|
2358
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数,并返回数组', orderNode, node);
|
|
2125
2359
|
}
|
|
2126
2360
|
orderBy = orderNode.map((arg) => {
|
|
2127
2361
|
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
@@ -2147,24 +2381,26 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2147
2381
|
ideVersion: '2.22',
|
|
2148
2382
|
});
|
|
2149
2383
|
if (hasErrorTSScopeColumn && !groupBy?.length && !having) {
|
|
2150
|
-
(0, utils_1.throwError)('SELECT 局部列不符合规范,需要按两层对象返回');
|
|
2384
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2151
2385
|
}
|
|
2152
2386
|
const hasScopeColumn = select?.selectElements?.find((selectElement) => selectElement?.concept === 'QueryFieldExpression' && !selectElement?.isDotStar);
|
|
2153
2387
|
if (hasScopeColumn && (groupBy?.length || having)) {
|
|
2154
|
-
(0, utils_1.throwError)('分组聚合与表字段局部列不允许同时出现');
|
|
2388
|
+
return (0, utils_1.throwError)(options?.parsingId, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2155
2389
|
}
|
|
2156
2390
|
if (hasScopeColumn && useResultItem) {
|
|
2157
|
-
(0, utils_1.throwError)("对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])");
|
|
2391
|
+
return (0, utils_1.throwError)(options?.parsingId, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])", node);
|
|
2158
2392
|
}
|
|
2159
2393
|
const isOnlyAggr = select?.selectElements?.find((selectElement) => selectElement?.concept !== 'QueryAggregateExpression');
|
|
2160
2394
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2161
2395
|
if (!isOnlyAggr && !calleeNames?.includes('AGGR_SELECT')) {
|
|
2162
|
-
(0, utils_1.throwError)('SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2396
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2163
2397
|
}
|
|
2164
2398
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2165
2399
|
return callQueryComponent;
|
|
2166
2400
|
}
|
|
2167
2401
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2402
|
+
if (options?.isRestricted)
|
|
2403
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2168
2404
|
const args = node.arguments;
|
|
2169
2405
|
const dataArg = args?.[0];
|
|
2170
2406
|
const procDefKeyArg = args?.[1];
|
|
@@ -2203,6 +2439,7 @@ function transform2LogicItem(node, options) {
|
|
|
2203
2439
|
transformManager.register('NumericLiteral', transform2NumericLiteral);
|
|
2204
2440
|
transformManager.register('NullLiteral', transform2NullLiteral);
|
|
2205
2441
|
transformManager.register('TemplateLiteral', transform2StringInterpolation);
|
|
2442
|
+
transformManager.register((node) => node.type === 'LogicalExpression' && node.operator === '??', transformDefaultExpression);
|
|
2206
2443
|
transformManager.register('BinaryExpression', transform2BinaryExpression);
|
|
2207
2444
|
transformManager.register('LogicalExpression', transform2BinaryExpression);
|
|
2208
2445
|
transformManager.register('UpdateExpression', transformUpdateExpression2Assignment);
|
|
@@ -2240,7 +2477,8 @@ function transform2LogicItem(node, options) {
|
|
|
2240
2477
|
}
|
|
2241
2478
|
});
|
|
2242
2479
|
transformManager.register('MemberExpression', transformMemberExpression);
|
|
2243
|
-
transformManager.register(
|
|
2480
|
+
transformManager.register('OptionalMemberExpression', transformMemberExpression);
|
|
2481
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && (node.callee.type === 'FunctionExpression' && node.callee.id?.name === 'match' || node.callee.type === 'ArrowFunctionExpression'), transformCallFunctionExpression2Match);
|
|
2244
2482
|
transformManager.registerCallExpression((node, calleeName) => /^\$refs\./.test(calleeName), transformCall2CallViewElementLogic);
|
|
2245
2483
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity'), transformCall2CallEntityLogic);
|
|
2246
2484
|
transformManager.registerCallExpression('nasl.oql.query', transformCall2OQLQuery);
|
|
@@ -2249,10 +2487,12 @@ function transform2LogicItem(node, options) {
|
|
|
2249
2487
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.logging.'), transformCall2Logging);
|
|
2250
2488
|
transformManager.registerCallExpression('nasl.util.jsonSerialize', transformCall2JSONFunctions);
|
|
2251
2489
|
transformManager.registerCallExpression('nasl.util.jsonDeserialize', transformCall2JSONFunctions);
|
|
2490
|
+
transformManager.registerCallExpression((node, calleeName) => (calleeName.startsWith('nasl.event.') || calleeName.startsWith('event.')) && (calleeName.endsWith('.preventDefault') || calleeName.endsWith('.stopPropagation')), transform2CallEventLogic);
|
|
2252
2491
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.forEach'), transformForEach2ForEachStatement);
|
|
2253
2492
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.util.'), transformCall2CallFunction);
|
|
2254
2493
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.auth.'), transformCall2LogicWithAuth);
|
|
2255
2494
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.ui.'), transform2UIFunction);
|
|
2495
|
+
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.browser.'), transform2CallOtherNASLLogic);
|
|
2256
2496
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.map'), transformMap2ListTransform);
|
|
2257
2497
|
transformManager.registerCallExpression('ForEach', transform2ForEachStatement);
|
|
2258
2498
|
transformManager.registerCallExpression('alert', transformAlert2ShowMessage);
|
|
@@ -2262,15 +2502,14 @@ function transform2LogicItem(node, options) {
|
|
|
2262
2502
|
transformManager.registerCallExpression('extensions.lcap_process_framework.logics.launchProcess', transformCall2LaunchProcess);
|
|
2263
2503
|
transformManager.registerCallExpression((node, calleeName) => /extensions\./.test(calleeName), transformCall2Extension);
|
|
2264
2504
|
transformManager.registerCallExpression((node, calleeName) => /connectors\./.test(calleeName), transformCall2Connector);
|
|
2265
|
-
transformManager.registerCallExpression((node) => node.callee.type === 'ArrowFunctionExpression', transformArrowFunction2Match);
|
|
2266
2505
|
transformManager.registerCallExpression((node, calleeName) => ['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'].includes(calleeName), transformCallExpressionToBinaryExpression);
|
|
2267
2506
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && calleeName.startsWith('viewLogic_'), transformCall2CallViewLogic);
|
|
2268
2507
|
transformManager.registerCallExpression('PAGINATE', transformCall2Paginate);
|
|
2269
2508
|
transformManager.registerCallExpression('FROM', transformCall2DataQuery);
|
|
2270
|
-
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1, transformCall2Logic);
|
|
2509
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2271
2510
|
let result = transformManager.apply(node, options);
|
|
2272
2511
|
delete options.typeAnnotation;
|
|
2273
|
-
return result;
|
|
2512
|
+
return result || undefined;
|
|
2274
2513
|
}
|
|
2275
2514
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2276
2515
|
//# sourceMappingURL=transform2LogicItem.js.map
|