@lcap/nasl 3.8.3-beta.4 → 3.8.3-beta.6
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/common/BaseNode.d.ts +9 -4
- package/out/common/BaseNode.js +73 -18
- package/out/common/BaseNode.js.map +1 -1
- package/out/common/utils.d.ts +5 -1
- package/out/common/utils.js +188 -6
- package/out/common/utils.js.map +1 -1
- package/out/concepts/App__.js +17 -13
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/AuthLogicForCallInterface__.js +2 -50
- package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
- package/out/concepts/BusinessComponent__.js +2 -42
- package/out/concepts/BusinessComponent__.js.map +1 -1
- package/out/concepts/BusinessLogic__.js +2 -50
- package/out/concepts/BusinessLogic__.js.map +1 -1
- package/out/concepts/CallFunction__.d.ts +1 -1
- package/out/concepts/CallFunction__.js +1 -1
- package/out/concepts/CallLogic__.js +2 -2
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/Identifier__.d.ts +2 -0
- package/out/concepts/Identifier__.js +51 -5
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/Logic__.js +6 -101
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.d.ts +1 -1
- package/out/concepts/MemberExpression__.js +15 -3
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.d.ts +0 -1
- package/out/concepts/OqlQueryComponent__.js +0 -70
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/OverriddenLogic__.js +2 -50
- package/out/concepts/OverriddenLogic__.js.map +1 -1
- package/out/concepts/ProcessElementV2__.js +4 -0
- package/out/concepts/ProcessElementV2__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +4 -0
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/ProcessV2__.js +4 -0
- package/out/concepts/ProcessV2__.js.map +1 -1
- package/out/concepts/Process__.js +4 -0
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/SubLogic__.js +5 -50
- package/out/concepts/SubLogic__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +1 -1
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/View__.js +10 -49
- package/out/concepts/View__.js.map +1 -1
- package/out/generator/genBundleFiles.js +5 -5
- package/out/generator/permission.js +21 -5
- package/out/generator/permission.js.map +1 -1
- package/out/generator/release-body/body.js.map +1 -1
- package/out/natural/transformTS2UI.js +5 -5
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +5 -5
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/server/naslServer.js +20 -2
- package/out/server/naslServer.js.map +1 -1
- package/out/server/semanticData.d.ts +32 -0
- package/out/server/semanticData.js +371 -0
- package/out/server/semanticData.js.map +1 -0
- package/out/service/logic/api.d.ts +9 -0
- package/out/service/logic/api.js +6 -0
- package/out/service/logic/api.js.map +1 -1
- package/out/templator/block2nasl/viewMergeBlock.js +2 -1
- package/out/templator/block2nasl/viewMergeBlock.js.map +1 -1
- package/package.json +1 -1
- package/sandbox/stdlib/nasl.collection.ts +3 -3
- package/src/common/BaseNode.ts +106 -36
- package/src/common/utils.ts +227 -5
- package/src/concepts/App__.ts +17 -13
- package/src/concepts/AuthLogicForCallInterface__.ts +3 -56
- package/src/concepts/BusinessComponent__.ts +6 -51
- package/src/concepts/BusinessLogic__.ts +4 -56
- package/src/concepts/CallFunction__.ts +1 -1
- package/src/concepts/CallLogic__.ts +8 -4
- package/src/concepts/Identifier__.ts +57 -6
- package/src/concepts/Logic__.ts +9 -111
- package/src/concepts/MemberExpression__.ts +21 -7
- package/src/concepts/OqlQueryComponent__.ts +1 -74
- package/src/concepts/OverriddenLogic__.ts +4 -56
- package/src/concepts/ProcessElementV2__.ts +4 -0
- package/src/concepts/ProcessElement__.ts +4 -0
- package/src/concepts/ProcessV2__.ts +5 -0
- package/src/concepts/Process__.ts +4 -0
- package/src/concepts/SubLogic__.ts +6 -56
- package/src/concepts/TypeAnnotation__.ts +1 -1
- package/src/concepts/View__.ts +14 -54
- package/src/generator/genBundleFiles.ts +5 -5
- package/src/generator/permission.ts +23 -5
- package/src/generator/release-body/body.ts +0 -1
- package/src/natural/transformTS2UI.ts +5 -5
- package/src/natural/transforms/transform2LogicItem.ts +5 -5
- package/src/server/naslServer.ts +26 -2
- package/src/server/semanticData.ts +447 -0
- package/src/service/logic/api.js +6 -0
- package/src/templator/block2nasl/viewMergeBlock.ts +2 -1
- package/src/translator/utils.ts +1 -1
- package/test/concepts/logic/__snapshots__/toEmbeddedTS.spec.ts.snap +182 -0
- package/test/concepts/logic/constant.ts +5 -0
- package/test/concepts/logic/fixtures/variable-host-call-logic-member-expression.json +267 -0
- package/test/concepts/logic/fixtures/variable-host-call-logic-nested-member-expression copy.json +457 -0
- package/test/concepts/logic/fixtures/variable-host-call-logic-with-handle-error-member-expression.json +267 -0
- package/test/concepts/logic/toEmbeddedTS.spec.ts +15 -0
|
@@ -25,6 +25,7 @@ import * as types from './utils/types';
|
|
|
25
25
|
import * as asserts from './utils/asserts';
|
|
26
26
|
|
|
27
27
|
import Logic from './Logic__';
|
|
28
|
+
import { reCollectTyInferCtx } from '../server/semanticData';
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* 业务组件逻辑
|
|
@@ -135,61 +136,8 @@ export class BusinessLogic extends Logic {
|
|
|
135
136
|
// 需要类型推导的局部变量/返回值需要调整申明顺序
|
|
136
137
|
const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
|
|
137
138
|
const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
|
|
138
|
-
yield*
|
|
139
|
-
|
|
140
|
-
el &&
|
|
141
|
-
// 批量赋值
|
|
142
|
-
(asserts.isBatchAssignment(el) ||
|
|
143
|
-
// 赋值
|
|
144
|
-
(asserts.isAssignment(el) && el.left?.name) ||
|
|
145
|
-
// 内置函数对集合类型的推导
|
|
146
|
-
(asserts.isCallFunction(el) && el.derivablecollection?.name))
|
|
147
|
-
) {
|
|
148
|
-
if (el?.getAncestor('SubLogic')) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (asserts.isAssignment(el)) {
|
|
152
|
-
const advanceVar = self.variables?.find(
|
|
153
|
-
(variable) => !variable.typeAnnotation && el.left?.name === variable.name,
|
|
154
|
-
);
|
|
155
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
156
|
-
advanceMap.set(advanceVar, el);
|
|
157
|
-
}
|
|
158
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
|
|
159
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
160
|
-
advanceMap.set(advanceRn, el);
|
|
161
|
-
}
|
|
162
|
-
} else if (asserts.isCallFunction(el)) {
|
|
163
|
-
// 需要被推导的集合
|
|
164
|
-
const expression = el.derivablecollection;
|
|
165
|
-
// 宽泛意义上的变量(变量+出参)
|
|
166
|
-
const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
|
|
167
|
-
return !variable.typeAnnotation && expression?.name === variable.name;
|
|
168
|
-
});
|
|
169
|
-
if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
|
|
170
|
-
callFunctionAdvanceMap.set(advanceVar, el);
|
|
171
|
-
}
|
|
172
|
-
} else if (asserts.isBatchAssignment(el)) {
|
|
173
|
-
yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
|
|
174
|
-
const leftCode =
|
|
175
|
-
leftIndex.length === 1
|
|
176
|
-
? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
|
|
177
|
-
: yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
178
|
-
returnOrigin('');
|
|
179
|
-
const advanceVar = self.variables?.find(
|
|
180
|
-
(variable) => !variable.typeAnnotation && leftCode === variable.name,
|
|
181
|
-
);
|
|
182
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
183
|
-
advanceMap.set(advanceVar, el);
|
|
184
|
-
}
|
|
185
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
|
|
186
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
187
|
-
advanceMap.set(advanceRn, el);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
});
|
|
139
|
+
yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
|
|
140
|
+
|
|
193
141
|
// 兼容 return 没有类型情况
|
|
194
142
|
if (self.returns.length && self.returns[0].typeAnnotation) {
|
|
195
143
|
code += ': ';
|
|
@@ -360,7 +308,7 @@ export class BusinessLogic extends Logic {
|
|
|
360
308
|
&& itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
|
|
361
309
|
)
|
|
362
310
|
|| (
|
|
363
|
-
(asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
|
|
311
|
+
(asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
|
|
364
312
|
&& !(itemNode?.typeAnnotation)
|
|
365
313
|
)
|
|
366
314
|
) {
|
|
@@ -1667,7 +1667,9 @@ export class CallLogic extends LogicItem {
|
|
|
1667
1667
|
return tag;
|
|
1668
1668
|
}
|
|
1669
1669
|
|
|
1670
|
-
getCallNodeUsingCache(
|
|
1670
|
+
getCallNodeUsingCache(
|
|
1671
|
+
frontNdCache : Map<string, Logic>, serverNdCache : Map<string, Logic>,
|
|
1672
|
+
processNdCache : Map<string, Logic>): ['front' | 'server' | 'process', Logic | undefined] {
|
|
1671
1673
|
const cwKey = this.calleewholeKey;
|
|
1672
1674
|
if (serverNdCache.get(cwKey)) {
|
|
1673
1675
|
return ['server', serverNdCache.get(cwKey)];
|
|
@@ -1681,18 +1683,20 @@ export class CallLogic extends LogicItem {
|
|
|
1681
1683
|
|
|
1682
1684
|
let node;
|
|
1683
1685
|
// 如果是页面局部逻辑
|
|
1684
|
-
if (!this.calleeNamespace && this.calleeName && this.
|
|
1685
|
-
node = this.
|
|
1686
|
+
if (!this.calleeNamespace && this.calleeName && this.likeComponent) {
|
|
1687
|
+
node = this.likeComponent.logics.find((l) => l.name === this.calleeName);
|
|
1686
1688
|
} else if (this.calleeNamespace?.startsWith('nasl.')) {
|
|
1687
1689
|
// 如果是页面组件
|
|
1688
1690
|
node = getNaslNodeByNodeCallee(this.calleeNamespace, this.calleeName);
|
|
1689
1691
|
} else if (this.calleeNamespace?.startsWith('elements.')) {
|
|
1690
1692
|
// 查找组件的逻辑,用于展示默认值
|
|
1691
1693
|
const elementsLogic = (this.app as any)?.naslServer?.elementsLogic || {};
|
|
1694
|
+
|
|
1692
1695
|
let tag = this.getElementTagByLogic();
|
|
1693
1696
|
// tag转换为首字母大写,驼峰
|
|
1694
1697
|
tag = tag.replace(/^\S/, (s) => s.toUpperCase())
|
|
1695
|
-
|
|
1698
|
+
.replace(/-(\w)/g, (all, letter) => letter.toUpperCase());
|
|
1699
|
+
|
|
1696
1700
|
const logics = elementsLogic[`${tag}`] || [];
|
|
1697
1701
|
node = logics.find((l: any) => l.name === this.calleeName);
|
|
1698
1702
|
} else {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { wrapForEachToGenerator as wrapForEach } from '../utils/time-slicing';
|
|
2
1
|
import {
|
|
3
2
|
TranslatorState,
|
|
4
3
|
withSourceMap,
|
|
@@ -30,6 +29,7 @@ import * as types from './utils/types';
|
|
|
30
29
|
import * as asserts from './utils/asserts';
|
|
31
30
|
|
|
32
31
|
import LogicItem from './LogicItem__';
|
|
32
|
+
import { varScopeCtx } from '../server/semanticData';
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* 标识符
|
|
@@ -97,7 +97,30 @@ export class Identifier extends LogicItem {
|
|
|
97
97
|
return findConceptKeyWordByNamespace(this.namespace) === 'enums';
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
get view() {
|
|
101
|
+
if (varScopeCtx.isFirstScreen) {
|
|
102
|
+
return varScopeCtx.idToView.get(this);
|
|
103
|
+
} else {
|
|
104
|
+
return this.getAncestor('View') as View;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
种类 namespace
|
|
110
|
+
后端全局变量 app.backend.variables
|
|
111
|
+
后端局部变量 undefined
|
|
112
|
+
前端局部变量 ""
|
|
113
|
+
前端页面变量 ""
|
|
114
|
+
前端全局变量 app.frontendTypes.pc.frontends.pc.variables
|
|
115
|
+
*/
|
|
116
|
+
// 热点代码,优化前占首屏时间 7.4%(赫基 3.2s)
|
|
100
117
|
get isFrontendVariables() {
|
|
118
|
+
if (varScopeCtx.isFirstScreen) {
|
|
119
|
+
if (!varScopeCtx.frontendGlobalVars.has(this.name)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
101
124
|
const frontendType = this.getAncestor('FrontendType') as FrontendType;
|
|
102
125
|
return (
|
|
103
126
|
this.namespace?.startsWith(`app.frontendTypes.${frontendType?.kind}.frontends`) &&
|
|
@@ -223,6 +246,26 @@ export class Identifier extends LogicItem {
|
|
|
223
246
|
);
|
|
224
247
|
}
|
|
225
248
|
|
|
249
|
+
|
|
250
|
+
fastIsViewOrGlobalDataVariable() {
|
|
251
|
+
const { parentNode, namespace, jsName: name } = this;
|
|
252
|
+
const isMemberExpressionProperty =
|
|
253
|
+
parentNode?.concept === 'MemberExpression' && this.parentKey === 'property';
|
|
254
|
+
if (isMemberExpressionProperty) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const nameInComponentLike = varScopeCtx.varInViewOrComponent.has(name) || varScopeCtx.logicInViewOrComponent.has(name);
|
|
259
|
+
return nameInComponentLike ||
|
|
260
|
+
this.globalDataMap[name] ||
|
|
261
|
+
namespace?.endsWith('nasl.browser') ||
|
|
262
|
+
namespace?.endsWith('nasl.auth') ||
|
|
263
|
+
namespace?.endsWith('nasl.configuration') ||
|
|
264
|
+
namespace?.endsWith('nasl.process') ||
|
|
265
|
+
this.isEnum() ||
|
|
266
|
+
this.isFrontendVariables;
|
|
267
|
+
}
|
|
268
|
+
|
|
226
269
|
toBrief(): string {
|
|
227
270
|
return this.name || '-';
|
|
228
271
|
}
|
|
@@ -234,17 +277,25 @@ export class Identifier extends LogicItem {
|
|
|
234
277
|
@withSourceMapGenerator
|
|
235
278
|
*toEmbeddedTS(state = createCompilerState(), options?: any): TranslatorGenerator {
|
|
236
279
|
const self = this;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (
|
|
280
|
+
|
|
281
|
+
let test : boolean;
|
|
282
|
+
if (varScopeCtx.isFirstScreen) {
|
|
283
|
+
test = this.fastIsViewOrGlobalDataVariable();
|
|
284
|
+
} else {
|
|
285
|
+
test = self.view && this.isViewOrGlobalDataVariable();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// 热点代码,优化前占首屏时间为 11.1%(4.8s)
|
|
289
|
+
// 属于页面下的变量
|
|
290
|
+
if (test) {
|
|
240
291
|
// 变量名是否与流程名一致
|
|
241
292
|
const processV2 = this.app?.processV2s.find((processV2) => {
|
|
242
293
|
return processV2.name === this.name;
|
|
243
294
|
});
|
|
244
295
|
if (processV2) {
|
|
245
296
|
let matched = false;
|
|
246
|
-
const viewNamespace = view.getNamespace();
|
|
247
|
-
const viewName = view.name;
|
|
297
|
+
const viewNamespace = self.view.getNamespace();
|
|
298
|
+
const viewName = self.view.name;
|
|
248
299
|
processV2.traverseChildren((node) => {
|
|
249
300
|
if (node?.concept === 'Destination') {
|
|
250
301
|
const { viewNamespace: desViewNamespace, viewName: desViewName } = node;
|
package/src/concepts/Logic__.ts
CHANGED
|
@@ -49,6 +49,9 @@ import type CallFunction from './CallFunction__';
|
|
|
49
49
|
import ProcessElementV2 from './ProcessElementV2__';
|
|
50
50
|
import ProcessV2 from './ProcessV2__';
|
|
51
51
|
import type SubLogic from './SubLogic__';
|
|
52
|
+
|
|
53
|
+
import { reCollectTyInferCtx, varScopeCtx } from '../server/semanticData';
|
|
54
|
+
|
|
52
55
|
//================================================================================
|
|
53
56
|
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
54
57
|
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
@@ -1568,63 +1571,9 @@ export class Logic extends Annotatable {
|
|
|
1568
1571
|
// 需要类型推导的局部变量/返回值需要调整申明顺序
|
|
1569
1572
|
const advanceMap: Map<Return | Variable, Assignment | BatchAssignment | CallFunction> = new Map();
|
|
1570
1573
|
const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
|
|
1574
|
+
yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
|
|
1575
|
+
|
|
1571
1576
|
const IDENTIFIERMAP = new Set<Variable | Return>();
|
|
1572
|
-
// const needGetSourceMapOqlList: Promise<any>[] = [];
|
|
1573
|
-
yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
|
|
1574
|
-
if (
|
|
1575
|
-
el &&
|
|
1576
|
-
// 批量赋值
|
|
1577
|
-
(asserts.isBatchAssignment(el) ||
|
|
1578
|
-
// 赋值
|
|
1579
|
-
(asserts.isAssignment(el) && el.left?.name) ||
|
|
1580
|
-
// 内置函数对集合类型的推导
|
|
1581
|
-
(asserts.isCallFunction(el) && el.derivablecollection?.name))
|
|
1582
|
-
) {
|
|
1583
|
-
if (el?.getAncestor('SubLogic')) {
|
|
1584
|
-
return;
|
|
1585
|
-
}
|
|
1586
|
-
if (asserts.isAssignment(el)) {
|
|
1587
|
-
const advanceVar = self.variables?.find(
|
|
1588
|
-
(variable) => !variable.typeAnnotation && el.left?.name === variable.name,
|
|
1589
|
-
);
|
|
1590
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1591
|
-
advanceMap.set(advanceVar, el);
|
|
1592
|
-
}
|
|
1593
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
|
|
1594
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1595
|
-
advanceMap.set(advanceRn, el);
|
|
1596
|
-
}
|
|
1597
|
-
} else if (asserts.isCallFunction(el)) {
|
|
1598
|
-
// 需要被推导的集合
|
|
1599
|
-
const expression = el.derivablecollection;
|
|
1600
|
-
// 宽泛意义上的变量(变量+出参)
|
|
1601
|
-
const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
|
|
1602
|
-
return !variable.typeAnnotation && expression?.name === variable.name;
|
|
1603
|
-
});
|
|
1604
|
-
if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
|
|
1605
|
-
callFunctionAdvanceMap.set(advanceVar, el);
|
|
1606
|
-
}
|
|
1607
|
-
} else if (asserts.isBatchAssignment(el)) {
|
|
1608
|
-
yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
|
|
1609
|
-
const leftCode =
|
|
1610
|
-
leftIndex.length === 1
|
|
1611
|
-
? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
|
|
1612
|
-
: yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
1613
|
-
returnOrigin('');
|
|
1614
|
-
const advanceVar = self.variables?.find(
|
|
1615
|
-
(variable) => !variable.typeAnnotation && leftCode === variable.name,
|
|
1616
|
-
);
|
|
1617
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1618
|
-
advanceMap.set(advanceVar, el);
|
|
1619
|
-
}
|
|
1620
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
|
|
1621
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1622
|
-
advanceMap.set(advanceRn, el);
|
|
1623
|
-
}
|
|
1624
|
-
});
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
});
|
|
1628
1577
|
|
|
1629
1578
|
for (const variable of self.variables) {
|
|
1630
1579
|
const ts = yield* variable.defaultValue?.toEmbeddedTS?.() ?? utils.returnOrigin('');
|
|
@@ -1894,61 +1843,7 @@ export class Logic extends Annotatable {
|
|
|
1894
1843
|
// 需要类型推导的局部变量/返回值需要调整申明顺序
|
|
1895
1844
|
const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
|
|
1896
1845
|
const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
|
|
1897
|
-
yield*
|
|
1898
|
-
if (
|
|
1899
|
-
el &&
|
|
1900
|
-
// 批量赋值
|
|
1901
|
-
(asserts.isBatchAssignment(el) ||
|
|
1902
|
-
// 赋值
|
|
1903
|
-
(asserts.isAssignment(el) && el.left?.name) ||
|
|
1904
|
-
// 内置函数对集合类型的推导
|
|
1905
|
-
(asserts.isCallFunction(el) && el.derivablecollection?.name))
|
|
1906
|
-
) {
|
|
1907
|
-
if (el?.getAncestor('SubLogic')) {
|
|
1908
|
-
return;
|
|
1909
|
-
}
|
|
1910
|
-
if (asserts.isAssignment(el)) {
|
|
1911
|
-
const advanceVar = self.variables?.find(
|
|
1912
|
-
(variable) => !variable.typeAnnotation && el.left?.name === variable.name,
|
|
1913
|
-
);
|
|
1914
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1915
|
-
advanceMap.set(advanceVar, el);
|
|
1916
|
-
}
|
|
1917
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
|
|
1918
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1919
|
-
advanceMap.set(advanceRn, el);
|
|
1920
|
-
}
|
|
1921
|
-
} else if (asserts.isCallFunction(el)) {
|
|
1922
|
-
// 需要被推导的集合
|
|
1923
|
-
const expression = el.derivablecollection;
|
|
1924
|
-
// 宽泛意义上的变量(变量+出参)
|
|
1925
|
-
const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
|
|
1926
|
-
return !variable.typeAnnotation && expression?.name === variable.name;
|
|
1927
|
-
});
|
|
1928
|
-
if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
|
|
1929
|
-
callFunctionAdvanceMap.set(advanceVar, el);
|
|
1930
|
-
}
|
|
1931
|
-
} else if (asserts.isBatchAssignment(el)) {
|
|
1932
|
-
yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
|
|
1933
|
-
const leftCode =
|
|
1934
|
-
leftIndex.length === 1
|
|
1935
|
-
? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
|
|
1936
|
-
: yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
1937
|
-
returnOrigin('');
|
|
1938
|
-
const advanceVar = self.variables?.find(
|
|
1939
|
-
(variable) => !variable.typeAnnotation && leftCode === variable.name,
|
|
1940
|
-
);
|
|
1941
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1942
|
-
advanceMap.set(advanceVar, el);
|
|
1943
|
-
}
|
|
1944
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
|
|
1945
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1946
|
-
advanceMap.set(advanceRn, el);
|
|
1947
|
-
}
|
|
1948
|
-
});
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
});
|
|
1846
|
+
yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
|
|
1952
1847
|
|
|
1953
1848
|
const needChooseParamTypes = completeTypeParams.filter((typeParam) => typeParam.needChoose);
|
|
1954
1849
|
// 兼容 return 没有类型情况
|
|
@@ -2914,6 +2809,9 @@ export class Logic extends Annotatable {
|
|
|
2914
2809
|
subLogics: Array<SubLogic> = [];
|
|
2915
2810
|
|
|
2916
2811
|
getSubLogics() {
|
|
2812
|
+
if (varScopeCtx.isFirstScreen) {
|
|
2813
|
+
return;
|
|
2814
|
+
}
|
|
2917
2815
|
const subLogics = this.findNaslNodeByBFS((node: BaseNode) => {
|
|
2918
2816
|
if (node?.concept === 'SubLogic') {
|
|
2919
2817
|
return true;
|
|
@@ -125,7 +125,7 @@ export class MemberExpression extends LogicItem {
|
|
|
125
125
|
let elementTag;
|
|
126
126
|
|
|
127
127
|
if (this.object?.namespace?.startsWith('elements.$ce')) {
|
|
128
|
-
elementName = this.getAncestor('ViewElement')?.name
|
|
128
|
+
elementName = this.getAncestor('ViewElement')?.name
|
|
129
129
|
} else {
|
|
130
130
|
elementName = this.object.name;
|
|
131
131
|
}
|
|
@@ -173,7 +173,7 @@ export class MemberExpression extends LogicItem {
|
|
|
173
173
|
this.object?.object?.name === 'elements' &&
|
|
174
174
|
this.object?.property?.name === '$ce'
|
|
175
175
|
) {
|
|
176
|
-
return this.
|
|
176
|
+
return this.transformAtrrLogic({ type: 'toVue' });
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
const object = String(this.object?.toVue(options)); // undefined 也让正常展示
|
|
@@ -302,7 +302,7 @@ export class MemberExpression extends LogicItem {
|
|
|
302
302
|
this.object?.object?.name === 'elements' &&
|
|
303
303
|
this.object?.property?.name === '$ce'
|
|
304
304
|
) {
|
|
305
|
-
return this.
|
|
305
|
+
return this.transformAtrrLogic();
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
const object: string = this.object?.toJS(state);
|
|
@@ -409,10 +409,13 @@ export class MemberExpression extends LogicItem {
|
|
|
409
409
|
return value;
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
-
|
|
412
|
+
transformAtrrLogic(options?: { type: 'toVue' | 'toJS' }) {
|
|
413
413
|
const { type = 'toJS' } = options || {};
|
|
414
414
|
|
|
415
|
-
const elementName = this.getAncestor('ViewElement')?.name
|
|
415
|
+
const elementName = this.getAncestor('ViewElement')?.name
|
|
416
|
+
// varScopeCtx.isFirstScreen
|
|
417
|
+
// ? varScopeCtx.memExprToViewElem.get(this)?.name
|
|
418
|
+
// : this.getAncestor('ViewElement')?.name;
|
|
416
419
|
let element;
|
|
417
420
|
let elementTag;
|
|
418
421
|
|
|
@@ -490,6 +493,17 @@ export class MemberExpression extends LogicItem {
|
|
|
490
493
|
*toEmbeddedTS(state = createCompilerState()): TranslatorGenerator {
|
|
491
494
|
const self = this;
|
|
492
495
|
let code = '';
|
|
496
|
+
|
|
497
|
+
// 变量提升且是调用逻辑取属性,此时需要翻译为立即执行函数规避 TS 的 BUG
|
|
498
|
+
if (asserts.isCallLogic(self.object) && state.isVariableHost) {
|
|
499
|
+
code += '(() => {\nconst __$1 = ';
|
|
500
|
+
code += `${yield* self.object.toEmbeddedTS(shiftState(state, code, { inline: true }))};\n`
|
|
501
|
+
code += `return __$1.`;
|
|
502
|
+
code += self.property ? yield* self.property.toEmbeddedTS(shiftState(state, code, { inline: true })) : '';
|
|
503
|
+
code += ';})()';
|
|
504
|
+
return code;
|
|
505
|
+
}
|
|
506
|
+
|
|
493
507
|
const leftCode = self.object
|
|
494
508
|
? `${yield* self.object.toEmbeddedTS(shiftState(state, code, { inline: true }))}.`
|
|
495
509
|
: '';
|
|
@@ -516,7 +530,7 @@ export class MemberExpression extends LogicItem {
|
|
|
516
530
|
) {
|
|
517
531
|
let newCode = '';
|
|
518
532
|
if (self.object?.namespace?.startsWith('elements.$ce')) {
|
|
519
|
-
const elementName = self.getAncestor('ViewElement')?.name
|
|
533
|
+
const elementName = self.getAncestor('ViewElement')?.name
|
|
520
534
|
newCode += `__elements['${elementName}']`;
|
|
521
535
|
if (asserts.isIdentifier(self.property) && self.property?.name) {
|
|
522
536
|
newCode += `['${self.property?.name}']`;
|
|
@@ -537,7 +551,7 @@ export class MemberExpression extends LogicItem {
|
|
|
537
551
|
self.object?.property?.name === '$ce'
|
|
538
552
|
) {
|
|
539
553
|
let newCode = '';
|
|
540
|
-
const elementName = self.getAncestor('ViewElement')?.name
|
|
554
|
+
const elementName = self.getAncestor('ViewElement')?.name
|
|
541
555
|
newCode += `__elements['${elementName}']`;
|
|
542
556
|
newCode += `.${self.property?.name}`;
|
|
543
557
|
return newCode;
|
|
@@ -14,9 +14,6 @@ import type StructureProperty from './StructureProperty__';
|
|
|
14
14
|
import type Structure from './Structure__';
|
|
15
15
|
import type Identifier from './Identifier__';
|
|
16
16
|
import type MemberExpression from './MemberExpression__';
|
|
17
|
-
import type { Entity } from './Entity__';
|
|
18
|
-
import type { EntityProperty } from './EntityProperty__';
|
|
19
|
-
import { naslOQLCacheStore } from '../utils/language-cache/nasl';
|
|
20
17
|
|
|
21
18
|
//================================================================================
|
|
22
19
|
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
@@ -32,6 +29,7 @@ import * as asserts from './utils/asserts';
|
|
|
32
29
|
|
|
33
30
|
import TypeAnnotation from './TypeAnnotation__';
|
|
34
31
|
import LogicItem from './LogicItem__';
|
|
32
|
+
import api from '../service/logic/api';
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
35
|
* SQL 查询
|
|
@@ -278,77 +276,6 @@ export class OqlQueryComponent extends LogicItem {
|
|
|
278
276
|
return `sql"${code}"`;
|
|
279
277
|
}
|
|
280
278
|
|
|
281
|
-
// 从服务端获取 SQL -> TS 的翻译和 sourceMap
|
|
282
|
-
async requestEmbeddedTS(): Promise<any> {
|
|
283
|
-
const { http, logger } = this.rootNode.naslServer;
|
|
284
|
-
|
|
285
|
-
if (this.code) {
|
|
286
|
-
let dataSourceNasl = this.app.findNodeByCompleteName(this.dataSource)?.toJSON();
|
|
287
|
-
if (dataSourceNasl) {
|
|
288
|
-
dataSourceNasl = {
|
|
289
|
-
concept: 'DataSource',
|
|
290
|
-
entities: (dataSourceNasl.entities = dataSourceNasl.entities?.map((entity: Entity) => {
|
|
291
|
-
return {
|
|
292
|
-
name: entity.name,
|
|
293
|
-
concept: entity.concept,
|
|
294
|
-
tableName: entity.tableName,
|
|
295
|
-
properties: entity.properties?.map((prop: EntityProperty) => {
|
|
296
|
-
return {
|
|
297
|
-
name: prop.name,
|
|
298
|
-
concept: prop.concept,
|
|
299
|
-
columnName: prop.columnName,
|
|
300
|
-
};
|
|
301
|
-
}),
|
|
302
|
-
};
|
|
303
|
-
})),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const query = async () => {
|
|
308
|
-
const params = {
|
|
309
|
-
appId: 'myAppId',
|
|
310
|
-
oqlIdentifier: 'myoqlIdentifier',
|
|
311
|
-
dataSourceName: this.dataSource,
|
|
312
|
-
oql: this.code,
|
|
313
|
-
ideVersion: this.app.ideVersion,
|
|
314
|
-
dataSourceNasl,
|
|
315
|
-
typeScriptStartLine: 1,
|
|
316
|
-
typeScriptStartLineColumn: 1,
|
|
317
|
-
};
|
|
318
|
-
const key = JSON.stringify(params);
|
|
319
|
-
let res = null;
|
|
320
|
-
let canUseCache = false;
|
|
321
|
-
try {
|
|
322
|
-
res = await naslOQLCacheStore.getItem(key);
|
|
323
|
-
canUseCache = true;
|
|
324
|
-
} catch (error) {}
|
|
325
|
-
if (res !== null) {
|
|
326
|
-
return res;
|
|
327
|
-
}
|
|
328
|
-
return http
|
|
329
|
-
.post('/api/v1/querydebug/generate/typescript', params)
|
|
330
|
-
.then(async ({ data }) => {
|
|
331
|
-
if (canUseCache) {
|
|
332
|
-
try {
|
|
333
|
-
await naslOQLCacheStore.setItem(key, data);
|
|
334
|
-
} catch (error) {}
|
|
335
|
-
}
|
|
336
|
-
return data;
|
|
337
|
-
});
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
return query()
|
|
341
|
-
.then((data: any) => {
|
|
342
|
-
this.codeSourceMap = data.result ?? { typescript: '', lexicalErrorCode: 1001 };
|
|
343
|
-
})
|
|
344
|
-
.catch((err) => {
|
|
345
|
-
logger.error('Oql 请求失败', err.toString());
|
|
346
|
-
this.codeSourceMap = { typescript: '', lexicalErrorCode: 1001 };
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
this.codeSourceMap = { typescript: '', lexicalErrorCode: 1001 };
|
|
350
|
-
}
|
|
351
|
-
|
|
352
279
|
/**
|
|
353
280
|
* 获取添加时的默认选项
|
|
354
281
|
* @returns
|
|
@@ -59,6 +59,7 @@ import Param from './Param__';
|
|
|
59
59
|
import Return from './Return__';
|
|
60
60
|
import Variable from './Variable__';
|
|
61
61
|
import LogicItem from './LogicItem__';
|
|
62
|
+
import { reCollectTyInferCtx } from '../server/semanticData';
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* 覆写逻辑
|
|
@@ -1584,61 +1585,8 @@ export class OverriddenLogic extends BaseNode {
|
|
|
1584
1585
|
// 需要类型推导的局部变量/返回值需要调整申明顺序
|
|
1585
1586
|
const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
|
|
1586
1587
|
const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
|
|
1587
|
-
yield*
|
|
1588
|
-
|
|
1589
|
-
el &&
|
|
1590
|
-
// 批量赋值
|
|
1591
|
-
(asserts.isBatchAssignment(el) ||
|
|
1592
|
-
// 赋值
|
|
1593
|
-
(asserts.isAssignment(el) && el.left?.name) ||
|
|
1594
|
-
// 内置函数对集合类型的推导
|
|
1595
|
-
(asserts.isCallFunction(el) && el.derivablecollection?.name))
|
|
1596
|
-
) {
|
|
1597
|
-
if (el?.getAncestor('SubLogic')) {
|
|
1598
|
-
return;
|
|
1599
|
-
}
|
|
1600
|
-
if (asserts.isAssignment(el)) {
|
|
1601
|
-
const advanceVar = self.variables?.find(
|
|
1602
|
-
(variable) => !variable.typeAnnotation && el.left?.name === variable.name,
|
|
1603
|
-
);
|
|
1604
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1605
|
-
advanceMap.set(advanceVar, el);
|
|
1606
|
-
}
|
|
1607
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
|
|
1608
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1609
|
-
advanceMap.set(advanceRn, el);
|
|
1610
|
-
}
|
|
1611
|
-
} else if (asserts.isCallFunction(el)) {
|
|
1612
|
-
// 需要被推导的集合
|
|
1613
|
-
const expression = el.derivablecollection;
|
|
1614
|
-
// 宽泛意义上的变量(变量+出参)
|
|
1615
|
-
const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
|
|
1616
|
-
return !variable.typeAnnotation && expression?.name === variable.name;
|
|
1617
|
-
});
|
|
1618
|
-
if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
|
|
1619
|
-
callFunctionAdvanceMap.set(advanceVar, el);
|
|
1620
|
-
}
|
|
1621
|
-
} else if (asserts.isBatchAssignment(el)) {
|
|
1622
|
-
yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
|
|
1623
|
-
const leftCode =
|
|
1624
|
-
leftIndex.length === 1
|
|
1625
|
-
? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
|
|
1626
|
-
: yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
1627
|
-
returnOrigin('');
|
|
1628
|
-
const advanceVar = self.variables?.find(
|
|
1629
|
-
(variable) => !variable.typeAnnotation && leftCode === variable.name,
|
|
1630
|
-
);
|
|
1631
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1632
|
-
advanceMap.set(advanceVar, el);
|
|
1633
|
-
}
|
|
1634
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
|
|
1635
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1636
|
-
advanceMap.set(advanceRn, el);
|
|
1637
|
-
}
|
|
1638
|
-
});
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1588
|
+
yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
|
|
1589
|
+
|
|
1642
1590
|
// 兼容 return 没有类型情况
|
|
1643
1591
|
if (self.returns.length && self.returns[0].typeAnnotation) {
|
|
1644
1592
|
code += ': ';
|
|
@@ -1778,7 +1726,7 @@ export class OverriddenLogic extends BaseNode {
|
|
|
1778
1726
|
&& itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
|
|
1779
1727
|
)
|
|
1780
1728
|
|| (
|
|
1781
|
-
(asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
|
|
1729
|
+
(asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
|
|
1782
1730
|
&& !(itemNode?.typeAnnotation)
|
|
1783
1731
|
)
|
|
1784
1732
|
) {
|
|
@@ -45,6 +45,7 @@ import FlowConditionV2 from './FlowConditionV2__';
|
|
|
45
45
|
import Logic from './Logic__';
|
|
46
46
|
import BindEvent from './BindEvent__';
|
|
47
47
|
import ApprovalPolicyV2 from './ApprovalPolicyV2__';
|
|
48
|
+
import { varScopeCtx } from '../server/semanticData';
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* 流程元素
|
|
@@ -1536,6 +1537,9 @@ export class ProcessElementV2 extends BaseNode {
|
|
|
1536
1537
|
subLogics: Array<SubLogic> = [];
|
|
1537
1538
|
|
|
1538
1539
|
getSubLogics() {
|
|
1540
|
+
if (varScopeCtx.isFirstScreen) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1539
1543
|
const subLogics = this.findNaslNodeByBFS((node: BaseNode) => {
|
|
1540
1544
|
if (asserts.isSubLogic(node)) {
|
|
1541
1545
|
return true;
|
|
@@ -43,6 +43,7 @@ import Return from './Return__';
|
|
|
43
43
|
import Constant from './Constant__';
|
|
44
44
|
import BindAttribute from './BindAttribute__';
|
|
45
45
|
import MultiApprovalPolicy from './MultiApprovalPolicy__';
|
|
46
|
+
import { varScopeCtx } from '../server/semanticData';
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
49
|
* 流程元素
|
|
@@ -1733,6 +1734,9 @@ export class ProcessElement extends BaseNode {
|
|
|
1733
1734
|
// 只有 AutoTask 才需要在他的节点下找子逻辑
|
|
1734
1735
|
// 其他直接在 BindEvent 下找
|
|
1735
1736
|
if (this.type !== 'AutoTask') return [] as SubLogic[];
|
|
1737
|
+
if (varScopeCtx.isFirstScreen) {
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1736
1740
|
const subLogics = this.findNaslNodeByBFS((node: BaseNode) => {
|
|
1737
1741
|
if (asserts.isSubLogic(node)) {
|
|
1738
1742
|
return true;
|