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