@lcap/nasl 4.1.0-beta.9 → 4.1.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 +21 -96
- 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/permission.d.ts.map +1 -1
- package/out/generator/permission.js +70 -34
- package/out/generator/permission.js.map +1 -1
- package/out/generator/release-body/body.d.ts.map +1 -1
- package/out/generator/release-body/body.js +3 -4
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/utils.d.ts +7 -3
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +7 -5
- 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 +200 -50
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +14 -0
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -0
- package/out/natural/parseNaturalTSXView.js +565 -0
- package/out/natural/parseNaturalTSXView.js.map +1 -0
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +15 -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 +7 -5
- 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 +3 -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 +39 -7
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +59 -29
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +377 -195
- 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 +10 -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/sqlCategory.json +410 -0
- package/out/server/OQL/sqlFunctions.json +695 -7
- package/out/server/client/nasl-server-client.d.ts +7 -0
- package/out/server/client/nasl-server-client.d.ts.map +1 -0
- package/out/server/client/nasl-server-client.js +9 -0
- package/out/server/client/nasl-server-client.js.map +1 -0
- package/out/server/extendBaseNode.d.ts.map +1 -1
- package/out/server/extendBaseNode.js +18 -9
- 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 +10 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +119 -62
- package/out/server/naslServer.js.map +1 -1
- package/out/service/initial/form-designer.d.ts +1 -1
- package/out/service/initial/form-designer.d.ts.map +1 -1
- package/out/service/initial/form-designer.js +4 -1
- package/out/service/initial/form-designer.js.map +1 -1
- package/out/service/initial/processV2.d.ts +1 -1
- package/out/service/initial/processV2.d.ts.map +1 -1
- package/out/service/initial/processV2.js +4 -1
- package/out/service/initial/processV2.js.map +1 -1
- package/out/service/initial/types.d.ts +1 -0
- package/out/service/initial/types.d.ts.map +1 -1
- package/out/service/storage/api.d.ts +16 -7
- package/out/service/storage/api.js +6 -0
- package/out/service/storage/api.js.map +1 -1
- package/out/service/storage/cache/index.d.ts +3 -15
- package/out/service/storage/cache/index.d.ts.map +1 -1
- package/out/service/storage/cache/index.js +14 -299
- package/out/service/storage/cache/index.js.map +1 -1
- package/out/service/storage/cache/split.d.ts +0 -21
- package/out/service/storage/cache/split.d.ts.map +1 -1
- package/out/service/storage/cache/split.js +24 -33
- package/out/service/storage/cache/split.js.map +1 -1
- package/out/service/storage/init.d.ts +9 -0
- package/out/service/storage/init.d.ts.map +1 -1
- package/out/service/storage/init.js +61 -90
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/service.js +1 -1
- package/out/service/storage/service.js.map +1 -1
- package/package.json +15 -13
- 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.transformCall2Extension = exports.transformCall2Connector = exports.transformCall2Interface = exports.transformAlert2ShowMessage = exports.transformForEach2ForEachStatement = exports.transformForOf2ForEachStatement = exports.transform2ForEachStatement = exports.transformMap2ListTransform = exports.transform2UIFunction = exports.transformCall2CallFunction = exports.transform2CallFunction = exports.transformCall2JSONFunctions = exports.transformCall2Logging = exports.transformCall2ConsoleLog = exports.transformCall2CallDataSourceLogic = exports.transformCall2CallEntityLogic = exports.transformCall2CallViewElementLogic = exports.
|
|
7
|
-
exports.transform2LogicItem = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic =
|
|
6
|
+
exports.transformCall2Extension = exports.transformCall2Connector = exports.transformCall2Interface = exports.transformAlert2ShowMessage = exports.transformForEach2ForEachStatement = exports.transformForOf2ForEachStatement = exports.transform2ForEachStatement = exports.transformMap2ListTransform = exports.transform2UIFunction = exports.transformCall2CallFunction = exports.transform2CallFunction = exports.transformCall2JSONFunctions = exports.transformCall2Logging = exports.transformCall2ConsoleLog = exports.transformCall2CallDataSourceLogic = exports.transformCall2CallEntityLogic = exports.transformCall2CallViewElementLogic = exports.transformCallFunctionExpression2Match = exports.transformMemberExpression = exports.transformNewExpression = exports.transform2PartialNewComposite = exports.transform2Comment = exports.transform2StringInterpolation = exports.transformReturnStatement2AssignmentOrEnd = exports.transform2NullLiteral = exports.transform2NumericLiteral = exports.transform2DirectiveLiteral = exports.transform2StringLiteral = exports.transform2BooleanLiteral = exports.transformUpdateExpression2Assignment = exports.transform2Assignment = exports.transform2AnonymousFunction = exports.transformIdentifier = exports.transformSwitchStatement2Match = exports.transform2WhileStatement = exports.transform2Break = exports.transform2Continue = exports.transform2IfStatement = exports.transform2BinaryExpression = exports.transform2VariadicExpression = exports.transformCallExpressionToBinaryExpression = exports.transform2Param = exports.fixLogicNode = exports.flatIfStatementForMatch = exports.flatMatchPatternsExpression = exports.getSelectMembers = exports.unflatMemberExpression = exports.flatMemberExpression = exports.fixExpression = exports.TransformManager = void 0;
|
|
7
|
+
exports.transform2LogicItem = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = 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)(`Unhandled node ${callee.map((item) => item.name).join('.')}
|
|
50
|
+
return (0, utils_1.throwError)(options?.parsingId, `Unhandled node ${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, 'Unhandled node', node.type, node);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
}
|
|
@@ -78,7 +77,7 @@ 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);
|
|
82
81
|
param && logic.addParam(param);
|
|
83
82
|
});
|
|
84
83
|
const newStatements = [];
|
|
@@ -122,9 +121,9 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
122
121
|
}
|
|
123
122
|
return logic;
|
|
124
123
|
}
|
|
125
|
-
function assertAssignmentRightIsNotAnonymousFunction(expression) {
|
|
124
|
+
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
126
125
|
if (expression?.concept === 'AnonymousFunction')
|
|
127
|
-
(0, utils_1.throwError)('Anonymous function is not allowed in assignment');
|
|
126
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function is not allowed in assignment', expression.toNaturalTS());
|
|
128
127
|
return expression;
|
|
129
128
|
}
|
|
130
129
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -232,16 +231,29 @@ function flatMatchPatternsExpression(node) {
|
|
|
232
231
|
}
|
|
233
232
|
return [node];
|
|
234
233
|
}
|
|
234
|
+
else if (node.concept === 'VariadicExpression') {
|
|
235
|
+
if (node.operator === '||') {
|
|
236
|
+
return node.expressions
|
|
237
|
+
?.filter((item) => item?.concept === 'BinaryExpression' && item?.right?.concept === 'StringLiteral')
|
|
238
|
+
?.map((item) => new utils_1.naslTypes.StringLiteral({ value: item?.right?.value })) || [node];
|
|
239
|
+
}
|
|
240
|
+
return [node];
|
|
241
|
+
}
|
|
235
242
|
return [node];
|
|
236
243
|
}
|
|
237
244
|
exports.flatMatchPatternsExpression = flatMatchPatternsExpression;
|
|
238
|
-
function
|
|
245
|
+
function flatIfStatementForMatch(node) {
|
|
239
246
|
if (node.alternate.type === 'IfStatement') {
|
|
240
|
-
return [...
|
|
247
|
+
return [node, ...flatIfStatementForMatch(node.alternate)];
|
|
241
248
|
}
|
|
242
|
-
return [node
|
|
249
|
+
return [node, {
|
|
250
|
+
type: 'IfStatement',
|
|
251
|
+
test: null,
|
|
252
|
+
consequent: node.alternate,
|
|
253
|
+
alternate: node.alternate,
|
|
254
|
+
}];
|
|
243
255
|
}
|
|
244
|
-
exports.
|
|
256
|
+
exports.flatIfStatementForMatch = flatIfStatementForMatch;
|
|
245
257
|
/**
|
|
246
258
|
* 这个函数是修复 AI 翻译出错的情况,与正常的 transform 做个区分
|
|
247
259
|
* @param node
|
|
@@ -257,7 +269,7 @@ function fixLogicNode(node) {
|
|
|
257
269
|
}
|
|
258
270
|
}
|
|
259
271
|
exports.fixLogicNode = fixLogicNode;
|
|
260
|
-
function transform2Param(node) {
|
|
272
|
+
function transform2Param(node, options) {
|
|
261
273
|
const exclude = ['event'];
|
|
262
274
|
if (node.type === 'ObjectProperty') {
|
|
263
275
|
const typeAnnotation = node?.value?.name ? utils_1.naslTypes.TypeAnnotation.createPrimitive((node?.value).name) : null;
|
|
@@ -269,7 +281,7 @@ function transform2Param(node) {
|
|
|
269
281
|
name,
|
|
270
282
|
typeAnnotation,
|
|
271
283
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
272
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
284
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
273
285
|
}),
|
|
274
286
|
});
|
|
275
287
|
}
|
|
@@ -281,9 +293,9 @@ function transform2Param(node) {
|
|
|
281
293
|
let defaultValueExpression = node.optional ? { type: 'NullLiteral' } : undefined;
|
|
282
294
|
return new utils_1.naslTypes.Param({
|
|
283
295
|
name,
|
|
284
|
-
typeAnnotation: typeAnnotation
|
|
296
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
285
297
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
286
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
298
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
287
299
|
}),
|
|
288
300
|
});
|
|
289
301
|
}
|
|
@@ -296,9 +308,9 @@ function transform2Param(node) {
|
|
|
296
308
|
return new utils_1.naslTypes.Param({
|
|
297
309
|
name,
|
|
298
310
|
required: !node.optional,
|
|
299
|
-
typeAnnotation: typeAnnotation
|
|
311
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
300
312
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
301
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
313
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
302
314
|
}),
|
|
303
315
|
});
|
|
304
316
|
}
|
|
@@ -319,14 +331,14 @@ function transform2Param(node) {
|
|
|
319
331
|
return null;
|
|
320
332
|
return new utils_1.naslTypes.Param({
|
|
321
333
|
name,
|
|
322
|
-
typeAnnotation: typeAnnotation
|
|
334
|
+
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
323
335
|
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
324
|
-
expression: transform2LogicItem(defaultValueExpression, { transformType: 'attr' }),
|
|
336
|
+
expression: transform2LogicItem(defaultValueExpression, { parsingId: options?.parsingId, transformType: 'attr', isRestricted: true }),
|
|
325
337
|
}),
|
|
326
338
|
});
|
|
327
339
|
}
|
|
328
340
|
else {
|
|
329
|
-
(0, utils_1.throwError)(
|
|
341
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unhandled node', node);
|
|
330
342
|
}
|
|
331
343
|
}
|
|
332
344
|
exports.transform2Param = transform2Param;
|
|
@@ -345,6 +357,12 @@ function transformCallExpressionToBinaryExpression(node, calleeName, callee, opt
|
|
|
345
357
|
IN: 'in',
|
|
346
358
|
IS_NULL: 'isNull',
|
|
347
359
|
};
|
|
360
|
+
if (calleeName === 'IS_NULL') {
|
|
361
|
+
return new utils_1.naslTypes.UnaryExpression({
|
|
362
|
+
operator: 'isNull',
|
|
363
|
+
argument: transformNodeFunction(argument?.[0], options),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
348
366
|
return new utils_1.naslTypes.BinaryExpression({
|
|
349
367
|
operator: map[calleeName],
|
|
350
368
|
left: transformNodeFunction(argument?.[0], options),
|
|
@@ -424,11 +442,21 @@ function transform2BinaryExpression(node, options) {
|
|
|
424
442
|
right: transformNodeFunction(node.right, options),
|
|
425
443
|
});
|
|
426
444
|
}
|
|
427
|
-
(0, utils_1.throwError)(
|
|
445
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unhandled node', node.type, node);
|
|
428
446
|
}
|
|
429
447
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
448
|
+
function transformDefaultExpression(node, options) {
|
|
449
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
450
|
+
return transformNodeFunction(node.left, options);
|
|
451
|
+
}
|
|
430
452
|
function transformConditionalExpression(node, options) {
|
|
431
453
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
454
|
+
if (options?.inCallQueryComponentField) {
|
|
455
|
+
const expr = (0, utils_1.generate)(node.test)?.code;
|
|
456
|
+
const then_expr = (0, utils_1.generate)(node.consequent)?.code;
|
|
457
|
+
const else_expr = (0, utils_1.generate)(node.alternate)?.code;
|
|
458
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
459
|
+
}
|
|
432
460
|
const test = transformNodeFunction(node.test, options);
|
|
433
461
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
434
462
|
const alternate = transformNodeFunction(node.alternate, options);
|
|
@@ -451,12 +479,12 @@ function transformConditionalExpression(node, options) {
|
|
|
451
479
|
cases: [
|
|
452
480
|
new utils_1.naslTypes.MatchCase({
|
|
453
481
|
patterns: [new utils_1.naslTypes.BooleanLiteral({ value: 'true' })],
|
|
454
|
-
body: [consequent],
|
|
482
|
+
body: consequent ? [consequent] : [],
|
|
455
483
|
isMatchedTypeEnumable: true,
|
|
456
484
|
}),
|
|
457
485
|
new utils_1.naslTypes.MatchCase({
|
|
458
|
-
patterns: [
|
|
459
|
-
body: [alternate],
|
|
486
|
+
patterns: [],
|
|
487
|
+
body: alternate ? [alternate] : [],
|
|
460
488
|
}),
|
|
461
489
|
],
|
|
462
490
|
});
|
|
@@ -467,17 +495,34 @@ function transformArrayExpression(node, options) {
|
|
|
467
495
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
468
496
|
return new utils_1.naslTypes.NewList({
|
|
469
497
|
typeAnnotation,
|
|
470
|
-
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })),
|
|
498
|
+
items: node?.elements?.map((arg) => transformNodeFunction(arg, { ...options, typeAnnotation: undefined })).filter(Boolean),
|
|
471
499
|
});
|
|
472
500
|
}
|
|
473
501
|
function transform2NewAnonymousStructure(node, options) {
|
|
502
|
+
for (let i = 0; i < node.properties.length; i++) {
|
|
503
|
+
const item = node.properties[i];
|
|
504
|
+
const itemValue = item?.value;
|
|
505
|
+
if (itemValue.type === 'NullLiteral') {
|
|
506
|
+
const currentType = options?.typeAnnotation?.properties?.[i];
|
|
507
|
+
if (currentType?.typeAnnotation) {
|
|
508
|
+
item.naslType = currentType.typeAnnotation;
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Do not allow NullLiteral without type, you can use as to carry the type', node);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
else if (itemValue.type === 'TSAsExpression') {
|
|
515
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(itemValue.typeAnnotation, options);
|
|
516
|
+
item.naslType = typeAnnotation;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
474
519
|
const newComposite = transform2PartialNewComposite(node, options);
|
|
475
520
|
const newProperties = node.properties.filter((prop) => prop.type === 'ObjectProperty' && prop.value.type !== 'ConditionalExpression');
|
|
476
521
|
const structureProperties = [];
|
|
477
522
|
newProperties.forEach((arg, index) => {
|
|
478
523
|
structureProperties.push(new utils_1.naslTypes.StructureProperty({
|
|
479
524
|
name: arg.key.name,
|
|
480
|
-
typeAnnotation: null
|
|
525
|
+
typeAnnotation: arg.naslType || null,
|
|
481
526
|
}));
|
|
482
527
|
});
|
|
483
528
|
newComposite.typeAnnotation = utils_1.naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties);
|
|
@@ -500,15 +545,15 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
500
545
|
}
|
|
501
546
|
else {
|
|
502
547
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('List', {
|
|
503
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
548
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
504
549
|
});
|
|
505
550
|
}
|
|
506
551
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
507
|
-
(0, utils_1.throwError)(
|
|
552
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Not allowed code in NewList', node);
|
|
508
553
|
}
|
|
509
554
|
return new utils_1.naslTypes.NewList({
|
|
510
555
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
511
|
-
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)),
|
|
556
|
+
items: node?.arguments?.[0]?.elements?.map((arg) => transformNodeFunction(arg, options)).filter(Boolean),
|
|
512
557
|
});
|
|
513
558
|
}
|
|
514
559
|
if (calleeName === 'NewMap') {
|
|
@@ -524,7 +569,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
524
569
|
}
|
|
525
570
|
else {
|
|
526
571
|
typeAnnotation = utils_1.naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
527
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
572
|
+
typeArguments: node?.typeParameters?.params.map((type) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(type, options)).filter(Boolean),
|
|
528
573
|
});
|
|
529
574
|
}
|
|
530
575
|
return new utils_1.naslTypes.NewMap({
|
|
@@ -537,13 +582,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
537
582
|
const typeParam = node.typeParameters?.params[0];
|
|
538
583
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
539
584
|
if (!typeNamespaceAndName)
|
|
540
|
-
(0, utils_1.throwError)(
|
|
585
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Not allowed empty namespace in NewEntity', node);
|
|
541
586
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
542
587
|
}
|
|
543
588
|
if (calleeName === 'NewAnonymousStructure') {
|
|
544
589
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
545
590
|
}
|
|
546
|
-
(0, utils_1.throwError)(
|
|
591
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unhandled ArrowFunctionExpression node', node.type, node);
|
|
547
592
|
}
|
|
548
593
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
549
594
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -608,7 +653,7 @@ function transform2ArrayPattern(decl, options) {
|
|
|
608
653
|
if (options.transformType === 'logic') {
|
|
609
654
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
610
655
|
name: element.name,
|
|
611
|
-
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation),
|
|
656
|
+
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined,
|
|
612
657
|
}));
|
|
613
658
|
}
|
|
614
659
|
}
|
|
@@ -640,7 +685,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
640
685
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
641
686
|
const declList = node?.declarations || [];
|
|
642
687
|
let newNode;
|
|
643
|
-
declList
|
|
688
|
+
declList.forEach((decl) => {
|
|
644
689
|
const variableName = decl.id.name;
|
|
645
690
|
const isArrayPattern = decl.id?.type === 'ArrayPattern';
|
|
646
691
|
if (isArrayPattern && decl.init) {
|
|
@@ -651,7 +696,7 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
651
696
|
let typeAnnotation;
|
|
652
697
|
if (options.transformType === 'logic' && ![...options.logic.variables, ...options.logic.returns].some((variable) => variable.name === variableName)) {
|
|
653
698
|
const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
|
|
654
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
699
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
655
700
|
options.logic.variables.push(new utils_1.naslTypes.Variable({
|
|
656
701
|
name: variableName,
|
|
657
702
|
typeAnnotation,
|
|
@@ -660,14 +705,14 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
660
705
|
if (decl.init) {
|
|
661
706
|
const calleeName = (0, utils_1.generate)(decl?.init?.callee).code;
|
|
662
707
|
const varTypeAnnotation = decl?.id?.typeAnnotation?.typeAnnotation;
|
|
663
|
-
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation);
|
|
708
|
+
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
664
709
|
if (calleeName === 'nasl.oql.query' && varTypeAnnotation) {
|
|
665
710
|
decl.init.typeAnnotations = varTypeAnnotation;
|
|
666
711
|
}
|
|
667
712
|
options.typeAnnotation = typeAnnotation;
|
|
668
713
|
newNode = new utils_1.naslTypes.Assignment({
|
|
669
714
|
left: transformNodeFunction(decl.id, options),
|
|
670
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation })),
|
|
715
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation }), options) || undefined,
|
|
671
716
|
});
|
|
672
717
|
}
|
|
673
718
|
});
|
|
@@ -777,6 +822,16 @@ function transformIdentifier(node, options) {
|
|
|
777
822
|
if (placeholderMap.includes(node.name)) {
|
|
778
823
|
return new utils_1.naslTypes.Identifier({});
|
|
779
824
|
}
|
|
825
|
+
if (node.name === '$self') {
|
|
826
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
827
|
+
object: new utils_1.naslTypes.Identifier({
|
|
828
|
+
name: 'elements',
|
|
829
|
+
}),
|
|
830
|
+
property: new utils_1.naslTypes.Identifier({
|
|
831
|
+
name: '$ce',
|
|
832
|
+
}),
|
|
833
|
+
});
|
|
834
|
+
}
|
|
780
835
|
return new utils_1.naslTypes.Identifier({
|
|
781
836
|
name: node.name,
|
|
782
837
|
});
|
|
@@ -805,7 +860,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
805
860
|
// @TODO
|
|
806
861
|
}
|
|
807
862
|
else {
|
|
808
|
-
(0, utils_1.throwError)(
|
|
863
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unsupported expression type for QueryFieldExpression', expression.type, expression);
|
|
809
864
|
}
|
|
810
865
|
}
|
|
811
866
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -814,10 +869,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
814
869
|
const arg = callExpression.arguments[0];
|
|
815
870
|
if (arg.type !== 'MemberExpression') {
|
|
816
871
|
const code = (0, utils_1.generate)(arg).code;
|
|
817
|
-
(0, utils_1.throwError)(`聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
872
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数的输入只能是表字段(实体.属性),但AVG(${code})中的${code}不是表字段`);
|
|
818
873
|
}
|
|
819
874
|
if (callExpression.arguments?.length > 1) {
|
|
820
|
-
(0, utils_1.throwError)(`聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
875
|
+
return (0, utils_1.throwError)(options?.parsingId, `聚合函数${callExpression.callee.name}只支持一个参数`);
|
|
821
876
|
}
|
|
822
877
|
return new utils_1.naslTypes.QueryAggregateExpression({
|
|
823
878
|
asName: asNameNode.name,
|
|
@@ -827,10 +882,10 @@ function transform2QueryAggregateExpression(node, options) {
|
|
|
827
882
|
}
|
|
828
883
|
function transform2AnonymousFunction(node, options) {
|
|
829
884
|
if (node.body.type === 'BlockStatement')
|
|
830
|
-
(0, utils_1.throwError)('Anonymous function with block statement is not supported');
|
|
885
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function with block statement is not supported', node);
|
|
831
886
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
832
887
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
833
|
-
params: node.params.map((param) => transform2Param(param)),
|
|
888
|
+
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
834
889
|
body: transformNodeFunction(node.body, options),
|
|
835
890
|
});
|
|
836
891
|
}
|
|
@@ -859,7 +914,7 @@ function transform2Assignment(node, options) {
|
|
|
859
914
|
}
|
|
860
915
|
return new utils_1.naslTypes.Assignment({
|
|
861
916
|
left: transformNodeFunction(node.left, options),
|
|
862
|
-
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options)),
|
|
917
|
+
right: assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options), options) || undefined,
|
|
863
918
|
});
|
|
864
919
|
}
|
|
865
920
|
exports.transform2Assignment = transform2Assignment;
|
|
@@ -936,15 +991,15 @@ function transformReturnStatement2AssignmentOrEnd(node, options) {
|
|
|
936
991
|
}
|
|
937
992
|
}
|
|
938
993
|
if (!logic.returns.length) {
|
|
939
|
-
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation) : undefined;
|
|
994
|
+
const typeAnnotation = node?.argument?.type === 'TSAsExpression' ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.argument?.typeAnnotation, options) || undefined : undefined;
|
|
940
995
|
logic.returns.push(new utils_1.naslTypes.Return({
|
|
941
996
|
name: 'result',
|
|
942
997
|
typeAnnotation
|
|
943
998
|
}));
|
|
944
999
|
}
|
|
945
1000
|
const leftName = logic.returns[0].name;
|
|
946
|
-
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options));
|
|
947
|
-
if (right.concept === 'Identifier' && right.name === leftName) {
|
|
1001
|
+
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(argument, options), options) || undefined;
|
|
1002
|
+
if (right && right.concept === 'Identifier' && right.name === leftName) {
|
|
948
1003
|
return new utils_1.naslTypes.End();
|
|
949
1004
|
}
|
|
950
1005
|
else {
|
|
@@ -994,7 +1049,7 @@ function transform2PartialNewComposite(node, options) {
|
|
|
994
1049
|
const rights = [];
|
|
995
1050
|
const structureProperties = [];
|
|
996
1051
|
const assignmentLines = [];
|
|
997
|
-
const newProperties = (node?.properties || node?.arguments?.[0]?.properties)
|
|
1052
|
+
const newProperties = (node?.properties || node?.arguments?.[0]?.properties);
|
|
998
1053
|
let idx = 0;
|
|
999
1054
|
newProperties?.forEach((arg, index) => {
|
|
1000
1055
|
properties.push(transformNodeFunction(arg.key, options));
|
|
@@ -1087,8 +1142,7 @@ function transformNewExpression(node, options) {
|
|
|
1087
1142
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1088
1143
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1089
1144
|
}
|
|
1090
|
-
|
|
1091
|
-
(0, utils_1.throwError)(`Unhandled node ${node.type}: ${errCode}`);
|
|
1145
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unhandled node', node.type, node);
|
|
1092
1146
|
}
|
|
1093
1147
|
exports.transformNewExpression = transformNewExpression;
|
|
1094
1148
|
function transformMemberExpression(node, options) {
|
|
@@ -1125,18 +1179,31 @@ function transformMemberExpression(node, options) {
|
|
|
1125
1179
|
});
|
|
1126
1180
|
}
|
|
1127
1181
|
if (calleeName?.startsWith('$refs.')) {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1182
|
+
if (callee[0].type === 'CallExpression') {
|
|
1183
|
+
const callExpression = callee[0];
|
|
1184
|
+
const callCallee = flatMemberExpression(callExpression.callee);
|
|
1185
|
+
const callCalleeName = (0, utils_1.generate)(callExpression)?.code;
|
|
1186
|
+
let callResult = transformCall2CallViewElementLogic(callExpression, callCalleeName, callCallee, options);
|
|
1187
|
+
const remainingCallee = callee.slice(1);
|
|
1188
|
+
if (remainingCallee.length > 0 && callResult) {
|
|
1189
|
+
return unflatMemberExpression(remainingCallee, options, callResult);
|
|
1190
|
+
}
|
|
1191
|
+
return callResult;
|
|
1192
|
+
}
|
|
1193
|
+
else {
|
|
1194
|
+
const componentName = callee?.[1]?.name;
|
|
1195
|
+
const propertyName = callee?.[2]?.name;
|
|
1196
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
1197
|
+
object: new utils_1.naslTypes.Identifier({
|
|
1198
|
+
namespace: `elements.${componentName}.property`,
|
|
1199
|
+
name: componentName,
|
|
1200
|
+
}),
|
|
1201
|
+
property: new utils_1.naslTypes.Identifier({
|
|
1202
|
+
namespace: propertyName,
|
|
1203
|
+
name: propertyName,
|
|
1204
|
+
}),
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1140
1207
|
}
|
|
1141
1208
|
const regex = /^(app\..+?)\.variables\.(.+)$/;
|
|
1142
1209
|
if (regex.test(calleeName)) {
|
|
@@ -1191,12 +1258,88 @@ function transformMemberExpression(node, options) {
|
|
|
1191
1258
|
});
|
|
1192
1259
|
}
|
|
1193
1260
|
exports.transformMemberExpression = transformMemberExpression;
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1261
|
+
/**
|
|
1262
|
+
* @example (function match(_value) {
|
|
1263
|
+
if (_value === true) {
|
|
1264
|
+
return 'green'
|
|
1265
|
+
} else {
|
|
1266
|
+
return 'red'
|
|
1267
|
+
}
|
|
1268
|
+
})(nasl.util.Convert<Boolean>(enabled))
|
|
1269
|
+
*/
|
|
1270
|
+
function transformCallFunctionExpression2Match(node, calleeName, callee, options) {
|
|
1271
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1272
|
+
const arg = node.arguments[0];
|
|
1273
|
+
const ifStatement = node.callee.body.body[0];
|
|
1274
|
+
if (ifStatement.type !== 'IfStatement') {
|
|
1275
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1276
|
+
}
|
|
1277
|
+
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1278
|
+
const match = new utils_1.naslTypes.Match({
|
|
1279
|
+
expression: transformNodeFunction(arg, options),
|
|
1280
|
+
isExpression: true,
|
|
1281
|
+
cases: flatedIfStatements.map((_case) => {
|
|
1282
|
+
let argument;
|
|
1283
|
+
if (_case.consequent.type === 'BlockStatement') {
|
|
1284
|
+
if (_case.consequent.body.length === 1 && _case.consequent.body[0].type === 'ReturnStatement') {
|
|
1285
|
+
argument = _case.consequent.body[0].argument;
|
|
1286
|
+
}
|
|
1287
|
+
else {
|
|
1288
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
else {
|
|
1292
|
+
if (_case.consequent.type === 'ReturnStatement') {
|
|
1293
|
+
argument = _case.consequent.argument;
|
|
1294
|
+
}
|
|
1295
|
+
else {
|
|
1296
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
const bodyNode = transformNodeFunction(argument, options);
|
|
1300
|
+
return new utils_1.naslTypes.MatchCase({
|
|
1301
|
+
isMatchedTypeEnumable: false,
|
|
1302
|
+
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1303
|
+
body: bodyNode ? [bodyNode] : [],
|
|
1304
|
+
});
|
|
1305
|
+
}).filter(Boolean),
|
|
1306
|
+
});
|
|
1307
|
+
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1308
|
+
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1309
|
+
isMatchedTypeEnumable: false,
|
|
1310
|
+
patterns: [],
|
|
1311
|
+
body: [],
|
|
1312
|
+
}));
|
|
1313
|
+
}
|
|
1314
|
+
match.cases.forEach((case_) => {
|
|
1315
|
+
if (case_.patterns.length) {
|
|
1316
|
+
if (case_.patterns[0].concept === 'BooleanLiteral' || case_.patterns[0].concept === 'StringLiteral') {
|
|
1317
|
+
case_.isMatchedTypeEnumable = true;
|
|
1318
|
+
}
|
|
1319
|
+
if (case_.patterns[0].concept === 'MemberExpression') {
|
|
1320
|
+
case_.isMatchedTypeEnumable = true;
|
|
1321
|
+
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1322
|
+
object: {
|
|
1323
|
+
concept: 'Identifier',
|
|
1324
|
+
name: case_.patterns[0].object.property.name,
|
|
1325
|
+
folded: false,
|
|
1326
|
+
namespace: 'app.enums'
|
|
1327
|
+
},
|
|
1328
|
+
property: {
|
|
1329
|
+
concept: 'Identifier',
|
|
1330
|
+
name: case_.patterns[0].property.value,
|
|
1331
|
+
folded: false,
|
|
1332
|
+
},
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
});
|
|
1337
|
+
return match;
|
|
1197
1338
|
}
|
|
1198
|
-
exports.
|
|
1339
|
+
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1199
1340
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1341
|
+
if (options?.isRestricted)
|
|
1342
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1200
1343
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1201
1344
|
const componentName = callee?.[1]?.name;
|
|
1202
1345
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1231,6 +1374,8 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1231
1374
|
}
|
|
1232
1375
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1233
1376
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1377
|
+
if (options?.isRestricted)
|
|
1378
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1234
1379
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1235
1380
|
// console.log('callee', callee);
|
|
1236
1381
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1243,6 +1388,8 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1243
1388
|
}
|
|
1244
1389
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1245
1390
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1391
|
+
if (options?.isRestricted)
|
|
1392
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1246
1393
|
if (calleeName?.includes('.entities.')) {
|
|
1247
1394
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1248
1395
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1301,6 +1448,10 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1301
1448
|
}
|
|
1302
1449
|
exports.transformCall2CallDataSourceLogic = transformCall2CallDataSourceLogic;
|
|
1303
1450
|
function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
1451
|
+
if (options?.isInFrontend)
|
|
1452
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在前端使用', node);
|
|
1453
|
+
if (options?.isRestricted)
|
|
1454
|
+
return (0, utils_1.throwError)(options?.parsingId, 'OQL组件不支持在组件或默认值表达式中使用', node);
|
|
1304
1455
|
if (options.transformType === 'logic' && options?.logicType === 'global_logic') {
|
|
1305
1456
|
// const _typeAnnotation = node?.typeParameters?.params?.length > 0 ? naslTypes.TypeAnnotation.createGeneric('List', {
|
|
1306
1457
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
@@ -1310,11 +1461,13 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1310
1461
|
return new utils_1.naslTypes.OqlQueryComponent({
|
|
1311
1462
|
dataSource: 'app.dataSources.defaultDS',
|
|
1312
1463
|
code,
|
|
1313
|
-
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations)
|
|
1464
|
+
typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node?.typeAnnotations, options) || undefined,
|
|
1314
1465
|
});
|
|
1315
1466
|
}
|
|
1316
1467
|
}
|
|
1317
1468
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1469
|
+
if (options?.isRestricted)
|
|
1470
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1318
1471
|
return new utils_1.naslTypes.CallLogic({
|
|
1319
1472
|
calleeNamespace: 'nasl.logging',
|
|
1320
1473
|
calleeName: 'INFO',
|
|
@@ -1326,6 +1479,8 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1326
1479
|
}
|
|
1327
1480
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1328
1481
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1482
|
+
if (options?.isRestricted)
|
|
1483
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1329
1484
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1330
1485
|
expression: arg?.name === "undefined" ?
|
|
1331
1486
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1357,7 +1512,7 @@ function transformCall2JSONFunctions(node, calleeName, callee, options) {
|
|
|
1357
1512
|
keyword: 'arg',
|
|
1358
1513
|
}),
|
|
1359
1514
|
],
|
|
1360
|
-
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType })),
|
|
1515
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1361
1516
|
});
|
|
1362
1517
|
}
|
|
1363
1518
|
exports.transformCall2JSONFunctions = transformCall2JSONFunctions;
|
|
@@ -1374,12 +1529,12 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1374
1529
|
keyword: func && func?.params[index]?.name || `param${index + 1}`,
|
|
1375
1530
|
});
|
|
1376
1531
|
});
|
|
1377
|
-
let newTypeArguments = node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation);
|
|
1378
|
-
if (calleeName === 'ListRepeat') {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
}
|
|
1532
|
+
let newTypeArguments = node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean);
|
|
1533
|
+
// if (calleeName === 'ListRepeat') {
|
|
1534
|
+
// newTypeArguments = [
|
|
1535
|
+
// new naslTypes.TypeAnnotation()
|
|
1536
|
+
// ];
|
|
1537
|
+
// }
|
|
1383
1538
|
if (calleeName === 'Concat') {
|
|
1384
1539
|
const expressions = newArguments.map((item) => item.expression);
|
|
1385
1540
|
return new utils_1.naslTypes.StringInterpolation({
|
|
@@ -1408,7 +1563,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1408
1563
|
const content = np?.toNaturalTS();
|
|
1409
1564
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1410
1565
|
if (!np && !p?.defaultExpression) {
|
|
1411
|
-
(0, utils_1.throwError)(`函数${calleeName}生成不符合标准的函数调用`);
|
|
1566
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用`);
|
|
1412
1567
|
}
|
|
1413
1568
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1414
1569
|
if (idx === 1) {
|
|
@@ -1441,7 +1596,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1441
1596
|
});
|
|
1442
1597
|
}
|
|
1443
1598
|
else {
|
|
1444
|
-
(0, utils_1.throwError)(`函数${calleeName}
|
|
1599
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}不存在`, node.callee);
|
|
1445
1600
|
}
|
|
1446
1601
|
if (!func.params?.length) {
|
|
1447
1602
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1463,7 +1618,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1463
1618
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1464
1619
|
const excludes = ['HasValue', 'ListSort'];
|
|
1465
1620
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1466
|
-
(0, utils_1.throwError)(`函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`);
|
|
1621
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`);
|
|
1467
1622
|
}
|
|
1468
1623
|
else {
|
|
1469
1624
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1480,19 +1635,22 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1480
1635
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1481
1636
|
});
|
|
1482
1637
|
if (calleeName === 'ListSort') {
|
|
1483
|
-
|
|
1638
|
+
const handledNode = (0, utils_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1639
|
+
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1484
1640
|
}
|
|
1485
1641
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
1486
|
-
(0, utils_1.throwError)(
|
|
1642
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持使用内置函数', nodeElement.calleeName, node);
|
|
1487
1643
|
}
|
|
1488
1644
|
return nodeElement;
|
|
1489
1645
|
}
|
|
1490
1646
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1491
1647
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1492
1648
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1493
|
-
(0, utils_1.throwError)(`数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`);
|
|
1649
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`);
|
|
1494
1650
|
}
|
|
1495
1651
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1652
|
+
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
1653
|
+
const func = server_1.default ? server_1.default?.getSqlFunction('mysql', calleeName) : null;
|
|
1496
1654
|
let addArguments = [];
|
|
1497
1655
|
if (specFunList.includes(calleeName)) {
|
|
1498
1656
|
const value = calleeName === 'COUNTD' ? 'DISTINCT' : 'ALL';
|
|
@@ -1505,20 +1663,20 @@ function transform2SqlFunction(node, calleeName, argument, options) {
|
|
|
1505
1663
|
}
|
|
1506
1664
|
const newArguments = argument.map((arg, index) => new utils_1.naslTypes.Argument({
|
|
1507
1665
|
expression: fixExpression(arg, options),
|
|
1508
|
-
keyword:
|
|
1666
|
+
keyword: func?.params[index]?.name || `param${index + 1}`,
|
|
1509
1667
|
}));
|
|
1510
1668
|
const nodeElement = new utils_1.naslTypes.CallFunction({
|
|
1511
1669
|
calleeNamespace: 'nasl.sqlFunction',
|
|
1512
1670
|
calleeName: utils_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1513
1671
|
arguments: [...addArguments, ...newArguments],
|
|
1514
|
-
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
1672
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1515
1673
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1516
1674
|
});
|
|
1517
1675
|
return nodeElement;
|
|
1518
1676
|
}
|
|
1519
1677
|
function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
1520
1678
|
let curCalleeName;
|
|
1521
|
-
if (callee.length
|
|
1679
|
+
if (callee.length >= 3)
|
|
1522
1680
|
curCalleeName = callee[callee.length - 1].name;
|
|
1523
1681
|
else {
|
|
1524
1682
|
let _callee = callee[0].callee;
|
|
@@ -1526,11 +1684,10 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1526
1684
|
_callee = _callee.callee;
|
|
1527
1685
|
curCalleeName = _callee.property.name;
|
|
1528
1686
|
}
|
|
1529
|
-
const argument = callee.length
|
|
1530
|
-
if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1531
|
-
|
|
1532
|
-
}
|
|
1533
|
-
;
|
|
1687
|
+
const argument = callee.length >= 3 ? node.arguments : callee[0].arguments;
|
|
1688
|
+
// if (['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN'].includes(curCalleeName)) {
|
|
1689
|
+
// return transformCallExpressionToBinaryExpression(node, curCalleeName, callee, options);
|
|
1690
|
+
// };
|
|
1534
1691
|
if (['NewList', 'NewMap', 'NewEntity', 'NewStructure', 'NewAnonymousStructure'].includes(curCalleeName)) {
|
|
1535
1692
|
return transform2NewExpression(curCalleeName, node, options);
|
|
1536
1693
|
}
|
|
@@ -1539,10 +1696,31 @@ function transformCall2CallFunction(node, calleeName, callee, options) {
|
|
|
1539
1696
|
exports.transformCall2CallFunction = transformCall2CallFunction;
|
|
1540
1697
|
function transform2UIFunction(node, calleeName, callee, options) {
|
|
1541
1698
|
if (callee[2].name === 'destination') {
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1699
|
+
let namespaceNode = node.arguments[0];
|
|
1700
|
+
let namespace = '';
|
|
1701
|
+
if (namespaceNode.type === 'TemplateLiteral') {
|
|
1702
|
+
namespace = namespaceNode.quasis[0]?.value?.cooked;
|
|
1703
|
+
}
|
|
1704
|
+
else if (namespaceNode.type === 'StringLiteral') {
|
|
1705
|
+
namespace = namespaceNode.value;
|
|
1706
|
+
}
|
|
1707
|
+
else {
|
|
1708
|
+
namespace = (0, utils_1.generate)(namespaceNode).code;
|
|
1709
|
+
}
|
|
1710
|
+
let nsArr;
|
|
1711
|
+
let viewNamespace = '';
|
|
1712
|
+
let viewName = '';
|
|
1713
|
+
if (namespace.startsWith('app.frontendTypes.')) {
|
|
1714
|
+
nsArr = namespace.split('.');
|
|
1715
|
+
viewName = nsArr.pop();
|
|
1716
|
+
viewNamespace = nsArr.join('.');
|
|
1717
|
+
}
|
|
1718
|
+
else {
|
|
1719
|
+
nsArr = namespace.split('.').map((item) => item.replace(/_view$/, ''));
|
|
1720
|
+
const pageType = nsArr.shift();
|
|
1721
|
+
viewName = nsArr.pop();
|
|
1722
|
+
viewNamespace = `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`;
|
|
1723
|
+
}
|
|
1546
1724
|
const newArguments = node?.arguments?.slice(1);
|
|
1547
1725
|
let argument = [];
|
|
1548
1726
|
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
@@ -1558,7 +1736,7 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1558
1736
|
}));
|
|
1559
1737
|
}
|
|
1560
1738
|
return new utils_1.naslTypes.Destination({
|
|
1561
|
-
viewNamespace
|
|
1739
|
+
viewNamespace,
|
|
1562
1740
|
viewName,
|
|
1563
1741
|
arguments: argument,
|
|
1564
1742
|
});
|
|
@@ -1568,6 +1746,8 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1568
1746
|
link: fixExpression(node?.arguments[0], options),
|
|
1569
1747
|
});
|
|
1570
1748
|
}
|
|
1749
|
+
if (options?.isRestricted)
|
|
1750
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1571
1751
|
return new utils_1.naslTypes.CallLogic({
|
|
1572
1752
|
calleeNamespace: 'nasl.ui',
|
|
1573
1753
|
calleeName: callee[2].name,
|
|
@@ -1604,11 +1784,11 @@ function transform2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1604
1784
|
each: transformNodeFunction(newCallee[0], options),
|
|
1605
1785
|
start: transformNodeFunction(newCallee[1], options),
|
|
1606
1786
|
end: newCallee[2]?.name === '__IDENTIFIER__' ? undefined : transformNodeFunction(newCallee[2], options),
|
|
1607
|
-
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0]) : new utils_1.naslTypes.Param({
|
|
1787
|
+
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0], options) || undefined : new utils_1.naslTypes.Param({
|
|
1608
1788
|
name: 'item',
|
|
1609
1789
|
typeAnnotation: undefined,
|
|
1610
1790
|
}),
|
|
1611
|
-
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1791
|
+
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1612
1792
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 4)}`,
|
|
1613
1793
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1614
1794
|
}),
|
|
@@ -1652,11 +1832,11 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1652
1832
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1653
1833
|
}),
|
|
1654
1834
|
end: endNode?.name === '__IDENTIFIER__' ? undefined : endNode ? transformNodeFunction(endNode, options) : undefined,
|
|
1655
|
-
item: itemNode ? transform2Param(itemNode) : new utils_1.naslTypes.Param({
|
|
1835
|
+
item: itemNode ? transform2Param(itemNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1656
1836
|
name: 'item',
|
|
1657
1837
|
typeAnnotation: undefined,
|
|
1658
1838
|
}),
|
|
1659
|
-
index: indexNode ? transform2Param(indexNode) : new utils_1.naslTypes.Param({
|
|
1839
|
+
index: indexNode ? transform2Param(indexNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1660
1840
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1661
1841
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1662
1842
|
}),
|
|
@@ -1676,8 +1856,8 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1676
1856
|
value: '0',
|
|
1677
1857
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1678
1858
|
}),
|
|
1679
|
-
item: transform2Param(arrowFunction.params[0]),
|
|
1680
|
-
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
1859
|
+
item: transform2Param(arrowFunction.params[0], options) || undefined,
|
|
1860
|
+
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1681
1861
|
name: `index_${(0, utils_2.uuidv4)().slice(0, 2)}`,
|
|
1682
1862
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1683
1863
|
}),
|
|
@@ -1687,6 +1867,8 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1687
1867
|
}
|
|
1688
1868
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1689
1869
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1870
|
+
if (options?.isRestricted)
|
|
1871
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1690
1872
|
return new utils_1.naslTypes.CallLogic({
|
|
1691
1873
|
calleeNamespace: 'nasl.ui',
|
|
1692
1874
|
calleeName: 'showMessage',
|
|
@@ -1698,6 +1880,8 @@ function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
|
1698
1880
|
}
|
|
1699
1881
|
exports.transformAlert2ShowMessage = transformAlert2ShowMessage;
|
|
1700
1882
|
function transformCall2Interface(node, calleeName, callee, options) {
|
|
1883
|
+
if (options?.isRestricted)
|
|
1884
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用接口不支持在组件或默认值表达式中使用', node);
|
|
1701
1885
|
return new utils_1.naslTypes.CallInterface({
|
|
1702
1886
|
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
1703
1887
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1709,13 +1893,15 @@ function transformCall2Interface(node, calleeName, callee, options) {
|
|
|
1709
1893
|
}
|
|
1710
1894
|
exports.transformCall2Interface = transformCall2Interface;
|
|
1711
1895
|
function transformCall2Connector(node, calleeName, callee, options) {
|
|
1896
|
+
if (options?.isRestricted)
|
|
1897
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1712
1898
|
let calleeConnectionName = undefined;
|
|
1713
1899
|
let calleeNamespace = undefined;
|
|
1714
1900
|
let calleeNamespacePrefix = `connector.${callee[1].name}`;
|
|
1715
1901
|
if (callee.length === 5) {
|
|
1716
1902
|
const connectArg = callee[2].arguments[0];
|
|
1717
1903
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1718
|
-
(0, utils_1.throwError)(
|
|
1904
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1719
1905
|
}
|
|
1720
1906
|
calleeConnectionName = connectArg.value;
|
|
1721
1907
|
const noNamespace = callee[3].name === 'logics';
|
|
@@ -1730,7 +1916,7 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1730
1916
|
calleeNamespace = calleeNamespacePrefix;
|
|
1731
1917
|
}
|
|
1732
1918
|
else {
|
|
1733
|
-
(0, utils_1.throwError)(`调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}
|
|
1919
|
+
return (0, utils_1.throwError)(options?.parsingId, `调用 connector,参数数量不正确,当前参数数量为 ${callee.length},${calleeName}`, node);
|
|
1734
1920
|
}
|
|
1735
1921
|
return new utils_1.naslTypes.CallConnector({
|
|
1736
1922
|
calleeConnectionName,
|
|
@@ -1743,6 +1929,8 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1743
1929
|
}
|
|
1744
1930
|
exports.transformCall2Connector = transformCall2Connector;
|
|
1745
1931
|
function transformCall2Extension(node, calleeName, callee, options) {
|
|
1932
|
+
if (options?.isRestricted)
|
|
1933
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用扩展逻辑不支持在组件或默认值表达式中使用', node);
|
|
1746
1934
|
return new utils_1.naslTypes.CallLogic({
|
|
1747
1935
|
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
1748
1936
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
@@ -1752,70 +1940,26 @@ function transformCall2Extension(node, calleeName, callee, options) {
|
|
|
1752
1940
|
});
|
|
1753
1941
|
}
|
|
1754
1942
|
exports.transformCall2Extension = transformCall2Extension;
|
|
1755
|
-
function transformArrowFunction2Match(node, calleeName, callee, options) {
|
|
1756
|
-
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1757
|
-
// NOTE: 适用于 if else
|
|
1758
|
-
const newCallee = node.callee.body.body;
|
|
1759
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__MatchExpressionFunction') {
|
|
1760
|
-
const match = new utils_1.naslTypes.Match({
|
|
1761
|
-
expression: fixExpression(newCallee[0], options),
|
|
1762
|
-
isExpression: options.transformType !== 'logic',
|
|
1763
|
-
cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new utils_1.naslTypes.MatchCase({
|
|
1764
|
-
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1765
|
-
body: transformBlockBody(_case.consequent.body.filter((item) => item.type !== 'BreakStatement'), options),
|
|
1766
|
-
})),
|
|
1767
|
-
});
|
|
1768
|
-
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1769
|
-
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1770
|
-
patterns: [],
|
|
1771
|
-
body: [],
|
|
1772
|
-
}));
|
|
1773
|
-
}
|
|
1774
|
-
match.cases.forEach((case_) => {
|
|
1775
|
-
if (case_.body.length && (case_.body[0].concept === 'BooleanLiteral' || case_.body[0].concept === 'StringLiteral')) {
|
|
1776
|
-
case_.isMatchedTypeEnumable = true;
|
|
1777
|
-
}
|
|
1778
|
-
if (case_.patterns.length && case_.patterns[0].concept === 'MemberExpression') {
|
|
1779
|
-
case_.isMatchedTypeEnumable = true;
|
|
1780
|
-
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1781
|
-
object: {
|
|
1782
|
-
concept: 'Identifier',
|
|
1783
|
-
name: case_.patterns[0].object.property.name,
|
|
1784
|
-
folded: false,
|
|
1785
|
-
namespace: 'app.enums'
|
|
1786
|
-
},
|
|
1787
|
-
property: {
|
|
1788
|
-
concept: 'Identifier',
|
|
1789
|
-
name: case_.patterns[0].property.value,
|
|
1790
|
-
folded: false,
|
|
1791
|
-
},
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
});
|
|
1795
|
-
return match;
|
|
1796
|
-
}
|
|
1797
|
-
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__SwitchExpressionFuntion') {
|
|
1798
|
-
const switchStatement = transformNodeFunction(newCallee[0].body.body[0], options);
|
|
1799
|
-
return switchStatement;
|
|
1800
|
-
}
|
|
1801
|
-
(0, utils_1.throwError)(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
1802
|
-
}
|
|
1803
|
-
exports.transformArrowFunction2Match = transformArrowFunction2Match;
|
|
1804
1943
|
function transformTSAsExpression(node, options) {
|
|
1805
1944
|
if (node.expression.type === 'NumericLiteral') {
|
|
1806
|
-
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation) });
|
|
1945
|
+
return transform2NumericLiteral(node.expression, { ...options, typeAnnotation: (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined });
|
|
1807
1946
|
}
|
|
1808
1947
|
else if (node.expression.type === 'ArrayExpression') {
|
|
1809
|
-
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation);
|
|
1948
|
+
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
1810
1949
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
1811
|
-
(0, utils_1.throwError)(`列表 as 必须为 List 类型`);
|
|
1950
|
+
return (0, utils_1.throwError)(options?.parsingId, `列表 as 必须为 List 类型`);
|
|
1812
1951
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
1813
1952
|
}
|
|
1953
|
+
else if (node.expression.type === 'NullLiteral') {
|
|
1954
|
+
return transform2NullLiteral(node.expression, options);
|
|
1955
|
+
}
|
|
1814
1956
|
else {
|
|
1815
|
-
(0, utils_1.throwError)(
|
|
1957
|
+
return (0, utils_1.throwError)(options?.parsingId, '表达式不支持使用 as 关键字', node.expression.type, node.expression);
|
|
1816
1958
|
}
|
|
1817
1959
|
}
|
|
1818
1960
|
function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
1961
|
+
if (options?.isRestricted)
|
|
1962
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用页面逻辑不支持在组件或默认值表达式中使用', node);
|
|
1819
1963
|
return new utils_1.naslTypes.CallLogic({
|
|
1820
1964
|
calleeNamespace: '',
|
|
1821
1965
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
@@ -1826,11 +1970,13 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
1826
1970
|
}
|
|
1827
1971
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
1828
1972
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
1973
|
+
if (options?.isRestricted)
|
|
1974
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1829
1975
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
1830
1976
|
// 未带前缀,补一下
|
|
1831
1977
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
1832
1978
|
}
|
|
1833
|
-
else if (
|
|
1979
|
+
else if (server_1.default.getSqlFunction('mysql', calleeName) || calleeName === 'COUNTD') {
|
|
1834
1980
|
return transform2SqlFunction(node, calleeName, node?.arguments || [], options);
|
|
1835
1981
|
}
|
|
1836
1982
|
let newCalleeName = calleeName?.includes('__IDENTIFIER__') ? undefined : calleeName;
|
|
@@ -1850,6 +1996,8 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
1850
1996
|
}
|
|
1851
1997
|
exports.transformCall2Logic = transformCall2Logic;
|
|
1852
1998
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
1999
|
+
if (options?.isRestricted)
|
|
2000
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用', node);
|
|
1853
2001
|
return new utils_1.naslTypes.CallLogic({
|
|
1854
2002
|
calleeNamespace: `nasl.auth`,
|
|
1855
2003
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -1874,10 +2022,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1874
2022
|
const calleeName = node.callee.name;
|
|
1875
2023
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
1876
2024
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
1877
|
-
(0, utils_1.throwError)('FROM should have a ArrowFunctionExpression as the second argument');
|
|
2025
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1]);
|
|
1878
2026
|
const arrowFunctionExpression = node.arguments[1];
|
|
1879
2027
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
1880
|
-
(0, utils_1.throwError)('FROM should have a CallExpression as the body of ArrowFunctionExpression');
|
|
2028
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body);
|
|
1881
2029
|
const body = arrowFunctionExpression.body;
|
|
1882
2030
|
const callExpressions = flatChainCallExpression(body);
|
|
1883
2031
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -1887,13 +2035,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
1887
2035
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
1888
2036
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
1889
2037
|
`;
|
|
1890
|
-
(0, utils_1.throwError)(error);
|
|
2038
|
+
return (0, utils_1.throwError)(options?.parsingId, error);
|
|
1891
2039
|
}
|
|
1892
2040
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
1893
2041
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
1894
2042
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
1895
2043
|
if (errorOrder) {
|
|
1896
|
-
(0, utils_1.throwError)('调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。'
|
|
2044
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。');
|
|
1897
2045
|
}
|
|
1898
2046
|
const result = [{
|
|
1899
2047
|
calleeName: calleeName,
|
|
@@ -1905,7 +2053,7 @@ FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); /
|
|
|
1905
2053
|
result[0].arguments[2] = item.arguments[0];
|
|
1906
2054
|
}
|
|
1907
2055
|
else if (['INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(item.callee.name)) {
|
|
1908
|
-
result.push(...flatCallQueryComponentChainNode(item, options));
|
|
2056
|
+
result.push(...flatCallQueryComponentChainNode(item, options) || []);
|
|
1909
2057
|
}
|
|
1910
2058
|
else {
|
|
1911
2059
|
result.push({
|
|
@@ -1938,33 +2086,37 @@ function flatOnExpressions(node) {
|
|
|
1938
2086
|
return [node];
|
|
1939
2087
|
}
|
|
1940
2088
|
}
|
|
1941
|
-
function transformMemberExpression2Entity(node, node2) {
|
|
2089
|
+
function transformMemberExpression2Entity(node, node2, options) {
|
|
1942
2090
|
const entityPath = flatMemberExpression(node);
|
|
1943
2091
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
1944
2092
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
1945
2093
|
if (!entityNamespace?.includes('.entities')) {
|
|
1946
|
-
(0, utils_1.throwError)(`${entityNamespace}.${entityName}
|
|
2094
|
+
return (0, utils_1.throwError)(options?.parsingId, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`);
|
|
1947
2095
|
}
|
|
1948
2096
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
1949
2097
|
if (asName) {
|
|
1950
|
-
(0, utils_1.throwError)(`FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
2098
|
+
return (0, utils_1.throwError)(options?.parsingId, `FROM 中回调函数的入参名称应为${entityName},但实际为${node2.name}`);
|
|
1951
2099
|
}
|
|
1952
2100
|
return { entityNamespace, entityName, asName };
|
|
1953
2101
|
}
|
|
1954
2102
|
function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
2103
|
+
if (options?.isInFrontend)
|
|
2104
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在前端使用', node);
|
|
2105
|
+
if (options?.isRestricted)
|
|
2106
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
1955
2107
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1956
2108
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
1957
2109
|
if (code?.includes('nasl.util')) {
|
|
1958
|
-
(0, utils_1.throwError)('数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理');
|
|
2110
|
+
return (0, utils_1.throwError)(options?.parsingId, '数据查询中不支持nasl.util内的库函数,请将对应操作放在数据查询外部进行处理', code);
|
|
1959
2111
|
}
|
|
1960
2112
|
if (!code?.includes('.SELECT(') && !code?.includes('.AGGR_SELECT(')) {
|
|
1961
|
-
(0, utils_1.throwError)('缺少 SELECT 或 AGGR_SELECT 语句');
|
|
2113
|
+
return (0, utils_1.throwError)(options?.parsingId, '缺少 SELECT 或 AGGR_SELECT 语句', code);
|
|
1962
2114
|
}
|
|
1963
2115
|
const flatted = flatCallQueryComponentChainNode(node, options);
|
|
1964
|
-
const calleeNames = flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2116
|
+
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
1965
2117
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
1966
2118
|
if (!isOrderCorrect) {
|
|
1967
|
-
(0, utils_1.throwError)('调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。'
|
|
2119
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。');
|
|
1968
2120
|
}
|
|
1969
2121
|
let from;
|
|
1970
2122
|
let where;
|
|
@@ -1977,11 +2129,13 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
1977
2129
|
let hasErrorTSScopeColumn = false;
|
|
1978
2130
|
let useResultItem = false;
|
|
1979
2131
|
// 这里只是一个示例,具体的逻辑需要根据flatted的内容来构建
|
|
1980
|
-
flatted.forEach((item) => {
|
|
2132
|
+
flatted && flatted.forEach((item) => {
|
|
1981
2133
|
// console.log(item.calleeName)
|
|
1982
2134
|
switch (item.calleeName) {
|
|
1983
2135
|
case 'FROM':
|
|
1984
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2136
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2137
|
+
if (!entity)
|
|
2138
|
+
break;
|
|
1985
2139
|
const entityName = entity.asName || entity.entityName;
|
|
1986
2140
|
entityAsNames.push(entityName);
|
|
1987
2141
|
from = new utils_1.naslTypes.QueryFromExpression({
|
|
@@ -1993,7 +2147,9 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
1993
2147
|
case 'LEFT_JOIN':
|
|
1994
2148
|
case 'RIGHT_JOIN':
|
|
1995
2149
|
case 'OUTER_JOIN':
|
|
1996
|
-
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1]);
|
|
2150
|
+
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2151
|
+
if (!entity)
|
|
2152
|
+
break;
|
|
1997
2153
|
entityAsNames.push(entity.asName || entity.entityName);
|
|
1998
2154
|
const rawJoinType = item.calleeName.slice(0, -5);
|
|
1999
2155
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
@@ -2014,7 +2170,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2014
2170
|
break;
|
|
2015
2171
|
case 'AGGR_SELECT':
|
|
2016
2172
|
if (groupBy?.length) {
|
|
2017
|
-
(0, utils_1.throwError)('存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2173
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2018
2174
|
}
|
|
2019
2175
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2020
2176
|
distinct: false,
|
|
@@ -2025,16 +2181,39 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2025
2181
|
propertyName: '',
|
|
2026
2182
|
})],
|
|
2027
2183
|
});
|
|
2028
|
-
item.arguments[0].
|
|
2029
|
-
|
|
2030
|
-
|
|
2184
|
+
if (item.arguments[0].type === 'ObjectExpression') {
|
|
2185
|
+
item.arguments[0].properties?.forEach((arg) => {
|
|
2186
|
+
if (arg?.value.type === 'CallExpression') {
|
|
2187
|
+
let selectElements = transform2QueryAggregateExpression(arg, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2188
|
+
if (selectElements) {
|
|
2189
|
+
const newSelectElements = [...select.selectElements, selectElements];
|
|
2190
|
+
select.setSelectElements(newSelectElements);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
else {
|
|
2194
|
+
return (0, utils_1.throwError)(options?.parsingId, `Unsupported expression type for QueryAggregateExpression`, arg?.value.type, arg?.value);
|
|
2195
|
+
}
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
else if (item.arguments[0].type === 'CallExpression') { // 只有一个的简写:AGGR_SELECT(SUM(Entity1.age))
|
|
2199
|
+
const selectElements = transform2QueryAggregateExpression({
|
|
2200
|
+
type: 'ObjectProperty',
|
|
2201
|
+
key: {
|
|
2202
|
+
type: 'Identifier',
|
|
2203
|
+
name: 'resultItem',
|
|
2204
|
+
},
|
|
2205
|
+
value: item.arguments[0],
|
|
2206
|
+
computed: false,
|
|
2207
|
+
shorthand: false,
|
|
2208
|
+
}, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2209
|
+
if (selectElements) {
|
|
2031
2210
|
const newSelectElements = [...select.selectElements, selectElements];
|
|
2032
2211
|
select.setSelectElements(newSelectElements);
|
|
2033
2212
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
}
|
|
2213
|
+
}
|
|
2214
|
+
else {
|
|
2215
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Unsupported expression type for QueryAggregateExpression', item.arguments[0].type, item.arguments[0]);
|
|
2216
|
+
}
|
|
2038
2217
|
break;
|
|
2039
2218
|
case 'SELECT':
|
|
2040
2219
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
@@ -2053,17 +2232,17 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2053
2232
|
}
|
|
2054
2233
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2055
2234
|
if (groupBy?.length) {
|
|
2056
|
-
(0, utils_1.throwError)('存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2235
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2057
2236
|
}
|
|
2058
2237
|
const originName = arg.key?.name || '';
|
|
2059
2238
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2060
2239
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2061
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`);
|
|
2240
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`);
|
|
2062
2241
|
}
|
|
2063
2242
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2064
2243
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2065
2244
|
if (!entityAsNames.includes(entityName)) {
|
|
2066
|
-
(0, utils_1.throwError)(`SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`);
|
|
2245
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`);
|
|
2067
2246
|
}
|
|
2068
2247
|
selectElements = arg.value.properties?.map((property) => {
|
|
2069
2248
|
const columnAsName = property.key?.name;
|
|
@@ -2071,7 +2250,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2071
2250
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2072
2251
|
if (columnAsName !== columnPropertyName) {
|
|
2073
2252
|
// eg: comment: Topic_Comment.comment_stu
|
|
2074
|
-
(0, utils_1.throwError)(`SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`);
|
|
2253
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`);
|
|
2075
2254
|
}
|
|
2076
2255
|
selectElement.isDotStar = false;
|
|
2077
2256
|
return selectElement;
|
|
@@ -2106,7 +2285,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2106
2285
|
}
|
|
2107
2286
|
}
|
|
2108
2287
|
else {
|
|
2109
|
-
(0, utils_1.throwError)('HAVING 不符合规范,请使用箭头函数');
|
|
2288
|
+
return (0, utils_1.throwError)(options?.parsingId, 'HAVING 不符合规范,请使用箭头函数', havingNode);
|
|
2110
2289
|
}
|
|
2111
2290
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2112
2291
|
break;
|
|
@@ -2121,7 +2300,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2121
2300
|
}
|
|
2122
2301
|
}
|
|
2123
2302
|
else {
|
|
2124
|
-
(0, utils_1.throwError)('ORDER_BY 不符合规范,请使用箭头函数');
|
|
2303
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数', orderNode);
|
|
2125
2304
|
}
|
|
2126
2305
|
orderBy = orderNode.map((arg) => {
|
|
2127
2306
|
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
@@ -2147,24 +2326,26 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2147
2326
|
ideVersion: '2.22',
|
|
2148
2327
|
});
|
|
2149
2328
|
if (hasErrorTSScopeColumn && !groupBy?.length && !having) {
|
|
2150
|
-
(0, utils_1.throwError)('SELECT 局部列不符合规范,需要按两层对象返回');
|
|
2329
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 局部列不符合规范,需要按两层对象返回');
|
|
2151
2330
|
}
|
|
2152
2331
|
const hasScopeColumn = select?.selectElements?.find((selectElement) => selectElement?.concept === 'QueryFieldExpression' && !selectElement?.isDotStar);
|
|
2153
2332
|
if (hasScopeColumn && (groupBy?.length || having)) {
|
|
2154
|
-
(0, utils_1.throwError)('分组聚合与表字段局部列不允许同时出现');
|
|
2333
|
+
return (0, utils_1.throwError)(options?.parsingId, '分组聚合与表字段局部列不允许同时出现');
|
|
2155
2334
|
}
|
|
2156
2335
|
if (hasScopeColumn && useResultItem) {
|
|
2157
|
-
(0, utils_1.throwError)("对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])");
|
|
2336
|
+
return (0, utils_1.throwError)(options?.parsingId, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])");
|
|
2158
2337
|
}
|
|
2159
2338
|
const isOnlyAggr = select?.selectElements?.find((selectElement) => selectElement?.concept !== 'QueryAggregateExpression');
|
|
2160
2339
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2161
2340
|
if (!isOnlyAggr && !calleeNames?.includes('AGGR_SELECT')) {
|
|
2162
|
-
(0, utils_1.throwError)('SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2341
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2163
2342
|
}
|
|
2164
2343
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2165
2344
|
return callQueryComponent;
|
|
2166
2345
|
}
|
|
2167
2346
|
function transformCall2LaunchProcess(node, calleeName, callee, options) {
|
|
2347
|
+
if (options?.isRestricted)
|
|
2348
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用流程逻辑不支持在组件或默认值表达式中使用', node);
|
|
2168
2349
|
const args = node.arguments;
|
|
2169
2350
|
const dataArg = args?.[0];
|
|
2170
2351
|
const procDefKeyArg = args?.[1];
|
|
@@ -2203,6 +2384,7 @@ function transform2LogicItem(node, options) {
|
|
|
2203
2384
|
transformManager.register('NumericLiteral', transform2NumericLiteral);
|
|
2204
2385
|
transformManager.register('NullLiteral', transform2NullLiteral);
|
|
2205
2386
|
transformManager.register('TemplateLiteral', transform2StringInterpolation);
|
|
2387
|
+
transformManager.register((node) => node.type === 'LogicalExpression' && node.operator === '??', transformDefaultExpression);
|
|
2206
2388
|
transformManager.register('BinaryExpression', transform2BinaryExpression);
|
|
2207
2389
|
transformManager.register('LogicalExpression', transform2BinaryExpression);
|
|
2208
2390
|
transformManager.register('UpdateExpression', transformUpdateExpression2Assignment);
|
|
@@ -2240,7 +2422,8 @@ function transform2LogicItem(node, options) {
|
|
|
2240
2422
|
}
|
|
2241
2423
|
});
|
|
2242
2424
|
transformManager.register('MemberExpression', transformMemberExpression);
|
|
2243
|
-
transformManager.register(
|
|
2425
|
+
transformManager.register('OptionalMemberExpression', transformMemberExpression);
|
|
2426
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && (node.callee.type === 'FunctionExpression' && node.callee.id?.name === 'match' || node.callee.type === 'ArrowFunctionExpression'), transformCallFunctionExpression2Match);
|
|
2244
2427
|
transformManager.registerCallExpression((node, calleeName) => /^\$refs\./.test(calleeName), transformCall2CallViewElementLogic);
|
|
2245
2428
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity'), transformCall2CallEntityLogic);
|
|
2246
2429
|
transformManager.registerCallExpression('nasl.oql.query', transformCall2OQLQuery);
|
|
@@ -2262,15 +2445,14 @@ function transform2LogicItem(node, options) {
|
|
|
2262
2445
|
transformManager.registerCallExpression('extensions.lcap_process_framework.logics.launchProcess', transformCall2LaunchProcess);
|
|
2263
2446
|
transformManager.registerCallExpression((node, calleeName) => /extensions\./.test(calleeName), transformCall2Extension);
|
|
2264
2447
|
transformManager.registerCallExpression((node, calleeName) => /connectors\./.test(calleeName), transformCall2Connector);
|
|
2265
|
-
transformManager.registerCallExpression((node) => node.callee.type === 'ArrowFunctionExpression', transformArrowFunction2Match);
|
|
2266
2448
|
transformManager.registerCallExpression((node, calleeName) => ['plus', 'minus', 'multiply', 'divide', 'remainder', 'STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'].includes(calleeName), transformCallExpressionToBinaryExpression);
|
|
2267
2449
|
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && calleeName.startsWith('viewLogic_'), transformCall2CallViewLogic);
|
|
2268
2450
|
transformManager.registerCallExpression('PAGINATE', transformCall2Paginate);
|
|
2269
2451
|
transformManager.registerCallExpression('FROM', transformCall2DataQuery);
|
|
2270
|
-
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1, transformCall2Logic);
|
|
2452
|
+
transformManager.registerCallExpression((node, calleeName, callee) => callee.length === 1 && !['ArrowFunctionExpression', 'FunctionExpression'].includes(callee[0].type), transformCall2Logic);
|
|
2271
2453
|
let result = transformManager.apply(node, options);
|
|
2272
2454
|
delete options.typeAnnotation;
|
|
2273
|
-
return result;
|
|
2455
|
+
return result || undefined;
|
|
2274
2456
|
}
|
|
2275
2457
|
exports.transform2LogicItem = transform2LogicItem;
|
|
2276
2458
|
//# sourceMappingURL=transform2LogicItem.js.map
|