@lcap/nasl 4.4.0-beta.3 → 4.4.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/generator/genBundleFiles.d.ts +2 -0
- package/out/generator/genBundleFiles.d.ts.map +1 -1
- package/out/generator/genBundleFiles.js +77 -12
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/icestark.d.ts +1 -1
- package/out/generator/icestark.d.ts.map +1 -1
- package/out/generator/icestark.js +6 -1
- package/out/generator/icestark.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 +9 -3
- package/out/generator/qiankun.js.map +1 -1
- package/out/generator/release-body/body.d.ts +0 -1
- package/out/generator/release-body/body.d.ts.map +1 -1
- package/out/generator/release-body/body.js +1 -390
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/data.d.ts.map +1 -1
- package/out/generator/release-body/data.js +38 -11
- package/out/generator/release-body/data.js.map +1 -1
- package/out/generator/release-body/internal.d.ts +1 -0
- package/out/generator/release-body/internal.d.ts.map +1 -1
- package/out/generator/release-body/internal.js.map +1 -1
- package/out/generator/release-body/share-content.js +1 -1
- package/out/generator/release-body/share-content.js.map +1 -1
- package/out/generator/release-body/types.d.ts +2 -0
- package/out/generator/release-body/types.d.ts.map +1 -1
- package/out/generator/release-body/utils.d.ts +1 -0
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +2 -1
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/generator/templates/chunk.js +1 -1
- package/out/generator/templates/runtime.js +2 -2
- package/out/generator/wujie.d.ts +1 -1
- package/out/generator/wujie.d.ts.map +1 -1
- package/out/generator/wujie.js +6 -1
- package/out/generator/wujie.js.map +1 -1
- package/out/natural/exports/nasl2Files.d.ts +34 -0
- package/out/natural/exports/nasl2Files.d.ts.map +1 -0
- package/out/natural/exports/nasl2Files.js +237 -0
- package/out/natural/exports/nasl2Files.js.map +1 -0
- package/out/natural/{transform2BatchActions.d.ts → exports/transform2BatchActions.d.ts} +20 -2
- package/out/natural/exports/transform2BatchActions.d.ts.map +1 -0
- package/out/natural/exports/transform2BatchActions.js +1233 -0
- package/out/natural/exports/transform2BatchActions.js.map +1 -0
- package/out/natural/index.d.ts +12 -12
- package/out/natural/index.d.ts.map +1 -1
- package/out/natural/index.js +12 -14
- package/out/natural/index.js.map +1 -1
- package/out/natural/{genNaturalTS.d.ts → old/getContext/genNaturalTS.d.ts} +12 -12
- package/out/natural/old/getContext/genNaturalTS.d.ts.map +1 -0
- package/out/natural/{genNaturalTS.js → old/getContext/genNaturalTS.js} +65 -65
- package/out/natural/old/getContext/genNaturalTS.js.map +1 -0
- package/out/natural/old/getContext/genTextualNASL.d.ts.map +1 -0
- package/out/natural/old/getContext/genTextualNASL.js.map +1 -0
- package/out/natural/{getContext → old/getContext}/getUILib.d.ts +1 -1
- package/out/natural/old/getContext/getUILib.d.ts.map +1 -0
- package/out/natural/{getContext → old/getContext}/getUILib.js +14 -14
- package/out/natural/old/getContext/getUILib.js.map +1 -0
- package/out/natural/{getContext → old/getContext}/index.d.ts +3 -3
- package/out/natural/old/getContext/index.d.ts.map +1 -0
- package/out/natural/{getContext → old/getContext}/index.js +4 -4
- package/out/natural/old/getContext/index.js.map +1 -0
- package/out/natural/old/getContext/naslStdlibMap.d.ts.map +1 -0
- package/out/natural/{getContext → old/getContext}/naslStdlibMap.js +10 -10
- package/out/natural/old/getContext/naslStdlibMap.js.map +1 -0
- package/out/natural/{transformTS2UI.d.ts → old/parser/transformTS2UI.d.ts} +2 -2
- package/out/natural/old/parser/transformTS2UI.d.ts.map +1 -0
- package/out/natural/{transformTS2UI.js → old/parser/transformTS2UI.js} +13 -14
- package/out/natural/old/parser/transformTS2UI.js.map +1 -0
- package/out/natural/{transformTSCode.d.ts → old/parser/transformTSCode.d.ts} +1 -1
- package/out/natural/old/parser/transformTSCode.d.ts.map +1 -0
- package/out/natural/{transformTSCode.js → old/parser/transformTSCode.js} +32 -8
- package/out/natural/old/parser/transformTSCode.js.map +1 -0
- package/out/natural/{tools.d.ts → old/tools.d.ts} +0 -4
- package/out/natural/old/tools.d.ts.map +1 -0
- package/out/natural/{tools.js → old/tools.js} +7 -25
- package/out/natural/old/tools.js.map +1 -0
- package/out/natural/{parseNaturalTS.d.ts → parser/parseNaturalTS.d.ts} +9 -2
- package/out/natural/parser/parseNaturalTS.d.ts.map +1 -0
- package/out/natural/{parseNaturalTS.js → parser/parseNaturalTS.js} +119 -38
- package/out/natural/parser/parseNaturalTS.js.map +1 -0
- package/out/natural/{parseNaturalTSXView.d.ts → parser/parseNaturalTSXView.d.ts} +1 -2
- package/out/natural/parser/parseNaturalTSXView.d.ts.map +1 -0
- package/out/natural/{parseNaturalTSXView.js → parser/parseNaturalTSXView.js} +181 -139
- package/out/natural/parser/parseNaturalTSXView.js.map +1 -0
- package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.d.ts +7 -0
- package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.d.ts.map +1 -0
- package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.js +38 -0
- package/out/natural/transforms/checker/checkDataQueryCalleeNameOrder.js.map +1 -0
- package/out/natural/transforms/checker/checkDefaultValue.d.ts +14 -0
- package/out/natural/transforms/checker/checkDefaultValue.d.ts.map +1 -0
- package/out/natural/transforms/checker/checkDefaultValue.js +39 -0
- package/out/natural/transforms/checker/checkDefaultValue.js.map +1 -0
- package/out/natural/transforms/checker/checkLcapEntity.d.ts +16 -0
- package/out/natural/transforms/checker/checkLcapEntity.d.ts.map +1 -0
- package/out/natural/transforms/checker/checkLcapEntity.js +337 -0
- package/out/natural/transforms/checker/checkLcapEntity.js.map +1 -0
- package/out/natural/transforms/checker/checkValidationCalleeName.d.ts +3 -0
- package/out/natural/transforms/checker/checkValidationCalleeName.d.ts.map +1 -0
- package/out/natural/transforms/checker/checkValidationCalleeName.js +88 -0
- package/out/natural/transforms/checker/checkValidationCalleeName.js.map +1 -0
- package/out/natural/transforms/checker/checkViewElement.d.ts +29 -0
- package/out/natural/transforms/checker/checkViewElement.d.ts.map +1 -0
- package/out/natural/transforms/checker/checkViewElement.js +618 -0
- package/out/natural/transforms/checker/checkViewElement.js.map +1 -0
- package/out/natural/transforms/checker/index.d.ts +19 -0
- package/out/natural/transforms/checker/index.d.ts.map +1 -0
- package/out/natural/transforms/checker/index.js +30 -0
- package/out/natural/transforms/checker/index.js.map +1 -0
- package/out/natural/transforms/transform2Entity.d.ts +13 -1
- package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
- package/out/natural/transforms/transform2Entity.js +172 -17
- package/out/natural/transforms/transform2Entity.js.map +1 -1
- package/out/natural/transforms/transform2Enum.d.ts +1 -1
- package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
- package/out/natural/transforms/transform2Enum.js +5 -1
- 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 +18 -4
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
- package/out/natural/transforms/transform2Logic.d.ts +4 -4
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +58 -17
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +11 -4
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +279 -178
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -1
- package/out/natural/transforms/transform2MetadataType.js +1 -1
- package/out/natural/transforms/transform2MetadataType.js.map +1 -1
- package/out/natural/transforms/transform2Param.d.ts +4 -0
- package/out/natural/transforms/transform2Param.d.ts.map +1 -0
- package/out/natural/transforms/transform2Param.js +114 -0
- package/out/natural/transforms/transform2Param.js.map +1 -0
- package/out/natural/transforms/transform2Structure.d.ts +1 -1
- package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
- package/out/natural/transforms/transform2Structure.js +13 -2
- package/out/natural/transforms/transform2Structure.js.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.js +3 -3
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts +2 -2
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.js +6 -1
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -1
- package/out/natural/transforms/transform2Variable.d.ts +4 -3
- package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
- package/out/natural/transforms/transform2Variable.js +57 -6
- package/out/natural/transforms/transform2Variable.js.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.d.ts +5 -2
- package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.js +26 -13
- package/out/natural/transforms/transformThemeAndStyle.js.map +1 -1
- package/out/natural/transforms/utils/createComponentLookupMap.d.ts +32 -0
- package/out/natural/transforms/utils/createComponentLookupMap.d.ts.map +1 -0
- package/out/natural/transforms/utils/createComponentLookupMap.js +57 -0
- package/out/natural/transforms/utils/createComponentLookupMap.js.map +1 -0
- package/out/natural/transforms/utils/iconNames.d.ts +2 -0
- package/out/natural/transforms/utils/iconNames.d.ts.map +1 -0
- package/out/natural/transforms/utils/iconNames.js +299 -0
- package/out/natural/transforms/utils/iconNames.js.map +1 -0
- package/out/natural/transforms/utils/misc.d.ts +16 -0
- package/out/natural/transforms/utils/misc.d.ts.map +1 -0
- package/out/natural/transforms/utils/misc.js +240 -0
- package/out/natural/transforms/utils/misc.js.map +1 -0
- package/out/natural/transforms/utils/normalizeNode.d.ts +3 -0
- package/out/natural/transforms/utils/normalizeNode.d.ts.map +1 -0
- package/out/natural/transforms/utils/normalizeNode.js +15 -0
- package/out/natural/transforms/utils/normalizeNode.js.map +1 -0
- package/out/natural/transforms/utils/parseDecorator.d.ts +74 -0
- package/out/natural/transforms/utils/parseDecorator.d.ts.map +1 -0
- package/out/natural/transforms/utils/parseDecorator.js +252 -0
- package/out/natural/transforms/utils/parseDecorator.js.map +1 -0
- package/out/natural/transforms/utils/transform2Directory.d.ts +59 -0
- package/out/natural/transforms/utils/transform2Directory.d.ts.map +1 -0
- package/out/natural/transforms/utils/transform2Directory.js +229 -0
- package/out/natural/transforms/utils/transform2Directory.js.map +1 -0
- package/out/natural/{transforms/utils.d.ts → utils/index.d.ts} +35 -18
- package/out/natural/utils/index.d.ts.map +1 -0
- package/out/natural/utils/index.js +206 -0
- package/out/natural/utils/index.js.map +1 -0
- package/out/natural/utils/nasl-file-types.d.ts +45 -0
- package/out/natural/utils/nasl-file-types.d.ts.map +1 -0
- package/out/natural/utils/nasl-file-types.js +131 -0
- package/out/natural/utils/nasl-file-types.js.map +1 -0
- package/out/server/OQL/sqlDbTypes.json +717 -0
- package/out/server/createUiTs.d.ts +0 -1
- package/out/server/createUiTs.d.ts.map +1 -1
- package/out/server/createUiTs.js +1 -118
- package/out/server/createUiTs.js.map +1 -1
- package/out/server/extendBaseNode.d.ts.map +1 -1
- package/out/server/extendBaseNode.js +17 -0
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/findReference.js +1 -1
- package/out/server/findReference.js.map +1 -1
- package/out/server/naslServer.d.ts +0 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +66 -55
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js.map +1 -1
- package/out/service/autofix/rules/rule-convert-incompatible-assignment-to-union.js.map +1 -1
- package/out/service/creator/add.configs.js +1 -1
- package/out/service/creator/add.configs.js.map +1 -1
- package/out/service/storage/init.d.ts +1 -1
- package/out/service/storage/init.d.ts.map +1 -1
- package/out/service/storage/init.js +26 -9
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/specTools.d.ts +20 -8
- package/out/service/storage/specTools.d.ts.map +1 -1
- package/out/service/storage/specTools.js +157 -5
- package/out/service/storage/specTools.js.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +4 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +20 -1
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +28 -1
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -1
- package/out/templator/block2nasl/transformBlock2Nasl.js +2 -2
- package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -1
- package/out/templator/block2nasl/viewMergeBlock.js +3 -2
- package/out/templator/block2nasl/viewMergeBlock.js.map +1 -1
- package/out/utils/can-i-use.d.ts.map +1 -1
- package/out/utils/can-i-use.js +1 -0
- package/out/utils/can-i-use.js.map +1 -1
- package/package.json +9 -9
- package/sandbox/stdlib/nasl.core.ts +2 -0
- package/sandbox/stdlib/nasl.io.ts +1 -1
- package/sandbox/stdlib/nasl.oql.ts +2 -0
- package/sandbox/stdlib/nasl.util.ts +1 -1
- package/sandbox/stdlib/nasl.validation.ts +50 -14
- package/out/natural/genNaturalTS.d.ts.map +0 -1
- package/out/natural/genNaturalTS.js.map +0 -1
- package/out/natural/genTextualNASL.d.ts.map +0 -1
- package/out/natural/genTextualNASL.js.map +0 -1
- package/out/natural/getContext/getUILib.d.ts.map +0 -1
- package/out/natural/getContext/getUILib.js.map +0 -1
- package/out/natural/getContext/index.d.ts.map +0 -1
- package/out/natural/getContext/index.js.map +0 -1
- package/out/natural/getContext/nasl2Files.d.ts +0 -15
- package/out/natural/getContext/nasl2Files.d.ts.map +0 -1
- package/out/natural/getContext/nasl2Files.js +0 -75
- package/out/natural/getContext/nasl2Files.js.map +0 -1
- package/out/natural/getContext/naslStdlibMap.d.ts.map +0 -1
- package/out/natural/getContext/naslStdlibMap.js.map +0 -1
- package/out/natural/parseNaturalTS.d.ts.map +0 -1
- package/out/natural/parseNaturalTS.js.map +0 -1
- package/out/natural/parseNaturalTSXView.d.ts.map +0 -1
- package/out/natural/parseNaturalTSXView.js.map +0 -1
- package/out/natural/tools.d.ts.map +0 -1
- package/out/natural/tools.js.map +0 -1
- package/out/natural/transform2BatchActions.d.ts.map +0 -1
- package/out/natural/transform2BatchActions.js +0 -387
- package/out/natural/transform2BatchActions.js.map +0 -1
- package/out/natural/transformTS2UI.d.ts.map +0 -1
- package/out/natural/transformTS2UI.js.map +0 -1
- package/out/natural/transformTSCode.d.ts.map +0 -1
- package/out/natural/transformTSCode.js.map +0 -1
- package/out/natural/transforms/utils.d.ts.map +0 -1
- package/out/natural/transforms/utils.js +0 -407
- package/out/natural/transforms/utils.js.map +0 -1
- /package/out/natural/{genTextualNASL.d.ts → old/getContext/genTextualNASL.d.ts} +0 -0
- /package/out/natural/{genTextualNASL.js → old/getContext/genTextualNASL.js} +0 -0
- /package/out/natural/{getContext → old/getContext}/naslStdlibMap.d.ts +0 -0
|
@@ -3,12 +3,15 @@ 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.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.
|
|
7
|
-
exports.transform2LogicItem = exports.transformNode2Directory = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = exports.transformCall2Extension = exports.transformCall2Connector =
|
|
8
|
-
const utils_1 = require("
|
|
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.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.fixLogicNode = exports.flatIfStatementForMatch = exports.flatMatchPatternsExpression = exports.getSelectMembers = exports.unflatMemberExpression = exports.flatMemberExpression = exports.fixExpression = exports.TransformManager = void 0;
|
|
7
|
+
exports.transform2LogicItem = exports.transform2DefaultValue = exports.transformNode2Directory = exports.transformCall2Paginate = exports.transformCall2LogicWithAuth = exports.transformCall2Logic = exports.transformCall2CallViewLogic = exports.transformCall2Extension = exports.transformCall2Connector = void 0;
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const misc_1 = require("./utils/misc");
|
|
10
|
+
const checkDataQueryCalleeNameOrder_1 = require("./checker/checkDataQueryCalleeNameOrder");
|
|
9
11
|
const transform2TypeAnnotation_1 = require("./transform2TypeAnnotation");
|
|
10
|
-
const
|
|
12
|
+
const transform2Param_1 = require("./transform2Param");
|
|
11
13
|
const server_1 = __importDefault(require("../../server"));
|
|
14
|
+
const parseDecorator_1 = require("./utils/parseDecorator");
|
|
12
15
|
;
|
|
13
16
|
class TransformManager {
|
|
14
17
|
constructor() {
|
|
@@ -63,7 +66,7 @@ exports.TransformManager = TransformManager;
|
|
|
63
66
|
function transformTSCode2SubLogic(node, options) {
|
|
64
67
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
65
68
|
const logic = new utils_1.naslTypes.SubLogic();
|
|
66
|
-
logic.name = options.transformType === 'logic' && options.logic?.getSubLogicUniqueName ? options.logic.getSubLogicUniqueName() : `subLogic_${(0,
|
|
69
|
+
logic.name = options.transformType === 'logic' && options.logic?.getSubLogicUniqueName ? options.logic.getSubLogicUniqueName() : `subLogic_${(0, utils_1.uuidv4)().slice(0, 2)}`;
|
|
67
70
|
logic.body = logic.body.slice(0, 1);
|
|
68
71
|
let parameters = [];
|
|
69
72
|
let statements = [];
|
|
@@ -77,7 +80,7 @@ function transformTSCode2SubLogic(node, options) {
|
|
|
77
80
|
statements = [...node?.body?.directives, ...node?.body?.body];
|
|
78
81
|
}
|
|
79
82
|
parameters.forEach((node) => {
|
|
80
|
-
const param = transform2Param(node, options);
|
|
83
|
+
const param = (0, transform2Param_1.transform2Param)(node, options);
|
|
81
84
|
if (param && !param?.typeAnnotation) {
|
|
82
85
|
param.typeAnnotation = null;
|
|
83
86
|
}
|
|
@@ -129,6 +132,15 @@ function assertAssignmentRightIsNotAnonymousFunction(expression, options) {
|
|
|
129
132
|
return (0, utils_1.throwError)(options, 'Anonymous function is not allowed in assignment');
|
|
130
133
|
return expression;
|
|
131
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* 处理赋值表达式右侧的判定逻辑
|
|
137
|
+
*/
|
|
138
|
+
function validateAssignmentRightExpression(right, options, node) {
|
|
139
|
+
if (right?.concept === 'CallLogic' && right.calleeName === 'delete' && right.calleeNamespace?.includes('app.dataSources')) {
|
|
140
|
+
return (0, utils_1.throwError)(options, 'delete 函数返回值为空,请移除赋值语句和相关判定操作。可默认 delete 函数执行成功,无需考虑失败情况处理。', node);
|
|
141
|
+
}
|
|
142
|
+
return right;
|
|
143
|
+
}
|
|
132
144
|
function fixExpression(arg, options, supportSubLogic = false) {
|
|
133
145
|
let expression;
|
|
134
146
|
if (options.transformType === 'logic' && supportSubLogic &&
|
|
@@ -146,11 +158,18 @@ function fixExpression(arg, options, supportSubLogic = false) {
|
|
|
146
158
|
if (arg?.body?.type === 'ReturnStatement') {
|
|
147
159
|
arg.body = arg?.body?.argument;
|
|
148
160
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
161
|
+
// app.logics.logic5("123", undefined);
|
|
162
|
+
// 这种情况 undefined 是一个参数,所以需要特殊处理
|
|
163
|
+
if (arg.type === 'Identifier' && arg.name === 'undefined') {
|
|
152
164
|
expression = undefined;
|
|
153
165
|
}
|
|
166
|
+
else {
|
|
167
|
+
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
168
|
+
expression = transformNodeFunction(arg, options);
|
|
169
|
+
if (expression?.concept === 'Identifier' && expression?.name === 'undefined') {
|
|
170
|
+
expression = undefined;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
154
173
|
}
|
|
155
174
|
return expression;
|
|
156
175
|
}
|
|
@@ -246,9 +265,12 @@ function flatMatchPatternsExpression(node) {
|
|
|
246
265
|
}
|
|
247
266
|
exports.flatMatchPatternsExpression = flatMatchPatternsExpression;
|
|
248
267
|
function flatIfStatementForMatch(node) {
|
|
249
|
-
if (node
|
|
268
|
+
if (node?.alternate?.type === 'IfStatement') {
|
|
250
269
|
return [node, ...flatIfStatementForMatch(node.alternate)];
|
|
251
270
|
}
|
|
271
|
+
if (node.test === null || !node.alternate) {
|
|
272
|
+
return [node];
|
|
273
|
+
}
|
|
252
274
|
return [node, {
|
|
253
275
|
type: 'IfStatement',
|
|
254
276
|
test: null,
|
|
@@ -272,79 +294,6 @@ function fixLogicNode(node) {
|
|
|
272
294
|
}
|
|
273
295
|
}
|
|
274
296
|
exports.fixLogicNode = fixLogicNode;
|
|
275
|
-
function transform2Param(node, options) {
|
|
276
|
-
const exclude = ['event'];
|
|
277
|
-
if (node.type === 'ObjectProperty') {
|
|
278
|
-
const typeAnnotation = node?.value?.name ? utils_1.naslTypes.TypeAnnotation.createPrimitive((node?.value).name) : null;
|
|
279
|
-
const name = node.key.name;
|
|
280
|
-
if (exclude.includes(name))
|
|
281
|
-
return null;
|
|
282
|
-
let defaultValueExpression = node.key.optional ? { type: 'NullLiteral' } : undefined;
|
|
283
|
-
return new utils_1.naslTypes.Param({
|
|
284
|
-
name,
|
|
285
|
-
typeAnnotation,
|
|
286
|
-
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
287
|
-
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
288
|
-
}),
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
else if (node.type === 'TSPropertySignature') {
|
|
292
|
-
const typeAnnotation = node.typeAnnotation?.typeAnnotation;
|
|
293
|
-
const name = node.key.name;
|
|
294
|
-
if (exclude.includes(name))
|
|
295
|
-
return null;
|
|
296
|
-
let defaultValueExpression = node.optional ? { type: 'NullLiteral' } : undefined;
|
|
297
|
-
return new utils_1.naslTypes.Param({
|
|
298
|
-
name,
|
|
299
|
-
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
300
|
-
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
301
|
-
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
302
|
-
}),
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
else if (node.type === 'Identifier') {
|
|
306
|
-
const typeAnnotation = node.typeAnnotation?.typeAnnotation;
|
|
307
|
-
const name = node.name;
|
|
308
|
-
if (exclude.includes(name))
|
|
309
|
-
return null;
|
|
310
|
-
let defaultValueExpression = node.optional ? { type: 'NullLiteral' } : undefined;
|
|
311
|
-
return new utils_1.naslTypes.Param({
|
|
312
|
-
name,
|
|
313
|
-
required: !node.optional,
|
|
314
|
-
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
315
|
-
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
316
|
-
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
317
|
-
}),
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
else if (node.type === 'AssignmentPattern') {
|
|
321
|
-
const identifier = node.left;
|
|
322
|
-
const typeAnnotation = identifier.typeAnnotation?.typeAnnotation;
|
|
323
|
-
let defaultValueExpression;
|
|
324
|
-
if (node.type === 'AssignmentPattern') {
|
|
325
|
-
if (node.right)
|
|
326
|
-
defaultValueExpression = node.right;
|
|
327
|
-
else if (identifier.optional) {
|
|
328
|
-
defaultValueExpression = { type: 'NullLiteral' };
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const exclude = ['event'];
|
|
332
|
-
const name = identifier.name;
|
|
333
|
-
if (exclude.includes(name))
|
|
334
|
-
return null;
|
|
335
|
-
return new utils_1.naslTypes.Param({
|
|
336
|
-
name,
|
|
337
|
-
typeAnnotation: typeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation, options) || undefined,
|
|
338
|
-
defaultValue: defaultValueExpression && new utils_1.naslTypes.DefaultValue({
|
|
339
|
-
expression: transform2LogicItem(defaultValueExpression, { ...options, transformType: 'attr', isRestricted: true }),
|
|
340
|
-
}),
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
return (0, utils_1.throwError)(options, '在输入参数中不支持节点类型', node);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
exports.transform2Param = transform2Param;
|
|
348
297
|
function transformCallExpressionToBinaryExpression(node, calleeName, callee, options) {
|
|
349
298
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
350
299
|
const argument = node?.arguments;
|
|
@@ -360,10 +309,11 @@ function transformCallExpressionToBinaryExpression(node, calleeName, callee, opt
|
|
|
360
309
|
IN: 'in',
|
|
361
310
|
IS_NULL: 'isNull',
|
|
362
311
|
};
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
312
|
+
// 4.4版本支持使用: https://projectmanage.netease-official.lcap.163yun.com/dashboard/FeatureDetail?id=2903738850213120
|
|
313
|
+
// const limitMap = ['STARTS_WITH', 'ENDS_WITH', 'LIKE', 'IN', 'IS_NULL'];
|
|
314
|
+
// if (limitMap.includes(calleeName) && options.transformType === 'logic' && !options.inCallQueryComponentField) {
|
|
315
|
+
// return throwError(options, `${calleeName} 仅支持在数据查询中使用`, node);
|
|
316
|
+
// }
|
|
367
317
|
if (calleeName === 'IS_NULL') {
|
|
368
318
|
return new utils_1.naslTypes.UnaryExpression({
|
|
369
319
|
operator: 'isNull',
|
|
@@ -403,6 +353,13 @@ function collectExpressions(node, operator, expressions, options) {
|
|
|
403
353
|
}
|
|
404
354
|
}
|
|
405
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* 检查节点是否为 null 或 undefined
|
|
358
|
+
*/
|
|
359
|
+
function isNullOrUndefined(node) {
|
|
360
|
+
return (node?.type === 'NullLiteral' ||
|
|
361
|
+
(node?.type === 'Identifier' && node.name === 'undefined'));
|
|
362
|
+
}
|
|
406
363
|
function transform2VariadicExpression(node, options) {
|
|
407
364
|
// 创建一个新的 VariadicExpression
|
|
408
365
|
const result = {
|
|
@@ -421,13 +378,13 @@ function transform2BinaryExpression(node, options) {
|
|
|
421
378
|
node.operator = '==';
|
|
422
379
|
if (node.operator === '!==')
|
|
423
380
|
node.operator = '!=';
|
|
424
|
-
if (node.operator === '==' && node.right
|
|
381
|
+
if (node.operator === '==' && isNullOrUndefined(node.right) && options?.inCallQueryComponentField) {
|
|
425
382
|
return new utils_1.naslTypes.UnaryExpression({
|
|
426
383
|
operator: 'isNull',
|
|
427
384
|
argument: transformNodeFunction(node.left, options),
|
|
428
385
|
});
|
|
429
386
|
}
|
|
430
|
-
if (node.operator === '!=' && node.right
|
|
387
|
+
if (node.operator === '!=' && isNullOrUndefined(node.right) && options?.inCallQueryComponentField) {
|
|
431
388
|
return new utils_1.naslTypes.UnaryExpression({
|
|
432
389
|
operator: '!',
|
|
433
390
|
argument: new utils_1.naslTypes.UnaryExpression({
|
|
@@ -464,36 +421,13 @@ function transformConditionalExpression(node, options) {
|
|
|
464
421
|
const else_expr = (0, utils_1.generate)(node.alternate)?.code;
|
|
465
422
|
return (0, utils_1.throwError)(options, `数据查询中不支持条件表达式!${(0, utils_1.generate)(node)?.code}, 请使用 SQL函数 IF(${expr} == null, ${then_expr}, ${else_expr})`);
|
|
466
423
|
}
|
|
467
|
-
const
|
|
424
|
+
const condition = transformNodeFunction(node.test, options);
|
|
468
425
|
const consequent = transformNodeFunction(node.consequent, options);
|
|
469
426
|
const alternate = transformNodeFunction(node.alternate, options);
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
calleeNamespace: 'nasl.util',
|
|
475
|
-
calleeName: 'Convert',
|
|
476
|
-
arguments: [
|
|
477
|
-
new utils_1.naslTypes.Argument({
|
|
478
|
-
expression: test,
|
|
479
|
-
}),
|
|
480
|
-
],
|
|
481
|
-
typeArguments: [utils_1.naslTypes.TypeAnnotation.createPrimitive('Boolean')],
|
|
482
|
-
});
|
|
483
|
-
return new utils_1.naslTypes.Match({
|
|
484
|
-
expression,
|
|
485
|
-
isExpression: true,
|
|
486
|
-
cases: [
|
|
487
|
-
new utils_1.naslTypes.MatchCase({
|
|
488
|
-
patterns: [new utils_1.naslTypes.BooleanLiteral({ value: 'true' })],
|
|
489
|
-
body: consequent ? [consequent] : [],
|
|
490
|
-
isMatchedTypeEnumable: true,
|
|
491
|
-
}),
|
|
492
|
-
new utils_1.naslTypes.MatchCase({
|
|
493
|
-
patterns: [],
|
|
494
|
-
body: alternate ? [alternate] : [],
|
|
495
|
-
}),
|
|
496
|
-
],
|
|
427
|
+
return new utils_1.naslTypes.IfExpression({
|
|
428
|
+
condition,
|
|
429
|
+
consequent,
|
|
430
|
+
alternate
|
|
497
431
|
});
|
|
498
432
|
}
|
|
499
433
|
function transformArrayExpression(node, options) {
|
|
@@ -637,7 +571,7 @@ function transform2ArrayPattern(decl, options) {
|
|
|
637
571
|
}
|
|
638
572
|
else {
|
|
639
573
|
getVariableNode = new utils_1.naslTypes.Identifier({
|
|
640
|
-
name: `temp_${(0,
|
|
574
|
+
name: `temp_${(0, utils_1.uuidv4)().slice(0, 4)}`,
|
|
641
575
|
});
|
|
642
576
|
logicItems.push(new utils_1.naslTypes.Assignment({
|
|
643
577
|
left: getVariableNode,
|
|
@@ -704,10 +638,22 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
704
638
|
if (options.transformType === 'logic' && ![...options.logic.variables, ...options.logic.returns].some((variable) => variable.name === variableName)) {
|
|
705
639
|
const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
|
|
706
640
|
typeAnnotation = varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation, options) || undefined;
|
|
707
|
-
|
|
641
|
+
const variable = new utils_1.naslTypes.Variable({
|
|
708
642
|
name: variableName,
|
|
709
643
|
typeAnnotation,
|
|
710
|
-
})
|
|
644
|
+
});
|
|
645
|
+
// 处理 $Variable 装饰器
|
|
646
|
+
if (options.decorator && options.decorator.arguments[0]?.type === 'ObjectExpression') {
|
|
647
|
+
const variableMetadata = (0, parseDecorator_1.pickDecoratorObject)(options.decorator.arguments[0], parseDecorator_1.VARIABLE_DECORATOR.allowedKeys, parseDecorator_1.VARIABLE_DECORATOR.mappings || {}, options);
|
|
648
|
+
if (variableMetadata.description) {
|
|
649
|
+
variable.description = variableMetadata.description;
|
|
650
|
+
}
|
|
651
|
+
// autoInferType: true 时跳过类型注解(依赖 TS 推断)
|
|
652
|
+
if (variableMetadata.autoInferType === true) {
|
|
653
|
+
delete variable.typeAnnotation;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
options.logic.variables.push(variable);
|
|
711
657
|
}
|
|
712
658
|
if (decl.init) {
|
|
713
659
|
const calleeName = (0, utils_1.generate)(decl?.init?.callee).code;
|
|
@@ -717,9 +663,11 @@ function transform2VariableAndAddAssignment(node, options) {
|
|
|
717
663
|
decl.init.typeAnnotations = varTypeAnnotation;
|
|
718
664
|
}
|
|
719
665
|
options.typeAnnotation = typeAnnotation;
|
|
666
|
+
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(decl.init, { ...options, typeAnnotation }), options) || undefined;
|
|
667
|
+
validateAssignmentRightExpression(right, options, node);
|
|
720
668
|
newNode = new utils_1.naslTypes.Assignment({
|
|
721
669
|
left: transformNodeFunction(decl.id, options),
|
|
722
|
-
right
|
|
670
|
+
right
|
|
723
671
|
});
|
|
724
672
|
}
|
|
725
673
|
});
|
|
@@ -851,13 +799,13 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
851
799
|
let expression = node.value;
|
|
852
800
|
let asNameNode = node.key;
|
|
853
801
|
if (expression.type === 'Identifier') {
|
|
854
|
-
const isSameName = (0,
|
|
802
|
+
const isSameName = (0, utils_1.firstUpperCase)(asNameNode.name) === expression.name;
|
|
855
803
|
if (!isSameName) {
|
|
856
|
-
return (0, utils_1.throwError)(options, `字段名需为 ${(0,
|
|
804
|
+
return (0, utils_1.throwError)(options, `字段名需为 ${(0, utils_1.firstLowerCase)(expression.name)}, 目前为: ${asNameNode.name}, 相关代码如下`, node);
|
|
857
805
|
}
|
|
858
806
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
859
807
|
isDotStar: true,
|
|
860
|
-
asName: (0,
|
|
808
|
+
asName: (0, utils_1.firstUpperCase)(asNameNode.name) === expression.name ? undefined : asNameNode.name,
|
|
861
809
|
entityAsName: expression.name,
|
|
862
810
|
propertyName: '',
|
|
863
811
|
});
|
|
@@ -865,7 +813,7 @@ function transform2SelectQueryFieldExpression(node, options) {
|
|
|
865
813
|
else if (expression.type === 'MemberExpression') {
|
|
866
814
|
return new utils_1.naslTypes.QueryFieldExpression({
|
|
867
815
|
isDotStar: false,
|
|
868
|
-
asName: (0,
|
|
816
|
+
asName: (0, utils_1.firstUpperCase)(asNameNode.name) === expression.property.name ? undefined : asNameNode.name,
|
|
869
817
|
entityAsName: expression.object.name,
|
|
870
818
|
propertyName: expression.property.name,
|
|
871
819
|
});
|
|
@@ -899,7 +847,7 @@ function transform2AnonymousFunction(node, options) {
|
|
|
899
847
|
return (0, utils_1.throwError)(options, 'Anonymous function with block statement is not supported', node);
|
|
900
848
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
901
849
|
return new utils_1.naslTypes.AnonymousFunction({
|
|
902
|
-
params: node.params.map((param) => transform2Param(param, options)).filter(Boolean),
|
|
850
|
+
params: node.params.map((param) => (0, transform2Param_1.transform2Param)(param, options)).filter(Boolean),
|
|
903
851
|
body: transformNodeFunction(node.body, options),
|
|
904
852
|
});
|
|
905
853
|
}
|
|
@@ -926,9 +874,11 @@ function transform2Assignment(node, options) {
|
|
|
926
874
|
if (options.transformType !== 'logic') {
|
|
927
875
|
return transformNodeFunction(node.right, options);
|
|
928
876
|
}
|
|
877
|
+
const right = assertAssignmentRightIsNotAnonymousFunction(transformNodeFunction(node.right, options), options) || undefined;
|
|
878
|
+
validateAssignmentRightExpression(right, options, node);
|
|
929
879
|
return new utils_1.naslTypes.Assignment({
|
|
930
880
|
left: transformNodeFunction(node.left, options),
|
|
931
|
-
right
|
|
881
|
+
right
|
|
932
882
|
});
|
|
933
883
|
}
|
|
934
884
|
exports.transform2Assignment = transform2Assignment;
|
|
@@ -1034,6 +984,22 @@ function transform2StringInterpolation(node, options) {
|
|
|
1034
984
|
end: element.end,
|
|
1035
985
|
}))];
|
|
1036
986
|
expressions.sort((a, b) => a.start - b.start);
|
|
987
|
+
// 在数据查询组件字段中,将模板字符串转换为 SQL CONCAT 函数
|
|
988
|
+
if (options?.inCallQueryComponentField) {
|
|
989
|
+
const transformedExpressions = expressions
|
|
990
|
+
// 过滤掉空字符串
|
|
991
|
+
.filter((item) => !(item.type === 'StringLiteral' && item.value === ''))
|
|
992
|
+
.map((item) => transformNodeFunction(item, options))
|
|
993
|
+
.filter(Boolean);
|
|
994
|
+
return new utils_1.naslTypes.CallFunction({
|
|
995
|
+
calleeNamespace: 'nasl.sqlFunction',
|
|
996
|
+
calleeName: 'CONCAT',
|
|
997
|
+
arguments: transformedExpressions.map((expr, index) => new utils_1.naslTypes.Argument({
|
|
998
|
+
expression: expr,
|
|
999
|
+
keyword: `param${index + 1}`,
|
|
1000
|
+
})),
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1037
1003
|
return new utils_1.naslTypes.StringInterpolation({
|
|
1038
1004
|
expressions: expressions.map((item) => transformNodeFunction(item, options))?.filter(Boolean),
|
|
1039
1005
|
});
|
|
@@ -1056,7 +1022,11 @@ function transform2Comment(node, options) {
|
|
|
1056
1022
|
exports.transform2Comment = transform2Comment;
|
|
1057
1023
|
function transformBlockStatement(node, options) {
|
|
1058
1024
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
1059
|
-
|
|
1025
|
+
const statements = node.body;
|
|
1026
|
+
return new utils_1.naslTypes.Block({
|
|
1027
|
+
folded: false,
|
|
1028
|
+
logicItems: statements.map((item) => transformNodeFunction(item, options))?.filter(Boolean),
|
|
1029
|
+
});
|
|
1060
1030
|
}
|
|
1061
1031
|
function transform2PartialNewComposite(node, options) {
|
|
1062
1032
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
@@ -1160,7 +1130,6 @@ function transform2NewRegex(node, options) {
|
|
|
1160
1130
|
flags = node.arguments[1] ? transformNodeFunction(node.arguments[1], options) : undefined;
|
|
1161
1131
|
}
|
|
1162
1132
|
return new utils_1.naslTypes.NewRegex({
|
|
1163
|
-
kind: "dynamic",
|
|
1164
1133
|
pattern,
|
|
1165
1134
|
flags
|
|
1166
1135
|
});
|
|
@@ -1247,6 +1216,14 @@ function transformMemberExpression(node, options) {
|
|
|
1247
1216
|
const regex = /^(app\..+?)\.variables\.(.+)$/;
|
|
1248
1217
|
if (regex.test(calleeName)) {
|
|
1249
1218
|
const [, namespace, variableName] = calleeName.match(regex);
|
|
1219
|
+
const isBackendVariable = calleeName.includes('app.backend.variables');
|
|
1220
|
+
const isLogic = options.transformType === 'logic';
|
|
1221
|
+
if (isLogic && options.logicType === 'global_logic' && !isBackendVariable) {
|
|
1222
|
+
return (0, utils_1.throwError)(options, '服务端逻辑不支持使用前端全局变量', node);
|
|
1223
|
+
}
|
|
1224
|
+
if (isLogic && options.logicType !== 'global_logic' && isBackendVariable) {
|
|
1225
|
+
return (0, utils_1.throwError)(options, '前端逻辑不支持使用服务端全局变量', node);
|
|
1226
|
+
}
|
|
1250
1227
|
const variableNameList = variableName.split('.');
|
|
1251
1228
|
if (variableNameList?.length === 1) {
|
|
1252
1229
|
return new utils_1.naslTypes.Identifier({
|
|
@@ -1256,13 +1233,17 @@ function transformMemberExpression(node, options) {
|
|
|
1256
1233
|
}
|
|
1257
1234
|
else {
|
|
1258
1235
|
// 前后端全局变量
|
|
1259
|
-
const number =
|
|
1236
|
+
const number = isBackendVariable ? 3 : 6;
|
|
1260
1237
|
const newCallee = callee.slice(number);
|
|
1261
1238
|
const newNode = unflatMemberExpression(newCallee, options, null, `${namespace}.variables`);
|
|
1262
1239
|
return newNode;
|
|
1263
1240
|
}
|
|
1264
1241
|
}
|
|
1265
1242
|
if (calleeName?.startsWith('nasl.auth.')) {
|
|
1243
|
+
const isLogic = options.transformType === 'logic';
|
|
1244
|
+
if (isLogic && options.logicType === 'global_logic') {
|
|
1245
|
+
return (0, utils_1.throwError)(options, '服务端逻辑不支持使用 nasl.auth 公共变量', node);
|
|
1246
|
+
}
|
|
1266
1247
|
const variableNameList = calleeName.split('.');
|
|
1267
1248
|
if (variableNameList?.length === 3) {
|
|
1268
1249
|
return new utils_1.naslTypes.Identifier({
|
|
@@ -1314,35 +1295,77 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1314
1295
|
return (0, utils_1.throwError)(options, 'Match 函数体内必须是一个 if 语句', ifStatement);
|
|
1315
1296
|
}
|
|
1316
1297
|
const flatedIfStatements = flatIfStatementForMatch(ifStatement);
|
|
1298
|
+
let isExpression = options.transformType !== 'logic';
|
|
1317
1299
|
const match = new utils_1.naslTypes.Match({
|
|
1318
1300
|
expression: transformNodeFunction(arg, options),
|
|
1319
|
-
isExpression
|
|
1320
|
-
cases: flatedIfStatements.map((_case) => {
|
|
1301
|
+
isExpression,
|
|
1302
|
+
cases: flatedIfStatements.map((_case, index) => {
|
|
1321
1303
|
let argument;
|
|
1322
1304
|
if (_case.consequent.type === 'BlockStatement') {
|
|
1323
1305
|
if (_case.consequent.body.length === 1 && _case.consequent.body[0].type === 'ReturnStatement') {
|
|
1324
1306
|
argument = _case.consequent.body[0].argument;
|
|
1307
|
+
// 有一个 Return, match 就按 expression 处理
|
|
1308
|
+
isExpression = true;
|
|
1325
1309
|
}
|
|
1326
1310
|
else {
|
|
1327
|
-
|
|
1311
|
+
const isLastCase = index === flatedIfStatements.length - 1;
|
|
1312
|
+
let allowEmptyBody = false;
|
|
1313
|
+
if (isExpression) {
|
|
1314
|
+
if (isLastCase) {
|
|
1315
|
+
// 检查前面所有case的test属性,对布尔或者枚举类型特殊处理
|
|
1316
|
+
allowEmptyBody = flatedIfStatements
|
|
1317
|
+
.slice(0, index)
|
|
1318
|
+
.every((prevCase) => {
|
|
1319
|
+
if (!prevCase.test || prevCase.test.type !== 'BinaryExpression')
|
|
1320
|
+
return false;
|
|
1321
|
+
const testNode = prevCase.test;
|
|
1322
|
+
const right = testNode.right;
|
|
1323
|
+
// 检查right是否为BooleanLiteral
|
|
1324
|
+
if (right?.type === 'BooleanLiteral')
|
|
1325
|
+
return true;
|
|
1326
|
+
// 检查right是否为MemberExpression且包含app.enums
|
|
1327
|
+
if (right?.type === 'MemberExpression') {
|
|
1328
|
+
const rightCode = (0, utils_1.generate)(right).code;
|
|
1329
|
+
return rightCode.includes('app.enums');
|
|
1330
|
+
}
|
|
1331
|
+
return false;
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
if (!allowEmptyBody) {
|
|
1335
|
+
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
else {
|
|
1339
|
+
allowEmptyBody = true;
|
|
1340
|
+
}
|
|
1328
1341
|
}
|
|
1329
1342
|
}
|
|
1330
1343
|
else {
|
|
1331
1344
|
if (_case.consequent.type === 'ReturnStatement') {
|
|
1332
1345
|
argument = _case.consequent.argument;
|
|
1346
|
+
isExpression = true;
|
|
1333
1347
|
}
|
|
1334
1348
|
else {
|
|
1335
1349
|
return (0, utils_1.throwError)(options, 'Match Case 的 if 中只能写一个 return 语句', _case.consequent);
|
|
1336
1350
|
}
|
|
1337
1351
|
}
|
|
1338
|
-
|
|
1352
|
+
let bodyNode = argument ? transformNodeFunction(argument, options) : undefined;
|
|
1353
|
+
let body = [];
|
|
1354
|
+
if (bodyNode) {
|
|
1355
|
+
body = [bodyNode];
|
|
1356
|
+
}
|
|
1357
|
+
if (!isExpression && _case.consequent.type === 'BlockStatement') {
|
|
1358
|
+
body = transformBlockBody(_case.consequent.body.filter((item) => item.type !== 'BreakStatement'), options);
|
|
1359
|
+
}
|
|
1339
1360
|
return new utils_1.naslTypes.MatchCase({
|
|
1340
1361
|
isMatchedTypeEnumable: false,
|
|
1341
1362
|
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNodeFunction(_case.test, options)),
|
|
1342
|
-
body
|
|
1363
|
+
body,
|
|
1343
1364
|
});
|
|
1344
1365
|
}).filter(Boolean),
|
|
1345
1366
|
});
|
|
1367
|
+
// 根据 toNaturalTS,有Return语句的默认为 expression
|
|
1368
|
+
match.isExpression = isExpression;
|
|
1346
1369
|
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
1347
1370
|
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
1348
1371
|
isMatchedTypeEnumable: false,
|
|
@@ -1352,7 +1375,7 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1352
1375
|
}
|
|
1353
1376
|
match.cases.forEach((case_) => {
|
|
1354
1377
|
if (case_.patterns.length) {
|
|
1355
|
-
if (case_.patterns[0].concept === 'BooleanLiteral'
|
|
1378
|
+
if (case_.patterns[0].concept === 'BooleanLiteral') {
|
|
1356
1379
|
case_.isMatchedTypeEnumable = true;
|
|
1357
1380
|
}
|
|
1358
1381
|
if (case_.patterns[0].concept === 'MemberExpression') {
|
|
@@ -1360,13 +1383,13 @@ function transformCallFunctionExpression2Match(node, calleeName, callee, options
|
|
|
1360
1383
|
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
1361
1384
|
object: {
|
|
1362
1385
|
concept: 'Identifier',
|
|
1363
|
-
name: case_.patterns[0].object.
|
|
1386
|
+
name: case_.patterns[0].object.name,
|
|
1364
1387
|
folded: false,
|
|
1365
1388
|
namespace: 'app.enums'
|
|
1366
1389
|
},
|
|
1367
1390
|
property: {
|
|
1368
1391
|
concept: 'Identifier',
|
|
1369
|
-
name: case_.patterns[0].property.
|
|
1392
|
+
name: case_.patterns[0].property.name,
|
|
1370
1393
|
folded: false,
|
|
1371
1394
|
},
|
|
1372
1395
|
});
|
|
@@ -1415,23 +1438,30 @@ exports.transformCall2CallViewElementLogic = transformCall2CallViewElementLogic;
|
|
|
1415
1438
|
function transformCall2CallEntityLogic(node, calleeName, callee, options) {
|
|
1416
1439
|
if (options?.isRestricted)
|
|
1417
1440
|
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1418
|
-
|
|
1419
|
-
//
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
})
|
|
1441
|
+
return (0, utils_1.throwError)(options, '调用实体逻辑必须要有完整的命名空间,如:app.dataSources.defaultDS.entities.XxxEntity.{create,update,delete,batchCreate,...}(...)', node);
|
|
1442
|
+
// const entityName = (callee[0] as babelTypes.Identifier).name.replace(/Entity$/, '');
|
|
1443
|
+
// // console.log('callee', callee);
|
|
1444
|
+
// return new naslTypes.CallLogic({
|
|
1445
|
+
// calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
|
|
1446
|
+
// calleeName: (callee[1] as babelTypes.Identifier).name,
|
|
1447
|
+
// arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
1448
|
+
// expression: fixExpression(arg, options),
|
|
1449
|
+
// })) as naslTypes.Argument[],
|
|
1450
|
+
// });
|
|
1427
1451
|
}
|
|
1428
1452
|
exports.transformCall2CallEntityLogic = transformCall2CallEntityLogic;
|
|
1429
1453
|
function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
1430
1454
|
if (options?.isRestricted)
|
|
1431
1455
|
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
1432
|
-
if (calleeName
|
|
1433
|
-
const
|
|
1434
|
-
|
|
1456
|
+
if (calleeName.includes('.entities.')) {
|
|
1457
|
+
const obj = node.callee.object;
|
|
1458
|
+
if (obj.type !== 'MemberExpression')
|
|
1459
|
+
return (0, utils_1.throwError)(options, '调用实体逻辑的命名空间不正确。正确示例如:app.dataSources.defaultDS.entities.XxxEntity.{create,update,delete,batchCreate,...}(...)', node);
|
|
1460
|
+
const calleeNamespace = (0, utils_1.generate)(obj.object).code;
|
|
1461
|
+
let entityName = obj.property.name;
|
|
1462
|
+
if (!entityName.endsWith('Entity'))
|
|
1463
|
+
return (0, utils_1.throwError)(options, '调用实体逻辑的实体名必须要有 Entity 后缀。正确示例如:app.dataSources.defaultDS.entities.XxxEntity.{create,update,delete,batchCreate,...}(...)', node);
|
|
1464
|
+
entityName = entityName.replace(/Entity$/, '');
|
|
1435
1465
|
let newArguments = node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
1436
1466
|
expression: fixExpression(arg, options),
|
|
1437
1467
|
}));
|
|
@@ -1439,15 +1469,39 @@ function transformCall2CallDataSourceLogic(node, calleeName, callee, options) {
|
|
|
1439
1469
|
if (['update', 'batchUpdate']?.includes(newCalleeName)) {
|
|
1440
1470
|
if (newArguments?.[0])
|
|
1441
1471
|
newArguments[0].keyword = 'body';
|
|
1472
|
+
if (newArguments?.[1]) {
|
|
1473
|
+
if (newArguments[1]?.expression.concept === 'AnonymousFunction' && newArguments[1]?.expression?.params?.[0]?.name) {
|
|
1474
|
+
newArguments[1].expression.params[0].typeAnnotation = utils_1.naslTypes.TypeAnnotation.createReference(entityName, {
|
|
1475
|
+
typeNamespace: calleeNamespace,
|
|
1476
|
+
typeName: entityName
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1442
1480
|
}
|
|
1443
1481
|
if (['updateBy', 'deleteBy']?.includes(newCalleeName)) {
|
|
1444
|
-
const expression = newArguments?.[0]?.expression
|
|
1482
|
+
const expression = newArguments?.[0]?.expression;
|
|
1483
|
+
if (expression && expression.concept === 'AnonymousFunction') {
|
|
1484
|
+
const firstParam = expression.params?.[0];
|
|
1485
|
+
if (firstParam && firstParam.name !== '_') {
|
|
1486
|
+
return (0, utils_1.throwError)(options, `调用实体逻辑 ${newCalleeName} 的筛选函数参数名必须为 _`, node.arguments[0]);
|
|
1487
|
+
}
|
|
1488
|
+
let hasError = false;
|
|
1489
|
+
expression.traverseStrictChildren((child) => {
|
|
1490
|
+
if ((child.concept === 'CallFunction' || child.concept === 'CallLogic') && child.calleeNamespace?.startsWith('nasl.util')) {
|
|
1491
|
+
(0, utils_1.throwError)(options, `调用实体逻辑 ${newCalleeName} 的筛选条件不能使用内置函数`, node.arguments[0]);
|
|
1492
|
+
hasError = true;
|
|
1493
|
+
}
|
|
1494
|
+
});
|
|
1495
|
+
if (hasError)
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
const expressionJson = expression?.toJSON();
|
|
1445
1499
|
const argument2 = newArguments?.[1];
|
|
1446
1500
|
newArguments = [new utils_1.naslTypes.Argument({
|
|
1447
1501
|
expression: new utils_1.naslTypes.Function({
|
|
1448
1502
|
name: "filter",
|
|
1449
|
-
returnExpression:
|
|
1450
|
-
params:
|
|
1503
|
+
returnExpression: expressionJson?.body || undefined,
|
|
1504
|
+
params: expressionJson?.params || [
|
|
1451
1505
|
new utils_1.naslTypes.Param({
|
|
1452
1506
|
name: '_',
|
|
1453
1507
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(entityName, {
|
|
@@ -1578,7 +1632,7 @@ function transform2CallOtherNASLLogic(node, calleeName, callee, options) {
|
|
|
1578
1632
|
}
|
|
1579
1633
|
exports.transform2CallOtherNASLLogic = transform2CallOtherNASLLogic;
|
|
1580
1634
|
function transform2CallFunction(node, calleeName, argument, options) {
|
|
1581
|
-
calleeName =
|
|
1635
|
+
calleeName = misc_1.replaceCallFunctionMap?.[calleeName] || calleeName;
|
|
1582
1636
|
const func = server_1.default ? server_1.default.getBuildInFunction(calleeName) : null;
|
|
1583
1637
|
let newArguments = argument.map((arg, index) => {
|
|
1584
1638
|
let supportSubLogic = false;
|
|
@@ -1625,6 +1679,16 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1625
1679
|
new utils_1.naslTypes.TypeAnnotation()
|
|
1626
1680
|
];
|
|
1627
1681
|
}
|
|
1682
|
+
if (calleeName === 'FromString') {
|
|
1683
|
+
if (newTypeArguments?.[0]?.typeName === 'Time' && newArguments?.[0]?.expression?.concept === 'StringLiteral') {
|
|
1684
|
+
const timeValue = newArguments?.[0]?.expression?.value;
|
|
1685
|
+
// 验证时分秒格式:严格的 HH:mm:ss (两位数字)
|
|
1686
|
+
const timeRegex = /^([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/;
|
|
1687
|
+
if (timeValue && !timeRegex.test(timeValue)) {
|
|
1688
|
+
return (0, utils_1.throwError)(options, `FromString<Time> 的参数值 "${timeValue}" 不符合时分秒格式,必须为 HH:mm:ss 格式`, node);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1628
1692
|
if (func) {
|
|
1629
1693
|
const needTypeMap = [
|
|
1630
1694
|
'ListDistinctBy',
|
|
@@ -1671,6 +1735,14 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1671
1735
|
expression: utils_1.naslTypes.BaseNode.from(p.defaultExpression.toJSON()),
|
|
1672
1736
|
}));
|
|
1673
1737
|
}
|
|
1738
|
+
if (np && p?.defaultExpression?.concept === 'AnonymousFunction' && p?.name === 'by' && p?.parentKey === 'params') {
|
|
1739
|
+
// 特殊处理下,因为 Params 中有默认行为,需要占个位
|
|
1740
|
+
if (np.expression?.params) {
|
|
1741
|
+
np.expression.params.forEach((param) => {
|
|
1742
|
+
param.typeAnnotation = null;
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1674
1746
|
// 类型不匹配时,使用默认值
|
|
1675
1747
|
if (calleeName === "GetDateCount" && idx === func.params?.length - 1 && np?.expression?.concept !== 'StringLiteral') {
|
|
1676
1748
|
np &&
|
|
@@ -1713,13 +1785,16 @@ function transform2CallFunction(node, calleeName, argument, options) {
|
|
|
1713
1785
|
}
|
|
1714
1786
|
const nodeElement = new utils_1.naslTypes.CallFunction({
|
|
1715
1787
|
calleeNamespace: 'nasl.util',
|
|
1716
|
-
calleeName:
|
|
1788
|
+
calleeName: misc_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1717
1789
|
arguments: newArguments,
|
|
1718
1790
|
typeArguments: newTypeArguments
|
|
1719
1791
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
1720
1792
|
});
|
|
1721
1793
|
if (calleeName === 'ListSort') {
|
|
1722
|
-
const handledNode = (0,
|
|
1794
|
+
const handledNode = (0, misc_1.handleListSort)(nodeElement?.toJSON(), options);
|
|
1795
|
+
if (handledNode === null) {
|
|
1796
|
+
return (0, utils_1.throwError)(options, 'ListSort 函数使用错误,ListSort 定义如下:export function ListSort<T>(list: List<T>, ...fns: ((item: T) => { asc: Boolean, by: Boolean | Long | Decimal | String | Date | Time | DateTime; })[]): List<T>;', node);
|
|
1797
|
+
}
|
|
1723
1798
|
return handledNode && new utils_1.naslTypes.CallFunction(handledNode);
|
|
1724
1799
|
}
|
|
1725
1800
|
if (options.transformType === 'logic' && options?.inCallQueryComponentField) {
|
|
@@ -1751,7 +1826,7 @@ function transform2SqlFunction(node, calleeName, argument, options) {
|
|
|
1751
1826
|
}));
|
|
1752
1827
|
const nodeElement = new utils_1.naslTypes.CallFunction({
|
|
1753
1828
|
calleeNamespace: 'nasl.sqlFunction',
|
|
1754
|
-
calleeName:
|
|
1829
|
+
calleeName: misc_1.replaceCallFunctionMap?.[calleeName] || calleeName,
|
|
1755
1830
|
arguments: [...addArguments, ...newArguments],
|
|
1756
1831
|
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType }, options)).filter(Boolean),
|
|
1757
1832
|
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
@@ -1871,12 +1946,12 @@ function transform2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1871
1946
|
each: transformNodeFunction(newCallee[0], options),
|
|
1872
1947
|
start: transformNodeFunction(newCallee[1], options),
|
|
1873
1948
|
end: newCallee[2]?.name === '__IDENTIFIER__' ? undefined : transformNodeFunction(newCallee[2], options),
|
|
1874
|
-
item: arrowFunction?.params?.[0] ? transform2Param(arrowFunction.params[0], options) || undefined : new utils_1.naslTypes.Param({
|
|
1949
|
+
item: arrowFunction?.params?.[0] ? (0, transform2Param_1.transform2Param)(arrowFunction.params[0], options, true) || undefined : new utils_1.naslTypes.Param({
|
|
1875
1950
|
name: 'item',
|
|
1876
1951
|
typeAnnotation: undefined,
|
|
1877
1952
|
}),
|
|
1878
|
-
index: arrowFunction?.params?.[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1879
|
-
name: `index_${(0,
|
|
1953
|
+
index: arrowFunction?.params?.[1] ? (0, transform2Param_1.transform2Param)(arrowFunction.params[1], options, true) || undefined : new utils_1.naslTypes.Param({
|
|
1954
|
+
name: `index_${(0, utils_1.uuidv4)().slice(0, 4)}`,
|
|
1880
1955
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1881
1956
|
}),
|
|
1882
1957
|
body: transformBlockBody(body, options),
|
|
@@ -1919,12 +1994,12 @@ function transformForOf2ForEachStatement(node, options) {
|
|
|
1919
1994
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1920
1995
|
}),
|
|
1921
1996
|
end: endNode?.name === '__IDENTIFIER__' ? undefined : endNode ? transformNodeFunction(endNode, options) : undefined,
|
|
1922
|
-
item: itemNode ? transform2Param(itemNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1997
|
+
item: itemNode ? (0, transform2Param_1.transform2Param)(itemNode, options, true) || undefined : new utils_1.naslTypes.Param({
|
|
1923
1998
|
name: 'item',
|
|
1924
1999
|
typeAnnotation: undefined,
|
|
1925
2000
|
}),
|
|
1926
|
-
index: indexNode ? transform2Param(indexNode, options) || undefined : new utils_1.naslTypes.Param({
|
|
1927
|
-
name: `index_${(0,
|
|
2001
|
+
index: indexNode ? (0, transform2Param_1.transform2Param)(indexNode, options, true) || undefined : new utils_1.naslTypes.Param({
|
|
2002
|
+
name: `index_${(0, utils_1.uuidv4)().slice(0, 2)}`,
|
|
1928
2003
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1929
2004
|
}),
|
|
1930
2005
|
body: transformBlockBody(body, options),
|
|
@@ -1943,9 +2018,9 @@ function transformForEach2ForEachStatement(node, calleeName, callee, options) {
|
|
|
1943
2018
|
value: '0',
|
|
1944
2019
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1945
2020
|
}),
|
|
1946
|
-
item: transform2Param(arrowFunction.params[0], options) || undefined,
|
|
1947
|
-
index: arrowFunction.params[1] ? transform2Param(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
1948
|
-
name: `index_${(0,
|
|
2021
|
+
item: (0, transform2Param_1.transform2Param)(arrowFunction.params[0], options) || undefined,
|
|
2022
|
+
index: arrowFunction.params[1] ? (0, transform2Param_1.transform2Param)(arrowFunction.params[1], options) || undefined : new utils_1.naslTypes.Param({
|
|
2023
|
+
name: `index_${(0, utils_1.uuidv4)().slice(0, 2)}`,
|
|
1949
2024
|
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
1950
2025
|
}),
|
|
1951
2026
|
body: transformBlockBody(body, options),
|
|
@@ -1987,9 +2062,11 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
1987
2062
|
return (0, utils_1.throwError)(options, '调用连接器不支持在组件或默认值表达式中使用', node);
|
|
1988
2063
|
let calleeConnectionName = undefined;
|
|
1989
2064
|
let calleeNamespace = undefined;
|
|
1990
|
-
|
|
1991
|
-
|
|
2065
|
+
const connectorName = callee[1].name;
|
|
2066
|
+
let calleeNamespacePrefix = `connector.${connectorName}`;
|
|
2067
|
+
if (callee.length === 5) { // connectors.connectorName.connect(connectionName).logics.logicName()
|
|
1992
2068
|
const connectArg = callee[2].arguments[0];
|
|
2069
|
+
console.log('connectArg', connectArg);
|
|
1993
2070
|
if (!connectArg || connectArg.type !== 'StringLiteral') {
|
|
1994
2071
|
return (0, utils_1.throwError)(options, '调用 connector 的 connect 参数不正确,只允许使用字符串字面量', node);
|
|
1995
2072
|
}
|
|
@@ -2002,14 +2079,11 @@ function transformCall2Connector(node, calleeName, callee, options) {
|
|
|
2002
2079
|
calleeNamespace = `${calleeNamespacePrefix}.${callee[3].name}`;
|
|
2003
2080
|
}
|
|
2004
2081
|
}
|
|
2005
|
-
else if (callee.length === 4) {
|
|
2006
|
-
calleeNamespace = calleeNamespacePrefix;
|
|
2007
|
-
}
|
|
2008
2082
|
else {
|
|
2009
|
-
return (0, utils_1.throwError)(options, `调用 connector
|
|
2083
|
+
return (0, utils_1.throwError)(options, `调用 connector 写法不正确,你可能少写了 .logics, .structures 或 .connect(connectionName)`, node);
|
|
2010
2084
|
}
|
|
2011
2085
|
return new utils_1.naslTypes.CallConnector({
|
|
2012
|
-
calleeConnectionName
|
|
2086
|
+
calleeConnectionName: calleeConnectionName || `${connectorName}Conn`,
|
|
2013
2087
|
calleeNamespace,
|
|
2014
2088
|
calleeName: callee[callee.length - 1].name,
|
|
2015
2089
|
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
@@ -2062,7 +2136,7 @@ exports.transformCall2CallViewLogic = transformCall2CallViewLogic;
|
|
|
2062
2136
|
function transformCall2Logic(node, calleeName, callee, options) {
|
|
2063
2137
|
if (options?.isRestricted)
|
|
2064
2138
|
return (0, utils_1.throwError)(options, '调用逻辑不支持在组件或默认值表达式中使用,请尝试单独赋值', node);
|
|
2065
|
-
if (
|
|
2139
|
+
if (misc_1.callFunctionMap.includes(calleeName)) {
|
|
2066
2140
|
// 未带前缀,补一下
|
|
2067
2141
|
return transform2CallFunction(node, calleeName, node?.arguments || [], options);
|
|
2068
2142
|
}
|
|
@@ -2194,6 +2268,8 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2194
2268
|
return (0, utils_1.throwError)(options, '数据查询组件不支持在前端使用', node);
|
|
2195
2269
|
if (options?.isRestricted)
|
|
2196
2270
|
return (0, utils_1.throwError)(options, '数据查询组件不支持在组件或默认值表达式中使用', node);
|
|
2271
|
+
if (options?.inCallQueryComponentField)
|
|
2272
|
+
return (0, utils_1.throwError)(options, '数据查询组件不支持嵌套使用,请将内层数据查询提取为独立的逻辑变量,再在外层查询中引用', node);
|
|
2197
2273
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|
|
2198
2274
|
const code = (0, utils_1.generate)(node)?.code || '';
|
|
2199
2275
|
if (code?.includes('nasl.util')) {
|
|
@@ -2206,7 +2282,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2206
2282
|
if (!flatted)
|
|
2207
2283
|
return;
|
|
2208
2284
|
const calleeNames = flatted && flatted.map((item) => item?.calleeName).filter((name) => name !== '$');
|
|
2209
|
-
const isOrderCorrect = (0,
|
|
2285
|
+
const isOrderCorrect = (0, checkDataQueryCalleeNameOrder_1.checkDataQueryCalleeNameOrder)(calleeNames);
|
|
2210
2286
|
if (!isOrderCorrect) {
|
|
2211
2287
|
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);
|
|
2212
2288
|
}
|
|
@@ -2220,6 +2296,12 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2220
2296
|
let entity;
|
|
2221
2297
|
let hasErrorTSScopeColumn = false;
|
|
2222
2298
|
let useResultItem = false;
|
|
2299
|
+
let simplifyType;
|
|
2300
|
+
if (node.arguments?.[2] &&
|
|
2301
|
+
node.arguments[2]?.type === 'StringLiteral' &&
|
|
2302
|
+
node.arguments[2].value === 'SIMPLIFY') {
|
|
2303
|
+
simplifyType = true;
|
|
2304
|
+
}
|
|
2223
2305
|
// 这里只是一个示例,具体的逻辑需要根据flatted的内容来构建
|
|
2224
2306
|
flatted && flatted.forEach((item) => {
|
|
2225
2307
|
// console.log(item.calleeName)
|
|
@@ -2334,11 +2416,11 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2334
2416
|
}
|
|
2335
2417
|
const originName = arg.key?.name || '';
|
|
2336
2418
|
if (originName && originName.charAt(0) === originName.charAt(0).toUpperCase()) {
|
|
2337
|
-
const needName = (0,
|
|
2419
|
+
const needName = (0, utils_1.firstLowerCase)(originName);
|
|
2338
2420
|
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needName}, 但实际为${originName}`, node);
|
|
2339
2421
|
}
|
|
2340
|
-
const entityName = (0,
|
|
2341
|
-
const needNameList = entityAsNames.map(item => (0,
|
|
2422
|
+
const entityName = (0, utils_1.firstUpperCase)(originName);
|
|
2423
|
+
const needNameList = entityAsNames.map(item => (0, utils_1.firstLowerCase)(item))?.join('或');
|
|
2342
2424
|
if (!entityAsNames.includes(entityName)) {
|
|
2343
2425
|
return (0, utils_1.throwError)(options, `SELECT 局部列第一层命名不符合规范, 应为${needNameList}, 但实际为${originName}`, node);
|
|
2344
2426
|
}
|
|
@@ -2436,6 +2518,7 @@ function transformCall2DataQuery(node, calleeName, callee, options) {
|
|
|
2436
2518
|
having: having || null,
|
|
2437
2519
|
orderBy,
|
|
2438
2520
|
ideVersion: '2.22',
|
|
2521
|
+
simplifyType
|
|
2439
2522
|
});
|
|
2440
2523
|
if (!select) {
|
|
2441
2524
|
return (0, utils_1.throwError)(options, 'SELECT 不符合规范', node);
|
|
@@ -2487,6 +2570,24 @@ function transformNode2Directory(node) {
|
|
|
2487
2570
|
return newNode;
|
|
2488
2571
|
}
|
|
2489
2572
|
exports.transformNode2Directory = transformNode2Directory;
|
|
2573
|
+
/**
|
|
2574
|
+
* 将默认值表达式转换为 NASL DefaultValue 对象
|
|
2575
|
+
*/
|
|
2576
|
+
function transform2DefaultValue(node, options) {
|
|
2577
|
+
const defaultValue = new utils_1.naslTypes.DefaultValue();
|
|
2578
|
+
try {
|
|
2579
|
+
const expression = transform2LogicItem(node, options);
|
|
2580
|
+
if (expression) {
|
|
2581
|
+
defaultValue.expression = expression;
|
|
2582
|
+
return defaultValue;
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
catch (error) {
|
|
2586
|
+
return (0, utils_1.throwError)(options, `默认值解析失败: ${error.message}`, node);
|
|
2587
|
+
}
|
|
2588
|
+
return undefined;
|
|
2589
|
+
}
|
|
2590
|
+
exports.transform2DefaultValue = transform2DefaultValue;
|
|
2490
2591
|
function transform2LogicItem(node, options) {
|
|
2491
2592
|
fixLogicNode(node);
|
|
2492
2593
|
const transformNodeFunction = options?.transformNodeFunction || transform2LogicItem;
|