@lcap/nasl 4.3.0-rc.4 → 4.4.0-beta.1
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/annotation/full.d.ts.map +1 -1
- package/out/generator/annotation/full.js +0 -32
- package/out/generator/annotation/full.js.map +1 -1
- package/out/generator/genBundleFiles.d.ts +1 -0
- package/out/generator/genBundleFiles.d.ts.map +1 -1
- package/out/generator/genBundleFiles.js +3 -2
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genSimpleBundleFile.d.ts +19 -0
- package/out/generator/genSimpleBundleFile.d.ts.map +1 -0
- package/out/generator/genSimpleBundleFile.js +114 -0
- package/out/generator/genSimpleBundleFile.js.map +1 -0
- package/out/generator/index.d.ts +1 -0
- package/out/generator/index.d.ts.map +1 -1
- package/out/generator/index.js +1 -0
- package/out/generator/index.js.map +1 -1
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +1 -0
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/manager/diagnostic.d.ts.map +1 -1
- package/out/manager/diagnostic.js +0 -1
- package/out/manager/diagnostic.js.map +1 -1
- package/out/natural/getContext/index.js +1 -1
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/index.d.ts +2 -0
- package/out/natural/index.d.ts.map +1 -1
- package/out/natural/index.js +4 -0
- package/out/natural/index.js.map +1 -1
- package/out/natural/parseNaturalTS.d.ts +5 -8
- package/out/natural/parseNaturalTS.d.ts.map +1 -1
- package/out/natural/parseNaturalTS.js +205 -54
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +7 -0
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -0
- package/out/natural/parseNaturalTSXView.js +722 -0
- package/out/natural/parseNaturalTSXView.js.map +1 -0
- package/out/natural/tools.js +2 -2
- package/out/natural/tools.js.map +1 -1
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +16 -25
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts.map +1 -1
- package/out/natural/transformTSCode.js +11 -4
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/transform2Entity.d.ts +2 -2
- package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
- package/out/natural/transforms/transform2Entity.js +31 -7
- package/out/natural/transforms/transform2Entity.js.map +1 -1
- package/out/natural/transforms/transform2Enum.d.ts +2 -2
- package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
- package/out/natural/transforms/transform2Enum.js +20 -4
- package/out/natural/transforms/transform2Enum.js.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +2 -2
- 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 -2
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +45 -8
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +63 -30
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +500 -222
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +3 -0
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -0
- package/out/natural/transforms/transform2MetadataType.js +14 -0
- package/out/natural/transforms/transform2MetadataType.js.map +1 -0
- package/out/natural/transforms/transform2Structure.d.ts +2 -2
- 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 -2
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.js +10 -14
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts +3 -0
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -0
- package/out/natural/transforms/transform2ValidationRule.js +24 -0
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -0
- package/out/natural/transforms/transform2Variable.d.ts +3 -2
- package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
- package/out/natural/transforms/transform2Variable.js +30 -6
- package/out/natural/transforms/transform2Variable.js.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.d.ts +24 -0
- package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -0
- package/out/natural/transforms/transformThemeAndStyle.js +269 -0
- package/out/natural/transforms/transformThemeAndStyle.js.map +1 -0
- package/out/natural/transforms/utils.d.ts +37 -3
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +95 -13
- package/out/natural/transforms/utils.js.map +1 -1
- package/out/server/OQL/oql-cache.js +1 -1
- package/out/server/OQL/oql-cache.js.map +1 -1
- package/out/server/OQL/sqlCategory.json +410 -0
- package/out/server/OQL/sqlFunctions.json +695 -7
- package/out/server/OQL/utils.d.ts +1 -0
- package/out/server/OQL/utils.d.ts.map +1 -1
- package/out/server/OQL/utils.js +1 -0
- package/out/server/OQL/utils.js.map +1 -1
- package/out/server/index.d.ts +1 -0
- package/out/server/index.d.ts.map +1 -1
- package/out/server/index.js +1 -0
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +4 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +39 -11
- package/out/server/naslServer.js.map +1 -1
- package/out/service/initial/form-designer.d.ts +1 -1
- package/out/service/initial/form-designer.d.ts.map +1 -1
- package/out/service/initial/form-designer.js +4 -1
- package/out/service/initial/form-designer.js.map +1 -1
- package/out/service/initial/processV2.d.ts +1 -1
- package/out/service/initial/processV2.d.ts.map +1 -1
- package/out/service/initial/processV2.js +4 -1
- package/out/service/initial/processV2.js.map +1 -1
- package/out/service/initial/types.d.ts +1 -0
- package/out/service/initial/types.d.ts.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +3 -6
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -1
- package/package.json +14 -12
- package/sandbox/stdlib/nasl.oql.ts +1 -0
- package/sandbox/stdlib/nasl.util.ts +9 -0
- package/out/natural/transforms/registerTransform.d.ts +0 -8
- package/out/natural/transforms/registerTransform.d.ts.map +0 -1
- package/out/natural/transforms/registerTransform.js +0 -24
- package/out/natural/transforms/registerTransform.js.map +0 -1
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.transform2LogicItem = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = exports.
|
|
6
|
+
exports.transformAlert2ShowMessage = exports.transformForEach2ForEachStatement = exports.transformForOf2ForEachStatement = exports.transform2ForEachStatement = exports.transformMap2ListTransform = exports.transform2UIFunction = exports.transformCall2CallFunction = exports.transform2CallFunction = exports.transform2CallOtherNASLLogic = exports.transform2CallEventLogic = exports.transformCall2JSONFunctions = exports.transformCall2Logging = exports.transformCall2ConsoleLog = exports.transformCall2CallDataSourceLogic = exports.transformCall2CallEntityLogic = exports.transformCall2CallViewElementLogic = exports.transformCallFunctionExpression2Match = exports.transformMemberExpression = exports.transformNewExpression = exports.transform2NewRegex = exports.transform2PartialNewComposite = exports.transform2Comment = exports.transform2StringInterpolation = exports.transformReturnStatement2AssignmentOrEnd = exports.transform2NullLiteral = exports.transform2NumericLiteral = exports.transform2DirectiveLiteral = exports.transform2StringLiteral = exports.transform2BooleanLiteral = exports.transformUpdateExpression2Assignment = exports.transform2Assignment = exports.transform2AnonymousFunction = exports.transformIdentifier = exports.transformSwitchStatement2Match = exports.transform2WhileStatement = exports.transform2Break = exports.transform2Continue = exports.transform2IfStatement = exports.transform2BinaryExpression = exports.transform2VariadicExpression = exports.transformCallExpressionToBinaryExpression = exports.transform2Param = exports.fixLogicNode = exports.flatIfStatementForMatch = exports.flatMatchPatternsExpression = exports.getSelectMembers = exports.unflatMemberExpression = exports.flatMemberExpression = exports.fixExpression = exports.TransformManager = void 0;
|
|
7
|
+
exports.transform2LogicItem = exports.transformNode2Directory = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = exports.transformCall2Extension = exports.transformCall2Connector = exports.transformCall2Interface = void 0;
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const transform2TypeAnnotation_1 = require("./transform2TypeAnnotation");
|
|
10
10
|
const utils_2 = require("../../utils");
|
|
@@ -24,7 +24,7 @@ class TransformManager {
|
|
|
24
24
|
apply(node, options) {
|
|
25
25
|
if (node.type === 'CallExpression') {
|
|
26
26
|
if (node.callee.type === 'CallExpression')
|
|
27
|
-
(0, utils_1.throwError)(
|
|
27
|
+
return (0, utils_1.throwError)(options, '不支持连续调用!', node.callee);
|
|
28
28
|
const callee = flatMemberExpression(node.callee);
|
|
29
29
|
if (callee[0]
|
|
30
30
|
&& callee[0].type === 'CallExpression'
|
|
@@ -36,9 +36,8 @@ class TransformManager {
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
for (const calleeItem of callee) {
|
|
39
|
-
if (calleeItem.type !== 'Identifier') {
|
|
40
|
-
|
|
41
|
-
(0, utils_1.throwError)(`不支持连续调用!${calleeName}`);
|
|
39
|
+
if (calleeItem.type !== 'Identifier' && !(calleeItem.type === 'FunctionExpression' && calleeItem.id?.name === 'match')) {
|
|
40
|
+
return (0, utils_1.throwError)(options, '不支持连续调用!', node.callee);
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
@@ -48,7 +47,7 @@ class TransformManager {
|
|
|
48
47
|
return transform(node, calleeName, callee, options);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
(0, utils_1.throwError)(
|
|
50
|
+
return (0, utils_1.throwError)(options, `不支持的节点类型 ${callee.map((item) => item.name).join('.')}`, node.type, node);
|
|
52
51
|
}
|
|
53
52
|
else {
|
|
54
53
|
for (const [type, transform] of this.transforms) {
|
|
@@ -56,7 +55,7 @@ class TransformManager {
|
|
|
56
55
|
return transform(node, options);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
(0, utils_1.throwError)(
|
|
58
|
+
return (0, utils_1.throwError)(options, '不支持的节点类型', node.type, node);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
}
|
|
@@ -78,7 +77,10 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
78
77
|
statements = [...node?.body?.directives, ...node?.body?.body];
|
|
79
78
|
}
|
|
80
79
|
parameters.forEach((node) => {
|
|
81
|
-
const param = transform2Param(node);
|
|
80
|
+
const param = transform2Param(node, options);
|
|
81
|
+
if (param && !param?.typeAnnotation) {
|
|
82
|
+
param.typeAnnotation = null;
|
|
83
|
+
}
|
|
82
84
|
param && logic.addParam(param);
|
|
83
85
|
});
|
|
84
86
|
const newStatements = [];
|
|
@@ -122,9 +124,9 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
122
124
|
}
|
|
123
125
|
return logic;
|
|
124
126
|
}
|
|
125
|
-
function assertAssignmentRightIsNotAnonymousFunction(expression) {
|
|
127
|
+
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
126
128
|
if (expression?.concept === 'AnonymousFunction')
|
|
127
|
-
(0, utils_1.throwError)('Anonymous function is not allowed in assignment');
|
|
129
|
+
return (0, utils_1.throwError)(options, 'Anonymous function is not allowed in assignment');
|
|
128
130
|
return expression;
|
|
129
131
|
}
|
|
130
132
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -243,13 +245,18 @@ function flatMatchPatternsExpression(node) {
|
|
|
243
245
|
return [node];
|
|
244
246
|
}
|
|
245
247
|
exports.flatMatchPatternsExpression = flatMatchPatternsExpression;
|
|
246
|
-
function
|
|
248
|
+
function flatIfStatementForMatch(node) {
|
|
247
249
|
if (node.alternate.type === 'IfStatement') {
|
|
248
|
-
return [...
|
|
250
|
+
return [node, ...flatIfStatementForMatch(node.alternate)];
|
|
249
251
|
}
|
|
250
|
-
return [node
|
|
252
|
+
return [node, {
|
|
253
|
+
type: 'IfStatement',
|
|
254
|
+
test: null,
|
|
255
|
+
consequent: node.alternate,
|
|
256
|
+
alternate: node.alternate,
|
|
257
|
+
}];
|
|
251
258
|
}
|
|
252
|
-
exports.
|
|
259
|
+
exports.flatIfStatementForMatch = flatIfStatementForMatch;
|
|
253
260
|
/**
|
|
254
261
|
* 这个函数是修复 AI 翻译出错的情况,与正常的 transform 做个区分
|
|
255
262
|
* @param node
|
|
@@ -265,7 +272,7 @@ function fixLogicNode(node) {
|
|
|
265
272
|
}
|
|
266
273
|
}
|
|
267
274
|
exports.fixLogicNode = fixLogicNode;
|
|
268
|
-
function transform2Param(node) {
|
|
275
|
+
function transform2Param(node, options) {
|
|
269
276
|
const exclude = ['event'];
|
|
270
277
|
if (node.type === 'ObjectProperty') {
|
|
271
278
|
const typeAnnotation = node?.value?.name ? utils_1.naslTypes.TypeAnnotation.createPrimitive((node?.value).name) : null;
|
|
@@ -277,7 +284,7 @@ function transform2Param(node) {
|
|
|
277
284
|
name,
|
|
278
285
|
typeAnnotation,
|
|
279
286
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
280
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
287
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
281
288
|
}),
|
|
282
289
|
});
|
|
283
290
|
}
|
|
@@ -289,9 +296,9 @@ function transform2Param(node) {
|
|
|
289
296
|
let defaultValueExpression = node.optional ? { type: 'NullLiteral' } : undefined;
|
|
290
297
|
return new utils_1.naslTypes.Param({
|
|
291
298
|
name,
|
|
292
|
-
typeAnnotation: typeAnnotation
|
|
299
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
293
300
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
294
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
301
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
295
302
|
}),
|
|
296
303
|
});
|
|
297
304
|
}
|
|
@@ -304,9 +311,9 @@ function transform2Param(node) {
|
|
|
304
311
|
return new utils_1.naslTypes.Param({
|
|
305
312
|
name,
|
|
306
313
|
required: !node.optional,
|
|
307
|
-
typeAnnotation: typeAnnotation
|
|
314
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
308
315
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
309
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
316
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
310
317
|
}),
|
|
311
318
|
});
|
|
312
319
|
}
|
|
@@ -327,14 +334,14 @@ function transform2Param(node) {
|
|
|
327
334
|
return null;
|
|
328
335
|
return new utils_1.naslTypes.Param({
|
|
329
336
|
name,
|
|
330
|
-
typeAnnotation: typeAnnotation
|
|
337
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
331
338
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
332
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
339
|
+
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
333
340
|
}),
|
|
334
341
|
});
|
|
335
342
|
}
|
|
336
343
|
else {
|
|
337
|
-
(0, utils_1.throwError)(
|
|
344
|
+
return (0, utils_1.throwError)(options, '在输入参数中不支持节点类型', node);
|
|
338
345
|
}
|
|
339
346
|
}
|
|
340
347
|
exports.transform2Param = transform2Param;
|
|
@@ -353,6 +360,16 @@ function transformCallExpressionToBinaryExpression(node, calleeName, callee, opt
|
|
|
353
360
|
IN: 'in',
|
|
354
361
|
IS_NULL: 'isNull',
|
|
355
362
|
};
|
|
363
|
+
const limitMap = ['STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'];
|
|
364
|
+
if (limitMap.includes(calleeName) && options.transformType === 'logic' && !options.inCallQueryComponentField) {
|
|
365
|
+
return (0, utils_1.throwError)(options, `${calleeName} 仅支持在数据查询中使用`, node);
|
|
366
|
+
}
|
|
367
|
+
if (calleeName === 'IS_NULL') {
|
|
368
|
+
return new utils_1.naslTypes.UnaryExpression({
|
|
369
|
+
operator: 'isNull',
|
|
370
|
+
argument: transformNodeFunction(argument?.[0], options),
|
|
371
|
+
});
|
|
372
|
+
}
|
|
356
373
|
return new utils_1.naslTypes.BinaryExpression({
|
|
357
374
|
operator: map[calleeName],
|
|
358
375
|
left: transformNodeFunction(argument?.[0], options),
|
|
@@ -432,11 +449,21 @@ function transform2BinaryExpression(node, options) {
|
|
|
432
449
|
right: transformNodeFunction(node.right, options),
|
|
433
450
|
});
|
|
434
451
|
}
|
|
435
|
-
(0, utils_1.throwError)(
|
|
452
|
+
return (0, utils_1.throwError)(options, '在二元表达式中不支持节点类型', node.type, node);
|
|
436
453
|
}
|
|
437
454
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
455
|
+
function transformDefaultExpression(node, options) {
|
|
456
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
457
|
+
return transformNodeFunction(node.left, options);
|
|
458
|
+
}
|
|
438
459
|
function transformConditionalExpression(node, options) {
|
|
439
460
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
461
|
+
if (options?.inCallQueryComponentField) {
|
|
462
|
+
const expr = (0, utils_1.generate)(node.test)?.code;
|
|
463
|
+
const then_expr = (0, utils_1.generate)(node.consequent)?.code;
|
|
464
|
+
const else_expr = (0, utils_1.generate)(node.alternate)?.code;
|
|
465
|
+
return (0, utils_1.throwError)(options, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
466
|
+
}
|
|
440
467
|
const test = transformNodeFunction(node.test, options);
|
|
441
468
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
442
469
|
const alternate = transformNodeFunction(node.alternate, options);
|
|
@@ -459,12 +486,12 @@ function transformConditionalExpression(node, options) {
|
|
|
459
486
|
cases: [
|
|
460
487
|
new utils_1.naslTypes.MatchCase({
|
|
461
488
|
patterns: [new utils_1.naslTypes.BooleanLiteral({ value: 'true' })],
|
|
462
|
-
body: [consequent],
|
|
489
|
+
body: consequent ? [consequent] : [],
|
|
463
490
|
isMatchedTypeEnumable: true,
|
|
464
491
|
}),
|
|
465
492
|
new utils_1.naslTypes.MatchCase({
|
|
466
493
|
patterns: [],
|
|
467
|
-
body: [alternate],
|
|
494
|
+
body: alternate ? [alternate] : [],
|
|
468
495
|
}),
|
|
469
496
|
],
|
|
470
497
|
});
|
|
@@ -475,17 +502,34 @@ function transformArrayExpression(node, options) {
|
|
|
475
502
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
476
503
|
return new utils_1.naslTypes.NewList({
|
|
477
504
|
typeAnnotation,
|
|
478
|
-
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })),
|
|
505
|
+
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })).filter(Boolean),
|
|
479
506
|
});
|
|
480
507
|
}
|
|
481
508
|
function transform2NewAnonymousStructure(node, options) {
|
|
509
|
+
for (let i = 0; i < node.properties.length; i++) {
|
|
510
|
+
const item = node.properties[i];
|
|
511
|
+
const itemValue = item?.value;
|
|
512
|
+
if (itemValue.type === 'NullLiteral') {
|
|
513
|
+
const currentType = options?.typeAnnotation?.properties?.[i];
|
|
514
|
+
if (currentType?.typeAnnotation) {
|
|
515
|
+
item.naslType = currentType.typeAnnotation;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
return (0, utils_1.throwError)(options, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
else if (itemValue.type === 'TSAsExpression') {
|
|
522
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation, options);
|
|
523
|
+
item.naslType = typeAnnotation;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
482
526
|
const newComposite = transform2PartialNewComposite(node, options);
|
|
483
527
|
const newProperties = node.properties.filter((prop) => prop.type === 'ObjectProperty' && prop.value.type !== 'ConditionalExpression');
|
|
484
528
|
const structureProperties = [];
|
|
485
529
|
newProperties.forEach((arg, index) => {
|
|
486
530
|
structureProperties.push(new utils_1.naslTypes.StructureProperty({
|
|
487
531
|
name: arg.key.name,
|
|
488
|
-
typeAnnotation: null
|
|
532
|
+
typeAnnotation: arg.naslType || null,
|
|
489
533
|
}));
|
|
490
534
|
});
|
|
491
535
|
newComposite.typeAnnotation = utils_1.naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties);
|
|
@@ -508,15 +552,15 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
508
552
|
}
|
|
509
553
|
else {
|
|
510
554
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('List', {
|
|
511
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
555
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
512
556
|
});
|
|
513
557
|
}
|
|
514
558
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
515
|
-
(0, utils_1.throwError)(
|
|
559
|
+
return (0, utils_1.throwError)(options, 'NewList 中不允许出现非数组表达式', node);
|
|
516
560
|
}
|
|
517
561
|
return new utils_1.naslTypes.NewList({
|
|
518
562
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
519
|
-
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)),
|
|
563
|
+
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)).filter(Boolean),
|
|
520
564
|
});
|
|
521
565
|
}
|
|
522
566
|
if (calleeName === 'NewMap') {
|
|
@@ -532,7 +576,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
532
576
|
}
|
|
533
577
|
else {
|
|
534
578
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
535
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
579
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
536
580
|
});
|
|
537
581
|
}
|
|
538
582
|
return new utils_1.naslTypes.NewMap({
|
|
@@ -545,13 +589,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
545
589
|
const typeParam = node.typeParameters?.params[0];
|
|
546
590
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
547
591
|
if (!typeNamespaceAndName)
|
|
548
|
-
(0, utils_1.throwError)(
|
|
592
|
+
return (0, utils_1.throwError)(options, 'NewEntity 中必须指定类型', node);
|
|
549
593
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
550
594
|
}
|
|
551
595
|
if (calleeName === 'NewAnonymousStructure') {
|
|
552
596
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
553
597
|
}
|
|
554
|
-
(0, utils_1.throwError)(
|
|
598
|
+
return (0, utils_1.throwError)(options, '在新建表达式中不支持节点类型', node.type, node);
|
|
555
599
|
}
|
|
556
600
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
557
601
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -578,7 +622,7 @@ function transformBlockBody(body, options) {
|
|
|
578
622
|
return body.flatMap((item) => {
|
|
579
623
|
const logicItem = transformNodeFunction(item, options);
|
|
580
624
|
if (!logicItem) {
|
|
581
|
-
console.log('item in block:', item);
|
|
625
|
+
console.log('item in block:', (0, utils_1.generate)(item).code);
|
|
582
626
|
return [];
|
|
583
627
|
}
|
|
584
628
|
return item?.type === 'ReturnStatement' && item?.argument && logicItem.concept !== 'End' ? [logicItem, new utils_1.naslTypes.End()] : [logicItem];
|
|
@@ -616,7 +660,7 @@ function transform2ArrayPattern(decl, options) {
|
|
|
616
660
|
if (options.transformType === 'logic') {
|
|
617
661
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
618
662
|
name: element.name,
|
|
619
|
-
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation),
|
|
663
|
+
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined,
|
|
620
664
|
}));
|
|
621
665
|
}
|
|
622
666
|
}
|
|
@@ -648,7 +692,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
648
692
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
649
693
|
const declList = node?.declarations || [];
|
|
650
694
|
let newNode;
|
|
651
|
-
declList
|
|
695
|
+
declList.forEach((decl) => {
|
|
652
696
|
const variableName = decl.id.name;
|
|
653
697
|
const isArrayPattern = decl.id?.type === 'ArrayPattern';
|
|
654
698
|
if (isArrayPattern && decl.init) {
|
|
@@ -659,7 +703,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
659
703
|
let typeAnnotation;
|
|
660
704
|
if (options.transformType === 'logic' && ![...options.logic.variables, ...options.logic.returns].some((variable) => variable.name === variableName)) {
|
|
661
705
|
const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
|
|
662
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
706
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
663
707
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
664
708
|
name: variableName,
|
|
665
709
|
typeAnnotation,
|
|
@@ -668,14 +712,14 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
668
712
|
if (decl.init) {
|
|
669
713
|
const calleeName = (0, utils_1.generate)(decl?.init?.callee).code;
|
|
670
714
|
const varTypeAnnotation = decl?.id?.typeAnnotation?.typeAnnotation;
|
|
671
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
715
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
672
716
|
if (calleeName === 'nasl.oql.query' && varTypeAnnotation) {
|
|
673
717
|
decl.init.typeAnnotations = varTypeAnnotation;
|
|
674
718
|
}
|
|
675
719
|
options.typeAnnotation = typeAnnotation;
|
|
676
720
|
newNode = new utils_1.naslTypes.Assignment({
|
|
677
721
|
left: transformNodeFunction(decl.id, options),
|
|
678
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation })),
|
|
722
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation }), options) || undefined,
|
|
679
723
|
});
|
|
680
724
|
}
|
|
681
725
|
});
|
|
@@ -781,10 +825,23 @@ function transformIdentifier(node, options) {
|
|
|
781
825
|
propertyName: '',
|
|
782
826
|
});
|
|
783
827
|
}
|
|
784
|
-
const placeholderMap = ['__IDENTIFIER__', '__LEFT__', '__RIGHT__', '__RIGHT', '__LEFT', '__IDENTIFIER'
|
|
828
|
+
const placeholderMap = ['__IDENTIFIER__', '__LEFT__', '__RIGHT__', '__RIGHT', '__LEFT', '__IDENTIFIER'];
|
|
785
829
|
if (placeholderMap.includes(node.name)) {
|
|
786
830
|
return new utils_1.naslTypes.Identifier({});
|
|
787
831
|
}
|
|
832
|
+
if (node.name === '$self') {
|
|
833
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
834
|
+
object: new utils_1.naslTypes.Identifier({
|
|
835
|
+
name: 'elements',
|
|
836
|
+
}),
|
|
837
|
+
property: new utils_1.naslTypes.Identifier({
|
|
838
|
+
name: '$ce',
|
|
839
|
+
}),
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
else if (node.name === 'undefined') {
|
|
843
|
+
return new utils_1.naslTypes.NullLiteral();
|
|
844
|
+
}
|
|
788
845
|
return new utils_1.naslTypes.Identifier({
|
|
789
846
|
name: node.name,
|
|
790
847
|
});
|
|
@@ -794,6 +851,10 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
794
851
|
let expression = node.value;
|
|
795
852
|
let asNameNode = node.key;
|
|
796
853
|
if (expression.type === 'Identifier') {
|
|
854
|
+
const isSameName = (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name;
|
|
855
|
+
if (!isSameName) {
|
|
856
|
+
return (0, utils_1.throwError)(options, `字段名需为 ${(0, utils_2.firstLowerCase)(expression.name)}, 目前为: ${asNameNode.name}, 相关代码如下`, node);
|
|
857
|
+
}
|
|
797
858
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
798
859
|
isDotStar: true,
|
|
799
860
|
asName: (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name ? undefined : asNameNode.name,
|
|
@@ -813,7 +874,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
813
874
|
// @TODO
|
|
814
875
|
}
|
|
815
876
|
else {
|
|
816
|
-
(0, utils_1.throwError)(
|
|
877
|
+
return (0, utils_1.throwError)(options, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
817
878
|
}
|
|
818
879
|
}
|
|
819
880
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -822,10 +883,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
822
883
|
const arg = callExpression.arguments[0];
|
|
823
884
|
if (arg.type !== 'MemberExpression') {
|
|
824
885
|
const code = (0, utils_1.generate)(arg).code;
|
|
825
|
-
(0, utils_1.throwError)(`聚合函数的输入只能是表字段(实体.属性)
|
|
886
|
+
return (0, utils_1.throwError)(options, `聚合函数的输入只能是表字段(实体.属性),但${callExpression.callee.name}(${code})中的${code}不是表字段`, node);
|
|
826
887
|
}
|
|
827
888
|
if (callExpression.arguments?.length > 1) {
|
|
828
|
-
(0, utils_1.throwError)(`聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
889
|
+
return (0, utils_1.throwError)(options, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
829
890
|
}
|
|
830
891
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
831
892
|
asName: asNameNode.name,
|
|
@@ -835,10 +896,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
835
896
|
}
|
|
836
897
|
function transform2AnonymousFunction(node, options) {
|
|
837
898
|
if (node.body.type === 'BlockStatement')
|
|
838
|
-
(0, utils_1.throwError)('Anonymous function with block statement is not supported');
|
|
899
|
+
return (0, utils_1.throwError)(options, 'Anonymous function with block statement is not supported', node);
|
|
839
900
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
840
901
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
841
|
-
params: node.params.map((param) => transform2Param(param)),
|
|
902
|
+
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
842
903
|
body: transformNodeFunction(node.body, options),
|
|
843
904
|
});
|
|
844
905
|
}
|
|
@@ -867,7 +928,7 @@ function transform2Assignment(node, options) {
|
|
|
867
928
|
}
|
|
868
929
|
return new utils_1.naslTypes.Assignment({
|
|
869
930
|
left: transformNodeFunction(node.left, options),
|
|
870
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options)),
|
|
931
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options), options) || undefined,
|
|
871
932
|
});
|
|
872
933
|
}
|
|
873
934
|
exports.transform2Assignment = transform2Assignment;
|
|
@@ -913,10 +974,11 @@ function transform2NumericLiteral(node, options) {
|
|
|
913
974
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
914
975
|
});
|
|
915
976
|
literal.typeAnnotation.typeName = literal.changeType(value);
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
977
|
+
// 新版本依赖自转换
|
|
978
|
+
// if (options.typeAnnotation && ['Integer', 'Long', 'Decimal'].includes(options.typeAnnotation.typeName)) {
|
|
979
|
+
// literal.typeAnnotation = options.typeAnnotation;
|
|
980
|
+
// delete options.typeAnnotation;
|
|
981
|
+
// }
|
|
920
982
|
return literal;
|
|
921
983
|
}
|
|
922
984
|
exports.transform2NumericLiteral = transform2NumericLiteral;
|
|
@@ -944,15 +1006,15 @@ function transformReturnStatement2AssignmentOrEnd(node, options) {
|
|
|
944
1006
|
}
|
|
945
1007
|
}
|
|
946
1008
|
if (!logic.returns.length) {
|
|
947
|
-
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation) : undefined;
|
|
1009
|
+
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation, options) || undefined : undefined;
|
|
948
1010
|
logic.returns.push(new utils_1.naslTypes.Return({
|
|
949
1011
|
name: 'result',
|
|
950
1012
|
typeAnnotation
|
|
951
1013
|
}));
|
|
952
1014
|
}
|
|
953
1015
|
const leftName = logic.returns[0].name;
|
|
954
|
-
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options));
|
|
955
|
-
if (right.concept === 'Identifier' && right.name === leftName) {
|
|
1016
|
+
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options), options) || undefined;
|
|
1017
|
+
if (right && right.concept === 'Identifier' && right.name === leftName) {
|
|
956
1018
|
return new utils_1.naslTypes.End();
|
|
957
1019
|
}
|
|
958
1020
|
else {
|
|
@@ -1002,7 +1064,7 @@ function transform2PartialNewComposite(node, options) {
|
|
|
1002
1064
|
const rights = [];
|
|
1003
1065
|
const structureProperties = [];
|
|
1004
1066
|
const assignmentLines = [];
|
|
1005
|
-
const newProperties = (node?.properties || node?.arguments?.[0]?.properties)
|
|
1067
|
+
const newProperties = (node?.properties || node?.arguments?.[0]?.properties);
|
|
1006
1068
|
let idx = 0;
|
|
1007
1069
|
newProperties?.forEach((arg, index) => {
|
|
1008
1070
|
properties.push(transformNodeFunction(arg.key, options));
|
|
@@ -1119,8 +1181,7 @@ function transformNewExpression(node, options) {
|
|
|
1119
1181
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1120
1182
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1121
1183
|
}
|
|
1122
|
-
|
|
1123
|
-
(0, utils_1.throwError)(`Unhandled node ${node.type}: ${errCode}`);
|
|
1184
|
+
return (0, utils_1.throwError)(options, '在新建表达式中不支持节点类型', node.type, node);
|
|
1124
1185
|
}
|
|
1125
1186
|
exports.transformNewExpression = transformNewExpression;
|
|
1126
1187
|
function transformMemberExpression(node, options) {
|
|
@@ -1157,18 +1218,31 @@ function transformMemberExpression(node, options) {
|
|
|
1157
1218
|
});
|
|
1158
1219
|
}
|
|
1159
1220
|
if (calleeName?.startsWith('$refs.')) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1221
|
+
if (callee[0].type === 'CallExpression') {
|
|
1222
|
+
const callExpression = callee[0];
|
|
1223
|
+
const callCallee = flatMemberExpression(callExpression.callee);
|
|
1224
|
+
const callCalleeName = (0, utils_1.generate)(callExpression)?.code;
|
|
1225
|
+
let callResult = transformCall2CallViewElementLogic(callExpression, callCalleeName, callCallee, options);
|
|
1226
|
+
const remainingCallee = callee.slice(1);
|
|
1227
|
+
if (remainingCallee.length > 0 && callResult) {
|
|
1228
|
+
return unflatMemberExpression(remainingCallee, options, callResult);
|
|
1229
|
+
}
|
|
1230
|
+
return callResult;
|
|
1231
|
+
}
|
|
1232
|
+
else {
|
|
1233
|
+
const componentName = callee?.[1]?.name;
|
|
1234
|
+
const propertyName = callee?.[2]?.name;
|
|
1235
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
1236
|
+
object: new utils_1.naslTypes.Identifier({
|
|
1237
|
+
namespace: `elements.${componentName}.property`,
|
|
1238
|
+
name: componentName,
|
|
1239
|
+
}),
|
|
1240
|
+
property: new utils_1.naslTypes.Identifier({
|
|
1241
|
+
namespace: propertyName,
|
|
1242
|
+
name: propertyName,
|
|
1243
|
+
}),
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1172
1246
|
}
|
|
1173
1247
|
const regex = /^(app\..+?)\.variables\.(.+)$/;
|
|
1174
1248
|
if (regex.test(calleeName)) {
|
|
@@ -1223,12 +1297,88 @@ function transformMemberExpression(node, options) {
|
|
|
1223
1297
|
});
|
|
1224
1298
|
}
|
|
1225
1299
|
exports.transformMemberExpression = transformMemberExpression;
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1300
|
+
/**
|
|
1301
|
+
* @example (function match(_value) {
|
|
1302
|
+
if (_value === true) {
|
|
1303
|
+
return 'green'
|
|
1304
|
+
} else {
|
|
1305
|
+
return 'red'
|
|
1306
|
+
}
|
|
1307
|
+
})(nasl.util.Convert<Boolean>(enabled))
|
|
1308
|
+
*/
|
|
1309
|
+
function transformCallFunctionExpression2Match(node, calleeName, callee, options) {
|
|
1310
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1311
|
+
const arg = node.arguments[0];
|
|
1312
|
+
const ifStatement = node.callee.body.body[0];
|
|
1313
|
+
if (ifStatement.type !== 'IfStatement') {
|
|
1314
|
+
return (0, utils_1.throwError)(options, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1315
|
+
}
|
|
1316
|
+
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1317
|
+
const match = new utils_1.naslTypes.Match({
|
|
1318
|
+
expression: transformNodeFunction(arg, options),
|
|
1319
|
+
isExpression: true,
|
|
1320
|
+
cases: flatedIfStatements.map((_case) => {
|
|
1321
|
+
let argument;
|
|
1322
|
+
if (_case.consequent.type === 'BlockStatement') {
|
|
1323
|
+
if (_case.consequent.body.length === 1 && _case.consequent.body[0].type === 'ReturnStatement') {
|
|
1324
|
+
argument = _case.consequent.body[0].argument;
|
|
1325
|
+
}
|
|
1326
|
+
else {
|
|
1327
|
+
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
else {
|
|
1331
|
+
if (_case.consequent.type === 'ReturnStatement') {
|
|
1332
|
+
argument = _case.consequent.argument;
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
const bodyNode = transformNodeFunction(argument, options);
|
|
1339
|
+
return new utils_1.naslTypes.MatchCase({
|
|
1340
|
+
isMatchedTypeEnumable: false,
|
|
1341
|
+
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1342
|
+
body: bodyNode ? [bodyNode] : [],
|
|
1343
|
+
});
|
|
1344
|
+
}).filter(Boolean),
|
|
1345
|
+
});
|
|
1346
|
+
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1347
|
+
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1348
|
+
isMatchedTypeEnumable: false,
|
|
1349
|
+
patterns: [],
|
|
1350
|
+
body: [],
|
|
1351
|
+
}));
|
|
1352
|
+
}
|
|
1353
|
+
match.cases.forEach((case_) => {
|
|
1354
|
+
if (case_.patterns.length) {
|
|
1355
|
+
if (case_.patterns[0].concept === 'BooleanLiteral' || case_.patterns[0].concept === 'StringLiteral') {
|
|
1356
|
+
case_.isMatchedTypeEnumable = true;
|
|
1357
|
+
}
|
|
1358
|
+
if (case_.patterns[0].concept === 'MemberExpression') {
|
|
1359
|
+
case_.isMatchedTypeEnumable = true;
|
|
1360
|
+
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1361
|
+
object: {
|
|
1362
|
+
concept: 'Identifier',
|
|
1363
|
+
name: case_.patterns[0].object.property.name,
|
|
1364
|
+
folded: false,
|
|
1365
|
+
namespace: 'app.enums'
|
|
1366
|
+
},
|
|
1367
|
+
property: {
|
|
1368
|
+
concept: 'Identifier',
|
|
1369
|
+
name: case_.patterns[0].property.value,
|
|
1370
|
+
folded: false,
|
|
1371
|
+
},
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
return match;
|
|
1229
1377
|
}
|
|
1230
|
-
exports.
|
|
1378
|
+
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1231
1379
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1380
|
+
if (options?.isRestricted)
|
|
1381
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1232
1382
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1233
1383
|
const componentName = callee?.[1]?.name;
|
|
1234
1384
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1263,6 +1413,8 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1263
1413
|
}
|
|
1264
1414
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1265
1415
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1416
|
+
if (options?.isRestricted)
|
|
1417
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1266
1418
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1267
1419
|
// console.log('callee', callee);
|
|
1268
1420
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1275,6 +1427,8 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1275
1427
|
}
|
|
1276
1428
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1277
1429
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1430
|
+
if (options?.isRestricted)
|
|
1431
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1278
1432
|
if (calleeName?.includes('.entities.')) {
|
|
1279
1433
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1280
1434
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1333,6 +1487,10 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1333
1487
|
}
|
|
1334
1488
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1335
1489
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1490
|
+
if (options?.isInFrontend)
|
|
1491
|
+
return (0, utils_1.throwError)(options, 'OQL组件不支持在前端使用', node);
|
|
1492
|
+
if (options?.isRestricted)
|
|
1493
|
+
return (0, utils_1.throwError)(options, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1336
1494
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1337
1495
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1338
1496
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1342,11 +1500,13 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1342
1500
|
return new utils_1.naslTypes.OqlQueryComponent({
|
|
1343
1501
|
dataSource: 'app.dataSources.defaultDS',
|
|
1344
1502
|
code,
|
|
1345
|
-
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations)
|
|
1503
|
+
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations, options) || undefined,
|
|
1346
1504
|
});
|
|
1347
1505
|
}
|
|
1348
1506
|
}
|
|
1349
1507
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1508
|
+
if (options?.isRestricted)
|
|
1509
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1350
1510
|
return new utils_1.naslTypes.CallLogic({
|
|
1351
1511
|
calleeNamespace: 'nasl.logging',
|
|
1352
1512
|
calleeName: 'INFO',
|
|
@@ -1358,6 +1518,8 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1358
1518
|
}
|
|
1359
1519
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1360
1520
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1521
|
+
if (options?.isRestricted)
|
|
1522
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1361
1523
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1362
1524
|
expression: arg?.name === "undefined" ?
|
|
1363
1525
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1389,10 +1551,32 @@ function transformCall2JSONFunctions(node, calleeName, callee, options) {
|
|
|
1389
1551
|
keyword: 'arg',
|
|
1390
1552
|
}),
|
|
1391
1553
|
],
|
|
1392
|
-
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType })),
|
|
1554
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1393
1555
|
});
|
|
1394
1556
|
}
|
|
1395
1557
|
exports.transformCall2JSONFunctions = transformCall2JSONFunctions;
|
|
1558
|
+
function transform2CallEventLogic(node, calleeName, callee, options) {
|
|
1559
|
+
const lastName = callee[callee.length - 1].name;
|
|
1560
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1561
|
+
calleeNamespace: 'nasl.event',
|
|
1562
|
+
calleeName: lastName,
|
|
1563
|
+
shortcut: true,
|
|
1564
|
+
arguments: [],
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
exports.transform2CallEventLogic = transform2CallEventLogic;
|
|
1568
|
+
function transform2CallOtherNASLLogic(node, calleeName, callee, options) {
|
|
1569
|
+
const arr = calleeName.split('.');
|
|
1570
|
+
const lastName = arr.pop();
|
|
1571
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1572
|
+
calleeNamespace: arr.join('.'),
|
|
1573
|
+
calleeName: lastName,
|
|
1574
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
1575
|
+
expression: fixExpression(arg, options),
|
|
1576
|
+
})),
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
exports.transform2CallOtherNASLLogic = transform2CallOtherNASLLogic;
|
|
1396
1580
|
function transform2CallFunction(node, calleeName, argument, options) {
|
|
1397
1581
|
calleeName = utils_1.replaceCallFunctionMap?.[calleeName] || calleeName;
|
|
1398
1582
|
const func = server_1.default ? server_1.default.getBuildInFunction(calleeName) : null;
|
|
@@ -1406,8 +1590,13 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1406
1590
|
keyword: func && func?.params[index]?.name || `param${index + 1}`,
|
|
1407
1591
|
});
|
|
1408
1592
|
});
|
|
1409
|
-
let newTypeArguments = node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation);
|
|
1410
|
-
if (calleeName === 'ListRepeat') {
|
|
1593
|
+
let newTypeArguments = node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean);
|
|
1594
|
+
// if (calleeName === 'ListRepeat') {
|
|
1595
|
+
// newTypeArguments = [
|
|
1596
|
+
// new naslTypes.TypeAnnotation()
|
|
1597
|
+
// ];
|
|
1598
|
+
// }
|
|
1599
|
+
if (calleeName === 'Convert' && !newTypeArguments) {
|
|
1411
1600
|
newTypeArguments = [
|
|
1412
1601
|
new utils_1.naslTypes.TypeAnnotation()
|
|
1413
1602
|
];
|
|
@@ -1418,6 +1607,17 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1418
1607
|
expressions: expressions?.filter(Boolean),
|
|
1419
1608
|
});
|
|
1420
1609
|
}
|
|
1610
|
+
if (calleeName === 'Length') {
|
|
1611
|
+
const expressions = newArguments.map((item) => item.expression);
|
|
1612
|
+
if (expressions.length === 1) {
|
|
1613
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
1614
|
+
object: expressions[0],
|
|
1615
|
+
property: new utils_1.naslTypes.Identifier({
|
|
1616
|
+
name: 'length',
|
|
1617
|
+
}),
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1421
1621
|
if (calleeName === 'Convert' && !newTypeArguments) {
|
|
1422
1622
|
newTypeArguments = [
|
|
1423
1623
|
new utils_1.naslTypes.TypeAnnotation()
|
|
@@ -1445,7 +1645,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1445
1645
|
const content = np?.toNaturalTS();
|
|
1446
1646
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1447
1647
|
if (!np && !p?.defaultExpression) {
|
|
1448
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1648
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1449
1649
|
}
|
|
1450
1650
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1451
1651
|
if (idx === 1) {
|
|
@@ -1478,7 +1678,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1478
1678
|
});
|
|
1479
1679
|
}
|
|
1480
1680
|
else {
|
|
1481
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1681
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}不存在`, node.callee, node);
|
|
1482
1682
|
}
|
|
1483
1683
|
if (!func.params?.length) {
|
|
1484
1684
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1500,7 +1700,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1500
1700
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1501
1701
|
const excludes = ['HasValue', 'ListSort'];
|
|
1502
1702
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1503
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1703
|
+
return (0, utils_1.throwError)(options, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1504
1704
|
}
|
|
1505
1705
|
else {
|
|
1506
1706
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1517,19 +1717,22 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1517
1717
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1518
1718
|
});
|
|
1519
1719
|
if (calleeName === 'ListSort') {
|
|
1520
|
-
|
|
1720
|
+
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1721
|
+
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1521
1722
|
}
|
|
1522
1723
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1523
|
-
(0, utils_1.throwError)(
|
|
1724
|
+
return (0, utils_1.throwError)(options, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1524
1725
|
}
|
|
1525
1726
|
return nodeElement;
|
|
1526
1727
|
}
|
|
1527
1728
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1528
1729
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1529
1730
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1530
|
-
(0, utils_1.throwError)(`数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}
|
|
1731
|
+
return (0, utils_1.throwError)(options, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`, node.callee, node);
|
|
1531
1732
|
}
|
|
1532
1733
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1734
|
+
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
1735
|
+
const func = server_1.default ? server_1.default?.getSqlFunction('mysql', calleeName) : null;
|
|
1533
1736
|
let addArguments = [];
|
|
1534
1737
|
if (specFunList.includes(calleeName)) {
|
|
1535
1738
|
const value = calleeName === 'COUNTD' ? 'DISTINCT' : 'ALL';
|
|
@@ -1542,20 +1745,20 @@ function transform2SqlFunction(node, calleeName, argument, options) {
|
|
|
1542
1745
|
}
|
|
1543
1746
|
const newArguments = argument.map((arg, index) => new utils_1.naslTypes.Argument({
|
|
1544
1747
|
expression: fixExpression(arg, options),
|
|
1545
|
-
keyword:
|
|
1748
|
+
keyword: func?.params[index]?.name || `param${index + 1}`,
|
|
1546
1749
|
}));
|
|
1547
1750
|
const nodeElement = new utils_1.naslTypes.CallFunction({
|
|
1548
1751
|
calleeNamespace: 'nasl.sqlFunction',
|
|
1549
1752
|
calleeName: utils_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1550
1753
|
arguments: [...addArguments, ...newArguments],
|
|
1551
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
1754
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1552
1755
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1553
1756
|
});
|
|
1554
1757
|
return nodeElement;
|
|
1555
1758
|
}
|
|
1556
1759
|
function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
1557
1760
|
let curCalleeName;
|
|
1558
|
-
if (callee.length
|
|
1761
|
+
if (callee.length >= 3)
|
|
1559
1762
|
curCalleeName = callee[callee.length - 1].name;
|
|
1560
1763
|
else {
|
|
1561
1764
|
let _callee = callee[0].callee;
|
|
@@ -1563,11 +1766,10 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1563
1766
|
_callee = _callee.callee;
|
|
1564
1767
|
curCalleeName = _callee.property.name;
|
|
1565
1768
|
}
|
|
1566
|
-
const argument = callee.length
|
|
1567
|
-
if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1570
|
-
;
|
|
1769
|
+
const argument = callee.length >= 3 ? node.arguments : callee[0].arguments;
|
|
1770
|
+
// if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1771
|
+
// return transformCallExpressionToBinaryExpression(node, curCalleeName, callee, options);
|
|
1772
|
+
// };
|
|
1571
1773
|
if (['NewList', 'NewMap', 'NewEntity', 'NewStructure', 'NewAnonymousStructure'].includes(curCalleeName)) {
|
|
1572
1774
|
return transform2NewExpression(curCalleeName, node, options);
|
|
1573
1775
|
}
|
|
@@ -1576,10 +1778,31 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1576
1778
|
exports.transformCall2CallFunction = transformCall2CallFunction;
|
|
1577
1779
|
function transform2UIFunction(node, calleeName, callee, options) {
|
|
1578
1780
|
if (callee[2].name === 'destination') {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1781
|
+
let namespaceNode = node.arguments[0];
|
|
1782
|
+
let namespace = '';
|
|
1783
|
+
if (namespaceNode.type === 'TemplateLiteral') {
|
|
1784
|
+
namespace = namespaceNode.quasis[0]?.value?.cooked;
|
|
1785
|
+
}
|
|
1786
|
+
else if (namespaceNode.type === 'StringLiteral') {
|
|
1787
|
+
namespace = namespaceNode.value;
|
|
1788
|
+
}
|
|
1789
|
+
else {
|
|
1790
|
+
namespace = (0, utils_1.generate)(namespaceNode).code;
|
|
1791
|
+
}
|
|
1792
|
+
let nsArr;
|
|
1793
|
+
let viewNamespace = '';
|
|
1794
|
+
let viewName = '';
|
|
1795
|
+
if (namespace.startsWith('app.frontendTypes.')) {
|
|
1796
|
+
nsArr = namespace.split('.');
|
|
1797
|
+
viewName = nsArr.pop();
|
|
1798
|
+
viewNamespace = nsArr.join('.');
|
|
1799
|
+
}
|
|
1800
|
+
else {
|
|
1801
|
+
nsArr = namespace.split('.').map((item) => item.replace(/_view$/, ''));
|
|
1802
|
+
const pageType = nsArr.shift();
|
|
1803
|
+
viewName = nsArr.pop();
|
|
1804
|
+
viewNamespace = `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`;
|
|
1805
|
+
}
|
|
1583
1806
|
const newArguments = node?.arguments?.slice(1);
|
|
1584
1807
|
let argument = [];
|
|
1585
1808
|
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
@@ -1595,7 +1818,7 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1595
1818
|
}));
|
|
1596
1819
|
}
|
|
1597
1820
|
return new utils_1.naslTypes.Destination({
|
|
1598
|
-
viewNamespace
|
|
1821
|
+
viewNamespace,
|
|
1599
1822
|
viewName,
|
|
1600
1823
|
arguments: argument,
|
|
1601
1824
|
});
|
|
@@ -1605,6 +1828,11 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1605
1828
|
link: fixExpression(node?.arguments[0], options),
|
|
1606
1829
|
});
|
|
1607
1830
|
}
|
|
1831
|
+
if (options?.isRestricted)
|
|
1832
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1833
|
+
// if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1834
|
+
// return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1835
|
+
// }
|
|
1608
1836
|
return new utils_1.naslTypes.CallLogic({
|
|
1609
1837
|
calleeNamespace: 'nasl.ui',
|
|
1610
1838
|
calleeName: callee[2].name,
|
|
@@ -1641,11 +1869,11 @@ function transform2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1641
1869
|
each: transformNodeFunction(newCallee[0], options),
|
|
1642
1870
|
start: transformNodeFunction(newCallee[1], options),
|
|
1643
1871
|
end: newCallee[2]?.name === '__IDENTIFIER__' ? undefined : transformNodeFunction(newCallee[2], options),
|
|
1644
|
-
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0]) : new utils_1.naslTypes.Param({
|
|
1872
|
+
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0], options) || undefined : new utils_1.naslTypes.Param({
|
|
1645
1873
|
name: 'item',
|
|
1646
1874
|
typeAnnotation: undefined,
|
|
1647
1875
|
}),
|
|
1648
|
-
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1876
|
+
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1649
1877
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 4)}`,
|
|
1650
1878
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1651
1879
|
}),
|
|
@@ -1672,8 +1900,8 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1672
1900
|
let endNode;
|
|
1673
1901
|
if (node?.right?.type === 'CallExpression') {
|
|
1674
1902
|
const rightNode = node?.right;
|
|
1675
|
-
const calleeName =
|
|
1676
|
-
const hasListEntries =
|
|
1903
|
+
const calleeName = (0, utils_1.generate)(rightNode.callee).code;
|
|
1904
|
+
const hasListEntries = ['ListEntries', 'nasl.util.ListEntries'].includes(calleeName);
|
|
1677
1905
|
const areaArguments = rightNode?.arguments;
|
|
1678
1906
|
eachNode = hasListEntries ? areaArguments?.[0] : rightNode;
|
|
1679
1907
|
startNode = hasListEntries ? areaArguments?.[1] : undefined;
|
|
@@ -1689,11 +1917,11 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1689
1917
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1690
1918
|
}),
|
|
1691
1919
|
end: endNode?.name === '__IDENTIFIER__' ? undefined : endNode ? transformNodeFunction(endNode, options) : undefined,
|
|
1692
|
-
item: itemNode ? transform2Param(itemNode) : new utils_1.naslTypes.Param({
|
|
1920
|
+
item: itemNode ? transform2Param(itemNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1693
1921
|
name: 'item',
|
|
1694
1922
|
typeAnnotation: undefined,
|
|
1695
1923
|
}),
|
|
1696
|
-
index: indexNode ? transform2Param(indexNode) : new utils_1.naslTypes.Param({
|
|
1924
|
+
index: indexNode ? transform2Param(indexNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1697
1925
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1698
1926
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1699
1927
|
}),
|
|
@@ -1713,8 +1941,8 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1713
1941
|
value: '0',
|
|
1714
1942
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1715
1943
|
}),
|
|
1716
|
-
item: transform2Param(arrowFunction.params[0]),
|
|
1717
|
-
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1944
|
+
item: transform2Param(arrowFunction.params[0], options) || undefined,
|
|
1945
|
+
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1718
1946
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1719
1947
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1720
1948
|
}),
|
|
@@ -1724,6 +1952,11 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1724
1952
|
}
|
|
1725
1953
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1726
1954
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1955
|
+
if (options?.isRestricted)
|
|
1956
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1957
|
+
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1958
|
+
return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1959
|
+
}
|
|
1727
1960
|
return new utils_1.naslTypes.CallLogic({
|
|
1728
1961
|
calleeNamespace: 'nasl.ui',
|
|
1729
1962
|
calleeName: 'showMessage',
|
|
@@ -1735,6 +1968,8 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1735
1968
|
}
|
|
1736
1969
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1737
1970
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1971
|
+
if (options?.isRestricted)
|
|
1972
|
+
return (0, utils_1.throwError)(options, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1738
1973
|
return new utils_1.naslTypes.CallInterface({
|
|
1739
1974
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1740
1975
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1746,13 +1981,15 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1746
1981
|
}
|
|
1747
1982
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1748
1983
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1984
|
+
if (options?.isRestricted)
|
|
1985
|
+
return (0, utils_1.throwError)(options, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1749
1986
|
let calleeConnectionName = undefined;
|
|
1750
1987
|
let calleeNamespace = undefined;
|
|
1751
1988
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1752
1989
|
if (callee.length === 5) {
|
|
1753
1990
|
const connectArg = callee[2].arguments[0];
|
|
1754
1991
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1755
|
-
(0, utils_1.throwError)(
|
|
1992
|
+
return (0, utils_1.throwError)(options, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1756
1993
|
}
|
|
1757
1994
|
calleeConnectionName = connectArg.value;
|
|
1758
1995
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -1767,7 +2004,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1767
2004
|
calleeNamespace = calleeNamespacePrefix;
|
|
1768
2005
|
}
|
|
1769
2006
|
else {
|
|
1770
|
-
(0, utils_1.throwError)(`调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}
|
|
2007
|
+
return (0, utils_1.throwError)(options, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1771
2008
|
}
|
|
1772
2009
|
return new utils_1.naslTypes.CallConnector({
|
|
1773
2010
|
calleeConnectionName,
|
|
@@ -1780,6 +2017,8 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1780
2017
|
}
|
|
1781
2018
|
exports.transformCall2Connector = transformCall2Connector;
|
|
1782
2019
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
2020
|
+
if (options?.isRestricted)
|
|
2021
|
+
return (0, utils_1.throwError)(options, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1783
2022
|
return new utils_1.naslTypes.CallLogic({
|
|
1784
2023
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
1785
2024
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -1789,70 +2028,26 @@ function transformCall2Extension(node, calleeName, callee, options) {
|
|
|
1789
2028
|
});
|
|
1790
2029
|
}
|
|
1791
2030
|
exports.transformCall2Extension = transformCall2Extension;
|
|
1792
|
-
function transformArrowFunction2Match(node, calleeName, callee, options) {
|
|
1793
|
-
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1794
|
-
// NOTE: 适用于 if else
|
|
1795
|
-
const newCallee = node.callee.body.body;
|
|
1796
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__MatchExpressionFunction') {
|
|
1797
|
-
const match = new utils_1.naslTypes.Match({
|
|
1798
|
-
expression: fixExpression(newCallee[0], options),
|
|
1799
|
-
isExpression: options.transformType !== 'logic',
|
|
1800
|
-
cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new utils_1.naslTypes.MatchCase({
|
|
1801
|
-
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1802
|
-
body: transformBlockBody(_case.consequent.body.filter((item) => item.type !== 'BreakStatement'), options),
|
|
1803
|
-
})),
|
|
1804
|
-
});
|
|
1805
|
-
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1806
|
-
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1807
|
-
patterns: [],
|
|
1808
|
-
body: [],
|
|
1809
|
-
}));
|
|
1810
|
-
}
|
|
1811
|
-
match.cases.forEach((case_) => {
|
|
1812
|
-
if (case_.body.length && (case_.body[0].concept === 'BooleanLiteral' || case_.body[0].concept === 'StringLiteral')) {
|
|
1813
|
-
case_.isMatchedTypeEnumable = true;
|
|
1814
|
-
}
|
|
1815
|
-
if (case_.patterns.length && case_.patterns[0].concept === 'MemberExpression') {
|
|
1816
|
-
case_.isMatchedTypeEnumable = true;
|
|
1817
|
-
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1818
|
-
object: {
|
|
1819
|
-
concept: 'Identifier',
|
|
1820
|
-
name: case_.patterns[0].object.property.name,
|
|
1821
|
-
folded: false,
|
|
1822
|
-
namespace: 'app.enums'
|
|
1823
|
-
},
|
|
1824
|
-
property: {
|
|
1825
|
-
concept: 'Identifier',
|
|
1826
|
-
name: case_.patterns[0].property.value,
|
|
1827
|
-
folded: false,
|
|
1828
|
-
},
|
|
1829
|
-
});
|
|
1830
|
-
}
|
|
1831
|
-
});
|
|
1832
|
-
return match;
|
|
1833
|
-
}
|
|
1834
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__SwitchExpressionFuntion') {
|
|
1835
|
-
const switchStatement = transformNodeFunction(newCallee[0].body.body[0], options);
|
|
1836
|
-
return switchStatement;
|
|
1837
|
-
}
|
|
1838
|
-
(0, utils_1.throwError)(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
1839
|
-
}
|
|
1840
|
-
exports.transformArrowFunction2Match = transformArrowFunction2Match;
|
|
1841
2031
|
function transformTSAsExpression(node, options) {
|
|
1842
2032
|
if (node.expression.type === 'NumericLiteral') {
|
|
1843
|
-
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation) });
|
|
2033
|
+
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined });
|
|
1844
2034
|
}
|
|
1845
2035
|
else if (node.expression.type === 'ArrayExpression') {
|
|
1846
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation);
|
|
2036
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
1847
2037
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
1848
|
-
(0, utils_1.throwError)(`列表 as 必须为 List
|
|
2038
|
+
return (0, utils_1.throwError)(options, `列表 as 必须为 List 类型`, node);
|
|
1849
2039
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
1850
2040
|
}
|
|
2041
|
+
else if (node.expression.type === 'NullLiteral') {
|
|
2042
|
+
return transform2NullLiteral(node.expression, options);
|
|
2043
|
+
}
|
|
1851
2044
|
else {
|
|
1852
|
-
(0, utils_1.throwError)(
|
|
2045
|
+
return (0, utils_1.throwError)(options, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
1853
2046
|
}
|
|
1854
2047
|
}
|
|
1855
2048
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
2049
|
+
if (options?.isRestricted)
|
|
2050
|
+
return (0, utils_1.throwError)(options, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
1856
2051
|
return new utils_1.naslTypes.CallLogic({
|
|
1857
2052
|
calleeNamespace: '',
|
|
1858
2053
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -1863,11 +2058,13 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
1863
2058
|
}
|
|
1864
2059
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
1865
2060
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
2061
|
+
if (options?.isRestricted)
|
|
2062
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1866
2063
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
1867
2064
|
// 未带前缀,补一下
|
|
1868
2065
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
1869
2066
|
}
|
|
1870
|
-
else if (
|
|
2067
|
+
else if (server_1.default.getSqlFunction('mysql', calleeName) || calleeName === 'COUNTD') {
|
|
1871
2068
|
return transform2SqlFunction(node, calleeName, node?.arguments || [], options);
|
|
1872
2069
|
}
|
|
1873
2070
|
let newCalleeName = calleeName?.includes('__IDENTIFIER__') ? undefined : calleeName;
|
|
@@ -1887,6 +2084,8 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
1887
2084
|
}
|
|
1888
2085
|
exports.transformCall2Logic = transformCall2Logic;
|
|
1889
2086
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
2087
|
+
if (options?.isRestricted)
|
|
2088
|
+
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1890
2089
|
return new utils_1.naslTypes.CallLogic({
|
|
1891
2090
|
calleeNamespace: `nasl.auth`,
|
|
1892
2091
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1911,10 +2110,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1911
2110
|
const calleeName = node.callee.name;
|
|
1912
2111
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
1913
2112
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
1914
|
-
(0, utils_1.throwError)('FROM should have a ArrowFunctionExpression as the second argument');
|
|
2113
|
+
return (0, utils_1.throwError)(options, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
1915
2114
|
const arrowFunctionExpression = node.arguments[1];
|
|
1916
2115
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
1917
|
-
(0, utils_1.throwError)('FROM should have a CallExpression as the body of ArrowFunctionExpression');
|
|
2116
|
+
return (0, utils_1.throwError)(options, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
1918
2117
|
const body = arrowFunctionExpression.body;
|
|
1919
2118
|
const callExpressions = flatChainCallExpression(body);
|
|
1920
2119
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -1924,13 +2123,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1924
2123
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
1925
2124
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
1926
2125
|
`;
|
|
1927
|
-
(0, utils_1.throwError)(error);
|
|
2126
|
+
return (0, utils_1.throwError)(options, error, node);
|
|
1928
2127
|
}
|
|
1929
2128
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
1930
2129
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
1931
2130
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
1932
2131
|
if (errorOrder) {
|
|
1933
|
-
(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 的调用顺序。',
|
|
2132
|
+
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);
|
|
1934
2133
|
}
|
|
1935
2134
|
const result = [{
|
|
1936
2135
|
calleeName: calleeName,
|
|
@@ -1942,7 +2141,7 @@ FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); /
|
|
|
1942
2141
|
result[0].arguments[2] = item.arguments[0];
|
|
1943
2142
|
}
|
|
1944
2143
|
else if (['INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(item.callee.name)) {
|
|
1945
|
-
result.push(...flatCallQueryComponentChainNode(item, options));
|
|
2144
|
+
result.push(...(flatCallQueryComponentChainNode(item, options) || []));
|
|
1946
2145
|
}
|
|
1947
2146
|
else {
|
|
1948
2147
|
result.push({
|
|
@@ -1975,33 +2174,39 @@ function flatOnExpressions(node) {
|
|
|
1975
2174
|
return [node];
|
|
1976
2175
|
}
|
|
1977
2176
|
}
|
|
1978
|
-
function transformMemberExpression2Entity(node, node2) {
|
|
2177
|
+
function transformMemberExpression2Entity(node, node2, options) {
|
|
1979
2178
|
const entityPath = flatMemberExpression(node);
|
|
1980
2179
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
1981
2180
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
1982
2181
|
if (!entityNamespace?.includes('.entities')) {
|
|
1983
|
-
(0, utils_1.throwError)(`${entityNamespace}.${entityName}
|
|
2182
|
+
return (0, utils_1.throwError)(options, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
1984
2183
|
}
|
|
1985
2184
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
1986
2185
|
if (asName) {
|
|
1987
|
-
(0, utils_1.throwError)(`FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2186
|
+
return (0, utils_1.throwError)(options, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
1988
2187
|
}
|
|
1989
2188
|
return { entityNamespace, entityName, asName };
|
|
1990
2189
|
}
|
|
1991
2190
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2191
|
+
if (options?.isInFrontend)
|
|
2192
|
+
return (0, utils_1.throwError)(options, '数据查询组件不支持在前端使用', node);
|
|
2193
|
+
if (options?.isRestricted)
|
|
2194
|
+
return (0, utils_1.throwError)(options, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
1992
2195
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1993
2196
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
1994
2197
|
if (code?.includes('nasl.util')) {
|
|
1995
|
-
(0, utils_1.throwError)('数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理');
|
|
2198
|
+
return (0, utils_1.throwError)(options, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
1996
2199
|
}
|
|
1997
2200
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
1998
|
-
(0, utils_1.throwError)('缺少 SELECT 或 AGGR_SELECT 语句');
|
|
2201
|
+
return (0, utils_1.throwError)(options, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
1999
2202
|
}
|
|
2000
2203
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
2001
|
-
|
|
2204
|
+
if (!flatted)
|
|
2205
|
+
return;
|
|
2206
|
+
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2002
2207
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
2003
2208
|
if (!isOrderCorrect) {
|
|
2004
|
-
(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 的调用顺序。',
|
|
2209
|
+
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);
|
|
2005
2210
|
}
|
|
2006
2211
|
let from;
|
|
2007
2212
|
let where;
|
|
@@ -2014,11 +2219,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2014
2219
|
let hasErrorTSScopeColumn = false;
|
|
2015
2220
|
let useResultItem = false;
|
|
2016
2221
|
// 这里只是一个示例,具体的逻辑需要根据flatted的内容来构建
|
|
2017
|
-
flatted.forEach((item) => {
|
|
2222
|
+
flatted && flatted.forEach((item) => {
|
|
2018
2223
|
// console.log(item.calleeName)
|
|
2019
2224
|
switch (item.calleeName) {
|
|
2020
2225
|
case 'FROM':
|
|
2021
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2226
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2227
|
+
if (!entity)
|
|
2228
|
+
return;
|
|
2022
2229
|
const entityName = entity.asName || entity.entityName;
|
|
2023
2230
|
entityAsNames.push(entityName);
|
|
2024
2231
|
from = new utils_1.naslTypes.QueryFromExpression({
|
|
@@ -2030,11 +2237,15 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2030
2237
|
case 'LEFT_JOIN':
|
|
2031
2238
|
case 'RIGHT_JOIN':
|
|
2032
2239
|
case 'OUTER_JOIN':
|
|
2033
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2240
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2241
|
+
if (!entity)
|
|
2242
|
+
break;
|
|
2034
2243
|
entityAsNames.push(entity.asName || entity.entityName);
|
|
2035
2244
|
const rawJoinType = item.calleeName.slice(0, -5);
|
|
2036
2245
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2037
2246
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2247
|
+
if (!from)
|
|
2248
|
+
return; // throwError(options, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2038
2249
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2039
2250
|
...entity,
|
|
2040
2251
|
joinType,
|
|
@@ -2050,57 +2261,84 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2050
2261
|
}));
|
|
2051
2262
|
break;
|
|
2052
2263
|
case 'AGGR_SELECT':
|
|
2053
|
-
if (groupBy
|
|
2054
|
-
(0, utils_1.throwError)('存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2264
|
+
if (groupBy.length) {
|
|
2265
|
+
return (0, utils_1.throwError)(options, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2055
2266
|
}
|
|
2056
2267
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2057
2268
|
distinct: false,
|
|
2058
2269
|
star: true,
|
|
2059
2270
|
selectElements: [new utils_1.naslTypes.QueryFieldExpression({
|
|
2060
2271
|
isDotStar: true,
|
|
2061
|
-
entityAsName: from
|
|
2272
|
+
entityAsName: from?.entityName,
|
|
2062
2273
|
propertyName: '',
|
|
2063
2274
|
})],
|
|
2064
2275
|
});
|
|
2065
|
-
item.arguments[0].
|
|
2066
|
-
|
|
2067
|
-
|
|
2276
|
+
if (item.arguments[0].type === 'ObjectExpression') {
|
|
2277
|
+
item.arguments[0].properties?.forEach((arg) => {
|
|
2278
|
+
if (arg?.value.type === 'CallExpression') {
|
|
2279
|
+
let selectElements = transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2280
|
+
if (selectElements) {
|
|
2281
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2282
|
+
select.setSelectElements(newSelectElements);
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
else {
|
|
2286
|
+
return (0, utils_1.throwError)(options, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2287
|
+
}
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
else if (item.arguments[0].type === 'CallExpression') { // 只有一个的简写:AGGR_SELECT(SUM(Entity1.age))
|
|
2291
|
+
const selectElements = transform2QueryAggregateExpression({
|
|
2292
|
+
type: 'ObjectProperty',
|
|
2293
|
+
key: {
|
|
2294
|
+
type: 'Identifier',
|
|
2295
|
+
name: 'resultItem',
|
|
2296
|
+
},
|
|
2297
|
+
value: item.arguments[0],
|
|
2298
|
+
computed: false,
|
|
2299
|
+
shorthand: false,
|
|
2300
|
+
}, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2301
|
+
if (selectElements) {
|
|
2068
2302
|
const newSelectElements = [...select.selectElements, selectElements];
|
|
2069
2303
|
select.setSelectElements(newSelectElements);
|
|
2070
2304
|
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
}
|
|
2305
|
+
}
|
|
2306
|
+
else {
|
|
2307
|
+
return (0, utils_1.throwError)(options, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2308
|
+
}
|
|
2075
2309
|
break;
|
|
2076
2310
|
case 'SELECT':
|
|
2077
2311
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2078
2312
|
distinct: false,
|
|
2079
2313
|
star: true,
|
|
2080
|
-
selectElements: groupBy
|
|
2314
|
+
selectElements: groupBy.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2081
2315
|
isDotStar: true,
|
|
2082
|
-
entityAsName: from
|
|
2316
|
+
entityAsName: from?.entityName,
|
|
2083
2317
|
propertyName: '',
|
|
2084
2318
|
})] : [],
|
|
2085
2319
|
});
|
|
2320
|
+
if (item.arguments[0].type !== 'ObjectExpression') {
|
|
2321
|
+
select = undefined;
|
|
2322
|
+
return (0, utils_1.throwError)(options, 'SELECT 参数应为 ObjectExpression,标准示例:.SELECT({ ... })', node);
|
|
2323
|
+
}
|
|
2086
2324
|
item.arguments[0].properties?.forEach((arg) => {
|
|
2087
2325
|
let selectElements = [];
|
|
2088
2326
|
if (arg.value.type === 'CallExpression') {
|
|
2089
2327
|
selectElements = [transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2090
2328
|
}
|
|
2091
2329
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2092
|
-
if (groupBy
|
|
2093
|
-
(0, utils_1.throwError)('存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2330
|
+
if (groupBy.length) {
|
|
2331
|
+
return (0, utils_1.throwError)(options, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2094
2332
|
}
|
|
2095
2333
|
const originName = arg.key?.name || '';
|
|
2096
2334
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2097
2335
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2098
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}
|
|
2336
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2099
2337
|
}
|
|
2100
2338
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2101
2339
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2102
2340
|
if (!entityAsNames.includes(entityName)) {
|
|
2103
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}
|
|
2341
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2104
2342
|
}
|
|
2105
2343
|
selectElements = arg.value.properties?.map((property) => {
|
|
2106
2344
|
const columnAsName = property.key?.name;
|
|
@@ -2108,7 +2346,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2108
2346
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2109
2347
|
if (columnAsName !== columnPropertyName) {
|
|
2110
2348
|
// eg: comment: Topic_Comment.comment_stu
|
|
2111
|
-
(0, utils_1.throwError)(`SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}
|
|
2349
|
+
return (0, utils_1.throwError)(options, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2112
2350
|
}
|
|
2113
2351
|
selectElement.isDotStar = false;
|
|
2114
2352
|
return selectElement;
|
|
@@ -2118,6 +2356,9 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2118
2356
|
if (arg.value.type === 'MemberExpression') {
|
|
2119
2357
|
hasErrorTSScopeColumn = true;
|
|
2120
2358
|
}
|
|
2359
|
+
if (arg.type === 'ObjectProperty' && select?.selectElements?.find(item => item?.concept === 'QueryFieldExpression' && item.entityAsName === arg.value?.name)) {
|
|
2360
|
+
return (0, utils_1.throwError)(options, `SELECT 禁止在一次查询中对同一实体设置多个别名,请修改`, node);
|
|
2361
|
+
}
|
|
2121
2362
|
selectElements = [transform2SelectQueryFieldExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2122
2363
|
}
|
|
2123
2364
|
const selectElement = selectElements?.[0];
|
|
@@ -2143,32 +2384,43 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2143
2384
|
}
|
|
2144
2385
|
}
|
|
2145
2386
|
else {
|
|
2146
|
-
(0, utils_1.throwError)('HAVING 不符合规范,请使用箭头函数');
|
|
2387
|
+
return (0, utils_1.throwError)(options, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2147
2388
|
}
|
|
2148
2389
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2149
2390
|
break;
|
|
2150
2391
|
case 'ORDER_BY':
|
|
2392
|
+
const ORDER_BY_ERROR_MESSAGE = `ORDER_BY 不符合规范,请使用箭头函数,并返回 Array<[字段值, "ASC" | "DESC"]> 的形式,示例:
|
|
2393
|
+
- .ORDER_BY((resultItem) => [[resultItem[sort], order]])
|
|
2394
|
+
- .ORDER_BY((resultItem) => [[Student.age, 'ASC'], [Student.name, 'DESC']])`;
|
|
2151
2395
|
let orderNode = item.arguments;
|
|
2152
2396
|
let restOptionParams = { entityAsNames };
|
|
2153
|
-
if (orderNode
|
|
2154
|
-
const params = orderNode
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2397
|
+
if (orderNode.length === 1 && orderNode[0].type === 'ArrowFunctionExpression') {
|
|
2398
|
+
const params = orderNode[0].params;
|
|
2399
|
+
if (orderNode[0].body.type !== 'ArrayExpression') {
|
|
2400
|
+
return (0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, orderNode, node);
|
|
2401
|
+
}
|
|
2402
|
+
orderNode = orderNode[0].body.elements;
|
|
2403
|
+
if (params.length && params[0].name) {
|
|
2404
|
+
restOptionParams = { inOqlIdentifierNamespace: params[0].name, entityAsNames };
|
|
2158
2405
|
}
|
|
2159
2406
|
}
|
|
2160
2407
|
else {
|
|
2161
|
-
(0, utils_1.throwError)(
|
|
2408
|
+
return (0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, orderNode, node);
|
|
2162
2409
|
}
|
|
2163
2410
|
orderBy = orderNode.map((arg) => {
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2411
|
+
if (arg.type === 'ArrayExpression') {
|
|
2412
|
+
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
2413
|
+
if (!useResultItem) {
|
|
2414
|
+
useResultItem = orderElementCode.includes('resultItem.');
|
|
2415
|
+
}
|
|
2416
|
+
return new utils_1.naslTypes.QueryOrderByExpression({
|
|
2417
|
+
orderElement: transformNodeFunction(arg.elements[0], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName }),
|
|
2418
|
+
order: transformNodeFunction(arg.elements[1], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName })
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
else {
|
|
2422
|
+
(0, utils_1.throwError)(options, ORDER_BY_ERROR_MESSAGE, arg, node);
|
|
2167
2423
|
}
|
|
2168
|
-
return new utils_1.naslTypes.QueryOrderByExpression({
|
|
2169
|
-
orderElement: transformNodeFunction(arg.elements[0], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName }),
|
|
2170
|
-
order: transformNodeFunction(arg.elements[1], { ...options, ...restOptionParams, inCallQueryComponentField: item.calleeName })
|
|
2171
|
-
});
|
|
2172
2424
|
});
|
|
2173
2425
|
break;
|
|
2174
2426
|
}
|
|
@@ -2183,25 +2435,30 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2183
2435
|
orderBy,
|
|
2184
2436
|
ideVersion: '2.22',
|
|
2185
2437
|
});
|
|
2186
|
-
if (
|
|
2187
|
-
(0, utils_1.throwError)('SELECT
|
|
2438
|
+
if (!select) {
|
|
2439
|
+
return (0, utils_1.throwError)(options, 'SELECT 不符合规范', node);
|
|
2188
2440
|
}
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2441
|
+
if (hasErrorTSScopeColumn && !groupBy.length && !having) {
|
|
2442
|
+
return (0, utils_1.throwError)(options, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2443
|
+
}
|
|
2444
|
+
const hasScopeColumn = select.selectElements.find((selectElement) => selectElement.concept === 'QueryFieldExpression' && !selectElement.isDotStar);
|
|
2445
|
+
if (hasScopeColumn && (groupBy.length || having)) {
|
|
2446
|
+
return (0, utils_1.throwError)(options, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2192
2447
|
}
|
|
2193
2448
|
if (hasScopeColumn && useResultItem) {
|
|
2194
|
-
(0, utils_1.throwError)("对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])");
|
|
2449
|
+
return (0, utils_1.throwError)(options, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])", node);
|
|
2195
2450
|
}
|
|
2196
|
-
const
|
|
2451
|
+
const onlyAggr = select.selectElements.length && select.selectElements.every((selectElement) => selectElement.concept === 'QueryAggregateExpression');
|
|
2197
2452
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2198
|
-
if (
|
|
2199
|
-
(0, utils_1.throwError)('SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2453
|
+
if (onlyAggr && !calleeNames.includes('AGGR_SELECT')) {
|
|
2454
|
+
return (0, utils_1.throwError)(options, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2200
2455
|
}
|
|
2201
2456
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2202
2457
|
return callQueryComponent;
|
|
2203
2458
|
}
|
|
2204
2459
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2460
|
+
if (options?.isRestricted)
|
|
2461
|
+
return (0, utils_1.throwError)(options, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2205
2462
|
const args = node.arguments;
|
|
2206
2463
|
const dataArg = args?.[0];
|
|
2207
2464
|
const procDefKeyArg = args?.[1];
|
|
@@ -2220,6 +2477,14 @@ function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
|
2220
2477
|
],
|
|
2221
2478
|
});
|
|
2222
2479
|
}
|
|
2480
|
+
// 处理文件夹
|
|
2481
|
+
function transformNode2Directory(node) {
|
|
2482
|
+
const newNode = new utils_1.naslTypes.Directory({
|
|
2483
|
+
name: node.value.name,
|
|
2484
|
+
});
|
|
2485
|
+
return newNode;
|
|
2486
|
+
}
|
|
2487
|
+
exports.transformNode2Directory = transformNode2Directory;
|
|
2223
2488
|
function transform2LogicItem(node, options) {
|
|
2224
2489
|
fixLogicNode(node);
|
|
2225
2490
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -2241,6 +2506,7 @@ function transform2LogicItem(node, options) {
|
|
|
2241
2506
|
transformManager.register('NullLiteral', transform2NullLiteral);
|
|
2242
2507
|
transformManager.register('RegExpLiteral', transform2NewRegex);
|
|
2243
2508
|
transformManager.register('TemplateLiteral', transform2StringInterpolation);
|
|
2509
|
+
transformManager.register((node) => node.type === 'LogicalExpression' && node.operator === '??', transformDefaultExpression);
|
|
2244
2510
|
transformManager.register('BinaryExpression', transform2BinaryExpression);
|
|
2245
2511
|
transformManager.register('LogicalExpression', transform2BinaryExpression);
|
|
2246
2512
|
transformManager.register('UpdateExpression', transformUpdateExpression2Assignment);
|
|
@@ -2278,7 +2544,8 @@ function transform2LogicItem(node, options) {
|
|
|
2278
2544
|
}
|
|
2279
2545
|
});
|
|
2280
2546
|
transformManager.register('MemberExpression', transformMemberExpression);
|
|
2281
|
-
transformManager.register(
|
|
2547
|
+
transformManager.register('OptionalMemberExpression', transformMemberExpression);
|
|
2548
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && (node.callee.type === 'FunctionExpression' && node.callee.id?.name === 'match' || node.callee.type === 'ArrowFunctionExpression'), transformCallFunctionExpression2Match);
|
|
2282
2549
|
transformManager.registerCallExpression((node, calleeName) => /^\$refs\./.test(calleeName), transformCall2CallViewElementLogic);
|
|
2283
2550
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity'), transformCall2CallEntityLogic);
|
|
2284
2551
|
transformManager.registerCallExpression('nasl.oql.query', transformCall2OQLQuery);
|
|
@@ -2287,10 +2554,12 @@ function transform2LogicItem(node, options) {
|
|
|
2287
2554
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.logging.'), transformCall2Logging);
|
|
2288
2555
|
transformManager.registerCallExpression('nasl.util.jsonSerialize', transformCall2JSONFunctions);
|
|
2289
2556
|
transformManager.registerCallExpression('nasl.util.jsonDeserialize', transformCall2JSONFunctions);
|
|
2557
|
+
transformManager.registerCallExpression((node, calleeName) => (calleeName.startsWith('nasl.event.') || calleeName.startsWith('event.')) && (calleeName.endsWith('.preventDefault') || calleeName.endsWith('.stopPropagation')), transform2CallEventLogic);
|
|
2290
2558
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.forEach'), transformForEach2ForEachStatement);
|
|
2291
2559
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.util.'), transformCall2CallFunction);
|
|
2292
2560
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.auth.'), transformCall2LogicWithAuth);
|
|
2293
2561
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.ui.'), transform2UIFunction);
|
|
2562
|
+
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.browser.'), transform2CallOtherNASLLogic);
|
|
2294
2563
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.map'), transformMap2ListTransform);
|
|
2295
2564
|
transformManager.registerCallExpression('ForEach', transform2ForEachStatement);
|
|
2296
2565
|
transformManager.registerCallExpression('alert', transformAlert2ShowMessage);
|
|
@@ -2300,15 +2569,24 @@ function transform2LogicItem(node, options) {
|
|
|
2300
2569
|
transformManager.registerCallExpression('extensions.lcap_process_framework.logics.launchProcess', transformCall2LaunchProcess);
|
|
2301
2570
|
transformManager.registerCallExpression((node, calleeName) => /extensions\./.test(calleeName), transformCall2Extension);
|
|
2302
2571
|
transformManager.registerCallExpression((node, calleeName) => /connectors\./.test(calleeName), transformCall2Connector);
|
|
2303
|
-
transformManager.registerCallExpression((node) => node.callee.type === 'ArrowFunctionExpression', transformArrowFunction2Match);
|
|
2304
2572
|
transformManager.registerCallExpression((node, calleeName) => ['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'].includes(calleeName), transformCallExpressionToBinaryExpression);
|
|
2305
2573
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && calleeName.startsWith('viewLogic_'), transformCall2CallViewLogic);
|
|
2306
2574
|
transformManager.registerCallExpression('PAGINATE', transformCall2Paginate);
|
|
2307
2575
|
transformManager.registerCallExpression('FROM', transformCall2DataQuery);
|
|
2308
|
-
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1, transformCall2Logic);
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2576
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2577
|
+
try {
|
|
2578
|
+
let result = transformManager.apply(node, options);
|
|
2579
|
+
return result || undefined;
|
|
2580
|
+
}
|
|
2581
|
+
catch (err) {
|
|
2582
|
+
if (err.name === 'ParseNaturalTSError')
|
|
2583
|
+
throw err;
|
|
2584
|
+
(0, utils_1.throwError)(options, `解析逻辑发生异常:${err?.message}\n相关代码如下`, node);
|
|
2585
|
+
return undefined;
|
|
2586
|
+
}
|
|
2587
|
+
finally {
|
|
2588
|
+
delete options.typeAnnotation;
|
|
2589
|
+
}
|
|
2312
2590
|
}
|
|
2313
2591
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2314
2592
|
//# sourceMappingURL=transform2LogicItem.js.map
|