@lcap/nasl 3.8.3-beta.4 → 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.
Files changed (88) hide show
  1. package/out/common/BaseNode.d.ts +9 -4
  2. package/out/common/BaseNode.js +73 -18
  3. package/out/common/BaseNode.js.map +1 -1
  4. package/out/concepts/App__.js +17 -13
  5. package/out/concepts/App__.js.map +1 -1
  6. package/out/concepts/AuthLogicForCallInterface__.js +2 -50
  7. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  8. package/out/concepts/BusinessComponent__.js +2 -42
  9. package/out/concepts/BusinessComponent__.js.map +1 -1
  10. package/out/concepts/BusinessLogic__.js +2 -50
  11. package/out/concepts/BusinessLogic__.js.map +1 -1
  12. package/out/concepts/CallFunction__.d.ts +1 -1
  13. package/out/concepts/CallFunction__.js +1 -1
  14. package/out/concepts/CallLogic__.js +2 -2
  15. package/out/concepts/CallLogic__.js.map +1 -1
  16. package/out/concepts/Identifier__.d.ts +2 -0
  17. package/out/concepts/Identifier__.js +51 -5
  18. package/out/concepts/Identifier__.js.map +1 -1
  19. package/out/concepts/Logic__.js +6 -101
  20. package/out/concepts/Logic__.js.map +1 -1
  21. package/out/concepts/MemberExpression__.d.ts +1 -1
  22. package/out/concepts/MemberExpression__.js +15 -3
  23. package/out/concepts/MemberExpression__.js.map +1 -1
  24. package/out/concepts/OverriddenLogic__.js +2 -50
  25. package/out/concepts/OverriddenLogic__.js.map +1 -1
  26. package/out/concepts/ProcessElementV2__.js +4 -0
  27. package/out/concepts/ProcessElementV2__.js.map +1 -1
  28. package/out/concepts/ProcessElement__.js +4 -0
  29. package/out/concepts/ProcessElement__.js.map +1 -1
  30. package/out/concepts/ProcessV2__.js +4 -0
  31. package/out/concepts/ProcessV2__.js.map +1 -1
  32. package/out/concepts/Process__.js +4 -0
  33. package/out/concepts/Process__.js.map +1 -1
  34. package/out/concepts/SubLogic__.js +5 -50
  35. package/out/concepts/SubLogic__.js.map +1 -1
  36. package/out/concepts/TypeAnnotation__.js +1 -1
  37. package/out/concepts/TypeAnnotation__.js.map +1 -1
  38. package/out/concepts/View__.js +10 -49
  39. package/out/concepts/View__.js.map +1 -1
  40. package/out/generator/genBundleFiles.js +5 -5
  41. package/out/generator/permission.js +21 -5
  42. package/out/generator/permission.js.map +1 -1
  43. package/out/generator/release-body/body.js.map +1 -1
  44. package/out/natural/transformTS2UI.js +5 -5
  45. package/out/natural/transformTS2UI.js.map +1 -1
  46. package/out/natural/transforms/transform2LogicItem.js +4 -4
  47. package/out/natural/transforms/transform2LogicItem.js.map +1 -1
  48. package/out/server/naslServer.js +17 -2
  49. package/out/server/naslServer.js.map +1 -1
  50. package/out/server/semanticData.d.ts +32 -0
  51. package/out/server/semanticData.js +371 -0
  52. package/out/server/semanticData.js.map +1 -0
  53. package/out/templator/block2nasl/viewMergeBlock.js +2 -1
  54. package/out/templator/block2nasl/viewMergeBlock.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/common/BaseNode.ts +106 -36
  57. package/src/concepts/App__.ts +17 -13
  58. package/src/concepts/AuthLogicForCallInterface__.ts +3 -56
  59. package/src/concepts/BusinessComponent__.ts +6 -51
  60. package/src/concepts/BusinessLogic__.ts +4 -56
  61. package/src/concepts/CallFunction__.ts +1 -1
  62. package/src/concepts/CallLogic__.ts +8 -4
  63. package/src/concepts/Identifier__.ts +57 -6
  64. package/src/concepts/Logic__.ts +9 -111
  65. package/src/concepts/MemberExpression__.ts +21 -7
  66. package/src/concepts/OverriddenLogic__.ts +4 -56
  67. package/src/concepts/ProcessElementV2__.ts +4 -0
  68. package/src/concepts/ProcessElement__.ts +4 -0
  69. package/src/concepts/ProcessV2__.ts +5 -0
  70. package/src/concepts/Process__.ts +4 -0
  71. package/src/concepts/SubLogic__.ts +6 -56
  72. package/src/concepts/TypeAnnotation__.ts +1 -1
  73. package/src/concepts/View__.ts +14 -54
  74. package/src/generator/genBundleFiles.ts +5 -5
  75. package/src/generator/permission.ts +23 -5
  76. package/src/generator/release-body/body.ts +0 -1
  77. package/src/natural/transformTS2UI.ts +5 -5
  78. package/src/natural/transforms/transform2LogicItem.ts +4 -4
  79. package/src/server/naslServer.ts +22 -2
  80. package/src/server/semanticData.ts +447 -0
  81. package/src/templator/block2nasl/viewMergeBlock.ts +2 -1
  82. package/src/translator/utils.ts +1 -1
  83. package/test/concepts/logic/__snapshots__/toEmbeddedTS.spec.ts.snap +182 -0
  84. package/test/concepts/logic/constant.ts +5 -0
  85. package/test/concepts/logic/fixtures/variable-host-call-logic-member-expression.json +267 -0
  86. package/test/concepts/logic/fixtures/variable-host-call-logic-nested-member-expression copy.json +457 -0
  87. package/test/concepts/logic/fixtures/variable-host-call-logic-with-handle-error-member-expression.json +267 -0
  88. package/test/concepts/logic/toEmbeddedTS.spec.ts +15 -0
