@lcap/nasl 3.3.0-alpha.1 → 3.3.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/automate/upgrader/2.20.js.map +1 -1
- package/out/bak/translator.js +52 -1
- package/out/bak/translator.js.map +1 -1
- package/out/breakpoint/shared/utils.js +0 -2
- package/out/breakpoint/shared/utils.js.map +1 -1
- package/out/common/Command.d.ts +1 -0
- package/out/common/Command.js +9 -1
- package/out/common/Command.js.map +1 -1
- package/out/concepts/Abort__.js +2 -1
- package/out/concepts/Abort__.js.map +1 -1
- package/out/concepts/Anchor__.js +1 -1
- package/out/concepts/Anchor__.js.map +1 -1
- package/out/concepts/AnonymousFunction__.js +2 -2
- package/out/concepts/AnonymousFunction__.js.map +1 -1
- package/out/concepts/Argument__.js +1 -1
- package/out/concepts/Argument__.js.map +1 -1
- package/out/concepts/Assignee__.js.map +1 -1
- package/out/concepts/AssignmentLine__.js +1 -1
- package/out/concepts/AssignmentLine__.js.map +1 -1
- package/out/concepts/Assignment__.js +2 -2
- package/out/concepts/Assignment__.js.map +1 -1
- package/out/concepts/BackendVariable__.js +1 -1
- package/out/concepts/BackendVariable__.js.map +1 -1
- package/out/concepts/Backend__.js +1 -1
- package/out/concepts/Backend__.js.map +1 -1
- package/out/concepts/BatchAssignment__.js +2 -2
- package/out/concepts/BatchAssignment__.js.map +1 -1
- package/out/concepts/BinaryExpression__.js +2 -2
- package/out/concepts/BinaryExpression__.js.map +1 -1
- package/out/concepts/BindAttribute__.d.ts +2 -0
- package/out/concepts/BindAttribute__.js +79 -4
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.js +1 -1
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindEvent__.d.ts +2 -1
- package/out/concepts/BindEvent__.js +44 -37
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/BindStyle__.js +1 -1
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BooleanLiteral__.js +1 -1
- package/out/concepts/BooleanLiteral__.js.map +1 -1
- package/out/concepts/CallAuthInterface__.js +1 -1
- package/out/concepts/CallAuthInterface__.js.map +1 -1
- package/out/concepts/CallConnector__.js +1 -1
- package/out/concepts/CallConnector__.js.map +1 -1
- package/out/concepts/CallFunction__.js +2 -2
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallInterface__.js +2 -2
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.js +69 -12
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +1 -1
- package/out/concepts/CallQueryComponent__.js +1 -1
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Comment__.js +1 -1
- package/out/concepts/Comment__.js.map +1 -1
- package/out/concepts/ConfigProperty__.js +1 -1
- package/out/concepts/ConfigProperty__.js.map +1 -1
- package/out/concepts/Connection__.js +9 -10
- package/out/concepts/Connection__.js.map +1 -1
- package/out/concepts/Constant__.js +1 -1
- package/out/concepts/Constant__.js.map +1 -1
- package/out/concepts/DataSource__.js +1 -1
- package/out/concepts/DataSource__.js.map +1 -1
- package/out/concepts/Destination__.js +2 -2
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/End__.js +1 -1
- package/out/concepts/End__.js.map +1 -1
- package/out/concepts/EntityIndex__.js +1 -1
- package/out/concepts/EntityIndex__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +2 -2
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.js +2 -2
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/EnumItem__.js +2 -2
- package/out/concepts/EnumItem__.js.map +1 -1
- package/out/concepts/Enum__.js +2 -2
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/ForEachStatement__.js +27 -37
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/Frontend__.js +1 -1
- package/out/concepts/Frontend__.js.map +1 -1
- package/out/concepts/Function__.js +2 -2
- package/out/concepts/Function__.js.map +1 -1
- package/out/concepts/Identifier__.js +1 -1
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/IfStatement__.js +2 -2
- package/out/concepts/IfStatement__.js.map +1 -1
- package/out/concepts/Interface__.js +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/JSBlock__.js +1 -1
- package/out/concepts/JSBlock__.js.map +1 -1
- package/out/concepts/JavaLogic__.js +1 -1
- package/out/concepts/JavaLogic__.js.map +1 -1
- package/out/concepts/LogicItem__.js +3 -2
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.js +2 -1
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchCase__.js +1 -1
- package/out/concepts/MatchCase__.js.map +1 -1
- package/out/concepts/Match__.js +2 -2
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.d.ts +1 -0
- package/out/concepts/MemberExpression__.js +117 -2
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/Module__.d.ts +1 -1
- package/out/concepts/Module__.js +34 -35
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/NewComposite__.js +2 -2
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/NewList__.js +2 -2
- package/out/concepts/NewList__.js.map +1 -1
- package/out/concepts/NewMap__.js +2 -2
- package/out/concepts/NewMap__.js.map +1 -1
- package/out/concepts/New__.js +1 -1
- package/out/concepts/New__.js.map +1 -1
- package/out/concepts/NullLiteral__.js +1 -1
- package/out/concepts/NullLiteral__.js.map +1 -1
- package/out/concepts/NumericLiteral__.js +1 -1
- package/out/concepts/NumericLiteral__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js +2 -2
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/Param__.js +1 -1
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +1 -1
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/ProcessOutcome__.js +1 -1
- package/out/concepts/ProcessOutcome__.js.map +1 -1
- package/out/concepts/ProcessOutcomes__.js +1 -1
- package/out/concepts/ProcessOutcomes__.js.map +1 -1
- package/out/concepts/Process__.js +1 -1
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/QueryAggregateExpression__.js +1 -1
- package/out/concepts/QueryAggregateExpression__.js.map +1 -1
- package/out/concepts/QueryFieldExpression__.js +1 -1
- package/out/concepts/QueryFieldExpression__.js.map +1 -1
- package/out/concepts/QueryFromExpression__.js +1 -1
- package/out/concepts/QueryFromExpression__.js.map +1 -1
- package/out/concepts/QueryJoinExpression__.js +1 -1
- package/out/concepts/QueryJoinExpression__.js.map +1 -1
- package/out/concepts/QueryLimitExpression__.js +1 -1
- package/out/concepts/QueryLimitExpression__.js.map +1 -1
- package/out/concepts/QueryOrderByExpression__.js +1 -1
- package/out/concepts/QueryOrderByExpression__.js.map +1 -1
- package/out/concepts/Return__.js +2 -2
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/Role__.js +1 -1
- package/out/concepts/Role__.js.map +1 -1
- package/out/concepts/SelectMembers__.js +1 -1
- package/out/concepts/SelectMembers__.js.map +1 -1
- package/out/concepts/SqlQueryComponent__.js +2 -2
- package/out/concepts/SqlQueryComponent__.js.map +1 -1
- package/out/concepts/Start__.js +1 -1
- package/out/concepts/Start__.js.map +1 -1
- package/out/concepts/StringInterpolation__.js +2 -2
- package/out/concepts/StringInterpolation__.js.map +1 -1
- package/out/concepts/StringLiteral__.js +1 -1
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.js +2 -2
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/Structure__.js +2 -2
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/SwitchCase__.js +1 -1
- package/out/concepts/SwitchCase__.js.map +1 -1
- package/out/concepts/SwitchStatement__.js +2 -2
- package/out/concepts/SwitchStatement__.js.map +1 -1
- package/out/concepts/TriggerLauncher__.js +1 -1
- package/out/concepts/TriggerLauncher__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.d.ts +4 -3
- package/out/concepts/TypeAnnotation__.js +116 -75
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/TypeParam__.js +1 -1
- package/out/concepts/TypeParam__.js.map +1 -1
- package/out/concepts/UnaryExpression__.js +2 -2
- package/out/concepts/UnaryExpression__.js.map +1 -1
- package/out/concepts/ValidationRule__.d.ts +14 -14
- package/out/concepts/ValidationRule__.js +28 -24
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.js +2 -2
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +88 -87
- package/out/concepts/ViewElement__.js +268 -204
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +6 -0
- package/out/concepts/View__.js +254 -11
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/WhileStatement__.js +2 -2
- package/out/concepts/WhileStatement__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.browser.js +1 -0
- package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.event.js +2 -0
- package/out/concepts/basics/stdlib/nasl.event.js.map +1 -1
- package/out/generator/genBundleFiles.js +90 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genReleaseBody.js +1 -1
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/generator/permission.js +3 -3
- package/out/generator/permission.js.map +1 -1
- package/out/index.d.ts +1 -0
- package/out/index.js +1 -0
- package/out/index.js.map +1 -1
- package/out/natural/genNaturalTS.js +7 -3
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/knowledgeMap.js +12 -12
- package/out/natural/knowledgeMap.js.map +1 -1
- package/out/natural/transformTSCode.d.ts +1 -1
- package/out/natural/transformTSCode.js +115 -141
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/extendBaseNode.js +69 -44
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/formatTsUtils.js +72 -63
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getLogics.js +20 -23
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.d.ts +1 -0
- package/out/server/getMemberIdentifier.js +149 -1
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.d.ts +3 -3
- package/out/server/naslServer.js +182 -132
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +43 -33
- package/out/server/translator.js.map +1 -1
- package/out/service/defaultErrorMessage.json +6 -6
- package/out/service/storage/init.js +16 -0
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genCreateBlock.js +5 -3
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +12 -8
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +8 -7
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genEditTableBlock.d.ts +1 -1
- package/out/templator/genEditTableBlock.js +12 -6
- package/out/templator/genEditTableBlock.js.map +1 -1
- package/out/templator/genEnumSelectBlock.js +2 -2
- package/out/templator/genEnumSelectBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +1 -1
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.d.ts +2 -2
- package/out/templator/genGridViewBlock.js +20 -7
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genListViewBlock.d.ts +2 -2
- package/out/templator/genListViewBlock.js +13 -5
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genSelectBlock.d.ts +2 -2
- package/out/templator/genSelectBlock.js +8 -6
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genTableBlock.d.ts +1 -1
- package/out/templator/genTableBlock.js +10 -5
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +5 -3
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/package.json +3 -1
- package/sandbox/stdlib/nasl.auth.ts +40 -44
- package/sandbox/stdlib/nasl.core.ts +8 -1
- package/sandbox/stdlib/nasl.http.ts +22 -22
- package/sandbox-natural/stdlib/nasl.util.ts +74 -15
- package/src/automate/upgrader/2.20.js +17 -13
- package/src/bak/translator.js +50 -1
- package/src/breakpoint/shared/utils.ts +0 -2
- package/src/common/Command.ts +8 -0
- package/src/concepts/Abort__.ts +2 -2
- package/src/concepts/Anchor__.ts +2 -2
- package/src/concepts/AnonymousFunction__.ts +3 -3
- package/src/concepts/Argument__.ts +2 -2
- package/src/concepts/Assignee__.ts +1 -1
- package/src/concepts/AssignmentLine__.ts +2 -2
- package/src/concepts/Assignment__.ts +3 -3
- package/src/concepts/BackendVariable__.ts +2 -2
- package/src/concepts/Backend__.ts +1 -1
- package/src/concepts/BatchAssignment__.ts +3 -3
- package/src/concepts/BinaryExpression__.ts +3 -3
- package/src/concepts/BindAttribute__.ts +69 -4
- package/src/concepts/BindDirective__.ts +2 -2
- package/src/concepts/BindEvent__.ts +44 -64
- package/src/concepts/BindStyle__.ts +2 -2
- package/src/concepts/BooleanLiteral__.ts +2 -2
- package/src/concepts/CallAuthInterface__.ts +2 -2
- package/src/concepts/CallConnector__.ts +2 -2
- package/src/concepts/CallFunction__.ts +3 -3
- package/src/concepts/CallInterface__.ts +3 -3
- package/src/concepts/CallLogic__.ts +69 -13
- package/src/concepts/CallQueryComponent__.ts +2 -2
- package/src/concepts/Comment__.ts +2 -2
- package/src/concepts/ConfigProperty__.ts +2 -2
- package/src/concepts/Connection__.ts +15 -21
- package/src/concepts/Constant__.ts +2 -2
- package/src/concepts/DataSource__.ts +1 -1
- package/src/concepts/Destination__.ts +3 -3
- package/src/concepts/End__.ts +2 -2
- package/src/concepts/EntityIndex__.ts +2 -2
- package/src/concepts/EntityProperty__.ts +3 -3
- package/src/concepts/Entity__.ts +2 -2
- package/src/concepts/EnumItem__.ts +3 -3
- package/src/concepts/Enum__.ts +2 -2
- package/src/concepts/ForEachStatement__.ts +35 -46
- package/src/concepts/Frontend__.ts +1 -1
- package/src/concepts/Function__.ts +3 -3
- package/src/concepts/Identifier__.ts +2 -2
- package/src/concepts/IfStatement__.ts +3 -3
- package/src/concepts/Interface__.ts +1 -1
- package/src/concepts/JSBlock__.ts +2 -2
- package/src/concepts/JavaLogic__.ts +2 -2
- package/src/concepts/LogicItem__.ts +3 -3
- package/src/concepts/Logic__.ts +2 -1
- package/src/concepts/MatchCase__.ts +2 -2
- package/src/concepts/Match__.ts +3 -3
- package/src/concepts/MemberExpression__.ts +112 -4
- package/src/concepts/Module__.ts +41 -58
- package/src/concepts/NewComposite__.ts +3 -3
- package/src/concepts/NewList__.ts +3 -3
- package/src/concepts/NewMap__.ts +3 -3
- package/src/concepts/New__.ts +2 -2
- package/src/concepts/NullLiteral__.ts +2 -2
- package/src/concepts/NumericLiteral__.ts +2 -2
- package/src/concepts/OqlQueryComponent__.ts +3 -3
- package/src/concepts/Param__.ts +2 -2
- package/src/concepts/ProcessElement__.ts +2 -2
- package/src/concepts/ProcessOutcome__.ts +2 -2
- package/src/concepts/ProcessOutcomes__.ts +2 -2
- package/src/concepts/Process__.ts +1 -1
- package/src/concepts/QueryAggregateExpression__.ts +2 -2
- package/src/concepts/QueryFieldExpression__.ts +2 -2
- package/src/concepts/QueryFromExpression__.ts +2 -2
- package/src/concepts/QueryJoinExpression__.ts +2 -2
- package/src/concepts/QueryLimitExpression__.ts +2 -2
- package/src/concepts/QueryOrderByExpression__.ts +2 -2
- package/src/concepts/Return__.ts +3 -3
- package/src/concepts/Role__.ts +1 -1
- package/src/concepts/SelectMembers__.ts +2 -2
- package/src/concepts/SqlQueryComponent__.ts +3 -3
- package/src/concepts/Start__.ts +2 -2
- package/src/concepts/StringInterpolation__.ts +3 -3
- package/src/concepts/StringLiteral__.ts +2 -2
- package/src/concepts/StructureProperty__.ts +3 -3
- package/src/concepts/Structure__.ts +2 -2
- package/src/concepts/SwitchCase__.ts +2 -2
- package/src/concepts/SwitchStatement__.ts +3 -3
- package/src/concepts/TriggerLauncher__.ts +1 -1
- package/src/concepts/TypeAnnotation__.ts +145 -125
- package/src/concepts/TypeParam__.ts +2 -2
- package/src/concepts/UnaryExpression__.ts +3 -3
- package/src/concepts/ValidationRule__.ts +554 -524
- package/src/concepts/Variable__.ts +3 -3
- package/src/concepts/ViewElement__.ts +2445 -2498
- package/src/concepts/View__.ts +258 -10
- package/src/concepts/WhileStatement__.ts +3 -3
- package/src/concepts/basics/stdlib/nasl.browser.ts +1 -0
- package/src/concepts/basics/stdlib/nasl.event.ts +2 -0
- package/src/generator/genBundleFiles.ts +91 -1
- package/src/generator/genReleaseBody.ts +1 -1
- package/src/generator/permission.ts +3 -3
- package/src/index.ts +1 -0
- package/src/natural/genNaturalTS.ts +8 -4
- package/src/natural/knowledgeMap.ts +12 -12
- package/src/natural/transformTSCode.ts +139 -151
- package/src/server/extendBaseNode.ts +71 -45
- package/src/server/formatTsUtils.ts +64 -64
- package/src/server/getLogics.ts +23 -30
- package/src/server/getMemberIdentifier.ts +143 -0
- package/src/server/naslServer.ts +174 -148
- package/src/server/translator.ts +40 -39
- package/src/service/defaultErrorMessage.json +6 -6
- package/src/service/storage/init.ts +17 -0
- package/src/templator/genCreateBlock.ts +5 -3
- package/src/templator/genCurdEditMultipleKeyBlock.ts +12 -8
- package/src/templator/genCurdMultipleKeyBlock.ts +8 -7
- package/src/templator/genEditTableBlock.ts +12 -7
- package/src/templator/genEnumSelectBlock.ts +2 -2
- package/src/templator/genGetBlock.ts +6 -6
- package/src/templator/genGridViewBlock.ts +22 -9
- package/src/templator/genListViewBlock.ts +14 -5
- package/src/templator/genSelectBlock.ts +8 -6
- package/src/templator/genTableBlock.ts +10 -9
- package/src/templator/genUpdateBlock.ts +5 -3
- package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +11 -0
- package/test/concepts/validation-rule/__snapshots__/toJS.spec.ts.snap +10 -0
- package/test/concepts/validation-rule/fixtures/argument-without-keyword.json +34 -0
- package/test/concepts/validation-rule/fixtures/empty-rule.json +9 -0
- package/test/concepts/validation-rule/validation-rule.spec.ts +15 -0
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// 走 babel 走 ts 都行,可能 babel 跟我们语法树更像一些
|
|
4
|
-
// import * as ts from 'typescript';
|
|
5
|
-
// export function transformFromTS2(tsCode: string, contextLogicName: string) {
|
|
6
|
-
// const result: Array<naslTypes.BaseNode> = [];
|
|
7
|
-
|
|
8
|
-
// const sourceFile = ts.createSourceFile(`result.ts`, tsCode, ts.ScriptTarget.ESNext);
|
|
9
|
-
// let realBody: ts.Node;
|
|
10
|
-
// function findRealBody(node: ts.Node) {
|
|
11
|
-
// if (ts.isFunctionDeclaration(node) && node.name.escapedText === contextLogicName) {
|
|
12
|
-
// return realBody = node.body;
|
|
13
|
-
// } else {
|
|
14
|
-
// node.forEachChild(findRealBody);
|
|
15
|
-
// }
|
|
16
|
-
// }
|
|
17
|
-
// sourceFile.forEachChild(findRealBody);
|
|
18
|
-
|
|
19
|
-
// if (!realBody)
|
|
20
|
-
// throw new Error('无法找到实现的函数!');
|
|
21
|
-
|
|
22
|
-
// realBody.forEachChild((node) => {
|
|
23
|
-
// console.log(node);
|
|
24
|
-
// });
|
|
25
|
-
// }
|
|
26
|
-
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
27
3
|
import * as babel from '@babel/core';
|
|
28
4
|
import * as babelTypes from '@babel/types';
|
|
29
5
|
import generate from '@babel/generator';
|
|
6
|
+
import * as naslTypes from '../concepts';
|
|
30
7
|
import { traverse } from '../utils';
|
|
31
8
|
|
|
32
9
|
export function tryParseTS(tsCode: string) {
|
|
@@ -42,6 +19,31 @@ export function tryParseTS(tsCode: string) {
|
|
|
42
19
|
}
|
|
43
20
|
}
|
|
44
21
|
|
|
22
|
+
function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
|
|
23
|
+
if (node.type === 'MemberExpression')
|
|
24
|
+
return [...flatMemberExpression(node.object), node.property];
|
|
25
|
+
return [node];
|
|
26
|
+
}
|
|
27
|
+
function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
|
|
28
|
+
if (node.concept === 'BinaryExpression') {
|
|
29
|
+
if (node.operator === '||') {
|
|
30
|
+
return [...flatMatchPatternsExpression(node.left), ...flatMatchPatternsExpression(node.right)];
|
|
31
|
+
}
|
|
32
|
+
if (node.operator === '==') {
|
|
33
|
+
return [node.right];
|
|
34
|
+
}
|
|
35
|
+
return [node];
|
|
36
|
+
}
|
|
37
|
+
return [node];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function flatIfStatement(node: any): Array<babelTypes.Node> {
|
|
41
|
+
if (node.alternate.type === 'IfStatement') {
|
|
42
|
+
return [...flatIfStatement(node.alternate), node];
|
|
43
|
+
}
|
|
44
|
+
return [node];
|
|
45
|
+
}
|
|
46
|
+
|
|
45
47
|
/**
|
|
46
48
|
* 这个函数是修复 AI 翻译出错的情况,与正常的 transform 做个区分
|
|
47
49
|
* @param node
|
|
@@ -72,18 +74,19 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
72
74
|
}
|
|
73
75
|
if (primitiveType) {
|
|
74
76
|
return naslTypes.TypeAnnotation.createPrimitive(typeName);
|
|
75
|
-
}
|
|
77
|
+
}
|
|
78
|
+
if (['List', 'Map', 'Current'].includes(typeName) && node.typeParameters) {
|
|
76
79
|
return naslTypes.TypeAnnotation.createGeneric(typeName, {
|
|
77
80
|
typeArguments: node.typeParameters.params.map(transformTypeAnnotation),
|
|
78
81
|
});
|
|
79
|
-
}
|
|
82
|
+
}
|
|
83
|
+
if (!node.typeParameters) {
|
|
80
84
|
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
81
85
|
typeNamespace: 'app.dataSources.defaultDS',
|
|
82
86
|
});
|
|
83
|
-
} else {
|
|
84
|
-
console.error(node);
|
|
85
|
-
throw new Error('Unhandled node ' + node.type);
|
|
86
87
|
}
|
|
88
|
+
console.error(node);
|
|
89
|
+
throw new Error(`Unhandled node ${node.type}`);
|
|
87
90
|
} else if (node.type === 'TSTypeLiteral') {
|
|
88
91
|
return naslTypes.TypeAnnotation.createTypeAnonymousStructure(node.members.map((member: babelTypes.TSPropertySignature) => new naslTypes.StructureProperty({
|
|
89
92
|
name: (member.key as babelTypes.Identifier).name,
|
|
@@ -98,13 +101,13 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
98
101
|
} else if (node.type === 'TSUnionType') {
|
|
99
102
|
const union = naslTypes.TypeAnnotation.createPrimitive('Union');
|
|
100
103
|
union.typeArguments = [];
|
|
101
|
-
node.types.forEach((
|
|
102
|
-
union.typeArguments.push(transformTypeAnnotation(
|
|
104
|
+
node.types.forEach((curType) => {
|
|
105
|
+
union.typeArguments.push(transformTypeAnnotation(curType));
|
|
103
106
|
});
|
|
104
107
|
return union;
|
|
105
108
|
} else {
|
|
106
109
|
console.error(node);
|
|
107
|
-
throw new Error(
|
|
110
|
+
throw new Error(`Unhandled node ${node.type}`);
|
|
108
111
|
}
|
|
109
112
|
}
|
|
110
113
|
function transformParam(node: babelTypes.Identifier): naslTypes.Param {
|
|
@@ -115,45 +118,49 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
120
|
function pushElseIf(ifNode: babelTypes.IfStatement, switchStatement: naslTypes.SwitchStatement) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
switchStatement.cases.push(new naslTypes.SwitchCase({
|
|
122
|
+
test: transformLogicNode(ifNode.test),
|
|
123
|
+
consequent: !ifNode.consequent ? [] : (ifNode.consequent as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
124
|
+
}));
|
|
125
|
+
if (ifNode.alternate && ifNode.alternate.type === 'IfStatement') {
|
|
126
|
+
pushElseIf(ifNode.alternate, switchStatement);
|
|
127
|
+
} else {
|
|
128
|
+
switchStatement.cases.push(new naslTypes.SwitchCase({
|
|
129
|
+
test: undefined,
|
|
130
|
+
consequent: !ifNode.consequent ? [] : (ifNode.consequent as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
131
135
|
function transformLogicNode(node: babelTypes.Node, typeAnnotation?: naslTypes.TypeAnnotation): naslTypes.LogicItem {
|
|
132
136
|
fixLogicNode(node);
|
|
133
137
|
// console.log('lemon ~~~ node--1:', node);
|
|
134
138
|
if (node.type === 'VariableDeclaration') { // 拆成局部变量和赋值
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
const declList = node?.declarations || [];
|
|
140
|
+
declList?.forEach((decl) => {
|
|
141
|
+
const variableName = (decl.id as babelTypes.Identifier).name;
|
|
142
|
+
if (!logic.variables.find((variable) => variable.name === variableName)) {
|
|
143
|
+
const varTypeAnnotation = ((decl.id as babelTypes.Identifier).typeAnnotation as babelTypes.TSTypeAnnotation)?.typeAnnotation;
|
|
139
144
|
logic.variables.push(new naslTypes.Variable({
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
name: variableName,
|
|
146
|
+
typeAnnotation: varTypeAnnotation && transformTypeAnnotation(varTypeAnnotation),
|
|
142
147
|
}));
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
}
|
|
149
|
+
if (decl.init) {
|
|
145
150
|
if (decl.init.type !== 'ArrayExpression') {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
if (type === 'expression') {
|
|
152
|
+
return transformLogicNode(decl.init);
|
|
153
|
+
}
|
|
154
|
+
const item = new naslTypes.Assignment({
|
|
155
|
+
left: new naslTypes.Identifier({
|
|
156
|
+
name: variableName,
|
|
157
|
+
}),
|
|
158
|
+
right: transformLogicNode(decl.init),
|
|
159
|
+
});
|
|
160
|
+
item && logic.body.push(item);
|
|
155
161
|
}
|
|
156
|
-
|
|
162
|
+
}
|
|
163
|
+
});
|
|
157
164
|
} else if (node.type === 'CallExpression') {
|
|
158
165
|
const callee = flatMemberExpression(node.callee);
|
|
159
166
|
const calleeName = generate(node.callee as any).code;
|
|
@@ -166,7 +173,8 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
166
173
|
expression: transformLogicNode(arg),
|
|
167
174
|
})) as naslTypes.Argument[],
|
|
168
175
|
});
|
|
169
|
-
}
|
|
176
|
+
}
|
|
177
|
+
if (callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity')) {
|
|
170
178
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
171
179
|
return new naslTypes.CallLogic({
|
|
172
180
|
calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
|
|
@@ -175,13 +183,15 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
175
183
|
expression: transformLogicNode(arg),
|
|
176
184
|
})) as naslTypes.Argument[],
|
|
177
185
|
});
|
|
178
|
-
}
|
|
186
|
+
}
|
|
187
|
+
if (calleeName === 'nasl.oql.query') {
|
|
179
188
|
return new naslTypes.OqlQueryComponent({
|
|
180
189
|
dataSource: 'app.dataSources.defaultDS',
|
|
181
190
|
code: generate(node.arguments[0] as any).code.trim().slice(1, -1),
|
|
182
191
|
});
|
|
183
|
-
}
|
|
184
|
-
|
|
192
|
+
}
|
|
193
|
+
if (calleeName.startsWith('nasl.util.')) {
|
|
194
|
+
const curCalleeName = callee.length === 3 ? (callee[callee.length - 1] as babelTypes.Identifier).name : (callee[0] as any).callee.property.name;
|
|
185
195
|
const argument = callee.length === 3 ? node.arguments : (callee[0] as any).arguments as any;
|
|
186
196
|
let typeNamespace: string;
|
|
187
197
|
if (argument?.[argument.length - 1]?.type === 'ObjectExpression') {
|
|
@@ -189,17 +199,18 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
189
199
|
}
|
|
190
200
|
const nodeElement = new naslTypes.CallFunction({
|
|
191
201
|
calleeNamespace: 'nasl.util',
|
|
192
|
-
calleeName,
|
|
202
|
+
calleeName: curCalleeName,
|
|
193
203
|
arguments: argument.map((arg: any, index: number) => new naslTypes.Argument({
|
|
194
204
|
expression: transformLogicNode(arg),
|
|
195
205
|
keyword: `str${index + 1}`,
|
|
196
206
|
})) as naslTypes.Argument[],
|
|
197
|
-
typeArguments: node?.typeParameters?.params.map((
|
|
207
|
+
typeArguments: node?.typeParameters?.params.map((curType: any) => transformTypeAnnotation({ ...curType, typeNamespace })),
|
|
198
208
|
|
|
199
209
|
});
|
|
200
210
|
// console.log('lemon ~ callFunction ~ 3:', nodeElement);
|
|
201
211
|
return nodeElement;
|
|
202
|
-
}
|
|
212
|
+
}
|
|
213
|
+
if (callee.length === 3 && calleeName.startsWith('nasl.ui.')) {
|
|
203
214
|
return new naslTypes.CallLogic({
|
|
204
215
|
calleeNamespace: 'nasl.ui',
|
|
205
216
|
calleeName: (callee[2] as babelTypes.Identifier).name,
|
|
@@ -213,15 +224,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
213
224
|
expression: transformLogicNode(arg),
|
|
214
225
|
})) as naslTypes.Argument[],
|
|
215
226
|
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
}
|
|
228
|
+
if (calleeName === 'ForEach') {
|
|
229
|
+
const newCallee = node.arguments;
|
|
230
|
+
const arrowFunction = node.arguments[3] as babelTypes.ArrowFunctionExpression;
|
|
231
|
+
const nodeElement = new naslTypes.ForEachStatement({
|
|
232
|
+
each: transformLogicNode(newCallee[0]),
|
|
233
|
+
start: transformLogicNode(newCallee[1]),
|
|
234
|
+
end: transformLogicNode(newCallee[2]),
|
|
235
|
+
item: transformParam(arrowFunction.params[0] as babelTypes.Identifier),
|
|
236
|
+
index: transformParam(arrowFunction.params[1] as babelTypes.Identifier),
|
|
237
|
+
body: (arrowFunction.body as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
238
|
+
});
|
|
239
|
+
return nodeElement;
|
|
240
|
+
}
|
|
241
|
+
if (callee.length === 2) {
|
|
242
|
+
const curCalleeName = (node.callee as any).property.name;
|
|
243
|
+
if (curCalleeName === 'forEach') {
|
|
244
|
+
const newCallee = (node.callee as any).object;
|
|
220
245
|
const arrowFunction = node.arguments[0] as babelTypes.ArrowFunctionExpression;
|
|
221
246
|
const nodeElement = new naslTypes.ForEachStatement({
|
|
222
247
|
each: transformLogicNode(newCallee.callee.object),
|
|
223
|
-
start: transformLogicNode(newCallee
|
|
224
|
-
end: transformLogicNode(newCallee
|
|
248
|
+
start: transformLogicNode(newCallee?.arguments?.[0]),
|
|
249
|
+
end: transformLogicNode(newCallee?.arguments?.[1]),
|
|
225
250
|
item: transformParam(arrowFunction.params[0] as babelTypes.Identifier),
|
|
226
251
|
index: transformParam(arrowFunction.params[1] as babelTypes.Identifier),
|
|
227
252
|
body: (arrowFunction.body as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
@@ -332,23 +357,16 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
332
357
|
}
|
|
333
358
|
});
|
|
334
359
|
return match;
|
|
335
|
-
}
|
|
360
|
+
}
|
|
361
|
+
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__SwitchExpressionFuntion') {
|
|
336
362
|
const switchStatement = transformLogicNode(newCallee[0].body.body[0]);
|
|
337
|
-
// const switchStatement = new naslTypes.SwitchStatement({
|
|
338
|
-
// cases: newCallee[0].body.body.map((_case: any) => new naslTypes.SwitchCase({
|
|
339
|
-
// test: transformLogicNode(_case.test),
|
|
340
|
-
// consequent: !_case.consequent ? [] : (_case.consequent as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
341
|
-
// })),
|
|
342
|
-
// });
|
|
343
|
-
// switchStatement.cases.push(new naslTypes.SwitchCase({}));
|
|
344
363
|
return switchStatement;
|
|
345
|
-
} else {
|
|
346
|
-
console.error(node);
|
|
347
|
-
throw new Error('Unhandled ArrowFunctionExpression node ' + node.type);
|
|
348
364
|
}
|
|
365
|
+
console.error(node);
|
|
366
|
+
throw new Error(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
349
367
|
} else {
|
|
350
368
|
console.error(node);
|
|
351
|
-
throw new Error(
|
|
369
|
+
throw new Error(`Unhandled node ${callee.map((item: babelTypes.Identifier) => item.name).join('.')} ${node.type}`);
|
|
352
370
|
}
|
|
353
371
|
} else if (node.type === 'IfStatement') {
|
|
354
372
|
if (node.alternate && node.alternate.type === 'IfStatement') {
|
|
@@ -357,13 +375,12 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
357
375
|
});
|
|
358
376
|
pushElseIf(node, switchStatement);
|
|
359
377
|
return switchStatement;
|
|
360
|
-
} else {
|
|
361
|
-
return new naslTypes.IfStatement({
|
|
362
|
-
test: transformLogicNode(node.test),
|
|
363
|
-
consequent: !node.consequent ? [] : (node.consequent as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
364
|
-
alternate: !node.alternate ? [] : (node.alternate as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
365
|
-
});
|
|
366
378
|
}
|
|
379
|
+
return new naslTypes.IfStatement({
|
|
380
|
+
test: transformLogicNode(node.test),
|
|
381
|
+
consequent: !node.consequent ? [] : (node.consequent as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
382
|
+
alternate: !node.alternate ? [] : (node.alternate as babelTypes.BlockStatement).body.map((item) => transformLogicNode(item)).filter((item) => !!item),
|
|
383
|
+
});
|
|
367
384
|
} else if (node.type === 'WhileStatement') {
|
|
368
385
|
return new naslTypes.WhileStatement({
|
|
369
386
|
test: transformLogicNode(node.test),
|
|
@@ -408,12 +425,11 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
408
425
|
}),
|
|
409
426
|
],
|
|
410
427
|
});
|
|
411
|
-
} else {
|
|
412
|
-
return new naslTypes.MemberExpression({
|
|
413
|
-
object: transformLogicNode(node.object),
|
|
414
|
-
property: transformLogicNode(node.property),
|
|
415
|
-
});
|
|
416
428
|
}
|
|
429
|
+
return new naslTypes.MemberExpression({
|
|
430
|
+
object: transformLogicNode(node.object),
|
|
431
|
+
property: transformLogicNode(node.property),
|
|
432
|
+
});
|
|
417
433
|
} else if (node.type === 'Identifier') {
|
|
418
434
|
return new naslTypes.Identifier({
|
|
419
435
|
name: node.name,
|
|
@@ -437,23 +453,21 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
437
453
|
right: transformLogicNode(node.right),
|
|
438
454
|
}),
|
|
439
455
|
});
|
|
440
|
-
} else {
|
|
441
|
-
if (type === 'expression') {
|
|
442
|
-
return transformLogicNode(node.right);
|
|
443
|
-
}
|
|
444
|
-
return new naslTypes.Assignment({
|
|
445
|
-
left: transformLogicNode(node.left),
|
|
446
|
-
right: transformLogicNode(node.right),
|
|
447
|
-
});
|
|
448
456
|
}
|
|
457
|
+
if (type === 'expression') {
|
|
458
|
+
return transformLogicNode(node.right);
|
|
459
|
+
}
|
|
460
|
+
return new naslTypes.Assignment({
|
|
461
|
+
left: transformLogicNode(node.left),
|
|
462
|
+
right: transformLogicNode(node.right),
|
|
463
|
+
});
|
|
449
464
|
} else if (node.type === 'NewExpression') {
|
|
450
465
|
const calleeName = generate(node.callee as any).code;
|
|
451
466
|
if (['Boolean', 'Integer', 'Double', 'Decimal', 'Long'].includes(calleeName)) {
|
|
452
467
|
return transformLogicNode(node.arguments[0], naslTypes.TypeAnnotation.createPrimitive(calleeName));
|
|
453
|
-
} else {
|
|
454
|
-
console.error(node);
|
|
455
|
-
throw new Error('Unhandled node ' + node.type);
|
|
456
468
|
}
|
|
469
|
+
console.error(node);
|
|
470
|
+
throw new Error(`Unhandled node ${node.type}`);
|
|
457
471
|
} else if (node.type === 'ArrowFunctionExpression') {
|
|
458
472
|
return new naslTypes.AnonymousFunction({
|
|
459
473
|
params: node.params.map((param: babelTypes.Identifier) => transformParam(param)),
|
|
@@ -499,25 +513,24 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
499
513
|
left: transformLogicNode(node.left),
|
|
500
514
|
right: transformLogicNode(node.right),
|
|
501
515
|
});
|
|
502
|
-
} else {
|
|
503
|
-
console.error(node);
|
|
504
|
-
throw new Error('Unhandled node ' + node.type);
|
|
505
516
|
}
|
|
517
|
+
console.error(node);
|
|
518
|
+
throw new Error(`Unhandled node ${node.type}`);
|
|
506
519
|
} else if (node.type === 'UnaryExpression') {
|
|
507
520
|
if (['!'].includes(node.operator)) {
|
|
508
521
|
return new naslTypes.UnaryExpression({
|
|
509
522
|
operator: node.operator as any,
|
|
510
523
|
argument: transformLogicNode(node.argument),
|
|
511
524
|
});
|
|
512
|
-
}
|
|
525
|
+
}
|
|
526
|
+
if (['-'].includes(node.operator) && node.argument.type === 'NumericLiteral') {
|
|
513
527
|
return transformLogicNode({
|
|
514
528
|
type: 'NumericLiteral',
|
|
515
529
|
value: -node.argument.value,
|
|
516
530
|
} as babelTypes.NumericLiteral);
|
|
517
|
-
} else {
|
|
518
|
-
console.error(node);
|
|
519
|
-
throw new Error('Unhandled node ' + node.type);
|
|
520
531
|
}
|
|
532
|
+
console.error(node);
|
|
533
|
+
throw new Error(`Unhandled node ${node.type}`);
|
|
521
534
|
} else if (node.type === 'UpdateExpression') {
|
|
522
535
|
if (node.operator === '++' || node.operator === '--') {
|
|
523
536
|
return new naslTypes.Assignment({
|
|
@@ -553,9 +566,11 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
553
566
|
return node.leadingComments && new naslTypes.Comment({
|
|
554
567
|
value: String(node.leadingComments[0].value),
|
|
555
568
|
});
|
|
569
|
+
} else if (node.type === 'BlockStatement') {
|
|
570
|
+
return transformLogicNode(node?.body?.[0]);
|
|
556
571
|
} else {
|
|
557
|
-
|
|
558
|
-
|
|
572
|
+
console.error(node);
|
|
573
|
+
throw new Error(`Unhandled node ${node.type}`);
|
|
559
574
|
}
|
|
560
575
|
}
|
|
561
576
|
|
|
@@ -612,33 +627,6 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
|
|
|
612
627
|
return logic;
|
|
613
628
|
}
|
|
614
629
|
|
|
615
|
-
function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
|
|
616
|
-
if (node.type === 'MemberExpression')
|
|
617
|
-
return [...flatMemberExpression(node.object), node.property];
|
|
618
|
-
else
|
|
619
|
-
return [node];
|
|
620
|
-
}
|
|
621
|
-
function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
|
|
622
|
-
if (node.concept === 'BinaryExpression') {
|
|
623
|
-
if (node.operator === '||') {
|
|
624
|
-
return [...flatMatchPatternsExpression(node.left), ...flatMatchPatternsExpression(node.right)];
|
|
625
|
-
}
|
|
626
|
-
if (node.operator === '==') {
|
|
627
|
-
return [node.right];
|
|
628
|
-
}
|
|
629
|
-
return [node];
|
|
630
|
-
} else
|
|
631
|
-
return [node];
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function flatIfStatement(node: any): Array<babelTypes.Node> {
|
|
635
|
-
if (node.alternate.type === 'IfStatement') {
|
|
636
|
-
return [...flatIfStatement(node.alternate), node];
|
|
637
|
-
} else {
|
|
638
|
-
return [node];
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
630
|
export function tryTransformTSCode(tsCode: string, contextLogicName: string, type?: string): naslTypes.Logic {
|
|
643
631
|
if (tsCode.includes('```')) {
|
|
644
632
|
const cap = tsCode.match(/```.*\n([\s\S]+?)```/);
|
|
@@ -653,9 +641,9 @@ export function transformTSCodeEx(answer: any, activeLogic: any, context: any) {
|
|
|
653
641
|
let logicName = activeLogic.name;
|
|
654
642
|
const { app, nasl } = context;
|
|
655
643
|
if (activeLogic.parentNode instanceof nasl.BindEvent && activeLogic.parentNode.parentNode instanceof nasl.View) {
|
|
656
|
-
logicName =
|
|
644
|
+
logicName = `on_view_${activeLogic.name}`;
|
|
657
645
|
} else if (activeLogic.parentNode instanceof nasl.BindEvent && activeLogic.parentNode.parentNode instanceof nasl.ViewElement) {
|
|
658
|
-
logicName =
|
|
646
|
+
logicName = `on_${(activeLogic.parentNode).element.name}_${activeLogic.name}`;
|
|
659
647
|
} else {
|
|
660
648
|
logicName = activeLogic.name;
|
|
661
649
|
}
|
|
@@ -686,7 +674,7 @@ export function transformTSCodeToExpression(answer: any, context: any) {
|
|
|
686
674
|
}
|
|
687
675
|
const { app } = context;
|
|
688
676
|
app.emit('collect:start', { actionMsg: '自然语言生成代码' });
|
|
689
|
-
const body = logic
|
|
677
|
+
const { body } = logic;
|
|
690
678
|
app.emit('collect:end');
|
|
691
679
|
return body;
|
|
692
680
|
}
|