@lcap/nasl 3.9.0-beta.2 → 3.9.0-beta.20
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/engine/utils.d.ts +0 -5
- package/out/automate/engine/utils.d.ts.map +1 -1
- package/out/automate/engine/utils.js +1 -123
- package/out/automate/engine/utils.js.map +1 -1
- package/out/automate/upgrader/2.18.js +1 -1
- package/out/automate/upgrader/2.18.js.map +1 -1
- package/out/common/Command.js +1 -1
- package/out/common/Command.js.map +1 -1
- package/out/common/Messager.d.ts.map +1 -1
- package/out/common/Messager.js +15 -5
- package/out/common/Messager.js.map +1 -1
- package/out/config.d.ts +2 -0
- package/out/config.d.ts.map +1 -1
- package/out/config.js +5 -2
- package/out/config.js.map +1 -1
- package/out/generator/annotation/full.d.ts +6 -0
- package/out/generator/annotation/full.d.ts.map +1 -0
- package/out/generator/annotation/full.js +28 -0
- package/out/generator/annotation/full.js.map +1 -0
- package/out/generator/annotation/incremental.d.ts +7 -0
- package/out/generator/annotation/incremental.d.ts.map +1 -0
- package/out/generator/annotation/incremental.js +145 -0
- package/out/generator/annotation/incremental.js.map +1 -0
- package/out/generator/annotation/index.d.ts +5 -0
- package/out/generator/annotation/index.d.ts.map +1 -0
- package/out/generator/annotation/index.js +21 -0
- package/out/generator/annotation/index.js.map +1 -0
- package/out/generator/annotation/types.d.ts +14 -0
- package/out/generator/annotation/types.d.ts.map +1 -0
- package/out/generator/annotation/types.js +3 -0
- package/out/generator/annotation/types.js.map +1 -0
- package/out/generator/annotation/utils.d.ts +14 -0
- package/out/generator/annotation/utils.d.ts.map +1 -0
- package/out/generator/annotation/utils.js +51 -0
- package/out/generator/annotation/utils.js.map +1 -0
- package/out/generator/compileComponent.d.ts.map +1 -1
- package/out/generator/compileComponent.js +2 -0
- package/out/generator/compileComponent.js.map +1 -1
- package/out/generator/genBundleFiles.d.ts +5 -2
- package/out/generator/genBundleFiles.d.ts.map +1 -1
- package/out/generator/genBundleFiles.js +42 -31
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/index.d.ts +2 -0
- package/out/generator/index.d.ts.map +1 -1
- package/out/generator/index.js +2 -0
- package/out/generator/index.js.map +1 -1
- package/out/generator/permission.d.ts.map +1 -1
- package/out/generator/permission.js +25 -5
- package/out/generator/permission.js.map +1 -1
- package/out/generator/release-body/body.d.ts +3 -1
- package/out/generator/release-body/body.d.ts.map +1 -1
- package/out/generator/release-body/body.js +40 -28
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/data.d.ts +1 -0
- package/out/generator/release-body/data.d.ts.map +1 -1
- package/out/generator/release-body/data.js +10 -2
- package/out/generator/release-body/data.js.map +1 -1
- package/out/generator/release-body/internal.d.ts.map +1 -1
- package/out/generator/release-body/utils.d.ts +4 -3
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +60 -10
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/generator/ui-library-declaration/basic.d.ts +7 -0
- package/out/generator/ui-library-declaration/basic.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/basic.js +114 -0
- package/out/generator/ui-library-declaration/basic.js.map +1 -0
- package/out/generator/ui-library-declaration/custom.d.ts +11 -0
- package/out/generator/ui-library-declaration/custom.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/custom.js +149 -0
- package/out/generator/ui-library-declaration/custom.js.map +1 -0
- package/out/generator/ui-library-declaration/dependency.d.ts +8 -0
- package/out/generator/ui-library-declaration/dependency.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/dependency.js +169 -0
- package/out/generator/ui-library-declaration/dependency.js.map +1 -0
- package/out/generator/ui-library-declaration/format.d.ts +30 -0
- package/out/generator/ui-library-declaration/format.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/format.js +382 -0
- package/out/generator/ui-library-declaration/format.js.map +1 -0
- package/out/generator/ui-library-declaration/index.d.ts +3 -0
- package/out/generator/ui-library-declaration/index.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/index.js +19 -0
- package/out/generator/ui-library-declaration/index.js.map +1 -0
- package/out/generator/ui-library-declaration/manifest.d.ts +5 -0
- package/out/generator/ui-library-declaration/manifest.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/manifest.js +27 -0
- package/out/generator/ui-library-declaration/manifest.js.map +1 -0
- package/out/generator/ui-library-declaration/material.d.ts +6 -0
- package/out/generator/ui-library-declaration/material.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/material.js +90 -0
- package/out/generator/ui-library-declaration/material.js.map +1 -0
- package/out/generator/ui-library-declaration/types.d.ts +458 -0
- package/out/generator/ui-library-declaration/types.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/types.js +3 -0
- package/out/generator/ui-library-declaration/types.js.map +1 -0
- package/out/generator/ui-library-declaration/utils.d.ts +3 -0
- package/out/generator/ui-library-declaration/utils.d.ts.map +1 -0
- package/out/generator/ui-library-declaration/utils.js +20 -0
- package/out/generator/ui-library-declaration/utils.js.map +1 -0
- package/out/manager/diagnostic.d.ts +2 -0
- package/out/manager/diagnostic.d.ts.map +1 -1
- package/out/manager/diagnostic.js +9 -0
- package/out/manager/diagnostic.js.map +1 -1
- package/out/natural/genNaturalTS.d.ts +45 -10
- package/out/natural/genNaturalTS.d.ts.map +1 -1
- package/out/natural/genNaturalTS.js +57 -33
- package/out/natural/genNaturalTS.js.map +1 -1
- package/out/natural/getContext/getUILib.d.ts.map +1 -1
- package/out/natural/getContext/getUILib.js +7 -3
- package/out/natural/getContext/getUILib.js.map +1 -1
- package/out/natural/getContext/index.d.ts +20 -7
- package/out/natural/getContext/index.d.ts.map +1 -1
- package/out/natural/getContext/index.js +150 -22
- 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 +21 -0
- package/out/natural/tools.d.ts.map +1 -1
- package/out/natural/tools.js +143 -2
- package/out/natural/tools.js.map +1 -1
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +378 -307
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts +3 -5
- package/out/natural/transformTSCode.d.ts.map +1 -1
- package/out/natural/transformTSCode.js +30 -1089
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/registerTransform.d.ts +8 -0
- package/out/natural/transforms/registerTransform.d.ts.map +1 -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 +25 -0
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -0
- package/out/natural/transforms/transform2LogicItem.js +1262 -0
- package/out/natural/transforms/transform2LogicItem.js.map +1 -0
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +3 -0
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -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 +9 -0
- package/out/natural/transforms/utils.d.ts.map +1 -0
- package/out/natural/transforms/utils.js +59 -0
- package/out/natural/transforms/utils.js.map +1 -0
- package/out/server/extendBaseNode.d.ts.map +1 -1
- package/out/server/extendBaseNode.js +3 -6
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/index.d.ts +1 -2
- package/out/server/index.d.ts.map +1 -1
- package/out/server/index.js +2 -2
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +10 -3
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +221 -126
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.d.ts +1 -1
- package/out/server/translator.d.ts.map +1 -1
- package/out/server/translator.js +89 -53
- package/out/server/translator.js.map +1 -1
- package/out/service/storage/init.d.ts +1 -25
- package/out/service/storage/init.d.ts.map +1 -1
- package/out/service/storage/init.js +19 -36
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/types.d.ts +41 -0
- package/out/service/storage/types.d.ts.map +1 -0
- package/out/service/storage/types.js +10 -0
- package/out/service/storage/types.js.map +1 -0
- package/out/service/storage/utils.d.ts +15 -0
- package/out/service/storage/utils.d.ts.map +1 -0
- package/out/service/storage/utils.js +68 -0
- package/out/service/storage/utils.js.map +1 -0
- package/out/templator/block2nasl/jsx2nasl/index.d.ts +6 -0
- package/out/templator/block2nasl/jsx2nasl/index.d.ts.map +1 -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 +4 -0
- package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts.map +1 -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 +15 -0
- package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts.map +1 -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 +5 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts.map +1 -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 +29 -0
- package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts.map +1 -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 +3 -0
- package/out/templator/block2nasl/jsx2nasl/utils.d.ts.map +1 -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 +11 -0
- package/out/templator/block2nasl/transformBlock2Nasl.d.ts.map +1 -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 +17 -0
- package/out/templator/block2nasl/viewMergeBlock.d.ts.map +1 -0
- package/out/templator/block2nasl/viewMergeBlock.js +185 -0
- package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
- package/out/templator/utils.js +1 -1
- package/out/templator/utils.js.map +1 -1
- package/out/utils/node.d.ts.map +1 -1
- package/out/utils/node.js +0 -4
- package/out/utils/node.js.map +1 -1
- package/out/utils/uiPathId.d.ts +2 -0
- package/out/utils/uiPathId.d.ts.map +1 -0
- package/out/utils/uiPathId.js +34 -0
- package/out/utils/uiPathId.js.map +1 -0
- package/package.json +13 -25
- package/sandbox/stdlib/nasl.processV2.ts +19 -0
- package/sandbox/stdlib/nasl.ui.components.pc.ts +16 -0
- package/sandbox/stdlib/nasl.ui.definition.ts +41 -1
- package/sandbox/stdlib/nasl.ui.ts +24 -8
- package/sandbox/stdlib/nasl.util.ts +6 -15
- 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} +50 -45
- package/ts-worker/bundle.js +2 -2
- package/ts-worker/lib/Messager.js +8 -1
- package/ts-worker/lib/tsserver.js +6 -6
- 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
|
@@ -22,25 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.tryTransformTS2UI = void 0;
|
|
30
27
|
/* eslint-disable global-require */
|
|
31
28
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
29
|
+
const utils_1 = require("./transforms/utils");
|
|
32
30
|
const lodash_1 = require("lodash");
|
|
33
31
|
const babel = __importStar(require("@babel/core"));
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const utils_1 = require("../utils");
|
|
37
|
-
const DEBUG = false;
|
|
38
|
-
function throwError(message) {
|
|
39
|
-
if (DEBUG)
|
|
40
|
-
throw new Error(message);
|
|
41
|
-
else
|
|
42
|
-
console.error(message);
|
|
43
|
-
}
|
|
32
|
+
const utils_2 = require("../utils");
|
|
33
|
+
const transform2TypeAnnotation_1 = require("./transforms/transform2TypeAnnotation");
|
|
44
34
|
function flatMemberExpression(node) {
|
|
45
35
|
if (node.type === 'MemberExpression')
|
|
46
36
|
return [...flatMemberExpression(node.object), node.property];
|
|
@@ -76,104 +66,48 @@ function flatIfStatement(node) {
|
|
|
76
66
|
*/
|
|
77
67
|
function fixLogicNode(node) {
|
|
78
68
|
if (node?.type === 'CallExpression') {
|
|
79
|
-
const calleeName = (0,
|
|
69
|
+
const calleeName = (0, utils_1.generate)(node.callee).code;
|
|
80
70
|
if (calleeName === 'nasl.util.ForEach') {
|
|
81
71
|
const callee = flatMemberExpression(node.callee);
|
|
82
72
|
node.callee = callee[2];
|
|
83
73
|
}
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
|
-
//
|
|
87
|
-
function
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (node?.typeNamespace) {
|
|
94
|
-
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
95
|
-
typeNamespace: node.typeNamespace,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
|
|
99
|
-
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
100
|
-
typeNamespace: 'nasl.ui'
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (typeName === 'Any' || typeName === 'any') {
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
if (typeName === 'Integer') {
|
|
107
|
-
return naslTypes.TypeAnnotation.createPrimitive('Long');
|
|
108
|
-
}
|
|
109
|
-
if (primitiveType) {
|
|
110
|
-
return naslTypes.TypeAnnotation.createPrimitive(typeName);
|
|
111
|
-
}
|
|
112
|
-
if (['List', 'Map', 'Current'].includes(typeName) && node?.typeParameters) {
|
|
113
|
-
return naslTypes.TypeAnnotation.createGeneric(typeName, {
|
|
114
|
-
typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (node?.typeName?.type === 'TSQualifiedName' && node?.typeParameters) {
|
|
118
|
-
const curTypeName = node?.typeName?.right?.name;
|
|
119
|
-
return naslTypes.TypeAnnotation.createGeneric(curTypeName, {
|
|
120
|
-
typeArguments: node?.typeParameters?.params.map(transformTypeAnnotation),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
if (!node.typeParameters) {
|
|
124
|
-
if (node?.typeName?.type === 'TSQualifiedName') {
|
|
125
|
-
const allTypeName = (0, generator_1.default)(node?.typeName?.left)?.code;
|
|
126
|
-
// 实体、枚举、结构体
|
|
127
|
-
if (/^app.dataSources|.enums|.structures|nasl.ui/.test(allTypeName)) {
|
|
128
|
-
const curTypeName = node?.typeName?.right?.name;
|
|
129
|
-
return naslTypes.TypeAnnotation.createReference(curTypeName, {
|
|
130
|
-
typeNamespace: allTypeName,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return naslTypes.TypeAnnotation.createReference(typeName, {
|
|
135
|
-
typeNamespace: null,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
throwError(`Unhandled node ${node.type}`);
|
|
139
|
-
}
|
|
140
|
-
else if (node.type === 'TSTypeLiteral') {
|
|
141
|
-
return naslTypes.TypeAnnotation.createTypeAnonymousStructure(node.members.map((member) => new naslTypes.StructureProperty({
|
|
142
|
-
name: member.key.name,
|
|
143
|
-
typeAnnotation: transformTypeAnnotation(member.typeAnnotation.typeAnnotation),
|
|
144
|
-
})));
|
|
145
|
-
}
|
|
146
|
-
else if (node.type === 'TSBooleanKeyword') {
|
|
147
|
-
return naslTypes.TypeAnnotation.createPrimitive('Boolean');
|
|
148
|
-
}
|
|
149
|
-
else if (node.type === 'TSStringKeyword') {
|
|
150
|
-
return naslTypes.TypeAnnotation.createPrimitive('String');
|
|
151
|
-
}
|
|
152
|
-
else if (node.type === 'TSNumberKeyword') {
|
|
153
|
-
return naslTypes.TypeAnnotation.createPrimitive('Double');
|
|
154
|
-
}
|
|
155
|
-
else if (node.type === 'TSUnionType') {
|
|
156
|
-
const union = naslTypes.TypeAnnotation.createPrimitive('Union');
|
|
157
|
-
union.typeArguments = [];
|
|
158
|
-
node.types.forEach((curType) => {
|
|
159
|
-
union.typeArguments.push(transformTypeAnnotation(curType));
|
|
76
|
+
// 处理参数
|
|
77
|
+
function transformParam(node) {
|
|
78
|
+
if (node.type === 'ObjectProperty') {
|
|
79
|
+
const typeAnnotation = node?.value?.name ? utils_1.naslTypes.TypeAnnotation.createPrimitive((node?.value).name) : null;
|
|
80
|
+
return new utils_1.naslTypes.Param({
|
|
81
|
+
name: node?.key?.name,
|
|
82
|
+
typeAnnotation: typeAnnotation,
|
|
160
83
|
});
|
|
161
|
-
return union;
|
|
162
84
|
}
|
|
163
|
-
|
|
164
|
-
|
|
85
|
+
if (node.type === 'Identifier') {
|
|
86
|
+
const typeAnnotation = node.typeAnnotation?.typeAnnotation;
|
|
87
|
+
const exclude = ['event'];
|
|
88
|
+
if (exclude.includes(node.name))
|
|
89
|
+
return null;
|
|
90
|
+
return new utils_1.naslTypes.Param({
|
|
91
|
+
name: node.name,
|
|
92
|
+
typeAnnotation: typeAnnotation ? (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation) : null,
|
|
93
|
+
});
|
|
165
94
|
}
|
|
166
95
|
}
|
|
167
|
-
//
|
|
168
|
-
function
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
96
|
+
// 处理生命周期函数
|
|
97
|
+
function transformLifecycle(node) {
|
|
98
|
+
const bindEvents = [];
|
|
99
|
+
node.properties?.forEach((property) => {
|
|
100
|
+
const eventName = property?.key?.name?.replace(/^on/, '')?.toLowerCase();
|
|
101
|
+
const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
|
|
102
|
+
property.value.elements.forEach((element) => {
|
|
103
|
+
let logicName = element?.id?.name || '';
|
|
104
|
+
logicName = bindEvent.getLogicUniqueName(logicName);
|
|
105
|
+
const curLogic = transformNode2Logic(element, logicName, 'view_logic');
|
|
106
|
+
bindEvent.addLogic(curLogic);
|
|
107
|
+
});
|
|
108
|
+
bindEvents.push(bindEvent);
|
|
176
109
|
});
|
|
110
|
+
return bindEvents;
|
|
177
111
|
}
|
|
178
112
|
// 处理变量
|
|
179
113
|
function transformVariableDeclaration(node) {
|
|
@@ -182,14 +116,14 @@ function transformVariableDeclaration(node) {
|
|
|
182
116
|
declList?.forEach((decl) => {
|
|
183
117
|
const variableName = decl.id.name;
|
|
184
118
|
const varTypeAnnotation = decl.id.typeAnnotation?.typeAnnotation;
|
|
185
|
-
newNode = new naslTypes.Variable({
|
|
119
|
+
newNode = new utils_1.naslTypes.Variable({
|
|
186
120
|
name: variableName,
|
|
187
|
-
typeAnnotation: varTypeAnnotation &&
|
|
121
|
+
typeAnnotation: varTypeAnnotation && (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(varTypeAnnotation),
|
|
188
122
|
});
|
|
189
123
|
if (decl.init) {
|
|
190
|
-
if (decl.init.type !== 'ArrayExpression'
|
|
124
|
+
if (decl.init.type !== 'ArrayExpression') {
|
|
191
125
|
// 变量值需要默认值还是赋值,在使用的地方处理
|
|
192
|
-
newNode.defaultValue = new naslTypes.DefaultValue({
|
|
126
|
+
newNode.defaultValue = new utils_1.naslTypes.DefaultValue({
|
|
193
127
|
expression: transformNode2Expression(decl.init),
|
|
194
128
|
});
|
|
195
129
|
}
|
|
@@ -199,7 +133,7 @@ function transformVariableDeclaration(node) {
|
|
|
199
133
|
}
|
|
200
134
|
// 处理 if
|
|
201
135
|
function pushElseIf(ifNode, switchStatement) {
|
|
202
|
-
switchStatement.cases.push(new naslTypes.SwitchCase({
|
|
136
|
+
switchStatement.cases.push(new utils_1.naslTypes.SwitchCase({
|
|
203
137
|
test: transformNode2Expression(ifNode.test),
|
|
204
138
|
consequent: !ifNode.consequent ? [] : ifNode.consequent.body.map((item) => transformNode2Expression(item)).filter((item) => !!item),
|
|
205
139
|
}));
|
|
@@ -207,7 +141,7 @@ function pushElseIf(ifNode, switchStatement) {
|
|
|
207
141
|
pushElseIf(ifNode.alternate, switchStatement);
|
|
208
142
|
}
|
|
209
143
|
else {
|
|
210
|
-
switchStatement.cases.push(new naslTypes.SwitchCase({
|
|
144
|
+
switchStatement.cases.push(new utils_1.naslTypes.SwitchCase({
|
|
211
145
|
test: undefined,
|
|
212
146
|
consequent: !ifNode?.alternate ? [] : ifNode?.alternate?.body.map((item) => transformNode2Expression(item)).filter((item) => !!item),
|
|
213
147
|
}));
|
|
@@ -222,7 +156,7 @@ function handleBinaryExpression(calleeName, argument) {
|
|
|
222
156
|
divide: '/',
|
|
223
157
|
remainder: '%',
|
|
224
158
|
};
|
|
225
|
-
return new naslTypes.BinaryExpression({
|
|
159
|
+
return new utils_1.naslTypes.BinaryExpression({
|
|
226
160
|
operator: map?.[calleeName],
|
|
227
161
|
left: transformNode2Expression(argument?.[0]),
|
|
228
162
|
right: transformNode2Expression(argument?.[1]),
|
|
@@ -231,9 +165,9 @@ function handleBinaryExpression(calleeName, argument) {
|
|
|
231
165
|
// 处理数据结构
|
|
232
166
|
function handleNewExpression(calleeName, node, type) {
|
|
233
167
|
if (calleeName === 'NewList') {
|
|
234
|
-
return new naslTypes.NewList({
|
|
235
|
-
typeAnnotation: naslTypes.TypeAnnotation.createGeneric('List', {
|
|
236
|
-
typeArguments: node?.typeParameters?.params.map(
|
|
168
|
+
return new utils_1.naslTypes.NewList({
|
|
169
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createGeneric('List', {
|
|
170
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
237
171
|
}),
|
|
238
172
|
items: node?.arguments?.[0]?.elements?.map((arg) => transformNode2Expression(arg, type)),
|
|
239
173
|
});
|
|
@@ -241,13 +175,13 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
241
175
|
if (calleeName === 'NewMap') {
|
|
242
176
|
const keys = [];
|
|
243
177
|
const values = [];
|
|
244
|
-
node?.arguments?.[0]?.properties
|
|
178
|
+
node?.arguments?.[0]?.properties?.forEach((arg) => {
|
|
245
179
|
keys.push(transformNode2Expression(arg.key));
|
|
246
180
|
values.push(transformNode2Expression(arg.value));
|
|
247
181
|
});
|
|
248
|
-
return new naslTypes.NewMap({
|
|
249
|
-
typeAnnotation: naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
250
|
-
typeArguments: node?.typeParameters?.params.map(
|
|
182
|
+
return new utils_1.naslTypes.NewMap({
|
|
183
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createGeneric('Map', {
|
|
184
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
251
185
|
}),
|
|
252
186
|
keys,
|
|
253
187
|
values,
|
|
@@ -257,28 +191,28 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
257
191
|
const properties = [];
|
|
258
192
|
const rights = [];
|
|
259
193
|
const assignmentLines = [];
|
|
260
|
-
node?.arguments?.[0]?.properties
|
|
194
|
+
node?.arguments?.[0]?.properties?.forEach((arg, index) => {
|
|
261
195
|
properties.push(transformNode2Expression(arg.key));
|
|
262
196
|
if (arg.value.type === 'MemberExpression') {
|
|
263
197
|
const expression = flatMemberExpression(arg.value);
|
|
264
198
|
const members = flatMembers(transformNode2Expression(arg.value));
|
|
265
|
-
rights.push(new naslTypes.SelectMembers({
|
|
199
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
266
200
|
expression: transformNode2Expression(expression[0]),
|
|
267
201
|
members,
|
|
268
202
|
}));
|
|
269
203
|
if (arg?.value) {
|
|
270
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
204
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
271
205
|
leftIndex: [0, index],
|
|
272
206
|
rightIndex: [index, members.length - 1],
|
|
273
207
|
}));
|
|
274
208
|
}
|
|
275
209
|
}
|
|
276
210
|
else {
|
|
277
|
-
rights.push(new naslTypes.SelectMembers({
|
|
211
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
278
212
|
expression: transformNode2Expression(arg.value)
|
|
279
213
|
}));
|
|
280
214
|
if (arg?.value) {
|
|
281
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
215
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
282
216
|
leftIndex: [0, index],
|
|
283
217
|
rightIndex: [index],
|
|
284
218
|
}));
|
|
@@ -288,10 +222,10 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
288
222
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
289
223
|
if (parameters && parameters?.type === 'TSTypeReference' && parameters?.typeName?.type === 'TSQualifiedName') {
|
|
290
224
|
const { left, right } = parameters?.typeName || {};
|
|
291
|
-
const typeNamespace = (0,
|
|
225
|
+
const typeNamespace = (0, utils_1.generate)(left)?.code;
|
|
292
226
|
const typeName = right?.name;
|
|
293
|
-
return new naslTypes.NewComposite({
|
|
294
|
-
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
227
|
+
return new utils_1.naslTypes.NewComposite({
|
|
228
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
|
|
295
229
|
typeNamespace,
|
|
296
230
|
typeName
|
|
297
231
|
}),
|
|
@@ -301,8 +235,8 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
301
235
|
});
|
|
302
236
|
}
|
|
303
237
|
const typeName = parameters?.typeName?.name;
|
|
304
|
-
return new naslTypes.NewComposite({
|
|
305
|
-
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
238
|
+
return new utils_1.naslTypes.NewComposite({
|
|
239
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
|
|
306
240
|
typeNamespace: 'app.dataSources.defaultDS.entities',
|
|
307
241
|
typeName
|
|
308
242
|
}),
|
|
@@ -315,28 +249,28 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
315
249
|
const properties = [];
|
|
316
250
|
const rights = [];
|
|
317
251
|
const assignmentLines = [];
|
|
318
|
-
node?.arguments?.[0]?.properties
|
|
252
|
+
node?.arguments?.[0]?.properties?.forEach((arg, index) => {
|
|
319
253
|
properties.push(transformNode2Expression(arg.key));
|
|
320
254
|
if (arg.value.type === 'MemberExpression') {
|
|
321
255
|
const expression = flatMemberExpression(arg.value);
|
|
322
256
|
const members = flatMembers(transformNode2Expression(arg.value));
|
|
323
|
-
rights.push(new naslTypes.SelectMembers({
|
|
257
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
324
258
|
expression: transformNode2Expression(expression[0]),
|
|
325
259
|
members,
|
|
326
260
|
}));
|
|
327
261
|
if (arg?.value) {
|
|
328
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
262
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
329
263
|
leftIndex: [0, index],
|
|
330
264
|
rightIndex: [index, members.length - 1],
|
|
331
265
|
}));
|
|
332
266
|
}
|
|
333
267
|
}
|
|
334
268
|
else {
|
|
335
|
-
rights.push(new naslTypes.SelectMembers({
|
|
269
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
336
270
|
expression: transformNode2Expression(arg.value)
|
|
337
271
|
}));
|
|
338
272
|
if (arg?.value) {
|
|
339
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
273
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
340
274
|
leftIndex: [0, index],
|
|
341
275
|
rightIndex: [index],
|
|
342
276
|
}));
|
|
@@ -346,10 +280,10 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
346
280
|
const parameters = node?.typeParameters?.params?.[0] || {};
|
|
347
281
|
if (parameters && parameters?.type === 'TSTypeReference' && parameters?.typeName?.type === 'TSQualifiedName') {
|
|
348
282
|
const { left, right } = parameters?.typeName || {};
|
|
349
|
-
const typeNamespace = (0,
|
|
283
|
+
const typeNamespace = (0, utils_1.generate)(left)?.code;
|
|
350
284
|
const typeName = right?.name;
|
|
351
|
-
return new naslTypes.NewComposite({
|
|
352
|
-
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
285
|
+
return new utils_1.naslTypes.NewComposite({
|
|
286
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
|
|
353
287
|
typeNamespace,
|
|
354
288
|
typeName
|
|
355
289
|
}),
|
|
@@ -359,8 +293,8 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
359
293
|
});
|
|
360
294
|
}
|
|
361
295
|
const typeName = parameters?.typeName?.name;
|
|
362
|
-
return new naslTypes.NewComposite({
|
|
363
|
-
typeAnnotation: naslTypes.TypeAnnotation.createReference(typeName, {
|
|
296
|
+
return new utils_1.naslTypes.NewComposite({
|
|
297
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createReference(typeName, {
|
|
364
298
|
typeNamespace: 'app.structures',
|
|
365
299
|
typeName
|
|
366
300
|
}),
|
|
@@ -379,35 +313,35 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
379
313
|
if (arg.value.type === 'MemberExpression') {
|
|
380
314
|
const expression = flatMemberExpression(arg.value);
|
|
381
315
|
const members = flatMembers(transformNode2Expression(arg.value));
|
|
382
|
-
rights.push(new naslTypes.SelectMembers({
|
|
316
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
383
317
|
expression: transformNode2Expression(expression[0]),
|
|
384
318
|
members,
|
|
385
319
|
}));
|
|
386
320
|
if (arg?.value) {
|
|
387
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
321
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
388
322
|
leftIndex: [0, index],
|
|
389
323
|
rightIndex: [index, members.length - 1],
|
|
390
324
|
}));
|
|
391
325
|
}
|
|
392
326
|
}
|
|
393
327
|
else {
|
|
394
|
-
rights.push(new naslTypes.SelectMembers({
|
|
328
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
395
329
|
expression: transformNode2Expression(arg.value)
|
|
396
330
|
}));
|
|
397
331
|
if (arg?.value) {
|
|
398
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
332
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
399
333
|
leftIndex: [0, index],
|
|
400
334
|
rightIndex: [index],
|
|
401
335
|
}));
|
|
402
336
|
}
|
|
403
337
|
}
|
|
404
|
-
structureProperties.push(new naslTypes.StructureProperty({
|
|
338
|
+
structureProperties.push(new utils_1.naslTypes.StructureProperty({
|
|
405
339
|
name: arg?.key?.name,
|
|
406
340
|
typeAnnotation: null
|
|
407
341
|
}));
|
|
408
342
|
});
|
|
409
|
-
return new naslTypes.NewComposite({
|
|
410
|
-
typeAnnotation: naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
|
|
343
|
+
return new utils_1.naslTypes.NewComposite({
|
|
344
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
|
|
411
345
|
properties,
|
|
412
346
|
rights,
|
|
413
347
|
assignmentLines
|
|
@@ -415,6 +349,13 @@ function handleNewExpression(calleeName, node, type) {
|
|
|
415
349
|
}
|
|
416
350
|
return node;
|
|
417
351
|
}
|
|
352
|
+
function fixExpression(arg, type) {
|
|
353
|
+
let expression = transformNode2Expression(arg, type);
|
|
354
|
+
if (expression?.concept === 'Identifier' && expression?.name === 'undefined') {
|
|
355
|
+
expression = undefined;
|
|
356
|
+
}
|
|
357
|
+
return expression;
|
|
358
|
+
}
|
|
418
359
|
// 处理表达式
|
|
419
360
|
function transformNode2Expression(node, type) {
|
|
420
361
|
if (!node)
|
|
@@ -429,57 +370,58 @@ function transformNode2Expression(node, type) {
|
|
|
429
370
|
}
|
|
430
371
|
else if (node.type === 'CallExpression') {
|
|
431
372
|
const callee = flatMemberExpression(node.callee);
|
|
432
|
-
const calleeName = (0,
|
|
373
|
+
const calleeName = (0, utils_1.generate)(node.callee).code;
|
|
433
374
|
// console.log('lemon ~~~ CallExpression', node, callee, calleeName);
|
|
434
375
|
if (/^\$refs\./.test(calleeName)) {
|
|
435
|
-
return new naslTypes.CallLogic({
|
|
376
|
+
return new utils_1.naslTypes.CallLogic({
|
|
436
377
|
calleeNamespace: `elements.${callee[1].name}.logics`,
|
|
437
378
|
calleeName: callee[2].name,
|
|
438
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
439
|
-
expression:
|
|
379
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
380
|
+
expression: fixExpression(arg, type),
|
|
440
381
|
})),
|
|
441
382
|
});
|
|
442
383
|
}
|
|
443
384
|
if (callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity')) {
|
|
444
385
|
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
445
|
-
return new naslTypes.CallLogic({
|
|
386
|
+
return new utils_1.naslTypes.CallLogic({
|
|
446
387
|
calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
|
|
447
388
|
calleeName: callee[1].name,
|
|
448
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
389
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
449
390
|
expression: transformNode2Expression(arg, type),
|
|
450
391
|
})),
|
|
451
392
|
});
|
|
452
393
|
}
|
|
394
|
+
// 需求变更 consoleLog 都转成nasl.logging
|
|
453
395
|
if (calleeName === 'nasl.util.consoleLog' || calleeName === 'console.log') {
|
|
454
|
-
return new naslTypes.CallLogic({
|
|
455
|
-
calleeNamespace: 'nasl.
|
|
456
|
-
calleeName: '
|
|
396
|
+
return new utils_1.naslTypes.CallLogic({
|
|
397
|
+
calleeNamespace: 'nasl.logging',
|
|
398
|
+
calleeName: 'INFO',
|
|
457
399
|
shortcut: true,
|
|
458
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
400
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
459
401
|
expression: transformNode2Expression(arg, type),
|
|
460
402
|
})),
|
|
461
403
|
});
|
|
462
404
|
}
|
|
463
405
|
if (calleeName.startsWith('nasl.logging.')) {
|
|
464
|
-
return new naslTypes.CallLogic({
|
|
406
|
+
return new utils_1.naslTypes.CallLogic({
|
|
465
407
|
calleeNamespace: 'nasl.logging',
|
|
466
408
|
calleeName: callee[2].name,
|
|
467
409
|
shortcut: true,
|
|
468
|
-
arguments: node.arguments.map((arg) => new naslTypes.Argument({
|
|
410
|
+
arguments: node.arguments.map((arg) => new utils_1.naslTypes.Argument({
|
|
469
411
|
expression: transformNode2Expression(arg, type),
|
|
470
412
|
})),
|
|
471
413
|
});
|
|
472
414
|
}
|
|
473
415
|
if (calleeName === 'nasl.util.jsonSerialize' || calleeName === 'nasl.util.jsonDeserialize') {
|
|
474
416
|
const curCalleeName = node.callee.property.name;
|
|
475
|
-
return new naslTypes.CallLogic({
|
|
417
|
+
return new utils_1.naslTypes.CallLogic({
|
|
476
418
|
calleeNamespace: 'nasl.util',
|
|
477
419
|
calleeName: curCalleeName,
|
|
478
420
|
shortcut: true,
|
|
479
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
421
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
480
422
|
expression: transformNode2Expression(arg, type),
|
|
481
423
|
})),
|
|
482
|
-
typeArguments: node?.typeParameters?.params.map((curType) =>
|
|
424
|
+
typeArguments: node?.typeParameters?.params.map((curType) => (0, transform2TypeAnnotation_1.transform2TypeAnnotation)({ ...curType })),
|
|
483
425
|
});
|
|
484
426
|
}
|
|
485
427
|
;
|
|
@@ -501,15 +443,15 @@ function transformNode2Expression(node, type) {
|
|
|
501
443
|
if (['NewList', 'NewMap', 'NewEntity', 'NewStructure', 'NewAnonymousStructure'].includes(curCalleeName)) {
|
|
502
444
|
return handleNewExpression(curCalleeName, node, type);
|
|
503
445
|
}
|
|
504
|
-
const nodeElement = new naslTypes.CallFunction({
|
|
446
|
+
const nodeElement = new utils_1.naslTypes.CallFunction({
|
|
505
447
|
calleeNamespace: 'nasl.util',
|
|
506
448
|
calleeName: curCalleeName,
|
|
507
|
-
arguments: argument.map((arg, index) => new naslTypes.Argument({
|
|
449
|
+
arguments: argument.map((arg, index) => new utils_1.naslTypes.Argument({
|
|
508
450
|
expression: transformNode2Expression(arg, type),
|
|
509
451
|
keyword: `str${index + 1}`,
|
|
510
452
|
})),
|
|
511
|
-
typeArguments: node?.typeParameters?.params.map(
|
|
512
|
-
// typeArguments: node?.typeParameters?.params.map((curType: any) =>
|
|
453
|
+
typeArguments: node?.typeParameters?.params.map(transform2TypeAnnotation_1.transform2TypeAnnotation),
|
|
454
|
+
// typeArguments: node?.typeParameters?.params.map((curType: any) => transform2TypeAnnotation({ ...curType, typeNamespace })),
|
|
513
455
|
});
|
|
514
456
|
return nodeElement;
|
|
515
457
|
}
|
|
@@ -519,15 +461,26 @@ function transformNode2Expression(node, type) {
|
|
|
519
461
|
const nsArr = namespace.split('.').map((item) => item.replace(/_view$/, ''));
|
|
520
462
|
const pageType = nsArr.shift();
|
|
521
463
|
const viewName = nsArr.pop();
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
464
|
+
const newArguments = node?.arguments?.slice(1);
|
|
465
|
+
let argument = [];
|
|
466
|
+
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
467
|
+
argument = newArguments?.[0]?.properties?.map((property) => new utils_1.naslTypes.Argument({
|
|
468
|
+
keyword: property?.key?.name,
|
|
469
|
+
expression: fixExpression(property?.value, type),
|
|
470
|
+
}));
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
argument = node.arguments.slice(1).map((arg) => new utils_1.naslTypes.Argument({
|
|
474
|
+
expression: fixExpression(arg, type),
|
|
475
|
+
}));
|
|
476
|
+
}
|
|
477
|
+
return new utils_1.naslTypes.Destination({
|
|
478
|
+
viewNamespace: `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((item) => `.${item}.views`)?.join('')}`,
|
|
479
|
+
viewName,
|
|
480
|
+
arguments: argument,
|
|
528
481
|
});
|
|
529
482
|
}
|
|
530
|
-
return new naslTypes.CallLogic({
|
|
483
|
+
return new utils_1.naslTypes.CallLogic({
|
|
531
484
|
calleeNamespace: 'nasl.ui',
|
|
532
485
|
calleeName: callee[2].name,
|
|
533
486
|
shortcut: true,
|
|
@@ -536,25 +489,25 @@ function transformNode2Expression(node, type) {
|
|
|
536
489
|
* @param node
|
|
537
490
|
* @returns
|
|
538
491
|
*/
|
|
539
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
492
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
540
493
|
expression: transformNode2Expression(arg, type),
|
|
541
494
|
})),
|
|
542
495
|
});
|
|
543
496
|
}
|
|
544
497
|
if (calleeName.endsWith('.map')) {
|
|
545
|
-
return new naslTypes.CallFunction({
|
|
498
|
+
return new utils_1.naslTypes.CallFunction({
|
|
546
499
|
calleeNamespace: 'nasl.util',
|
|
547
500
|
calleeName: 'ListTransform',
|
|
548
|
-
arguments: [new naslTypes.Argument({
|
|
501
|
+
arguments: [new utils_1.naslTypes.Argument({
|
|
549
502
|
expression: transformNode2Expression(node.callee.object, type),
|
|
550
|
-
}), ...node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
503
|
+
}), ...node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
551
504
|
expression: transformNode2Expression(arg, type),
|
|
552
505
|
}))],
|
|
553
506
|
});
|
|
554
507
|
}
|
|
555
508
|
if (calleeName === 'PAGINATE') {
|
|
556
509
|
const newCallee = node?.arguments || [];
|
|
557
|
-
return new naslTypes.Paginate({
|
|
510
|
+
return new utils_1.naslTypes.Paginate({
|
|
558
511
|
list: newCallee?.[0] && transformNode2Expression(newCallee?.[0], type),
|
|
559
512
|
page: newCallee?.[1] && transformNode2Expression(newCallee?.[1], type),
|
|
560
513
|
size: newCallee?.[2] && transformNode2Expression(newCallee?.[2], type),
|
|
@@ -563,15 +516,15 @@ function transformNode2Expression(node, type) {
|
|
|
563
516
|
if (calleeName === 'ForEach') {
|
|
564
517
|
const newCallee = node.arguments;
|
|
565
518
|
const arrowFunction = node.arguments[3];
|
|
566
|
-
const nodeElement = new naslTypes.ForEachStatement({
|
|
519
|
+
const nodeElement = new utils_1.naslTypes.ForEachStatement({
|
|
567
520
|
each: transformNode2Expression(newCallee[0], type),
|
|
568
521
|
start: transformNode2Expression(newCallee[1], type),
|
|
569
522
|
end: transformNode2Expression(newCallee[2], type),
|
|
570
523
|
item: transformParam(arrowFunction.params[0]),
|
|
571
|
-
index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new naslTypes.Param({
|
|
572
|
-
name: 'index', typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
524
|
+
index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
525
|
+
name: 'index', typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
573
526
|
}),
|
|
574
|
-
body: arrowFunction.body.body.map((item) => transformNode2Expression(item
|
|
527
|
+
body: arrowFunction.body.body.map((item) => transformNode2Expression(item)).filter((item) => !!item && item?.concept !== 'Variable'),
|
|
575
528
|
});
|
|
576
529
|
return nodeElement;
|
|
577
530
|
}
|
|
@@ -580,15 +533,15 @@ function transformNode2Expression(node, type) {
|
|
|
580
533
|
if (curCalleeName === 'forEach') {
|
|
581
534
|
const newCallee = node.callee.object;
|
|
582
535
|
const arrowFunction = node.arguments[0];
|
|
583
|
-
const nodeElement = new naslTypes.ForEachStatement({
|
|
536
|
+
const nodeElement = new utils_1.naslTypes.ForEachStatement({
|
|
584
537
|
each: transformNode2Expression(newCallee.callee.object, type),
|
|
585
538
|
start: transformNode2Expression(newCallee?.arguments?.[0], type),
|
|
586
539
|
end: transformNode2Expression(newCallee?.arguments?.[1], type),
|
|
587
540
|
item: transformParam(arrowFunction.params[0]),
|
|
588
|
-
index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new naslTypes.Param({
|
|
589
|
-
name: 'index', typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
541
|
+
index: arrowFunction.params[1] ? transformParam(arrowFunction.params[1]) : new utils_1.naslTypes.Param({
|
|
542
|
+
name: 'index', typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Long'),
|
|
590
543
|
}),
|
|
591
|
-
body: arrowFunction.body.body.map((item) => transformNode2Expression(item
|
|
544
|
+
body: arrowFunction.body.body.map((item) => transformNode2Expression(item)).filter((item) => !!item && item?.concept !== 'Variable'),
|
|
592
545
|
});
|
|
593
546
|
return nodeElement;
|
|
594
547
|
}
|
|
@@ -597,89 +550,89 @@ function transformNode2Expression(node, type) {
|
|
|
597
550
|
return handleBinaryExpression(calleeName, node?.arguments);
|
|
598
551
|
}
|
|
599
552
|
else if (calleeName === 'alert') {
|
|
600
|
-
return new naslTypes.CallLogic({
|
|
553
|
+
return new utils_1.naslTypes.CallLogic({
|
|
601
554
|
calleeNamespace: 'nasl.ui',
|
|
602
555
|
calleeName: 'showMessage',
|
|
603
556
|
shortcut: true,
|
|
604
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
557
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
605
558
|
expression: transformNode2Expression(arg, type),
|
|
606
559
|
})),
|
|
607
560
|
});
|
|
608
561
|
}
|
|
609
562
|
else if (/^app.dataSources|app.logics/.test(calleeName)) {
|
|
610
563
|
if (calleeName?.includes('.entities.')) {
|
|
611
|
-
const calleeNamespace = (0,
|
|
564
|
+
const calleeNamespace = (0, utils_1.generate)(node?.callee?.object?.object)?.code;
|
|
612
565
|
const entityName = node?.callee?.object?.property?.name?.replace(/Entity$/, '');
|
|
613
|
-
return new naslTypes.CallLogic({
|
|
566
|
+
return new utils_1.naslTypes.CallLogic({
|
|
614
567
|
calleeNamespace: `${calleeNamespace}.${entityName}.logics`,
|
|
615
568
|
calleeName: node?.callee?.property?.name,
|
|
616
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
569
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
617
570
|
expression: transformNode2Expression(arg, type),
|
|
618
571
|
})),
|
|
619
572
|
});
|
|
620
573
|
}
|
|
621
|
-
return new naslTypes.CallLogic({
|
|
622
|
-
calleeNamespace: (0,
|
|
574
|
+
return new utils_1.naslTypes.CallLogic({
|
|
575
|
+
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
623
576
|
calleeName: callee[callee.length - 1].name,
|
|
624
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
577
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
625
578
|
expression: transformNode2Expression(arg, type),
|
|
626
579
|
})),
|
|
627
580
|
});
|
|
628
581
|
}
|
|
629
582
|
else if (callee.length === 1) {
|
|
630
583
|
if (calleeName.startsWith('viewLogic_')) {
|
|
631
|
-
return new naslTypes.CallLogic({
|
|
584
|
+
return new utils_1.naslTypes.CallLogic({
|
|
632
585
|
calleeNamespace: '',
|
|
633
586
|
calleeName: calleeName.slice('viewLogic_'.length),
|
|
634
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
587
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
635
588
|
expression: transformNode2Expression(arg, type),
|
|
636
589
|
})),
|
|
637
590
|
});
|
|
638
591
|
}
|
|
639
592
|
if (calleeName === 'FROM') {
|
|
640
593
|
// TODO
|
|
641
|
-
return new naslTypes.CallLogic({
|
|
594
|
+
return new utils_1.naslTypes.CallLogic({
|
|
642
595
|
calleeNamespace: `app.logics`,
|
|
643
596
|
calleeName,
|
|
644
597
|
arguments: [],
|
|
645
598
|
});
|
|
646
599
|
}
|
|
647
|
-
return new naslTypes.CallLogic({
|
|
648
|
-
calleeNamespace:
|
|
600
|
+
return new utils_1.naslTypes.CallLogic({
|
|
601
|
+
calleeNamespace: ``,
|
|
649
602
|
calleeName,
|
|
650
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
603
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
651
604
|
expression: transformNode2Expression(arg, type),
|
|
652
605
|
})),
|
|
653
606
|
});
|
|
654
607
|
}
|
|
655
608
|
else if (/interfaces/.test(calleeName)) {
|
|
656
|
-
return new naslTypes.CallInterface({
|
|
657
|
-
calleeNamespace: (0,
|
|
609
|
+
return new utils_1.naslTypes.CallInterface({
|
|
610
|
+
calleeNamespace: (0, utils_1.generate)(node.callee.object).code,
|
|
658
611
|
calleeName: callee[callee.length - 1].name,
|
|
659
|
-
arguments: node?.arguments?.map((arg) => arg?.properties?.map((item) => new naslTypes.Argument({
|
|
612
|
+
arguments: node?.arguments?.map((arg) => arg?.properties?.map((item) => new utils_1.naslTypes.Argument({
|
|
660
613
|
keyword: item?.key?.name,
|
|
661
614
|
expression: transformNode2Expression(item?.value, type),
|
|
662
|
-
}))).flat(),
|
|
615
|
+
})) || []).flat() || [],
|
|
663
616
|
});
|
|
664
617
|
}
|
|
665
618
|
else if (/connector./.test(calleeName)) {
|
|
666
|
-
const flatCalleeKey = (0,
|
|
619
|
+
const flatCalleeKey = (0, utils_1.generate)(node?.callee)?.code;
|
|
667
620
|
const [, calleeConnectionName, calleeNamespace, calleeFunName] = flatCalleeKey?.match(/^(\w+)\.([\w.]+)\.(\w+)$/);
|
|
668
|
-
return new naslTypes.CallConnector({
|
|
621
|
+
return new utils_1.naslTypes.CallConnector({
|
|
669
622
|
calleeConnectionName,
|
|
670
623
|
calleeNamespace,
|
|
671
624
|
calleeName: calleeFunName,
|
|
672
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
625
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
673
626
|
expression: transformNode2Expression(arg, type),
|
|
674
627
|
})),
|
|
675
628
|
});
|
|
676
629
|
}
|
|
677
630
|
else if (/extensions./.test(calleeName)) {
|
|
678
|
-
return new naslTypes.CallLogic({
|
|
679
|
-
calleeNamespace: (0,
|
|
631
|
+
return new utils_1.naslTypes.CallLogic({
|
|
632
|
+
calleeNamespace: (0, utils_1.generate)(node?.callee?.object)?.code,
|
|
680
633
|
calleeName: callee?.[callee?.length - 1]?.name,
|
|
681
634
|
handleError: true,
|
|
682
|
-
arguments: node?.arguments?.map((arg) => new naslTypes.Argument({
|
|
635
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
683
636
|
expression: transformNode2Expression(arg, type),
|
|
684
637
|
})),
|
|
685
638
|
});
|
|
@@ -688,16 +641,16 @@ function transformNode2Expression(node, type) {
|
|
|
688
641
|
// NOTE: 适用于 if else
|
|
689
642
|
const newCallee = node.callee.body.body;
|
|
690
643
|
if (newCallee[newCallee.length - 1].argument?.callee?.name === '__MatchExpressionFuntion') {
|
|
691
|
-
const match = new naslTypes.Match({
|
|
644
|
+
const match = new utils_1.naslTypes.Match({
|
|
692
645
|
expression: transformNode2Expression(newCallee[0], type),
|
|
693
646
|
isExpression: type !== 'logic',
|
|
694
|
-
cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new naslTypes.MatchCase({
|
|
647
|
+
cases: flatIfStatement(newCallee[1].body.body[0]).map((_case) => new utils_1.naslTypes.MatchCase({
|
|
695
648
|
patterns: !_case.test ? [] : flatMatchPatternsExpression(transformNode2Expression(_case.test, type)),
|
|
696
649
|
body: _case.consequent.body.filter((item) => item.type !== 'BreakStatement').map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
|
|
697
650
|
})),
|
|
698
651
|
});
|
|
699
652
|
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
700
|
-
match.cases.push(new naslTypes.MatchCase({
|
|
653
|
+
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
701
654
|
patterns: [],
|
|
702
655
|
body: [],
|
|
703
656
|
}));
|
|
@@ -708,7 +661,7 @@ function transformNode2Expression(node, type) {
|
|
|
708
661
|
}
|
|
709
662
|
if (case_.patterns.length && case_.patterns[0].concept === 'MemberExpression') {
|
|
710
663
|
case_.isMatchedTypeEnumable = true;
|
|
711
|
-
case_.patterns[0] = new naslTypes.MemberExpression({
|
|
664
|
+
case_.patterns[0] = new utils_1.naslTypes.MemberExpression({
|
|
712
665
|
object: {
|
|
713
666
|
concept: 'Identifier',
|
|
714
667
|
name: case_.patterns[0].object.property.name,
|
|
@@ -729,15 +682,24 @@ function transformNode2Expression(node, type) {
|
|
|
729
682
|
const switchStatement = transformNode2Expression(newCallee[0].body.body[0], type);
|
|
730
683
|
return switchStatement;
|
|
731
684
|
}
|
|
732
|
-
throwError(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
685
|
+
(0, utils_1.throwError)(`Unhandled ArrowFunctionExpression node ${node.type}`);
|
|
686
|
+
}
|
|
687
|
+
else if (/nasl.auth./.test(calleeName)) {
|
|
688
|
+
return new utils_1.naslTypes.CallLogic({
|
|
689
|
+
calleeNamespace: 'nasl.auth',
|
|
690
|
+
calleeName: callee[callee.length - 1].name,
|
|
691
|
+
arguments: node?.arguments?.map((arg) => new utils_1.naslTypes.Argument({
|
|
692
|
+
expression: transformNode2Expression(arg, type),
|
|
693
|
+
})),
|
|
694
|
+
});
|
|
733
695
|
}
|
|
734
696
|
else {
|
|
735
|
-
throwError(`Unhandled node ${callee.map((item) => item.name).join('.')} ${node.type}`);
|
|
697
|
+
(0, utils_1.throwError)(`Unhandled node ${callee.map((item) => item.name).join('.')} ${node.type}`);
|
|
736
698
|
}
|
|
737
699
|
}
|
|
738
700
|
else if (node.type === 'IfStatement') {
|
|
739
701
|
if (node.alternate && node.alternate.type === 'IfStatement') {
|
|
740
|
-
const switchStatement = new naslTypes.SwitchStatement({
|
|
702
|
+
const switchStatement = new utils_1.naslTypes.SwitchStatement({
|
|
741
703
|
cases: [],
|
|
742
704
|
});
|
|
743
705
|
pushElseIf(node, switchStatement);
|
|
@@ -745,7 +707,7 @@ function transformNode2Expression(node, type) {
|
|
|
745
707
|
}
|
|
746
708
|
let consequentIndex;
|
|
747
709
|
let alternateIndex;
|
|
748
|
-
const naslNode = new naslTypes.IfStatement({
|
|
710
|
+
const naslNode = new utils_1.naslTypes.IfStatement({
|
|
749
711
|
test: transformNode2Expression(node.test, type),
|
|
750
712
|
consequent: !node.consequent ? [] : node.consequent.body.map((item, index) => {
|
|
751
713
|
if (item?.type === 'ReturnStatement') {
|
|
@@ -767,30 +729,30 @@ function transformNode2Expression(node, type) {
|
|
|
767
729
|
}).filter((item) => !!item),
|
|
768
730
|
});
|
|
769
731
|
if (consequentIndex !== undefined) {
|
|
770
|
-
naslNode
|
|
732
|
+
naslNode.insertItemInConsequentAt(new utils_1.naslTypes.End(), consequentIndex + 1);
|
|
771
733
|
}
|
|
772
734
|
if (alternateIndex !== undefined) {
|
|
773
|
-
naslNode
|
|
735
|
+
naslNode.insertItemInAlternateAt(new utils_1.naslTypes.End(), alternateIndex + 1);
|
|
774
736
|
}
|
|
775
737
|
return naslNode;
|
|
776
738
|
}
|
|
777
739
|
else if (node.type === 'WhileStatement') {
|
|
778
|
-
return new naslTypes.WhileStatement({
|
|
740
|
+
return new utils_1.naslTypes.WhileStatement({
|
|
779
741
|
test: transformNode2Expression(node.test, type),
|
|
780
742
|
body: node.body.body.map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
|
|
781
743
|
});
|
|
782
744
|
}
|
|
783
745
|
else if (node.type === 'SwitchStatement') {
|
|
784
|
-
const match = new naslTypes.Match({
|
|
746
|
+
const match = new utils_1.naslTypes.Match({
|
|
785
747
|
expression: transformNode2Expression(node.discriminant, type),
|
|
786
748
|
isExpression: type !== 'logic',
|
|
787
|
-
cases: node.cases.map((_case) => new naslTypes.MatchCase({
|
|
749
|
+
cases: node.cases.map((_case) => new utils_1.naslTypes.MatchCase({
|
|
788
750
|
patterns: !_case.test ? [] : [transformNode2Expression(_case.test, type)],
|
|
789
751
|
body: _case.consequent.filter((item) => item.type !== 'BreakStatement').map((item) => transformNode2Expression(item, type)).filter((item) => !!item),
|
|
790
752
|
})),
|
|
791
753
|
});
|
|
792
754
|
if (!match.cases.length || match.cases[match.cases.length - 1].patterns.length) {
|
|
793
|
-
match.cases.push(new naslTypes.MatchCase({
|
|
755
|
+
match.cases.push(new utils_1.naslTypes.MatchCase({
|
|
794
756
|
patterns: [],
|
|
795
757
|
body: [],
|
|
796
758
|
}));
|
|
@@ -808,40 +770,59 @@ function transformNode2Expression(node, type) {
|
|
|
808
770
|
}
|
|
809
771
|
else if (node.type === 'MemberExpression') {
|
|
810
772
|
const callee = flatMemberExpression(node);
|
|
811
|
-
const calleeName = (0,
|
|
773
|
+
const calleeName = (0, utils_1.generate)(node)?.code;
|
|
812
774
|
if (calleeName?.includes('app.enums')) {
|
|
813
775
|
const name = callee?.[3]?.value || callee?.[3]?.name || callee?.[3]?.value;
|
|
814
|
-
return new naslTypes.MemberExpression({
|
|
815
|
-
object: new naslTypes.Identifier({
|
|
776
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
777
|
+
object: new utils_1.naslTypes.Identifier({
|
|
816
778
|
namespace: 'app.enums',
|
|
817
779
|
name: callee?.[2]?.name,
|
|
818
780
|
}),
|
|
819
|
-
property: new naslTypes.Identifier({
|
|
781
|
+
property: new utils_1.naslTypes.Identifier({
|
|
820
782
|
name: String(name),
|
|
821
783
|
}),
|
|
822
784
|
});
|
|
823
785
|
}
|
|
786
|
+
if (calleeName?.includes('nasl.auth.')) {
|
|
787
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
788
|
+
object: new utils_1.naslTypes.Identifier({
|
|
789
|
+
namespace: 'nasl.auth',
|
|
790
|
+
name: callee?.[2]?.name,
|
|
791
|
+
}),
|
|
792
|
+
property: new utils_1.naslTypes.Identifier({
|
|
793
|
+
name: callee?.[3]?.name,
|
|
794
|
+
}),
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
const regex = /^(app\..+?)\.variables\.(.+)$/;
|
|
798
|
+
if (regex.test(calleeName)) {
|
|
799
|
+
const [, namespace, variableName] = calleeName.match(regex);
|
|
800
|
+
return new utils_1.naslTypes.Identifier({
|
|
801
|
+
name: String(variableName),
|
|
802
|
+
namespace: `${namespace}.variables`
|
|
803
|
+
});
|
|
804
|
+
}
|
|
824
805
|
if (node.property.type === 'NumericLiteral') {
|
|
825
|
-
return new naslTypes.CallFunction({
|
|
806
|
+
return new utils_1.naslTypes.CallFunction({
|
|
826
807
|
calleeNamespace: 'nasl.util',
|
|
827
808
|
calleeName: 'Get',
|
|
828
809
|
arguments: [
|
|
829
|
-
new naslTypes.Argument({
|
|
810
|
+
new utils_1.naslTypes.Argument({
|
|
830
811
|
expression: transformNode2Expression(node.object, type),
|
|
831
812
|
}),
|
|
832
|
-
new naslTypes.Argument({
|
|
813
|
+
new utils_1.naslTypes.Argument({
|
|
833
814
|
expression: transformNode2Expression(node.property, type),
|
|
834
815
|
}),
|
|
835
816
|
],
|
|
836
817
|
});
|
|
837
818
|
}
|
|
838
|
-
return new naslTypes.MemberExpression({
|
|
819
|
+
return new utils_1.naslTypes.MemberExpression({
|
|
839
820
|
object: transformNode2Expression(node.object, type),
|
|
840
821
|
property: transformNode2Expression(node.property, type),
|
|
841
822
|
});
|
|
842
823
|
}
|
|
843
824
|
else if (node.type === 'Identifier') {
|
|
844
|
-
return new naslTypes.Identifier({
|
|
825
|
+
return new utils_1.naslTypes.Identifier({
|
|
845
826
|
name: node.name,
|
|
846
827
|
});
|
|
847
828
|
}
|
|
@@ -851,16 +832,16 @@ function transformNode2Expression(node, type) {
|
|
|
851
832
|
else if (node.type === 'AssignmentExpression') {
|
|
852
833
|
if (node.operator === '+=' || node.operator === '-=') {
|
|
853
834
|
if (type === 'logic') {
|
|
854
|
-
return new naslTypes.Assignment({
|
|
835
|
+
return new utils_1.naslTypes.Assignment({
|
|
855
836
|
left: transformNode2Expression(node.left, type),
|
|
856
|
-
right: new naslTypes.BinaryExpression({
|
|
837
|
+
right: new utils_1.naslTypes.BinaryExpression({
|
|
857
838
|
operator: node.operator[0],
|
|
858
839
|
left: transformNode2Expression(node.left, type),
|
|
859
840
|
right: transformNode2Expression(node.right, type),
|
|
860
841
|
}),
|
|
861
842
|
});
|
|
862
843
|
}
|
|
863
|
-
return new naslTypes.BinaryExpression({
|
|
844
|
+
return new utils_1.naslTypes.BinaryExpression({
|
|
864
845
|
operator: node.operator[0],
|
|
865
846
|
left: transformNode2Expression(node.left, type),
|
|
866
847
|
right: transformNode2Expression(node.right, type),
|
|
@@ -869,44 +850,44 @@ function transformNode2Expression(node, type) {
|
|
|
869
850
|
if (type !== 'logic') {
|
|
870
851
|
return transformNode2Expression(node.right, type);
|
|
871
852
|
}
|
|
872
|
-
return new naslTypes.Assignment({
|
|
853
|
+
return new utils_1.naslTypes.Assignment({
|
|
873
854
|
left: transformNode2Expression(node.left, type),
|
|
874
855
|
right: transformNode2Expression(node.right, type),
|
|
875
856
|
});
|
|
876
857
|
}
|
|
877
858
|
else if (node.type === 'NewExpression') {
|
|
878
|
-
const calleeName = (0,
|
|
859
|
+
const calleeName = (0, utils_1.generate)(node.callee).code;
|
|
879
860
|
if (['Boolean', 'Integer', 'Double', 'Decimal', 'Long'].includes(calleeName)) {
|
|
880
861
|
return transformNode2Expression(node.arguments[0], type);
|
|
881
862
|
}
|
|
882
|
-
throwError(`Unhandled node ${node.type}`);
|
|
863
|
+
(0, utils_1.throwError)(`Unhandled node ${node.type}`);
|
|
883
864
|
}
|
|
884
865
|
else if (node.type === 'ArrowFunctionExpression') {
|
|
885
|
-
return new naslTypes.AnonymousFunction({
|
|
866
|
+
return new utils_1.naslTypes.AnonymousFunction({
|
|
886
867
|
params: node.params.map((param) => transformParam(param)),
|
|
887
868
|
body: transformNode2Expression(node.body, type),
|
|
888
869
|
});
|
|
889
870
|
}
|
|
890
871
|
else if (node.type === 'BooleanLiteral') {
|
|
891
|
-
return new naslTypes.BooleanLiteral({
|
|
872
|
+
return new utils_1.naslTypes.BooleanLiteral({
|
|
892
873
|
value: String(node.value),
|
|
893
874
|
});
|
|
894
875
|
}
|
|
895
876
|
else if (node.type === 'StringLiteral') {
|
|
896
|
-
return new naslTypes.StringLiteral({
|
|
877
|
+
return new utils_1.naslTypes.StringLiteral({
|
|
897
878
|
value: node.value,
|
|
898
879
|
});
|
|
899
880
|
}
|
|
900
881
|
else if (node.type === 'NumericLiteral') {
|
|
901
|
-
const literal = new naslTypes.NumericLiteral({
|
|
882
|
+
const literal = new utils_1.naslTypes.NumericLiteral({
|
|
902
883
|
value: String(node.value),
|
|
903
|
-
typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
884
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
904
885
|
});
|
|
905
886
|
literal.typeAnnotation.typeName = literal.changeType(String(node.value));
|
|
906
887
|
return literal;
|
|
907
888
|
}
|
|
908
889
|
else if (node.type === 'NullLiteral') {
|
|
909
|
-
return new naslTypes.NullLiteral();
|
|
890
|
+
return new utils_1.naslTypes.NullLiteral();
|
|
910
891
|
}
|
|
911
892
|
else if (node.type === 'TemplateLiteral') {
|
|
912
893
|
const expressions = [...node.expressions, ...node.quasis.map((element) => ({
|
|
@@ -916,7 +897,7 @@ function transformNode2Expression(node, type) {
|
|
|
916
897
|
end: element.end,
|
|
917
898
|
}))];
|
|
918
899
|
expressions.sort((a, b) => a.start - b.start);
|
|
919
|
-
return new naslTypes.StringInterpolation({
|
|
900
|
+
return new utils_1.naslTypes.StringInterpolation({
|
|
920
901
|
expressions: expressions.map((item) => transformNode2Expression(item, type)),
|
|
921
902
|
});
|
|
922
903
|
}
|
|
@@ -926,17 +907,17 @@ function transformNode2Expression(node, type) {
|
|
|
926
907
|
if (node.operator === '!==')
|
|
927
908
|
node.operator = '!=';
|
|
928
909
|
if (['+', '-', '*', '/', '%', '==', '!=', '>', '<', '>=', '<=', '&&', '||', 'startwith', 'endwith', 'like', 'in'].includes(node.operator)) {
|
|
929
|
-
return new naslTypes.BinaryExpression({
|
|
910
|
+
return new utils_1.naslTypes.BinaryExpression({
|
|
930
911
|
operator: node.operator,
|
|
931
912
|
left: transformNode2Expression(node.left, type),
|
|
932
913
|
right: transformNode2Expression(node.right, type),
|
|
933
914
|
});
|
|
934
915
|
}
|
|
935
|
-
throwError(`Unhandled node ${node.type}`);
|
|
916
|
+
(0, utils_1.throwError)(`Unhandled node ${node.type}`);
|
|
936
917
|
}
|
|
937
918
|
else if (node.type === 'UnaryExpression') {
|
|
938
919
|
if (['!'].includes(node.operator)) {
|
|
939
|
-
return new naslTypes.UnaryExpression({
|
|
920
|
+
return new utils_1.naslTypes.UnaryExpression({
|
|
940
921
|
operator: node.operator,
|
|
941
922
|
argument: transformNode2Expression(node.argument, type),
|
|
942
923
|
});
|
|
@@ -947,18 +928,18 @@ function transformNode2Expression(node, type) {
|
|
|
947
928
|
value: -node.argument.value,
|
|
948
929
|
}, type);
|
|
949
930
|
}
|
|
950
|
-
throwError(`Unhandled node ${node.type}`);
|
|
931
|
+
(0, utils_1.throwError)(`Unhandled node ${node.type}`);
|
|
951
932
|
}
|
|
952
933
|
else if (node.type === 'UpdateExpression') {
|
|
953
934
|
if (node.operator === '++' || node.operator === '--') {
|
|
954
|
-
return new naslTypes.Assignment({
|
|
935
|
+
return new utils_1.naslTypes.Assignment({
|
|
955
936
|
left: transformNode2Expression(node.argument, type),
|
|
956
|
-
right: new naslTypes.BinaryExpression({
|
|
937
|
+
right: new utils_1.naslTypes.BinaryExpression({
|
|
957
938
|
operator: node.operator[0],
|
|
958
939
|
left: transformNode2Expression(node.argument, type),
|
|
959
|
-
right: new naslTypes.NumericLiteral({
|
|
940
|
+
right: new utils_1.naslTypes.NumericLiteral({
|
|
960
941
|
value: '1',
|
|
961
|
-
typeAnnotation: naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
942
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createPrimitive('Integer'),
|
|
962
943
|
}),
|
|
963
944
|
}),
|
|
964
945
|
});
|
|
@@ -966,11 +947,11 @@ function transformNode2Expression(node, type) {
|
|
|
966
947
|
}
|
|
967
948
|
else if (node.type === 'ReturnStatement') {
|
|
968
949
|
if (node?.ends) {
|
|
969
|
-
return new naslTypes.End();
|
|
950
|
+
return new utils_1.naslTypes.End();
|
|
970
951
|
}
|
|
971
952
|
}
|
|
972
953
|
else if (node.type === 'EmptyStatement') {
|
|
973
|
-
return node.leadingComments && new naslTypes.Comment({
|
|
954
|
+
return node.leadingComments && new utils_1.naslTypes.Comment({
|
|
974
955
|
value: String(node.leadingComments[0].value),
|
|
975
956
|
});
|
|
976
957
|
}
|
|
@@ -987,77 +968,104 @@ function transformNode2Expression(node, type) {
|
|
|
987
968
|
if (arg.value.type === 'MemberExpression') {
|
|
988
969
|
const expression = flatMemberExpression(arg.value);
|
|
989
970
|
const members = flatMembers(transformNode2Expression(arg.value, type));
|
|
990
|
-
rights.push(new naslTypes.SelectMembers({
|
|
971
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
991
972
|
expression: transformNode2Expression(expression[0]),
|
|
992
973
|
members,
|
|
993
974
|
}));
|
|
994
975
|
if (arg?.value) {
|
|
995
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
976
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
996
977
|
leftIndex: [0, index],
|
|
997
978
|
rightIndex: [index, members.length - 1],
|
|
998
979
|
}));
|
|
999
980
|
}
|
|
1000
981
|
}
|
|
1001
982
|
else {
|
|
1002
|
-
rights.push(new naslTypes.SelectMembers({
|
|
983
|
+
rights.push(new utils_1.naslTypes.SelectMembers({
|
|
1003
984
|
expression: transformNode2Expression(arg?.value, type)
|
|
1004
985
|
}));
|
|
1005
986
|
if (arg?.value) {
|
|
1006
|
-
assignmentLines.push(new naslTypes.AssignmentLine({
|
|
987
|
+
assignmentLines.push(new utils_1.naslTypes.AssignmentLine({
|
|
1007
988
|
leftIndex: [0, index],
|
|
1008
989
|
rightIndex: [index],
|
|
1009
990
|
}));
|
|
1010
991
|
}
|
|
1011
992
|
}
|
|
1012
|
-
structureProperties.push(new naslTypes.StructureProperty({
|
|
993
|
+
structureProperties.push(new utils_1.naslTypes.StructureProperty({
|
|
1013
994
|
name: arg?.key?.name,
|
|
1014
995
|
typeAnnotation: null
|
|
1015
996
|
}));
|
|
1016
997
|
});
|
|
1017
|
-
return new naslTypes.NewComposite({
|
|
1018
|
-
typeAnnotation: naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
|
|
998
|
+
return new utils_1.naslTypes.NewComposite({
|
|
999
|
+
typeAnnotation: utils_1.naslTypes.TypeAnnotation.createTypeAnonymousStructure(structureProperties),
|
|
1019
1000
|
properties,
|
|
1020
1001
|
rights,
|
|
1021
1002
|
assignmentLines
|
|
1022
1003
|
});
|
|
1023
1004
|
}
|
|
1024
1005
|
else {
|
|
1025
|
-
throwError(`Unhandled node ${node.type}`);
|
|
1006
|
+
(0, utils_1.throwError)(`Unhandled node ${node.type}`);
|
|
1026
1007
|
}
|
|
1027
1008
|
}
|
|
1028
1009
|
// 处理逻辑
|
|
1029
|
-
function transformNode2Logic(node, name) {
|
|
1010
|
+
function transformNode2Logic(node, name, type) {
|
|
1030
1011
|
const parameters = node.params;
|
|
1031
1012
|
const statements = node.body.body;
|
|
1032
|
-
const curLogic = new naslTypes.Logic({ name: name ?? node.id.name });
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
curLogic.
|
|
1037
|
-
|
|
1038
|
-
|
|
1013
|
+
const curLogic = new utils_1.naslTypes.Logic({ name: name ?? node.id.name });
|
|
1014
|
+
if (type !== 'event_logic') {
|
|
1015
|
+
parameters.forEach((item) => {
|
|
1016
|
+
const param = transformParam(item);
|
|
1017
|
+
if (param && param.name !== 'event' && !curLogic.params.find((_) => _.name === param.name))
|
|
1018
|
+
curLogic.addParam(param);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
statements?.forEach((item) => {
|
|
1039
1022
|
if (item.type === 'ReturnStatement' && item?.argument) {
|
|
1040
|
-
if (
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1023
|
+
if (type === 'view_logic') {
|
|
1024
|
+
if (item.argument?.type === 'Identifier') {
|
|
1025
|
+
if (!curLogic.returns.length) {
|
|
1026
|
+
const curVariable = curLogic?.variables?.find((it) => it.name === item?.argument?.name);
|
|
1027
|
+
if (curVariable) {
|
|
1028
|
+
curLogic.variables = curLogic?.variables?.filter((it) => it.name !== item?.argument?.name);
|
|
1029
|
+
curLogic.addReturn(curVariable);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
else {
|
|
1034
|
+
if (!curLogic.returns.length) {
|
|
1035
|
+
curLogic.returns.push(new utils_1.naslTypes.Return({
|
|
1036
|
+
name: 'result',
|
|
1037
|
+
}));
|
|
1038
|
+
}
|
|
1039
|
+
const logicItem = new utils_1.naslTypes.Assignment({
|
|
1040
|
+
left: new utils_1.naslTypes.Identifier({
|
|
1041
|
+
name: curLogic.returns[0].name,
|
|
1042
|
+
}),
|
|
1043
|
+
right: transformNode2Expression(item.argument, 'logic')
|
|
1044
|
+
});
|
|
1045
|
+
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
else {
|
|
1049
|
+
if (item.argument?.type !== 'Identifier') {
|
|
1050
|
+
curLogic.addVariable('tempVar');
|
|
1051
|
+
const logicItem = new utils_1.naslTypes.Assignment({
|
|
1052
|
+
left: new utils_1.naslTypes.Identifier({
|
|
1053
|
+
name: 'tempVar',
|
|
1054
|
+
}),
|
|
1055
|
+
right: transformNode2Expression(item.argument, 'logic')
|
|
1056
|
+
});
|
|
1057
|
+
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
1058
|
+
}
|
|
1044
1059
|
}
|
|
1045
|
-
const logicItem = new naslTypes.Assignment({
|
|
1046
|
-
left: new naslTypes.Identifier({
|
|
1047
|
-
name: curLogic.returns[0].name,
|
|
1048
|
-
}),
|
|
1049
|
-
right: transformNode2Expression(item.argument, 'logic')
|
|
1050
|
-
});
|
|
1051
|
-
curLogic.insertItemInBodyAt(logicItem, curLogic.body.length - 1);
|
|
1052
1060
|
}
|
|
1053
1061
|
else {
|
|
1054
1062
|
let logicItem = transformNode2Expression(item, 'logic');
|
|
1055
1063
|
if (logicItem) {
|
|
1056
1064
|
if (logicItem.concept === 'Variable') {
|
|
1057
1065
|
if (!curLogic.variables.find((_) => _.name === logicItem.name))
|
|
1058
|
-
curLogic.addVariable(logicItem);
|
|
1059
|
-
logicItem = new naslTypes.Assignment({
|
|
1060
|
-
left: new naslTypes.Identifier({ name: logicItem?.name }),
|
|
1066
|
+
curLogic.addVariable({ ...logicItem, defaultValue: undefined });
|
|
1067
|
+
logicItem = new utils_1.naslTypes.Assignment({
|
|
1068
|
+
left: new utils_1.naslTypes.Identifier({ name: logicItem?.name }),
|
|
1061
1069
|
right: logicItem.defaultValue?.expression || '',
|
|
1062
1070
|
});
|
|
1063
1071
|
if (logicItem.right)
|
|
@@ -1087,7 +1095,7 @@ function transformNode2Attribute(node) {
|
|
|
1087
1095
|
item = {
|
|
1088
1096
|
name: node.key.name,
|
|
1089
1097
|
type: 'string',
|
|
1090
|
-
value: (0,
|
|
1098
|
+
value: (0, utils_1.generate)(node.value.body).code,
|
|
1091
1099
|
};
|
|
1092
1100
|
}
|
|
1093
1101
|
else if (['CallExpression'].includes(node.value.type) && node.value?.callee?.name === 'sync') {
|
|
@@ -1098,6 +1106,35 @@ function transformNode2Attribute(node) {
|
|
|
1098
1106
|
expression: transformNode2Expression(node.value.arguments[0]),
|
|
1099
1107
|
};
|
|
1100
1108
|
}
|
|
1109
|
+
else if (['destination'].includes(node.key.name)) {
|
|
1110
|
+
const namespace = node?.value?.arguments?.[0]?.value;
|
|
1111
|
+
const nsArr = namespace.split('.').map((it) => it.replace(/_view$/, ''));
|
|
1112
|
+
const pageType = nsArr.shift();
|
|
1113
|
+
const viewName = nsArr.pop();
|
|
1114
|
+
const newArguments = node?.value?.arguments?.slice(1);
|
|
1115
|
+
let argument = [];
|
|
1116
|
+
if (newArguments?.[0]?.type === 'ObjectExpression') {
|
|
1117
|
+
argument = newArguments?.[0]?.properties?.map((property) => new utils_1.naslTypes.Argument({
|
|
1118
|
+
keyword: property?.key?.name,
|
|
1119
|
+
expression: fixExpression(property?.value),
|
|
1120
|
+
}));
|
|
1121
|
+
}
|
|
1122
|
+
else {
|
|
1123
|
+
argument = node?.arguments?.slice(1)?.map((arg) => new utils_1.naslTypes.Argument({
|
|
1124
|
+
expression: fixExpression(arg),
|
|
1125
|
+
}));
|
|
1126
|
+
}
|
|
1127
|
+
const destination = new utils_1.naslTypes.Destination({
|
|
1128
|
+
viewNamespace: `app.frontendTypes.${pageType}.frontends.${pageType}.views${nsArr?.map((it) => `.${it}.views`)?.join('')}`,
|
|
1129
|
+
viewName,
|
|
1130
|
+
arguments: argument,
|
|
1131
|
+
});
|
|
1132
|
+
item = {
|
|
1133
|
+
name: node?.key?.name,
|
|
1134
|
+
type: 'dynamic',
|
|
1135
|
+
destination,
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1101
1138
|
else {
|
|
1102
1139
|
// ['TemplateLiteral', 'BooleanLiteral', 'NullLiteral', 'CallExpression']
|
|
1103
1140
|
item = {
|
|
@@ -1112,7 +1149,7 @@ function transformNode2Attribute(node) {
|
|
|
1112
1149
|
if (propertyName === 'tooltip') {
|
|
1113
1150
|
item.rawName = 'v-tooltip';
|
|
1114
1151
|
}
|
|
1115
|
-
newNode = new naslTypes.BindDirective({ ...item, name: propertyName });
|
|
1152
|
+
newNode = new utils_1.naslTypes.BindDirective({ ...item, name: propertyName });
|
|
1116
1153
|
}
|
|
1117
1154
|
else if (['_staticStyle'].includes(node.key.name)) {
|
|
1118
1155
|
newNode = {
|
|
@@ -1124,11 +1161,11 @@ function transformNode2Attribute(node) {
|
|
|
1124
1161
|
else if (['_color', '_backgroundColor', '_backgroundImage'].includes(node.key.name)) {
|
|
1125
1162
|
// 样式属性
|
|
1126
1163
|
const propertyName = node.key?.name?.replace(/^_/, '').replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
1127
|
-
newNode = new naslTypes.BindStyle({ ...item, name: propertyName });
|
|
1164
|
+
newNode = new utils_1.naslTypes.BindStyle({ ...item, name: propertyName });
|
|
1128
1165
|
}
|
|
1129
1166
|
else {
|
|
1130
1167
|
// 组件属性
|
|
1131
|
-
newNode = new naslTypes.BindAttribute(item);
|
|
1168
|
+
newNode = new utils_1.naslTypes.BindAttribute(item);
|
|
1132
1169
|
}
|
|
1133
1170
|
return newNode;
|
|
1134
1171
|
}
|
|
@@ -1137,18 +1174,18 @@ function transformNode2ViewElement(node, componentName) {
|
|
|
1137
1174
|
if (viewNode.type === 'ObjectExpression') {
|
|
1138
1175
|
const tag = (0, lodash_1.kebabCase)((node?.callee).name);
|
|
1139
1176
|
const name = componentName?.replace(/-/g, '_');
|
|
1140
|
-
const newViewElement = new naslTypes.ViewElement({
|
|
1177
|
+
const newViewElement = new utils_1.naslTypes.ViewElement({
|
|
1141
1178
|
tag,
|
|
1142
1179
|
name,
|
|
1143
1180
|
});
|
|
1144
|
-
viewNode.properties
|
|
1181
|
+
viewNode.properties?.forEach((prop, propIndex) => {
|
|
1145
1182
|
if (prop?.value?.type === 'ArrayExpression' && ['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.elements?.[0]?.type)) {
|
|
1146
1183
|
// 事件逻辑
|
|
1147
1184
|
const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
|
|
1148
|
-
const bindEvent = new naslTypes.BindEvent({ name: eventName });
|
|
1185
|
+
const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
|
|
1149
1186
|
prop.value.elements.forEach((element) => {
|
|
1150
1187
|
const logicName = bindEvent.getLogicUniqueName();
|
|
1151
|
-
const curLogic = transformNode2Logic(element, logicName);
|
|
1188
|
+
const curLogic = transformNode2Logic(element, logicName, 'event_logic');
|
|
1152
1189
|
bindEvent.addLogic(curLogic);
|
|
1153
1190
|
});
|
|
1154
1191
|
newViewElement.addBindEvent(bindEvent);
|
|
@@ -1156,9 +1193,9 @@ function transformNode2ViewElement(node, componentName) {
|
|
|
1156
1193
|
else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.type) && /^on/.test(prop.key.name)) {
|
|
1157
1194
|
// 事件逻辑
|
|
1158
1195
|
const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
|
|
1159
|
-
const bindEvent = new naslTypes.BindEvent({ name: eventName });
|
|
1196
|
+
const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
|
|
1160
1197
|
const logicName = bindEvent.getLogicUniqueName();
|
|
1161
|
-
bindEvent.addLogic(transformNode2Logic(prop.value, logicName));
|
|
1198
|
+
bindEvent.addLogic(transformNode2Logic(prop.value, logicName, 'event_logic'));
|
|
1162
1199
|
newViewElement.addBindEvent(bindEvent);
|
|
1163
1200
|
}
|
|
1164
1201
|
else if (['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.type) && ['ArrayExpression'].includes(prop.value.body?.type)) {
|
|
@@ -1184,7 +1221,7 @@ function transformNode2ViewElement(node, componentName) {
|
|
|
1184
1221
|
}
|
|
1185
1222
|
else {
|
|
1186
1223
|
const slotScope = prop.value?.params[0]?.name || '';
|
|
1187
|
-
const newTemplateElement = new naslTypes.ViewElement({
|
|
1224
|
+
const newTemplateElement = new utils_1.naslTypes.ViewElement({
|
|
1188
1225
|
tag: 'template',
|
|
1189
1226
|
slotTarget,
|
|
1190
1227
|
slotScope,
|
|
@@ -1193,13 +1230,13 @@ function transformNode2ViewElement(node, componentName) {
|
|
|
1193
1230
|
prop.value.body.elements.forEach((element, index) => {
|
|
1194
1231
|
// $ref.componentName = new xxx({}) 形式,这种是标准的
|
|
1195
1232
|
if (element.type === 'AssignmentExpression' && element.right?.type === 'NewExpression') {
|
|
1196
|
-
newTemplateElement.name = `template_${(0,
|
|
1233
|
+
newTemplateElement.name = `template_${(0, utils_2.genHash)(`${slotTarget}_template_${propIndex}_${name}`)}`;
|
|
1197
1234
|
const elementName = element?.left?.property?.name;
|
|
1198
1235
|
newTemplateElement.addViewElement(transformNode2ViewElement(element.right, elementName));
|
|
1199
1236
|
}
|
|
1200
1237
|
// new xxx({}) 形式,这种是没有组件名称,为了兼容,自己建一个
|
|
1201
1238
|
if (element.type === 'NewExpression') {
|
|
1202
|
-
newTemplateElement.name = `template_${(0,
|
|
1239
|
+
newTemplateElement.name = `template_${(0, utils_2.genHash)(`${slotTarget}_template_${propIndex}_${name}`)}`;
|
|
1203
1240
|
const eleTag = (0, lodash_1.kebabCase)((element?.callee).name);
|
|
1204
1241
|
const eleName = `${eleTag}_${index}_${newTemplateElement.name}`;
|
|
1205
1242
|
newTemplateElement.addViewElement(transformNode2ViewElement(element, eleName));
|
|
@@ -1235,12 +1272,18 @@ function transformNode2ViewConstruct(node) {
|
|
|
1235
1272
|
// console.log("lemon ~ transformNode2ViewConstruct ~ node:", node);
|
|
1236
1273
|
// 变量声明
|
|
1237
1274
|
if (node.type === 'VariableDeclaration') {
|
|
1275
|
+
const declList = node?.declarations || [];
|
|
1276
|
+
const declListFirstNodde = declList[0];
|
|
1277
|
+
const variableName = declListFirstNodde?.id?.name;
|
|
1278
|
+
if (variableName === '$lifecycles' && declListFirstNodde.init) {
|
|
1279
|
+
return transformLifecycle(declListFirstNodde.init);
|
|
1280
|
+
}
|
|
1238
1281
|
return transformVariableDeclaration(node);
|
|
1239
1282
|
}
|
|
1240
1283
|
// 页面逻辑
|
|
1241
1284
|
if (node.type === 'FunctionDeclaration') {
|
|
1242
1285
|
const logicName = node.id.name.replace(/^viewLogic_/, '');
|
|
1243
|
-
return transformNode2Logic(node, logicName);
|
|
1286
|
+
return transformNode2Logic(node, logicName, 'view_logic');
|
|
1244
1287
|
}
|
|
1245
1288
|
if (node.type === 'ExpressionStatement') {
|
|
1246
1289
|
return transformNode2ViewConstruct(node.expression);
|
|
@@ -1273,12 +1316,20 @@ function transformNode2ViewConstruct(node) {
|
|
|
1273
1316
|
else {
|
|
1274
1317
|
properties?.[3].value.elements.forEach((element) => {
|
|
1275
1318
|
let newNode = {};
|
|
1319
|
+
const propertiesMap = ['BindDirective', 'BindStyle', 'BindAttribute'];
|
|
1276
1320
|
if (properties?.[2].value.value === 'ViewElement') {
|
|
1277
1321
|
newNode = transformNode2ViewConstruct(element);
|
|
1278
1322
|
}
|
|
1279
|
-
else if (properties?.[2]
|
|
1323
|
+
else if (propertiesMap.includes(properties?.[2]?.value?.value)) {
|
|
1280
1324
|
newNode = transformNode2Attribute({ key: element.left, value: element.right });
|
|
1281
1325
|
}
|
|
1326
|
+
else if (properties?.[2]?.value?.value === 'BindEvent') {
|
|
1327
|
+
const eventName = element?.left?.name?.replace(/^on/, '')?.toLowerCase();
|
|
1328
|
+
const bindEvent = new utils_1.naslTypes.BindEvent({ name: eventName });
|
|
1329
|
+
const logicName = bindEvent.getLogicUniqueName();
|
|
1330
|
+
bindEvent.addLogic(transformNode2Logic(element?.right?.elements[0], logicName, 'event_logic'));
|
|
1331
|
+
newNode = bindEvent;
|
|
1332
|
+
}
|
|
1282
1333
|
const newNodeBackup = (0, lodash_1.cloneDeep)(newNode);
|
|
1283
1334
|
newNode.aiParams = {
|
|
1284
1335
|
action: properties?.[0].value.value,
|
|
@@ -1306,11 +1357,22 @@ function transformNode2View(node, root) {
|
|
|
1306
1357
|
if (currentPositionComment) {
|
|
1307
1358
|
statements = statements.filter((stat) => stat.start > currentPositionComment.start);
|
|
1308
1359
|
}
|
|
1309
|
-
const view = new naslTypes.View();
|
|
1310
|
-
parameters
|
|
1311
|
-
const
|
|
1312
|
-
|
|
1313
|
-
|
|
1360
|
+
const view = new utils_1.naslTypes.View();
|
|
1361
|
+
if (parameters?.length === 1 && parameters?.[0]?.type === 'ObjectPattern') {
|
|
1362
|
+
const { properties } = parameters[0] || {};
|
|
1363
|
+
properties?.forEach((item) => {
|
|
1364
|
+
const param = transformParam(item);
|
|
1365
|
+
view.params = view.params || [];
|
|
1366
|
+
param && view.params.push(param);
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
else {
|
|
1370
|
+
parameters?.forEach((item) => {
|
|
1371
|
+
const param = transformParam(item);
|
|
1372
|
+
view.params = view.params || [];
|
|
1373
|
+
param && view.params.push(param);
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1314
1376
|
const json = [];
|
|
1315
1377
|
statements.forEach((item) => {
|
|
1316
1378
|
const viewItem = transformNode2ViewConstruct(item);
|
|
@@ -1324,7 +1386,8 @@ function transformNode2View(node, root) {
|
|
|
1324
1386
|
viewItem?.forEach((element) => {
|
|
1325
1387
|
if (element.aiParams)
|
|
1326
1388
|
json.push(element.aiParams);
|
|
1327
|
-
|
|
1389
|
+
if (element?.concept === 'ViewElement')
|
|
1390
|
+
view.addViewElement(element);
|
|
1328
1391
|
});
|
|
1329
1392
|
}
|
|
1330
1393
|
if (viewItem?.concept === 'Variable') {
|
|
@@ -1340,6 +1403,12 @@ function transformNode2View(node, root) {
|
|
|
1340
1403
|
if (viewItem.aiParams)
|
|
1341
1404
|
json.push(viewItem.aiParams);
|
|
1342
1405
|
}
|
|
1406
|
+
// 生命周期函数
|
|
1407
|
+
if (item.type === 'VariableDeclaration' && Array.isArray(viewItem) && viewItem[0]?.concept === 'BindEvent') {
|
|
1408
|
+
viewItem.forEach((bindEvent) => {
|
|
1409
|
+
view.addBindEvent(bindEvent);
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1343
1412
|
});
|
|
1344
1413
|
// console.log("lemon ~ 转换出的 view:", view);
|
|
1345
1414
|
return { view: view.toJSON(), json };
|
|
@@ -1362,22 +1431,24 @@ const transformTS2View = (tsCode) => {
|
|
|
1362
1431
|
// console.log("lemon ~ 初始 node", func);
|
|
1363
1432
|
return transformNode2View(func, root);
|
|
1364
1433
|
};
|
|
1365
|
-
const handleNodeName = (curView, object) => {
|
|
1366
|
-
const list = [];
|
|
1434
|
+
const handleNodeName = (curView, object, memory) => {
|
|
1435
|
+
const list = [...memory || []];
|
|
1367
1436
|
if (object.concept === 'ViewElement') {
|
|
1368
1437
|
const oldName = object.name;
|
|
1369
1438
|
const newName = curView?.getViewElementUniqueNameOld(oldName);
|
|
1370
1439
|
if (oldName !== newName) {
|
|
1371
|
-
object.name = `${newName}_${(0,
|
|
1440
|
+
object.name = `${newName}_${(0, utils_2.genHash)(new Date().getTime() + newName)}`;
|
|
1372
1441
|
list.push({ oldName, newName: object.name });
|
|
1373
1442
|
}
|
|
1374
1443
|
if (object?.children?.length) {
|
|
1375
1444
|
object.children.forEach((child) => {
|
|
1376
|
-
handleNodeName(curView, child);
|
|
1445
|
+
const { list: childList } = handleNodeName(curView, child, list);
|
|
1446
|
+
// 去重并合并
|
|
1447
|
+
list.push(...childList?.filter((item) => !list?.find((it) => it.oldName === item.oldName)));
|
|
1377
1448
|
});
|
|
1378
1449
|
}
|
|
1379
1450
|
}
|
|
1380
|
-
return {
|
|
1451
|
+
return { list };
|
|
1381
1452
|
};
|
|
1382
1453
|
function tryTransformTS2UI(tsCode, curView) {
|
|
1383
1454
|
if (tsCode.includes('```')) {
|
|
@@ -1387,7 +1458,7 @@ function tryTransformTS2UI(tsCode, curView) {
|
|
|
1387
1458
|
}
|
|
1388
1459
|
if (!curView)
|
|
1389
1460
|
return transformTS2View(tsCode);
|
|
1390
|
-
const newView = new naslTypes.View(curView);
|
|
1461
|
+
const newView = new utils_1.naslTypes.View(curView);
|
|
1391
1462
|
const { json } = transformTS2View(tsCode);
|
|
1392
1463
|
const replaceNameList = [];
|
|
1393
1464
|
const selectedNodeNames = [];
|