@lcap/nasl 4.1.0-creator.1 → 4.1.0-creator.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/nasl/error.ts +45 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/datasources/defaultDS/entities/StockFinancials.ts +89 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/datasources/defaultDS/entities/Stocks.ts +96 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/datasources/defaultDS.ts +5 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/enums/FinancialStatementType.ts +13 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/logics/getStockFinancialStatements.ts +62 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/roles/DEV-AdminRole.ts +5 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/sqlFunctions/dameng.ts +73 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/sqlFunctions/mysql.ts +67 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/sqlFunctions/oracle.ts +59 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/sqlFunctions/postgresql.ts +30 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/sqlFunctions/vastbase_pg.ts +28 -0
- package/out/debug/apps/24b6fb54-2871-4866-b64b-676bec0f7eb5/embedded/zystestnew/structures/FinancialDataItem.ts +9 -0
- package/out/debug/apps/anonymous/extension.component.ts +0 -0
- package/out/debug/apps/anonymous/nasl.ui.component.ts +7743 -0
- 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 +71 -67
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +12 -4
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -1
- package/out/natural/parseNaturalTSXView.js +107 -78
- 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 +4 -4
- 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 +2 -2
- 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 +9 -8
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +27 -25
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +138 -126
- 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/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
|
@@ -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,7 @@ 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
81
|
param && logic.addParam(param);
|
|
82
82
|
});
|
|
83
83
|
const newStatements = [];
|
|
@@ -121,9 +121,9 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
121
121
|
}
|
|
122
122
|
return logic;
|
|
123
123
|
}
|
|
124
|
-
function assertAssignmentRightIsNotAnonymousFunction(expression) {
|
|
124
|
+
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
125
125
|
if (expression?.concept === 'AnonymousFunction')
|
|
126
|
-
(0, utils_1.throwError)('Anonymous function is not allowed in assignment'
|
|
126
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function is not allowed in assignment');
|
|
127
127
|
return expression;
|
|
128
128
|
}
|
|
129
129
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -269,7 +269,7 @@ function fixLogicNode(node) {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
exports.fixLogicNode = fixLogicNode;
|
|
272
|
-
function transform2Param(node) {
|
|
272
|
+
function transform2Param(node, options) {
|
|
273
273
|
const exclude = ['event'];
|
|
274
274
|
if (node.type === 'ObjectProperty') {
|
|
275
275
|
const typeAnnotation = node?.value?.name ? utils_1.naslTypes.TypeAnnotation.createPrimitive((node?.value).name) : null;
|
|
@@ -281,7 +281,7 @@ function transform2Param(node) {
|
|
|
281
281
|
name,
|
|
282
282
|
typeAnnotation,
|
|
283
283
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
284
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
284
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
285
285
|
}),
|
|
286
286
|
});
|
|
287
287
|
}
|
|
@@ -293,9 +293,9 @@ function transform2Param(node) {
|
|
|
293
293
|
let defaultValueExpression = node.optional ? { type: 'NullLiteral' } : undefined;
|
|
294
294
|
return new utils_1.naslTypes.Param({
|
|
295
295
|
name,
|
|
296
|
-
typeAnnotation: typeAnnotation
|
|
296
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
297
297
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
298
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
298
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
299
299
|
}),
|
|
300
300
|
});
|
|
301
301
|
}
|
|
@@ -308,9 +308,9 @@ function transform2Param(node) {
|
|
|
308
308
|
return new utils_1.naslTypes.Param({
|
|
309
309
|
name,
|
|
310
310
|
required: !node.optional,
|
|
311
|
-
typeAnnotation: typeAnnotation
|
|
311
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
312
312
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
313
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
313
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
314
314
|
}),
|
|
315
315
|
});
|
|
316
316
|
}
|
|
@@ -331,14 +331,14 @@ function transform2Param(node) {
|
|
|
331
331
|
return null;
|
|
332
332
|
return new utils_1.naslTypes.Param({
|
|
333
333
|
name,
|
|
334
|
-
typeAnnotation: typeAnnotation
|
|
334
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
335
335
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
336
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr', isRestricted: true }),
|
|
336
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
337
337
|
}),
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
340
|
else {
|
|
341
|
-
(0, utils_1.throwError)(
|
|
341
|
+
return (0, utils_1.throwError)(options?.parsingId, '在输入参数中不支持节点类型', node);
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
exports.transform2Param = transform2Param;
|
|
@@ -442,7 +442,7 @@ function transform2BinaryExpression(node, options) {
|
|
|
442
442
|
right: transformNodeFunction(node.right, options),
|
|
443
443
|
});
|
|
444
444
|
}
|
|
445
|
-
(0, utils_1.throwError)(
|
|
445
|
+
return (0, utils_1.throwError)(options?.parsingId, '在二元表达式中不支持节点类型', node.type, node);
|
|
446
446
|
}
|
|
447
447
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
448
448
|
function transformDefaultExpression(node, options) {
|
|
@@ -455,7 +455,7 @@ function transformConditionalExpression(node, options) {
|
|
|
455
455
|
const expr = (0, utils_1.generate)(node.test)?.code;
|
|
456
456
|
const then_expr = (0, utils_1.generate)(node.consequent)?.code;
|
|
457
457
|
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})`);
|
|
458
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
459
459
|
}
|
|
460
460
|
const test = transformNodeFunction(node.test, options);
|
|
461
461
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
@@ -479,12 +479,12 @@ function transformConditionalExpression(node, options) {
|
|
|
479
479
|
cases: [
|
|
480
480
|
new utils_1.naslTypes.MatchCase({
|
|
481
481
|
patterns: [new utils_1.naslTypes.BooleanLiteral({ value: 'true' })],
|
|
482
|
-
body: [consequent],
|
|
482
|
+
body: consequent ? [consequent] : [],
|
|
483
483
|
isMatchedTypeEnumable: true,
|
|
484
484
|
}),
|
|
485
485
|
new utils_1.naslTypes.MatchCase({
|
|
486
486
|
patterns: [],
|
|
487
|
-
body: [alternate],
|
|
487
|
+
body: alternate ? [alternate] : [],
|
|
488
488
|
}),
|
|
489
489
|
],
|
|
490
490
|
});
|
|
@@ -495,7 +495,7 @@ function transformArrayExpression(node, options) {
|
|
|
495
495
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
496
496
|
return new utils_1.naslTypes.NewList({
|
|
497
497
|
typeAnnotation,
|
|
498
|
-
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })),
|
|
498
|
+
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })).filter(Boolean),
|
|
499
499
|
});
|
|
500
500
|
}
|
|
501
501
|
function transform2NewAnonymousStructure(node, options) {
|
|
@@ -508,11 +508,11 @@ function transform2NewAnonymousStructure(node, options) {
|
|
|
508
508
|
item.naslType = currentType.typeAnnotation;
|
|
509
509
|
}
|
|
510
510
|
else {
|
|
511
|
-
(0, utils_1.throwError)('
|
|
511
|
+
return (0, utils_1.throwError)(options?.parsingId, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
514
|
else if (itemValue.type === 'TSAsExpression') {
|
|
515
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation);
|
|
515
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation, options);
|
|
516
516
|
item.naslType = typeAnnotation;
|
|
517
517
|
}
|
|
518
518
|
}
|
|
@@ -545,15 +545,15 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
545
545
|
}
|
|
546
546
|
else {
|
|
547
547
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('List', {
|
|
548
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
548
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
551
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
552
|
-
(0, utils_1.throwError)('
|
|
552
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewList 中不允许出现非数组表达式', node);
|
|
553
553
|
}
|
|
554
554
|
return new utils_1.naslTypes.NewList({
|
|
555
555
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
556
|
-
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)),
|
|
556
|
+
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)).filter(Boolean),
|
|
557
557
|
});
|
|
558
558
|
}
|
|
559
559
|
if (calleeName === 'NewMap') {
|
|
@@ -569,7 +569,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
569
569
|
}
|
|
570
570
|
else {
|
|
571
571
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
572
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
572
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
573
573
|
});
|
|
574
574
|
}
|
|
575
575
|
return new utils_1.naslTypes.NewMap({
|
|
@@ -582,13 +582,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
582
582
|
const typeParam = node.typeParameters?.params[0];
|
|
583
583
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
584
584
|
if (!typeNamespaceAndName)
|
|
585
|
-
(0, utils_1.throwError)('
|
|
585
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewEntity 中必须指定类型', node);
|
|
586
586
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
587
587
|
}
|
|
588
588
|
if (calleeName === 'NewAnonymousStructure') {
|
|
589
589
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
590
590
|
}
|
|
591
|
-
(0, utils_1.throwError)(
|
|
591
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
592
592
|
}
|
|
593
593
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
594
594
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -653,7 +653,7 @@ function transform2ArrayPattern(decl, options) {
|
|
|
653
653
|
if (options.transformType === 'logic') {
|
|
654
654
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
655
655
|
name: element.name,
|
|
656
|
-
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation),
|
|
656
|
+
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined,
|
|
657
657
|
}));
|
|
658
658
|
}
|
|
659
659
|
}
|
|
@@ -696,7 +696,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
696
696
|
let typeAnnotation;
|
|
697
697
|
if (options.transformType === 'logic' && ![...options.logic.variables, ...options.logic.returns].some((variable) => variable.name === variableName)) {
|
|
698
698
|
const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
|
|
699
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
699
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
700
700
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
701
701
|
name: variableName,
|
|
702
702
|
typeAnnotation,
|
|
@@ -705,14 +705,14 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
705
705
|
if (decl.init) {
|
|
706
706
|
const calleeName = (0, utils_1.generate)(decl?.init?.callee).code;
|
|
707
707
|
const varTypeAnnotation = decl?.id?.typeAnnotation?.typeAnnotation;
|
|
708
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
708
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
709
709
|
if (calleeName === 'nasl.oql.query' && varTypeAnnotation) {
|
|
710
710
|
decl.init.typeAnnotations = varTypeAnnotation;
|
|
711
711
|
}
|
|
712
712
|
options.typeAnnotation = typeAnnotation;
|
|
713
713
|
newNode = new utils_1.naslTypes.Assignment({
|
|
714
714
|
left: transformNodeFunction(decl.id, options),
|
|
715
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation })),
|
|
715
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation }), options) || undefined,
|
|
716
716
|
});
|
|
717
717
|
}
|
|
718
718
|
});
|
|
@@ -860,7 +860,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
860
860
|
// @TODO
|
|
861
861
|
}
|
|
862
862
|
else {
|
|
863
|
-
(0, utils_1.throwError)('
|
|
863
|
+
return (0, utils_1.throwError)(options?.parsingId, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
864
864
|
}
|
|
865
865
|
}
|
|
866
866
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -869,10 +869,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
869
869
|
const arg = callExpression.arguments[0];
|
|
870
870
|
if (arg.type !== 'MemberExpression') {
|
|
871
871
|
const code = (0, utils_1.generate)(arg).code;
|
|
872
|
-
(0, utils_1.throwError)(`聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
872
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
873
873
|
}
|
|
874
874
|
if (callExpression.arguments?.length > 1) {
|
|
875
|
-
(0, utils_1.throwError)(`聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
875
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
876
876
|
}
|
|
877
877
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
878
878
|
asName: asNameNode.name,
|
|
@@ -882,10 +882,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
882
882
|
}
|
|
883
883
|
function transform2AnonymousFunction(node, options) {
|
|
884
884
|
if (node.body.type === 'BlockStatement')
|
|
885
|
-
(0, utils_1.throwError)('Anonymous function with block statement is not supported', node);
|
|
885
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function with block statement is not supported', node);
|
|
886
886
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
887
887
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
888
|
-
params: node.params.map((param) => transform2Param(param)),
|
|
888
|
+
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
889
889
|
body: transformNodeFunction(node.body, options),
|
|
890
890
|
});
|
|
891
891
|
}
|
|
@@ -914,7 +914,7 @@ function transform2Assignment(node, options) {
|
|
|
914
914
|
}
|
|
915
915
|
return new utils_1.naslTypes.Assignment({
|
|
916
916
|
left: transformNodeFunction(node.left, options),
|
|
917
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options)),
|
|
917
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options), options) || undefined,
|
|
918
918
|
});
|
|
919
919
|
}
|
|
920
920
|
exports.transform2Assignment = transform2Assignment;
|
|
@@ -991,15 +991,15 @@ function transformReturnStatement2AssignmentOrEnd(node, options) {
|
|
|
991
991
|
}
|
|
992
992
|
}
|
|
993
993
|
if (!logic.returns.length) {
|
|
994
|
-
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation) : undefined;
|
|
994
|
+
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation, options) || undefined : undefined;
|
|
995
995
|
logic.returns.push(new utils_1.naslTypes.Return({
|
|
996
996
|
name: 'result',
|
|
997
997
|
typeAnnotation
|
|
998
998
|
}));
|
|
999
999
|
}
|
|
1000
1000
|
const leftName = logic.returns[0].name;
|
|
1001
|
-
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options));
|
|
1002
|
-
if (right.concept === 'Identifier' && right.name === leftName) {
|
|
1001
|
+
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options), options) || undefined;
|
|
1002
|
+
if (right && right.concept === 'Identifier' && right.name === leftName) {
|
|
1003
1003
|
return new utils_1.naslTypes.End();
|
|
1004
1004
|
}
|
|
1005
1005
|
else {
|
|
@@ -1142,7 +1142,7 @@ function transformNewExpression(node, options) {
|
|
|
1142
1142
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1143
1143
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1144
1144
|
}
|
|
1145
|
-
(0, utils_1.throwError)(
|
|
1145
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
1146
1146
|
}
|
|
1147
1147
|
exports.transformNewExpression = transformNewExpression;
|
|
1148
1148
|
function transformMemberExpression(node, options) {
|
|
@@ -1185,7 +1185,7 @@ function transformMemberExpression(node, options) {
|
|
|
1185
1185
|
const callCalleeName = (0, utils_1.generate)(callExpression)?.code;
|
|
1186
1186
|
let callResult = transformCall2CallViewElementLogic(callExpression, callCalleeName, callCallee, options);
|
|
1187
1187
|
const remainingCallee = callee.slice(1);
|
|
1188
|
-
if (remainingCallee.length > 0) {
|
|
1188
|
+
if (remainingCallee.length > 0 && callResult) {
|
|
1189
1189
|
return unflatMemberExpression(remainingCallee, options, callResult);
|
|
1190
1190
|
}
|
|
1191
1191
|
return callResult;
|
|
@@ -1272,7 +1272,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1272
1272
|
const arg = node.arguments[0];
|
|
1273
1273
|
const ifStatement = node.callee.body.body[0];
|
|
1274
1274
|
if (ifStatement.type !== 'IfStatement') {
|
|
1275
|
-
(0, utils_1.throwError)('Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1275
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1276
1276
|
}
|
|
1277
1277
|
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1278
1278
|
const match = new utils_1.naslTypes.Match({
|
|
@@ -1285,7 +1285,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1285
1285
|
argument = _case.consequent.body[0].argument;
|
|
1286
1286
|
}
|
|
1287
1287
|
else {
|
|
1288
|
-
(0, utils_1.throwError)('Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1288
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1289
1289
|
}
|
|
1290
1290
|
}
|
|
1291
1291
|
else {
|
|
@@ -1293,15 +1293,16 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1293
1293
|
argument = _case.consequent.argument;
|
|
1294
1294
|
}
|
|
1295
1295
|
else {
|
|
1296
|
-
(0, utils_1.throwError)('Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1296
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1297
1297
|
}
|
|
1298
1298
|
}
|
|
1299
|
+
const bodyNode = transformNodeFunction(argument, options);
|
|
1299
1300
|
return new utils_1.naslTypes.MatchCase({
|
|
1300
1301
|
isMatchedTypeEnumable: false,
|
|
1301
1302
|
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1302
|
-
body: [
|
|
1303
|
+
body: bodyNode ? [bodyNode] : [],
|
|
1303
1304
|
});
|
|
1304
|
-
}),
|
|
1305
|
+
}).filter(Boolean),
|
|
1305
1306
|
});
|
|
1306
1307
|
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1307
1308
|
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
@@ -1338,7 +1339,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1338
1339
|
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1339
1340
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1340
1341
|
if (options?.isRestricted)
|
|
1341
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1342
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1342
1343
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1343
1344
|
const componentName = callee?.[1]?.name;
|
|
1344
1345
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1374,7 +1375,7 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1374
1375
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1375
1376
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1376
1377
|
if (options?.isRestricted)
|
|
1377
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1378
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1378
1379
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1379
1380
|
// console.log('callee', callee);
|
|
1380
1381
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1388,7 +1389,7 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1388
1389
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1389
1390
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1390
1391
|
if (options?.isRestricted)
|
|
1391
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1392
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1392
1393
|
if (calleeName?.includes('.entities.')) {
|
|
1393
1394
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1394
1395
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1448,9 +1449,9 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1448
1449
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1449
1450
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1450
1451
|
if (options?.isInFrontend)
|
|
1451
|
-
(0, utils_1.throwError)('OQL组件不支持在前端使用', node);
|
|
1452
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在前端使用', node);
|
|
1452
1453
|
if (options?.isRestricted)
|
|
1453
|
-
(0, utils_1.throwError)('OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1454
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1454
1455
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1455
1456
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1456
1457
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1460,13 +1461,13 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1460
1461
|
return new utils_1.naslTypes.OqlQueryComponent({
|
|
1461
1462
|
dataSource: 'app.dataSources.defaultDS',
|
|
1462
1463
|
code,
|
|
1463
|
-
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations)
|
|
1464
|
+
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations, options) || undefined,
|
|
1464
1465
|
});
|
|
1465
1466
|
}
|
|
1466
1467
|
}
|
|
1467
1468
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1468
1469
|
if (options?.isRestricted)
|
|
1469
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1470
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1470
1471
|
return new utils_1.naslTypes.CallLogic({
|
|
1471
1472
|
calleeNamespace: 'nasl.logging',
|
|
1472
1473
|
calleeName: 'INFO',
|
|
@@ -1479,7 +1480,7 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1479
1480
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1480
1481
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1481
1482
|
if (options?.isRestricted)
|
|
1482
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1483
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1483
1484
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1484
1485
|
expression: arg?.name === "undefined" ?
|
|
1485
1486
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1511,7 +1512,7 @@ function transformCall2JSONFunctions(node, calleeName, callee, options) {
|
|
|
1511
1512
|
keyword: 'arg',
|
|
1512
1513
|
}),
|
|
1513
1514
|
],
|
|
1514
|
-
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType })),
|
|
1515
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1515
1516
|
});
|
|
1516
1517
|
}
|
|
1517
1518
|
exports.transformCall2JSONFunctions = transformCall2JSONFunctions;
|
|
@@ -1528,7 +1529,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1528
1529
|
keyword: func && func?.params[index]?.name || `param${index + 1}`,
|
|
1529
1530
|
});
|
|
1530
1531
|
});
|
|
1531
|
-
let newTypeArguments = node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation);
|
|
1532
|
+
let newTypeArguments = node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean);
|
|
1532
1533
|
// if (calleeName === 'ListRepeat') {
|
|
1533
1534
|
// newTypeArguments = [
|
|
1534
1535
|
// new naslTypes.TypeAnnotation()
|
|
@@ -1562,7 +1563,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1562
1563
|
const content = np?.toNaturalTS();
|
|
1563
1564
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1564
1565
|
if (!np && !p?.defaultExpression) {
|
|
1565
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1566
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1566
1567
|
}
|
|
1567
1568
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1568
1569
|
if (idx === 1) {
|
|
@@ -1595,7 +1596,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1595
1596
|
});
|
|
1596
1597
|
}
|
|
1597
1598
|
else {
|
|
1598
|
-
(0, utils_1.throwError)(`函数${calleeName}不存在`, node.callee);
|
|
1599
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}不存在`, node.callee, node);
|
|
1599
1600
|
}
|
|
1600
1601
|
if (!func.params?.length) {
|
|
1601
1602
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1617,7 +1618,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1617
1618
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1618
1619
|
const excludes = ['HasValue', 'ListSort'];
|
|
1619
1620
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1620
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1621
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1621
1622
|
}
|
|
1622
1623
|
else {
|
|
1623
1624
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1634,17 +1635,18 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1634
1635
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1635
1636
|
});
|
|
1636
1637
|
if (calleeName === 'ListSort') {
|
|
1637
|
-
|
|
1638
|
+
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1639
|
+
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1638
1640
|
}
|
|
1639
1641
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1640
|
-
(0, utils_1.throwError)('数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1642
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1641
1643
|
}
|
|
1642
1644
|
return nodeElement;
|
|
1643
1645
|
}
|
|
1644
1646
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1645
1647
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1646
1648
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1647
|
-
(0, utils_1.throwError)(`数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}
|
|
1649
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`, node.callee, node);
|
|
1648
1650
|
}
|
|
1649
1651
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1650
1652
|
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
@@ -1667,7 +1669,7 @@ function transform2SqlFunction(node, calleeName, argument, options) {
|
|
|
1667
1669
|
calleeNamespace: 'nasl.sqlFunction',
|
|
1668
1670
|
calleeName: utils_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1669
1671
|
arguments: [...addArguments, ...newArguments],
|
|
1670
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
1672
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1671
1673
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1672
1674
|
});
|
|
1673
1675
|
return nodeElement;
|
|
@@ -1745,7 +1747,7 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1745
1747
|
});
|
|
1746
1748
|
}
|
|
1747
1749
|
if (options?.isRestricted)
|
|
1748
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1750
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1749
1751
|
return new utils_1.naslTypes.CallLogic({
|
|
1750
1752
|
calleeNamespace: 'nasl.ui',
|
|
1751
1753
|
calleeName: callee[2].name,
|
|
@@ -1782,11 +1784,11 @@ function transform2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1782
1784
|
each: transformNodeFunction(newCallee[0], options),
|
|
1783
1785
|
start: transformNodeFunction(newCallee[1], options),
|
|
1784
1786
|
end: newCallee[2]?.name === '__IDENTIFIER__' ? undefined : transformNodeFunction(newCallee[2], options),
|
|
1785
|
-
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0]) : new utils_1.naslTypes.Param({
|
|
1787
|
+
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0], options) || undefined : new utils_1.naslTypes.Param({
|
|
1786
1788
|
name: 'item',
|
|
1787
1789
|
typeAnnotation: undefined,
|
|
1788
1790
|
}),
|
|
1789
|
-
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1791
|
+
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1790
1792
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 4)}`,
|
|
1791
1793
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1792
1794
|
}),
|
|
@@ -1813,8 +1815,8 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1813
1815
|
let endNode;
|
|
1814
1816
|
if (node?.right?.type === 'CallExpression') {
|
|
1815
1817
|
const rightNode = node?.right;
|
|
1816
|
-
const calleeName =
|
|
1817
|
-
const hasListEntries =
|
|
1818
|
+
const calleeName = (0, utils_1.generate)(rightNode.callee).code;
|
|
1819
|
+
const hasListEntries = ['ListEntries', 'nasl.util.ListEntries'].includes(calleeName);
|
|
1818
1820
|
const areaArguments = rightNode?.arguments;
|
|
1819
1821
|
eachNode = hasListEntries ? areaArguments?.[0] : rightNode;
|
|
1820
1822
|
startNode = hasListEntries ? areaArguments?.[1] : undefined;
|
|
@@ -1830,11 +1832,11 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1830
1832
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1831
1833
|
}),
|
|
1832
1834
|
end: endNode?.name === '__IDENTIFIER__' ? undefined : endNode ? transformNodeFunction(endNode, options) : undefined,
|
|
1833
|
-
item: itemNode ? transform2Param(itemNode) : new utils_1.naslTypes.Param({
|
|
1835
|
+
item: itemNode ? transform2Param(itemNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1834
1836
|
name: 'item',
|
|
1835
1837
|
typeAnnotation: undefined,
|
|
1836
1838
|
}),
|
|
1837
|
-
index: indexNode ? transform2Param(indexNode) : new utils_1.naslTypes.Param({
|
|
1839
|
+
index: indexNode ? transform2Param(indexNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1838
1840
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1839
1841
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1840
1842
|
}),
|
|
@@ -1854,8 +1856,8 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1854
1856
|
value: '0',
|
|
1855
1857
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1856
1858
|
}),
|
|
1857
|
-
item: transform2Param(arrowFunction.params[0]),
|
|
1858
|
-
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1859
|
+
item: transform2Param(arrowFunction.params[0], options) || undefined,
|
|
1860
|
+
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1859
1861
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1860
1862
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1861
1863
|
}),
|
|
@@ -1866,7 +1868,7 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1866
1868
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1867
1869
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1868
1870
|
if (options?.isRestricted)
|
|
1869
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1871
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1870
1872
|
return new utils_1.naslTypes.CallLogic({
|
|
1871
1873
|
calleeNamespace: 'nasl.ui',
|
|
1872
1874
|
calleeName: 'showMessage',
|
|
@@ -1879,7 +1881,7 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1879
1881
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1880
1882
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1881
1883
|
if (options?.isRestricted)
|
|
1882
|
-
(0, utils_1.throwError)('调用接口不支持在组件或默认值表达式中使用', node);
|
|
1884
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1883
1885
|
return new utils_1.naslTypes.CallInterface({
|
|
1884
1886
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1885
1887
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1892,14 +1894,14 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1892
1894
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1893
1895
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1894
1896
|
if (options?.isRestricted)
|
|
1895
|
-
(0, utils_1.throwError)('调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1897
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1896
1898
|
let calleeConnectionName = undefined;
|
|
1897
1899
|
let calleeNamespace = undefined;
|
|
1898
1900
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1899
1901
|
if (callee.length === 5) {
|
|
1900
1902
|
const connectArg = callee[2].arguments[0];
|
|
1901
1903
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1902
|
-
(0, utils_1.throwError)('调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1904
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1903
1905
|
}
|
|
1904
1906
|
calleeConnectionName = connectArg.value;
|
|
1905
1907
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -1914,7 +1916,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1914
1916
|
calleeNamespace = calleeNamespacePrefix;
|
|
1915
1917
|
}
|
|
1916
1918
|
else {
|
|
1917
|
-
(0, utils_1.throwError)(`调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1919
|
+
return (0, utils_1.throwError)(options?.parsingId, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1918
1920
|
}
|
|
1919
1921
|
return new utils_1.naslTypes.CallConnector({
|
|
1920
1922
|
calleeConnectionName,
|
|
@@ -1928,7 +1930,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1928
1930
|
exports.transformCall2Connector = transformCall2Connector;
|
|
1929
1931
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
1930
1932
|
if (options?.isRestricted)
|
|
1931
|
-
(0, utils_1.throwError)('调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1933
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1932
1934
|
return new utils_1.naslTypes.CallLogic({
|
|
1933
1935
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
1934
1936
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -1940,24 +1942,24 @@ function transformCall2Extension(node, calleeName, callee, options) {
|
|
|
1940
1942
|
exports.transformCall2Extension = transformCall2Extension;
|
|
1941
1943
|
function transformTSAsExpression(node, options) {
|
|
1942
1944
|
if (node.expression.type === 'NumericLiteral') {
|
|
1943
|
-
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation) });
|
|
1945
|
+
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined });
|
|
1944
1946
|
}
|
|
1945
1947
|
else if (node.expression.type === 'ArrayExpression') {
|
|
1946
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation);
|
|
1948
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
1947
1949
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
1948
|
-
(0, utils_1.throwError)(`列表 as 必须为 List
|
|
1950
|
+
return (0, utils_1.throwError)(options?.parsingId, `列表 as 必须为 List 类型`, node);
|
|
1949
1951
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
1950
1952
|
}
|
|
1951
1953
|
else if (node.expression.type === 'NullLiteral') {
|
|
1952
1954
|
return transform2NullLiteral(node.expression, options);
|
|
1953
1955
|
}
|
|
1954
1956
|
else {
|
|
1955
|
-
(0, utils_1.throwError)('表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
1957
|
+
return (0, utils_1.throwError)(options?.parsingId, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
1956
1958
|
}
|
|
1957
1959
|
}
|
|
1958
1960
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
1959
1961
|
if (options?.isRestricted)
|
|
1960
|
-
(0, utils_1.throwError)('调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
1962
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
1961
1963
|
return new utils_1.naslTypes.CallLogic({
|
|
1962
1964
|
calleeNamespace: '',
|
|
1963
1965
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -1969,7 +1971,7 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
1969
1971
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
1970
1972
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
1971
1973
|
if (options?.isRestricted)
|
|
1972
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1974
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1973
1975
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
1974
1976
|
// 未带前缀,补一下
|
|
1975
1977
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
@@ -1995,7 +1997,7 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
1995
1997
|
exports.transformCall2Logic = transformCall2Logic;
|
|
1996
1998
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
1997
1999
|
if (options?.isRestricted)
|
|
1998
|
-
(0, utils_1.throwError)('调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
2000
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1999
2001
|
return new utils_1.naslTypes.CallLogic({
|
|
2000
2002
|
calleeNamespace: `nasl.auth`,
|
|
2001
2003
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -2020,10 +2022,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2020
2022
|
const calleeName = node.callee.name;
|
|
2021
2023
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
2022
2024
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
2023
|
-
(0, utils_1.throwError)('FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1]);
|
|
2025
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
2024
2026
|
const arrowFunctionExpression = node.arguments[1];
|
|
2025
2027
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
2026
|
-
(0, utils_1.throwError)('FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body);
|
|
2028
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
2027
2029
|
const body = arrowFunctionExpression.body;
|
|
2028
2030
|
const callExpressions = flatChainCallExpression(body);
|
|
2029
2031
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -2033,13 +2035,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2033
2035
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
2034
2036
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
2035
2037
|
`;
|
|
2036
|
-
(0, utils_1.throwError)(error);
|
|
2038
|
+
return (0, utils_1.throwError)(options?.parsingId, error, node);
|
|
2037
2039
|
}
|
|
2038
2040
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
2039
2041
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
2040
2042
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
2041
2043
|
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 的调用顺序。');
|
|
2044
|
+
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
2045
|
}
|
|
2044
2046
|
const result = [{
|
|
2045
2047
|
calleeName: calleeName,
|
|
@@ -2051,7 +2053,7 @@ FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); /
|
|
|
2051
2053
|
result[0].arguments[2] = item.arguments[0];
|
|
2052
2054
|
}
|
|
2053
2055
|
else if (['INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(item.callee.name)) {
|
|
2054
|
-
result.push(...flatCallQueryComponentChainNode(item, options));
|
|
2056
|
+
result.push(...flatCallQueryComponentChainNode(item, options) || []);
|
|
2055
2057
|
}
|
|
2056
2058
|
else {
|
|
2057
2059
|
result.push({
|
|
@@ -2084,37 +2086,37 @@ function flatOnExpressions(node) {
|
|
|
2084
2086
|
return [node];
|
|
2085
2087
|
}
|
|
2086
2088
|
}
|
|
2087
|
-
function transformMemberExpression2Entity(node, node2) {
|
|
2089
|
+
function transformMemberExpression2Entity(node, node2, options) {
|
|
2088
2090
|
const entityPath = flatMemberExpression(node);
|
|
2089
2091
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
2090
2092
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
2091
2093
|
if (!entityNamespace?.includes('.entities')) {
|
|
2092
|
-
(0, utils_1.throwError)(`${entityNamespace}.${entityName}
|
|
2094
|
+
return (0, utils_1.throwError)(options?.parsingId, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
2093
2095
|
}
|
|
2094
2096
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
2095
2097
|
if (asName) {
|
|
2096
|
-
(0, utils_1.throwError)(`FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2098
|
+
return (0, utils_1.throwError)(options?.parsingId, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2097
2099
|
}
|
|
2098
2100
|
return { entityNamespace, entityName, asName };
|
|
2099
2101
|
}
|
|
2100
2102
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2101
2103
|
if (options?.isInFrontend)
|
|
2102
|
-
(0, utils_1.throwError)('数据查询组件不支持在前端使用', node);
|
|
2104
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在前端使用', node);
|
|
2103
2105
|
if (options?.isRestricted)
|
|
2104
|
-
(0, utils_1.throwError)('数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
2106
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
2105
2107
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
2106
2108
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
2107
2109
|
if (code?.includes('nasl.util')) {
|
|
2108
|
-
(0, utils_1.throwError)('数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
2110
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
2109
2111
|
}
|
|
2110
2112
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
2111
|
-
(0, utils_1.throwError)('缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
2113
|
+
return (0, utils_1.throwError)(options?.parsingId, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
2112
2114
|
}
|
|
2113
2115
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
2114
|
-
const calleeNames = flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2116
|
+
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2115
2117
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
2116
2118
|
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 的调用顺序。');
|
|
2119
|
+
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
2120
|
}
|
|
2119
2121
|
let from;
|
|
2120
2122
|
let where;
|
|
@@ -2127,11 +2129,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2127
2129
|
let hasErrorTSScopeColumn = false;
|
|
2128
2130
|
let useResultItem = false;
|
|
2129
2131
|
// 这里只是一个示例,具体的逻辑需要根据flatted的内容来构建
|
|
2130
|
-
flatted.forEach((item) => {
|
|
2132
|
+
flatted && flatted.forEach((item) => {
|
|
2131
2133
|
// console.log(item.calleeName)
|
|
2132
2134
|
switch (item.calleeName) {
|
|
2133
2135
|
case 'FROM':
|
|
2134
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2136
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2137
|
+
if (!entity)
|
|
2138
|
+
return;
|
|
2135
2139
|
const entityName = entity.asName || entity.entityName;
|
|
2136
2140
|
entityAsNames.push(entityName);
|
|
2137
2141
|
from = new utils_1.naslTypes.QueryFromExpression({
|
|
@@ -2143,11 +2147,15 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2143
2147
|
case 'LEFT_JOIN':
|
|
2144
2148
|
case 'RIGHT_JOIN':
|
|
2145
2149
|
case 'OUTER_JOIN':
|
|
2146
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2150
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2151
|
+
if (!entity)
|
|
2152
|
+
break;
|
|
2147
2153
|
entityAsNames.push(entity.asName || entity.entityName);
|
|
2148
2154
|
const rawJoinType = item.calleeName.slice(0, -5);
|
|
2149
2155
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2150
2156
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2157
|
+
if (!from)
|
|
2158
|
+
return; // throwError(options?.parsingId, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2151
2159
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2152
2160
|
...entity,
|
|
2153
2161
|
joinType,
|
|
@@ -2164,14 +2172,14 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2164
2172
|
break;
|
|
2165
2173
|
case 'AGGR_SELECT':
|
|
2166
2174
|
if (groupBy?.length) {
|
|
2167
|
-
(0, utils_1.throwError)('存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2175
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2168
2176
|
}
|
|
2169
2177
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2170
2178
|
distinct: false,
|
|
2171
2179
|
star: true,
|
|
2172
2180
|
selectElements: [new utils_1.naslTypes.QueryFieldExpression({
|
|
2173
2181
|
isDotStar: true,
|
|
2174
|
-
entityAsName: from
|
|
2182
|
+
entityAsName: from?.entityName,
|
|
2175
2183
|
propertyName: '',
|
|
2176
2184
|
})],
|
|
2177
2185
|
});
|
|
@@ -2179,11 +2187,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2179
2187
|
item.arguments[0].properties?.forEach((arg) => {
|
|
2180
2188
|
if (arg?.value.type === 'CallExpression') {
|
|
2181
2189
|
let selectElements = transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2182
|
-
|
|
2183
|
-
|
|
2190
|
+
if (selectElements) {
|
|
2191
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2192
|
+
select.setSelectElements(newSelectElements);
|
|
2193
|
+
}
|
|
2184
2194
|
}
|
|
2185
2195
|
else {
|
|
2186
|
-
(0, utils_1.throwError)(`Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2196
|
+
return (0, utils_1.throwError)(options?.parsingId, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2187
2197
|
}
|
|
2188
2198
|
});
|
|
2189
2199
|
}
|
|
@@ -2198,11 +2208,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2198
2208
|
computed: false,
|
|
2199
2209
|
shorthand: false,
|
|
2200
2210
|
}, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2201
|
-
|
|
2202
|
-
|
|
2211
|
+
if (selectElements) {
|
|
2212
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2213
|
+
select.setSelectElements(newSelectElements);
|
|
2214
|
+
}
|
|
2203
2215
|
}
|
|
2204
2216
|
else {
|
|
2205
|
-
(0, utils_1.throwError)('Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2217
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2206
2218
|
}
|
|
2207
2219
|
break;
|
|
2208
2220
|
case 'SELECT':
|
|
@@ -2211,7 +2223,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2211
2223
|
star: true,
|
|
2212
2224
|
selectElements: groupBy?.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2213
2225
|
isDotStar: true,
|
|
2214
|
-
entityAsName: from
|
|
2226
|
+
entityAsName: from?.entityName,
|
|
2215
2227
|
propertyName: '',
|
|
2216
2228
|
})] : [],
|
|
2217
2229
|
});
|
|
@@ -2222,17 +2234,17 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2222
2234
|
}
|
|
2223
2235
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2224
2236
|
if (groupBy?.length) {
|
|
2225
|
-
(0, utils_1.throwError)('存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2237
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2226
2238
|
}
|
|
2227
2239
|
const originName = arg.key?.name || '';
|
|
2228
2240
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2229
2241
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2230
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}
|
|
2242
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2231
2243
|
}
|
|
2232
2244
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2233
2245
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2234
2246
|
if (!entityAsNames.includes(entityName)) {
|
|
2235
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}
|
|
2247
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2236
2248
|
}
|
|
2237
2249
|
selectElements = arg.value.properties?.map((property) => {
|
|
2238
2250
|
const columnAsName = property.key?.name;
|
|
@@ -2240,7 +2252,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2240
2252
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2241
2253
|
if (columnAsName !== columnPropertyName) {
|
|
2242
2254
|
// eg: comment: Topic_Comment.comment_stu
|
|
2243
|
-
(0, utils_1.throwError)(`SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}
|
|
2255
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2244
2256
|
}
|
|
2245
2257
|
selectElement.isDotStar = false;
|
|
2246
2258
|
return selectElement;
|
|
@@ -2275,7 +2287,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2275
2287
|
}
|
|
2276
2288
|
}
|
|
2277
2289
|
else {
|
|
2278
|
-
(0, utils_1.throwError)('HAVING 不符合规范,请使用箭头函数', havingNode);
|
|
2290
|
+
return (0, utils_1.throwError)(options?.parsingId, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2279
2291
|
}
|
|
2280
2292
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2281
2293
|
break;
|
|
@@ -2290,7 +2302,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2290
2302
|
}
|
|
2291
2303
|
}
|
|
2292
2304
|
else {
|
|
2293
|
-
(0, utils_1.throwError)('ORDER_BY 不符合规范,请使用箭头函数', orderNode);
|
|
2305
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数', orderNode, node);
|
|
2294
2306
|
}
|
|
2295
2307
|
orderBy = orderNode.map((arg) => {
|
|
2296
2308
|
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
@@ -2316,26 +2328,26 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2316
2328
|
ideVersion: '2.22',
|
|
2317
2329
|
});
|
|
2318
2330
|
if (hasErrorTSScopeColumn && !groupBy?.length && !having) {
|
|
2319
|
-
(0, utils_1.throwError)('SELECT 局部列不符合规范,需要按两层对象返回');
|
|
2331
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2320
2332
|
}
|
|
2321
2333
|
const hasScopeColumn = select?.selectElements?.find((selectElement) => selectElement?.concept === 'QueryFieldExpression' && !selectElement?.isDotStar);
|
|
2322
2334
|
if (hasScopeColumn && (groupBy?.length || having)) {
|
|
2323
|
-
(0, utils_1.throwError)('分组聚合与表字段局部列不允许同时出现');
|
|
2335
|
+
return (0, utils_1.throwError)(options?.parsingId, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2324
2336
|
}
|
|
2325
2337
|
if (hasScopeColumn && useResultItem) {
|
|
2326
|
-
(0, utils_1.throwError)("对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])");
|
|
2338
|
+
return (0, utils_1.throwError)(options?.parsingId, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])", node);
|
|
2327
2339
|
}
|
|
2328
2340
|
const isOnlyAggr = select?.selectElements?.find((selectElement) => selectElement?.concept !== 'QueryAggregateExpression');
|
|
2329
2341
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2330
2342
|
if (!isOnlyAggr && !calleeNames?.includes('AGGR_SELECT')) {
|
|
2331
|
-
(0, utils_1.throwError)('SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2343
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2332
2344
|
}
|
|
2333
2345
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2334
2346
|
return callQueryComponent;
|
|
2335
2347
|
}
|
|
2336
2348
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2337
2349
|
if (options?.isRestricted)
|
|
2338
|
-
(0, utils_1.throwError)('调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2350
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2339
2351
|
const args = node.arguments;
|
|
2340
2352
|
const dataArg = args?.[0];
|
|
2341
2353
|
const procDefKeyArg = args?.[1];
|
|
@@ -2442,7 +2454,7 @@ function transform2LogicItem(node, options) {
|
|
|
2442
2454
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2443
2455
|
let result = transformManager.apply(node, options);
|
|
2444
2456
|
delete options.typeAnnotation;
|
|
2445
|
-
return result;
|
|
2457
|
+
return result || undefined;
|
|
2446
2458
|
}
|
|
2447
2459
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2448
2460
|
//# sourceMappingURL=transform2LogicItem.js.map
|