@lcap/nasl 3.8.2-beta.9 → 3.8.3-beta.2

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 (233) hide show
  1. package/ai-engineer.config.js +617 -0
  2. package/out/common/BaseNode.d.ts +9 -4
  3. package/out/common/BaseNode.js +43 -10
  4. package/out/common/BaseNode.js.map +1 -1
  5. package/out/concepts/AuthLogicForCallInterface__.js +2 -50
  6. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  7. package/out/concepts/BackendVariable__.js +16 -1
  8. package/out/concepts/BackendVariable__.js.map +1 -1
  9. package/out/concepts/BindAttribute__.js +12 -4
  10. package/out/concepts/BindAttribute__.js.map +1 -1
  11. package/out/concepts/BindDirective__.js +1 -1
  12. package/out/concepts/BindDirective__.js.map +1 -1
  13. package/out/concepts/BindStyle__.js +1 -1
  14. package/out/concepts/BindStyle__.js.map +1 -1
  15. package/out/concepts/BusinessComponent__.js +2 -42
  16. package/out/concepts/BusinessComponent__.js.map +1 -1
  17. package/out/concepts/BusinessLogic__.js +2 -50
  18. package/out/concepts/BusinessLogic__.js.map +1 -1
  19. package/out/concepts/CallFunction__.d.ts +1 -1
  20. package/out/concepts/CallFunction__.js +1 -1
  21. package/out/concepts/CallLogic__.js +7 -1
  22. package/out/concepts/CallLogic__.js.map +1 -1
  23. package/out/concepts/CallQueryComponent__.d.ts +1 -0
  24. package/out/concepts/CallQueryComponent__.js +23 -12
  25. package/out/concepts/CallQueryComponent__.js.map +1 -1
  26. package/out/concepts/Destination__.js +11 -8
  27. package/out/concepts/Destination__.js.map +1 -1
  28. package/out/concepts/EntityProperty__.js +3 -2
  29. package/out/concepts/EntityProperty__.js.map +1 -1
  30. package/out/concepts/Entity__.js +1 -1
  31. package/out/concepts/Entity__.js.map +1 -1
  32. package/out/concepts/Identifier__.d.ts +2 -0
  33. package/out/concepts/Identifier__.js +51 -5
  34. package/out/concepts/Identifier__.js.map +1 -1
  35. package/out/concepts/Interface__.js +1 -1
  36. package/out/concepts/Interface__.js.map +1 -1
  37. package/out/concepts/Logic__.js +33 -111
  38. package/out/concepts/Logic__.js.map +1 -1
  39. package/out/concepts/MemberExpression__.d.ts +1 -1
  40. package/out/concepts/MemberExpression__.js +15 -3
  41. package/out/concepts/MemberExpression__.js.map +1 -1
  42. package/out/concepts/OqlQueryComponent__.js +37 -12
  43. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  44. package/out/concepts/OverriddenLogic__.js +2 -50
  45. package/out/concepts/OverriddenLogic__.js.map +1 -1
  46. package/out/concepts/Param__.js +5 -4
  47. package/out/concepts/Param__.js.map +1 -1
  48. package/out/concepts/ProcessElementV2__.js +4 -0
  49. package/out/concepts/ProcessElementV2__.js.map +1 -1
  50. package/out/concepts/ProcessElement__.js +4 -0
  51. package/out/concepts/ProcessElement__.js.map +1 -1
  52. package/out/concepts/ProcessV2__.js +4 -0
  53. package/out/concepts/ProcessV2__.js.map +1 -1
  54. package/out/concepts/Process__.js +4 -0
  55. package/out/concepts/Process__.js.map +1 -1
  56. package/out/concepts/QueryOrderByExpression__.d.ts +0 -1
  57. package/out/concepts/QueryOrderByExpression__.js +0 -1
  58. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  59. package/out/concepts/Structure__.js +5 -7
  60. package/out/concepts/Structure__.js.map +1 -1
  61. package/out/concepts/SubLogic__.js +5 -50
  62. package/out/concepts/SubLogic__.js.map +1 -1
  63. package/out/concepts/Variable__.js +5 -0
  64. package/out/concepts/Variable__.js.map +1 -1
  65. package/out/concepts/ViewElement__.d.ts +1 -0
  66. package/out/concepts/ViewElement__.js +16 -6
  67. package/out/concepts/ViewElement__.js.map +1 -1
  68. package/out/concepts/View__.js +48 -49
  69. package/out/concepts/View__.js.map +1 -1
  70. package/out/natural/genNaturalTS.d.ts +45 -10
  71. package/out/natural/genNaturalTS.js +57 -33
  72. package/out/natural/genNaturalTS.js.map +1 -1
  73. package/out/natural/getContext/getUILib.js +6 -3
  74. package/out/natural/getContext/getUILib.js.map +1 -1
  75. package/out/natural/getContext/index.d.ts +20 -7
  76. package/out/natural/getContext/index.js +143 -23
  77. package/out/natural/getContext/index.js.map +1 -1
  78. package/out/natural/getContext/naslStdlibMap.js +8 -8
  79. package/out/natural/getContext/naslStdlibMap.js.map +1 -1
  80. package/out/natural/tools.d.ts +16 -0
  81. package/out/natural/tools.js +110 -2
  82. package/out/natural/tools.js.map +1 -1
  83. package/out/natural/transformTS2UI.js +343 -292
  84. package/out/natural/transformTS2UI.js.map +1 -1
  85. package/out/natural/transformTSCode.d.ts +3 -5
  86. package/out/natural/transformTSCode.js +30 -1089
  87. package/out/natural/transformTSCode.js.map +1 -1
  88. package/out/natural/transforms/registerTransform.d.ts +7 -0
  89. package/out/natural/transforms/registerTransform.js +24 -0
  90. package/out/natural/transforms/registerTransform.js.map +1 -0
  91. package/out/natural/transforms/transform2LogicItem.d.ts +24 -0
  92. package/out/natural/transforms/transform2LogicItem.js +1240 -0
  93. package/out/natural/transforms/transform2LogicItem.js.map +1 -0
  94. package/out/natural/transforms/transform2TypeAnnotation.d.ts +2 -0
  95. package/out/natural/transforms/transform2TypeAnnotation.js +86 -0
  96. package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -0
  97. package/out/natural/transforms/utils.d.ts +8 -0
  98. package/out/natural/transforms/utils.js +59 -0
  99. package/out/natural/transforms/utils.js.map +1 -0
  100. package/out/server/getLogics.js +12 -12
  101. package/out/server/getLogics.js.map +1 -1
  102. package/out/server/naslServer.d.ts +2 -2
  103. package/out/server/naslServer.js +48 -18
  104. package/out/server/naslServer.js.map +1 -1
  105. package/out/server/semanticData.d.ts +32 -0
  106. package/out/server/semanticData.js +371 -0
  107. package/out/server/semanticData.js.map +1 -0
  108. package/out/server/translator.js +5 -0
  109. package/out/server/translator.js.map +1 -1
  110. package/out/templator/block2nasl/jsx2nasl/index.d.ts +5 -0
  111. package/out/templator/block2nasl/jsx2nasl/index.js +15 -0
  112. package/out/templator/block2nasl/jsx2nasl/index.js.map +1 -0
  113. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.d.ts +3 -0
  114. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js +213 -0
  115. package/out/templator/block2nasl/jsx2nasl/transform-expression2nasl.js.map +1 -0
  116. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.d.ts +14 -0
  117. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js +201 -0
  118. package/out/templator/block2nasl/jsx2nasl/transform-func2nasl.js.map +1 -0
  119. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.d.ts +4 -0
  120. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js +186 -0
  121. package/out/templator/block2nasl/jsx2nasl/transform-tstype2nasl.js.map +1 -0
  122. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.d.ts +28 -0
  123. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js +336 -0
  124. package/out/templator/block2nasl/jsx2nasl/transform-tsx2nasl.js.map +1 -0
  125. package/out/templator/block2nasl/jsx2nasl/utils.d.ts +2 -0
  126. package/out/templator/block2nasl/jsx2nasl/utils.js +26 -0
  127. package/out/templator/block2nasl/jsx2nasl/utils.js.map +1 -0
  128. package/out/templator/block2nasl/transformBlock2Nasl.d.ts +10 -0
  129. package/out/templator/block2nasl/transformBlock2Nasl.js +122 -0
  130. package/out/templator/block2nasl/transformBlock2Nasl.js.map +1 -0
  131. package/out/templator/block2nasl/viewMergeBlock.d.ts +9 -0
  132. package/out/templator/block2nasl/viewMergeBlock.js +111 -0
  133. package/out/templator/block2nasl/viewMergeBlock.js.map +1 -0
  134. package/out/translator/types.d.ts +2 -0
  135. package/out/translator/utils.js +1 -1
  136. package/out/translator/utils.js.map +1 -1
  137. package/out/utils/index.js +0 -4
  138. package/out/utils/index.js.map +1 -1
  139. package/out/utils/language-cache/constant.d.ts +2 -1
  140. package/out/utils/language-cache/constant.js +1 -0
  141. package/out/utils/language-cache/constant.js.map +1 -1
  142. package/out/utils/language-cache/nasl.d.ts +1 -0
  143. package/out/utils/language-cache/nasl.js +9 -1
  144. package/out/utils/language-cache/nasl.js.map +1 -1
  145. package/package.json +6 -2
  146. package/sandbox-natural/stdlib/nasl.core.d.ts +54 -0
  147. package/sandbox-natural/stdlib/nasl.oql.d.ts +22 -0
  148. package/sandbox-natural/stdlib/nasl.ui.d.ts +78 -0
  149. package/sandbox-natural/stdlib/nasl.ui.h5.d.ts +1684 -1643
  150. package/sandbox-natural/stdlib/nasl.ui.h5.json +15746 -15045
  151. package/sandbox-natural/stdlib/nasl.ui.pc.d.ts +5341 -5154
  152. package/sandbox-natural/stdlib/nasl.ui.pc.json +31176 -30681
  153. package/sandbox-natural/stdlib/{nasl.util.ts → nasl.util.d.ts} +49 -43
  154. package/src/common/BaseNode.ts +50 -8
  155. package/src/concepts/AuthLogicForCallInterface__.ts +3 -56
  156. package/src/concepts/BackendVariable__.ts +16 -1
  157. package/src/concepts/BindAttribute__.ts +18 -13
  158. package/src/concepts/BindDirective__.ts +1 -1
  159. package/src/concepts/BindStyle__.ts +1 -1
  160. package/src/concepts/BusinessComponent__.ts +6 -51
  161. package/src/concepts/BusinessLogic__.ts +4 -56
  162. package/src/concepts/CallFunction__.ts +1 -1
  163. package/src/concepts/CallLogic__.ts +21 -16
  164. package/src/concepts/CallQueryComponent__.ts +26 -12
  165. package/src/concepts/Destination__.ts +14 -12
  166. package/src/concepts/EntityProperty__.ts +5 -5
  167. package/src/concepts/Entity__.ts +1 -1
  168. package/src/concepts/Identifier__.ts +57 -6
  169. package/src/concepts/Interface__.ts +1 -1
  170. package/src/concepts/Logic__.ts +44 -134
  171. package/src/concepts/MemberExpression__.ts +21 -7
  172. package/src/concepts/OqlQueryComponent__.ts +29 -5
  173. package/src/concepts/OverriddenLogic__.ts +4 -56
  174. package/src/concepts/Param__.ts +5 -4
  175. package/src/concepts/ProcessElementV2__.ts +4 -0
  176. package/src/concepts/ProcessElement__.ts +4 -0
  177. package/src/concepts/ProcessV2__.ts +5 -0
  178. package/src/concepts/Process__.ts +4 -0
  179. package/src/concepts/QueryOrderByExpression__.ts +0 -1
  180. package/src/concepts/Structure__.ts +5 -7
  181. package/src/concepts/SubLogic__.ts +6 -56
  182. package/src/concepts/Variable__.ts +9 -5
  183. package/src/concepts/ViewElement__.ts +24 -7
  184. package/src/concepts/View__.ts +75 -76
  185. package/src/natural/genNaturalTS.ts +88 -39
  186. package/src/natural/getContext/getUILib.ts +6 -3
  187. package/src/natural/getContext/index.ts +125 -23
  188. package/src/natural/getContext/naslStdlibMap.ts +8 -8
  189. package/src/natural/tools.ts +107 -2
  190. package/src/natural/transformTS2UI.ts +190 -137
  191. package/src/natural/transformTSCode.ts +29 -1055
  192. package/src/natural/transforms/registerTransform.ts +34 -0
  193. package/src/natural/transforms/transform2LogicItem.ts +1335 -0
  194. package/src/natural/transforms/transform2TypeAnnotation.ts +77 -0
  195. package/src/natural/transforms/utils.ts +25 -0
  196. package/src/server/getLogics.ts +12 -12
  197. package/src/server/naslServer.ts +54 -19
  198. package/src/server/semanticData.ts +447 -0
  199. package/src/server/translator.ts +5 -0
  200. package/src/templator/block2nasl/jsx2nasl/index.ts +11 -0
  201. package/src/templator/block2nasl/jsx2nasl/transform-expression2nasl.ts +238 -0
  202. package/src/templator/block2nasl/jsx2nasl/transform-func2nasl.ts +241 -0
  203. package/src/templator/block2nasl/jsx2nasl/transform-tstype2nasl.ts +213 -0
  204. package/src/templator/block2nasl/jsx2nasl/transform-tsx2nasl.ts +422 -0
  205. package/src/templator/block2nasl/jsx2nasl/utils.ts +19 -0
  206. package/src/templator/block2nasl/transformBlock2Nasl.ts +99 -0
  207. package/src/templator/block2nasl/viewMergeBlock.ts +150 -0
  208. package/src/translator/types.ts +2 -0
  209. package/src/translator/utils.ts +2 -2
  210. package/src/utils/index.ts +0 -4
  211. package/src/utils/language-cache/constant.ts +1 -0
  212. package/src/utils/language-cache/nasl.ts +6 -0
  213. package/test/concepts/logic/__snapshots__/toEmbeddedTS.spec.ts.snap +182 -0
  214. package/test/concepts/logic/constant.ts +5 -0
  215. package/test/concepts/logic/fixtures/variable-host-call-logic-member-expression.json +267 -0
  216. package/test/concepts/logic/fixtures/variable-host-call-logic-nested-member-expression copy.json +457 -0
  217. package/test/concepts/logic/fixtures/variable-host-call-logic-with-handle-error-member-expression.json +267 -0
  218. package/test/concepts/logic/toEmbeddedTS.spec.ts +15 -0
  219. package/test/tdd/dataQuery/QueryFieldExpression/case1/ast.json +7 -0
  220. package/test/tdd/dataQuery/QueryFieldExpression/case1/natural.ts.txt +1 -0
  221. package/test/tdd/dataQuery/QueryFieldExpression/case2/ast.json +7 -0
  222. package/test/tdd/dataQuery/QueryFieldExpression/case2/natural.ts.txt +1 -0
  223. package/test/tdd/transform/case1/ast.json +243 -0
  224. package/test/tdd/transform/case1/natural.ts.md +20 -0
  225. package/test/tdd/transform/case2/ast.json +207 -0
  226. package/test/tdd/transform/case2/natural.ts.md +12 -0
  227. package/test/tdd.test.js +10 -0
  228. package/test/tdd.transform.test.js +38 -0
  229. package/test/utils.js +40 -0
  230. package/sandbox-natural/stdlib/nasl.core.ts +0 -36
  231. package/sandbox-natural/stdlib/nasl.oql.ts +0 -14
  232. package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +0 -90
  233. package/sandbox-natural/stdlib/nasl.ui.ts +0 -63