@@ -3839,23 +3839,24 @@ export class App extends BaseNode {
3839
3839
  deleteCompose(path: string[]) {
3840
3840
  if (!Array.isArray(path)) return;
3841
3841
  let compose = this.composeCache;
3842
-
3843
- const delNodes = (_compose: composeCacheType) => {
3842
+ const delNodes = (_compose: composeCacheType, key: string) => {
3844
3843
  if (_compose?.nodes) {
3845
3844
  for (const key in _compose) {
3846
- if (key !== 'nodes') {
3847
- delNodes(_compose[key]);
3845
+ // 只有form和table层级触发删除
3846
+ if (key !== 'nodes' && key !== 'saveModalForm') {
3847
+ delNodes(_compose[key], key);
3848
3848
  }
3849
3849
  }
3850
3850
  const arr = [..._compose.nodes] || [];
3851
- const triggerNode: BaseNode[] = []; // 触点放在最后删
3852
- arr.forEach((node) => {
3853
- if (node.name === path?.[0]) {
3854
- triggerNode.push(node);
3855
- } else {
3856
- node && node.delete();
3857
- }
3858
- });
3851
+ // table内的saveModalForm.nodes也在table层级一起删除,避免先删父后删子的情况
3852
+ if (_compose.hasOwnProperty('saveModalForm')) {
3853
+ arr.push(..._compose.saveModalForm.nodes);
3854
+ }
3855
+ // 按照路径长度,粗粒度处理好父子关系后,再删除节点
3856
+ const triggerNode = arr
3857
+ .map((item, index) => ({ nodePath: item?.nodePath, index }))
3858
+ .sort((a, b) => b.nodePath.length - a.nodePath.length)
3859
+ .map((item) => arr[item.index]);
3859
3860
 
3860
3861
  triggerNode.forEach((node) => {
3861
3862
  node && node.delete();
@@ -3867,10 +3868,13 @@ export class App extends BaseNode {
3867
3868
 
3868
3869
  this.emit('collect:start', {
3869
3870
  actionMsg: '删除同一分组节点',
3871
+ extra: {
3872
+ isCustomDesigner: true,
3873
+ },
3870
3874
  });
3871
3875
  path.forEach((key, index) => {
3872
3876
  if (index === path.length - 1) {
3873
- delNodes(compose?.[key]);
3877
+ delNodes(compose?.[key], key);
3874
3878
  } else {
3875
3879
  compose = compose[key];
3876
3880
  }
@@ -42,6 +42,7 @@ import * as asserts from './utils/asserts';
42
42
 
43
43
  import Param from './Param__';
44
44
  import AuthLogic from './AuthLogic__';
45
+ import { reCollectTyInferCtx } from '../server/semanticData';
45
46
 
46
47
  /**
47
48
  * 调用接口的鉴权逻辑
@@ -352,61 +353,7 @@ export class AuthLogicForCallInterface extends AuthLogic {
352
353
  // 需要类型推导的局部变量/返回值需要调整申明顺序
353
354
  const advanceMap: Map<Return | Variable, Assignment | BatchAssignment> = new Map();
354
355
  const callFunctionAdvanceMap: Map<Return | Variable, CallFunction> = new Map();
355
- yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
356
- if (
357
- el &&
358
- // 批量赋值
359
- (asserts.isBatchAssignment(el) ||
360
- // 赋值
361
- (asserts.isAssignment(el) && el.left?.name) ||
362
- // 内置函数对集合类型的推导
363
- (asserts.isCallFunction(el) && el.derivablecollection?.name))
364
- ) {
365
- if (el?.getAncestor('SubLogic')) {
366
- return;
367
- }
368
- if (asserts.isAssignment(el)) {
369
- const advanceVar = self.variables?.find(
370
- (variable) => !variable.typeAnnotation && el.left?.name === variable.name,
371
- );
372
- if (advanceVar && !advanceMap.get(advanceVar)) {
373
- advanceMap.set(advanceVar, el);
374
- }
375
- const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && el.left?.name === ret.name);
376
- if (advanceRn && !advanceMap.get(advanceRn)) {
377
- advanceMap.set(advanceRn, el);
378
- }
379
- } else if (asserts.isCallFunction(el)) {
380
- // 需要被推导的集合
381
- const expression = el.derivablecollection;
382
- // 宽泛意义上的变量(变量+出参)
383
- const advanceVar = [...(self.variables || []), ...(self.returns || [])].find((variable) => {
384
- return !variable.typeAnnotation && expression?.name === variable.name;
385
- });
386
- if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
387
- callFunctionAdvanceMap.set(advanceVar, el);
388
- }
389
- } else if (asserts.isBatchAssignment(el)) {
390
- yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
391
- const leftCode =
392
- leftIndex.length === 1
393
- ? yield* el.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
394
- : yield* el.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
395
- returnOrigin('');
396
- const advanceVar = self.variables?.find(
397
- (variable) => !variable.typeAnnotation && leftCode === variable.name,
398
- );
399
- if (advanceVar && !advanceMap.get(advanceVar)) {
400
- advanceMap.set(advanceVar, el);
401
- }
402
- const advanceRn = self.returns?.find((ret) => !ret.typeAnnotation && leftCode === ret.name);
403
- if (advanceRn && !advanceMap.get(advanceRn)) {
404
- advanceMap.set(advanceRn, el);
405
- }
406
- });
407
- }
408
- }
409
- });
356
+ yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
410
357
  code += '{\n';
411
358
  // 用于虚拟节点的查找引用
412
359
  if (Array.isArray(self.virtualParams)) {
@@ -551,7 +498,7 @@ export class AuthLogicForCallInterface extends AuthLogic {
551
498
  && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
552
499
  )
553
500
  || (
554
- (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
501
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
555
502
  && !(itemNode?.typeAnnotation)
556
503
  )
557
504
  ) {
@@ -46,6 +46,7 @@ import Variable from './Variable__';
46
46
  import BindEvent from './BindEvent__';
47
47
  import BusinessLogic from './BusinessLogic__';
48
48
  import ViewElement from './ViewElement__';
49
+ import { reCollectTyInferCtx } from '../server/semanticData';
49
50
 
50
51
  /**
51
52
  * 业务组件
@@ -1999,53 +2000,7 @@ export class BusinessComponent extends BaseNode {
1999
2000
 
2000
2001
  const advanceMap: Map<Variable, Assignment | BatchAssignment> = new Map();
2001
2002
  const callFunctionAdvanceMap: Map<Variable, CallFunction> = new Map();
2002
- yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
2003
- if (
2004
- el &&
2005
- // 批量赋值
2006
- (asserts.isBatchAssignment(el) ||
2007
- // 赋值
2008
- (asserts.isAssignment(el) && el.left?.name) ||
2009
- // 内置函数对集合类型的推导
2010
- (asserts.isCallFunction(el) && el.derivablecollection?.name))
2011
- ) {
2012
- if (el?.getAncestor('SubLogic')) {
2013
- return;
2014
- }
2015
- if (asserts.isAssignment(el)) {
2016
- const advanceVar = self.variables?.find(
2017
- (variable) => !variable.typeAnnotation && el.left?.name === variable.name,
2018
- );
2019
- if (advanceVar && !advanceMap.get(advanceVar)) {
2020
- advanceMap.set(advanceVar, el);
2021
- }
2022
- } else if (asserts.isCallFunction(el)) {
2023
- // 需要被推导的集合
2024
- const expression = el.derivablecollection;
2025
- const advanceVar = self.variables?.find((variable) => {
2026
- return !variable.typeAnnotation && expression?.name === variable.name;
2027
- });
2028
- if (advanceVar && !callFunctionAdvanceMap.get(advanceVar)) {
2029
- callFunctionAdvanceMap.set(advanceVar, el);
2030
- }
2031
- } else if (asserts.isBatchAssignment(el)) {
2032
- yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
2033
- const leftCode =
2034
- leftIndex.length === 1
2035
- ? yield* el.left?.expression?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2036
- returnOrigin('')
2037
- : yield* el.left?.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
2038
- returnOrigin('');
2039
- const advanceVar = self.variables?.find(
2040
- (variable) => !variable.typeAnnotation && leftCode === variable.name,
2041
- );
2042
- if (advanceVar && !advanceMap.get(advanceVar)) {
2043
- advanceMap.set(advanceVar, el);
2044
- }
2045
- });
2046
- }
2047
- }
2048
- });
2003
+ yield* reCollectTyInferCtx(advanceMap, callFunctionAdvanceMap, self);
2049
2004
 
2050
2005
  // 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
2051
2006
  const IDENTIFIERMAP = new Set<Variable>();
@@ -2155,7 +2110,7 @@ export class BusinessComponent extends BaseNode {
2155
2110
  && itemNode.typeAnnotation?.typeKind === 'anonymousStructure'
2156
2111
  )
2157
2112
  || (
2158
- (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
2113
+ (asserts.isNewList(itemNode) || asserts.isNewMap(itemNode))
2159
2114
  && !(itemNode?.typeAnnotation)
2160
2115
  )
2161
2116
  ) {
@@ -2523,11 +2478,11 @@ export class BusinessComponent extends BaseNode {
2523
2478
  @withSourceMap()
2524
2479
  toTextualNASL(state = createCompilerState()): string {
2525
2480
  let code = '';
2526
-
2481
+
2527
2482
  code += createDecoratorCode(state, this, ['title', 'description']);
2528
2483
 
2529
2484
  code += `viewComponent ${this.name}`;
2530
-
2485
+
2531
2486
  code += `(\n`;
2532
2487
  this.params.forEach((param, index) => {
2533
2488
  code += param.toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
@@ -2551,7 +2506,7 @@ export class BusinessComponent extends BaseNode {
2551
2506
  code += '\n';
2552
2507
  });
2553
2508
  if (this.logics.length) code += '\n';
2554
-
2509
+
2555
2510
  code += this.elements[0].toTextualNASL(shiftState(state, code, { tabSize: state.tabSize + 1 }));
2556
2511
 
2557
2512
  code += `\n${indent(state.tabSize)}}`;
@@ -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* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
139
- if (
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
  ) {
@@ -787,7 +787,7 @@ export class CallFunction extends LogicItem {
787
787
  }
788
788
 
789
789
  // 集合
790
- get derivablecollection() {
790
+ get derivableCollection() {
791
791
  if (this.isDerivableCollection) {
792
792
  return this.arguments?.[0]?.expression;
793
793
  }
@@ -1667,7 +1667,9 @@ export class CallLogic extends LogicItem {
1667
1667
  return tag;
1668
1668
  }
1669
1669
 
1670
- getCallNodeUsingCache(frontNdCache: Map<string, Logic>, serverNdCache: Map<string, Logic>, processNdCache: Map<string, Logic>): ['front' | 'server' | 'process', Logic | undefined] {
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.view) {
1685
- node = this.view.logics.find((l) => l.name === this.calleeName);
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
- .replace(/-(\w)/g, (all, letter) => letter.toUpperCase());
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
- const view = this.getAncestor('View') as View;
238
- // 属于页面下 的变量
239
- if (view && this.isViewOrGlobalDataVariable) {
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;
@@ -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* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
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;