@lcap/nasl 3.8.2-beta.8 → 3.8.3-beta.1
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/ai-engineer.config.js +617 -0
- package/out/common/BaseNode.js +5 -3
- package/out/common/BaseNode.js.map +1 -1
- package/out/common/ComponentAPI.d.ts +9 -0
- package/out/concepts/AuthLogicForCallInterface__.js +21 -6
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
- package/out/concepts/BackendVariable__.js +16 -1
- package/out/concepts/BackendVariable__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +12 -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/BindStyle__.js +1 -1
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/BusinessComponent__.js +24 -8
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +21 -6
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallInterface__.js +2 -1
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +1 -0
- package/out/concepts/CallLogic__.js +32 -11
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +1 -0
- package/out/concepts/CallQueryComponent__.js +23 -12
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Destination__.js +11 -8
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +3 -2
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.js +1 -1
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Interface__.js +1 -1
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/Logic__.js +49 -17
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.js +19 -13
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js +37 -12
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.js +21 -6
- package/out/concepts/OverriddenLogic__.js.map +1 -1
- package/out/concepts/Param__.js +5 -4
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/QueryOrderByExpression__.d.ts +0 -1
- package/out/concepts/QueryOrderByExpression__.js +0 -1
- package/out/concepts/QueryOrderByExpression__.js.map +1 -1
- package/out/concepts/Structure__.js +5 -7
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/Variable__.js +5 -0
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +1 -0
- package/out/concepts/ViewElement__.js +17 -7
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +70 -14
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.processV2.js +78 -0
- package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.ui.js +40 -40
- package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
- package/out/generator/genBundleFiles.js +1 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/release-body/utils.js +1 -1
- package/out/natural/genNaturalTS.d.ts +45 -10
- package/out/natural/genNaturalTS.js +57 -33
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.js +6 -3
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +20 -7
- package/out/natural/getContext/index.js +143 -23
- package/out/natural/getContext/index.js.map +1 -1
- package/out/natural/getContext/naslStdlibMap.js +8 -8
- package/out/natural/getContext/naslStdlibMap.js.map +1 -1
- package/out/natural/tools.d.ts +16 -0
- package/out/natural/tools.js +110 -2
- package/out/natural/tools.js.map +1 -1
- package/out/natural/transformTS2UI.js +361 -304
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts +3 -5
- package/out/natural/transformTSCode.js +30 -1089
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/registerTransform.d.ts +7 -0
- package/out/natural/transforms/registerTransform.js +24 -0
- package/out/natural/transforms/registerTransform.js.map +1 -0
- package/out/natural/transforms/transform2LogicItem.d.ts +24 -0
- package/out/natural/transforms/transform2LogicItem.js +1240 -0
- package/out/natural/transforms/transform2LogicItem.js.map +1 -0
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -0
- package/out/natural/transforms/transform2TypeAnnotation.js +86 -0
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -0
- package/out/natural/transforms/utils.d.ts +8 -0
- package/out/natural/transforms/utils.js +59 -0
- package/out/natural/transforms/utils.js.map +1 -0
- package/out/server/getLogics.js +12 -12
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +11 -17
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.d.ts +2 -2
- package/out/server/naslServer.js +38 -18
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +5 -0
- package/out/server/translator.js.map +1 -1
- package/out/templator/block2nasl/jsx2nasl/index.d.ts +5 -0
- package/out/templator/block2nasl/jsx2nasl/index.js +15 -0
- package/out/templator/block2nasl/jsx2nasl/index.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts +3 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +213 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +14 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +201 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts +4 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js +186 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts +28 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +336 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/utils.d.ts +2 -0
- package/out/templator/block2nasl/jsx2nasl/utils.js +26 -0
- package/out/templator/block2nasl/jsx2nasl/utils.js.map +1 -0
- package/out/templator/block2nasl/transformBlock2Nasl.d.ts +10 -0
- package/out/templator/block2nasl/transformBlock2Nasl.js +122 -0
- package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -0
- package/out/templator/block2nasl/viewMergeBlock.d.ts +9 -0
- package/out/templator/block2nasl/viewMergeBlock.js +110 -0
- package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
- package/out/translator/types.d.ts +2 -0
- package/out/translator/utils.js +1 -1
- package/out/translator/utils.js.map +1 -1
- package/out/utils/index.js +0 -4
- package/out/utils/index.js.map +1 -1
- package/out/utils/language-cache/constant.d.ts +2 -1
- package/out/utils/language-cache/constant.js +1 -0
- package/out/utils/language-cache/constant.js.map +1 -1
- package/out/utils/language-cache/nasl.d.ts +1 -0
- package/out/utils/language-cache/nasl.js +9 -1
- package/out/utils/language-cache/nasl.js.map +1 -1
- package/package.json +6 -2
- package/sandbox/stdlib/nasl.processV2.ts +19 -0
- package/sandbox/stdlib/nasl.ui.ts +8 -8
- package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
- package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
- package/sandbox-natural/stdlib/nasl.ui.d.ts +78 -0
- package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
- package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
- package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
- package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
- package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +49 -43
- package/src/common/BaseNode.ts +5 -3
- package/src/common/ComponentAPI.ts +7 -0
- package/src/concepts/AuthLogicForCallInterface__.ts +23 -6
- package/src/concepts/BackendVariable__.ts +16 -1
- package/src/concepts/BindAttribute__.ts +18 -13
- package/src/concepts/BindDirective__.ts +1 -1
- package/src/concepts/BindStyle__.ts +1 -1
- package/src/concepts/BusinessComponent__.ts +26 -8
- package/src/concepts/BusinessLogic__.ts +23 -6
- package/src/concepts/CallInterface__.ts +2 -2
- package/src/concepts/CallLogic__.ts +50 -24
- package/src/concepts/CallQueryComponent__.ts +26 -12
- package/src/concepts/Destination__.ts +14 -12
- package/src/concepts/EntityProperty__.ts +5 -5
- package/src/concepts/Entity__.ts +1 -1
- package/src/concepts/Interface__.ts +1 -1
- package/src/concepts/Logic__.ts +62 -33
- package/src/concepts/MemberExpression__.ts +20 -13
- package/src/concepts/OqlQueryComponent__.ts +29 -5
- package/src/concepts/OverriddenLogic__.ts +23 -6
- package/src/concepts/Param__.ts +5 -4
- package/src/concepts/QueryOrderByExpression__.ts +0 -1
- package/src/concepts/Structure__.ts +5 -7
- package/src/concepts/Variable__.ts +9 -5
- package/src/concepts/ViewElement__.ts +25 -9
- package/src/concepts/View__.ts +97 -37
- package/src/concepts/basics/stdlib/nasl.processV2.ts +79 -0
- package/src/concepts/basics/stdlib/nasl.ui.ts +40 -40
- package/src/generator/genBundleFiles.ts +1 -1
- package/src/generator/release-body/utils.ts +1 -1
- package/src/natural/genNaturalTS.ts +88 -39
- package/src/natural/getContext/getUILib.ts +6 -3
- package/src/natural/getContext/index.ts +125 -23
- package/src/natural/getContext/naslStdlibMap.ts +8 -8
- package/src/natural/tools.ts +107 -2
- package/src/natural/transformTS2UI.ts +205 -147
- package/src/natural/transformTSCode.ts +29 -1055
- package/src/natural/transforms/registerTransform.ts +34 -0
- package/src/natural/transforms/transform2LogicItem.ts +1335 -0
- package/src/natural/transforms/transform2TypeAnnotation.ts +77 -0
- package/src/natural/transforms/utils.ts +25 -0
- package/src/server/getLogics.ts +12 -12
- package/src/server/getMemberIdentifier.ts +14 -14
- package/src/server/naslServer.ts +39 -19
- package/src/server/translator.ts +5 -0
- package/src/templator/block2nasl/jsx2nasl/index.ts +11 -0
- package/src/templator/block2nasl/jsx2nasl/transform-expression2nasl.ts +238 -0
- package/src/templator/block2nasl/jsx2nasl/transform-func2nasl.ts +241 -0
- package/src/templator/block2nasl/jsx2nasl/transform-tstype2nasl.ts +213 -0
- package/src/templator/block2nasl/jsx2nasl/transform-tsx2nasl.ts +422 -0
- package/src/templator/block2nasl/jsx2nasl/utils.ts +19 -0
- package/src/templator/block2nasl/transformBlock2Nasl.ts +99 -0
- package/src/templator/block2nasl/viewMergeBlock.ts +149 -0
- package/src/translator/types.ts +2 -0
- package/src/translator/utils.ts +1 -1
- package/src/utils/index.ts +0 -4
- package/src/utils/language-cache/constant.ts +1 -0
- package/src/utils/language-cache/nasl.ts +6 -0
- package/test/concepts/member-expression/__snapshots__/toJS.spec.ts.snap +1 -1
- package/test/concepts/member-expression/__snapshots__/toVue.spec.ts.snap +1 -1
- package/test/tdd/dataQuery/QueryFieldExpression/case1/ast.json +7 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case1/natural.ts.txt +1 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case2/ast.json +7 -0
- package/test/tdd/dataQuery/QueryFieldExpression/case2/natural.ts.txt +1 -0
- package/test/tdd/transform/case1/ast.json +243 -0
- package/test/tdd/transform/case1/natural.ts.md +20 -0
- package/test/tdd/transform/case2/ast.json +207 -0
- package/test/tdd/transform/case2/natural.ts.md +12 -0
- package/test/tdd.test.js +10 -0
- package/test/tdd.transform.test.js +38 -0
- package/test/utils.js +40 -0
- package/sandbox-natural/stdlib/nasl.core.ts +0 -36
- package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
- package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +0 -90
- package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
/* eslint-disable global-require */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
3
|
+
import { babelTypes, naslTypes, generate, DEBUG, throwError, tryParseTS } from './transforms/utils';
|
|
3
4
|
import { kebabCase, cloneDeep } from 'lodash';
|
|
4
5
|
import * as babel from '@babel/core';
|
|
5
|
-
import * as babelTypes from '@babel/types';
|
|
6
|
-
import generate from '@babel/generator';
|
|
7
|
-
import * as naslTypes from '../concepts';
|
|
8
6
|
import { genHash } from '../generator';
|
|
9
7
|
import { type ParseResult } from '@babel/parser';
|
|
10
|
-
|
|
11
|
-
const DEBUG = false;
|
|
12
|
-
function throwError(message: string) {
|
|
13
|
-
if (DEBUG) throw new Error(message);
|
|
14
|
-
else console.error(message);
|
|
15
|
-
}
|
|
8
|
+
import { transform2TypeAnnotation } from './transforms/transform2TypeAnnotation';
|
|
16
9
|
|
|
17
10
|
function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
|
|
18
11
|
if (node.type === 'MemberExpression')
|
|
@@ -61,83 +54,6 @@ function fixLogicNode(node: babelTypes.Node): void {
|
|
|
61
54
|
}
|
|
62
55
|
}
|
|
63
56
|
|
|
64
|
-
// 处理类型
|
|
65
|
-
function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotation {
|
|
66
|
-
if (!node) return null;
|
|
67
|
-
if (node.type === 'TSTypeReference') {
|
|
68
|
-
const typeName = (node.typeName as babelTypes.Identifier).name;
|
|
69
|
-
const primitiveType = naslTypes.primitiveTypeList.find((ta) => ta.typeName === typeName);
|
|
70
|
-
if ((node as any)?.typeNamespace) {
|
|
71
|
-
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
72
|
-
typeNamespace: (node as any).typeNamespace,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
|
|
77
|
-
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
78
|
-
typeNamespace: 'nasl.ui'
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (typeName === 'Any' || typeName === 'any') {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
if (typeName === 'Integer') {
|
|
86
|
-
return naslTypes.TypeAnnotation.createPrimitive('Long');
|
|
87
|
-
}
|
|
88
|
-
if (primitiveType) {
|
|
89
|
-
return naslTypes.TypeAnnotation.createPrimitive(typeName);
|
|
90
|
-
}
|
|
91
|
-
if (['List', 'Map', 'Current'].includes(typeName) && node?.typeParameters) {
|
|
92
|
-
return naslTypes.TypeAnnotation.createGeneric(typeName, {
|
|
93
|
-
typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
if (node?.typeName?.type === 'TSQualifiedName' && node?.typeParameters) {
|
|
97
|
-
const curTypeName = (node?.typeName as any)?.right?.name;
|
|
98
|
-
return naslTypes.TypeAnnotation.createGeneric(curTypeName, {
|
|
99
|
-
typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (!node.typeParameters) {
|
|
103
|
-
if (node?.typeName?.type === 'TSQualifiedName') {
|
|
104
|
-
const allTypeName = generate(node?.typeName?.left as any)?.code;
|
|
105
|
-
// 实体、枚举、结构体
|
|
106
|
-
if (/^app.dataSources|.enums|.structures|nasl.ui/.test(allTypeName)) {
|
|
107
|
-
const curTypeName = (node?.typeName as any)?.right?.name;
|
|
108
|
-
return naslTypes.TypeAnnotation.createReference(curTypeName, {
|
|
109
|
-
typeNamespace: allTypeName,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
114
|
-
typeNamespace: null,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
throwError(`Unhandled node ${node.type}`);
|
|
118
|
-
} else if (node.type === 'TSTypeLiteral') {
|
|
119
|
-
return naslTypes.TypeAnnotation.createTypeAnonymousStructure(node.members.map((member: babelTypes.TSPropertySignature) => new naslTypes.StructureProperty({
|
|
120
|
-
name: (member.key as babelTypes.Identifier).name,
|
|
121
|
-
typeAnnotation: transformTypeAnnotation(member.typeAnnotation.typeAnnotation),
|
|
122
|
-
})));
|
|
123
|
-
} else if (node.type === 'TSBooleanKeyword') {
|
|
124
|
-
return naslTypes.TypeAnnotation.createPrimitive('Boolean');
|
|
125
|
-
} else if (node.type === 'TSStringKeyword') {
|
|
126
|
-
return naslTypes.TypeAnnotation.createPrimitive('String');
|
|
127
|
-
} else if (node.type === 'TSNumberKeyword') {
|
|
128
|
-
return naslTypes.TypeAnnotation.createPrimitive('Double');
|
|
129
|
-
} else if (node.type === 'TSUnionType') {
|
|
130
|
-
const union = naslTypes.TypeAnnotation.createPrimitive('Union');
|
|
131
|
-
union.typeArguments = [];
|
|
132
|
-
node.types.forEach((curType) => {
|
|
133
|
-
union.typeArguments.push(transformTypeAnnotation(curType));
|
|
134
|
-
});
|
|
135
|
-
return union;
|
|
136
|
-
} else {
|
|
137
|
-
throwError(`Unhandled node ${node.type}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
57
|
// 处理参数
|
|
142
58
|
function transformParam(node: babelTypes.Identifier): naslTypes.Param {
|
|
143
59
|
const typeAnnotation = (node.typeAnnotation as babelTypes.TSTypeAnnotation)?.typeAnnotation;
|
|
@@ -145,8 +61,25 @@ function transformParam(node: babelTypes.Identifier): naslTypes.Param {
|
|
|
145
61
|
if (exclude.includes(node.name)) return null;
|
|
146
62
|
return new naslTypes.Param({
|
|
147
63
|
name: node.name,
|
|
148
|
-
typeAnnotation: typeAnnotation ?
|
|
64
|
+
typeAnnotation: typeAnnotation ? transform2TypeAnnotation(typeAnnotation) : null,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 处理生命周期函数
|
|
69
|
+
function transformLifecycle(node: babelTypes.ObjectExpression): Array<naslTypes.BindEvent> {
|
|
70
|
+
const bindEvents: Array<naslTypes.BindEvent> = []
|
|
71
|
+
node.properties.forEach((property: any) => {
|
|
72
|
+
const eventName = property?.key?.name?.replace(/^on/, '')?.toLowerCase();
|
|
73
|
+
const bindEvent = new naslTypes.BindEvent({ name: eventName });
|
|
74
|
+
property.value.elements.forEach((element: any) => {
|
|
75
|
+
let logicName = element?.id?.name || '';
|
|
76
|
+
logicName = bindEvent.getLogicUniqueName(logicName);
|
|
77
|
+
const curLogic: any = transformNode2Logic(element, logicName, 'view_logic');
|
|
78
|
+
bindEvent.addLogic(curLogic);
|
|
79
|
+
});
|
|
80
|
+
bindEvents.push(bindEvent);
|
|
149
81
|
});
|
|
82
|
+
return bindEvents;
|
|
150
83
|
}
|
|
151
84
|
|
|
152
85
|
// 处理变量
|
|
@@ -158,7 +91,7 @@ function transformVariableDeclaration(node: babelTypes.VariableDeclaration): nas
|
|
|
158
91
|
const varTypeAnnotation = ((decl.id as babelTypes.Identifier).typeAnnotation as babelTypes.TSTypeAnnotation)?.typeAnnotation;
|
|
159
92
|
newNode = new naslTypes.Variable({
|
|
160
93
|
name: variableName,
|
|
161
|
-
typeAnnotation: varTypeAnnotation &&
|
|
94
|
+
typeAnnotation: varTypeAnnotation && transform2TypeAnnotation(varTypeAnnotation),
|
|
162
95
|
});
|
|
163
96
|
if (decl.init) {
|
|
164
97
|
if (decl.init.type !== 'ArrayExpression' && decl.init.type !== 'ObjectExpression') {
|
|
@@ -209,7 +142,7 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
209
142
|
if (calleeName === 'NewList') {
|
|
210
143
|
return new naslTypes.NewList({
|
|
211
144
|
typeAnnotation: naslTypes.TypeAnnotation.createGeneric('List', {
|
|
212
|
-
typeArguments: node?.typeParameters?.params.map(
|
|
145
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation),
|
|
213
146
|
}),
|
|
214
147
|
items: node?.arguments?.[0]?.elements?.map((arg: any) => transformNode2Expression(arg, type)),
|
|
215
148
|
});
|
|
@@ -223,7 +156,7 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
223
156
|
});
|
|
224
157
|
return new naslTypes.NewMap({
|
|
225
158
|
typeAnnotation: naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
226
|
-
typeArguments: node?.typeParameters?.params.map(
|
|
159
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation),
|
|
227
160
|
}),
|
|
228
161
|
keys,
|
|
229
162
|
values,
|
|
@@ -389,6 +322,14 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
389
322
|
return node;
|
|
390
323
|
}
|
|
391
324
|
|
|
325
|
+
function fixExpression(arg: any, type?: string) {
|
|
326
|
+
let expression = transformNode2Expression(arg, type);
|
|
327
|
+
if (expression?.concept === 'Identifier' && expression?.name === 'undefined') {
|
|
328
|
+
expression = undefined;
|
|
329
|
+
}
|
|
330
|
+
return expression;
|
|
331
|
+
}
|
|
332
|
+
|
|
392
333
|
// 处理表达式
|
|
393
334
|
function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
394
335
|
if (!node) return null;
|
|
@@ -408,12 +349,12 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
408
349
|
calleeNamespace: `elements.${(callee[1] as babelTypes.Identifier).name}.logics`,
|
|
409
350
|
calleeName: (callee[2] as babelTypes.Identifier).name,
|
|
410
351
|
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
411
|
-
expression:
|
|
352
|
+
expression: fixExpression(arg, type),
|
|
412
353
|
})) as naslTypes.Argument[],
|
|
413
354
|
});
|
|
414
355
|
}
|
|
415
356
|
if (callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity')) {
|
|
416
|
-
const entityName = callee[0].name.replace(/Entity
|
|
357
|
+
const entityName = callee[0].name.replace(/Entity/, '');
|
|
417
358
|
return new naslTypes.CallLogic({
|
|
418
359
|
calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
|
|
419
360
|
calleeName: (callee[1] as babelTypes.Identifier).name,
|
|
@@ -451,7 +392,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
451
392
|
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
452
393
|
expression: transformNode2Expression(arg, type),
|
|
453
394
|
})) as naslTypes.Argument[],
|
|
454
|
-
typeArguments: node?.typeParameters?.params.map((curType: any) =>
|
|
395
|
+
typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType })),
|
|
455
396
|
});
|
|
456
397
|
};
|
|
457
398
|
if (calleeName.startsWith('nasl.util.')) {
|
|
@@ -481,8 +422,8 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
481
422
|
expression: transformNode2Expression(arg, type),
|
|
482
423
|
keyword: `str${index + 1}`,
|
|
483
424
|
})) as naslTypes.Argument[],
|
|
484
|
-
typeArguments: node?.typeParameters?.params.map(
|
|
485
|
-
// typeArguments: node?.typeParameters?.params.map((curType: any) =>
|
|
425
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation),
|
|
426
|
+
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
486
427
|
});
|
|
487
428
|
return nodeElement;
|
|
488
429
|
}
|
|
@@ -492,13 +433,22 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
492
433
|
const nsArr = namespace.split('.').map((item) => item.replace(/_view$/, ''));
|
|
493
434
|
const pageType = nsArr.shift();
|
|
494
435
|
const viewName = nsArr.pop();
|
|
436
|
+
const newArguments = node?.arguments?.slice(1);
|
|
437
|
+
let argument = [] as naslTypes.Argument[];
|
|
438
|
+
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
439
|
+
argument = newArguments?.[0]?.properties?.map((property: any) => new naslTypes.Argument({
|
|
440
|
+
keyword: property?.key?.name,
|
|
441
|
+
expression: fixExpression(property?.value, type),
|
|
442
|
+
})) as naslTypes.Argument[];
|
|
443
|
+
} else {
|
|
444
|
+
argument = node.arguments.slice(1).map((arg) => new naslTypes.Argument({
|
|
445
|
+
expression: fixExpression(arg, type),
|
|
446
|
+
})) as naslTypes.Argument[];
|
|
447
|
+
}
|
|
495
448
|
return new naslTypes.Destination({
|
|
496
|
-
viewNamespace: `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`,
|
|
497
|
-
viewName,
|
|
498
|
-
|
|
499
|
-
arguments: node.arguments.slice(1).map((arg) => new naslTypes.Argument({
|
|
500
|
-
expression: transformNode2Expression(arg, type),
|
|
501
|
-
})) as naslTypes.Argument[],
|
|
449
|
+
viewNamespace: `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`,
|
|
450
|
+
viewName,
|
|
451
|
+
arguments: argument,
|
|
502
452
|
});
|
|
503
453
|
}
|
|
504
454
|
return new naslTypes.CallLogic({
|
|
@@ -545,7 +495,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
545
495
|
index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1] as babelTypes.Identifier) : new naslTypes.Param({
|
|
546
496
|
name: 'index', typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
547
497
|
}),
|
|
548
|
-
body: (arrowFunction.body as babelTypes.BlockStatement).body.map((item) => transformNode2Expression(item
|
|
498
|
+
body: (arrowFunction.body as babelTypes.BlockStatement).body.map((item) => transformNode2Expression(item)).filter((item) => !!item && item?.concept !== 'Variable'),
|
|
549
499
|
});
|
|
550
500
|
return nodeElement;
|
|
551
501
|
}
|
|
@@ -562,7 +512,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
562
512
|
index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1] as babelTypes.Identifier) : new naslTypes.Param({
|
|
563
513
|
name: 'index', typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
564
514
|
}),
|
|
565
|
-
body: (arrowFunction.body as babelTypes.BlockStatement).body.map((item) => transformNode2Expression(item
|
|
515
|
+
body: (arrowFunction.body as babelTypes.BlockStatement).body.map((item) => transformNode2Expression(item)).filter((item) => !!item && item?.concept !== 'Variable'),
|
|
566
516
|
});
|
|
567
517
|
return nodeElement;
|
|
568
518
|
}
|
|
@@ -580,7 +530,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
580
530
|
} else if (/^app.dataSources|app.logics/.test(calleeName)) {
|
|
581
531
|
if (calleeName?.includes('.entities.')) {
|
|
582
532
|
const calleeNamespace = generate((node?.callee as any)?.object?.object)?.code;
|
|
583
|
-
const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity
|
|
533
|
+
const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity/, '');
|
|
584
534
|
return new naslTypes.CallLogic({
|
|
585
535
|
calleeNamespace: `${calleeNamespace}.${entityName}.logics`,
|
|
586
536
|
calleeName: (node?.callee as any)?.property?.name,
|
|
@@ -616,7 +566,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
616
566
|
});
|
|
617
567
|
}
|
|
618
568
|
return new naslTypes.CallLogic({
|
|
619
|
-
calleeNamespace:
|
|
569
|
+
calleeNamespace: ``,
|
|
620
570
|
calleeName,
|
|
621
571
|
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
622
572
|
expression: transformNode2Expression(arg, type),
|
|
@@ -629,7 +579,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
629
579
|
arguments: node?.arguments?.map((arg: any) => arg?.properties?.map((item: any) => new naslTypes.Argument({
|
|
630
580
|
keyword: item?.key?.name,
|
|
631
581
|
expression: transformNode2Expression(item?.value, type),
|
|
632
|
-
}))).flat() as naslTypes.Argument[],
|
|
582
|
+
})) || []).flat() as naslTypes.Argument[] || [],
|
|
633
583
|
});
|
|
634
584
|
} else if (/connector./.test(calleeName)) {
|
|
635
585
|
const flatCalleeKey = generate(node?.callee as any)?.code;
|
|
@@ -697,6 +647,14 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
697
647
|
return switchStatement;
|
|
698
648
|
}
|
|
699
649
|
throwError(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
650
|
+
} else if (/nasl.auth./.test(calleeName)) {
|
|
651
|
+
return new naslTypes.CallLogic({
|
|
652
|
+
calleeNamespace: 'nasl.auth',
|
|
653
|
+
calleeName: (callee[callee.length - 1] as babelTypes.Identifier).name,
|
|
654
|
+
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
655
|
+
expression: transformNode2Expression(arg, type),
|
|
656
|
+
})) as naslTypes.Argument[],
|
|
657
|
+
});
|
|
700
658
|
} else {
|
|
701
659
|
throwError(`Unhandled node ${callee.map((item: babelTypes.Identifier) => item.name).join('.')} ${node.type}`);
|
|
702
660
|
}
|
|
@@ -783,6 +741,25 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
783
741
|
}),
|
|
784
742
|
});
|
|
785
743
|
}
|
|
744
|
+
if (calleeName?.includes('nasl.auth.')) {
|
|
745
|
+
return new naslTypes.MemberExpression({
|
|
746
|
+
object: new naslTypes.Identifier({
|
|
747
|
+
namespace: 'nasl.auth',
|
|
748
|
+
name: (callee?.[2] as babelTypes.Identifier)?.name,
|
|
749
|
+
}),
|
|
750
|
+
property: new naslTypes.Identifier({
|
|
751
|
+
name: (callee?.[3] as babelTypes.Identifier)?.name,
|
|
752
|
+
}),
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
const regex = /^(app\..+?)\.variables\.(.+)$/;
|
|
756
|
+
if (regex.test(calleeName)) {
|
|
757
|
+
const [, namespace, variableName] = calleeName.match(regex);
|
|
758
|
+
return new naslTypes.Identifier({
|
|
759
|
+
name: String(variableName),
|
|
760
|
+
namespace: `${namespace}.variables`
|
|
761
|
+
});
|
|
762
|
+
}
|
|
786
763
|
if (node.property.type === 'NumericLiteral') {
|
|
787
764
|
return new naslTypes.CallFunction({
|
|
788
765
|
calleeNamespace: 'nasl.util',
|
|
@@ -971,29 +948,55 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
971
948
|
}
|
|
972
949
|
|
|
973
950
|
// 处理逻辑
|
|
974
|
-
function transformNode2Logic(node: babelTypes.FunctionDeclaration, name
|
|
951
|
+
function transformNode2Logic(node: babelTypes.FunctionDeclaration, name: string, type: string): naslTypes.Logic {
|
|
975
952
|
const parameters: babelTypes.Identifier[] = node.params as babelTypes.Identifier[];
|
|
976
953
|
const statements: babelTypes.Statement[] = node.body.body;
|
|
977
954
|
|
|
978
955
|
const curLogic: any = new naslTypes.Logic({ name: name ?? node.id.name });
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
956
|
+
if (type !== 'event_logic') {
|
|
957
|
+
parameters.forEach((item: babelTypes.Identifier) => {
|
|
958
|
+
const param = transformParam(item);
|
|
959
|
+
if (param && param.name !== 'event' && !curLogic.params.find((_: any) => _.name === param.name)) curLogic.addParam(param);
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
statements?.forEach((item) => {
|
|
984
963
|
if (item.type === 'ReturnStatement' && item?.argument) {
|
|
985
|
-
if (
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
964
|
+
if (type === 'view_logic') {
|
|
965
|
+
if (item.argument?.type === 'Identifier') {
|
|
966
|
+
if (!curLogic.returns.length) {
|
|
967
|
+
const curVariable = curLogic?.variables?.find((it: any) => it.name === (item?.argument as any)?.name);
|
|
968
|
+
if (curVariable) {
|
|
969
|
+
curLogic.variables = curLogic?.variables?.filter((it: any) => it.name !== (item?.argument as any)?.name);
|
|
970
|
+
curLogic.addReturn(curVariable as any);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
} else {
|
|
974
|
+
if (!curLogic.returns.length) {
|
|
975
|
+
curLogic.returns.push(new naslTypes.Return({
|
|
976
|
+
name: 'result',
|
|
977
|
+
}));
|
|
978
|
+
}
|
|
979
|
+
const logicItem = new naslTypes.Assignment({
|
|
980
|
+
left: new naslTypes.Identifier({
|
|
981
|
+
name: curLogic.returns[0].name,
|
|
982
|
+
}),
|
|
983
|
+
right: transformNode2Expression(item.argument, 'logic')
|
|
984
|
+
});
|
|
985
|
+
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
986
|
+
}
|
|
987
|
+
} else {
|
|
988
|
+
if (item.argument?.type !== 'Identifier') {
|
|
989
|
+
curLogic.addVariable('tempVar');
|
|
990
|
+
const logicItem = new naslTypes.Assignment({
|
|
991
|
+
left: new naslTypes.Identifier({
|
|
992
|
+
name: 'tempVar',
|
|
993
|
+
}),
|
|
994
|
+
right: transformNode2Expression(item.argument, 'logic')
|
|
995
|
+
});
|
|
996
|
+
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
997
|
+
}
|
|
989
998
|
}
|
|
990
|
-
|
|
991
|
-
left: new naslTypes.Identifier({
|
|
992
|
-
name: curLogic.returns[0].name,
|
|
993
|
-
}),
|
|
994
|
-
right: transformNode2Expression(item.argument, 'logic')
|
|
995
|
-
});
|
|
996
|
-
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
999
|
+
|
|
997
1000
|
} else {
|
|
998
1001
|
let logicItem = transformNode2Expression(item, 'logic');
|
|
999
1002
|
if (logicItem) {
|
|
@@ -1015,6 +1018,7 @@ function transformNode2Logic(node: babelTypes.FunctionDeclaration, name?: string
|
|
|
1015
1018
|
|
|
1016
1019
|
// 处理属性
|
|
1017
1020
|
function transformNode2Attribute(node: any): any {
|
|
1021
|
+
if (!node?.value || !node?.key) return {};
|
|
1018
1022
|
let item = {} as any;
|
|
1019
1023
|
let newNode = {} as any;
|
|
1020
1024
|
if (['StringLiteral', 'NumericLiteral'].includes(node.value.type)) {
|
|
@@ -1037,8 +1041,35 @@ function transformNode2Attribute(node: any): any {
|
|
|
1037
1041
|
sync: true,
|
|
1038
1042
|
expression: transformNode2Expression(node.value.arguments[0]),
|
|
1039
1043
|
};
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1044
|
+
} else if (['destination'].includes(node.key.name)) {
|
|
1045
|
+
const namespace = node?.value?.arguments?.[0]?.value;
|
|
1046
|
+
const nsArr = namespace.split('.').map((it: string) => it.replace(/_view$/, ''));
|
|
1047
|
+
const pageType = nsArr.shift();
|
|
1048
|
+
const viewName = nsArr.pop();
|
|
1049
|
+
const newArguments = node?.value?.arguments?.slice(1);
|
|
1050
|
+
let argument = [] as naslTypes.Argument[];
|
|
1051
|
+
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
1052
|
+
argument = newArguments?.[0]?.properties?.map((property: any) => new naslTypes.Argument({
|
|
1053
|
+
keyword: property?.key?.name,
|
|
1054
|
+
expression: fixExpression(property?.value),
|
|
1055
|
+
})) as naslTypes.Argument[];
|
|
1056
|
+
} else {
|
|
1057
|
+
argument = node?.arguments?.slice(1)?.map((arg: any) => new naslTypes.Argument({
|
|
1058
|
+
expression: fixExpression(arg),
|
|
1059
|
+
})) as naslTypes.Argument[];
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
const destination = new naslTypes.Destination({
|
|
1063
|
+
viewNamespace: `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((it: any) => `.${it}.views`)?.join('')}`,
|
|
1064
|
+
viewName,
|
|
1065
|
+
arguments: argument,
|
|
1066
|
+
});
|
|
1067
|
+
item = {
|
|
1068
|
+
name: node?.key?.name,
|
|
1069
|
+
type: 'dynamic',
|
|
1070
|
+
destination,
|
|
1071
|
+
};
|
|
1072
|
+
} else {
|
|
1042
1073
|
// ['TemplateLiteral', 'BooleanLiteral', 'NullLiteral', 'CallExpression']
|
|
1043
1074
|
item = {
|
|
1044
1075
|
name: node.key.name,
|
|
@@ -1086,7 +1117,7 @@ function transformNode2ViewElement(node: babelTypes.NewExpression, componentName
|
|
|
1086
1117
|
const bindEvent = new naslTypes.BindEvent({ name: eventName });
|
|
1087
1118
|
prop.value.elements.forEach((element: any) => {
|
|
1088
1119
|
const logicName = bindEvent.getLogicUniqueName();
|
|
1089
|
-
const curLogic: any = transformNode2Logic(element, logicName);
|
|
1120
|
+
const curLogic: any = transformNode2Logic(element, logicName, 'event_logic');
|
|
1090
1121
|
bindEvent.addLogic(curLogic);
|
|
1091
1122
|
});
|
|
1092
1123
|
newViewElement.addBindEvent(bindEvent);
|
|
@@ -1095,7 +1126,7 @@ function transformNode2ViewElement(node: babelTypes.NewExpression, componentName
|
|
|
1095
1126
|
const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
|
|
1096
1127
|
const bindEvent = new naslTypes.BindEvent({ name: eventName });
|
|
1097
1128
|
const logicName = bindEvent.getLogicUniqueName();
|
|
1098
|
-
bindEvent.addLogic(transformNode2Logic(prop.value, logicName));
|
|
1129
|
+
bindEvent.addLogic(transformNode2Logic(prop.value, logicName, 'event_logic'));
|
|
1099
1130
|
newViewElement.addBindEvent(bindEvent);
|
|
1100
1131
|
} else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.type) && ['ArrayExpression'].includes(prop.value.body?.type)) {
|
|
1101
1132
|
// 子组件
|
|
@@ -1163,18 +1194,24 @@ function transformNode2ViewElement(node: babelTypes.NewExpression, componentName
|
|
|
1163
1194
|
/**
|
|
1164
1195
|
* 转换Node为View下的构件
|
|
1165
1196
|
*/
|
|
1166
|
-
function transformNode2ViewConstruct(node: babelTypes.Node): naslTypes.ViewElement | naslTypes.Variable | naslTypes.Logic | naslTypes.View {
|
|
1197
|
+
function transformNode2ViewConstruct(node: babelTypes.Node): naslTypes.ViewElement | naslTypes.Variable | naslTypes.Logic | naslTypes.View | Array<naslTypes.BindEvent> {
|
|
1167
1198
|
// console.log("lemon ~ transformNode2ViewConstruct ~ node:", node);
|
|
1168
1199
|
|
|
1169
1200
|
// 变量声明
|
|
1170
1201
|
if (node.type === 'VariableDeclaration') {
|
|
1202
|
+
const declList = node?.declarations || [];
|
|
1203
|
+
const declListFirstNodde = declList[0];
|
|
1204
|
+
const variableName = (declListFirstNodde as any)?.id?.name;
|
|
1205
|
+
if(variableName === '$lifecycles' && declListFirstNodde.init) {
|
|
1206
|
+
return transformLifecycle(declListFirstNodde.init as any);
|
|
1207
|
+
}
|
|
1171
1208
|
return transformVariableDeclaration(node);
|
|
1172
1209
|
}
|
|
1173
1210
|
|
|
1174
1211
|
// 页面逻辑
|
|
1175
1212
|
if (node.type === 'FunctionDeclaration') {
|
|
1176
1213
|
const logicName = node.id.name.replace(/^viewLogic_/, '');
|
|
1177
|
-
return transformNode2Logic(node, logicName);
|
|
1214
|
+
return transformNode2Logic(node, logicName, 'view_logic');
|
|
1178
1215
|
}
|
|
1179
1216
|
|
|
1180
1217
|
if (node.type === 'ExpressionStatement') {
|
|
@@ -1209,19 +1246,28 @@ function transformNode2ViewConstruct(node: babelTypes.Node): naslTypes.ViewEleme
|
|
|
1209
1246
|
} else {
|
|
1210
1247
|
properties?.[3].value.elements.forEach((element: any) => {
|
|
1211
1248
|
let newNode = {} as any;
|
|
1249
|
+
const propertiesMap = ['BindDirective', 'BindStyle', 'BindAttribute'];
|
|
1212
1250
|
if (properties?.[2].value.value === 'ViewElement') {
|
|
1213
1251
|
newNode = transformNode2ViewConstruct(element);
|
|
1214
|
-
} else if (properties?.[2]
|
|
1252
|
+
} else if (propertiesMap.includes(properties?.[2]?.value?.value)) {
|
|
1215
1253
|
newNode = transformNode2Attribute({ key: element.left, value: element.right });
|
|
1254
|
+
} else if (properties?.[2]?.value?.value === 'BindEvent') {
|
|
1255
|
+
const eventName = element?.left?.name?.replace(/^on/, '')?.toLowerCase();
|
|
1256
|
+
const bindEvent = new naslTypes.BindEvent({ name: eventName });
|
|
1257
|
+
const logicName = bindEvent.getLogicUniqueName();
|
|
1258
|
+
bindEvent.addLogic(transformNode2Logic(element?.right?.elements[0], logicName, 'event_logic'));
|
|
1259
|
+
newNode = bindEvent;
|
|
1260
|
+
}
|
|
1261
|
+
if (newNode) {
|
|
1262
|
+
const newNodeBackup = cloneDeep(newNode);
|
|
1263
|
+
(newNode as any).aiParams = {
|
|
1264
|
+
action: properties?.[0].value.value,
|
|
1265
|
+
selectedNodeName: properties?.[1].value.value,
|
|
1266
|
+
concept: properties?.[2].value.value,
|
|
1267
|
+
object: newNodeBackup
|
|
1268
|
+
};
|
|
1269
|
+
newViewElement.push(newNode);
|
|
1216
1270
|
}
|
|
1217
|
-
const newNodeBackup = cloneDeep(newNode);
|
|
1218
|
-
(newNode as any).aiParams = {
|
|
1219
|
-
action: properties?.[0].value.value,
|
|
1220
|
-
selectedNodeName: properties?.[1].value.value,
|
|
1221
|
-
concept: properties?.[2].value.value,
|
|
1222
|
-
object: newNodeBackup
|
|
1223
|
-
};
|
|
1224
|
-
newViewElement.push(newNode);
|
|
1225
1271
|
});
|
|
1226
1272
|
}
|
|
1227
1273
|
});
|
|
@@ -1246,24 +1292,28 @@ function transformNode2View(node: babelTypes.FunctionDeclaration, root?: ParseRe
|
|
|
1246
1292
|
}
|
|
1247
1293
|
|
|
1248
1294
|
const view = new naslTypes.View();
|
|
1249
|
-
parameters
|
|
1295
|
+
parameters?.forEach((item) => {
|
|
1250
1296
|
const param = transformParam(item);
|
|
1297
|
+
view.params = view.params || [];
|
|
1251
1298
|
param && view.params.push(param);
|
|
1252
1299
|
});
|
|
1253
1300
|
|
|
1254
1301
|
const json: any = [];
|
|
1255
|
-
statements
|
|
1302
|
+
statements?.forEach((item) => {
|
|
1256
1303
|
const viewItem = transformNode2ViewConstruct(item) as any;
|
|
1257
1304
|
if (item.type === 'ReturnStatement' && item?.argument?.type === 'CallExpression') {
|
|
1258
1305
|
const action = (item.argument as any)?.callee?.name;
|
|
1259
1306
|
const selectedNodeName = (item.argument as any).arguments?.[0]?.property?.name;
|
|
1260
|
-
|
|
1261
|
-
|
|
1307
|
+
if (viewItem) {
|
|
1308
|
+
const newNodeBackup = cloneDeep(viewItem);
|
|
1309
|
+
(viewItem as any).aiParams = { selectedNodeName, action, concept: 'ViewElement', object: newNodeBackup };
|
|
1310
|
+
}
|
|
1262
1311
|
}
|
|
1263
1312
|
if (item.type === 'ReturnStatement' && item?.argument?.type === 'ArrayExpression') {
|
|
1264
1313
|
viewItem?.forEach((element: any) => {
|
|
1265
1314
|
if (element.aiParams) json.push(element.aiParams);
|
|
1266
|
-
|
|
1315
|
+
if (element?.concept === 'ViewElement')
|
|
1316
|
+
view.addViewElement(element);
|
|
1267
1317
|
});
|
|
1268
1318
|
}
|
|
1269
1319
|
if (viewItem?.concept === 'Variable') {
|
|
@@ -1276,6 +1326,12 @@ function transformNode2View(node: babelTypes.FunctionDeclaration, root?: ParseRe
|
|
|
1276
1326
|
view.addViewElement(viewItem);
|
|
1277
1327
|
if (viewItem.aiParams) json.push(viewItem.aiParams);
|
|
1278
1328
|
}
|
|
1329
|
+
// 生命周期函数
|
|
1330
|
+
if(item.type === 'VariableDeclaration' && Array.isArray(viewItem) && viewItem[0]?.concept === 'BindEvent') {
|
|
1331
|
+
viewItem.forEach((bindEvent: any) => {
|
|
1332
|
+
view.addBindEvent(bindEvent);
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1279
1335
|
});
|
|
1280
1336
|
// console.log("lemon ~ 转换出的 view:", view);
|
|
1281
1337
|
return { view: view.toJSON(), json };
|
|
@@ -1302,8 +1358,8 @@ const transformTS2View = (tsCode: string): any => {
|
|
|
1302
1358
|
return transformNode2View(func, root);
|
|
1303
1359
|
};
|
|
1304
1360
|
|
|
1305
|
-
const handleNodeName = (curView: any, object: any) => {
|
|
1306
|
-
const list = [];
|
|
1361
|
+
const handleNodeName = (curView: any, object: any, memory?: any) => {
|
|
1362
|
+
const list = [...memory || []];
|
|
1307
1363
|
if (object.concept === 'ViewElement') {
|
|
1308
1364
|
const oldName = object.name;
|
|
1309
1365
|
const newName = curView?.getViewElementUniqueNameOld(oldName);
|
|
@@ -1313,11 +1369,13 @@ const handleNodeName = (curView: any, object: any) => {
|
|
|
1313
1369
|
}
|
|
1314
1370
|
if (object?.children?.length) {
|
|
1315
1371
|
object.children.forEach((child: any) => {
|
|
1316
|
-
handleNodeName(curView, child);
|
|
1372
|
+
const { list: childList } = handleNodeName(curView, child, list);
|
|
1373
|
+
// 去重并合并
|
|
1374
|
+
list.push(...childList?.filter((item: any) => !list?.find((it: any) => it.oldName === item.oldName)));
|
|
1317
1375
|
});
|
|
1318
1376
|
}
|
|
1319
1377
|
}
|
|
1320
|
-
return {
|
|
1378
|
+
return { list };
|
|
1321
1379
|
};
|
|
1322
1380
|
|
|
1323
1381
|
export function tryTransformTS2UI(tsCode: string, curView?: any): any {
|