@lcap/nasl-language-server-core 3.14.0-rc.3 → 3.14.0-rc.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/out/checker.d.ts.map +1 -1
- package/out/checker.js +93 -36
- package/out/checker.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -1
- package/out/index.js.map +1 -1
- package/out/module/graph.js +6 -6
- package/out/module/graph.js.map +1 -1
- package/out/module/module.d.ts.map +1 -1
- package/out/module/module.js +3 -6
- package/out/module/module.js.map +1 -1
- package/out/reference-manager/builtin-q-name.d.ts +8 -1
- package/out/reference-manager/builtin-q-name.d.ts.map +1 -1
- package/out/reference-manager/builtin-q-name.js +55 -1
- package/out/reference-manager/builtin-q-name.js.map +1 -1
- package/out/reference-manager/get-q-name.js.map +1 -1
- package/out/reference-manager/reference-manager.d.ts +14 -6
- package/out/reference-manager/reference-manager.d.ts.map +1 -1
- package/out/reference-manager/reference-manager.js +221 -111
- package/out/reference-manager/reference-manager.js.map +1 -1
- package/out/reference-manager/rename-q-name.d.ts.map +1 -1
- package/out/reference-manager/rename-q-name.js +3 -0
- package/out/reference-manager/rename-q-name.js.map +1 -1
- package/out/reference-manager/symbol-type.d.ts +5 -3
- package/out/reference-manager/symbol-type.d.ts.map +1 -1
- package/out/reference-manager/symbol-type.js +11 -8
- package/out/reference-manager/symbol-type.js.map +1 -1
- package/out/reference-manager/update-nasl-fragment.d.ts.map +1 -1
- package/out/reference-manager/update-nasl-fragment.js +5 -4
- package/out/reference-manager/update-nasl-fragment.js.map +1 -1
- package/out/symbol/graph.js +2 -2
- package/out/symbol/graph.js.map +1 -1
- package/out/typer/collectGlobalDefs.d.ts.map +1 -1
- package/out/typer/collectGlobalDefs.js +79 -15
- package/out/typer/collectGlobalDefs.js.map +1 -1
- package/out/typer/component-def-manager/component-def-manager.d.ts +11 -7
- package/out/typer/component-def-manager/component-def-manager.d.ts.map +1 -1
- package/out/typer/component-def-manager/component-def-manager.js +17 -6
- package/out/typer/component-def-manager/component-def-manager.js.map +1 -1
- package/out/typer/component-def-manager/utils.d.ts.map +1 -1
- package/out/typer/component-def-manager/utils.js +5 -3
- package/out/typer/component-def-manager/utils.js.map +1 -1
- package/out/typer/dispatch-def.d.ts +0 -2
- package/out/typer/dispatch-def.d.ts.map +1 -1
- package/out/typer/dispatch-def.js +15 -43
- package/out/typer/dispatch-def.js.map +1 -1
- package/out/typer/dispatch-expr.d.ts.map +1 -1
- package/out/typer/dispatch-expr.js +135 -97
- package/out/typer/dispatch-expr.js.map +1 -1
- package/out/typer/dispatch-process.d.ts +0 -1
- package/out/typer/dispatch-process.d.ts.map +1 -1
- package/out/typer/dispatch-process.js +22 -14
- package/out/typer/dispatch-process.js.map +1 -1
- package/out/typer/dispatch-stmt.d.ts.map +1 -1
- package/out/typer/dispatch-stmt.js +30 -21
- package/out/typer/dispatch-stmt.js.map +1 -1
- package/out/typer/dispatch-view.d.ts.map +1 -1
- package/out/typer/dispatch-view.js +90 -40
- package/out/typer/dispatch-view.js.map +1 -1
- package/out/typer/incremental-update.d.ts +7 -30
- package/out/typer/incremental-update.d.ts.map +1 -1
- package/out/typer/incremental-update.js +133 -217
- package/out/typer/incremental-update.js.map +1 -1
- package/out/typer/index.d.ts +3 -4
- package/out/typer/index.d.ts.map +1 -1
- package/out/typer/index.js +4 -4
- package/out/typer/index.js.map +1 -1
- package/out/typer/sem-diag.d.ts +1 -0
- package/out/typer/sem-diag.d.ts.map +1 -1
- package/out/typer/sem-diag.js +24 -17
- package/out/typer/sem-diag.js.map +1 -1
- package/out/typer/solver.d.ts +1 -0
- package/out/typer/solver.d.ts.map +1 -1
- package/out/typer/solver.js +9 -1
- package/out/typer/solver.js.map +1 -1
- package/out/typer/subster.d.ts.map +1 -1
- package/out/typer/subster.js +21 -10
- package/out/typer/subster.js.map +1 -1
- package/out/typer/type-manager.d.ts +3 -2
- package/out/typer/type-manager.d.ts.map +1 -1
- package/out/typer/type-manager.js +30 -20
- package/out/typer/type-manager.js.map +1 -1
- package/out/typer/type-predicate.d.ts +15 -2
- package/out/typer/type-predicate.d.ts.map +1 -1
- package/out/typer/type-predicate.js +56 -24
- package/out/typer/type-predicate.js.map +1 -1
- package/out/typer/typer.d.ts +25 -2
- package/out/typer/typer.d.ts.map +1 -1
- package/out/typer/typer.js +39 -7
- package/out/typer/typer.js.map +1 -1
- package/out/typer/unifier.d.ts.map +1 -1
- package/out/typer/unifier.js +37 -27
- package/out/typer/unifier.js.map +1 -1
- package/out/utils/parseTsClassType.d.ts +2 -0
- package/out/utils/parseTsClassType.d.ts.map +1 -1
- package/out/utils/parseTsClassType.js +7 -2
- package/out/utils/parseTsClassType.js.map +1 -1
- package/out/utils/type-operator.d.ts +2 -2
- package/out/utils/type-operator.d.ts.map +1 -1
- package/out/utils/type-operator.js +24 -7
- package/out/utils/type-operator.js.map +1 -1
- package/package.json +5 -6
- package/out/utils/vue-hack.d.ts +0 -25
- package/out/utils/vue-hack.d.ts.map +0 -1
- package/out/utils/vue-hack.js +0 -33
- package/out/utils/vue-hack.js.map +0 -1
- package/out/utils/vue.d.ts +0 -2
- package/out/utils/vue.d.ts.map +0 -1
- package/out/utils/vue.js +0 -10
- package/out/utils/vue.js.map +0 -1
|
@@ -21,6 +21,7 @@ const set_1 = require("mnemonist/set");
|
|
|
21
21
|
const nasl_predicate_1 = require("../typer/nasl-predicate");
|
|
22
22
|
const type_manager_1 = require("../typer/type-manager");
|
|
23
23
|
const oql_1 = require("../utils/oql");
|
|
24
|
+
const parseTsClassType_1 = require("../utils/parseTsClassType");
|
|
24
25
|
/**
|
|
25
26
|
* 考虑这样一个例子:
|
|
26
27
|
* x = f(...)
|
|
@@ -117,7 +118,7 @@ const oql_1 = require("../utils/oql");
|
|
|
117
118
|
*/
|
|
118
119
|
/**
|
|
119
120
|
* 一些奇怪的引用或关联关系,特别容易出错的:
|
|
120
|
-
* - BindAttr 的 field
|
|
121
|
+
* - BindAttr 的 field、valueField、textField、parentField 字符串暗含的特殊引用
|
|
121
122
|
* - QueryFieldExpression、QueryJoinExpression、QueryFromExpression 中的特殊引用,可能是字符串也可能是别的,注意 QueryFromExpression 内部包含 QueryJoinExpression
|
|
122
123
|
* - 触碰到 Logic 时,要同时看看 OverriddenLogic
|
|
123
124
|
* - 触碰到实体时,要看看实体逻辑
|
|
@@ -188,9 +189,8 @@ class ReferenceManager {
|
|
|
188
189
|
this.cachedQNameSymbolRefs = new Map();
|
|
189
190
|
// 上一次查找引用局部符号建立的 cache
|
|
190
191
|
this.lastBoundary = undefined;
|
|
191
|
-
this.localQNameDefs = new Map();
|
|
192
|
-
this.localSymbolRefs = new Map();
|
|
193
192
|
this.isLocalCacheValid = true;
|
|
193
|
+
this.localQNameRefs = new Map();
|
|
194
194
|
// 当前文件节点
|
|
195
195
|
this.curFileNode = undefined;
|
|
196
196
|
this.buildSymbolRefsFromSymbolGraph = (symbolGraph) => {
|
|
@@ -202,20 +202,62 @@ class ReferenceManager {
|
|
|
202
202
|
// 约 20 万节点 200ms
|
|
203
203
|
this.slowBuildSymbolRefsForApp = (env, app) => {
|
|
204
204
|
this.modeForCollect = "create" /* Operation.Create */;
|
|
205
|
-
const allRefs =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
205
|
+
const allRefs = new Array();
|
|
206
|
+
for (const dataSource of app.dataSources) {
|
|
207
|
+
allRefs.push(...this.collectRefs(env, dataSource));
|
|
208
|
+
}
|
|
209
|
+
for (const structure of app.structures) {
|
|
210
|
+
allRefs.push(...this.collectRefs(env, structure));
|
|
211
|
+
}
|
|
212
|
+
for (const e of app.enums) {
|
|
213
|
+
allRefs.push(...this.collectRefs(env, e));
|
|
214
|
+
}
|
|
215
|
+
for (const l of app.logics) {
|
|
216
|
+
allRefs.push(...this.collectRefs(env, l));
|
|
217
|
+
}
|
|
218
|
+
for (const ol of app.overriddenLogics) {
|
|
219
|
+
allRefs.push(...this.collectRefs(env, ol));
|
|
220
|
+
}
|
|
221
|
+
for (const i of app.interfaces) {
|
|
222
|
+
allRefs.push(...this.collectRefs(env, i));
|
|
223
|
+
}
|
|
224
|
+
// 见下面
|
|
225
|
+
// for (const frontendType of app.frontendTypes) {
|
|
226
|
+
// allRefs.push(...this.collectRefs(env, frontendType));
|
|
227
|
+
// }
|
|
228
|
+
for (const process of app.processes) {
|
|
229
|
+
allRefs.push(...this.collectRefs(env, process));
|
|
230
|
+
}
|
|
231
|
+
// 见下面
|
|
232
|
+
// for (const processV2 of app.processV2s) {
|
|
233
|
+
// allRefs.push(...this.collectRefs(env, processV2));
|
|
234
|
+
// }
|
|
235
|
+
for (const role of app.roles) {
|
|
236
|
+
allRefs.push(...this.collectRefs(env, role));
|
|
237
|
+
}
|
|
238
|
+
for (const connectorDependency of app.connectorDependencies) {
|
|
239
|
+
allRefs.push(...this.collectRefs(env, connectorDependency));
|
|
240
|
+
}
|
|
241
|
+
for (const interfaceDependency of app.interfaceDependencies) {
|
|
242
|
+
allRefs.push(...this.collectRefs(env, interfaceDependency));
|
|
243
|
+
}
|
|
244
|
+
for (const sharedAppDependency of app?.sharedAppDependencies) {
|
|
245
|
+
allRefs.push(...this.collectRefs(env, sharedAppDependency));
|
|
246
|
+
}
|
|
247
|
+
for (const authLogic of app.authLogics) {
|
|
248
|
+
allRefs.push(...this.collectRefs(env, authLogic));
|
|
249
|
+
}
|
|
250
|
+
for (const triggerLauncher of app.triggerLaunchers) {
|
|
251
|
+
allRefs.push(...this.collectRefs(env, triggerLauncher));
|
|
252
|
+
}
|
|
253
|
+
for (const metadataType of app.metadataTypes) {
|
|
254
|
+
allRefs.push(...this.collectRefs(env, metadataType));
|
|
255
|
+
}
|
|
256
|
+
// for (const preference of app.preferenceMap) {
|
|
257
|
+
// allRefs.push(...this.collectRefs(env, preference as any as ValidExtInp));
|
|
258
|
+
// }
|
|
259
|
+
app.integration && allRefs.push(...this.collectRefs(env, app.integration));
|
|
260
|
+
app.backend && allRefs.push(...this.collectRefs(env, app.backend));
|
|
219
261
|
allRefs.forEach(([ref, qName]) => {
|
|
220
262
|
if (!ref) {
|
|
221
263
|
return;
|
|
@@ -233,6 +275,42 @@ class ReferenceManager {
|
|
|
233
275
|
}
|
|
234
276
|
}
|
|
235
277
|
});
|
|
278
|
+
// 如果 QA 说查找引用要能看到实体逻辑里的类型啥的,再给注释去掉
|
|
279
|
+
// 处理一下实体逻辑
|
|
280
|
+
// app.dataSources.forEach(ds => {
|
|
281
|
+
// ds.entities.forEach(e => {
|
|
282
|
+
// e.logics.forEach((l: Logic) => {
|
|
283
|
+
// const refsInLogic = this.collectRefs(env, l);
|
|
284
|
+
// refsInLogic.forEach((qName, ref) => {
|
|
285
|
+
// console.log('xx')
|
|
286
|
+
// allRefs.set(ref, qName);
|
|
287
|
+
// });
|
|
288
|
+
// });
|
|
289
|
+
// });
|
|
290
|
+
// });
|
|
291
|
+
// 暂时特殊处理一下流程,应该不会太慢
|
|
292
|
+
for (const p of app.processV2s) {
|
|
293
|
+
this.addRefsForGlobalSym(env, p);
|
|
294
|
+
}
|
|
295
|
+
for (const fet of app.frontendTypes) {
|
|
296
|
+
for (const bc of fet.businessComponents) {
|
|
297
|
+
this.addRefsForGlobalSym(env, bc);
|
|
298
|
+
}
|
|
299
|
+
for (const cd of fet.componentDependencies) {
|
|
300
|
+
this.addRefsForGlobalSym(env, cd);
|
|
301
|
+
}
|
|
302
|
+
for (const fe of fet.frontends) {
|
|
303
|
+
for (const v of fe.views) {
|
|
304
|
+
this.addRefsForGlobalSym(env, v);
|
|
305
|
+
}
|
|
306
|
+
for (const be of fe.bindEvents) {
|
|
307
|
+
this.addRefsForGlobalSym(env, be);
|
|
308
|
+
}
|
|
309
|
+
for (const v of fe.variables) {
|
|
310
|
+
this.addRefsForGlobalSym(env, v);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
236
314
|
this.modeForCollect = null;
|
|
237
315
|
};
|
|
238
316
|
this.fastBuildQNameDefs = (app) => {
|
|
@@ -242,7 +320,15 @@ class ReferenceManager {
|
|
|
242
320
|
this.addQNameDefs(app);
|
|
243
321
|
}
|
|
244
322
|
// Build builtin types
|
|
245
|
-
buildBuiltinTypeQNameDefs(this.qNameDefs);
|
|
323
|
+
(0, builtin_q_name_1.buildBuiltinTypeQNameDefs)(this.qNameDefs);
|
|
324
|
+
for (const fn of parseTsClassType_1.overloadedBuiltinFns) {
|
|
325
|
+
const def = (0, builtin_q_name_1.createDefaultOverloadedFnDef)(fn, 'nasl.util');
|
|
326
|
+
this.addQNameDef(def.name, def); // name 已经带了 namespace
|
|
327
|
+
}
|
|
328
|
+
for (const fn of parseTsClassType_1.overloadedSqlFns) {
|
|
329
|
+
const def = (0, builtin_q_name_1.createDefaultOverloadedFnDef)(fn, 'nasl.sqlFunction');
|
|
330
|
+
this.addQNameDef(def.name, def); // name 已经带了 namespace
|
|
331
|
+
}
|
|
246
332
|
// Process enums
|
|
247
333
|
const processEnumCollection = (0, collect_q_name_1.adhocBuildProcessEnum)();
|
|
248
334
|
processEnumCollection.forEach(([qName, def]) => {
|
|
@@ -262,7 +348,7 @@ class ReferenceManager {
|
|
|
262
348
|
};
|
|
263
349
|
// Update the addQNameDefs method to use the new collection functions
|
|
264
350
|
/**
|
|
265
|
-
* FIXME wudengke rename this
|
|
351
|
+
* FIXME wudengke rename this to collectFullDefs
|
|
266
352
|
* @param app
|
|
267
353
|
*/
|
|
268
354
|
this.addQNameDefs = (app) => {
|
|
@@ -270,11 +356,9 @@ class ReferenceManager {
|
|
|
270
356
|
const qNameDefs = (0, collect_q_name_1.collectAllQNames)('')(app);
|
|
271
357
|
qNameDefs.forEach(([qName, def]) => {
|
|
272
358
|
if ((0, component_def_manager_1.isGeneralViewElementDefinition)(def)) {
|
|
273
|
-
this.compDefMgr.add(def, 'referenceManager
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
this.addQNameDef(qName, def);
|
|
359
|
+
this.compDefMgr.add(def, 'referenceManager#addQNameDefs');
|
|
277
360
|
}
|
|
361
|
+
this.addQNameDef(qName, def);
|
|
278
362
|
});
|
|
279
363
|
}
|
|
280
364
|
};
|
|
@@ -366,7 +450,7 @@ class ReferenceManager {
|
|
|
366
450
|
else { // 局部符号才需要即时获取
|
|
367
451
|
const boundary = toRaw(getBoundary(nd));
|
|
368
452
|
if (this.lastBoundary === boundary && this.isLocalCacheValid) {
|
|
369
|
-
res = this.
|
|
453
|
+
res = this.localQNameRefs.get((0, get_q_name_1.getTokenQualifiedName)(nd));
|
|
370
454
|
}
|
|
371
455
|
else {
|
|
372
456
|
// 局部扫描,建立所有局部引用
|
|
@@ -380,15 +464,12 @@ class ReferenceManager {
|
|
|
380
464
|
};
|
|
381
465
|
// 建立所有局部引用,先处理上一次的缓存
|
|
382
466
|
this.clearRebuildLocalCache = (env, nd_) => {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
this.localSymbolRefs.clear();
|
|
386
|
-
}
|
|
387
|
-
return this.buildLocalQNameDefs(env, toRaw(nd_));
|
|
467
|
+
this.localQNameRefs.clear();
|
|
468
|
+
return this.buildLocalQNameRefs(env, toRaw(nd_));
|
|
388
469
|
};
|
|
389
470
|
// 给类似 FileNode 级别的定义建立局部索引
|
|
390
471
|
// 修改后:不写入 env map 了,不做缓存,直接返回数据
|
|
391
|
-
this.
|
|
472
|
+
this.buildLocalQNameRefs = (env, __nd) => {
|
|
392
473
|
this.modeForCollect = "create" /* Operation.Create */;
|
|
393
474
|
const nd = toRaw(__nd);
|
|
394
475
|
let logicVars = new Array();
|
|
@@ -417,20 +498,19 @@ class ReferenceManager {
|
|
|
417
498
|
[...allVars, ...logics].forEach(def => {
|
|
418
499
|
const qName = (0, get_q_name_1.getTokenQualifiedName)(def);
|
|
419
500
|
if (qName) {
|
|
420
|
-
this.
|
|
421
|
-
this.localSymbolRefs.set(def, new Set());
|
|
501
|
+
this.localQNameRefs.set(qName, new Set());
|
|
422
502
|
}
|
|
423
503
|
});
|
|
424
504
|
let subRefs = this.collectRefs(env, boundary);
|
|
425
505
|
this.lastBoundary = boundary;
|
|
426
506
|
subRefs?.forEach(([rf, qName]) => {
|
|
427
|
-
|
|
428
|
-
|
|
507
|
+
// 不存在则表示不是局部符号
|
|
508
|
+
this.localQNameRefs.get(qName)?.add(rf);
|
|
429
509
|
});
|
|
430
510
|
// Note: 暂不支持 BindAttr、BindDirective 里的变量的查找引用
|
|
431
511
|
this.isLocalCacheValid = true;
|
|
432
512
|
this.modeForCollect = null;
|
|
433
|
-
return this.
|
|
513
|
+
return this.localQNameRefs.get((0, get_q_name_1.getTokenQualifiedName)(nd));
|
|
434
514
|
};
|
|
435
515
|
/**
|
|
436
516
|
* References to view elements are calls of component logic and access of properties
|
|
@@ -557,8 +637,6 @@ class ReferenceManager {
|
|
|
557
637
|
// 目前的策略是 re-link:删除 logic1 后,不会删除引用。新建一个 logic1 后,自动关联到老的引用上
|
|
558
638
|
case "create" /* Operation.Create */: {
|
|
559
639
|
if (symbol_type_1.localDefConcept.includes(defNode.concept)) {
|
|
560
|
-
this.localQNameDefs.set(qName, defNode);
|
|
561
|
-
this.localSymbolRefs.set(defNode, new Set());
|
|
562
640
|
this.isLocalCacheValid = false;
|
|
563
641
|
}
|
|
564
642
|
else {
|
|
@@ -567,6 +645,9 @@ class ReferenceManager {
|
|
|
567
645
|
oldRefs && this.setSymbolRefs(defNode, oldRefs);
|
|
568
646
|
// qName 链接到新的 defNode 的 mem addr
|
|
569
647
|
this.addQNameDef(qName, defNode);
|
|
648
|
+
if ((0, component_def_manager_1.isGeneralViewElementDefinition)(defNode)) {
|
|
649
|
+
this.compDefMgr.add(defNode, 'handleDefOp');
|
|
650
|
+
}
|
|
570
651
|
// 删除缓存
|
|
571
652
|
this.cachedQNameSymbolRefs.delete(qName);
|
|
572
653
|
}
|
|
@@ -574,14 +655,15 @@ class ReferenceManager {
|
|
|
574
655
|
}
|
|
575
656
|
case "delete" /* Operation.Remove */: { // 连根拔起,但缓存
|
|
576
657
|
if (symbol_type_1.localDefConcept.includes(defNode.concept)) {
|
|
577
|
-
this.localQNameDefs.delete(qName);
|
|
578
|
-
this.localSymbolRefs.delete(defNode);
|
|
579
658
|
this.isLocalCacheValid = false;
|
|
580
659
|
}
|
|
581
660
|
else {
|
|
582
661
|
const refs = this.getSymbolRefs(defNode);
|
|
583
662
|
refs && this.cachedQNameSymbolRefs.set(qName, refs);
|
|
584
663
|
this.qNameDefs.delete(qName);
|
|
664
|
+
if ((0, component_def_manager_1.isGeneralViewElementDefinition)(defNode)) {
|
|
665
|
+
this.compDefMgr.removeComponentGroup(defNode);
|
|
666
|
+
}
|
|
585
667
|
this.deleteSymbolRefs(defNode);
|
|
586
668
|
}
|
|
587
669
|
break;
|
|
@@ -668,35 +750,51 @@ class ReferenceManager {
|
|
|
668
750
|
}
|
|
669
751
|
}
|
|
670
752
|
};
|
|
671
|
-
|
|
672
|
-
|
|
753
|
+
// 处理的 concept 是 Identifier,可以由调用方处理
|
|
754
|
+
this.handleNewCompositeNode = (nd, res) => {
|
|
755
|
+
if (!nd.typeAnnotation) {
|
|
673
756
|
return;
|
|
674
757
|
}
|
|
675
|
-
|
|
758
|
+
const typeAnnotation = nd.typeAnnotation;
|
|
759
|
+
if (!(0, type_predicate_1.isEntityTy)(typeAnnotation) && !(0, type_predicate_1.isStructureTy)(typeAnnotation)) {
|
|
676
760
|
return;
|
|
677
761
|
}
|
|
678
|
-
const tyQName = (0, get_q_name_1.getTokenQualifiedName)(
|
|
762
|
+
const tyQName = (0, get_q_name_1.getTokenQualifiedName)(typeAnnotation);
|
|
679
763
|
if (!tyQName) {
|
|
680
764
|
return;
|
|
681
765
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
766
|
+
res.push([typeAnnotation, tyQName]);
|
|
767
|
+
const parentConcept = (0, type_predicate_1.isEntityTy)(typeAnnotation) ? 'Entity' : 'Structure';
|
|
768
|
+
for (const prop of nd.properties) {
|
|
769
|
+
const propQName = (0, get_q_name_1.getPropQName)(tyQName, prop.name, parentConcept);
|
|
770
|
+
res.push([prop, propQName]);
|
|
686
771
|
}
|
|
687
|
-
|
|
688
|
-
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* RefConcept 里暂时没有加 EntityProperty,因为它是个 Definition,
|
|
775
|
+
* 所以只能在这个函数里直接加入,而不能由调用方处理
|
|
776
|
+
*/
|
|
777
|
+
this.handleForeignKeyRef = (env, nd) => {
|
|
778
|
+
const relNsp = nd.relationNamespace;
|
|
779
|
+
const relEntity = nd.relationEntity;
|
|
780
|
+
const relProperty = nd.relationProperty;
|
|
781
|
+
if (!relNsp || !relEntity || !relProperty) {
|
|
782
|
+
return;
|
|
689
783
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
784
|
+
const relEntityQName = `${relNsp}.${relEntity}`;
|
|
785
|
+
this.handleRefOp(env, this.modeForCollect, nd, relEntityQName);
|
|
786
|
+
const relPropQName = (0, get_q_name_1.getPropQName)(`${relNsp}.${relEntity}`, `${relProperty}`, 'Entity');
|
|
787
|
+
this.handleRefOp(env, this.modeForCollect, nd, relPropQName);
|
|
788
|
+
};
|
|
789
|
+
this.handleBusinessComponentRefs = (env, nd) => {
|
|
790
|
+
const bsName = nd.tag.split('bs-')[1];
|
|
791
|
+
// 虽然慢,但它数量少哇!
|
|
792
|
+
const fet = nd.frontendType;
|
|
793
|
+
const bsDef = fet.businessComponents.find(bc => bc.name === bsName);
|
|
794
|
+
if (!bsDef) {
|
|
795
|
+
return;
|
|
699
796
|
}
|
|
797
|
+
this.handleRefOp(env, this.modeForCollect, nd, (0, get_q_name_1.getTokenQualifiedName)(bsDef));
|
|
700
798
|
};
|
|
701
799
|
/**
|
|
702
800
|
* 无论根节点是 ref 还是 def,都要递归收集下层所有的引用节点
|
|
@@ -719,8 +817,8 @@ class ReferenceManager {
|
|
|
719
817
|
const normalCb = (n) => {
|
|
720
818
|
// 隐式引用 - 来自 __TypeAnnotation
|
|
721
819
|
this.handleSymbolImplicitRefs(n);
|
|
722
|
-
|
|
723
|
-
this.
|
|
820
|
+
n.concept === 'ViewElement' && n.tag.startsWith('bs-') && this.handleBusinessComponentRefs(env, n);
|
|
821
|
+
n.concept === 'EntityProperty' && this.handleForeignKeyRef(env, n);
|
|
724
822
|
if (!symbol_type_1.refConcept.includes(n.concept)) {
|
|
725
823
|
return;
|
|
726
824
|
}
|
|
@@ -735,7 +833,10 @@ class ReferenceManager {
|
|
|
735
833
|
const compositeNodePred = (n) => n.concept === 'MemberExpression' ||
|
|
736
834
|
n.concept === 'QueryFieldExpression' ||
|
|
737
835
|
n.concept === 'TypeAnnotation' ||
|
|
738
|
-
n.concept === 'OqlQueryComponent'
|
|
836
|
+
n.concept === 'OqlQueryComponent' ||
|
|
837
|
+
n.concept === 'FieldPermissionV2' ||
|
|
838
|
+
// @ts-expect-error 临时 hack,下个版本应该把左侧 concept 改一改
|
|
839
|
+
n.concept === 'NewComposite';
|
|
739
840
|
// 会终止子树迭代
|
|
740
841
|
const compositeNodeCb = (n) => {
|
|
741
842
|
let qNameRefs = new Array();
|
|
@@ -743,11 +844,6 @@ class ReferenceManager {
|
|
|
743
844
|
case 'MemberExpression':
|
|
744
845
|
qNameRefs = this.hackMemExpr(env, n);
|
|
745
846
|
break;
|
|
746
|
-
case 'QueryFieldExpression':
|
|
747
|
-
// case 'QueryFromExpression': 这样做行不通或者说很难处理,因为 from 里包含了 join,不会再走到 join
|
|
748
|
-
// case 'QueryJoinExpression':
|
|
749
|
-
qNameRefs = this.splitQueryLike(n);
|
|
750
|
-
break;
|
|
751
847
|
case 'TypeAnnotation':
|
|
752
848
|
const refs = this.splitPolyType(n);
|
|
753
849
|
for (const ref of refs) {
|
|
@@ -755,11 +851,26 @@ class ReferenceManager {
|
|
|
755
851
|
qName && qNameRefs.push([ref, qName]);
|
|
756
852
|
}
|
|
757
853
|
break;
|
|
854
|
+
case 'NewComposite':
|
|
855
|
+
// New 左侧不是成员访问,需单独特殊处理,且需要终止子树迭代:否则会给局部同名变量错误添加引用,如 Entity1.variable1 会错误给局部变量 variable1 添加引用
|
|
856
|
+
this.handleNewCompositeNode(n, res);
|
|
857
|
+
// 右侧构成的引用
|
|
858
|
+
qNameRefs = n.rights
|
|
859
|
+
.flatMap(r => this.collectRefs(env, r));
|
|
860
|
+
break;
|
|
758
861
|
case 'OqlQueryComponent':
|
|
759
862
|
for (const qName of (0, oql_1.extractSymbolsFromOqlQueryComponent)(n)) {
|
|
760
863
|
qNameRefs.push([n, qName]);
|
|
761
864
|
}
|
|
762
865
|
break;
|
|
866
|
+
case 'QueryFieldExpression':
|
|
867
|
+
// case 'QueryFromExpression': 这样做行不通或者说很难处理,因为 from 里包含了 join,不会再走到 join
|
|
868
|
+
// case 'QueryJoinExpression':
|
|
869
|
+
qNameRefs = this.splitQueryLike(n);
|
|
870
|
+
break;
|
|
871
|
+
case 'FieldPermissionV2':
|
|
872
|
+
qNameRefs = this.splitFieldPermissionV2(env, n);
|
|
873
|
+
break;
|
|
763
874
|
default: break;
|
|
764
875
|
}
|
|
765
876
|
for (const [ref, qName] of qNameRefs) {
|
|
@@ -794,6 +905,7 @@ class ReferenceManager {
|
|
|
794
905
|
/**
|
|
795
906
|
* @warning Only handle global symbols
|
|
796
907
|
* 仅清除全局符号的引用。外部优先调用此接口,不要直接调用 collectRefs
|
|
908
|
+
* 不是说输入是 global symbol,而是说对于任何输入,只移除内部对 global symbol 的引用
|
|
797
909
|
*/
|
|
798
910
|
this.removeRefsForGlobalSym = (env, rmNd) => {
|
|
799
911
|
this.curFileNode = rmNd;
|
|
@@ -801,12 +913,16 @@ class ReferenceManager {
|
|
|
801
913
|
if (rmNd.concept === 'View' || rmNd.concept === 'BusinessComponent') {
|
|
802
914
|
env.viewAssocProcess = env.processViewBindings.get((0, get_q_name_1.getTokenQualifiedName)(rmNd)) ?? null;
|
|
803
915
|
}
|
|
804
|
-
|
|
916
|
+
if (rmNd.concept === 'ProcessV2') {
|
|
917
|
+
env.processAssocBind = rmNd.bind;
|
|
918
|
+
}
|
|
919
|
+
// const localVars = env.localVars.get(rmNd as any) ?? [];
|
|
805
920
|
const refAndQNames = this.collectRefs(env, rmNd);
|
|
806
921
|
for (const [ref, qName] of refAndQNames) {
|
|
807
|
-
if (localVars.includes(qName) || cheapTestLocalSymbol(qName)) {
|
|
808
|
-
|
|
809
|
-
}
|
|
922
|
+
// if (localVars.includes(qName) || cheapTestLocalSymbol(qName)) {
|
|
923
|
+
// continue;
|
|
924
|
+
// }
|
|
925
|
+
// 删的时候似乎也不用管是不是局部的、全局的,虽然添加的时候要注意
|
|
810
926
|
this.handleRefOp(env, "delete" /* Operation.Remove */, ref, qName);
|
|
811
927
|
}
|
|
812
928
|
this.modeForCollect = null;
|
|
@@ -823,10 +939,12 @@ class ReferenceManager {
|
|
|
823
939
|
(0, update_nasl_fragment_1.removeBindAttrRef)(this, rmNd);
|
|
824
940
|
}
|
|
825
941
|
env.viewAssocProcess = null;
|
|
942
|
+
env.processAssocBind = null;
|
|
826
943
|
};
|
|
827
944
|
/**
|
|
828
945
|
* @warning Only handle global symbols
|
|
829
946
|
* 仅收集全局符号的引用。外部优先调用此接口,不要直接调用 collectRefs
|
|
947
|
+
* 不是说输入是 global symbol,而是说对于任何输入,只收集内部对 global symbol 的引用
|
|
830
948
|
*/
|
|
831
949
|
this.addRefsForGlobalSym = (env, nd) => {
|
|
832
950
|
this.curFileNode = nd;
|
|
@@ -835,6 +953,9 @@ class ReferenceManager {
|
|
|
835
953
|
// 如果是 null,则设置为 null,否则会报错
|
|
836
954
|
env.viewAssocProcess = env.processViewBindings.get((0, get_q_name_1.getTokenQualifiedName)(nd)) ?? null;
|
|
837
955
|
}
|
|
956
|
+
if (nd.concept === 'ProcessV2') {
|
|
957
|
+
env.processAssocBind = nd.bind;
|
|
958
|
+
}
|
|
838
959
|
const refAndQNames = this.collectRefs(env, nd);
|
|
839
960
|
const localVars = env.localVars.get(nd) ?? [];
|
|
840
961
|
for (const [ref, qName] of refAndQNames) {
|
|
@@ -846,11 +967,9 @@ class ReferenceManager {
|
|
|
846
967
|
this.modeForCollect = null;
|
|
847
968
|
this.curFileNode = undefined;
|
|
848
969
|
env.viewAssocProcess = null;
|
|
970
|
+
env.processAssocBind = null;
|
|
849
971
|
};
|
|
850
|
-
this.
|
|
851
|
-
const qName = (0, get_q_name_1.getTokenQualifiedName)(nd);
|
|
852
|
-
this.localQNameDefs.delete(qName);
|
|
853
|
-
this.localSymbolRefs.delete(nd);
|
|
972
|
+
this.invalidateLocalSymCache = (nd) => {
|
|
854
973
|
this.isLocalCacheValid = false;
|
|
855
974
|
};
|
|
856
975
|
/**
|
|
@@ -1053,6 +1172,24 @@ class ReferenceManager {
|
|
|
1053
1172
|
}
|
|
1054
1173
|
return res;
|
|
1055
1174
|
};
|
|
1175
|
+
this.splitFieldPermissionV2 = (env, nd) => {
|
|
1176
|
+
const res = [];
|
|
1177
|
+
const bind = env.processAssocBind;
|
|
1178
|
+
if (!bind) {
|
|
1179
|
+
return res;
|
|
1180
|
+
}
|
|
1181
|
+
const entityRef = bind.typeAnnotation.properties.find(p => p.name === nd.propertyName);
|
|
1182
|
+
if (!entityRef) {
|
|
1183
|
+
return res;
|
|
1184
|
+
}
|
|
1185
|
+
const entityQName = nd.propertyName === 'data'
|
|
1186
|
+
? (0, get_q_name_1.getTokenQualifiedName)(entityRef.typeAnnotation) // data 是 Entity
|
|
1187
|
+
: (0, get_q_name_1.getTokenQualifiedName)(entityRef.typeAnnotation.typeArguments[0]); // relation_data 是 List<Entity>
|
|
1188
|
+
for (const sub of nd.subFieldPermissions) {
|
|
1189
|
+
res.push([sub, (0, get_q_name_1.getPropQName)(entityQName, sub.propertyName, 'Entity')]);
|
|
1190
|
+
}
|
|
1191
|
+
return res;
|
|
1192
|
+
};
|
|
1056
1193
|
/**
|
|
1057
1194
|
* 获取 Reference Manager 的内存统计信息
|
|
1058
1195
|
*/
|
|
@@ -1061,8 +1198,7 @@ class ReferenceManager {
|
|
|
1061
1198
|
qNameDefs: this.qNameDefs,
|
|
1062
1199
|
symbolRefs: this.symbolRefs, // Exporting private map for serialization
|
|
1063
1200
|
cachedQNameSymbolRefs: this.cachedQNameSymbolRefs,
|
|
1064
|
-
|
|
1065
|
-
localSymbolRefs: this.localSymbolRefs,
|
|
1201
|
+
localQNameRefs: this.localQNameRefs,
|
|
1066
1202
|
compDefMgr: this.compDefMgr,
|
|
1067
1203
|
};
|
|
1068
1204
|
const result = {
|
|
@@ -1170,44 +1306,12 @@ class ReferenceManager {
|
|
|
1170
1306
|
this.clearSymbolRefs();
|
|
1171
1307
|
this.qNameDefs.clear();
|
|
1172
1308
|
this.cachedQNameSymbolRefs.clear();
|
|
1173
|
-
this.
|
|
1174
|
-
this.localSymbolRefs.clear();
|
|
1309
|
+
this.localQNameRefs.clear();
|
|
1175
1310
|
this.compDefMgr.clearAll();
|
|
1176
1311
|
this.symbolImplicitRefs = new WeakMap();
|
|
1177
1312
|
}
|
|
1178
1313
|
}
|
|
1179
1314
|
exports.ReferenceManager = ReferenceManager;
|
|
1180
|
-
const buildBuiltinTypeQNameDefs = (qNameDefs) => {
|
|
1181
|
-
const createNaslPrimTyDef = (name) => nasl_concepts_1.Structure.createProtoTypeOnly({ name, properties: [] });
|
|
1182
|
-
['Boolean', 'String', 'Long', 'Decimal', 'Date', 'DateTime', 'Time', 'Binary', 'Null', 'any', 'void'].forEach(str => {
|
|
1183
|
-
const def = createNaslPrimTyDef(str);
|
|
1184
|
-
if (def.name === 'String') {
|
|
1185
|
-
def.properties.push(nasl_concepts_1.StructureProperty.createProtoTypeOnly({
|
|
1186
|
-
name: 'length',
|
|
1187
|
-
typeAnnotation: typer_1.naslLongTy
|
|
1188
|
-
}));
|
|
1189
|
-
}
|
|
1190
|
-
// type namespace is nasl.core
|
|
1191
|
-
qNameDefs.set(`nasl.core.${str}`, def);
|
|
1192
|
-
});
|
|
1193
|
-
const createNaslGenericTyDef = (name) => nasl_concepts_1.Structure.createProtoTypeOnly({
|
|
1194
|
-
name,
|
|
1195
|
-
properties: [nasl_concepts_1.StructureProperty.createProtoTypeOnly({ name: 'length', typeAnnotation: typer_1.naslLongTy })],
|
|
1196
|
-
});
|
|
1197
|
-
['Map', 'List'].forEach(str => {
|
|
1198
|
-
const def = createNaslGenericTyDef(str);
|
|
1199
|
-
if (str === 'List') {
|
|
1200
|
-
def.typeParams = [(0, typer_1.createTyParam)('T')];
|
|
1201
|
-
}
|
|
1202
|
-
else if (str === 'Map') {
|
|
1203
|
-
def.typeParams = [(0, typer_1.createTyParam)('K'), (0, typer_1.createTyParam)('V')];
|
|
1204
|
-
}
|
|
1205
|
-
// type namespace is nasl.collection
|
|
1206
|
-
qNameDefs.set(`nasl.collection.${str}`, def);
|
|
1207
|
-
});
|
|
1208
|
-
// Current<T>
|
|
1209
|
-
(0, builtin_q_name_1.collectAllNaslNameSpace)(qNameDefs);
|
|
1210
|
-
};
|
|
1211
1315
|
// prependStr moved to get-q-name.ts
|
|
1212
1316
|
// getTokenQualifiedName moved to get-q-name.ts
|
|
1213
1317
|
// getTokenQualifiedNameForMatchedExpr moved to get-q-name.ts
|
|
@@ -1401,8 +1505,14 @@ const cheapTestLocalSymbol = (qName) => {
|
|
|
1401
1505
|
if (qName.startsWith('a+') || qName.startsWith('Tp+') ||
|
|
1402
1506
|
qName.startsWith('nasl.core') || qName.startsWith('elements.') ||
|
|
1403
1507
|
qName.startsWith('nasl.util') ||
|
|
1404
|
-
qName.startsWith('nasl.collection')
|
|
1405
|
-
|
|
1508
|
+
qName.startsWith('nasl.collection')) {
|
|
1509
|
+
return true;
|
|
1510
|
+
}
|
|
1511
|
+
// 页面下引用的 Process 的 qName
|
|
1512
|
+
// if (qName.startsWith('Process_')) {
|
|
1513
|
+
// return false;
|
|
1514
|
+
// }
|
|
1515
|
+
if (qName.indexOf('.') === -1) {
|
|
1406
1516
|
return true;
|
|
1407
1517
|
}
|
|
1408
1518
|
return false;
|