@lcap/nasl 4.1.0-creator.1 → 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/natural/index.d.ts +1 -0
- package/out/natural/index.d.ts.map +1 -1
- package/out/natural/index.js +3 -0
- package/out/natural/index.js.map +1 -1
- package/out/natural/parseNaturalTS.d.ts +4 -7
- package/out/natural/parseNaturalTS.d.ts.map +1 -1
- package/out/natural/parseNaturalTS.js +84 -69
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +16 -4
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -1
- package/out/natural/parseNaturalTSXView.js +196 -91
- package/out/natural/parseNaturalTSXView.js.map +1 -1
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +9 -8
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.js +3 -3
- 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 +28 -6
- 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 +20 -4
- 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 -3
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +14 -8
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +30 -26
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +199 -132
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +3 -1
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -1
- package/out/natural/transforms/transform2MetadataType.js +2 -2
- package/out/natural/transforms/transform2MetadataType.js.map +1 -1
- 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 +3 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.js +9 -4
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -1
- package/out/natural/transforms/transform2Variable.d.ts +6 -2
- package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
- package/out/natural/transforms/transform2Variable.js +10 -10
- package/out/natural/transforms/transform2Variable.js.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.d.ts +6 -2
- package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.js +7 -7
- package/out/natural/transforms/transformThemeAndStyle.js.map +1 -1
- package/out/natural/transforms/utils.d.ts +8 -3
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +20 -8
- package/out/natural/transforms/utils.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/package.json +10 -10
- 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 = void 0;
|
|
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)('不支持连续调用!', node.callee);
|
|
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'
|
|
@@ -37,7 +37,7 @@ class TransformManager {
|
|
|
37
37
|
else {
|
|
38
38
|
for (const calleeItem of callee) {
|
|
39
39
|
if (calleeItem.type !== 'Identifier' && !(calleeItem.type === 'FunctionExpression' && calleeItem.id?.name === 'match')) {
|
|
40
|
-
(0, utils_1.throwError)('不支持连续调用!', node.callee);
|
|
40
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持连续调用!', node.callee);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -47,7 +47,7 @@ class TransformManager {
|
|
|
47
47
|
return transform(node, calleeName, callee, options);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
(0, utils_1.throwError)(
|
|
50
|
+
return (0, utils_1.throwError)(options?.parsingId, `不支持的节点类型 ${callee.map((item) => item.name).join('.')}`, node.type, node);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
53
|
for (const [type, transform] of this.transforms) {
|
|
@@ -55,7 +55,7 @@ class TransformManager {
|
|
|
55
55
|
return transform(node, options);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
(0, utils_1.throwError)(
|
|
58
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的节点类型', node.type, node);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -77,7 +77,10 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
77
77
|
statements = [...node?.body?.directives, ...node?.body?.body];
|
|
78
78
|
}
|
|
79
79
|
parameters.forEach((node) => {
|
|
80
|
-
const param = transform2Param(node);
|
|
80
|
+
const param = transform2Param(node, options);
|
|
81
|
+
if (param && !param?.typeAnnotation) {
|
|
82
|
+
param.typeAnnotation = null;
|
|
83
|
+
}
|
|
81
84
|
param && logic.addParam(param);
|
|
82
85
|
});
|
|
83
86
|
const newStatements = [];
|
|
@@ -121,9 +124,9 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
121
124
|
}
|
|
122
125
|
return logic;
|
|
123
126
|
}
|
|
124
|
-
function assertAssignmentRightIsNotAnonymousFunction(expression) {
|
|
127
|
+
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
125
128
|
if (expression?.concept === 'AnonymousFunction')
|
|
126
|
-
(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');
|
|
127
130
|
return expression;
|
|
128
131
|
}
|
|
129
132
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -269,7 +272,7 @@ function fixLogicNode(node) {
|
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
274
|
exports.fixLogicNode = fixLogicNode;
|
|
272
|
-
function transform2Param(node) {
|
|
275
|
+
function transform2Param(node, options) {
|
|
273
276
|
const exclude = ['event'];
|
|
274
277
|
if (node.type === 'ObjectProperty') {
|
|
275
278
|
const typeAnnotation = node?.value?.name ? utils_1.naslTypes.TypeAnnotation.createPrimitive((node?.value).name) : null;
|
|
@@ -281,7 +284,7 @@ function transform2Param(node) {
|
|
|
281
284
|
name,
|
|
282
285
|
typeAnnotation,
|
|
283
286
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
284
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
287
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
285
288
|
}),
|
|
286
289
|
});
|
|
287
290
|
}
|
|
@@ -293,9 +296,9 @@ function transform2Param(node) {
|
|
|
293
296
|
let defaultValueExpression = node.optional ? { type: 'NullLiteral' } : undefined;
|
|
294
297
|
return new utils_1.naslTypes.Param({
|
|
295
298
|
name,
|
|
296
|
-
typeAnnotation: typeAnnotation
|
|
299
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
297
300
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
298
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
301
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
299
302
|
}),
|
|
300
303
|
});
|
|
301
304
|
}
|
|
@@ -308,9 +311,9 @@ function transform2Param(node) {
|
|
|
308
311
|
return new utils_1.naslTypes.Param({
|
|
309
312
|
name,
|
|
310
313
|
required: !node.optional,
|
|
311
|
-
typeAnnotation: typeAnnotation
|
|
314
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
312
315
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
313
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
316
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
314
317
|
}),
|
|
315
318
|
});
|
|
316
319
|
}
|
|
@@ -331,14 +334,14 @@ function transform2Param(node) {
|
|
|
331
334
|
return null;
|
|
332
335
|
return new utils_1.naslTypes.Param({
|
|
333
336
|
name,
|
|
334
|
-
typeAnnotation: typeAnnotation
|
|
337
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
335
338
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
336
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
339
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
337
340
|
}),
|
|
338
341
|
});
|
|
339
342
|
}
|
|
340
343
|
else {
|
|
341
|
-
(0, utils_1.throwError)(
|
|
344
|
+
return (0, utils_1.throwError)(options?.parsingId, '在输入参数中不支持节点类型', node);
|
|
342
345
|
}
|
|
343
346
|
}
|
|
344
347
|
exports.transform2Param = transform2Param;
|
|
@@ -357,6 +360,10 @@ function transformCallExpressionToBinaryExpression(node, calleeName, callee, opt
|
|
|
357
360
|
IN: 'in',
|
|
358
361
|
IS_NULL: 'isNull',
|
|
359
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
|
+
}
|
|
360
367
|
if (calleeName === 'IS_NULL') {
|
|
361
368
|
return new utils_1.naslTypes.UnaryExpression({
|
|
362
369
|
operator: 'isNull',
|
|
@@ -442,7 +449,7 @@ function transform2BinaryExpression(node, options) {
|
|
|
442
449
|
right: transformNodeFunction(node.right, options),
|
|
443
450
|
});
|
|
444
451
|
}
|
|
445
|
-
(0, utils_1.throwError)(
|
|
452
|
+
return (0, utils_1.throwError)(options?.parsingId, '在二元表达式中不支持节点类型', node.type, node);
|
|
446
453
|
}
|
|
447
454
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
448
455
|
function transformDefaultExpression(node, options) {
|
|
@@ -455,7 +462,7 @@ function transformConditionalExpression(node, options) {
|
|
|
455
462
|
const expr = (0, utils_1.generate)(node.test)?.code;
|
|
456
463
|
const then_expr = (0, utils_1.generate)(node.consequent)?.code;
|
|
457
464
|
const else_expr = (0, utils_1.generate)(node.alternate)?.code;
|
|
458
|
-
(0, utils_1.throwError)(`数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
465
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
459
466
|
}
|
|
460
467
|
const test = transformNodeFunction(node.test, options);
|
|
461
468
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
@@ -479,12 +486,12 @@ function transformConditionalExpression(node, options) {
|
|
|
479
486
|
cases: [
|
|
480
487
|
new utils_1.naslTypes.MatchCase({
|
|
481
488
|
patterns: [new utils_1.naslTypes.BooleanLiteral({ value: 'true' })],
|
|
482
|
-
body: [consequent],
|
|
489
|
+
body: consequent ? [consequent] : [],
|
|
483
490
|
isMatchedTypeEnumable: true,
|
|
484
491
|
}),
|
|
485
492
|
new utils_1.naslTypes.MatchCase({
|
|
486
493
|
patterns: [],
|
|
487
|
-
body: [alternate],
|
|
494
|
+
body: alternate ? [alternate] : [],
|
|
488
495
|
}),
|
|
489
496
|
],
|
|
490
497
|
});
|
|
@@ -495,7 +502,7 @@ function transformArrayExpression(node, options) {
|
|
|
495
502
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
496
503
|
return new utils_1.naslTypes.NewList({
|
|
497
504
|
typeAnnotation,
|
|
498
|
-
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })),
|
|
505
|
+
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })).filter(Boolean),
|
|
499
506
|
});
|
|
500
507
|
}
|
|
501
508
|
function transform2NewAnonymousStructure(node, options) {
|
|
@@ -508,11 +515,11 @@ function transform2NewAnonymousStructure(node, options) {
|
|
|
508
515
|
item.naslType = currentType.typeAnnotation;
|
|
509
516
|
}
|
|
510
517
|
else {
|
|
511
|
-
(0, utils_1.throwError)('
|
|
518
|
+
return (0, utils_1.throwError)(options?.parsingId, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
512
519
|
}
|
|
513
520
|
}
|
|
514
521
|
else if (itemValue.type === 'TSAsExpression') {
|
|
515
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation);
|
|
522
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation, options);
|
|
516
523
|
item.naslType = typeAnnotation;
|
|
517
524
|
}
|
|
518
525
|
}
|
|
@@ -545,15 +552,15 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
545
552
|
}
|
|
546
553
|
else {
|
|
547
554
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('List', {
|
|
548
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
555
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
549
556
|
});
|
|
550
557
|
}
|
|
551
558
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
552
|
-
(0, utils_1.throwError)('
|
|
559
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewList 中不允许出现非数组表达式', node);
|
|
553
560
|
}
|
|
554
561
|
return new utils_1.naslTypes.NewList({
|
|
555
562
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
556
|
-
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)),
|
|
563
|
+
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)).filter(Boolean),
|
|
557
564
|
});
|
|
558
565
|
}
|
|
559
566
|
if (calleeName === 'NewMap') {
|
|
@@ -569,7 +576,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
569
576
|
}
|
|
570
577
|
else {
|
|
571
578
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
572
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
579
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
573
580
|
});
|
|
574
581
|
}
|
|
575
582
|
return new utils_1.naslTypes.NewMap({
|
|
@@ -582,13 +589,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
582
589
|
const typeParam = node.typeParameters?.params[0];
|
|
583
590
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
584
591
|
if (!typeNamespaceAndName)
|
|
585
|
-
(0, utils_1.throwError)('
|
|
592
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewEntity 中必须指定类型', node);
|
|
586
593
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
587
594
|
}
|
|
588
595
|
if (calleeName === 'NewAnonymousStructure') {
|
|
589
596
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
590
597
|
}
|
|
591
|
-
(0, utils_1.throwError)(
|
|
598
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
592
599
|
}
|
|
593
600
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
594
601
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -653,7 +660,7 @@ function transform2ArrayPattern(decl, options) {
|
|
|
653
660
|
if (options.transformType === 'logic') {
|
|
654
661
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
655
662
|
name: element.name,
|
|
656
|
-
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation),
|
|
663
|
+
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined,
|
|
657
664
|
}));
|
|
658
665
|
}
|
|
659
666
|
}
|
|
@@ -696,7 +703,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
696
703
|
let typeAnnotation;
|
|
697
704
|
if (options.transformType === 'logic' && ![...options.logic.variables, ...options.logic.returns].some((variable) => variable.name === variableName)) {
|
|
698
705
|
const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
|
|
699
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
706
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
700
707
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
701
708
|
name: variableName,
|
|
702
709
|
typeAnnotation,
|
|
@@ -705,14 +712,14 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
705
712
|
if (decl.init) {
|
|
706
713
|
const calleeName = (0, utils_1.generate)(decl?.init?.callee).code;
|
|
707
714
|
const varTypeAnnotation = decl?.id?.typeAnnotation?.typeAnnotation;
|
|
708
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
715
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
709
716
|
if (calleeName === 'nasl.oql.query' && varTypeAnnotation) {
|
|
710
717
|
decl.init.typeAnnotations = varTypeAnnotation;
|
|
711
718
|
}
|
|
712
719
|
options.typeAnnotation = typeAnnotation;
|
|
713
720
|
newNode = new utils_1.naslTypes.Assignment({
|
|
714
721
|
left: transformNodeFunction(decl.id, options),
|
|
715
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation })),
|
|
722
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation }), options) || undefined,
|
|
716
723
|
});
|
|
717
724
|
}
|
|
718
725
|
});
|
|
@@ -841,6 +848,10 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
841
848
|
let expression = node.value;
|
|
842
849
|
let asNameNode = node.key;
|
|
843
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
|
+
}
|
|
844
855
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
845
856
|
isDotStar: true,
|
|
846
857
|
asName: (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name ? undefined : asNameNode.name,
|
|
@@ -860,7 +871,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
860
871
|
// @TODO
|
|
861
872
|
}
|
|
862
873
|
else {
|
|
863
|
-
(0, utils_1.throwError)('
|
|
874
|
+
return (0, utils_1.throwError)(options?.parsingId, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
864
875
|
}
|
|
865
876
|
}
|
|
866
877
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -869,10 +880,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
869
880
|
const arg = callExpression.arguments[0];
|
|
870
881
|
if (arg.type !== 'MemberExpression') {
|
|
871
882
|
const code = (0, utils_1.generate)(arg).code;
|
|
872
|
-
(0, utils_1.throwError)(`聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
883
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
873
884
|
}
|
|
874
885
|
if (callExpression.arguments?.length > 1) {
|
|
875
|
-
(0, utils_1.throwError)(`聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
886
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
876
887
|
}
|
|
877
888
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
878
889
|
asName: asNameNode.name,
|
|
@@ -882,10 +893,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
882
893
|
}
|
|
883
894
|
function transform2AnonymousFunction(node, options) {
|
|
884
895
|
if (node.body.type === 'BlockStatement')
|
|
885
|
-
(0, utils_1.throwError)('Anonymous function with block statement is not supported', node);
|
|
896
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function with block statement is not supported', node);
|
|
886
897
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
887
898
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
888
|
-
params: node.params.map((param) => transform2Param(param)),
|
|
899
|
+
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
889
900
|
body: transformNodeFunction(node.body, options),
|
|
890
901
|
});
|
|
891
902
|
}
|
|
@@ -914,7 +925,7 @@ function transform2Assignment(node, options) {
|
|
|
914
925
|
}
|
|
915
926
|
return new utils_1.naslTypes.Assignment({
|
|
916
927
|
left: transformNodeFunction(node.left, options),
|
|
917
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options)),
|
|
928
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options), options) || undefined,
|
|
918
929
|
});
|
|
919
930
|
}
|
|
920
931
|
exports.transform2Assignment = transform2Assignment;
|
|
@@ -960,10 +971,11 @@ function transform2NumericLiteral(node, options) {
|
|
|
960
971
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
961
972
|
});
|
|
962
973
|
literal.typeAnnotation.typeName = literal.changeType(value);
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
974
|
+
// 新版本依赖自转换
|
|
975
|
+
// if (options.typeAnnotation && ['Integer', 'Long', 'Decimal'].includes(options.typeAnnotation.typeName)) {
|
|
976
|
+
// literal.typeAnnotation = options.typeAnnotation;
|
|
977
|
+
// delete options.typeAnnotation;
|
|
978
|
+
// }
|
|
967
979
|
return literal;
|
|
968
980
|
}
|
|
969
981
|
exports.transform2NumericLiteral = transform2NumericLiteral;
|
|
@@ -991,15 +1003,15 @@ function transformReturnStatement2AssignmentOrEnd(node, options) {
|
|
|
991
1003
|
}
|
|
992
1004
|
}
|
|
993
1005
|
if (!logic.returns.length) {
|
|
994
|
-
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;
|
|
995
1007
|
logic.returns.push(new utils_1.naslTypes.Return({
|
|
996
1008
|
name: 'result',
|
|
997
1009
|
typeAnnotation
|
|
998
1010
|
}));
|
|
999
1011
|
}
|
|
1000
1012
|
const leftName = logic.returns[0].name;
|
|
1001
|
-
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options));
|
|
1002
|
-
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) {
|
|
1003
1015
|
return new utils_1.naslTypes.End();
|
|
1004
1016
|
}
|
|
1005
1017
|
else {
|
|
@@ -1142,7 +1154,7 @@ function transformNewExpression(node, options) {
|
|
|
1142
1154
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1143
1155
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1144
1156
|
}
|
|
1145
|
-
(0, utils_1.throwError)(
|
|
1157
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
1146
1158
|
}
|
|
1147
1159
|
exports.transformNewExpression = transformNewExpression;
|
|
1148
1160
|
function transformMemberExpression(node, options) {
|
|
@@ -1185,7 +1197,7 @@ function transformMemberExpression(node, options) {
|
|
|
1185
1197
|
const callCalleeName = (0, utils_1.generate)(callExpression)?.code;
|
|
1186
1198
|
let callResult = transformCall2CallViewElementLogic(callExpression, callCalleeName, callCallee, options);
|
|
1187
1199
|
const remainingCallee = callee.slice(1);
|
|
1188
|
-
if (remainingCallee.length > 0) {
|
|
1200
|
+
if (remainingCallee.length > 0 && callResult) {
|
|
1189
1201
|
return unflatMemberExpression(remainingCallee, options, callResult);
|
|
1190
1202
|
}
|
|
1191
1203
|
return callResult;
|
|
@@ -1272,7 +1284,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1272
1284
|
const arg = node.arguments[0];
|
|
1273
1285
|
const ifStatement = node.callee.body.body[0];
|
|
1274
1286
|
if (ifStatement.type !== 'IfStatement') {
|
|
1275
|
-
(0, utils_1.throwError)('Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1287
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1276
1288
|
}
|
|
1277
1289
|
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1278
1290
|
const match = new utils_1.naslTypes.Match({
|
|
@@ -1285,7 +1297,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1285
1297
|
argument = _case.consequent.body[0].argument;
|
|
1286
1298
|
}
|
|
1287
1299
|
else {
|
|
1288
|
-
(0, utils_1.throwError)('Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1300
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1289
1301
|
}
|
|
1290
1302
|
}
|
|
1291
1303
|
else {
|
|
@@ -1293,15 +1305,16 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1293
1305
|
argument = _case.consequent.argument;
|
|
1294
1306
|
}
|
|
1295
1307
|
else {
|
|
1296
|
-
(0, utils_1.throwError)('Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1308
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1297
1309
|
}
|
|
1298
1310
|
}
|
|
1311
|
+
const bodyNode = transformNodeFunction(argument, options);
|
|
1299
1312
|
return new utils_1.naslTypes.MatchCase({
|
|
1300
1313
|
isMatchedTypeEnumable: false,
|
|
1301
1314
|
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1302
|
-
body: [
|
|
1315
|
+
body: bodyNode ? [bodyNode] : [],
|
|
1303
1316
|
});
|
|
1304
|
-
}),
|
|
1317
|
+
}).filter(Boolean),
|
|
1305
1318
|
});
|
|
1306
1319
|
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1307
1320
|
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
@@ -1338,7 +1351,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1338
1351
|
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1339
1352
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1340
1353
|
if (options?.isRestricted)
|
|
1341
|
-
(0, utils_1.throwError)('
|
|
1354
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1342
1355
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1343
1356
|
const componentName = callee?.[1]?.name;
|
|
1344
1357
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1374,7 +1387,7 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1374
1387
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1375
1388
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1376
1389
|
if (options?.isRestricted)
|
|
1377
|
-
(0, utils_1.throwError)('
|
|
1390
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1378
1391
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1379
1392
|
// console.log('callee', callee);
|
|
1380
1393
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1388,7 +1401,7 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1388
1401
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1389
1402
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1390
1403
|
if (options?.isRestricted)
|
|
1391
|
-
(0, utils_1.throwError)('
|
|
1404
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1392
1405
|
if (calleeName?.includes('.entities.')) {
|
|
1393
1406
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1394
1407
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1448,9 +1461,9 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1448
1461
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1449
1462
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1450
1463
|
if (options?.isInFrontend)
|
|
1451
|
-
(0, utils_1.throwError)('OQL组件不支持在前端使用', node);
|
|
1464
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在前端使用', node);
|
|
1452
1465
|
if (options?.isRestricted)
|
|
1453
|
-
(0, utils_1.throwError)('OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1466
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1454
1467
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1455
1468
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1456
1469
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1460,13 +1473,13 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1460
1473
|
return new utils_1.naslTypes.OqlQueryComponent({
|
|
1461
1474
|
dataSource: 'app.dataSources.defaultDS',
|
|
1462
1475
|
code,
|
|
1463
|
-
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations)
|
|
1476
|
+
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations, options) || undefined,
|
|
1464
1477
|
});
|
|
1465
1478
|
}
|
|
1466
1479
|
}
|
|
1467
1480
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1468
1481
|
if (options?.isRestricted)
|
|
1469
|
-
(0, utils_1.throwError)('
|
|
1482
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1470
1483
|
return new utils_1.naslTypes.CallLogic({
|
|
1471
1484
|
calleeNamespace: 'nasl.logging',
|
|
1472
1485
|
calleeName: 'INFO',
|
|
@@ -1479,7 +1492,7 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1479
1492
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1480
1493
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1481
1494
|
if (options?.isRestricted)
|
|
1482
|
-
(0, utils_1.throwError)('
|
|
1495
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1483
1496
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1484
1497
|
expression: arg?.name === "undefined" ?
|
|
1485
1498
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1511,10 +1524,32 @@ function transformCall2JSONFunctions(node, calleeName, callee, options) {
|
|
|
1511
1524
|
keyword: 'arg',
|
|
1512
1525
|
}),
|
|
1513
1526
|
],
|
|
1514
|
-
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),
|
|
1515
1528
|
});
|
|
1516
1529
|
}
|
|
1517
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;
|
|
1518
1553
|
function transform2CallFunction(node, calleeName, argument, options) {
|
|
1519
1554
|
calleeName = utils_1.replaceCallFunctionMap?.[calleeName] || calleeName;
|
|
1520
1555
|
const func = server_1.default ? server_1.default.getBuildInFunction(calleeName) : null;
|
|
@@ -1528,12 +1563,17 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1528
1563
|
keyword: func && func?.params[index]?.name || `param${index + 1}`,
|
|
1529
1564
|
});
|
|
1530
1565
|
});
|
|
1531
|
-
let newTypeArguments = node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation);
|
|
1566
|
+
let newTypeArguments = node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean);
|
|
1532
1567
|
// if (calleeName === 'ListRepeat') {
|
|
1533
1568
|
// newTypeArguments = [
|
|
1534
1569
|
// new naslTypes.TypeAnnotation()
|
|
1535
1570
|
// ];
|
|
1536
1571
|
// }
|
|
1572
|
+
if (calleeName === 'Convert' && !newTypeArguments) {
|
|
1573
|
+
newTypeArguments = [
|
|
1574
|
+
new utils_1.naslTypes.TypeAnnotation()
|
|
1575
|
+
];
|
|
1576
|
+
}
|
|
1537
1577
|
if (calleeName === 'Concat') {
|
|
1538
1578
|
const expressions = newArguments.map((item) => item.expression);
|
|
1539
1579
|
return new utils_1.naslTypes.StringInterpolation({
|
|
@@ -1562,7 +1602,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1562
1602
|
const content = np?.toNaturalTS();
|
|
1563
1603
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1564
1604
|
if (!np && !p?.defaultExpression) {
|
|
1565
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1605
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1566
1606
|
}
|
|
1567
1607
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1568
1608
|
if (idx === 1) {
|
|
@@ -1595,7 +1635,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1595
1635
|
});
|
|
1596
1636
|
}
|
|
1597
1637
|
else {
|
|
1598
|
-
(0, utils_1.throwError)(`函数${calleeName}不存在`, node.callee);
|
|
1638
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}不存在`, node.callee, node);
|
|
1599
1639
|
}
|
|
1600
1640
|
if (!func.params?.length) {
|
|
1601
1641
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1617,7 +1657,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1617
1657
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1618
1658
|
const excludes = ['HasValue', 'ListSort'];
|
|
1619
1659
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1620
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1660
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1621
1661
|
}
|
|
1622
1662
|
else {
|
|
1623
1663
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1634,17 +1674,18 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1634
1674
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1635
1675
|
});
|
|
1636
1676
|
if (calleeName === 'ListSort') {
|
|
1637
|
-
|
|
1677
|
+
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1678
|
+
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1638
1679
|
}
|
|
1639
1680
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1640
|
-
(0, utils_1.throwError)('数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1681
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1641
1682
|
}
|
|
1642
1683
|
return nodeElement;
|
|
1643
1684
|
}
|
|
1644
1685
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1645
1686
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1646
1687
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1647
|
-
(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);
|
|
1648
1689
|
}
|
|
1649
1690
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1650
1691
|
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
@@ -1667,7 +1708,7 @@ function transform2SqlFunction(node, calleeName, argument, options) {
|
|
|
1667
1708
|
calleeNamespace: 'nasl.sqlFunction',
|
|
1668
1709
|
calleeName: utils_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1669
1710
|
arguments: [...addArguments, ...newArguments],
|
|
1670
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
1711
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1671
1712
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1672
1713
|
});
|
|
1673
1714
|
return nodeElement;
|
|
@@ -1745,7 +1786,10 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1745
1786
|
});
|
|
1746
1787
|
}
|
|
1747
1788
|
if (options?.isRestricted)
|
|
1748
|
-
(0, utils_1.throwError)('
|
|
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
|
+
}
|
|
1749
1793
|
return new utils_1.naslTypes.CallLogic({
|
|
1750
1794
|
calleeNamespace: 'nasl.ui',
|
|
1751
1795
|
calleeName: callee[2].name,
|
|
@@ -1782,11 +1826,11 @@ function transform2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1782
1826
|
each: transformNodeFunction(newCallee[0], options),
|
|
1783
1827
|
start: transformNodeFunction(newCallee[1], options),
|
|
1784
1828
|
end: newCallee[2]?.name === '__IDENTIFIER__' ? undefined : transformNodeFunction(newCallee[2], options),
|
|
1785
|
-
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({
|
|
1786
1830
|
name: 'item',
|
|
1787
1831
|
typeAnnotation: undefined,
|
|
1788
1832
|
}),
|
|
1789
|
-
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({
|
|
1790
1834
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 4)}`,
|
|
1791
1835
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1792
1836
|
}),
|
|
@@ -1813,8 +1857,8 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1813
1857
|
let endNode;
|
|
1814
1858
|
if (node?.right?.type === 'CallExpression') {
|
|
1815
1859
|
const rightNode = node?.right;
|
|
1816
|
-
const calleeName =
|
|
1817
|
-
const hasListEntries =
|
|
1860
|
+
const calleeName = (0, utils_1.generate)(rightNode.callee).code;
|
|
1861
|
+
const hasListEntries = ['ListEntries', 'nasl.util.ListEntries'].includes(calleeName);
|
|
1818
1862
|
const areaArguments = rightNode?.arguments;
|
|
1819
1863
|
eachNode = hasListEntries ? areaArguments?.[0] : rightNode;
|
|
1820
1864
|
startNode = hasListEntries ? areaArguments?.[1] : undefined;
|
|
@@ -1830,11 +1874,11 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1830
1874
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1831
1875
|
}),
|
|
1832
1876
|
end: endNode?.name === '__IDENTIFIER__' ? undefined : endNode ? transformNodeFunction(endNode, options) : undefined,
|
|
1833
|
-
item: itemNode ? transform2Param(itemNode) : new utils_1.naslTypes.Param({
|
|
1877
|
+
item: itemNode ? transform2Param(itemNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1834
1878
|
name: 'item',
|
|
1835
1879
|
typeAnnotation: undefined,
|
|
1836
1880
|
}),
|
|
1837
|
-
index: indexNode ? transform2Param(indexNode) : new utils_1.naslTypes.Param({
|
|
1881
|
+
index: indexNode ? transform2Param(indexNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1838
1882
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1839
1883
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1840
1884
|
}),
|
|
@@ -1854,8 +1898,8 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1854
1898
|
value: '0',
|
|
1855
1899
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1856
1900
|
}),
|
|
1857
|
-
item: transform2Param(arrowFunction.params[0]),
|
|
1858
|
-
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({
|
|
1859
1903
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1860
1904
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1861
1905
|
}),
|
|
@@ -1866,7 +1910,10 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1866
1910
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1867
1911
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1868
1912
|
if (options?.isRestricted)
|
|
1869
|
-
(0, utils_1.throwError)('
|
|
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
|
+
}
|
|
1870
1917
|
return new utils_1.naslTypes.CallLogic({
|
|
1871
1918
|
calleeNamespace: 'nasl.ui',
|
|
1872
1919
|
calleeName: 'showMessage',
|
|
@@ -1879,7 +1926,7 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1879
1926
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1880
1927
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1881
1928
|
if (options?.isRestricted)
|
|
1882
|
-
(0, utils_1.throwError)('调用接口不支持在组件或默认值表达式中使用', node);
|
|
1929
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1883
1930
|
return new utils_1.naslTypes.CallInterface({
|
|
1884
1931
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1885
1932
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1892,14 +1939,14 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1892
1939
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1893
1940
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1894
1941
|
if (options?.isRestricted)
|
|
1895
|
-
(0, utils_1.throwError)('调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1942
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1896
1943
|
let calleeConnectionName = undefined;
|
|
1897
1944
|
let calleeNamespace = undefined;
|
|
1898
1945
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1899
1946
|
if (callee.length === 5) {
|
|
1900
1947
|
const connectArg = callee[2].arguments[0];
|
|
1901
1948
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1902
|
-
(0, utils_1.throwError)('调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1949
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1903
1950
|
}
|
|
1904
1951
|
calleeConnectionName = connectArg.value;
|
|
1905
1952
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -1914,7 +1961,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1914
1961
|
calleeNamespace = calleeNamespacePrefix;
|
|
1915
1962
|
}
|
|
1916
1963
|
else {
|
|
1917
|
-
(0, utils_1.throwError)(`调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1964
|
+
return (0, utils_1.throwError)(options?.parsingId, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1918
1965
|
}
|
|
1919
1966
|
return new utils_1.naslTypes.CallConnector({
|
|
1920
1967
|
calleeConnectionName,
|
|
@@ -1928,7 +1975,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1928
1975
|
exports.transformCall2Connector = transformCall2Connector;
|
|
1929
1976
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
1930
1977
|
if (options?.isRestricted)
|
|
1931
|
-
(0, utils_1.throwError)('调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1978
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1932
1979
|
return new utils_1.naslTypes.CallLogic({
|
|
1933
1980
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
1934
1981
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -1940,24 +1987,24 @@ function transformCall2Extension(node, calleeName, callee, options) {
|
|
|
1940
1987
|
exports.transformCall2Extension = transformCall2Extension;
|
|
1941
1988
|
function transformTSAsExpression(node, options) {
|
|
1942
1989
|
if (node.expression.type === 'NumericLiteral') {
|
|
1943
|
-
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 });
|
|
1944
1991
|
}
|
|
1945
1992
|
else if (node.expression.type === 'ArrayExpression') {
|
|
1946
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation);
|
|
1993
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
1947
1994
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
1948
|
-
(0, utils_1.throwError)(`列表 as 必须为 List
|
|
1995
|
+
return (0, utils_1.throwError)(options?.parsingId, `列表 as 必须为 List 类型`, node);
|
|
1949
1996
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
1950
1997
|
}
|
|
1951
1998
|
else if (node.expression.type === 'NullLiteral') {
|
|
1952
1999
|
return transform2NullLiteral(node.expression, options);
|
|
1953
2000
|
}
|
|
1954
2001
|
else {
|
|
1955
|
-
(0, utils_1.throwError)('表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
2002
|
+
return (0, utils_1.throwError)(options?.parsingId, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
1956
2003
|
}
|
|
1957
2004
|
}
|
|
1958
2005
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
1959
2006
|
if (options?.isRestricted)
|
|
1960
|
-
(0, utils_1.throwError)('调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
2007
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
1961
2008
|
return new utils_1.naslTypes.CallLogic({
|
|
1962
2009
|
calleeNamespace: '',
|
|
1963
2010
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -1969,7 +2016,7 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
1969
2016
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
1970
2017
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
1971
2018
|
if (options?.isRestricted)
|
|
1972
|
-
(0, utils_1.throwError)('
|
|
2019
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1973
2020
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
1974
2021
|
// 未带前缀,补一下
|
|
1975
2022
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
@@ -1995,7 +2042,7 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
1995
2042
|
exports.transformCall2Logic = transformCall2Logic;
|
|
1996
2043
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
1997
2044
|
if (options?.isRestricted)
|
|
1998
|
-
(0, utils_1.throwError)('
|
|
2045
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1999
2046
|
return new utils_1.naslTypes.CallLogic({
|
|
2000
2047
|
calleeNamespace: `nasl.auth`,
|
|
2001
2048
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -2020,10 +2067,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2020
2067
|
const calleeName = node.callee.name;
|
|
2021
2068
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
2022
2069
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
2023
|
-
(0, utils_1.throwError)('FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1]);
|
|
2070
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
2024
2071
|
const arrowFunctionExpression = node.arguments[1];
|
|
2025
2072
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
2026
|
-
(0, utils_1.throwError)('FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body);
|
|
2073
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
2027
2074
|
const body = arrowFunctionExpression.body;
|
|
2028
2075
|
const callExpressions = flatChainCallExpression(body);
|
|
2029
2076
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -2033,13 +2080,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2033
2080
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
2034
2081
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
2035
2082
|
`;
|
|
2036
|
-
(0, utils_1.throwError)(error);
|
|
2083
|
+
return (0, utils_1.throwError)(options?.parsingId, error, node);
|
|
2037
2084
|
}
|
|
2038
2085
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
2039
2086
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
2040
2087
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
2041
2088
|
if (errorOrder) {
|
|
2042
|
-
(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);
|
|
2043
2090
|
}
|
|
2044
2091
|
const result = [{
|
|
2045
2092
|
calleeName: calleeName,
|
|
@@ -2051,7 +2098,7 @@ FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); /
|
|
|
2051
2098
|
result[0].arguments[2] = item.arguments[0];
|
|
2052
2099
|
}
|
|
2053
2100
|
else if (['INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(item.callee.name)) {
|
|
2054
|
-
result.push(...flatCallQueryComponentChainNode(item, options));
|
|
2101
|
+
result.push(...(flatCallQueryComponentChainNode(item, options) || []));
|
|
2055
2102
|
}
|
|
2056
2103
|
else {
|
|
2057
2104
|
result.push({
|
|
@@ -2084,37 +2131,39 @@ function flatOnExpressions(node) {
|
|
|
2084
2131
|
return [node];
|
|
2085
2132
|
}
|
|
2086
2133
|
}
|
|
2087
|
-
function transformMemberExpression2Entity(node, node2) {
|
|
2134
|
+
function transformMemberExpression2Entity(node, node2, options) {
|
|
2088
2135
|
const entityPath = flatMemberExpression(node);
|
|
2089
2136
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
2090
2137
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
2091
2138
|
if (!entityNamespace?.includes('.entities')) {
|
|
2092
|
-
(0, utils_1.throwError)(`${entityNamespace}.${entityName}
|
|
2139
|
+
return (0, utils_1.throwError)(options?.parsingId, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
2093
2140
|
}
|
|
2094
2141
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
2095
2142
|
if (asName) {
|
|
2096
|
-
(0, utils_1.throwError)(`FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2143
|
+
return (0, utils_1.throwError)(options?.parsingId, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2097
2144
|
}
|
|
2098
2145
|
return { entityNamespace, entityName, asName };
|
|
2099
2146
|
}
|
|
2100
2147
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2101
2148
|
if (options?.isInFrontend)
|
|
2102
|
-
(0, utils_1.throwError)('数据查询组件不支持在前端使用', node);
|
|
2149
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在前端使用', node);
|
|
2103
2150
|
if (options?.isRestricted)
|
|
2104
|
-
(0, utils_1.throwError)('数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
2151
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
2105
2152
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
2106
2153
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
2107
2154
|
if (code?.includes('nasl.util')) {
|
|
2108
|
-
(0, utils_1.throwError)('数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
2155
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
2109
2156
|
}
|
|
2110
2157
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
2111
|
-
(0, utils_1.throwError)('缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
2158
|
+
return (0, utils_1.throwError)(options?.parsingId, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
2112
2159
|
}
|
|
2113
2160
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
2114
|
-
|
|
2161
|
+
if (!flatted)
|
|
2162
|
+
return;
|
|
2163
|
+
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2115
2164
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
2116
2165
|
if (!isOrderCorrect) {
|
|
2117
|
-
(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);
|
|
2118
2167
|
}
|
|
2119
2168
|
let from;
|
|
2120
2169
|
let where;
|
|
@@ -2127,11 +2176,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2127
2176
|
let hasErrorTSScopeColumn = false;
|
|
2128
2177
|
let useResultItem = false;
|
|
2129
2178
|
// 这里只是一个示例,具体的逻辑需要根据flatted的内容来构建
|
|
2130
|
-
flatted.forEach((item) => {
|
|
2179
|
+
flatted && flatted.forEach((item) => {
|
|
2131
2180
|
// console.log(item.calleeName)
|
|
2132
2181
|
switch (item.calleeName) {
|
|
2133
2182
|
case 'FROM':
|
|
2134
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2183
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2184
|
+
if (!entity)
|
|
2185
|
+
return;
|
|
2135
2186
|
const entityName = entity.asName || entity.entityName;
|
|
2136
2187
|
entityAsNames.push(entityName);
|
|
2137
2188
|
from = new utils_1.naslTypes.QueryFromExpression({
|
|
@@ -2143,11 +2194,15 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2143
2194
|
case 'LEFT_JOIN':
|
|
2144
2195
|
case 'RIGHT_JOIN':
|
|
2145
2196
|
case 'OUTER_JOIN':
|
|
2146
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2197
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2198
|
+
if (!entity)
|
|
2199
|
+
break;
|
|
2147
2200
|
entityAsNames.push(entity.asName || entity.entityName);
|
|
2148
2201
|
const rawJoinType = item.calleeName.slice(0, -5);
|
|
2149
2202
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2150
2203
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2204
|
+
if (!from)
|
|
2205
|
+
return; // throwError(options?.parsingId, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2151
2206
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2152
2207
|
...entity,
|
|
2153
2208
|
joinType,
|
|
@@ -2164,14 +2219,14 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2164
2219
|
break;
|
|
2165
2220
|
case 'AGGR_SELECT':
|
|
2166
2221
|
if (groupBy?.length) {
|
|
2167
|
-
(0, utils_1.throwError)('存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2222
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2168
2223
|
}
|
|
2169
2224
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2170
2225
|
distinct: false,
|
|
2171
2226
|
star: true,
|
|
2172
2227
|
selectElements: [new utils_1.naslTypes.QueryFieldExpression({
|
|
2173
2228
|
isDotStar: true,
|
|
2174
|
-
entityAsName: from
|
|
2229
|
+
entityAsName: from?.entityName,
|
|
2175
2230
|
propertyName: '',
|
|
2176
2231
|
})],
|
|
2177
2232
|
});
|
|
@@ -2179,11 +2234,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2179
2234
|
item.arguments[0].properties?.forEach((arg) => {
|
|
2180
2235
|
if (arg?.value.type === 'CallExpression') {
|
|
2181
2236
|
let selectElements = transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2182
|
-
|
|
2183
|
-
|
|
2237
|
+
if (selectElements) {
|
|
2238
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2239
|
+
select.setSelectElements(newSelectElements);
|
|
2240
|
+
}
|
|
2184
2241
|
}
|
|
2185
2242
|
else {
|
|
2186
|
-
(0, utils_1.throwError)(`Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2243
|
+
return (0, utils_1.throwError)(options?.parsingId, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2187
2244
|
}
|
|
2188
2245
|
});
|
|
2189
2246
|
}
|
|
@@ -2198,11 +2255,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2198
2255
|
computed: false,
|
|
2199
2256
|
shorthand: false,
|
|
2200
2257
|
}, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2201
|
-
|
|
2202
|
-
|
|
2258
|
+
if (selectElements) {
|
|
2259
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2260
|
+
select.setSelectElements(newSelectElements);
|
|
2261
|
+
}
|
|
2203
2262
|
}
|
|
2204
2263
|
else {
|
|
2205
|
-
(0, utils_1.throwError)('Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2264
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2206
2265
|
}
|
|
2207
2266
|
break;
|
|
2208
2267
|
case 'SELECT':
|
|
@@ -2211,7 +2270,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2211
2270
|
star: true,
|
|
2212
2271
|
selectElements: groupBy?.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2213
2272
|
isDotStar: true,
|
|
2214
|
-
entityAsName: from
|
|
2273
|
+
entityAsName: from?.entityName,
|
|
2215
2274
|
propertyName: '',
|
|
2216
2275
|
})] : [],
|
|
2217
2276
|
});
|
|
@@ -2222,17 +2281,17 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2222
2281
|
}
|
|
2223
2282
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2224
2283
|
if (groupBy?.length) {
|
|
2225
|
-
(0, utils_1.throwError)('存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2284
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2226
2285
|
}
|
|
2227
2286
|
const originName = arg.key?.name || '';
|
|
2228
2287
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2229
2288
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2230
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}
|
|
2289
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2231
2290
|
}
|
|
2232
2291
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2233
2292
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2234
2293
|
if (!entityAsNames.includes(entityName)) {
|
|
2235
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}
|
|
2294
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2236
2295
|
}
|
|
2237
2296
|
selectElements = arg.value.properties?.map((property) => {
|
|
2238
2297
|
const columnAsName = property.key?.name;
|
|
@@ -2240,7 +2299,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2240
2299
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2241
2300
|
if (columnAsName !== columnPropertyName) {
|
|
2242
2301
|
// eg: comment: Topic_Comment.comment_stu
|
|
2243
|
-
(0, utils_1.throwError)(`SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}
|
|
2302
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2244
2303
|
}
|
|
2245
2304
|
selectElement.isDotStar = false;
|
|
2246
2305
|
return selectElement;
|
|
@@ -2250,6 +2309,9 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2250
2309
|
if (arg.value.type === 'MemberExpression') {
|
|
2251
2310
|
hasErrorTSScopeColumn = true;
|
|
2252
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
|
+
}
|
|
2253
2315
|
selectElements = [transform2SelectQueryFieldExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2254
2316
|
}
|
|
2255
2317
|
const selectElement = selectElements?.[0];
|
|
@@ -2275,7 +2337,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2275
2337
|
}
|
|
2276
2338
|
}
|
|
2277
2339
|
else {
|
|
2278
|
-
(0, utils_1.throwError)('HAVING 不符合规范,请使用箭头函数', havingNode);
|
|
2340
|
+
return (0, utils_1.throwError)(options?.parsingId, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2279
2341
|
}
|
|
2280
2342
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2281
2343
|
break;
|
|
@@ -2284,13 +2346,16 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2284
2346
|
let restOptionParams = { entityAsNames };
|
|
2285
2347
|
if (orderNode?.length === 1 && orderNode?.[0]?.type === 'ArrowFunctionExpression') {
|
|
2286
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
|
+
}
|
|
2287
2352
|
orderNode = orderNode?.[0]?.body?.elements;
|
|
2288
2353
|
if (params?.length && params?.[0]?.name) {
|
|
2289
2354
|
restOptionParams = { inOqlIdentifierNamespace: params?.[0]?.name, entityAsNames };
|
|
2290
2355
|
}
|
|
2291
2356
|
}
|
|
2292
2357
|
else {
|
|
2293
|
-
(0, utils_1.throwError)('ORDER_BY
|
|
2358
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数,并返回数组', orderNode, node);
|
|
2294
2359
|
}
|
|
2295
2360
|
orderBy = orderNode.map((arg) => {
|
|
2296
2361
|
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
@@ -2316,26 +2381,26 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2316
2381
|
ideVersion: '2.22',
|
|
2317
2382
|
});
|
|
2318
2383
|
if (hasErrorTSScopeColumn && !groupBy?.length && !having) {
|
|
2319
|
-
(0, utils_1.throwError)('SELECT 局部列不符合规范,需要按两层对象返回');
|
|
2384
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2320
2385
|
}
|
|
2321
2386
|
const hasScopeColumn = select?.selectElements?.find((selectElement) => selectElement?.concept === 'QueryFieldExpression' && !selectElement?.isDotStar);
|
|
2322
2387
|
if (hasScopeColumn && (groupBy?.length || having)) {
|
|
2323
|
-
(0, utils_1.throwError)('分组聚合与表字段局部列不允许同时出现');
|
|
2388
|
+
return (0, utils_1.throwError)(options?.parsingId, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2324
2389
|
}
|
|
2325
2390
|
if (hasScopeColumn && useResultItem) {
|
|
2326
|
-
(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);
|
|
2327
2392
|
}
|
|
2328
2393
|
const isOnlyAggr = select?.selectElements?.find((selectElement) => selectElement?.concept !== 'QueryAggregateExpression');
|
|
2329
2394
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2330
2395
|
if (!isOnlyAggr && !calleeNames?.includes('AGGR_SELECT')) {
|
|
2331
|
-
(0, utils_1.throwError)('SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2396
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2332
2397
|
}
|
|
2333
2398
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2334
2399
|
return callQueryComponent;
|
|
2335
2400
|
}
|
|
2336
2401
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2337
2402
|
if (options?.isRestricted)
|
|
2338
|
-
(0, utils_1.throwError)('调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2403
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2339
2404
|
const args = node.arguments;
|
|
2340
2405
|
const dataArg = args?.[0];
|
|
2341
2406
|
const procDefKeyArg = args?.[1];
|
|
@@ -2422,10 +2487,12 @@ function transform2LogicItem(node, options) {
|
|
|
2422
2487
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.logging.'), transformCall2Logging);
|
|
2423
2488
|
transformManager.registerCallExpression('nasl.util.jsonSerialize', transformCall2JSONFunctions);
|
|
2424
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);
|
|
2425
2491
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.forEach'), transformForEach2ForEachStatement);
|
|
2426
2492
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.util.'), transformCall2CallFunction);
|
|
2427
2493
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.auth.'), transformCall2LogicWithAuth);
|
|
2428
2494
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.ui.'), transform2UIFunction);
|
|
2495
|
+
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.browser.'), transform2CallOtherNASLLogic);
|
|
2429
2496
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.map'), transformMap2ListTransform);
|
|
2430
2497
|
transformManager.registerCallExpression('ForEach', transform2ForEachStatement);
|
|
2431
2498
|
transformManager.registerCallExpression('alert', transformAlert2ShowMessage);
|
|
@@ -2442,7 +2509,7 @@ function transform2LogicItem(node, options) {
|
|
|
2442
2509
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2443
2510
|
let result = transformManager.apply(node, options);
|
|
2444
2511
|
delete options.typeAnnotation;
|
|
2445
|
-
return result;
|
|
2512
|
+
return result || undefined;
|
|
2446
2513
|
}
|
|
2447
2514
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2448
2515
|
//# sourceMappingURL=transform2LogicItem.js.map
|