@lcap/nasl 3.8.3-beta.3 → 3.8.3-beta.5
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/.nyc_output/5e5782a5-633b-47eb-bb36-1fbde5cd0e70.json +1 -0
- package/.nyc_output/processinfo/5e5782a5-633b-47eb-bb36-1fbde5cd0e70.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/coverage/cobertura-coverage.xml +10802 -66292
- 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/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/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 +7 -7
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +7 -7
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/server/naslServer.js +17 -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/templator/block2nasl/viewMergeBlock.js +2 -1
- package/out/templator/block2nasl/viewMergeBlock.js.map +1 -1
- package/package.json +1 -1
- package/src/common/BaseNode.ts +106 -36
- 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/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 +7 -7
- package/src/natural/transforms/transform2LogicItem.ts +7 -7
- package/src/server/naslServer.ts +22 -2
- package/src/server/semanticData.ts +447 -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
- package/.nyc_output/943352aa-23df-44e0-863b-3dcd3e8bf57a.json +0 -1
- package/.nyc_output/processinfo/943352aa-23df-44e0-863b-3dcd3e8bf57a.json +0 -1
|
@@ -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;
|
|
@@ -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;
|
|
@@ -28,6 +28,8 @@ import ProcessElementV2 from './ProcessElementV2__';
|
|
|
28
28
|
import HistoryProcessV2 from './HistoryProcessV2__';
|
|
29
29
|
import ProcessBindV2 from './ProcessBindV2__';
|
|
30
30
|
import BindEvent from './BindEvent__';
|
|
31
|
+
import { varScopeCtx } from '../server/semanticData';
|
|
32
|
+
|
|
31
33
|
/**
|
|
32
34
|
* 流程
|
|
33
35
|
*/
|
|
@@ -1046,6 +1048,9 @@ export class ProcessV2 extends BaseNode {
|
|
|
1046
1048
|
subLogics: Array<SubLogic> = [];
|
|
1047
1049
|
|
|
1048
1050
|
getSubLogics() {
|
|
1051
|
+
if (varScopeCtx.isFirstScreen) {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1049
1054
|
const subLogics = this.findNaslNodeByBFS((node: BaseNode) => {
|
|
1050
1055
|
if (asserts.isSubLogic(node)) {
|
|
1051
1056
|
return true;
|
|
@@ -36,6 +36,7 @@ import Param from './Param__';
|
|
|
36
36
|
import Return from './Return__';
|
|
37
37
|
import Constant from './Constant__';
|
|
38
38
|
import ProcessElement from './ProcessElement__';
|
|
39
|
+
import { varScopeCtx } from '../server/semanticData';
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* 流程
|
|
@@ -1497,6 +1498,9 @@ export class Process extends BaseNode {
|
|
|
1497
1498
|
subLogics: Array<SubLogic> = [];
|
|
1498
1499
|
|
|
1499
1500
|
getSubLogics() {
|
|
1501
|
+
if (varScopeCtx.isFirstScreen) {
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1500
1504
|
const subLogics = this.findNaslNodeByBFS((node: BaseNode) => {
|
|
1501
1505
|
if (asserts.isSubLogic(node)) {
|
|
1502
1506
|
return true;
|
|
@@ -63,6 +63,7 @@ import Param from './Param__';
|
|
|
63
63
|
import Return from './Return__';
|
|
64
64
|
import Variable from './Variable__';
|
|
65
65
|
import LogicItem from './LogicItem__';
|
|
66
|
+
import { reCollectTyInferCtx, varScopeCtx } from '../server/semanticData';
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* 子逻辑
|
|
@@ -1181,61 +1182,7 @@ export class SubLogic extends LogicItem {
|
|
|
1181
1182
|
code += ')';
|
|
1182
1183
|
const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
|
|
1183
1184
|
const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
|
|
1184
|
-
yield*
|
|
1185
|
-
if (
|
|
1186
|
-
el &&
|
|
1187
|
-
// 批量赋值
|
|
1188
|
-
(asserts.isBatchAssignment(el) ||
|
|
1189
|
-
// 赋值
|
|
1190
|
-
(asserts.isAssignment(el) && el.left?.name) ||
|
|
1191
|
-
// 内置函数对集合类型的推导
|
|
1192
|
-
(asserts.isCallFunction(el) && el.derivablecollection?.name))
|
|
1193
|
-
) {
|
|
1194
|
-
if (el?.getAncestor('SubLogic') !== self) {
|
|
1195
|
-
return;
|
|
1196
|
-
}
|
|
1197
|
-
if (asserts.isAssignment(el)) {
|
|
1198
|
-
const advanceVar = self.variables?.find(
|
|
1199
|
-
(variable) => !variable.typeAnnotation && el.left?.name === variable.name,
|
|
1200
|
-
);
|
|
1201
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1202
|
-
advanceMap.set(advanceVar, el);
|
|
1203
|
-
}
|
|
1204
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
|
|
1205
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1206
|
-
advanceMap.set(advanceRn, el);
|
|
1207
|
-
}
|
|
1208
|
-
} else if (asserts.isCallFunction(el)) {
|
|
1209
|
-
// 需要被推导的集合
|
|
1210
|
-
const expression = el.derivablecollection;
|
|
1211
|
-
// 宽泛意义上的变量(变量+出参)
|
|
1212
|
-
const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
|
|
1213
|
-
return !variable.typeAnnotation && expression?.name === variable.name;
|
|
1214
|
-
});
|
|
1215
|
-
if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
|
|
1216
|
-
callFunctionAdvanceMap.set(advanceVar, el);
|
|
1217
|
-
}
|
|
1218
|
-
} else if (asserts.isBatchAssignment(el)) {
|
|
1219
|
-
yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
|
|
1220
|
-
const leftCode =
|
|
1221
|
-
leftIndex.length === 1
|
|
1222
|
-
? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
|
|
1223
|
-
: yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
1224
|
-
returnOrigin('');
|
|
1225
|
-
const advanceVar = self.variables?.find(
|
|
1226
|
-
(variable) => !variable.typeAnnotation && leftCode === variable.name,
|
|
1227
|
-
);
|
|
1228
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1229
|
-
advanceMap.set(advanceVar, el);
|
|
1230
|
-
}
|
|
1231
|
-
const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
|
|
1232
|
-
if (advanceRn && !advanceMap.get(advanceRn)) {
|
|
1233
|
-
advanceMap.set(advanceRn, el);
|
|
1234
|
-
}
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1185
|
+
yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
|
|
1239
1186
|
|
|
1240
1187
|
// 兼容 return 没有类型情况
|
|
1241
1188
|
if (self.returns.length && self.returns[0].typeAnnotation) {
|
|
@@ -1508,7 +1455,10 @@ export class SubLogic extends LogicItem {
|
|
|
1508
1455
|
subLogics: SubLogic[] = [];
|
|
1509
1456
|
|
|
1510
1457
|
getSubLogics() {
|
|
1511
|
-
|
|
1458
|
+
if (varScopeCtx.isFirstScreen) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
const subLogics = this.findNaslNodeByBFS((node) => {
|
|
1512
1462
|
if (asserts.isSubLogic(node)) {
|
|
1513
1463
|
return true;
|
|
1514
1464
|
}
|
package/src/concepts/View__.ts
CHANGED
|
@@ -46,6 +46,8 @@ const removedViewElementCache: {
|
|
|
46
46
|
[key: string]: number | bigint;
|
|
47
47
|
} = {};
|
|
48
48
|
|
|
49
|
+
import { reCollectTyInferCtx, varScopeCtx } from '../server/semanticData';
|
|
50
|
+
|
|
49
51
|
import { config } from '../config';
|
|
50
52
|
|
|
51
53
|
//================================================================================
|
|
@@ -2182,7 +2184,12 @@ export class View extends Annotatable {
|
|
|
2182
2184
|
*toEmbeddedTS(state = createCompilerState()): TranslatorGenerator {
|
|
2183
2185
|
const self = this;
|
|
2184
2186
|
// 获取所有子节点用于树上填充
|
|
2187
|
+
// const time1 = Date.now();
|
|
2185
2188
|
self.getSubLogics();
|
|
2189
|
+
// const time2 = Date.now();
|
|
2190
|
+
// if (time2 - time1 > 100) {
|
|
2191
|
+
// console.log('获取 getSubLogics 耗时', (time2 - time1) / 1000, 's');
|
|
2192
|
+
// }
|
|
2186
2193
|
function chineseTsName(name: string) {
|
|
2187
2194
|
let tsName = name;
|
|
2188
2195
|
// 匹配所有特殊字符都转为_
|
|
@@ -2209,57 +2216,7 @@ export class View extends Annotatable {
|
|
|
2209
2216
|
// 需要类型推导的局部变量/返回值需要调整申明顺序
|
|
2210
2217
|
const advanceMap: Map<Variable, Assignment | BatchAssignment> = new Map();
|
|
2211
2218
|
const callFunctionAdvanceMap: Map<Variable, CallFunction> = new Map();
|
|
2212
|
-
yield*
|
|
2213
|
-
if (
|
|
2214
|
-
el &&
|
|
2215
|
-
// 批量赋值
|
|
2216
|
-
(asserts.isBatchAssignment(el) ||
|
|
2217
|
-
// 赋值
|
|
2218
|
-
(asserts.isAssignment(el) && el.left?.name) ||
|
|
2219
|
-
// 内置函数对集合类型的推导
|
|
2220
|
-
(asserts.isCallFunction(el) && el.derivablecollection?.name))
|
|
2221
|
-
) {
|
|
2222
|
-
if (el?.getAncestor('SubLogic')) {
|
|
2223
|
-
return;
|
|
2224
|
-
}
|
|
2225
|
-
// 子页面内部逻辑过滤
|
|
2226
|
-
if (el.view !== self) return;
|
|
2227
|
-
if (asserts.isAssignment(el)) {
|
|
2228
|
-
// 需要被推导的赋值左侧
|
|
2229
|
-
const expression = el.left;
|
|
2230
|
-
const advanceVar = self.variables?.find((variable) => {
|
|
2231
|
-
return !variable.typeAnnotation && expression?.name === variable.name;
|
|
2232
|
-
});
|
|
2233
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
2234
|
-
advanceMap.set(advanceVar, el);
|
|
2235
|
-
}
|
|
2236
|
-
} else if (asserts.isCallFunction(el)) {
|
|
2237
|
-
// 需要被推导的集合
|
|
2238
|
-
const expression = el.derivablecollection;
|
|
2239
|
-
const advanceVar = self.variables?.find((variable) => {
|
|
2240
|
-
return !variable.typeAnnotation && expression?.name === variable.name;
|
|
2241
|
-
});
|
|
2242
|
-
if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
|
|
2243
|
-
callFunctionAdvanceMap.set(advanceVar, el);
|
|
2244
|
-
}
|
|
2245
|
-
} else if (asserts.isBatchAssignment(el)) {
|
|
2246
|
-
yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
|
|
2247
|
-
const leftCode =
|
|
2248
|
-
leftIndex.length === 1
|
|
2249
|
-
? yield* el.left?.expression?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
2250
|
-
returnOrigin('')
|
|
2251
|
-
: yield* el.left?.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
2252
|
-
returnOrigin('');
|
|
2253
|
-
const advanceVar = self.variables?.find(
|
|
2254
|
-
(variable) => !variable.typeAnnotation && leftCode === variable.name,
|
|
2255
|
-
);
|
|
2256
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
2257
|
-
advanceMap.set(advanceVar, el);
|
|
2258
|
-
}
|
|
2259
|
-
});
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
});
|
|
2219
|
+
yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
|
|
2263
2220
|
|
|
2264
2221
|
// 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
|
|
2265
2222
|
const IDENTIFIERMAP = new Set<Variable>();
|
|
@@ -2789,8 +2746,8 @@ export class View extends Annotatable {
|
|
|
2789
2746
|
this.elements.forEach((item) => {
|
|
2790
2747
|
utils.traverse(
|
|
2791
2748
|
(current) => {
|
|
2792
|
-
current.node.bindEvents.forEach((bindEvent) => {
|
|
2793
|
-
bindEvent.logics.forEach((logic) => {
|
|
2749
|
+
current.node.bindEvents.forEach((bindEvent: BindEvent) => {
|
|
2750
|
+
bindEvent.logics.forEach((logic: Logic) => {
|
|
2794
2751
|
if (!logic?.name || logic?.name?.startsWith('__')) {
|
|
2795
2752
|
return;
|
|
2796
2753
|
}
|
|
@@ -3186,7 +3143,10 @@ export class View extends Annotatable {
|
|
|
3186
3143
|
subLogics: Array<SubLogic> = [];
|
|
3187
3144
|
|
|
3188
3145
|
getSubLogics() {
|
|
3189
|
-
|
|
3146
|
+
if (varScopeCtx.isFirstScreen) {
|
|
3147
|
+
return;
|
|
3148
|
+
}
|
|
3149
|
+
const subLogics = this.findNaslNodeByBFS((node) => {
|
|
3190
3150
|
// 仅仅是为了处理数据源中的子逻辑,Logic 下面的,交由Logic 自己处理
|
|
3191
3151
|
if (node?.concept === 'Logic') {
|
|
3192
3152
|
return true;
|
|
@@ -502,7 +502,7 @@ export function genBundleFiles(app: App, frontend: Frontend, config: Config) {
|
|
|
502
502
|
if (frontend.globalScaleEnabled) {
|
|
503
503
|
content += `{
|
|
504
504
|
// 如果是顶层页面,才使用iframe缩放,否则会死循环
|
|
505
|
-
if(window.
|
|
505
|
+
if(!window.isScaledFrame){
|
|
506
506
|
// 顶层页面里有个iframe,用来缩放页面
|
|
507
507
|
document.body.innerHTML = '<iframe src="' + location.href + '"></iframe>';
|
|
508
508
|
const iframe = document.querySelector('iframe');
|
|
@@ -538,10 +538,10 @@ export function genBundleFiles(app: App, frontend: Frontend, config: Config) {
|
|
|
538
538
|
document.documentElement.style.setProperty('--scrollbar-size', 0);
|
|
539
539
|
// 移除 iframe 边框
|
|
540
540
|
iframe.style.border = 'none';
|
|
541
|
-
//
|
|
542
|
-
|
|
541
|
+
// 标记全局缩放的iframe,原因:全局缩放页面可能在 iframe 中
|
|
542
|
+
iframe.contentWindow.isScaledFrame = true;
|
|
543
543
|
return;
|
|
544
|
-
} else
|
|
544
|
+
} else {
|
|
545
545
|
// 点击跳转到外部页面时,通知顶层页面
|
|
546
546
|
document.body.addEventListener('click', (e) => {
|
|
547
547
|
if(!e.target.href) return;
|
|
@@ -681,7 +681,7 @@ export function genBundleFiles(app: App, frontend: Frontend, config: Config) {
|
|
|
681
681
|
if (frontend.globalScaleEnabled) {
|
|
682
682
|
content += `
|
|
683
683
|
// 同步逻辑仅在 iframe 内部执行
|
|
684
|
-
if(window.
|
|
684
|
+
if(window.isScaledFrame) {
|
|
685
685
|
/**
|
|
686
686
|
* iframe 路由同步的几种情况:
|
|
687
687
|
* 1. 跳转时,iframe 同步到顶层
|
|
@@ -332,7 +332,7 @@ export async function genPermissionDataOld(app: App) {
|
|
|
332
332
|
if (authVals?.length) {
|
|
333
333
|
authVals.forEach((item) => {
|
|
334
334
|
const { key, authValue } = item;
|
|
335
|
-
if (key.startsWith('/upload'
|
|
335
|
+
if (key.startsWith('/upload') || key.startsWith('/api/')) {
|
|
336
336
|
logicPageResourceDtoList[`${key}:POST`] = checkPageAndUploadAuth(uploaders, key) ? [[]] : convertArray(authValue);
|
|
337
337
|
}
|
|
338
338
|
});
|
|
@@ -365,6 +365,14 @@ function createArrayOnAdd<K, V>(k : K, v : V, m: Map<K, Array<V>>) {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
function createSetOnAdd<K, V>(k : K, v : V, m: Map<K, Set<V>>) {
|
|
369
|
+
if (m.get(k)) {
|
|
370
|
+
m.get(k).add(v);
|
|
371
|
+
} else {
|
|
372
|
+
m.set(k, new Set([v]));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
368
376
|
// 需要区分:前端逻辑、后端逻辑、流程逻辑
|
|
369
377
|
// 需要的信息:后端逻辑、流程逻辑的 service path;逻辑调用到其定义的映射;
|
|
370
378
|
// 流程逻辑 call 的 getCallNode() 每次都不同
|
|
@@ -418,8 +426,12 @@ export function genPermissionData(app: App): { [key: string]: ResourceNode[][];
|
|
|
418
426
|
const urlAttr = nd.bindAttrs.find((item : BindAttribute) => item.name === 'url');
|
|
419
427
|
const url = urlAttr?.value;
|
|
420
428
|
if (url) {
|
|
421
|
-
if (!uploaders.has(url))
|
|
422
|
-
|
|
429
|
+
if (!uploaders.has(url)) {
|
|
430
|
+
uploaders.set(url, [nd]);
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
uploaders.get(url).push(nd);
|
|
434
|
+
}
|
|
423
435
|
}
|
|
424
436
|
}
|
|
425
437
|
break;
|
|
@@ -519,6 +531,7 @@ export function genPermissionData(app: App): { [key: string]: ResourceNode[][];
|
|
|
519
531
|
});
|
|
520
532
|
|
|
521
533
|
frontendLogicCallCtx.forEach(({ view, viewElements, thisLogic }) => {
|
|
534
|
+
const visitedCalls = new Map<Logic, Set<CallLogic>>(); // 防止 A 调用 A 自我调用或 A 调用 B,B 又调用 A 等循环调用
|
|
522
535
|
const findCallBackendLogic = ([kind, l] : ['process' | 'server' | 'front', Logic]) => {
|
|
523
536
|
if (!l) {
|
|
524
537
|
return;
|
|
@@ -536,7 +549,12 @@ export function genPermissionData(app: App): { [key: string]: ResourceNode[][];
|
|
|
536
549
|
}
|
|
537
550
|
case 'front': {
|
|
538
551
|
const lgcCalls : Array<CallLogic> = defToCalls.get(l);
|
|
539
|
-
lgcCalls?.forEach(
|
|
552
|
+
lgcCalls?.forEach(call => {
|
|
553
|
+
if (!visitedCalls.get(l)?.has(call)) {
|
|
554
|
+
createSetOnAdd(l, call, visitedCalls);
|
|
555
|
+
findCallBackendLogic(call.getCallNodeUsingCache(frontNdCache, serverNdCache, processNdCache));
|
|
556
|
+
}
|
|
557
|
+
});
|
|
540
558
|
break;
|
|
541
559
|
}
|
|
542
560
|
default: {
|
|
@@ -579,7 +597,7 @@ export function genPermissionData(app: App): { [key: string]: ResourceNode[][];
|
|
|
579
597
|
if (authVals?.length) {
|
|
580
598
|
authVals.forEach((item) => {
|
|
581
599
|
const { key, authValue } = item;
|
|
582
|
-
if (key.startsWith('/upload' || '/api/')) {
|
|
600
|
+
if (key.startsWith('/upload') || (key.startsWith('/api/'))) {
|
|
583
601
|
logicPageResourceDtoList[`${key}:POST`] =
|
|
584
602
|
checkPageAndUploadAuth(uploaders, key) ? [[]] : convertArray(authValue);
|
|
585
603
|
}
|
|
@@ -212,7 +212,6 @@ async function mergeBodyData(app: App, opt: InternalReleaseData) {
|
|
|
212
212
|
const authReport: ReturnType<typeof getAuthReport> = getAuthReport(app, opt.frontends);
|
|
213
213
|
await opt.logPublishFunc?.('权限', '分析权限数据成功!');
|
|
214
214
|
const logicPageResourceDtoList = genPermissionData(app);
|
|
215
|
-
|
|
216
215
|
// 与老板逻辑权限数据对比
|
|
217
216
|
// await testWithOldPermissionResult(app, logicPageResourceDtoList);
|
|
218
217
|
const allFrontends = getFrontendByTypes(app?.frontendTypes);
|
|
@@ -68,7 +68,7 @@ function transformParam(node: babelTypes.Identifier): naslTypes.Param {
|
|
|
68
68
|
// 处理生命周期函数
|
|
69
69
|
function transformLifecycle(node: babelTypes.ObjectExpression): Array<naslTypes.BindEvent> {
|
|
70
70
|
const bindEvents: Array<naslTypes.BindEvent> = [];
|
|
71
|
-
node.properties
|
|
71
|
+
node.properties?.forEach((property: any) => {
|
|
72
72
|
const eventName = property?.key?.name?.replace(/^on/, '')?.toLowerCase();
|
|
73
73
|
const bindEvent = new naslTypes.BindEvent({ name: eventName });
|
|
74
74
|
property.value.elements.forEach((element: any) => {
|
|
@@ -150,7 +150,7 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
150
150
|
if (calleeName === 'NewMap') {
|
|
151
151
|
const keys: any = [];
|
|
152
152
|
const values: any = [];
|
|
153
|
-
node?.arguments?.[0]?.properties
|
|
153
|
+
node?.arguments?.[0]?.properties?.forEach((arg: any) => {
|
|
154
154
|
keys.push(transformNode2Expression(arg.key));
|
|
155
155
|
values.push(transformNode2Expression(arg.value));
|
|
156
156
|
});
|
|
@@ -166,7 +166,7 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
166
166
|
const properties: any = [];
|
|
167
167
|
const rights: any = [];
|
|
168
168
|
const assignmentLines: any = [];
|
|
169
|
-
node?.arguments?.[0]?.properties
|
|
169
|
+
node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
|
|
170
170
|
properties.push(transformNode2Expression(arg.key));
|
|
171
171
|
if (arg.value.type === 'MemberExpression') {
|
|
172
172
|
const expression = flatMemberExpression(arg.value);
|
|
@@ -223,7 +223,7 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
|
|
|
223
223
|
const properties: any = [];
|
|
224
224
|
const rights: any = [];
|
|
225
225
|
const assignmentLines: any = [];
|
|
226
|
-
node?.arguments?.[0]?.properties
|
|
226
|
+
node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
|
|
227
227
|
properties.push(transformNode2Expression(arg.key));
|
|
228
228
|
if (arg.value.type === 'MemberExpression') {
|
|
229
229
|
const expression = flatMemberExpression(arg.value);
|
|
@@ -354,7 +354,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
if (callee.length === 2 && callee[0].type === 'Identifier' && callee[0].name.endsWith('Entity')) {
|
|
357
|
-
const entityName = callee[0].name.replace(/Entity
|
|
357
|
+
const entityName = callee[0].name.replace(/Entity$/, '');
|
|
358
358
|
return new naslTypes.CallLogic({
|
|
359
359
|
calleeNamespace: `app.dataSources.defaultDS.entities.${entityName}.logics`,
|
|
360
360
|
calleeName: (callee[1] as babelTypes.Identifier).name,
|
|
@@ -530,7 +530,7 @@ function transformNode2Expression(node: babelTypes.Node, type?: string): any {
|
|
|
530
530
|
} else if (/^app.dataSources|app.logics/.test(calleeName)) {
|
|
531
531
|
if (calleeName?.includes('.entities.')) {
|
|
532
532
|
const calleeNamespace = generate((node?.callee as any)?.object?.object)?.code;
|
|
533
|
-
const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity
|
|
533
|
+
const entityName = (node?.callee as any)?.object?.property?.name?.replace(/Entity$/, '');
|
|
534
534
|
return new naslTypes.CallLogic({
|
|
535
535
|
calleeNamespace: `${calleeNamespace}.${entityName}.logics`,
|
|
536
536
|
calleeName: (node?.callee as any)?.property?.name,
|
|
@@ -1110,7 +1110,7 @@ function transformNode2ViewElement(node: babelTypes.NewExpression, componentName
|
|
|
1110
1110
|
tag,
|
|
1111
1111
|
name,
|
|
1112
1112
|
});
|
|
1113
|
-
viewNode.properties
|
|
1113
|
+
viewNode.properties?.forEach((prop: any, propIndex: number) => {
|
|
1114
1114
|
if (prop?.value?.type === 'ArrayExpression' && ['FunctionExpression', 'ArrowFunctionExpression'].includes(prop?.value?.elements?.[0]?.type)) {
|
|
1115
1115
|
// 事件逻辑
|
|
1116
1116
|
const eventName = prop?.key?.name?.replace(/^on/, '')?.toLowerCase();
|