@lcap/nasl 4.3.0-creator.3 → 4.3.0-creator.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/generator/genSimpleBundleFile.js +1 -1
- package/out/generator/genSimpleBundleFile.js.map +1 -1
- package/out/natural/parseNaturalTS.d.ts +7 -0
- package/out/natural/parseNaturalTS.d.ts.map +1 -1
- package/out/natural/parseNaturalTS.js +93 -98
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +6 -17
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -1
- package/out/natural/parseNaturalTSXView.js +128 -59
- package/out/natural/parseNaturalTSXView.js.map +1 -1
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +4 -4
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts.map +1 -1
- package/out/natural/transformTSCode.js +8 -1
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/transform2Entity.d.ts +2 -4
- package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
- package/out/natural/transforms/transform2Entity.js +5 -5
- package/out/natural/transforms/transform2Entity.js.map +1 -1
- package/out/natural/transforms/transform2Enum.d.ts +2 -4
- package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
- package/out/natural/transforms/transform2Enum.js +5 -5
- package/out/natural/transforms/transform2Enum.js.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +2 -4
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js +4 -4
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
- package/out/natural/transforms/transform2Logic.d.ts +4 -10
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +3 -2
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +6 -6
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +198 -114
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +2 -4
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -1
- package/out/natural/transforms/transform2MetadataType.js +3 -3
- package/out/natural/transforms/transform2MetadataType.js.map +1 -1
- package/out/natural/transforms/transform2Structure.d.ts +2 -4
- package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
- package/out/natural/transforms/transform2Structure.js +5 -5
- package/out/natural/transforms/transform2Structure.js.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -4
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.js +10 -13
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts +2 -4
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.js +3 -3
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -1
- package/out/natural/transforms/transform2Variable.d.ts +3 -7
- 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 +3 -7
- 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 +99 -7
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +336 -14
- package/out/natural/transforms/utils.js.map +1 -1
- package/out/server/naslServer.d.ts +0 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +19 -8
- package/out/server/naslServer.js.map +1 -1
- package/out/service/initial/form-designer.d.ts +1 -1
- package/out/service/initial/form-designer.d.ts.map +1 -1
- package/out/service/initial/form-designer.js +2 -2
- package/out/service/initial/form-designer.js.map +1 -1
- package/out/service/initial/processV2.d.ts +1 -1
- package/out/service/initial/processV2.d.ts.map +1 -1
- package/out/service/initial/processV2.js +2 -2
- package/out/service/initial/processV2.js.map +1 -1
- package/out/service/initial/types.d.ts +1 -1
- package/out/service/initial/types.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -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
|
-
return (0, utils_1.throwError)(options
|
|
27
|
+
return (0, utils_1.throwError)(options, '不支持连续调用!', 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
|
-
return (0, utils_1.throwError)(options
|
|
40
|
+
return (0, utils_1.throwError)(options, '不支持连续调用!', 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
|
-
return (0, utils_1.throwError)(options
|
|
50
|
+
return (0, utils_1.throwError)(options, `不支持的节点类型 ${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
|
-
return (0, utils_1.throwError)(options
|
|
58
|
+
return (0, utils_1.throwError)(options, '不支持的节点类型', node.type, node);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -126,7 +126,7 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
126
126
|
}
|
|
127
127
|
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
128
128
|
if (expression?.concept === 'AnonymousFunction')
|
|
129
|
-
return (0, utils_1.throwError)(options
|
|
129
|
+
return (0, utils_1.throwError)(options, 'Anonymous function is not allowed in assignment');
|
|
130
130
|
return expression;
|
|
131
131
|
}
|
|
132
132
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -284,7 +284,7 @@ function transform2Param(node, options) {
|
|
|
284
284
|
name,
|
|
285
285
|
typeAnnotation,
|
|
286
286
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
287
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
287
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
288
288
|
}),
|
|
289
289
|
});
|
|
290
290
|
}
|
|
@@ -298,7 +298,7 @@ function transform2Param(node, options) {
|
|
|
298
298
|
name,
|
|
299
299
|
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
300
300
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
301
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
301
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
302
302
|
}),
|
|
303
303
|
});
|
|
304
304
|
}
|
|
@@ -313,7 +313,7 @@ function transform2Param(node, options) {
|
|
|
313
313
|
required: !node.optional,
|
|
314
314
|
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
315
315
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
316
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
316
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
317
317
|
}),
|
|
318
318
|
});
|
|
319
319
|
}
|
|
@@ -336,12 +336,12 @@ function transform2Param(node, options) {
|
|
|
336
336
|
name,
|
|
337
337
|
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
338
338
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
339
|
-
expression: transform2LogicItem(defaultValueExpression, {
|
|
339
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
340
340
|
}),
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
else {
|
|
344
|
-
return (0, utils_1.throwError)(options
|
|
344
|
+
return (0, utils_1.throwError)(options, '在输入参数中不支持节点类型', node);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
exports.transform2Param = transform2Param;
|
|
@@ -362,7 +362,7 @@ function transformCallExpressionToBinaryExpression(node, calleeName, callee, opt
|
|
|
362
362
|
};
|
|
363
363
|
const limitMap = ['STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'];
|
|
364
364
|
if (limitMap.includes(calleeName) && options.transformType === 'logic' && !options.inCallQueryComponentField) {
|
|
365
|
-
return (0, utils_1.throwError)(options
|
|
365
|
+
return (0, utils_1.throwError)(options, `${calleeName} 仅支持在数据查询中使用`, node);
|
|
366
366
|
}
|
|
367
367
|
if (calleeName === 'IS_NULL') {
|
|
368
368
|
return new utils_1.naslTypes.UnaryExpression({
|
|
@@ -449,7 +449,7 @@ function transform2BinaryExpression(node, options) {
|
|
|
449
449
|
right: transformNodeFunction(node.right, options),
|
|
450
450
|
});
|
|
451
451
|
}
|
|
452
|
-
return (0, utils_1.throwError)(options
|
|
452
|
+
return (0, utils_1.throwError)(options, '在二元表达式中不支持节点类型', node.type, node);
|
|
453
453
|
}
|
|
454
454
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
455
455
|
function transformDefaultExpression(node, options) {
|
|
@@ -462,7 +462,7 @@ function transformConditionalExpression(node, options) {
|
|
|
462
462
|
const expr = (0, utils_1.generate)(node.test)?.code;
|
|
463
463
|
const then_expr = (0, utils_1.generate)(node.consequent)?.code;
|
|
464
464
|
const else_expr = (0, utils_1.generate)(node.alternate)?.code;
|
|
465
|
-
return (0, utils_1.throwError)(options
|
|
465
|
+
return (0, utils_1.throwError)(options, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
466
466
|
}
|
|
467
467
|
const test = transformNodeFunction(node.test, options);
|
|
468
468
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
@@ -515,7 +515,7 @@ function transform2NewAnonymousStructure(node, options) {
|
|
|
515
515
|
item.naslType = currentType.typeAnnotation;
|
|
516
516
|
}
|
|
517
517
|
else {
|
|
518
|
-
return (0, utils_1.throwError)(options
|
|
518
|
+
return (0, utils_1.throwError)(options, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
else if (itemValue.type === 'TSAsExpression') {
|
|
@@ -556,7 +556,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
556
556
|
});
|
|
557
557
|
}
|
|
558
558
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
559
|
-
return (0, utils_1.throwError)(options
|
|
559
|
+
return (0, utils_1.throwError)(options, 'NewList 中不允许出现非数组表达式', node);
|
|
560
560
|
}
|
|
561
561
|
return new utils_1.naslTypes.NewList({
|
|
562
562
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
@@ -589,13 +589,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
589
589
|
const typeParam = node.typeParameters?.params[0];
|
|
590
590
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
591
591
|
if (!typeNamespaceAndName)
|
|
592
|
-
return (0, utils_1.throwError)(options
|
|
592
|
+
return (0, utils_1.throwError)(options, 'NewEntity 中必须指定类型', node);
|
|
593
593
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
594
594
|
}
|
|
595
595
|
if (calleeName === 'NewAnonymousStructure') {
|
|
596
596
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
597
597
|
}
|
|
598
|
-
return (0, utils_1.throwError)(options
|
|
598
|
+
return (0, utils_1.throwError)(options, '在新建表达式中不支持节点类型', node.type, node);
|
|
599
599
|
}
|
|
600
600
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
601
601
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -622,7 +622,7 @@ function transformBlockBody(body, options) {
|
|
|
622
622
|
return body.flatMap((item) => {
|
|
623
623
|
const logicItem = transformNodeFunction(item, options);
|
|
624
624
|
if (!logicItem) {
|
|
625
|
-
console.log('item in block:', item);
|
|
625
|
+
console.log('item in block:', (0, utils_1.generate)(item).code);
|
|
626
626
|
return [];
|
|
627
627
|
}
|
|
628
628
|
return item?.type === 'ReturnStatement' && item?.argument && logicItem.concept !== 'End' ? [logicItem, new utils_1.naslTypes.End()] : [logicItem];
|
|
@@ -825,7 +825,7 @@ function transformIdentifier(node, options) {
|
|
|
825
825
|
propertyName: '',
|
|
826
826
|
});
|
|
827
827
|
}
|
|
828
|
-
const placeholderMap = ['__IDENTIFIER__', '__LEFT__', '__RIGHT__', '__RIGHT', '__LEFT', '__IDENTIFIER'
|
|
828
|
+
const placeholderMap = ['__IDENTIFIER__', '__LEFT__', '__RIGHT__', '__RIGHT', '__LEFT', '__IDENTIFIER'];
|
|
829
829
|
if (placeholderMap.includes(node.name)) {
|
|
830
830
|
return new utils_1.naslTypes.Identifier({});
|
|
831
831
|
}
|
|
@@ -839,6 +839,9 @@ function transformIdentifier(node, options) {
|
|
|
839
839
|
}),
|
|
840
840
|
});
|
|
841
841
|
}
|
|
842
|
+
else if (node.name === 'undefined') {
|
|
843
|
+
return new utils_1.naslTypes.NullLiteral();
|
|
844
|
+
}
|
|
842
845
|
return new utils_1.naslTypes.Identifier({
|
|
843
846
|
name: node.name,
|
|
844
847
|
});
|
|
@@ -850,7 +853,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
850
853
|
if (expression.type === 'Identifier') {
|
|
851
854
|
const isSameName = (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name;
|
|
852
855
|
if (!isSameName) {
|
|
853
|
-
return (0, utils_1.throwError)(options
|
|
856
|
+
return (0, utils_1.throwError)(options, `字段名需为 ${(0, utils_2.firstLowerCase)(expression.name)}, 目前为: ${asNameNode.name}, 相关代码如下`, node);
|
|
854
857
|
}
|
|
855
858
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
856
859
|
isDotStar: true,
|
|
@@ -871,7 +874,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
871
874
|
// @TODO
|
|
872
875
|
}
|
|
873
876
|
else {
|
|
874
|
-
return (0, utils_1.throwError)(options
|
|
877
|
+
return (0, utils_1.throwError)(options, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
875
878
|
}
|
|
876
879
|
}
|
|
877
880
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -880,10 +883,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
880
883
|
const arg = callExpression.arguments[0];
|
|
881
884
|
if (arg.type !== 'MemberExpression') {
|
|
882
885
|
const code = (0, utils_1.generate)(arg).code;
|
|
883
|
-
return (0, utils_1.throwError)(options
|
|
886
|
+
return (0, utils_1.throwError)(options, `聚合函数的输入只能是表字段(实体.属性),但${callExpression.callee.name}(${code})中的${code}不是表字段`, node);
|
|
884
887
|
}
|
|
885
888
|
if (callExpression.arguments?.length > 1) {
|
|
886
|
-
return (0, utils_1.throwError)(options
|
|
889
|
+
return (0, utils_1.throwError)(options, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
887
890
|
}
|
|
888
891
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
889
892
|
asName: asNameNode.name,
|
|
@@ -893,7 +896,7 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
893
896
|
}
|
|
894
897
|
function transform2AnonymousFunction(node, options) {
|
|
895
898
|
if (node.body.type === 'BlockStatement')
|
|
896
|
-
return (0, utils_1.throwError)(options
|
|
899
|
+
return (0, utils_1.throwError)(options, 'Anonymous function with block statement is not supported', node);
|
|
897
900
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
898
901
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
899
902
|
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
@@ -1178,7 +1181,7 @@ function transformNewExpression(node, options) {
|
|
|
1178
1181
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1179
1182
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1180
1183
|
}
|
|
1181
|
-
return (0, utils_1.throwError)(options
|
|
1184
|
+
return (0, utils_1.throwError)(options, '在新建表达式中不支持节点类型', node.type, node);
|
|
1182
1185
|
}
|
|
1183
1186
|
exports.transformNewExpression = transformNewExpression;
|
|
1184
1187
|
function transformMemberExpression(node, options) {
|
|
@@ -1308,38 +1311,80 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1308
1311
|
const arg = node.arguments[0];
|
|
1309
1312
|
const ifStatement = node.callee.body.body[0];
|
|
1310
1313
|
if (ifStatement.type !== 'IfStatement') {
|
|
1311
|
-
return (0, utils_1.throwError)(options
|
|
1314
|
+
return (0, utils_1.throwError)(options, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1312
1315
|
}
|
|
1313
1316
|
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1317
|
+
let isExpression = options.transformType !== 'logic';
|
|
1314
1318
|
const match = new utils_1.naslTypes.Match({
|
|
1315
1319
|
expression: transformNodeFunction(arg, options),
|
|
1316
|
-
isExpression
|
|
1317
|
-
cases: flatedIfStatements.map((_case) => {
|
|
1320
|
+
isExpression,
|
|
1321
|
+
cases: flatedIfStatements.map((_case, index) => {
|
|
1318
1322
|
let argument;
|
|
1319
1323
|
if (_case.consequent.type === 'BlockStatement') {
|
|
1320
1324
|
if (_case.consequent.body.length === 1 && _case.consequent.body[0].type === 'ReturnStatement') {
|
|
1321
1325
|
argument = _case.consequent.body[0].argument;
|
|
1326
|
+
// 有一个 Return, match 就按 expression 处理
|
|
1327
|
+
isExpression = true;
|
|
1322
1328
|
}
|
|
1323
1329
|
else {
|
|
1324
|
-
|
|
1330
|
+
const isLastCase = index === flatedIfStatements.length - 1;
|
|
1331
|
+
let allowEmptyBody = false;
|
|
1332
|
+
if (isExpression) {
|
|
1333
|
+
if (isLastCase) {
|
|
1334
|
+
// 检查前面所有case的test属性,对布尔或者枚举类型特殊处理
|
|
1335
|
+
allowEmptyBody = flatedIfStatements
|
|
1336
|
+
.slice(0, index)
|
|
1337
|
+
.every((prevCase) => {
|
|
1338
|
+
if (!prevCase.test || prevCase.test.type !== 'BinaryExpression')
|
|
1339
|
+
return false;
|
|
1340
|
+
const testNode = prevCase.test;
|
|
1341
|
+
const right = testNode.right;
|
|
1342
|
+
// 检查right是否为BooleanLiteral
|
|
1343
|
+
if (right?.type === 'BooleanLiteral')
|
|
1344
|
+
return true;
|
|
1345
|
+
// 检查right是否为MemberExpression且包含app.enums
|
|
1346
|
+
if (right?.type === 'MemberExpression') {
|
|
1347
|
+
const rightCode = (0, utils_1.generate)(right).code;
|
|
1348
|
+
return rightCode.includes('app.enums');
|
|
1349
|
+
}
|
|
1350
|
+
return false;
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
if (!allowEmptyBody) {
|
|
1354
|
+
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
else {
|
|
1358
|
+
allowEmptyBody = true;
|
|
1359
|
+
}
|
|
1325
1360
|
}
|
|
1326
1361
|
}
|
|
1327
1362
|
else {
|
|
1328
1363
|
if (_case.consequent.type === 'ReturnStatement') {
|
|
1329
1364
|
argument = _case.consequent.argument;
|
|
1365
|
+
isExpression = true;
|
|
1330
1366
|
}
|
|
1331
1367
|
else {
|
|
1332
|
-
return (0, utils_1.throwError)(options
|
|
1368
|
+
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1333
1369
|
}
|
|
1334
1370
|
}
|
|
1335
|
-
|
|
1371
|
+
let bodyNode = transformNodeFunction(argument, options);
|
|
1372
|
+
let body = [];
|
|
1373
|
+
if (bodyNode) {
|
|
1374
|
+
body = [bodyNode];
|
|
1375
|
+
}
|
|
1376
|
+
if (!isExpression && _case.consequent.type === 'BlockStatement') {
|
|
1377
|
+
body = transformBlockBody(_case.consequent.body.filter((item) => item.type !== 'BreakStatement'), options);
|
|
1378
|
+
}
|
|
1336
1379
|
return new utils_1.naslTypes.MatchCase({
|
|
1337
1380
|
isMatchedTypeEnumable: false,
|
|
1338
1381
|
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1339
|
-
body
|
|
1382
|
+
body,
|
|
1340
1383
|
});
|
|
1341
1384
|
}).filter(Boolean),
|
|
1342
1385
|
});
|
|
1386
|
+
// 根据 toNaturalTS,有Return语句的默认为 expression
|
|
1387
|
+
match.isExpression = isExpression;
|
|
1343
1388
|
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1344
1389
|
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1345
1390
|
isMatchedTypeEnumable: false,
|
|
@@ -1349,7 +1394,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1349
1394
|
}
|
|
1350
1395
|
match.cases.forEach((case_) => {
|
|
1351
1396
|
if (case_.patterns.length) {
|
|
1352
|
-
if (case_.patterns[0].concept === 'BooleanLiteral'
|
|
1397
|
+
if (case_.patterns[0].concept === 'BooleanLiteral') {
|
|
1353
1398
|
case_.isMatchedTypeEnumable = true;
|
|
1354
1399
|
}
|
|
1355
1400
|
if (case_.patterns[0].concept === 'MemberExpression') {
|
|
@@ -1357,13 +1402,13 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1357
1402
|
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1358
1403
|
object: {
|
|
1359
1404
|
concept: 'Identifier',
|
|
1360
|
-
name: case_.patterns[0].object.
|
|
1405
|
+
name: case_.patterns[0].object.name,
|
|
1361
1406
|
folded: false,
|
|
1362
1407
|
namespace: 'app.enums'
|
|
1363
1408
|
},
|
|
1364
1409
|
property: {
|
|
1365
1410
|
concept: 'Identifier',
|
|
1366
|
-
name: case_.patterns[0].property.
|
|
1411
|
+
name: case_.patterns[0].property.name,
|
|
1367
1412
|
folded: false,
|
|
1368
1413
|
},
|
|
1369
1414
|
});
|
|
@@ -1375,7 +1420,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1375
1420
|
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1376
1421
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1377
1422
|
if (options?.isRestricted)
|
|
1378
|
-
return (0, utils_1.throwError)(options
|
|
1423
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1379
1424
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1380
1425
|
const componentName = callee?.[1]?.name;
|
|
1381
1426
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1411,7 +1456,7 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1411
1456
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1412
1457
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1413
1458
|
if (options?.isRestricted)
|
|
1414
|
-
return (0, utils_1.throwError)(options
|
|
1459
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1415
1460
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1416
1461
|
// console.log('callee', callee);
|
|
1417
1462
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1425,7 +1470,7 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1425
1470
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1426
1471
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1427
1472
|
if (options?.isRestricted)
|
|
1428
|
-
return (0, utils_1.throwError)(options
|
|
1473
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1429
1474
|
if (calleeName?.includes('.entities.')) {
|
|
1430
1475
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1431
1476
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1485,9 +1530,9 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1485
1530
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1486
1531
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1487
1532
|
if (options?.isInFrontend)
|
|
1488
|
-
return (0, utils_1.throwError)(options
|
|
1533
|
+
return (0, utils_1.throwError)(options, 'OQL组件不支持在前端使用', node);
|
|
1489
1534
|
if (options?.isRestricted)
|
|
1490
|
-
return (0, utils_1.throwError)(options
|
|
1535
|
+
return (0, utils_1.throwError)(options, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1491
1536
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1492
1537
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1493
1538
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1503,7 +1548,7 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1503
1548
|
}
|
|
1504
1549
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1505
1550
|
if (options?.isRestricted)
|
|
1506
|
-
return (0, utils_1.throwError)(options
|
|
1551
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1507
1552
|
return new utils_1.naslTypes.CallLogic({
|
|
1508
1553
|
calleeNamespace: 'nasl.logging',
|
|
1509
1554
|
calleeName: 'INFO',
|
|
@@ -1516,7 +1561,7 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1516
1561
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1517
1562
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1518
1563
|
if (options?.isRestricted)
|
|
1519
|
-
return (0, utils_1.throwError)(options
|
|
1564
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1520
1565
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1521
1566
|
expression: arg?.name === "undefined" ?
|
|
1522
1567
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1604,6 +1649,17 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1604
1649
|
expressions: expressions?.filter(Boolean),
|
|
1605
1650
|
});
|
|
1606
1651
|
}
|
|
1652
|
+
if (calleeName === 'Length') {
|
|
1653
|
+
const expressions = newArguments.map((item) => item.expression);
|
|
1654
|
+
if (expressions.length === 1) {
|
|
1655
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
1656
|
+
object: expressions[0],
|
|
1657
|
+
property: new utils_1.naslTypes.Identifier({
|
|
1658
|
+
name: 'length',
|
|
1659
|
+
}),
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1607
1663
|
if (calleeName === 'Convert' && !newTypeArguments) {
|
|
1608
1664
|
newTypeArguments = [
|
|
1609
1665
|
new utils_1.naslTypes.TypeAnnotation()
|
|
@@ -1631,7 +1687,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1631
1687
|
const content = np?.toNaturalTS();
|
|
1632
1688
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1633
1689
|
if (!np && !p?.defaultExpression) {
|
|
1634
|
-
return (0, utils_1.throwError)(options
|
|
1690
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1635
1691
|
}
|
|
1636
1692
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1637
1693
|
if (idx === 1) {
|
|
@@ -1664,7 +1720,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1664
1720
|
});
|
|
1665
1721
|
}
|
|
1666
1722
|
else {
|
|
1667
|
-
return (0, utils_1.throwError)(options
|
|
1723
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}不存在`, node.callee, node);
|
|
1668
1724
|
}
|
|
1669
1725
|
if (!func.params?.length) {
|
|
1670
1726
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1686,7 +1742,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1686
1742
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1687
1743
|
const excludes = ['HasValue', 'ListSort'];
|
|
1688
1744
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1689
|
-
return (0, utils_1.throwError)(options
|
|
1745
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1690
1746
|
}
|
|
1691
1747
|
else {
|
|
1692
1748
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1704,17 +1760,20 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1704
1760
|
});
|
|
1705
1761
|
if (calleeName === 'ListSort') {
|
|
1706
1762
|
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1763
|
+
if (handledNode === null) {
|
|
1764
|
+
return (0, utils_1.throwError)(options, 'ListSort 函数使用错误,ListSort 定义如下:export function ListSort<T>(list: List<T>, ...fns: ((item: T) => { asc: Boolean, by: Boolean | Long | Decimal | String | Date | Time | DateTime; })[]): List<T>;', node);
|
|
1765
|
+
}
|
|
1707
1766
|
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1708
1767
|
}
|
|
1709
1768
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1710
|
-
return (0, utils_1.throwError)(options
|
|
1769
|
+
return (0, utils_1.throwError)(options, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1711
1770
|
}
|
|
1712
1771
|
return nodeElement;
|
|
1713
1772
|
}
|
|
1714
1773
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1715
1774
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1716
1775
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1717
|
-
return (0, utils_1.throwError)(options
|
|
1776
|
+
return (0, utils_1.throwError)(options, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`, node.callee, node);
|
|
1718
1777
|
}
|
|
1719
1778
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1720
1779
|
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
@@ -1815,10 +1874,10 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1815
1874
|
});
|
|
1816
1875
|
}
|
|
1817
1876
|
if (options?.isRestricted)
|
|
1818
|
-
return (0, utils_1.throwError)(options
|
|
1819
|
-
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1820
|
-
|
|
1821
|
-
}
|
|
1877
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1878
|
+
// if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1879
|
+
// return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1880
|
+
// }
|
|
1822
1881
|
return new utils_1.naslTypes.CallLogic({
|
|
1823
1882
|
calleeNamespace: 'nasl.ui',
|
|
1824
1883
|
calleeName: callee[2].name,
|
|
@@ -1939,7 +1998,7 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1939
1998
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1940
1999
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1941
2000
|
if (options?.isRestricted)
|
|
1942
|
-
return (0, utils_1.throwError)(options
|
|
2001
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1943
2002
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1944
2003
|
return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1945
2004
|
}
|
|
@@ -1955,7 +2014,7 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1955
2014
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1956
2015
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1957
2016
|
if (options?.isRestricted)
|
|
1958
|
-
return (0, utils_1.throwError)(options
|
|
2017
|
+
return (0, utils_1.throwError)(options, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1959
2018
|
return new utils_1.naslTypes.CallInterface({
|
|
1960
2019
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1961
2020
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1968,14 +2027,14 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1968
2027
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1969
2028
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1970
2029
|
if (options?.isRestricted)
|
|
1971
|
-
return (0, utils_1.throwError)(options
|
|
2030
|
+
return (0, utils_1.throwError)(options, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1972
2031
|
let calleeConnectionName = undefined;
|
|
1973
2032
|
let calleeNamespace = undefined;
|
|
1974
2033
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1975
2034
|
if (callee.length === 5) {
|
|
1976
2035
|
const connectArg = callee[2].arguments[0];
|
|
1977
2036
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1978
|
-
return (0, utils_1.throwError)(options
|
|
2037
|
+
return (0, utils_1.throwError)(options, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1979
2038
|
}
|
|
1980
2039
|
calleeConnectionName = connectArg.value;
|
|
1981
2040
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -1990,7 +2049,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1990
2049
|
calleeNamespace = calleeNamespacePrefix;
|
|
1991
2050
|
}
|
|
1992
2051
|
else {
|
|
1993
|
-
return (0, utils_1.throwError)(options
|
|
2052
|
+
return (0, utils_1.throwError)(options, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1994
2053
|
}
|
|
1995
2054
|
return new utils_1.naslTypes.CallConnector({
|
|
1996
2055
|
calleeConnectionName,
|
|
@@ -2004,7 +2063,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
2004
2063
|
exports.transformCall2Connector = transformCall2Connector;
|
|
2005
2064
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
2006
2065
|
if (options?.isRestricted)
|
|
2007
|
-
return (0, utils_1.throwError)(options
|
|
2066
|
+
return (0, utils_1.throwError)(options, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
2008
2067
|
return new utils_1.naslTypes.CallLogic({
|
|
2009
2068
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
2010
2069
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -2021,19 +2080,19 @@ function transformTSAsExpression(node, options) {
|
|
|
2021
2080
|
else if (node.expression.type === 'ArrayExpression') {
|
|
2022
2081
|
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
2023
2082
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
2024
|
-
return (0, utils_1.throwError)(options
|
|
2083
|
+
return (0, utils_1.throwError)(options, `列表 as 必须为 List 类型`, node);
|
|
2025
2084
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
2026
2085
|
}
|
|
2027
2086
|
else if (node.expression.type === 'NullLiteral') {
|
|
2028
2087
|
return transform2NullLiteral(node.expression, options);
|
|
2029
2088
|
}
|
|
2030
2089
|
else {
|
|
2031
|
-
return (0, utils_1.throwError)(options
|
|
2090
|
+
return (0, utils_1.throwError)(options, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
2032
2091
|
}
|
|
2033
2092
|
}
|
|
2034
2093
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
2035
2094
|
if (options?.isRestricted)
|
|
2036
|
-
return (0, utils_1.throwError)(options
|
|
2095
|
+
return (0, utils_1.throwError)(options, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
2037
2096
|
return new utils_1.naslTypes.CallLogic({
|
|
2038
2097
|
calleeNamespace: '',
|
|
2039
2098
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -2045,7 +2104,7 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
2045
2104
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
2046
2105
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
2047
2106
|
if (options?.isRestricted)
|
|
2048
|
-
return (0, utils_1.throwError)(options
|
|
2107
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
2049
2108
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
2050
2109
|
// 未带前缀,补一下
|
|
2051
2110
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
@@ -2071,7 +2130,7 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
2071
2130
|
exports.transformCall2Logic = transformCall2Logic;
|
|
2072
2131
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
2073
2132
|
if (options?.isRestricted)
|
|
2074
|
-
return (0, utils_1.throwError)(options
|
|
2133
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
2075
2134
|
return new utils_1.naslTypes.CallLogic({
|
|
2076
2135
|
calleeNamespace: `nasl.auth`,
|
|
2077
2136
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -2096,10 +2155,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2096
2155
|
const calleeName = node.callee.name;
|
|
2097
2156
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
2098
2157
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
2099
|
-
return (0, utils_1.throwError)(options
|
|
2158
|
+
return (0, utils_1.throwError)(options, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
2100
2159
|
const arrowFunctionExpression = node.arguments[1];
|
|
2101
2160
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
2102
|
-
return (0, utils_1.throwError)(options
|
|
2161
|
+
return (0, utils_1.throwError)(options, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
2103
2162
|
const body = arrowFunctionExpression.body;
|
|
2104
2163
|
const callExpressions = flatChainCallExpression(body);
|
|
2105
2164
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -2109,13 +2168,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2109
2168
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
2110
2169
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
2111
2170
|
`;
|
|
2112
|
-
return (0, utils_1.throwError)(options
|
|
2171
|
+
return (0, utils_1.throwError)(options, error, node);
|
|
2113
2172
|
}
|
|
2114
2173
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
2115
2174
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
2116
2175
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
2117
2176
|
if (errorOrder) {
|
|
2118
|
-
return (0, utils_1.throwError)(options
|
|
2177
|
+
return (0, utils_1.throwError)(options, '调用顺序错误,期望的调用顺序为 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);
|
|
2119
2178
|
}
|
|
2120
2179
|
const result = [{
|
|
2121
2180
|
calleeName: calleeName,
|
|
@@ -2165,26 +2224,26 @@ function transformMemberExpression2Entity(node, node2, options) {
|
|
|
2165
2224
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
2166
2225
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
2167
2226
|
if (!entityNamespace?.includes('.entities')) {
|
|
2168
|
-
return (0, utils_1.throwError)(options
|
|
2227
|
+
return (0, utils_1.throwError)(options, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
2169
2228
|
}
|
|
2170
2229
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
2171
2230
|
if (asName) {
|
|
2172
|
-
return (0, utils_1.throwError)(options
|
|
2231
|
+
return (0, utils_1.throwError)(options, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2173
2232
|
}
|
|
2174
2233
|
return { entityNamespace, entityName, asName };
|
|
2175
2234
|
}
|
|
2176
2235
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2177
2236
|
if (options?.isInFrontend)
|
|
2178
|
-
return (0, utils_1.throwError)(options
|
|
2237
|
+
return (0, utils_1.throwError)(options, '数据查询组件不支持在前端使用', node);
|
|
2179
2238
|
if (options?.isRestricted)
|
|
2180
|
-
return (0, utils_1.throwError)(options
|
|
2239
|
+
return (0, utils_1.throwError)(options, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
2181
2240
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
2182
2241
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
2183
2242
|
if (code?.includes('nasl.util')) {
|
|
2184
|
-
return (0, utils_1.throwError)(options
|
|
2243
|
+
return (0, utils_1.throwError)(options, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
2185
2244
|
}
|
|
2186
2245
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
2187
|
-
return (0, utils_1.throwError)(options
|
|
2246
|
+
return (0, utils_1.throwError)(options, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
2188
2247
|
}
|
|
2189
2248
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
2190
2249
|
if (!flatted)
|
|
@@ -2192,7 +2251,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2192
2251
|
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2193
2252
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
2194
2253
|
if (!isOrderCorrect) {
|
|
2195
|
-
return (0, utils_1.throwError)(options
|
|
2254
|
+
return (0, utils_1.throwError)(options, '调用顺序错误,期望的调用顺序为 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);
|
|
2196
2255
|
}
|
|
2197
2256
|
let from;
|
|
2198
2257
|
let where;
|
|
@@ -2231,7 +2290,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2231
2290
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2232
2291
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2233
2292
|
if (!from)
|
|
2234
|
-
return; // throwError(options
|
|
2293
|
+
return; // throwError(options, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2235
2294
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2236
2295
|
...entity,
|
|
2237
2296
|
joinType,
|
|
@@ -2247,8 +2306,8 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2247
2306
|
}));
|
|
2248
2307
|
break;
|
|
2249
2308
|
case 'AGGR_SELECT':
|
|
2250
|
-
if (groupBy
|
|
2251
|
-
return (0, utils_1.throwError)(options
|
|
2309
|
+
if (groupBy.length) {
|
|
2310
|
+
return (0, utils_1.throwError)(options, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2252
2311
|
}
|
|
2253
2312
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2254
2313
|
distinct: false,
|
|
@@ -2269,7 +2328,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2269
2328
|
}
|
|
2270
2329
|
}
|
|
2271
2330
|
else {
|
|
2272
|
-
return (0, utils_1.throwError)(options
|
|
2331
|
+
return (0, utils_1.throwError)(options, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2273
2332
|
}
|
|
2274
2333
|
});
|
|
2275
2334
|
}
|
|
@@ -2290,37 +2349,41 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2290
2349
|
}
|
|
2291
2350
|
}
|
|
2292
2351
|
else {
|
|
2293
|
-
return (0, utils_1.throwError)(options
|
|
2352
|
+
return (0, utils_1.throwError)(options, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2294
2353
|
}
|
|
2295
2354
|
break;
|
|
2296
2355
|
case 'SELECT':
|
|
2297
2356
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2298
2357
|
distinct: false,
|
|
2299
2358
|
star: true,
|
|
2300
|
-
selectElements: groupBy
|
|
2359
|
+
selectElements: groupBy.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2301
2360
|
isDotStar: true,
|
|
2302
2361
|
entityAsName: from?.entityName,
|
|
2303
2362
|
propertyName: '',
|
|
2304
2363
|
})] : [],
|
|
2305
2364
|
});
|
|
2365
|
+
if (item.arguments[0].type !== 'ObjectExpression') {
|
|
2366
|
+
select = undefined;
|
|
2367
|
+
return (0, utils_1.throwError)(options, 'SELECT 参数应为 ObjectExpression,标准示例:.SELECT({ ... })', node);
|
|
2368
|
+
}
|
|
2306
2369
|
item.arguments[0].properties?.forEach((arg) => {
|
|
2307
2370
|
let selectElements = [];
|
|
2308
2371
|
if (arg.value.type === 'CallExpression') {
|
|
2309
2372
|
selectElements = [transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2310
2373
|
}
|
|
2311
2374
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2312
|
-
if (groupBy
|
|
2313
|
-
return (0, utils_1.throwError)(options
|
|
2375
|
+
if (groupBy.length) {
|
|
2376
|
+
return (0, utils_1.throwError)(options, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2314
2377
|
}
|
|
2315
2378
|
const originName = arg.key?.name || '';
|
|
2316
2379
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2317
2380
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2318
|
-
return (0, utils_1.throwError)(options
|
|
2381
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2319
2382
|
}
|
|
2320
2383
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2321
2384
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2322
2385
|
if (!entityAsNames.includes(entityName)) {
|
|
2323
|
-
return (0, utils_1.throwError)(options
|
|
2386
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2324
2387
|
}
|
|
2325
2388
|
selectElements = arg.value.properties?.map((property) => {
|
|
2326
2389
|
const columnAsName = property.key?.name;
|
|
@@ -2328,7 +2391,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2328
2391
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2329
2392
|
if (columnAsName !== columnPropertyName) {
|
|
2330
2393
|
// eg: comment: Topic_Comment.comment_stu
|
|
2331
|
-
return (0, utils_1.throwError)(options
|
|
2394
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2332
2395
|
}
|
|
2333
2396
|
selectElement.isDotStar = false;
|
|
2334
2397
|
return selectElement;
|
|
@@ -2339,7 +2402,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2339
2402
|
hasErrorTSScopeColumn = true;
|
|
2340
2403
|
}
|
|
2341
2404
|
if (arg.type === 'ObjectProperty' && select?.selectElements?.find(item => item?.concept === 'QueryFieldExpression' && item.entityAsName === arg.value?.name)) {
|
|
2342
|
-
return (0, utils_1.throwError)(options
|
|
2405
|
+
return (0, utils_1.throwError)(options, `SELECT 禁止在一次查询中对同一实体设置多个别名,请修改`, node);
|
|
2343
2406
|
}
|
|
2344
2407
|
selectElements = [transform2SelectQueryFieldExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2345
2408
|
}
|
|
@@ -2366,35 +2429,43 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2366
2429
|
}
|
|
2367
2430
|
}
|
|
2368
2431
|
else {
|
|
2369
|
-
return (0, utils_1.throwError)(options
|
|
2432
|
+
return (0, utils_1.throwError)(options, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2370
2433
|
}
|
|
2371
2434
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2372
2435
|
break;
|
|
2373
2436
|
case 'ORDER_BY':
|
|
2437
|
+
const ORDER_BY_ERROR_MESSAGE = `ORDER_BY 不符合规范,请使用箭头函数,并返回 Array<[字段值, "ASC" | "DESC"]> 的形式,示例:
|
|
2438
|
+
- .ORDER_BY((resultItem) => [[resultItem[sort], order]])
|
|
2439
|
+
- .ORDER_BY((resultItem) => [[Student.age, 'ASC'], [Student.name, 'DESC']])`;
|
|
2374
2440
|
let orderNode = item.arguments;
|
|
2375
2441
|
let restOptionParams = { entityAsNames };
|
|
2376
|
-
if (orderNode
|
|
2377
|
-
const params = orderNode
|
|
2378
|
-
if (orderNode
|
|
2379
|
-
return (0, utils_1.throwError)(options
|
|
2442
|
+
if (orderNode.length === 1 && orderNode[0].type === 'ArrowFunctionExpression') {
|
|
2443
|
+
const params = orderNode[0].params;
|
|
2444
|
+
if (orderNode[0].body.type !== 'ArrayExpression') {
|
|
2445
|
+
return (0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, orderNode, node);
|
|
2380
2446
|
}
|
|
2381
|
-
orderNode = orderNode
|
|
2382
|
-
if (params
|
|
2383
|
-
restOptionParams = { inOqlIdentifierNamespace: params
|
|
2447
|
+
orderNode = orderNode[0].body.elements;
|
|
2448
|
+
if (params.length && params[0].name) {
|
|
2449
|
+
restOptionParams = { inOqlIdentifierNamespace: params[0].name, entityAsNames };
|
|
2384
2450
|
}
|
|
2385
2451
|
}
|
|
2386
2452
|
else {
|
|
2387
|
-
return (0, utils_1.throwError)(options
|
|
2453
|
+
return (0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, orderNode, node);
|
|
2388
2454
|
}
|
|
2389
2455
|
orderBy = orderNode.map((arg) => {
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2456
|
+
if (arg.type === 'ArrayExpression') {
|
|
2457
|
+
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
2458
|
+
if (!useResultItem) {
|
|
2459
|
+
useResultItem = orderElementCode.includes('resultItem.');
|
|
2460
|
+
}
|
|
2461
|
+
return new utils_1.naslTypes.QueryOrderByExpression({
|
|
2462
|
+
orderElement: transformNodeFunction(arg.elements[0], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName }),
|
|
2463
|
+
order: transformNodeFunction(arg.elements[1], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName })
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
else {
|
|
2467
|
+
(0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, arg, node);
|
|
2393
2468
|
}
|
|
2394
|
-
return new utils_1.naslTypes.QueryOrderByExpression({
|
|
2395
|
-
orderElement: transformNodeFunction(arg.elements[0], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName }),
|
|
2396
|
-
order: transformNodeFunction(arg.elements[1], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName })
|
|
2397
|
-
});
|
|
2398
2469
|
});
|
|
2399
2470
|
break;
|
|
2400
2471
|
}
|
|
@@ -2409,27 +2480,30 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2409
2480
|
orderBy,
|
|
2410
2481
|
ideVersion: '2.22',
|
|
2411
2482
|
});
|
|
2412
|
-
if (
|
|
2413
|
-
return (0, utils_1.throwError)(options
|
|
2483
|
+
if (!select) {
|
|
2484
|
+
return (0, utils_1.throwError)(options, 'SELECT 不符合规范', node);
|
|
2485
|
+
}
|
|
2486
|
+
if (hasErrorTSScopeColumn && !groupBy.length && !having) {
|
|
2487
|
+
return (0, utils_1.throwError)(options, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2414
2488
|
}
|
|
2415
|
-
const hasScopeColumn = select
|
|
2416
|
-
if (hasScopeColumn && (groupBy
|
|
2417
|
-
return (0, utils_1.throwError)(options
|
|
2489
|
+
const hasScopeColumn = select.selectElements.find((selectElement) => selectElement.concept === 'QueryFieldExpression' && !selectElement.isDotStar);
|
|
2490
|
+
if (hasScopeColumn && (groupBy.length || having)) {
|
|
2491
|
+
return (0, utils_1.throwError)(options, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2418
2492
|
}
|
|
2419
2493
|
if (hasScopeColumn && useResultItem) {
|
|
2420
|
-
return (0, utils_1.throwError)(options
|
|
2494
|
+
return (0, utils_1.throwError)(options, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])", node);
|
|
2421
2495
|
}
|
|
2422
|
-
const
|
|
2496
|
+
const onlyAggr = select.selectElements.length && select.selectElements.every((selectElement) => selectElement.concept === 'QueryAggregateExpression');
|
|
2423
2497
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2424
|
-
if (
|
|
2425
|
-
return (0, utils_1.throwError)(options
|
|
2498
|
+
if (onlyAggr && !calleeNames.includes('AGGR_SELECT')) {
|
|
2499
|
+
return (0, utils_1.throwError)(options, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2426
2500
|
}
|
|
2427
2501
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2428
2502
|
return callQueryComponent;
|
|
2429
2503
|
}
|
|
2430
2504
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2431
2505
|
if (options?.isRestricted)
|
|
2432
|
-
return (0, utils_1.throwError)(options
|
|
2506
|
+
return (0, utils_1.throwError)(options, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2433
2507
|
const args = node.arguments;
|
|
2434
2508
|
const dataArg = args?.[0];
|
|
2435
2509
|
const procDefKeyArg = args?.[1];
|
|
@@ -2545,9 +2619,19 @@ function transform2LogicItem(node, options) {
|
|
|
2545
2619
|
transformManager.registerCallExpression('PAGINATE', transformCall2Paginate);
|
|
2546
2620
|
transformManager.registerCallExpression('FROM', transformCall2DataQuery);
|
|
2547
2621
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2622
|
+
try {
|
|
2623
|
+
let result = transformManager.apply(node, options);
|
|
2624
|
+
return result || undefined;
|
|
2625
|
+
}
|
|
2626
|
+
catch (err) {
|
|
2627
|
+
if (err.name === 'ParseNaturalTSError')
|
|
2628
|
+
throw err;
|
|
2629
|
+
(0, utils_1.throwError)(options, `解析逻辑发生异常:${err?.message}\n相关代码如下`, node);
|
|
2630
|
+
return undefined;
|
|
2631
|
+
}
|
|
2632
|
+
finally {
|
|
2633
|
+
delete options.typeAnnotation;
|
|
2634
|
+
}
|
|
2551
2635
|
}
|
|
2552
2636
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2553
2637
|
//# sourceMappingURL=transform2LogicItem.js.map
|