@lcap/nasl 4.1.0-creator.2 → 4.1.0-creator.4
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/natural/parseNaturalTS.js +2 -2
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +3 -0
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -1
- package/out/natural/parseNaturalTSXView.js +64 -13
- package/out/natural/parseNaturalTSXView.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +2 -0
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +78 -49
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/package.json +12 -12
|
@@ -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 = void 0;
|
|
6
|
+
exports.transformCall2Interface = 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.transform2PartialNewComposite = exports.transform2Comment = exports.transform2StringInterpolation = exports.transformReturnStatement2AssignmentOrEnd = exports.transform2NullLiteral = exports.transform2NumericLiteral = exports.transform2DirectiveLiteral = exports.transform2StringLiteral = exports.transform2BooleanLiteral = exports.transformUpdateExpression2Assignment = exports.transform2Assignment = exports.transform2AnonymousFunction = exports.transformIdentifier = exports.transformSwitchStatement2Match = exports.transform2WhileStatement = exports.transform2Break = exports.transform2Continue = exports.transform2IfStatement = exports.transform2BinaryExpression = exports.transform2VariadicExpression = exports.transformCallExpressionToBinaryExpression = exports.transform2Param = exports.fixLogicNode = exports.flatIfStatementForMatch = exports.flatMatchPatternsExpression = exports.getSelectMembers = exports.unflatMemberExpression = exports.flatMemberExpression = exports.fixExpression = exports.TransformManager = void 0;
|
|
7
|
+
exports.transform2LogicItem = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = exports.transformCall2Extension = exports.transformCall2Connector = void 0;
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
9
|
const transform2TypeAnnotation_1 = require("./transform2TypeAnnotation");
|
|
10
10
|
const utils_2 = require("../../utils");
|
|
@@ -47,7 +47,7 @@ class TransformManager {
|
|
|
47
47
|
return transform(node, calleeName, callee, options);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
return (0, utils_1.throwError)(options?.parsingId,
|
|
50
|
+
return (0, utils_1.throwError)(options?.parsingId, `不支持的节点类型 ${callee.map((item) => item.name).join('.')}`, node.type, node);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
53
|
for (const [type, transform] of this.transforms) {
|
|
@@ -55,7 +55,7 @@ class TransformManager {
|
|
|
55
55
|
return transform(node, options);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
58
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的节点类型', node.type, node);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -123,7 +123,7 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
123
123
|
}
|
|
124
124
|
function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
125
125
|
if (expression?.concept === 'AnonymousFunction')
|
|
126
|
-
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function is not allowed in assignment'
|
|
126
|
+
return (0, utils_1.throwError)(options?.parsingId, 'Anonymous function is not allowed in assignment');
|
|
127
127
|
return expression;
|
|
128
128
|
}
|
|
129
129
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
@@ -338,7 +338,7 @@ function transform2Param(node, options) {
|
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
340
|
else {
|
|
341
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
341
|
+
return (0, utils_1.throwError)(options?.parsingId, '在输入参数中不支持节点类型', node);
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
exports.transform2Param = transform2Param;
|
|
@@ -442,7 +442,7 @@ function transform2BinaryExpression(node, options) {
|
|
|
442
442
|
right: transformNodeFunction(node.right, options),
|
|
443
443
|
});
|
|
444
444
|
}
|
|
445
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
445
|
+
return (0, utils_1.throwError)(options?.parsingId, '在二元表达式中不支持节点类型', node.type, node);
|
|
446
446
|
}
|
|
447
447
|
exports.transform2BinaryExpression = transform2BinaryExpression;
|
|
448
448
|
function transformDefaultExpression(node, options) {
|
|
@@ -508,7 +508,7 @@ function transform2NewAnonymousStructure(node, options) {
|
|
|
508
508
|
item.naslType = currentType.typeAnnotation;
|
|
509
509
|
}
|
|
510
510
|
else {
|
|
511
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
511
|
+
return (0, utils_1.throwError)(options?.parsingId, '匿名数据结构的属性中, 不允许出现没有类型的 null 值,请使用 as 关键字来指定类型,如 { price: null as Decimal }', node);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
514
|
else if (itemValue.type === 'TSAsExpression') {
|
|
@@ -549,7 +549,7 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
551
|
if (node?.arguments && node?.arguments?.[0]?.type !== 'ArrayExpression') {
|
|
552
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
552
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewList 中不允许出现非数组表达式', node);
|
|
553
553
|
}
|
|
554
554
|
return new utils_1.naslTypes.NewList({
|
|
555
555
|
typeAnnotation: node?.typeParameters ? typeAnnotation : undefined,
|
|
@@ -582,13 +582,13 @@ function transform2NewExpression(calleeName, node, options) {
|
|
|
582
582
|
const typeParam = node.typeParameters?.params[0];
|
|
583
583
|
const typeNamespaceAndName = typeParam ? (0, utils_1.generate)(typeParam).code : '';
|
|
584
584
|
if (!typeNamespaceAndName)
|
|
585
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
585
|
+
return (0, utils_1.throwError)(options?.parsingId, 'NewEntity 中必须指定类型', node);
|
|
586
586
|
return transform2NewStructure(typeNamespaceAndName, node.arguments[0], options);
|
|
587
587
|
}
|
|
588
588
|
if (calleeName === 'NewAnonymousStructure') {
|
|
589
589
|
return transform2NewAnonymousStructure(node.arguments[0], options);
|
|
590
590
|
}
|
|
591
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
591
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
592
592
|
}
|
|
593
593
|
function pushElseIf(ifNode, switchStatement, options) {
|
|
594
594
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -860,7 +860,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
860
860
|
// @TODO
|
|
861
861
|
}
|
|
862
862
|
else {
|
|
863
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
863
|
+
return (0, utils_1.throwError)(options?.parsingId, '在 QueryFieldExpression 不支持表达式类型', expression.type, expression);
|
|
864
864
|
}
|
|
865
865
|
}
|
|
866
866
|
function transform2QueryAggregateExpression(node, options) {
|
|
@@ -1142,7 +1142,7 @@ function transformNewExpression(node, options) {
|
|
|
1142
1142
|
else if (calleeName.includes('.entities.') || calleeName.includes('.structures.')) {
|
|
1143
1143
|
return transform2NewStructure(calleeName, node.arguments[0], options);
|
|
1144
1144
|
}
|
|
1145
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1145
|
+
return (0, utils_1.throwError)(options?.parsingId, '在新建表达式中不支持节点类型', node.type, node);
|
|
1146
1146
|
}
|
|
1147
1147
|
exports.transformNewExpression = transformNewExpression;
|
|
1148
1148
|
function transformMemberExpression(node, options) {
|
|
@@ -1339,7 +1339,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1339
1339
|
exports.transformCallFunctionExpression2Match = transformCallFunctionExpression2Match;
|
|
1340
1340
|
function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
1341
1341
|
if (options?.isRestricted)
|
|
1342
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1342
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1343
1343
|
if (calleeName?.includes('getPropValue') || calleeName?.includes('setPropValue')) {
|
|
1344
1344
|
const componentName = callee?.[1]?.name;
|
|
1345
1345
|
const propertyName = node?.arguments?.[0]?.value;
|
|
@@ -1375,7 +1375,7 @@ function transformCall2CallViewElementLogic(node, calleeName, callee, options) {
|
|
|
1375
1375
|
exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
1376
1376
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1377
1377
|
if (options?.isRestricted)
|
|
1378
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1378
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1379
1379
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
1380
1380
|
// console.log('callee', callee);
|
|
1381
1381
|
return new utils_1.naslTypes.CallLogic({
|
|
@@ -1389,7 +1389,7 @@ function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
|
1389
1389
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1390
1390
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1391
1391
|
if (options?.isRestricted)
|
|
1392
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1392
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1393
1393
|
if (calleeName?.includes('.entities.')) {
|
|
1394
1394
|
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
1395
1395
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
@@ -1467,7 +1467,7 @@ function transformCall2OQLQuery(node, calleeName, callee, options) {
|
|
|
1467
1467
|
}
|
|
1468
1468
|
function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
1469
1469
|
if (options?.isRestricted)
|
|
1470
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1470
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1471
1471
|
return new utils_1.naslTypes.CallLogic({
|
|
1472
1472
|
calleeNamespace: 'nasl.logging',
|
|
1473
1473
|
calleeName: 'INFO',
|
|
@@ -1480,7 +1480,7 @@ function transformCall2ConsoleLog(node, calleeName, callee, options) {
|
|
|
1480
1480
|
exports.transformCall2ConsoleLog = transformCall2ConsoleLog;
|
|
1481
1481
|
function transformCall2Logging(node, calleeName, callee, options) {
|
|
1482
1482
|
if (options?.isRestricted)
|
|
1483
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1483
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1484
1484
|
const newArguments = node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
1485
1485
|
expression: arg?.name === "undefined" ?
|
|
1486
1486
|
new utils_1.naslTypes.StringLiteral()
|
|
@@ -1516,6 +1516,28 @@ function transformCall2JSONFunctions(node, calleeName, callee, options) {
|
|
|
1516
1516
|
});
|
|
1517
1517
|
}
|
|
1518
1518
|
exports.transformCall2JSONFunctions = transformCall2JSONFunctions;
|
|
1519
|
+
function transform2CallEventLogic(node, calleeName, callee, options) {
|
|
1520
|
+
const lastName = callee[callee.length - 1].name;
|
|
1521
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1522
|
+
calleeNamespace: 'nasl.event',
|
|
1523
|
+
calleeName: lastName,
|
|
1524
|
+
shortcut: true,
|
|
1525
|
+
arguments: [],
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
exports.transform2CallEventLogic = transform2CallEventLogic;
|
|
1529
|
+
function transform2CallOtherNASLLogic(node, calleeName, callee, options) {
|
|
1530
|
+
const arr = calleeName.split('.');
|
|
1531
|
+
const lastName = arr.pop();
|
|
1532
|
+
return new utils_1.naslTypes.CallLogic({
|
|
1533
|
+
calleeNamespace: arr.join('.'),
|
|
1534
|
+
calleeName: lastName,
|
|
1535
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
1536
|
+
expression: fixExpression(arg, options),
|
|
1537
|
+
})),
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
exports.transform2CallOtherNASLLogic = transform2CallOtherNASLLogic;
|
|
1519
1541
|
function transform2CallFunction(node, calleeName, argument, options) {
|
|
1520
1542
|
calleeName = utils_1.replaceCallFunctionMap?.[calleeName] || calleeName;
|
|
1521
1543
|
const func = server_1.default ? server_1.default.getBuildInFunction(calleeName) : null;
|
|
@@ -1563,7 +1585,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1563
1585
|
const content = np?.toNaturalTS();
|
|
1564
1586
|
const noContent = np?.toNaturalTS()?.includes('__IDENTIFIER__');
|
|
1565
1587
|
if (!np && !p?.defaultExpression) {
|
|
1566
|
-
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}
|
|
1588
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用`, content);
|
|
1567
1589
|
}
|
|
1568
1590
|
if (np && calleeName === 'ListDistinctBy') {
|
|
1569
1591
|
if (idx === 1) {
|
|
@@ -1596,7 +1618,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1596
1618
|
});
|
|
1597
1619
|
}
|
|
1598
1620
|
else {
|
|
1599
|
-
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}不存在`, node.callee);
|
|
1621
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}不存在`, node.callee, node);
|
|
1600
1622
|
}
|
|
1601
1623
|
if (!func.params?.length) {
|
|
1602
1624
|
const needDefaultParam = ['CurrDate', 'CurrTime', 'CurrDateTime'];
|
|
@@ -1618,7 +1640,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1618
1640
|
// 这两个参数比较特殊,可以无限加参数,不再判断参数数量
|
|
1619
1641
|
const excludes = ['HasValue', 'ListSort'];
|
|
1620
1642
|
if (func.params?.length !== newArguments?.length && !excludes.includes(calleeName)) {
|
|
1621
|
-
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}
|
|
1643
|
+
return (0, utils_1.throwError)(options?.parsingId, `函数${calleeName}生成不符合标准的函数调用,参数数量不匹配`, node.callee, node);
|
|
1622
1644
|
}
|
|
1623
1645
|
else {
|
|
1624
1646
|
newArguments?.forEach((arg, idx) => {
|
|
@@ -1646,7 +1668,7 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1646
1668
|
exports.transform2CallFunction = transform2CallFunction;
|
|
1647
1669
|
function transform2SqlFunction(node, calleeName, argument, options) {
|
|
1648
1670
|
if (options.inCallQueryComponentField && !['WHERE', 'HAVING', 'ORDER_BY'].includes(options.inCallQueryComponentField)) {
|
|
1649
|
-
return (0, utils_1.throwError)(options?.parsingId, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}
|
|
1671
|
+
return (0, utils_1.throwError)(options?.parsingId, `数据查询中只有 WHERE, HAVING, ORDER_BY 支持 SQL 函数,而当前字段为 ${options.inCallQueryComponentField}`, node.callee, node);
|
|
1650
1672
|
}
|
|
1651
1673
|
const specFunList = ['COUNT', 'COUNTD', 'SUM', 'AVG', 'MAX', 'MIN'];
|
|
1652
1674
|
// TODO: 先写死了 mysql,后续需要传入: 参考 requestSqlFunctions
|
|
@@ -1747,7 +1769,7 @@ function transform2UIFunction(node, calleeName, callee, options) {
|
|
|
1747
1769
|
});
|
|
1748
1770
|
}
|
|
1749
1771
|
if (options?.isRestricted)
|
|
1750
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1772
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1751
1773
|
return new utils_1.naslTypes.CallLogic({
|
|
1752
1774
|
calleeNamespace: 'nasl.ui',
|
|
1753
1775
|
calleeName: callee[2].name,
|
|
@@ -1815,8 +1837,8 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1815
1837
|
let endNode;
|
|
1816
1838
|
if (node?.right?.type === 'CallExpression') {
|
|
1817
1839
|
const rightNode = node?.right;
|
|
1818
|
-
const calleeName =
|
|
1819
|
-
const hasListEntries =
|
|
1840
|
+
const calleeName = (0, utils_1.generate)(rightNode.callee).code;
|
|
1841
|
+
const hasListEntries = ['ListEntries', 'nasl.util.ListEntries'].includes(calleeName);
|
|
1820
1842
|
const areaArguments = rightNode?.arguments;
|
|
1821
1843
|
eachNode = hasListEntries ? areaArguments?.[0] : rightNode;
|
|
1822
1844
|
startNode = hasListEntries ? areaArguments?.[1] : undefined;
|
|
@@ -1868,7 +1890,7 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1868
1890
|
exports.transformForEach2ForEachStatement = transformForEach2ForEachStatement;
|
|
1869
1891
|
function transformAlert2ShowMessage(node, calleeName, callee, options) {
|
|
1870
1892
|
if (options?.isRestricted)
|
|
1871
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1893
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1872
1894
|
return new utils_1.naslTypes.CallLogic({
|
|
1873
1895
|
calleeNamespace: 'nasl.ui',
|
|
1874
1896
|
calleeName: 'showMessage',
|
|
@@ -1947,7 +1969,7 @@ function transformTSAsExpression(node, options) {
|
|
|
1947
1969
|
else if (node.expression.type === 'ArrayExpression') {
|
|
1948
1970
|
const typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(node.typeAnnotation, options) || undefined;
|
|
1949
1971
|
if (typeAnnotation.typeName !== 'List' && typeAnnotation.typeNamespace !== 'nasl.collection')
|
|
1950
|
-
return (0, utils_1.throwError)(options?.parsingId, `列表 as 必须为 List
|
|
1972
|
+
return (0, utils_1.throwError)(options?.parsingId, `列表 as 必须为 List 类型`, node);
|
|
1951
1973
|
return transformArrayExpression(node.expression, { ...options, typeAnnotation });
|
|
1952
1974
|
}
|
|
1953
1975
|
else if (node.expression.type === 'NullLiteral') {
|
|
@@ -1971,7 +1993,7 @@ function transformCall2CallViewLogic(node, calleeName, callee, options) {
|
|
|
1971
1993
|
exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
1972
1994
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
1973
1995
|
if (options?.isRestricted)
|
|
1974
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
1996
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1975
1997
|
if (utils_1.callFunctionMap.includes(calleeName)) {
|
|
1976
1998
|
// 未带前缀,补一下
|
|
1977
1999
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
@@ -1997,7 +2019,7 @@ function transformCall2Logic(node, calleeName, callee, options) {
|
|
|
1997
2019
|
exports.transformCall2Logic = transformCall2Logic;
|
|
1998
2020
|
function transformCall2LogicWithAuth(node, calleeName, callee, options) {
|
|
1999
2021
|
if (options?.isRestricted)
|
|
2000
|
-
return (0, utils_1.throwError)(options?.parsingId, '
|
|
2022
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
2001
2023
|
return new utils_1.naslTypes.CallLogic({
|
|
2002
2024
|
calleeNamespace: `nasl.auth`,
|
|
2003
2025
|
calleeName: callee[callee.length - 1].name,
|
|
@@ -2022,10 +2044,10 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2022
2044
|
const calleeName = node.callee.name;
|
|
2023
2045
|
if (['FROM', 'INNER_JOIN', 'LEFT_JOIN', 'RIGHT_JOIN', 'OUTER_JOIN'].includes(calleeName)) {
|
|
2024
2046
|
if (node.arguments[1].type !== 'ArrowFunctionExpression')
|
|
2025
|
-
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1]);
|
|
2047
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a ArrowFunctionExpression as the second argument', node.arguments[1], node);
|
|
2026
2048
|
const arrowFunctionExpression = node.arguments[1];
|
|
2027
2049
|
if (arrowFunctionExpression.body.type !== 'CallExpression')
|
|
2028
|
-
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body);
|
|
2050
|
+
return (0, utils_1.throwError)(options?.parsingId, 'FROM should have a CallExpression as the body of ArrowFunctionExpression', arrowFunctionExpression.body, node);
|
|
2029
2051
|
const body = arrowFunctionExpression.body;
|
|
2030
2052
|
const callExpressions = flatChainCallExpression(body);
|
|
2031
2053
|
const joinNode = callExpressions?.filter((item) => item?.callee?.name.includes('_JOIN'));
|
|
@@ -2035,13 +2057,13 @@ function flatCallQueryComponentChainNode(node, options) {
|
|
|
2035
2057
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id)).SELECT(...)); // 错误用法, ${name}的回调函数必须是完整的QueryChain
|
|
2036
2058
|
FROM(T1Entity, T1 => ${name}(T2Entity, T2 => ON(T1.id == T2.id).SELECT(...))); // 正确用法, 后续查询都在${name}的回调函数中进行
|
|
2037
2059
|
`;
|
|
2038
|
-
return (0, utils_1.throwError)(options?.parsingId, error);
|
|
2060
|
+
return (0, utils_1.throwError)(options?.parsingId, error, node);
|
|
2039
2061
|
}
|
|
2040
2062
|
const joinCode = (0, utils_1.generate)(joinNode[0])?.code || '';
|
|
2041
2063
|
const count = joinCode.match(/_JOIN/g)?.length || 0;
|
|
2042
2064
|
const errorOrder = count >= 1 && !callExpressions?.[callExpressions?.length - 1]?.callee?.name?.includes('_JOIN');
|
|
2043
2065
|
if (errorOrder) {
|
|
2044
|
-
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。');
|
|
2066
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
2045
2067
|
}
|
|
2046
2068
|
const result = [{
|
|
2047
2069
|
calleeName: calleeName,
|
|
@@ -2091,7 +2113,7 @@ function transformMemberExpression2Entity(node, node2, options) {
|
|
|
2091
2113
|
const entityNamespace = entityPath.slice(0, -1).map(n => n.name).join('.');
|
|
2092
2114
|
const entityName = entityPath[entityPath.length - 1].name.replace(/Entity$/, '');
|
|
2093
2115
|
if (!entityNamespace?.includes('.entities')) {
|
|
2094
|
-
return (0, utils_1.throwError)(options?.parsingId, `${entityNamespace}.${entityName}
|
|
2116
|
+
return (0, utils_1.throwError)(options?.parsingId, `${entityNamespace}.${entityName} 不是一个数据库表,无法使用数据查询`, node);
|
|
2095
2117
|
}
|
|
2096
2118
|
const asName = node2.name === entityName ? undefined : node2.name;
|
|
2097
2119
|
if (asName) {
|
|
@@ -2116,7 +2138,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2116
2138
|
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2117
2139
|
const isOrderCorrect = (0, utils_1.checkOQLCalleeNameOrder)(calleeNames);
|
|
2118
2140
|
if (!isOrderCorrect) {
|
|
2119
|
-
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。');
|
|
2141
|
+
return (0, utils_1.throwError)(options?.parsingId, '调用顺序错误,期望的调用顺序为 FROM -> JOIN -> WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY。其中,FROM在最外层,FROM内部是零到多层JOIN嵌套调用,在最内层的JOIN内部是 WHERE -> GROUP_BY -> SELECT/AGGR_SELECT -> HAVING -> ORDER_BY 的调用顺序。', node);
|
|
2120
2142
|
}
|
|
2121
2143
|
let from;
|
|
2122
2144
|
let where;
|
|
@@ -2135,7 +2157,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2135
2157
|
case 'FROM':
|
|
2136
2158
|
entity = transformMemberExpression2Entity(item.arguments[0], item.arguments[1], options);
|
|
2137
2159
|
if (!entity)
|
|
2138
|
-
|
|
2160
|
+
return;
|
|
2139
2161
|
const entityName = entity.asName || entity.entityName;
|
|
2140
2162
|
entityAsNames.push(entityName);
|
|
2141
2163
|
from = new utils_1.naslTypes.QueryFromExpression({
|
|
@@ -2154,6 +2176,8 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2154
2176
|
const rawJoinType = item.calleeName.slice(0, -5);
|
|
2155
2177
|
const joinType = rawJoinType === 'OUTER' ? 'FULL' : rawJoinType;
|
|
2156
2178
|
const onExpressions = flatOnExpressions(item.arguments[2]);
|
|
2179
|
+
if (!from)
|
|
2180
|
+
return; // throwError(options?.parsingId, 'FROM 不存在或异常,无法添加 JOIN 子句', node);
|
|
2157
2181
|
from.addJoinPart(new utils_1.naslTypes.QueryJoinExpression({
|
|
2158
2182
|
...entity,
|
|
2159
2183
|
joinType,
|
|
@@ -2170,14 +2194,14 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2170
2194
|
break;
|
|
2171
2195
|
case 'AGGR_SELECT':
|
|
2172
2196
|
if (groupBy?.length) {
|
|
2173
|
-
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT');
|
|
2197
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,应使用 SELECT 进行查询,但实际为 AGGR_SELECT', node);
|
|
2174
2198
|
}
|
|
2175
2199
|
select = new utils_1.naslTypes.QuerySelectExpression({
|
|
2176
2200
|
distinct: false,
|
|
2177
2201
|
star: true,
|
|
2178
2202
|
selectElements: [new utils_1.naslTypes.QueryFieldExpression({
|
|
2179
2203
|
isDotStar: true,
|
|
2180
|
-
entityAsName: from
|
|
2204
|
+
entityAsName: from?.entityName,
|
|
2181
2205
|
propertyName: '',
|
|
2182
2206
|
})],
|
|
2183
2207
|
});
|
|
@@ -2221,7 +2245,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2221
2245
|
star: true,
|
|
2222
2246
|
selectElements: groupBy?.length ? [new utils_1.naslTypes.QueryFieldExpression({
|
|
2223
2247
|
isDotStar: true,
|
|
2224
|
-
entityAsName: from
|
|
2248
|
+
entityAsName: from?.entityName,
|
|
2225
2249
|
propertyName: '',
|
|
2226
2250
|
})] : [],
|
|
2227
2251
|
});
|
|
@@ -2232,17 +2256,17 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2232
2256
|
}
|
|
2233
2257
|
else if (arg.value.type === 'ObjectExpression') {
|
|
2234
2258
|
if (groupBy?.length) {
|
|
2235
|
-
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列');
|
|
2259
|
+
return (0, utils_1.throwError)(options?.parsingId, '存在 GROUP_BY,SELECT应为单层结构,不应使用双层局部列', node);
|
|
2236
2260
|
}
|
|
2237
2261
|
const originName = arg.key?.name || '';
|
|
2238
2262
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2239
2263
|
const needName = (0, utils_2.firstLowerCase)(originName);
|
|
2240
|
-
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}
|
|
2264
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2241
2265
|
}
|
|
2242
2266
|
const entityName = (0, utils_2.firstUpperCase)(originName);
|
|
2243
2267
|
const needNameList = entityAsNames.map(item => (0, utils_2.firstLowerCase)(item))?.join('或');
|
|
2244
2268
|
if (!entityAsNames.includes(entityName)) {
|
|
2245
|
-
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}
|
|
2269
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2246
2270
|
}
|
|
2247
2271
|
selectElements = arg.value.properties?.map((property) => {
|
|
2248
2272
|
const columnAsName = property.key?.name;
|
|
@@ -2250,7 +2274,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2250
2274
|
const selectElement = transform2SelectQueryFieldExpression(property, { ...options, entityAsNames, inCallQueryComponentField: item.calleeName });
|
|
2251
2275
|
if (columnAsName !== columnPropertyName) {
|
|
2252
2276
|
// eg: comment: Topic_Comment.comment_stu
|
|
2253
|
-
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}
|
|
2277
|
+
return (0, utils_1.throwError)(options?.parsingId, `SELECT 局部列第二层命名不符合规范, 应为${columnPropertyName}, 但实际为${columnAsName}`, node);
|
|
2254
2278
|
}
|
|
2255
2279
|
selectElement.isDotStar = false;
|
|
2256
2280
|
return selectElement;
|
|
@@ -2285,7 +2309,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2285
2309
|
}
|
|
2286
2310
|
}
|
|
2287
2311
|
else {
|
|
2288
|
-
return (0, utils_1.throwError)(options?.parsingId, 'HAVING 不符合规范,请使用箭头函数', havingNode);
|
|
2312
|
+
return (0, utils_1.throwError)(options?.parsingId, 'HAVING 不符合规范,请使用箭头函数', havingNode, node);
|
|
2289
2313
|
}
|
|
2290
2314
|
having = transformNodeFunction(havingNode, { ...options, ...restParams });
|
|
2291
2315
|
break;
|
|
@@ -2294,13 +2318,16 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2294
2318
|
let restOptionParams = { entityAsNames };
|
|
2295
2319
|
if (orderNode?.length === 1 && orderNode?.[0]?.type === 'ArrowFunctionExpression') {
|
|
2296
2320
|
const params = orderNode?.[0]?.params;
|
|
2321
|
+
if (orderNode?.[0]?.body?.type !== 'ArrayExpression') {
|
|
2322
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数,并返回数组', orderNode, node);
|
|
2323
|
+
}
|
|
2297
2324
|
orderNode = orderNode?.[0]?.body?.elements;
|
|
2298
2325
|
if (params?.length && params?.[0]?.name) {
|
|
2299
2326
|
restOptionParams = { inOqlIdentifierNamespace: params?.[0]?.name, entityAsNames };
|
|
2300
2327
|
}
|
|
2301
2328
|
}
|
|
2302
2329
|
else {
|
|
2303
|
-
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY
|
|
2330
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ORDER_BY 不符合规范,请使用箭头函数,并返回数组', orderNode, node);
|
|
2304
2331
|
}
|
|
2305
2332
|
orderBy = orderNode.map((arg) => {
|
|
2306
2333
|
let orderElementCode = (0, utils_1.generate)(arg)?.code || '';
|
|
@@ -2326,19 +2353,19 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2326
2353
|
ideVersion: '2.22',
|
|
2327
2354
|
});
|
|
2328
2355
|
if (hasErrorTSScopeColumn && !groupBy?.length && !having) {
|
|
2329
|
-
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 局部列不符合规范,需要按两层对象返回');
|
|
2356
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 局部列不符合规范,需要按两层对象返回', node);
|
|
2330
2357
|
}
|
|
2331
2358
|
const hasScopeColumn = select?.selectElements?.find((selectElement) => selectElement?.concept === 'QueryFieldExpression' && !selectElement?.isDotStar);
|
|
2332
2359
|
if (hasScopeColumn && (groupBy?.length || having)) {
|
|
2333
|
-
return (0, utils_1.throwError)(options?.parsingId, '分组聚合与表字段局部列不允许同时出现');
|
|
2360
|
+
return (0, utils_1.throwError)(options?.parsingId, '分组聚合与表字段局部列不允许同时出现', node);
|
|
2334
2361
|
}
|
|
2335
2362
|
if (hasScopeColumn && useResultItem) {
|
|
2336
|
-
return (0, utils_1.throwError)(options?.parsingId, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])");
|
|
2363
|
+
return (0, utils_1.throwError)(options?.parsingId, "对于局部列的排序,只支持 实体.属性名 的格式,例如 ORDER_BY((resultItem) => [[Student.age, 'ASC']])", node);
|
|
2337
2364
|
}
|
|
2338
2365
|
const isOnlyAggr = select?.selectElements?.find((selectElement) => selectElement?.concept !== 'QueryAggregateExpression');
|
|
2339
2366
|
// 如果 select 中只有聚合属性时,并且没有用 AGGR_SELECT 来指定列
|
|
2340
2367
|
if (!isOnlyAggr && !calleeNames?.includes('AGGR_SELECT')) {
|
|
2341
|
-
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 不符合规范,请使用 AGGR_SELECT');
|
|
2368
|
+
return (0, utils_1.throwError)(options?.parsingId, 'SELECT 不符合规范,请使用 AGGR_SELECT', node);
|
|
2342
2369
|
}
|
|
2343
2370
|
// callQueryComponent.typeAnnotation = callQueryComponent.computeStructure();
|
|
2344
2371
|
return callQueryComponent;
|
|
@@ -2432,10 +2459,12 @@ function transform2LogicItem(node, options) {
|
|
|
2432
2459
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.logging.'), transformCall2Logging);
|
|
2433
2460
|
transformManager.registerCallExpression('nasl.util.jsonSerialize', transformCall2JSONFunctions);
|
|
2434
2461
|
transformManager.registerCallExpression('nasl.util.jsonDeserialize', transformCall2JSONFunctions);
|
|
2462
|
+
transformManager.registerCallExpression((node, calleeName) => (calleeName.startsWith('nasl.event.') || calleeName.startsWith('event.')) && (calleeName.endsWith('.preventDefault') || calleeName.endsWith('.stopPropagation')), transform2CallEventLogic);
|
|
2435
2463
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.forEach'), transformForEach2ForEachStatement);
|
|
2436
2464
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.util.'), transformCall2CallFunction);
|
|
2437
2465
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.auth.'), transformCall2LogicWithAuth);
|
|
2438
2466
|
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.ui.'), transform2UIFunction);
|
|
2467
|
+
transformManager.registerCallExpression((node, calleeName) => calleeName.startsWith('nasl.browser.'), transform2CallOtherNASLLogic);
|
|
2439
2468
|
transformManager.registerCallExpression((node, calleeName) => calleeName.endsWith('.map'), transformMap2ListTransform);
|
|
2440
2469
|
transformManager.registerCallExpression('ForEach', transform2ForEachStatement);
|
|
2441
2470
|
transformManager.registerCallExpression('alert', transformAlert2ShowMessage);
|