@@ -0,0 +1,447 @@
1
+ import { App, Identifier, MemberExpression, View, ViewElement, BaseNode, Return, Variable,
2
+ Assignment, BatchAssignment, CallFunction, AuthLogicForCallInterface, BusinessComponent, BusinessLogic,
3
+ Logic, OverriddenLogic, SubLogic,
4
+ Process,
5
+ ProcessV2,
6
+ ProcessElement,
7
+ ProcessElementV2,
8
+ } from '..';
9
+
10
+ import { SyntaxNode } from '../concepts/utils/types';
11
+
12
+ import { createCompilerState, shiftState } from '../translator';
13
+ import { runGeneratorAsync, runGeneratorSync, wrapForEachToGenerator, returnOrigin } from '../utils';
14
+
15
+ type VarScopeCtx = {
16
+ // 优化首屏 getAncestor 热点代码
17
+ app: App;
18
+ isFirstScreen: boolean;
19
+ frontendGlobalVars: Set<string>;
20
+ varInViewOrComponent: Set<string>;
21
+ logicInViewOrComponent: Set<string>;
22
+ idToView: Map<Identifier, View>;
23
+ ctxViewElement: Array<ViewElement>;
24
+ ctxView: Array<View>;
25
+ isInViewOrComponent: boolean;
26
+ memExprToViewElem: Map<MemberExpression, ViewElement>;
27
+ }
28
+
29
+ type TyInferCtx = {
30
+ // 优化首屏 类型推导,变量提升
31
+ inferViaAsgnMap: Map<Return | Variable , Assignment | BatchAssignment | CallFunction>,
32
+ inferViaFnCallMap: Map<Return | Variable , CallFunction>,
33
+ scope: Array<AuthLogicForCallInterface | BusinessComponent | BusinessLogic | Logic | OverriddenLogic | SubLogic | View>,
34
+ // key 用 name 是不精确的,应该用地址。 暂时用 name,后面比较的时候简单点,暂时应该没 bug
35
+ // 全局变量暂不支持推导
36
+ capturedVars: Map<string, Variable | Return>,
37
+ }
38
+
39
+ type SubLogicCtx = {
40
+ // naslNodesCount: number;
41
+ ctx: Logic | Process | ProcessV2 | ProcessElement | ProcessElementV2 | null;
42
+ // 我也不知道为啥 view 这么特殊
43
+ viewSubLogics: Set<SubLogic>;
44
+ }
45
+
46
+ // 前端全局变量很少,一般就十个以内,所以 map 大小可以忽略不计
47
+ export const varScopeCtx : VarScopeCtx = {
48
+ app: null,
49
+ isFirstScreen: false,
50
+ frontendGlobalVars: new Set<string>(),
51
+ // Collect all params, (local) variables, and logic names under business component
52
+ // Note that within a business component, one can only refer to the above variables, and cannot refer to
53
+ // frontend global variables and any other variables under Views; therefore, checking the Name already suffices.
54
+ // 收集业务组件下的所有参数、(局部)变量和逻辑名称,请注意,在业务组件中,只能引用上述变量,
55
+ // 而不能引用前端全局变量和其他任何 “视图 ”下的变量;因此,检查 “Name” 已经足够了。
56
+ varInViewOrComponent: new Set<string>(),
57
+
58
+ logicInViewOrComponent: new Set<string>(),
59
+
60
+ // Collect all params, (local) variables, and logic names under views
61
+ // Actually, frontendGlobalVars U idInView U idInComponent should be the complete set of accessible variables
62
+ // 事实上,frontendGlobalVars 并上 idInView 并上 idInComponent 应该是前端所有能访问到的变量(名的集合)
63
+
64
+ // 赫基 27w 应用,前端 View 下有 2000 个变量名字;56176 个变量引用,内存占用约 1M。
65
+ idToView: new Map<Identifier, View>(),
66
+
67
+ // 路径上的 ViewElement 节点
68
+ ctxViewElement: [],
69
+
70
+ // 路径上的 View 节点
71
+ ctxView: [],
72
+
73
+ isInViewOrComponent: false,
74
+
75
+ memExprToViewElem: new Map<MemberExpression, ViewElement>(),
76
+ };
77
+
78
+ export const tyInferCtx : TyInferCtx = {
79
+ inferViaAsgnMap: new Map(),
80
+ inferViaFnCallMap: new Map(),
81
+ scope: [],
82
+ capturedVars: new Map(),
83
+ }
84
+
85
+ export const subLogicCtx : SubLogicCtx = {
86
+ // naslNodesCount: 0,
87
+ ctx: null, // 当前逻辑
88
+ viewSubLogics : new Set<SubLogic>(), // 隶属于 view 的 SubLogic,需要排除掉隶属于 Logic 的 SubLogic。
89
+ }
90
+
91
+ const last = <T>(arr: Array<T>) => arr[arr.length - 1];
92
+
93
+
94
+ export function *collectAllSemanticCtx(app: App) {
95
+ varScopeCtx.app = app;
96
+ varScopeCtx.isFirstScreen = true;
97
+ const tasks = [
98
+ // collectFrontendVariablesTask, 这样不值得,能快一点还是快一点吧,
99
+ collectVarInViewOrComponentCtxTask,
100
+ collectLogicInViewOrComponentTask,
101
+ // collectMemExprToViewElemCtxTask, // 因为 $ce 的原因,暂时用不了
102
+ collectIdToViewCtxTask,
103
+ collectSubLogicCtxTask,
104
+ collectTyInferCtxTask
105
+ ];
106
+
107
+ const cleanups = [
108
+ collectVarInViewOrComponentCtxCleanup,
109
+ // collectLogicInViewOrComponentCleanup,
110
+ // collectMemExprToViewElemCtxCleanup, // 因为 $ce 的原因,暂时用不了
111
+ collectIdToViewCtxCleanup,
112
+ collectSubLogicCtxCleanup,
113
+ collectTyInferCtxCleanup
114
+ ];
115
+
116
+ runGeneratorSync(collectFrontendVariablesTask(app));
117
+ runGeneratorSync(app.traverseStrictChildrenDoMultiTasks(tasks, cleanups));
118
+ }
119
+
120
+
121
+ function *collectFrontendVariablesTask(app: App) {
122
+ app.frontendTypes.forEach(ft => {
123
+ ft.frontends.forEach(f => {
124
+ f.variables.forEach(v => {
125
+ varScopeCtx.frontendGlobalVars.add(v.name);
126
+ });
127
+ });
128
+ })
129
+ }
130
+
131
+ function *collectVarInViewOrComponentCtxTask(nd: SyntaxNode) {
132
+ switch (nd.concept) {
133
+ case 'Variable': /* FALL THROUGH */
134
+ case 'Param': /* FALL THROUGH */
135
+ case 'Return': {
136
+ if (varScopeCtx.isInViewOrComponent) {
137
+ varScopeCtx.varInViewOrComponent.add(nd.name);
138
+ }
139
+ break;
140
+ }
141
+ case 'View': /* FALL THROUGH */
142
+ case 'BusinessComponent': varScopeCtx.isInViewOrComponent = true; break;
143
+ default: break;
144
+ }
145
+ }
146
+
147
+ function *collectVarInViewOrComponentCtxCleanup(nd: SyntaxNode) {
148
+ if (nd.concept === 'View' || nd.concept === 'BusinessComponent') {
149
+ varScopeCtx.isInViewOrComponent = false;
150
+ }
151
+ }
152
+
153
+
154
+ // component-like:业务组件下的变量引用
155
+ function *collectLogicInViewOrComponentTask(nd: SyntaxNode) {
156
+ if (nd.concept === 'Logic' || nd.concept === 'BusinessComponent') {
157
+ if (varScopeCtx.isInViewOrComponent) {
158
+ varScopeCtx.logicInViewOrComponent.add(nd.name);
159
+ }
160
+ }
161
+ }
162
+ // collectLogicInViewOrComponentCleanup 的事情被 collectVarInViewOrComponentCtxPost 做了
163
+
164
+
165
+ function *collectMemExprToViewElemCtxTask(nd: SyntaxNode) {
166
+ // view 下的 identifier 的 getAncestor 必定有 view
167
+ switch (nd.concept) {
168
+ case 'ViewElement': {
169
+ varScopeCtx.ctxViewElement.push(nd as ViewElement);
170
+ break;
171
+ }
172
+ case 'MemberExpression': {
173
+ if (varScopeCtx.ctxViewElement) {
174
+ varScopeCtx.memExprToViewElem.set(nd as MemberExpression, last(varScopeCtx.ctxViewElement));
175
+ }
176
+ break;
177
+ }
178
+ default: break;
179
+ }
180
+ }
181
+
182
+ function *collectMemExprToViewElemCtxCleanup(nd: SyntaxNode) {
183
+ if (nd.concept === 'ViewElement') {
184
+ varScopeCtx.ctxViewElement.pop();
185
+ }
186
+ }
187
+
188
+
189
+ function *collectIdToViewCtxTask(nd: SyntaxNode) {
190
+ // view 下的 identifier 的 getAncestor 必定有 view
191
+ switch (nd.concept) {
192
+ case 'View': varScopeCtx.ctxView.push(nd); break;
193
+ case 'Identifier': {
194
+ if (varScopeCtx.ctxView.length > 0) {
195
+ varScopeCtx.idToView.set(nd as Identifier, last(varScopeCtx.ctxView));
196
+ }
197
+ break;
198
+ }
199
+ default: break;
200
+ }
201
+ }
202
+
203
+ function *collectIdToViewCtxCleanup(nd: SyntaxNode) {
204
+ switch (nd.concept) {
205
+ case 'View': varScopeCtx.ctxView.pop(); break;
206
+ default: break;
207
+ }
208
+ }
209
+
210
+
211
+ function *collectSubLogicCtxTask(nd : SyntaxNode) {
212
+ switch (nd.concept) {
213
+ case 'Logic': /* FALL THROUGH */
214
+ /* 流程支持子逻辑 */
215
+ /* 流程变量不支持类型推导 */
216
+ case 'Process': /* FALL THROUGH */
217
+ case 'ProcessV2': /* FALL THROUGH */
218
+ case 'ProcessElement': /* FALL THROUGH */
219
+ case 'ProcessElementV2': /* FALL THROUGH */
220
+ case 'BusinessLogic': subLogicCtx.ctx = nd; break;
221
+ case 'SubLogic': {
222
+ // 收集子逻辑
223
+ if (subLogicCtx.ctx) {
224
+ subLogicCtx.ctx.subLogics.push(nd as SubLogic);
225
+ // console.log('逻辑或流程的子逻辑:', subLogicCtx.ctx)
226
+ } else {
227
+ subLogicCtx.viewSubLogics.add(nd as SubLogic);
228
+ }
229
+ break;
230
+ }
231
+ default: break;
232
+ }
233
+ }
234
+
235
+ function *collectSubLogicCtxCleanup(nd : SyntaxNode) {
236
+ switch (nd.concept) {
237
+ /* 流程支持子逻辑 */
238
+ /* 流程变量不支持类型推导 */
239
+ case 'Logic': /* FALL THROUGH */
240
+ case 'Process': /* FALL THROUGH */
241
+ case 'ProcessV2': /* FALL THROUGH */
242
+ case 'ProcessElement': /* FALL THROUGH */
243
+ case 'ProcessElementV2': subLogicCtx.ctx = null; break;
244
+ // 可能是有人忘了给业务组件加 subLogics?
245
+ case 'View': {
246
+ subLogicCtx.viewSubLogics.forEach(sl => { nd.subLogics.push(sl); });
247
+ // console.log('View 的子逻辑:', nd.subLogics)
248
+ subLogicCtx.viewSubLogics.clear();
249
+ break;
250
+ }
251
+ default: break;
252
+ }
253
+ }
254
+
255
+
256
+ const addVars = (nd : Array<Variable> | Array<Return>, s : Map<string, Variable | Return>) => {
257
+ nd.forEach(v => {
258
+ if (!v.typeAnnotation) {
259
+ s.set(v.name, v);
260
+ }
261
+ })
262
+ }
263
+
264
+ const removeVars = (nd : Array<Variable> | Array<Return>, s : Map<string, Variable | Return>) => {
265
+ nd.forEach(v => s.delete(v.name))
266
+ }
267
+
268
+
269
+ // OQL 批量优化优化完成前请勿移除
270
+ // const oqlSet = new Set<string>();
271
+
272
+ function *collectTyInferCtxTask(nd : SyntaxNode) {
273
+ // ++subLogicCtx.naslNodesCount;
274
+ // if (nd.concept === 'OqlQueryComponent') {
275
+ // oqlSet.add(nd.code);
276
+ // }
277
+ switch (nd.concept) {
278
+ case 'Logic': /* FALL THROUGH */
279
+ case 'AuthLogicForCallInterface': /* FALL THROUGH */
280
+ case 'BusinessLogic': /* FALL THROUGH */
281
+ case 'OverriddenLogic': /* FALL THROUGH */
282
+ case 'SubLogic': {
283
+ // 全局变量不支持类型推导;逻辑的变量也不支持跨子逻辑推导
284
+ // addVars(nd.variables, tyInferCtx.capturedVars);
285
+ // addVars(nd.returns, tyInferCtx.capturedVars);
286
+ tyInferCtx.scope.push(nd);
287
+ break;
288
+ }
289
+ case 'View': /* FALL THROUGH */
290
+ case 'BusinessComponent': {
291
+ addVars(nd.variables, tyInferCtx.capturedVars);
292
+ tyInferCtx.scope.push(nd);
293
+ break;
294
+ }
295
+ default: {
296
+ runGeneratorAsync(
297
+ collectAsgn(tyInferCtx.inferViaAsgnMap, tyInferCtx.inferViaFnCallMap, nd));
298
+ break;
299
+ }
300
+ }
301
+ }
302
+
303
+ function *collectTyInferCtxCleanup(nd : SyntaxNode) {
304
+ switch (nd.concept) {
305
+ case 'Logic': /* FALL THROUGH */
306
+ case 'AuthLogicForCallInterface': /* FALL THROUGH */
307
+ case 'BusinessLogic': /* FALL THROUGH */
308
+ case 'OverriddenLogic': /* FALL THROUGH */
309
+ case 'SubLogic': {
310
+ // removeVars(nd.variables, tyInferCtx.capturedVars);
311
+ // removeVars(nd.returns, tyInferCtx.capturedVars);
312
+ tyInferCtx.scope.pop();
313
+ break;
314
+ }
315
+
316
+ case 'View': /* FALL THROUGH */
317
+ case 'BusinessComponent': {
318
+ removeVars(nd.variables, tyInferCtx.capturedVars);
319
+ tyInferCtx.scope.pop();
320
+ break;
321
+ }
322
+ default: break;
323
+ }
324
+ }
325
+
326
+
327
+ type LogicContainer = AuthLogicForCallInterface | BusinessComponent | BusinessLogic | Logic | OverriddenLogic | SubLogic | View;
328
+
329
+ export function *reCollectTyInferCtx(
330
+ inferViaAsgn: Map<Return | Variable, Assignment | BatchAssignment | CallFunction>,
331
+ inferViaFnCall: Map<Return | Variable, CallFunction>,
332
+ self: LogicContainer) {
333
+
334
+ // No (types of) variables to be inferred
335
+ // @ts-ignore
336
+ const preTest = self.variables?.some((v : Variable) => !v.typeAnnotation) || self.returns?.some((v : Variable) => !v.typeAnnotation)
337
+ if (!preTest) {
338
+ return;
339
+ }
340
+
341
+ // 非首次则清空脏 map,重新收集所需上下文
342
+ if (!varScopeCtx.isFirstScreen) {
343
+ tyInferCtx.inferViaAsgnMap.clear();
344
+ tyInferCtx.inferViaFnCallMap.clear();
345
+ yield* self.traverseChildrenGenerator(collectTyInferCtxTask);
346
+ }
347
+
348
+ self.variables.forEach((locVar : Variable) => {
349
+ if (tyInferCtx.inferViaAsgnMap.has(locVar)){
350
+ inferViaAsgn.set(locVar, tyInferCtx.inferViaAsgnMap.get(locVar))
351
+ } else if (tyInferCtx.inferViaFnCallMap.has(locVar)){
352
+ inferViaFnCall.set(locVar, tyInferCtx.inferViaFnCallMap.get(locVar))
353
+ }
354
+ });
355
+ // @ts-ignore
356
+ self.returns?.forEach((locRet : Return) => {
357
+ if (tyInferCtx.inferViaAsgnMap.has(locRet)){
358
+ inferViaAsgn.set(locRet, tyInferCtx.inferViaAsgnMap.get(locRet))
359
+ } else if (tyInferCtx.inferViaFnCallMap.has(locRet)){
360
+ inferViaFnCall.set(locRet, tyInferCtx.inferViaFnCallMap.get(locRet))
361
+ }
362
+ });
363
+ }
364
+
365
+ function *collectAsgn(
366
+ inferViaAsgnMap: Map<Return | Variable, Assignment | BatchAssignment | CallFunction>,
367
+ inferViaBuiltinFnMap: Map<Return | Variable, CallFunction>,
368
+ nd: SyntaxNode) {
369
+ const self = last(tyInferCtx.scope); // 可能是 undefined
370
+ if (!nd || !self) {
371
+ return;
372
+ }
373
+
374
+ if (nd.concept === 'Assignment' && nd.left?.name) {
375
+ if (!self) {
376
+ console.log('nd', nd)
377
+ }
378
+ const hoistVar = self.variables?.find(v => nd.left?.name === v.name && !v.typeAnnotation)
379
+ // View 和 BusinessComponent 没有 returns
380
+ // @ts-ignore
381
+ ?? self.returns?.find(ret => nd.left?.name === ret.name && !ret.typeAnnotation)
382
+ ?? tyInferCtx.capturedVars.get(nd.left.name);
383
+ if (hoistVar && !inferViaAsgnMap.has(hoistVar)) {
384
+ inferViaAsgnMap.set(hoistVar, nd);
385
+ }
386
+ } else if (nd.concept === 'BatchAssignment') {
387
+ yield* wrapForEachToGenerator(nd.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
388
+ const leftCode =
389
+ leftIndex.length === 1
390
+ ? yield* nd.left.expression.toEmbeddedTS(shiftState(createCompilerState(), '', { inline: true }))
391
+ : yield* nd.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(createCompilerState(), '', { inline: true })) ??
392
+ returnOrigin('');
393
+ const hoistVar = self.variables?.find((v : Variable) => leftCode === v.name && !v.typeAnnotation)
394
+ // View 和 BusinessComponent 没有 returns
395
+ // @ts-ignore
396
+ ?? self.returns?.find(ret => leftCode === ret.name && !ret.typeAnnotation)
397
+ ?? tyInferCtx.capturedVars.get(leftCode);
398
+ if (hoistVar && !inferViaAsgnMap.has(hoistVar)) {
399
+ inferViaAsgnMap.set(hoistVar, nd);
400
+ }
401
+ });
402
+ } else if (nd.concept === 'CallFunction' && nd.derivableCollection?.name) {
403
+ // 需要被推导的集合
404
+ const expr = nd.derivableCollection;
405
+ // 宽泛意义上的变量(变量+出参),View 和 BusinessComponent 没有 returns
406
+ const hoistVar = self.variables.find((v) => expr?.name === v.name && !v.typeAnnotation)
407
+ // @ts-ignore
408
+ ?? self.returns?.find(ret => expr?.name === ret.name && !ret.typeAnnotation)
409
+ ?? tyInferCtx.capturedVars.get(expr.name);
410
+ if (hoistVar && !inferViaBuiltinFnMap.has(hoistVar)) {
411
+ inferViaBuiltinFnMap.set(hoistVar, nd);
412
+ }
413
+ }
414
+ }
415
+
416
+ export const clearSemanticData = () => {
417
+ varScopeCtx.isFirstScreen = false;
418
+ varScopeCtx.frontendGlobalVars.clear();
419
+ varScopeCtx.varInViewOrComponent.clear();
420
+ varScopeCtx.logicInViewOrComponent.clear();
421
+ varScopeCtx.idToView.clear();
422
+ varScopeCtx.ctxViewElement = [];
423
+ varScopeCtx.memExprToViewElem.clear();
424
+ tyInferCtx.inferViaAsgnMap.clear();
425
+ tyInferCtx.inferViaFnCallMap.clear();
426
+ tyInferCtx.scope = [];
427
+ tyInferCtx.capturedVars.clear();
428
+ subLogicCtx.viewSubLogics.clear();
429
+ subLogicCtx.ctx = null;
430
+ }
431
+
432
+ export function printSemanticDataInfo() {
433
+ console.log('frontendGlobalVars', varScopeCtx.frontendGlobalVars)
434
+ console.log('varInViewOrComponent', varScopeCtx.varInViewOrComponent)
435
+ console.log('logicInViewOrComponent', varScopeCtx.logicInViewOrComponent)
436
+ console.log('idToView', varScopeCtx.idToView)
437
+ console.log('memExprToViewElem', varScopeCtx.memExprToViewElem)
438
+ console.log('inferViaAsgnMap', tyInferCtx.inferViaAsgnMap)
439
+ console.log('inferViaFnCallMap', tyInferCtx.inferViaFnCallMap)
440
+ // console.log(oqlSet)
441
+ // console.log('capturedVars', tyInferCtx.capturedVars)
442
+ // console.log('viewSubLogics', subLogicCtx.viewSubLogics)
443
+ // console.log('naslNodesCount', subLogicCtx.naslNodesCount)
444
+ // console.log('ctx', subLogicCtx.ctx)
445
+ // console.log('scope', tyInferCtx.scope)
446
+ // console.log('isFirstScreen', varScopeCtx.isFirstScreen)
447
+ }
@@ -332,6 +332,11 @@ const TS_RULES: Array<{
332
332
  re: /Cannot find name '__UNSUPPORTED__ENTITY__FIELDS__'./,
333
333
  result: '可能为实体属性别名,动态条件中仅支持使用变量',
334
334
  },
335
+ {
336
+ re: /Cannot find name '__UNDEFINED__VARIABLE__(.+?)__'./,
337
+ result: '所选择的内容 $1 未定义。',
338
+ transforms: [outOriginalvalue],
339
+ },
335
340
  {
336
341
  re: /No value exists in scope for the shorthand property '__(?:IDENTIFIER|LEFT|RIGHT)__'. Either declare one or provide an initializer./,
337
342
  result: '用户任务未关联页面',
@@ -0,0 +1,11 @@
1
+ import transformExpression2nasl from './transform-expression2nasl';
2
+ import transformTsType2Nasl from './transform-tstype2nasl';
3
+ import transformFunc2Nasl from './transform-func2nasl';
4
+ import transformTSX2Nasl from './transform-tsx2nasl';
5
+
6
+ export {
7
+ transformExpression2nasl,
8
+ transformTsType2Nasl,
9
+ transformFunc2Nasl,
10
+ transformTSX2Nasl,
11
+ };