@lcap/nasl 4.3.0-beta.9 → 4.3.0-creator.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/generator/genBundleFiles.d.ts +1 -0
- package/out/generator/genBundleFiles.d.ts.map +1 -1
- package/out/generator/genBundleFiles.js +2 -1
- 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/data.d.ts.map +1 -1
- package/out/generator/release-body/data.js +2 -0
- package/out/generator/release-body/data.js.map +1 -1
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +2 -1
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/out/natural/index.d.ts +2 -0
- package/out/natural/index.d.ts.map +1 -1
- package/out/natural/index.js +4 -0
- package/out/natural/index.js.map +1 -1
- package/out/natural/parseNaturalTS.d.ts +5 -8
- package/out/natural/parseNaturalTS.d.ts.map +1 -1
- package/out/natural/parseNaturalTS.js +211 -50
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +18 -0
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -0
- package/out/natural/parseNaturalTSXView.js +641 -0
- package/out/natural/parseNaturalTSXView.js.map +1 -0
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +16 -17
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts.map +1 -1
- package/out/natural/transformTSCode.js +4 -4
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/transform2Entity.d.ts +3 -1
- package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
- package/out/natural/transforms/transform2Entity.js +31 -7
- package/out/natural/transforms/transform2Entity.js.map +1 -1
- package/out/natural/transforms/transform2Enum.d.ts +3 -1
- package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
- package/out/natural/transforms/transform2Enum.js +19 -3
- package/out/natural/transforms/transform2Enum.js.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +3 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js +3 -3
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
- package/out/natural/transforms/transform2Logic.d.ts +9 -1
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +44 -7
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +61 -28
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +459 -198
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +5 -0
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -0
- package/out/natural/transforms/transform2MetadataType.js +14 -0
- package/out/natural/transforms/transform2MetadataType.js.map +1 -0
- package/out/natural/transforms/transform2Structure.d.ts +3 -1
- package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
- package/out/natural/transforms/transform2Structure.js +4 -4
- package/out/natural/transforms/transform2Structure.js.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +3 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.js +15 -11
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts +5 -0
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -0
- package/out/natural/transforms/transform2ValidationRule.js +24 -0
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -0
- package/out/natural/transforms/transform2Variable.d.ts +6 -1
- package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
- package/out/natural/transforms/transform2Variable.js +30 -6
- package/out/natural/transforms/transform2Variable.js.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.d.ts +28 -0
- package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -0
- package/out/natural/transforms/transformThemeAndStyle.js +269 -0
- package/out/natural/transforms/transformThemeAndStyle.js.map +1 -0
- package/out/natural/transforms/utils.d.ts +22 -3
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +80 -12
- package/out/natural/transforms/utils.js.map +1 -1
- package/out/server/OQL/oql-cache.d.ts.map +1 -1
- package/out/server/OQL/oql-cache.js +3 -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/extendBaseNode.js +1 -1
- package/out/server/extendBaseNode.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 +6 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +76 -21
- package/out/server/naslServer.js.map +1 -1
- package/out/service/autofix/rules/rule-delete-void-expression.d.ts.map +1 -1
- package/out/service/autofix/rules/rule-delete-void-expression.js +5 -1
- package/out/service/autofix/rules/rule-delete-void-expression.js.map +1 -1
- package/out/service/creator/errHandles.js +0 -5
- package/out/service/creator/errHandles.js.map +1 -1
- package/out/service/initial/form-designer.d.ts +1 -1
- package/out/service/initial/form-designer.d.ts.map +1 -1
- package/out/service/initial/form-designer.js +4 -1
- package/out/service/initial/form-designer.js.map +1 -1
- package/out/service/initial/processV2.d.ts +1 -1
- package/out/service/initial/processV2.d.ts.map +1 -1
- package/out/service/initial/processV2.js +4 -1
- package/out/service/initial/processV2.js.map +1 -1
- package/out/service/initial/types.d.ts +1 -0
- package/out/service/initial/types.d.ts.map +1 -1
- package/out/service/storage/init.d.ts +5 -0
- package/out/service/storage/init.d.ts.map +1 -1
- package/out/service/storage/init.js +9 -3
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/service.d.ts.map +1 -1
- package/out/service/storage/service.js +1 -0
- package/out/service/storage/service.js.map +1 -1
- package/out/templator/utils.d.ts +16 -7
- package/out/templator/utils.d.ts.map +1 -1
- package/out/templator/utils.js +14 -2
- package/out/templator/utils.js.map +1 -1
- package/package.json +14 -12
- package/sandbox/stdlib/nasl.io.ts +10 -0
- package/sandbox/stdlib/nasl.oql.ts +1 -0
- package/sandbox/stdlib/nasl.ui.ts +1 -9
- 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.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?.parsingId, '不支持连续调用!', node.callee);
|
|
28
28
|
const callee = flatMemberExpression(node.callee);
|
|
29
29
|
if (callee[0]
|
|
30
30
|
&& callee[0].type === 'CallExpression'
|
|
@@ -36,9 +36,8 @@ class TransformManager {
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
for (const calleeItem of callee) {
|
|
39
|
-
if (calleeItem.type !== 'Identifier') {
|
|
40
|
-
|
|
41
|
-
(0, utils_1.throwError)(`不支持连续调用!${calleeName}`);
|
|
39
|
+
if (calleeItem.type !== 'Identifier' && !(calleeItem.type === 'FunctionExpression' && calleeItem.id?.name === 'match')) {
|
|
40
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持连续调用!', node.callee);
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
@@ -48,7 +47,7 @@ class TransformManager {
|
|
|
48
47
|
return transform(node, calleeName, callee, options);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
(0, utils_1.throwError)(
|
|
50
|
+
return (0, utils_1.throwError)(options?.parsingId, `不支持的节点类型 ${callee.map((item) => item.name).join('.')}`, node.type, node);
|
|
52
51
|
}
|
|
53
52
|
else {
|
|
54
53
|
for (const [type, transform] of this.transforms) {
|
|
@@ -56,7 +55,7 @@ class TransformManager {
|
|
|
56
55
|
return transform(node, options);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
(0, utils_1.throwError)(
|
|
58
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的节点类型', node.type, node);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
}
|
|
@@ -78,7 +77,10 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
78
77
|
statements = [...node?.body?.directives, ...node?.body?.body];
|
|
79
78
|
}
|
|
80
79
|
parameters.forEach((node) => {
|
|
81
|
-
const param = transform2Param(node);
|
|
80
|
+
const param = transform2Param(node, options);
|
|
81
|
+
if (param && !param?.typeAnnotation) {
|
|
82
|
+
param.typeAnnotation = null;
|
|
83
|
+
}
|
|
82
84
|
param && logic.addParam(param);
|
|
83
85
|
});
|
|
84
86
|
const newStatements = [];
|
|
@@ -122,9 +124,9 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
122
124
|
}
|
|
123
125
|
return logic;
|
|
124
126
|
}
|
|
125
|
-
function assertAssignmentRightIsNotAnonymousFunction(expression) {
|
|
127
|
+
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
126
128
|
if (expression?.concept === 'AnonymousFunction')
|
|
127
|
-
(0, utils_1.throwError)('Anonymous function is not allowed in assignment');
|
|
129
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function is not allowed in assignment');
|
|
128
130
|
return expression;
|
|
129
131
|
}
|
|
130
132
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -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, { parsingId: options?.parsingId, 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, { parsingId: options?.parsingId, 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, { parsingId: options?.parsingId, 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, { parsingId: options?.parsingId, 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?.parsingId, '在输入参数中不支持节点类型', 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?.parsingId, `${calleeName} 仅支持在数据查询中使用`, node);
|
|
366
|
+
}
|
|
367
|
+
if (calleeName === 'IS_NULL') {
|
|
368
|
+
return new utils_1.naslTypes.UnaryExpression({
|
|
369
|
+
operator: 'isNull',
|
|
370
|
+
argument: transformNodeFunction(argument?.[0], options),
|
|
371
|
+
});
|
|
372
|
+
}
|
|
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?.parsingId, '在二元表达式中不支持节点类型', 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?.parsingId, `数据查询中不支持条件表达式!${(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?.parsingId, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
else if (itemValue.type === 'TSAsExpression') {
|
|
522
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation, options);
|
|
523
|
+
item.naslType = typeAnnotation;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
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?.parsingId, '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?.parsingId, '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?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
555
599
|
}
|
|
556
600
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
557
601
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -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
|
});
|
|
@@ -785,6 +829,16 @@ function transformIdentifier(node, options) {
|
|
|
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
|
+
}
|
|
788
842
|
return new utils_1.naslTypes.Identifier({
|
|
789
843
|
name: node.name,
|
|
790
844
|
});
|
|
@@ -794,6 +848,10 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
794
848
|
let expression = node.value;
|
|
795
849
|
let asNameNode = node.key;
|
|
796
850
|
if (expression.type === 'Identifier') {
|
|
851
|
+
const isSameName = (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name;
|
|
852
|
+
if (!isSameName) {
|
|
853
|
+
return (0, utils_1.throwError)(options?.parsingId, `字段名需为 ${(0, utils_2.firstLowerCase)(expression.name)}, 目前为: ${asNameNode.name}, 相关代码如下`, node);
|
|
854
|
+
}
|
|
797
855
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
798
856
|
isDotStar: true,
|
|
799
857
|
asName: (0, utils_2.firstUpperCase)(asNameNode.name) === expression.name ? undefined : asNameNode.name,
|
|
@@ -813,7 +871,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
813
871
|
// @TODO
|
|
814
872
|
}
|
|
815
873
|
else {
|
|
816
|
-
(0, utils_1.throwError)(
|
|
874
|
+
return (0, utils_1.throwError)(options?.parsingId, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
817
875
|
}
|
|
818
876
|
}
|
|
819
877
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -822,10 +880,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
822
880
|
const arg = callExpression.arguments[0];
|
|
823
881
|
if (arg.type !== 'MemberExpression') {
|
|
824
882
|
const code = (0, utils_1.generate)(arg).code;
|
|
825
|
-
(0, utils_1.throwError)(`聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
883
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
826
884
|
}
|
|
827
885
|
if (callExpression.arguments?.length > 1) {
|
|
828
|
-
(0, utils_1.throwError)(`聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
886
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
829
887
|
}
|
|
830
888
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
831
889
|
asName: asNameNode.name,
|
|
@@ -835,10 +893,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
835
893
|
}
|
|
836
894
|
function transform2AnonymousFunction(node, options) {
|
|
837
895
|
if (node.body.type === 'BlockStatement')
|
|
838
|
-
(0, utils_1.throwError)('Anonymous function with block statement is not supported');
|
|
896
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function with block statement is not supported', node);
|
|
839
897
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
840
898
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
841
|
-
params: node.params.map((param) => transform2Param(param)),
|
|
899
|
+
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
842
900
|
body: transformNodeFunction(node.body, options),
|
|
843
901
|
});
|
|
844
902
|
}
|
|
@@ -867,7 +925,7 @@ function transform2Assignment(node, options) {
|
|
|
867
925
|
}
|
|
868
926
|
return new utils_1.naslTypes.Assignment({
|
|
869
927
|
left: transformNodeFunction(node.left, options),
|
|
870
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options)),
|
|
928
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options), options) || undefined,
|
|
871
929
|
});
|
|
872
930
|
}
|
|
873
931
|
exports.transform2Assignment = transform2Assignment;
|
|
@@ -913,10 +971,11 @@ function transform2NumericLiteral(node, options) {
|
|
|
913
971
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
914
972
|
});
|
|
915
973
|
literal.typeAnnotation.typeName = literal.changeType(value);
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
974
|
+
// 新版本依赖自转换
|
|
975
|
+
// if (options.typeAnnotation && ['Integer', 'Long', 'Decimal'].includes(options.typeAnnotation.typeName)) {
|
|
976
|
+
// literal.typeAnnotation = options.typeAnnotation;
|
|
977
|
+
// delete options.typeAnnotation;
|
|
978
|
+
// }
|
|
920
979
|
return literal;
|
|
921
980
|
}
|
|
922
981
|
exports.transform2NumericLiteral = transform2NumericLiteral;
|
|
@@ -944,15 +1003,15 @@ function transformReturnStatement2AssignmentOrEnd(node, options) {
|
|
|
944
1003
|
}
|
|
945
1004
|
}
|
|
946
1005
|
if (!logic.returns.length) {
|
|
947
|
-
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation) : undefined;
|
|
1006
|
+
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation, options) || undefined : undefined;
|
|
948
1007
|
logic.returns.push(new utils_1.naslTypes.Return({
|
|
949
1008
|
name: 'result',
|
|
950
1009
|
typeAnnotation
|
|
951
1010
|
}));
|
|
952
1011
|
}
|
|
953
1012
|
const leftName = logic.returns[0].name;
|
|
954
|
-
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options));
|
|
955
|
-
if (right.concept === 'Identifier' && right.name === leftName) {
|
|
1013
|
+
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options), options) || undefined;
|
|
1014
|
+
if (right && right.concept === 'Identifier' && right.name === leftName) {
|
|
956
1015
|
return new utils_1.naslTypes.End();
|
|
957
1016
|
}
|
|
958
1017
|
else {
|
|
@@ -1002,7 +1061,7 @@ function transform2PartialNewComposite(node, options) {
|
|
|
1002
1061
|
const rights = [];
|
|
1003
1062
|
const structureProperties = [];
|
|
1004
1063
|
const assignmentLines = [];
|
|
1005
|
-
const newProperties = (node?.properties || node?.arguments?.[0]?.properties)
|
|
1064
|
+
const newProperties = (node?.properties || node?.arguments?.[0]?.properties);
|
|
1006
1065
|
let idx = 0;
|
|
1007
1066
|
newProperties?.forEach((arg, index) => {
|
|
1008
1067
|
properties.push(transformNodeFunction(arg.key, options));
|
|
@@ -1083,6 +1142,27 @@ function transform2PartialNewComposite(node, options) {
|
|
|
1083
1142
|
});
|
|
1084
1143
|
}
|
|
1085
1144
|
exports.transform2PartialNewComposite = transform2PartialNewComposite;
|
|
1145
|
+
function transform2NewRegex(node, options) {
|
|
1146
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1147
|
+
let pattern;
|
|
1148
|
+
let flags;
|
|
1149
|
+
if (node.type === 'RegExpLiteral') {
|
|
1150
|
+
// 处理正则表达式字面量 /pattern/flags
|
|
1151
|
+
pattern = new utils_1.naslTypes.StringLiteral({ value: node?.pattern || '' });
|
|
1152
|
+
flags = new utils_1.naslTypes.StringLiteral({ value: node?.flags || '' });
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
// 处理 new RegExp(pattern, flags)
|
|
1156
|
+
pattern = transformNodeFunction(node.arguments[0], options) || undefined;
|
|
1157
|
+
flags = node.arguments[1] ? transformNodeFunction(node.arguments[1], options) : undefined;
|
|
1158
|
+
}
|
|
1159
|
+
return new utils_1.naslTypes.NewRegex({
|
|
1160
|
+
kind: "dynamic",
|
|
1161
|
+
pattern,
|
|
1162
|
+
flags
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
exports.transform2NewRegex = transform2NewRegex;
|
|
1086
1166
|
function transformNewExpression(node, options) {
|
|
1087
1167
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1088
1168
|
const calleeName = (0, utils_1.generate)(node.callee).code;
|
|
@@ -1092,11 +1172,13 @@ function transformNewExpression(node, options) {
|
|
|
1092
1172
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive(calleeName),
|
|
1093
1173
|
});
|
|
1094
1174
|
}
|
|
1175
|
+
else if (calleeName === 'RegExp') {
|
|
1176
|
+
return transform2NewRegex(node, options);
|
|
1177
|
+
}
|
|
1095
1178
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1096
1179
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1097
1180
|
}
|
|
1098
|
-
|
|
1099
|
-
(0, utils_1.throwError)(`Unhandled node ${node.type}: ${errCode}`);
|
|
1181
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
1100
1182
|
}
|
|
1101
1183
|
exports.transformNewExpression = transformNewExpression;
|
|
1102
1184
|
function transformMemberExpression(node, options) {
|
|
@@ -1133,18 +1215,31 @@ function transformMemberExpression(node, options) {
|
|
|
1133
1215
|
});
|
|
1134
1216
|
}
|
|
1135
1217
|
if (calleeName?.startsWith('$refs.')) {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1218
|
+
if (callee[0].type === 'CallExpression') {
|
|
1219
|
+
const callExpression = callee[0];
|
|
1220
|
+
const callCallee = flatMemberExpression(callExpression.callee);
|
|
1221
|
+
const callCalleeName = (0, utils_1.generate)(callExpression)?.code;
|
|
1222
|
+
let callResult = transformCall2CallViewElementLogic(callExpression, callCalleeName, callCallee, options);
|
|
1223
|
+
const remainingCallee = callee.slice(1);
|
|
1224
|
+
if (remainingCallee.length > 0 && callResult) {
|
|
1225
|
+
return unflatMemberExpression(remainingCallee, options, callResult);
|
|
1226
|
+
}
|
|
1227
|
+
return callResult;
|
|
1228
|
+
}
|
|
1229
|
+
else {
|
|
1230
|
+
const componentName = callee?.[1]?.name;
|
|
1231
|
+
const propertyName = callee?.[2]?.name;
|
|
1232
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
1233
|
+
object: new utils_1.naslTypes.Identifier({
|
|
1234
|
+
namespace: `elements.${componentName}.property`,
|
|
1235
|
+
name: componentName,
|
|
1236
|
+
}),
|
|
1237
|
+
property: new utils_1.naslTypes.Identifier({
|
|
1238
|
+
namespace: propertyName,
|
|
1239
|
+
name: propertyName,
|
|
1240
|
+
}),
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1148
1243
|
}
|
|
1149
1244
|
const regex = /^(app\..+?)\.variables\.(.+)$/;
|
|
1150
1245
|
if (regex.test(calleeName)) {
|
|
@@ -1199,12 +1294,88 @@ function transformMemberExpression(node, options) {
|
|
|
1199
1294
|
});
|
|
1200
1295
|
}
|
|
1201
1296
|
exports.transformMemberExpression = transformMemberExpression;
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1297
|
+
/**
|
|
1298
|
+
* @example (function match(_value) {
|
|
1299
|
+
if (_value === true) {
|
|
1300
|
+
return 'green'
|
|
1301
|
+
} else {
|
|
1302
|
+
return 'red'
|
|
1303
|
+
}
|
|
1304
|
+
})(nasl.util.Convert<Boolean>(enabled))
|
|
1305
|
+
*/
|
|
1306
|
+
function transformCallFunctionExpression2Match(node, calleeName, callee, options) {
|
|
1307
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1308
|
+
const arg = node.arguments[0];
|
|
1309
|
+
const ifStatement = node.callee.body.body[0];
|
|
1310
|
+
if (ifStatement.type !== 'IfStatement') {
|
|
1311
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1312
|
+
}
|
|
1313
|
+
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1314
|
+
const match = new utils_1.naslTypes.Match({
|
|
1315
|
+
expression: transformNodeFunction(arg, options),
|
|
1316
|
+
isExpression: true,
|
|
1317
|
+
cases: flatedIfStatements.map((_case) => {
|
|
1318
|
+
let argument;
|
|
1319
|
+
if (_case.consequent.type === 'BlockStatement') {
|
|
1320
|
+
if (_case.consequent.body.length === 1 && _case.consequent.body[0].type === 'ReturnStatement') {
|
|
1321
|
+
argument = _case.consequent.body[0].argument;
|
|
1322
|
+
}
|
|
1323
|
+
else {
|
|
1324
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
else {
|
|
1328
|
+
if (_case.consequent.type === 'ReturnStatement') {
|
|
1329
|
+
argument = _case.consequent.argument;
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
const bodyNode = transformNodeFunction(argument, options);
|
|
1336
|
+
return new utils_1.naslTypes.MatchCase({
|
|
1337
|
+
isMatchedTypeEnumable: false,
|
|
1338
|
+
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1339
|
+
body: bodyNode ? [bodyNode] : [],
|
|
1340
|
+
});
|
|
1341
|
+
}).filter(Boolean),
|
|
1342
|
+
});
|
|
1343
|
+
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1344
|
+
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1345
|
+
isMatchedTypeEnumable: false,
|
|
1346
|
+
patterns: [],
|
|
1347
|
+
body: [],
|
|
1348
|
+
}));
|
|
1349
|
+
}
|
|
1350
|
+
match.cases.forEach((case_) => {
|
|
1351
|
+
if (case_.patterns.length) {
|
|
1352
|
+
if (case_.patterns[0].concept === 'BooleanLiteral' || case_.patterns[0].concept === 'StringLiteral') {
|
|
1353
|
+
case_.isMatchedTypeEnumable = true;
|
|
1354
|
+
}
|
|
1355
|
+
if (case_.patterns[0].concept === 'MemberExpression') {
|
|
1356
|
+
case_.isMatchedTypeEnumable = true;
|
|
1357
|
+
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1358
|
+
object: {
|
|
1359
|
+
concept: 'Identifier',
|
|
1360
|
+
name: case_.patterns[0].object.property.name,
|
|
1361
|
+
folded: false,
|
|
1362
|
+
namespace: 'app.enums'
|
|
1363
|
+
},
|
|
1364
|
+
property: {
|
|
1365
|
+
concept: 'Identifier',
|
|
1366
|
+
name: case_.patterns[0].property.value,
|
|
1367
|
+
folded: false,
|
|
1368
|
+
},
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
return match;
|
|
1205
1374
|
}
|
|
1206
|
-
exports.
|
|
1375
|
+
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1207
1376
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1377
|
+
if (options?.isRestricted)
|
|
1378
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1208
1379
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1209
1380
|
const componentName = callee?.[1]?.name;
|
|
1210
1381
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1239,6 +1410,8 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1239
1410
|
}
|
|
1240
1411
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1241
1412
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1413
|
+
if (options?.isRestricted)
|
|
1414
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1242
1415
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1243
1416
|
// console.log('callee', callee);
|
|
1244
1417
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1251,6 +1424,8 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1251
1424
|
}
|
|
1252
1425
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1253
1426
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1427
|
+
if (options?.isRestricted)
|
|
1428
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1254
1429
|
if (calleeName?.includes('.entities.')) {
|
|
1255
1430
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1256
1431
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1309,6 +1484,10 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1309
1484
|
}
|
|
1310
1485
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1311
1486
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1487
|
+
if (options?.isInFrontend)
|
|
1488
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在前端使用', node);
|
|
1489
|
+
if (options?.isRestricted)
|
|
1490
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1312
1491
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1313
1492
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1314
1493
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1318,11 +1497,13 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1318
1497
|
return new utils_1.naslTypes.OqlQueryComponent({
|
|
1319
1498
|
dataSource: 'app.dataSources.defaultDS',
|
|
1320
1499
|
code,
|
|
1321
|
-
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations)
|
|
1500
|
+
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations, options) || undefined,
|
|
1322
1501
|
});
|
|
1323
1502
|
}
|
|
1324
1503
|
}
|
|
1325
1504
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1505
|
+
if (options?.isRestricted)
|
|
1506
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1326
1507
|
return new utils_1.naslTypes.CallLogic({
|
|
1327
1508
|
calleeNamespace: 'nasl.logging',
|
|
1328
1509
|
calleeName: 'INFO',
|
|
@@ -1334,6 +1515,8 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1334
1515
|
}
|
|
1335
1516
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1336
1517
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1518
|
+
if (options?.isRestricted)
|
|
1519
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1337
1520
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1338
1521
|
expression: arg?.name === "undefined" ?
|
|
1339
1522
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1365,10 +1548,32 @@ function transformCall2JSONFunctions(node, calleeName, callee, options) {
|
|
|
1365
1548
|
keyword: 'arg',
|
|
1366
1549
|
}),
|
|
1367
1550
|
],
|
|
1368
|
-
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType })),
|
|
1551
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1369
1552
|
});
|
|
1370
1553
|
}
|
|
1371
1554
|
exports.transformCall2JSONFunctions = transformCall2JSONFunctions;
|
|
1555
|
+
function transform2CallEventLogic(node, calleeName, callee, options) {
|
|
1556
|
+
const lastName = callee[callee.length - 1].name;
|
|
1557
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1558
|
+
calleeNamespace: 'nasl.event',
|
|
1559
|
+
calleeName: lastName,
|
|
1560
|
+
shortcut: true,
|
|
1561
|
+
arguments: [],
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
exports.transform2CallEventLogic = transform2CallEventLogic;
|
|
1565
|
+
function transform2CallOtherNASLLogic(node, calleeName, callee, options) {
|
|
1566
|
+
const arr = calleeName.split('.');
|
|
1567
|
+
const lastName = arr.pop();
|
|
1568
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1569
|
+
calleeNamespace: arr.join('.'),
|
|
1570
|
+
calleeName: lastName,
|
|
1571
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
1572
|
+
expression: fixExpression(arg, options),
|
|
1573
|
+
})),
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
exports.transform2CallOtherNASLLogic = transform2CallOtherNASLLogic;
|
|
1372
1577
|
function transform2CallFunction(node, calleeName, argument, options) {
|
|
1373
1578
|
calleeName = utils_1.replaceCallFunctionMap?.[calleeName] || calleeName;
|
|
1374
1579
|
const func = server_1.default ? server_1.default.getBuildInFunction(calleeName) : null;
|
|
@@ -1382,8 +1587,13 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1382
1587
|
keyword: func && func?.params[index]?.name || `param${index + 1}`,
|
|
1383
1588
|
});
|
|
1384
1589
|
});
|
|
1385
|
-
let newTypeArguments = node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation);
|
|
1386
|
-
if (calleeName === 'ListRepeat') {
|
|
1590
|
+
let newTypeArguments = node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean);
|
|
1591
|
+
// if (calleeName === 'ListRepeat') {
|
|
1592
|
+
// newTypeArguments = [
|
|
1593
|
+
// new naslTypes.TypeAnnotation()
|
|
1594
|
+
// ];
|
|
1595
|
+
// }
|
|
1596
|
+
if (calleeName === 'Convert' && !newTypeArguments) {
|
|
1387
1597
|
newTypeArguments = [
|
|
1388
1598
|
new utils_1.naslTypes.TypeAnnotation()
|
|
1389
1599
|
];
|
|
@@ -1394,6 +1604,11 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1394
1604
|
expressions: expressions?.filter(Boolean),
|
|
1395
1605
|
});
|
|
1396
1606
|
}
|
|
1607
|
+
if (calleeName === 'Convert' && !newTypeArguments) {
|
|
1608
|
+
newTypeArguments = [
|
|
1609
|
+
new utils_1.naslTypes.TypeAnnotation()
|
|
1610
|
+
];
|
|
1611
|
+
}
|
|
1397
1612
|
if (func) {
|
|
1398
1613
|
const needTypeMap = [
|
|
1399
1614
|
'ListDistinctBy',
|
|
@@ -1416,7 +1631,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1416
1631
|
const content = np?.toNaturalTS();
|
|
1417
1632
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1418
1633
|
if (!np && !p?.defaultExpression) {
|
|
1419
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1634
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1420
1635
|
}
|
|
1421
1636
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1422
1637
|
if (idx === 1) {
|
|
@@ -1449,7 +1664,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1449
1664
|
});
|
|
1450
1665
|
}
|
|
1451
1666
|
else {
|
|
1452
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1667
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}不存在`, node.callee, node);
|
|
1453
1668
|
}
|
|
1454
1669
|
if (!func.params?.length) {
|
|
1455
1670
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1471,7 +1686,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1471
1686
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1472
1687
|
const excludes = ['HasValue', 'ListSort'];
|
|
1473
1688
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1474
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1689
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1475
1690
|
}
|
|
1476
1691
|
else {
|
|
1477
1692
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1488,19 +1703,22 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1488
1703
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1489
1704
|
});
|
|
1490
1705
|
if (calleeName === 'ListSort') {
|
|
1491
|
-
|
|
1706
|
+
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1707
|
+
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1492
1708
|
}
|
|
1493
1709
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1494
|
-
(0, utils_1.throwError)(
|
|
1710
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1495
1711
|
}
|
|
1496
1712
|
return nodeElement;
|
|
1497
1713
|
}
|
|
1498
1714
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1499
1715
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1500
1716
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1501
|
-
(0, utils_1.throwError)(`数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}
|
|
1717
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`, node.callee, node);
|
|
1502
1718
|
}
|
|
1503
1719
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1720
|
+
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
1721
|
+
const func = server_1.default ? server_1.default?.getSqlFunction('mysql', calleeName) : null;
|
|
1504
1722
|
let addArguments = [];
|
|
1505
1723
|
if (specFunList.includes(calleeName)) {
|
|
1506
1724
|
const value = calleeName === 'COUNTD' ? 'DISTINCT' : 'ALL';
|
|
@@ -1513,20 +1731,20 @@ function transform2SqlFunction(node, calleeName, argument, options) {
|
|
|
1513
1731
|
}
|
|
1514
1732
|
const newArguments = argument.map((arg, index) => new utils_1.naslTypes.Argument({
|
|
1515
1733
|
expression: fixExpression(arg, options),
|
|
1516
|
-
keyword:
|
|
1734
|
+
keyword: func?.params[index]?.name || `param${index + 1}`,
|
|
1517
1735
|
}));
|
|
1518
1736
|
const nodeElement = new utils_1.naslTypes.CallFunction({
|
|
1519
1737
|
calleeNamespace: 'nasl.sqlFunction',
|
|
1520
1738
|
calleeName: utils_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1521
1739
|
arguments: [...addArguments, ...newArguments],
|
|
1522
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
1740
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1523
1741
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1524
1742
|
});
|
|
1525
1743
|
return nodeElement;
|
|
1526
1744
|
}
|
|
1527
1745
|
function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
1528
1746
|
let curCalleeName;
|
|
1529
|
-
if (callee.length
|
|
1747
|
+
if (callee.length >= 3)
|
|
1530
1748
|
curCalleeName = callee[callee.length - 1].name;
|
|
1531
1749
|
else {
|
|
1532
1750
|
let _callee = callee[0].callee;
|
|
@@ -1534,11 +1752,10 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1534
1752
|
_callee = _callee.callee;
|
|
1535
1753
|
curCalleeName = _callee.property.name;
|
|
1536
1754
|
}
|
|
1537
|
-
const argument = callee.length
|
|
1538
|
-
if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
;
|
|
1755
|
+
const argument = callee.length >= 3 ? node.arguments : callee[0].arguments;
|
|
1756
|
+
// if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1757
|
+
// return transformCallExpressionToBinaryExpression(node, curCalleeName, callee, options);
|
|
1758
|
+
// };
|
|
1542
1759
|
if (['NewList', 'NewMap', 'NewEntity', 'NewStructure', 'NewAnonymousStructure'].includes(curCalleeName)) {
|
|
1543
1760
|
return transform2NewExpression(curCalleeName, node, options);
|
|
1544
1761
|
}
|
|
@@ -1547,10 +1764,31 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1547
1764
|
exports.transformCall2CallFunction = transformCall2CallFunction;
|
|
1548
1765
|
function transform2UIFunction(node, calleeName, callee, options) {
|
|
1549
1766
|
if (callee[2].name === 'destination') {
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1767
|
+
let namespaceNode = node.arguments[0];
|
|
1768
|
+
let namespace = '';
|
|
1769
|
+
if (namespaceNode.type === 'TemplateLiteral') {
|
|
1770
|
+
namespace = namespaceNode.quasis[0]?.value?.cooked;
|
|
1771
|
+
}
|
|
1772
|
+
else if (namespaceNode.type === 'StringLiteral') {
|
|
1773
|
+
namespace = namespaceNode.value;
|
|
1774
|
+
}
|
|
1775
|
+
else {
|
|
1776
|
+
namespace = (0, utils_1.generate)(namespaceNode).code;
|
|
1777
|
+
}
|
|
1778
|
+
let nsArr;
|
|
1779
|
+
let viewNamespace = '';
|
|
1780
|
+
let viewName = '';
|
|
1781
|
+
if (namespace.startsWith('app.frontendTypes.')) {
|
|
1782
|
+
nsArr = namespace.split('.');
|
|
1783
|
+
viewName = nsArr.pop();
|
|
1784
|
+
viewNamespace = nsArr.join('.');
|
|
1785
|
+
}
|
|
1786
|
+
else {
|
|
1787
|
+
nsArr = namespace.split('.').map((item) => item.replace(/_view$/, ''));
|
|
1788
|
+
const pageType = nsArr.shift();
|
|
1789
|
+
viewName = nsArr.pop();
|
|
1790
|
+
viewNamespace = `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`;
|
|
1791
|
+
}
|
|
1554
1792
|
const newArguments = node?.arguments?.slice(1);
|
|
1555
1793
|
let argument = [];
|
|
1556
1794
|
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
@@ -1566,7 +1804,7 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1566
1804
|
}));
|
|
1567
1805
|
}
|
|
1568
1806
|
return new utils_1.naslTypes.Destination({
|
|
1569
|
-
viewNamespace
|
|
1807
|
+
viewNamespace,
|
|
1570
1808
|
viewName,
|
|
1571
1809
|
arguments: argument,
|
|
1572
1810
|
});
|
|
@@ -1576,6 +1814,11 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1576
1814
|
link: fixExpression(node?.arguments[0], options),
|
|
1577
1815
|
});
|
|
1578
1816
|
}
|
|
1817
|
+
if (options?.isRestricted)
|
|
1818
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1819
|
+
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1820
|
+
return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1821
|
+
}
|
|
1579
1822
|
return new utils_1.naslTypes.CallLogic({
|
|
1580
1823
|
calleeNamespace: 'nasl.ui',
|
|
1581
1824
|
calleeName: callee[2].name,
|
|
@@ -1612,11 +1855,11 @@ function transform2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1612
1855
|
each: transformNodeFunction(newCallee[0], options),
|
|
1613
1856
|
start: transformNodeFunction(newCallee[1], options),
|
|
1614
1857
|
end: newCallee[2]?.name === '__IDENTIFIER__' ? undefined : transformNodeFunction(newCallee[2], options),
|
|
1615
|
-
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0]) : new utils_1.naslTypes.Param({
|
|
1858
|
+
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0], options) || undefined : new utils_1.naslTypes.Param({
|
|
1616
1859
|
name: 'item',
|
|
1617
1860
|
typeAnnotation: undefined,
|
|
1618
1861
|
}),
|
|
1619
|
-
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1862
|
+
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1620
1863
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 4)}`,
|
|
1621
1864
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1622
1865
|
}),
|
|
@@ -1643,8 +1886,8 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1643
1886
|
let endNode;
|
|
1644
1887
|
if (node?.right?.type === 'CallExpression') {
|
|
1645
1888
|
const rightNode = node?.right;
|
|
1646
|
-
const calleeName =
|
|
1647
|
-
const hasListEntries =
|
|
1889
|
+
const calleeName = (0, utils_1.generate)(rightNode.callee).code;
|
|
1890
|
+
const hasListEntries = ['ListEntries', 'nasl.util.ListEntries'].includes(calleeName);
|
|
1648
1891
|
const areaArguments = rightNode?.arguments;
|
|
1649
1892
|
eachNode = hasListEntries ? areaArguments?.[0] : rightNode;
|
|
1650
1893
|
startNode = hasListEntries ? areaArguments?.[1] : undefined;
|
|
@@ -1660,11 +1903,11 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1660
1903
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1661
1904
|
}),
|
|
1662
1905
|
end: endNode?.name === '__IDENTIFIER__' ? undefined : endNode ? transformNodeFunction(endNode, options) : undefined,
|
|
1663
|
-
item: itemNode ? transform2Param(itemNode) : new utils_1.naslTypes.Param({
|
|
1906
|
+
item: itemNode ? transform2Param(itemNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1664
1907
|
name: 'item',
|
|
1665
1908
|
typeAnnotation: undefined,
|
|
1666
1909
|
}),
|
|
1667
|
-
index: indexNode ? transform2Param(indexNode) : new utils_1.naslTypes.Param({
|
|
1910
|
+
index: indexNode ? transform2Param(indexNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1668
1911
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1669
1912
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1670
1913
|
}),
|
|
@@ -1684,8 +1927,8 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1684
1927
|
value: '0',
|
|
1685
1928
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1686
1929
|
}),
|
|
1687
|
-
item: transform2Param(arrowFunction.params[0]),
|
|
1688
|
-
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1930
|
+
item: transform2Param(arrowFunction.params[0], options) || undefined,
|
|
1931
|
+
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1689
1932
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1690
1933
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1691
1934
|
}),
|
|
@@ -1695,6 +1938,11 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1695
1938
|
}
|
|
1696
1939
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1697
1940
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1941
|
+
if (options?.isRestricted)
|
|
1942
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1943
|
+
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1944
|
+
return transformCall2ConsoleLog(node, calleeName, callee, options);
|
|
1945
|
+
}
|
|
1698
1946
|
return new utils_1.naslTypes.CallLogic({
|
|
1699
1947
|
calleeNamespace: 'nasl.ui',
|
|
1700
1948
|
calleeName: 'showMessage',
|
|
@@ -1706,6 +1954,8 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1706
1954
|
}
|
|
1707
1955
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1708
1956
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1957
|
+
if (options?.isRestricted)
|
|
1958
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1709
1959
|
return new utils_1.naslTypes.CallInterface({
|
|
1710
1960
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1711
1961
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1717,13 +1967,15 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1717
1967
|
}
|
|
1718
1968
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1719
1969
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1970
|
+
if (options?.isRestricted)
|
|
1971
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1720
1972
|
let calleeConnectionName = undefined;
|
|
1721
1973
|
let calleeNamespace = undefined;
|
|
1722
1974
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1723
1975
|
if (callee.length === 5) {
|
|
1724
1976
|
const connectArg = callee[2].arguments[0];
|
|
1725
1977
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1726
|
-
(0, utils_1.throwError)(
|
|
1978
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1727
1979
|
}
|
|
1728
1980
|
calleeConnectionName = connectArg.value;
|
|
1729
1981
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -1738,7 +1990,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1738
1990
|
calleeNamespace = calleeNamespacePrefix;
|
|
1739
1991
|
}
|
|
1740
1992
|
else {
|
|
1741
|
-
(0, utils_1.throwError)(`调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}
|
|
1993
|
+
return (0, utils_1.throwError)(options?.parsingId, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1742
1994
|
}
|
|
1743
1995
|
return new utils_1.naslTypes.CallConnector({
|
|
1744
1996
|
calleeConnectionName,
|
|
@@ -1751,6 +2003,8 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1751
2003
|
}
|
|
1752
2004
|
exports.transformCall2Connector = transformCall2Connector;
|
|
1753
2005
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
2006
|
+
if (options?.isRestricted)
|
|
2007
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1754
2008
|
return new utils_1.naslTypes.CallLogic({
|
|
1755
2009
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
1756
2010
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -1760,70 +2014,26 @@ function transformCall2Extension(node, calleeName, callee, options) {
|
|
|
1760
2014
|
});
|
|
1761
2015
|
}
|
|
1762
2016
|
exports.transformCall2Extension = transformCall2Extension;
|
|
1763
|
-
function transformArrowFunction2Match(node, calleeName, callee, options) {
|
|
1764
|
-
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1765
|
-
// NOTE: 适用于 if else
|
|
1766
|
-
const newCallee = node.callee.body.body;
|
|
1767
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__MatchExpressionFunction') {
|
|
1768
|
-
const match = new utils_1.naslTypes.Match({
|
|
1769
|
-
expression: fixExpression(newCallee[0], options),
|
|
1770
|
-
isExpression: options.transformType !== 'logic',
|
|
1771
|
-
cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new utils_1.naslTypes.MatchCase({
|
|
1772
|
-
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1773
|
-
body: transformBlockBody(_case.consequent.body.filter((item) => item.type !== 'BreakStatement'), options),
|
|
1774
|
-
})),
|
|
1775
|
-
});
|
|
1776
|
-
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1777
|
-
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1778
|
-
patterns: [],
|
|
1779
|
-
body: [],
|
|
1780
|
-
}));
|
|
1781
|
-
}
|
|
1782
|
-
match.cases.forEach((case_) => {
|
|
1783
|
-
if (case_.body.length && (case_.body[0].concept === 'BooleanLiteral' || case_.body[0].concept === 'StringLiteral')) {
|
|
1784
|
-
case_.isMatchedTypeEnumable = true;
|
|
1785
|
-
}
|
|
1786
|
-
if (case_.patterns.length && case_.patterns[0].concept === 'MemberExpression') {
|
|
1787
|
-
case_.isMatchedTypeEnumable = true;
|
|
1788
|
-
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1789
|
-
object: {
|
|
1790
|
-
concept: 'Identifier',
|
|
1791
|
-
name: case_.patterns[0].object.property.name,
|
|
1792
|
-
folded: false,
|
|
1793
|
-
namespace: 'app.enums'
|
|
1794
|
-
},
|
|
1795
|
-
property: {
|
|
1796
|
-
concept: 'Identifier',
|
|
1797
|
-
name: case_.patterns[0].property.value,
|
|
1798
|
-
folded: false,
|
|
1799
|
-
},
|
|
1800
|
-
});
|
|
1801
|
-
}
|
|
1802
|
-
});
|
|
1803
|
-
return match;
|
|
1804
|
-
}
|
|
1805
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__SwitchExpressionFuntion') {
|
|
1806
|
-
const switchStatement = transformNodeFunction(newCallee[0].body.body[0], options);
|
|
1807
|
-
return switchStatement;
|
|
1808
|
-
}
|
|
1809
|
-
(0, utils_1.throwError)(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
1810
|
-
}
|
|
1811
|
-
exports.transformArrowFunction2Match = transformArrowFunction2Match;
|
|
1812
2017
|
function transformTSAsExpression(node, options) {
|
|
1813
2018
|
if (node.expression.type === 'NumericLiteral') {
|
|
1814
|
-
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation) });
|
|
2019
|
+
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined });
|
|
1815
2020
|
}
|
|
1816
2021
|
else if (node.expression.type === 'ArrayExpression') {
|
|
1817
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation);
|
|
2022
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
1818
2023
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
1819
|
-
(0, utils_1.throwError)(`列表 as 必须为 List
|
|
2024
|
+
return (0, utils_1.throwError)(options?.parsingId, `列表 as 必须为 List 类型`, node);
|
|
1820
2025
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
1821
2026
|
}
|
|
2027
|
+
else if (node.expression.type === 'NullLiteral') {
|
|
2028
|
+
return transform2NullLiteral(node.expression, options);
|
|
2029
|
+
}
|
|
1822
2030
|
else {
|
|
1823
|
-
(0, utils_1.throwError)(
|
|
2031
|
+
return (0, utils_1.throwError)(options?.parsingId, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
1824
2032
|
}
|
|
1825
2033
|
}
|
|
1826
2034
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
2035
|
+
if (options?.isRestricted)
|
|
2036
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
1827
2037
|
return new utils_1.naslTypes.CallLogic({
|
|
1828
2038
|
calleeNamespace: '',
|
|
1829
2039
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -1834,11 +2044,13 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
1834
2044
|
}
|
|
1835
2045
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
1836
2046
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
2047
|
+
if (options?.isRestricted)
|
|
2048
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1837
2049
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
1838
2050
|
// 未带前缀,补一下
|
|
1839
2051
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
1840
2052
|
}
|
|
1841
|
-
else if (
|
|
2053
|
+
else if (server_1.default.getSqlFunction('mysql', calleeName) || calleeName === 'COUNTD') {
|
|
1842
2054
|
return transform2SqlFunction(node, calleeName, node?.arguments || [], options);
|
|
1843
2055
|
}
|
|
1844
2056
|
let newCalleeName = calleeName?.includes('__IDENTIFIER__') ? undefined : calleeName;
|
|
@@ -1858,6 +2070,8 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
1858
2070
|
}
|
|
1859
2071
|
exports.transformCall2Logic = transformCall2Logic;
|
|
1860
2072
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
2073
|
+
if (options?.isRestricted)
|
|
2074
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1861
2075
|
return new utils_1.naslTypes.CallLogic({
|
|
1862
2076
|
calleeNamespace: `nasl.auth`,
|
|
1863
2077
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1882,10 +2096,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1882
2096
|
const calleeName = node.callee.name;
|
|
1883
2097
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
1884
2098
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
1885
|
-
(0, utils_1.throwError)('FROM should have a ArrowFunctionExpression as the second argument');
|
|
2099
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
1886
2100
|
const arrowFunctionExpression = node.arguments[1];
|
|
1887
2101
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
1888
|
-
(0, utils_1.throwError)('FROM should have a CallExpression as the body of ArrowFunctionExpression');
|
|
2102
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
1889
2103
|
const body = arrowFunctionExpression.body;
|
|
1890
2104
|
const callExpressions = flatChainCallExpression(body);
|
|
1891
2105
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -1895,13 +2109,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1895
2109
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
1896
2110
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
1897
2111
|
`;
|
|
1898
|
-
(0, utils_1.throwError)(error);
|
|
2112
|
+
return (0, utils_1.throwError)(options?.parsingId, error, node);
|
|
1899
2113
|
}
|
|
1900
2114
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
1901
2115
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
1902
2116
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
1903
2117
|
if (errorOrder) {
|
|
1904
|
-
(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 的调用顺序。',
|
|
2118
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
1905
2119
|
}
|
|
1906
2120
|
const result = [{
|
|
1907
2121
|
calleeName: calleeName,
|
|
@@ -1913,7 +2127,7 @@ FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); /
|
|
|
1913
2127
|
result[0].arguments[2] = item.arguments[0];
|
|
1914
2128
|
}
|
|
1915
2129
|
else if (['INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(item.callee.name)) {
|
|
1916
|
-
result.push(...flatCallQueryComponentChainNode(item, options));
|
|
2130
|
+
result.push(...(flatCallQueryComponentChainNode(item, options) || []));
|
|
1917
2131
|
}
|
|
1918
2132
|
else {
|
|
1919
2133
|
result.push({
|
|
@@ -1946,33 +2160,39 @@ function flatOnExpressions(node) {
|
|
|
1946
2160
|
return [node];
|
|
1947
2161
|
}
|
|
1948
2162
|
}
|
|
1949
|
-
function transformMemberExpression2Entity(node, node2) {
|
|
2163
|
+
function transformMemberExpression2Entity(node, node2, options) {
|
|
1950
2164
|
const entityPath = flatMemberExpression(node);
|
|
1951
2165
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
1952
2166
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
1953
2167
|
if (!entityNamespace?.includes('.entities')) {
|
|
1954
|
-
(0, utils_1.throwError)(`${entityNamespace}.${entityName}
|
|
2168
|
+
return (0, utils_1.throwError)(options?.parsingId, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
1955
2169
|
}
|
|
1956
2170
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
1957
2171
|
if (asName) {
|
|
1958
|
-
(0, utils_1.throwError)(`FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2172
|
+
return (0, utils_1.throwError)(options?.parsingId, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
1959
2173
|
}
|
|
1960
2174
|
return { entityNamespace, entityName, asName };
|
|
1961
2175
|
}
|
|
1962
2176
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2177
|
+
if (options?.isInFrontend)
|
|
2178
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在前端使用', node);
|
|
2179
|
+
if (options?.isRestricted)
|
|
2180
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
1963
2181
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1964
2182
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
1965
2183
|
if (code?.includes('nasl.util')) {
|
|
1966
|
-
(0, utils_1.throwError)('数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理');
|
|
2184
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
1967
2185
|
}
|
|
1968
2186
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
1969
|
-
(0, utils_1.throwError)('缺少 SELECT 或 AGGR_SELECT 语句');
|
|
2187
|
+
return (0, utils_1.throwError)(options?.parsingId, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
1970
2188
|
}
|
|
1971
2189
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
1972
|
-
|
|
2190
|
+
if (!flatted)
|
|
2191
|
+
return;
|
|
2192
|
+
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
1973
2193
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
1974
2194
|
if (!isOrderCorrect) {
|
|
1975
|
-
(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 的调用顺序。',
|
|
2195
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
1976
2196
|
}
|
|
1977
2197
|
let from;
|
|
1978
2198
|
let where;
|
|
@@ -1985,11 +2205,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
1985
2205
|
let hasErrorTSScopeColumn = false;
|
|
1986
2206
|
let useResultItem = false;
|
|
1987
2207
|
// 这里只是一个示例,具体的逻辑需要根据flatted的内容来构建
|
|
1988
|
-
flatted.forEach((item) => {
|
|
2208
|
+
flatted && flatted.forEach((item) => {
|
|
1989
2209
|
// console.log(item.calleeName)
|
|
1990
2210
|
switch (item.calleeName) {
|
|
1991
2211
|
case 'FROM':
|
|
1992
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2212
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2213
|
+
if (!entity)
|
|
2214
|
+
return;
|
|
1993
2215
|
const entityName = entity.asName || entity.entityName;
|
|
1994
2216
|
entityAsNames.push(entityName);
|
|
1995
2217
|
from = new utils_1.naslTypes.QueryFromExpression({
|
|
@@ -2001,11 +2223,15 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2001
2223
|
case 'LEFT_JOIN':
|
|
2002
2224
|
case 'RIGHT_JOIN':
|
|
2003
2225
|
case 'OUTER_JOIN':
|
|
2004
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2226
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2227
|
+
if (!entity)
|
|
2228
|
+
break;
|
|
2005
2229
|
entityAsNames.push(entity.asName || entity.entityName);
|
|
2006
2230
|
const rawJoinType = item.calleeName.slice(0, -5);
|
|
2007
2231
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2008
2232
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2233
|
+
if (!from)
|
|
2234
|
+
return; // throwError(options?.parsingId, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2009
2235
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2010
2236
|
...entity,
|
|
2011
2237
|
joinType,
|
|
@@ -2022,27 +2248,50 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2022
2248
|
break;
|
|
2023
2249
|
case 'AGGR_SELECT':
|
|
2024
2250
|
if (groupBy?.length) {
|
|
2025
|
-
(0, utils_1.throwError)('存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2251
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2026
2252
|
}
|
|
2027
2253
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2028
2254
|
distinct: false,
|
|
2029
2255
|
star: true,
|
|
2030
2256
|
selectElements: [new utils_1.naslTypes.QueryFieldExpression({
|
|
2031
2257
|
isDotStar: true,
|
|
2032
|
-
entityAsName: from
|
|
2258
|
+
entityAsName: from?.entityName,
|
|
2033
2259
|
propertyName: '',
|
|
2034
2260
|
})],
|
|
2035
2261
|
});
|
|
2036
|
-
item.arguments[0].
|
|
2037
|
-
|
|
2038
|
-
|
|
2262
|
+
if (item.arguments[0].type === 'ObjectExpression') {
|
|
2263
|
+
item.arguments[0].properties?.forEach((arg) => {
|
|
2264
|
+
if (arg?.value.type === 'CallExpression') {
|
|
2265
|
+
let selectElements = transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2266
|
+
if (selectElements) {
|
|
2267
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2268
|
+
select.setSelectElements(newSelectElements);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
else {
|
|
2272
|
+
return (0, utils_1.throwError)(options?.parsingId, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2273
|
+
}
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
else if (item.arguments[0].type === 'CallExpression') { // 只有一个的简写:AGGR_SELECT(SUM(Entity1.age))
|
|
2277
|
+
const selectElements = transform2QueryAggregateExpression({
|
|
2278
|
+
type: 'ObjectProperty',
|
|
2279
|
+
key: {
|
|
2280
|
+
type: 'Identifier',
|
|
2281
|
+
name: 'resultItem',
|
|
2282
|
+
},
|
|
2283
|
+
value: item.arguments[0],
|
|
2284
|
+
computed: false,
|
|
2285
|
+
shorthand: false,
|
|
2286
|
+
}, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2287
|
+
if (selectElements) {
|
|
2039
2288
|
const newSelectElements = [...select.selectElements, selectElements];
|
|
2040
2289
|
select.setSelectElements(newSelectElements);
|
|
2041
2290
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
}
|
|
2291
|
+
}
|
|
2292
|
+
else {
|
|
2293
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2294
|
+
}
|
|
2046
2295
|
break;
|
|
2047
2296
|
case 'SELECT':
|
|
2048
2297
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
@@ -2050,7 +2299,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2050
2299
|
star: true,
|
|
2051
2300
|
selectElements: groupBy?.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2052
2301
|
isDotStar: true,
|
|
2053
|
-
entityAsName: from
|
|
2302
|
+
entityAsName: from?.entityName,
|
|
2054
2303
|
propertyName: '',
|
|
2055
2304
|
})] : [],
|
|
2056
2305
|
});
|
|
@@ -2061,17 +2310,17 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2061
2310
|
}
|
|
2062
2311
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2063
2312
|
if (groupBy?.length) {
|
|
2064
|
-
(0, utils_1.throwError)('存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2313
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2065
2314
|
}
|
|
2066
2315
|
const originName = arg.key?.name || '';
|
|
2067
2316
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2068
2317
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2069
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}
|
|
2318
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2070
2319
|
}
|
|
2071
2320
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2072
2321
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2073
2322
|
if (!entityAsNames.includes(entityName)) {
|
|
2074
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}
|
|
2323
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2075
2324
|
}
|
|
2076
2325
|
selectElements = arg.value.properties?.map((property) => {
|
|
2077
2326
|
const columnAsName = property.key?.name;
|
|
@@ -2079,7 +2328,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2079
2328
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2080
2329
|
if (columnAsName !== columnPropertyName) {
|
|
2081
2330
|
// eg: comment: Topic_Comment.comment_stu
|
|
2082
|
-
(0, utils_1.throwError)(`SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}
|
|
2331
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2083
2332
|
}
|
|
2084
2333
|
selectElement.isDotStar = false;
|
|
2085
2334
|
return selectElement;
|
|
@@ -2089,6 +2338,9 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2089
2338
|
if (arg.value.type === 'MemberExpression') {
|
|
2090
2339
|
hasErrorTSScopeColumn = true;
|
|
2091
2340
|
}
|
|
2341
|
+
if (arg.type === 'ObjectProperty' && select?.selectElements?.find(item => item?.concept === 'QueryFieldExpression' && item.entityAsName === arg.value?.name)) {
|
|
2342
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 禁止在一次查询中对同一实体设置多个别名,请修改`, node);
|
|
2343
|
+
}
|
|
2092
2344
|
selectElements = [transform2SelectQueryFieldExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName })];
|
|
2093
2345
|
}
|
|
2094
2346
|
const selectElement = selectElements?.[0];
|
|
@@ -2114,7 +2366,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2114
2366
|
}
|
|
2115
2367
|
}
|
|
2116
2368
|
else {
|
|
2117
|
-
(0, utils_1.throwError)('HAVING 不符合规范,请使用箭头函数');
|
|
2369
|
+
return (0, utils_1.throwError)(options?.parsingId, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2118
2370
|
}
|
|
2119
2371
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2120
2372
|
break;
|
|
@@ -2123,13 +2375,16 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2123
2375
|
let restOptionParams = { entityAsNames };
|
|
2124
2376
|
if (orderNode?.length === 1 && orderNode?.[0]?.type === 'ArrowFunctionExpression') {
|
|
2125
2377
|
const params = orderNode?.[0]?.params;
|
|
2378
|
+
if (orderNode?.[0]?.body?.type !== 'ArrayExpression') {
|
|
2379
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数,并返回数组', orderNode, node);
|
|
2380
|
+
}
|
|
2126
2381
|
orderNode = orderNode?.[0]?.body?.elements;
|
|
2127
2382
|
if (params?.length && params?.[0]?.name) {
|
|
2128
2383
|
restOptionParams = { inOqlIdentifierNamespace: params?.[0]?.name, entityAsNames };
|
|
2129
2384
|
}
|
|
2130
2385
|
}
|
|
2131
2386
|
else {
|
|
2132
|
-
(0, utils_1.throwError)('ORDER_BY
|
|
2387
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数,并返回数组', orderNode, node);
|
|
2133
2388
|
}
|
|
2134
2389
|
orderBy = orderNode.map((arg) => {
|
|
2135
2390
|
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
@@ -2155,24 +2410,26 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2155
2410
|
ideVersion: '2.22',
|
|
2156
2411
|
});
|
|
2157
2412
|
if (hasErrorTSScopeColumn && !groupBy?.length && !having) {
|
|
2158
|
-
(0, utils_1.throwError)('SELECT 局部列不符合规范,需要按两层对象返回');
|
|
2413
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2159
2414
|
}
|
|
2160
2415
|
const hasScopeColumn = select?.selectElements?.find((selectElement) => selectElement?.concept === 'QueryFieldExpression' && !selectElement?.isDotStar);
|
|
2161
2416
|
if (hasScopeColumn && (groupBy?.length || having)) {
|
|
2162
|
-
(0, utils_1.throwError)('分组聚合与表字段局部列不允许同时出现');
|
|
2417
|
+
return (0, utils_1.throwError)(options?.parsingId, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2163
2418
|
}
|
|
2164
2419
|
if (hasScopeColumn && useResultItem) {
|
|
2165
|
-
(0, utils_1.throwError)("对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])");
|
|
2420
|
+
return (0, utils_1.throwError)(options?.parsingId, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])", node);
|
|
2166
2421
|
}
|
|
2167
2422
|
const isOnlyAggr = select?.selectElements?.find((selectElement) => selectElement?.concept !== 'QueryAggregateExpression');
|
|
2168
2423
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2169
2424
|
if (!isOnlyAggr && !calleeNames?.includes('AGGR_SELECT')) {
|
|
2170
|
-
(0, utils_1.throwError)('SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2425
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2171
2426
|
}
|
|
2172
2427
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2173
2428
|
return callQueryComponent;
|
|
2174
2429
|
}
|
|
2175
2430
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2431
|
+
if (options?.isRestricted)
|
|
2432
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2176
2433
|
const args = node.arguments;
|
|
2177
2434
|
const dataArg = args?.[0];
|
|
2178
2435
|
const procDefKeyArg = args?.[1];
|
|
@@ -2210,7 +2467,9 @@ function transform2LogicItem(node, options) {
|
|
|
2210
2467
|
transformManager.register('Directive', transform2DirectiveLiteral);
|
|
2211
2468
|
transformManager.register('NumericLiteral', transform2NumericLiteral);
|
|
2212
2469
|
transformManager.register('NullLiteral', transform2NullLiteral);
|
|
2470
|
+
transformManager.register('RegExpLiteral', transform2NewRegex);
|
|
2213
2471
|
transformManager.register('TemplateLiteral', transform2StringInterpolation);
|
|
2472
|
+
transformManager.register((node) => node.type === 'LogicalExpression' && node.operator === '??', transformDefaultExpression);
|
|
2214
2473
|
transformManager.register('BinaryExpression', transform2BinaryExpression);
|
|
2215
2474
|
transformManager.register('LogicalExpression', transform2BinaryExpression);
|
|
2216
2475
|
transformManager.register('UpdateExpression', transformUpdateExpression2Assignment);
|
|
@@ -2248,7 +2507,8 @@ function transform2LogicItem(node, options) {
|
|
|
2248
2507
|
}
|
|
2249
2508
|
});
|
|
2250
2509
|
transformManager.register('MemberExpression', transformMemberExpression);
|
|
2251
|
-
transformManager.register(
|
|
2510
|
+
transformManager.register('OptionalMemberExpression', transformMemberExpression);
|
|
2511
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && (node.callee.type === 'FunctionExpression' && node.callee.id?.name === 'match' || node.callee.type === 'ArrowFunctionExpression'), transformCallFunctionExpression2Match);
|
|
2252
2512
|
transformManager.registerCallExpression((node, calleeName) => /^\$refs\./.test(calleeName), transformCall2CallViewElementLogic);
|
|
2253
2513
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity'), transformCall2CallEntityLogic);
|
|
2254
2514
|
transformManager.registerCallExpression('nasl.oql.query', transformCall2OQLQuery);
|
|
@@ -2257,10 +2517,12 @@ function transform2LogicItem(node, options) {
|
|
|
2257
2517
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.logging.'), transformCall2Logging);
|
|
2258
2518
|
transformManager.registerCallExpression('nasl.util.jsonSerialize', transformCall2JSONFunctions);
|
|
2259
2519
|
transformManager.registerCallExpression('nasl.util.jsonDeserialize', transformCall2JSONFunctions);
|
|
2520
|
+
transformManager.registerCallExpression((node, calleeName) => (calleeName.startsWith('nasl.event.') || calleeName.startsWith('event.')) && (calleeName.endsWith('.preventDefault') || calleeName.endsWith('.stopPropagation')), transform2CallEventLogic);
|
|
2260
2521
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.forEach'), transformForEach2ForEachStatement);
|
|
2261
2522
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.util.'), transformCall2CallFunction);
|
|
2262
2523
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.auth.'), transformCall2LogicWithAuth);
|
|
2263
2524
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.ui.'), transform2UIFunction);
|
|
2525
|
+
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.browser.'), transform2CallOtherNASLLogic);
|
|
2264
2526
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.map'), transformMap2ListTransform);
|
|
2265
2527
|
transformManager.registerCallExpression('ForEach', transform2ForEachStatement);
|
|
2266
2528
|
transformManager.registerCallExpression('alert', transformAlert2ShowMessage);
|
|
@@ -2270,15 +2532,14 @@ function transform2LogicItem(node, options) {
|
|
|
2270
2532
|
transformManager.registerCallExpression('extensions.lcap_process_framework.logics.launchProcess', transformCall2LaunchProcess);
|
|
2271
2533
|
transformManager.registerCallExpression((node, calleeName) => /extensions\./.test(calleeName), transformCall2Extension);
|
|
2272
2534
|
transformManager.registerCallExpression((node, calleeName) => /connectors\./.test(calleeName), transformCall2Connector);
|
|
2273
|
-
transformManager.registerCallExpression((node) => node.callee.type === 'ArrowFunctionExpression', transformArrowFunction2Match);
|
|
2274
2535
|
transformManager.registerCallExpression((node, calleeName) => ['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'].includes(calleeName), transformCallExpressionToBinaryExpression);
|
|
2275
2536
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && calleeName.startsWith('viewLogic_'), transformCall2CallViewLogic);
|
|
2276
2537
|
transformManager.registerCallExpression('PAGINATE', transformCall2Paginate);
|
|
2277
2538
|
transformManager.registerCallExpression('FROM', transformCall2DataQuery);
|
|
2278
|
-
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1, transformCall2Logic);
|
|
2539
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2279
2540
|
let result = transformManager.apply(node, options);
|
|
2280
2541
|
delete options.typeAnnotation;
|
|
2281
|
-
return result;
|
|
2542
|
+
return result || undefined;
|
|
2282
2543
|
}
|
|
2283
2544
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2284
2545
|
//# sourceMappingURL=transform2LogicItem.js.map
|