@lcap/nasl 4.1.0-beta.2 → 4.1.0-beta.20
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/generator/genBundleFiles.d.ts.map +1 -1
- package/out/generator/genBundleFiles.js +18 -116
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/permission.d.ts.map +1 -1
- package/out/generator/permission.js +70 -34
- package/out/generator/permission.js.map +1 -1
- package/out/generator/release-body/body.d.ts +5 -3
- package/out/generator/release-body/body.d.ts.map +1 -1
- package/out/generator/release-body/body.js +395 -392
- package/out/generator/release-body/body.js.map +1 -1
- package/out/generator/release-body/data.d.ts +4 -2
- package/out/generator/release-body/data.d.ts.map +1 -1
- package/out/generator/release-body/data.js +67 -52
- package/out/generator/release-body/data.js.map +1 -1
- package/out/generator/release-body/index.d.ts +1 -0
- package/out/generator/release-body/index.d.ts.map +1 -1
- package/out/generator/release-body/index.js +1 -0
- package/out/generator/release-body/index.js.map +1 -1
- package/out/generator/release-body/memory-optimization.d.ts +47 -0
- package/out/generator/release-body/memory-optimization.d.ts.map +1 -0
- package/out/generator/release-body/memory-optimization.js +267 -0
- package/out/generator/release-body/memory-optimization.js.map +1 -0
- package/out/generator/release-body/utils.d.ts +11 -4
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +55 -23
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/generator/ui-library-declaration/basic.d.ts.map +1 -1
- package/out/generator/ui-library-declaration/basic.js +6 -0
- package/out/generator/ui-library-declaration/basic.js.map +1 -1
- package/out/generator/ui-library-declaration/dependency.d.ts.map +1 -1
- package/out/generator/ui-library-declaration/dependency.js +2 -0
- package/out/generator/ui-library-declaration/dependency.js.map +1 -1
- package/out/generator/ui-library-declaration/types.d.ts +2 -0
- package/out/generator/ui-library-declaration/types.d.ts.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/natural/transforms/transform2LogicItem.d.ts +2 -1
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +92 -13
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/utils.d.ts +1 -1
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +10 -4
- package/out/natural/transforms/utils.js.map +1 -1
- package/out/server/client/nasl-server-client.d.ts +7 -0
- package/out/server/client/nasl-server-client.d.ts.map +1 -0
- package/out/server/client/nasl-server-client.js +9 -0
- package/out/server/client/nasl-server-client.js.map +1 -0
- package/out/server/extendBaseNode.d.ts.map +1 -1
- package/out/server/extendBaseNode.js +19 -10
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/findReference.d.ts.map +1 -1
- package/out/server/findReference.js +5 -1
- package/out/server/findReference.js.map +1 -1
- package/out/server/index.d.ts +0 -1
- package/out/server/index.d.ts.map +1 -1
- package/out/server/index.js +1 -2
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +9 -11
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +121 -109
- package/out/server/naslServer.js.map +1 -1
- package/out/service/storage/api.d.ts +13 -4
- package/out/service/storage/api.js +6 -0
- package/out/service/storage/api.js.map +1 -1
- package/out/service/storage/init.d.ts +11 -0
- package/out/service/storage/init.d.ts.map +1 -1
- package/out/service/storage/init.js +43 -18
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/service.d.ts +9 -0
- package/out/service/storage/service.d.ts.map +1 -1
- package/out/service/storage/service.js +17 -0
- package/out/service/storage/service.js.map +1 -1
- package/out/templator/utils.d.ts.map +1 -1
- package/out/templator/utils.js +1 -0
- package/out/templator/utils.js.map +1 -1
- package/package.json +11 -12
- package/sandbox/stdlib/nasl.util.ts +18 -4
package/out/server/naslServer.js
CHANGED
|
@@ -46,9 +46,11 @@ const path = __importStar(require("path"));
|
|
|
46
46
|
const worker_threads_1 = require("worker_threads");
|
|
47
47
|
/// #endif
|
|
48
48
|
const concepts_1 = require("../concepts");
|
|
49
|
+
// import { validator, VusionValidator } from '@lcap/nasl-concepts';
|
|
49
50
|
const asserts_1 = require("@lcap/nasl-concepts/asserts");
|
|
50
51
|
const service_1 = require("@lcap/nasl-concepts/service");
|
|
51
52
|
const utils = __importStar(require("../utils"));
|
|
53
|
+
const memory_optimization_1 = require("../generator/release-body/memory-optimization");
|
|
52
54
|
const createUiTs_1 = __importStar(require("./createUiTs"));
|
|
53
55
|
const translator_1 = require("../translator");
|
|
54
56
|
const translator_2 = require("./translator");
|
|
@@ -59,25 +61,7 @@ const decorators_1 = require("../decorators");
|
|
|
59
61
|
const nasl_concepts_1 = require("@lcap/nasl-concepts");
|
|
60
62
|
const nasl_language_server_core_1 = require("@lcap/nasl-language-server-core");
|
|
61
63
|
const findReference_1 = require("./findReference");
|
|
62
|
-
const
|
|
63
|
-
'textField',
|
|
64
|
-
'valueField',
|
|
65
|
-
'iconField',
|
|
66
|
-
'toField',
|
|
67
|
-
'parentField',
|
|
68
|
-
'childrenField',
|
|
69
|
-
'hasChildrenField',
|
|
70
|
-
'field',
|
|
71
|
-
'idField',
|
|
72
|
-
'titleField',
|
|
73
|
-
'closableField',
|
|
74
|
-
'descriptionField',
|
|
75
|
-
'expandedField',
|
|
76
|
-
'disabledField',
|
|
77
|
-
'nameField',
|
|
78
|
-
'labelField',
|
|
79
|
-
'sortField'
|
|
80
|
-
];
|
|
64
|
+
const nasl_server_client_1 = require("./client/nasl-server-client");
|
|
81
65
|
const SentryMessager = (0, nasl_sentry_1.sentryMonitorTSWorkerMessager)(Messager_1.default);
|
|
82
66
|
// naslStdlib文件缓存;作为全局变量给多实例用复用
|
|
83
67
|
const __naslStdlibFileCacheMap = new Map();
|
|
@@ -371,7 +355,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
371
355
|
// 目前里面包含所有定义、逻辑、业务组件、前端全局变量等
|
|
372
356
|
fixAllUseBeforeAssignTasks = await (0, nasl_language_server_core_1.firstScreenCheckAndCompare)(this.semEnv, rawApp);
|
|
373
357
|
// 类型检查完才能收集引用
|
|
374
|
-
this.semEnv.refMgr.buildSymbolRefsForApp(this.semEnv, rawApp
|
|
358
|
+
this.semEnv.refMgr.buildSymbolRefsForApp(this.semEnv, rawApp);
|
|
375
359
|
}
|
|
376
360
|
catch (err) {
|
|
377
361
|
this.semEnv.logger.fatal('\x1b[44m\x1b[97m 类型检查出错了,估计没标完 \x1b[0m');
|
|
@@ -387,13 +371,13 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
387
371
|
const diagAppStartTime = performance.now();
|
|
388
372
|
await utils.runGeneratorAsync(this.semEnv.errorDiagnoser.diagnosticApp());
|
|
389
373
|
const diagAppEndTime = performance.now();
|
|
390
|
-
console.
|
|
374
|
+
console.info(`\x1b[44m\x1b[97m Diagnostic App \x1b[0m: ${((diagAppEndTime - diagAppStartTime) / 1000).toFixed(3)}s`);
|
|
391
375
|
const diagnosticMap = this.semEnv.errorDiagnoser.getAllDiagnostics();
|
|
392
376
|
const transformStartTime = performance.now();
|
|
393
377
|
const records = transformDiagnosticMapToRecords(diagnosticMap);
|
|
394
378
|
await this.diagnosticManager.setInitialDiagData(records);
|
|
395
379
|
const transformEndTime = performance.now();
|
|
396
|
-
console.
|
|
380
|
+
console.info(`\x1b[44m\x1b[97m Transform Diagnostic Map To Records \x1b[0m: ${((transformEndTime - transformStartTime) / 1000).toFixed(3)}s`);
|
|
397
381
|
// 首屏和增量通路不同,首屏时需要手动调用lsRunEndSwitch;增量时则在增量代码中调用
|
|
398
382
|
this._lsRunEndSwitch();
|
|
399
383
|
this.isFirstScreen = false;
|
|
@@ -405,7 +389,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
405
389
|
rawApp.emit('collect:end');
|
|
406
390
|
this.semData.isFirstScreen = false;
|
|
407
391
|
this.semEnv.allocatedVEQNames.forEach(n => {
|
|
408
|
-
this.semEnv.refMgr.
|
|
392
|
+
this.semEnv.refMgr.gQNameDefs.delete(n);
|
|
409
393
|
});
|
|
410
394
|
this.semEnv.allocatedVEQNames.length = 0;
|
|
411
395
|
for (const value of this.cachedEventPayloadValues) {
|
|
@@ -417,6 +401,12 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
417
401
|
}
|
|
418
402
|
utils.isDebugMode && console.timeEnd('\x1b[44m\x1b[97m 用户体感首屏检查耗时 \x1b[0m');
|
|
419
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* @warning 不放在这里无法起到加速效果,且读到的 cache 为空,抛出 undefined 值
|
|
406
|
+
* 放在这里的话好像是有些“时序”问题?
|
|
407
|
+
*/
|
|
408
|
+
this.semData.recoverSlowGetters();
|
|
409
|
+
this.semData.clearSemanticData();
|
|
420
410
|
(0, nasl_language_server_core_1.clearFileNodeCache)();
|
|
421
411
|
}
|
|
422
412
|
this.notifyPublishDiagnosticsEnd(tsDiagnostics);
|
|
@@ -852,8 +842,6 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
852
842
|
await this.waitOqlQueryComponentChildrenFinish(app);
|
|
853
843
|
// 翻译 ts 文件
|
|
854
844
|
const results = await utils.runGeneratorAsync(getAllTsFiles());
|
|
855
|
-
this.semData.recoverSlowGetters();
|
|
856
|
-
this.semData.clearSemanticData();
|
|
857
845
|
const files = results.map((result) => ({
|
|
858
846
|
file: result.filePath,
|
|
859
847
|
fileContent: result.code,
|
|
@@ -1614,7 +1602,9 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
1614
1602
|
// // this.logger.info(refsList, 'refsList');
|
|
1615
1603
|
// return refsList;
|
|
1616
1604
|
// }
|
|
1617
|
-
|
|
1605
|
+
/**
|
|
1606
|
+
* @warning 主要是 rename 等内部调用的查找引用,不是用户点击的 "查找引用"
|
|
1607
|
+
*/
|
|
1618
1608
|
async _isHaveRef(__node) {
|
|
1619
1609
|
const wrapRefs = (refs) => {
|
|
1620
1610
|
const result = [];
|
|
@@ -1642,35 +1632,34 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
1642
1632
|
return [];
|
|
1643
1633
|
}
|
|
1644
1634
|
const { parentNode } = nd;
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
result.push(...wrapRefs(this.semEnv.refMgr.getReferences(this.semEnv, l)));
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
else if (nd.concept === 'ViewElement') {
|
|
1653
|
-
const refMemAddrs = this.semEnv.refMgr.getViewElementRefs(this.semEnv, nd);
|
|
1654
|
-
result.push(...wrapRefs(refMemAddrs));
|
|
1655
|
-
}
|
|
1656
|
-
else if (nd.concept === 'ProcessElementV2') {
|
|
1657
|
-
const refMemAddrs = this.semEnv.refMgr.getProcessElementRefs(this.semEnv, nd);
|
|
1635
|
+
const semEnv = NaslServer_1.toRaw(this.semEnv);
|
|
1636
|
+
let result = wrapRefs(semEnv.refMgr.getReferences(semEnv, nd));
|
|
1637
|
+
if (nd.concept === 'ProcessElementV2') {
|
|
1638
|
+
const refMemAddrs = semEnv.refMgr.getProcessElementRefs(semEnv, nd);
|
|
1658
1639
|
result.push(...wrapRefs(refMemAddrs));
|
|
1659
1640
|
}
|
|
1660
1641
|
else if (nd.concept === 'DataSource') {
|
|
1661
1642
|
for (const entity of nd.entities) {
|
|
1662
|
-
const ettRefs =
|
|
1643
|
+
const ettRefs = semEnv.refMgr.getReferences(semEnv, entity);
|
|
1663
1644
|
result.push(...wrapRefs(ettRefs));
|
|
1664
1645
|
for (const l of entity.logics) {
|
|
1665
|
-
result.push(...wrapRefs(
|
|
1646
|
+
result.push(...wrapRefs(semEnv.refMgr.getReferences(semEnv, l)));
|
|
1666
1647
|
}
|
|
1667
1648
|
}
|
|
1668
1649
|
}
|
|
1669
|
-
else if (
|
|
1650
|
+
else if (nd.concept === 'BindEvent') {
|
|
1651
|
+
// v4.1 新增 绑定事件 改类型,需要把 事件逻辑的引用,全部迁移过去
|
|
1652
|
+
// v4.1 修改:logics 其实只能有一个
|
|
1653
|
+
if (nd.logics[0].concept === 'Logic') {
|
|
1654
|
+
const eventLogicRefs = semEnv.refMgr.getReferences(semEnv, nd.logics[0]);
|
|
1655
|
+
result.push(...wrapRefs(eventLogicRefs));
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
else if (nd.concept === 'Param' || nd.concept === 'ParamWithGroup') {
|
|
1670
1659
|
// 调用处的 keyword = XXX 等也要修改,所以查 Logic、View 等的引用
|
|
1671
1660
|
const pNode = NaslServer_1.toRaw(parentNode);
|
|
1672
|
-
if (
|
|
1673
|
-
const refs =
|
|
1661
|
+
if ((0, service_1.isCallableNaslLogic)(pNode) || concepts_1.asserts.isStrictView(pNode)) {
|
|
1662
|
+
const refs = semEnv.refMgr.getReferences(semEnv, pNode);
|
|
1674
1663
|
result.push(...wrapRefs(refs));
|
|
1675
1664
|
}
|
|
1676
1665
|
}
|
|
@@ -1713,6 +1702,22 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
1713
1702
|
const minRange = {
|
|
1714
1703
|
...record,
|
|
1715
1704
|
};
|
|
1705
|
+
// 搞事情:v4.1 新增 绑定事件 改类型,需要把 事件逻辑的引用,全部迁移过去
|
|
1706
|
+
if (nd.concept === 'BindEvent') {
|
|
1707
|
+
if (minRange.node.concept === 'Identifier') {
|
|
1708
|
+
/**
|
|
1709
|
+
* 使用正则替换倒数第二个点和倒数第一个点之间的内容
|
|
1710
|
+
* 例如 elements.button_1.bindEvents.XXX.logics -> elements.button_1.bindEvents.YYY.logics
|
|
1711
|
+
*/
|
|
1712
|
+
minRange.newValue = minRange.node.namespace.replace(/(\.bindEvents\.)([^.]+)(\.logics)$/, `$1${newValue}$3`);
|
|
1713
|
+
minRange.setTypeMethods = 'setNamespace';
|
|
1714
|
+
}
|
|
1715
|
+
else if (minRange.node === nd) {
|
|
1716
|
+
// 自己
|
|
1717
|
+
minRange.newValue = newValue;
|
|
1718
|
+
minRange.setTypeMethods = 'setName';
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1716
1721
|
// 节点上ts临时变量标识,如果有这个就不rename
|
|
1717
1722
|
if (minRange.node?.noTsReName) {
|
|
1718
1723
|
return null;
|
|
@@ -1746,6 +1751,22 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
1746
1751
|
}
|
|
1747
1752
|
// 如果匹配到的节点是Identifier表达式
|
|
1748
1753
|
if (minRange.node instanceof concepts_1.Identifier) {
|
|
1754
|
+
/**
|
|
1755
|
+
* v4.1 新增 Identifier 可能是 页面元素 的事件逻辑 Logic 的引用 或 逻辑的引用
|
|
1756
|
+
* 页面元素 改名后,这个 Identifier 的 namespace 中间的元素名需要修改
|
|
1757
|
+
*/
|
|
1758
|
+
if (nd.concept === 'ViewElement') {
|
|
1759
|
+
minRange.setTypeMethods = 'setNamespace';
|
|
1760
|
+
/**
|
|
1761
|
+
* 使用正则替换第二个点和第三个点之间的内容
|
|
1762
|
+
* 例如 elements.XXX.bindEvents.click.logics -> elements.YYY.bindEvents.click.logics
|
|
1763
|
+
*/
|
|
1764
|
+
const parts = minRange.node.namespace.split('.');
|
|
1765
|
+
if (parts.length >= 1) {
|
|
1766
|
+
parts[1] = newValue;
|
|
1767
|
+
minRange.newValue = parts.join('.');
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1749
1770
|
// 如果参数修改影响了Identifier, 就说明是上一级逻辑的引用,所以就直接过滤掉就好了
|
|
1750
1771
|
if (nd instanceof concepts_1.Param && minRange.node?.namespace?.endsWith('logics')) {
|
|
1751
1772
|
return null;
|
|
@@ -1824,7 +1845,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
1824
1845
|
minRange.setTypeMethods = 'setUrlValue';
|
|
1825
1846
|
minRange.newValue = newTextValue;
|
|
1826
1847
|
}
|
|
1827
|
-
else if (minRange.node instanceof concepts_1.BindAttribute &&
|
|
1848
|
+
else if (minRange.node instanceof concepts_1.BindAttribute && nasl_language_server_core_1.specialStringRefs.includes(minRange.node.name)) {
|
|
1828
1849
|
// eslint-disable-next-line no-confusing-arrow
|
|
1829
1850
|
minRange.newValue = (minRange.node.value ?? '').split('.').map((v, i) => i ? v : newValue.charAt(0).toLowerCase() + newValue.slice(1)).join('.');
|
|
1830
1851
|
minRange.setTypeMethods = 'setValue';
|
|
@@ -1863,7 +1884,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
1863
1884
|
// 如果要修改实体属性
|
|
1864
1885
|
if (nd instanceof concepts_1.EntityProperty) {
|
|
1865
1886
|
// 如果是修改实体属性,要同步绑定属性(属性名为 valueField / textField)
|
|
1866
|
-
if (minRange.node instanceof concepts_1.BindAttribute &&
|
|
1887
|
+
if (minRange.node instanceof concepts_1.BindAttribute && nasl_language_server_core_1.specialStringRefs.includes(minRange.node.name)) {
|
|
1867
1888
|
// eslint-disable-next-line no-confusing-arrow
|
|
1868
1889
|
minRange.newValue = (minRange.node.value ?? '').split('.').slice(0, -1).concat(newValue).join('.');
|
|
1869
1890
|
minRange.setTypeMethods = 'setValue';
|
|
@@ -2128,7 +2149,16 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2128
2149
|
// 增加参数的副作用,用于更新logic和view
|
|
2129
2150
|
_addParamsEffect(refsList, nd) {
|
|
2130
2151
|
const parentNode = nd?.parentNode;
|
|
2131
|
-
|
|
2152
|
+
// 按 node.nodePath 降序排列,保证父级或更深层的引用先处理
|
|
2153
|
+
const sortedRefs = (refsList || []).slice().sort((a, b) => {
|
|
2154
|
+
const pa = a?.node?.nodePath ?? '';
|
|
2155
|
+
const pb = b?.node?.nodePath ?? '';
|
|
2156
|
+
return pb.localeCompare(pa);
|
|
2157
|
+
});
|
|
2158
|
+
// 考虑 CallA(CallA(null))
|
|
2159
|
+
// 如果 不按 nodePath 降序排列,那么更新了第一个 CallA 后,第二个的 CallA 的 nodePath 中会有 -1
|
|
2160
|
+
// 推测可能是 CallA 变成了新节点,所以存的 node 变了
|
|
2161
|
+
sortedRefs.forEach(({ node: minRangeNode }) => {
|
|
2132
2162
|
// 如果找到节点是callLogic就去更新
|
|
2133
2163
|
if (nd instanceof concepts_1.Param) {
|
|
2134
2164
|
if (minRangeNode instanceof concepts_1.CallLogic || minRangeNode instanceof concepts_1.CallAuthInterface) {
|
|
@@ -2356,6 +2386,8 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2356
2386
|
utils.delay(55);
|
|
2357
2387
|
}
|
|
2358
2388
|
const { node, filePath, item } = itemDetail;
|
|
2389
|
+
if (!item)
|
|
2390
|
+
return;
|
|
2359
2391
|
// 先按照顺序占位
|
|
2360
2392
|
types.set(node, null);
|
|
2361
2393
|
// 获取已知节点类型的类型
|
|
@@ -2386,6 +2418,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2386
2418
|
'CallFunction',
|
|
2387
2419
|
'CallInterface',
|
|
2388
2420
|
'CallMicroserviceInterface',
|
|
2421
|
+
'CallGatewayInterface',
|
|
2389
2422
|
'MemberExpression',
|
|
2390
2423
|
'Return',
|
|
2391
2424
|
'Variable',
|
|
@@ -2621,32 +2654,12 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2621
2654
|
// 不用 TS LS 的最新类型,用现有类型直接写入 NASL json
|
|
2622
2655
|
async fastGetNaslAnnotatedJSON(naslNode) {
|
|
2623
2656
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
2624
|
-
const isApp = concepts_1.asserts.isApp(naslNode);
|
|
2625
2657
|
if (this.changeStackList?.length) {
|
|
2626
2658
|
throw new Error(`当前还有${this.changeStackList.length}个文件还在执行更新操作`);
|
|
2627
2659
|
}
|
|
2628
2660
|
this.logger.time('app to AnnotatedJSON');
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
// 不知道为什么实体的(国际化、流程)枚举的默认值的 expr 和 expr.object 和 expr.property 都没标类型,但是逻辑变量的默认值就标了
|
|
2632
|
-
// 不标类型,服务端就认为是用户自定义枚举,然后 import 一个奇怪的文件,就挂了
|
|
2633
|
-
// Enum1.prop,怎么想 prop 也不应该标 Enum1 类型啊,现在就得是 prop、Enum1、Enum1.prop 都标成 Enum1 类型……
|
|
2634
|
-
const fixEnumDefValTypesInEntity = (app) => {
|
|
2635
|
-
app.dataSources.forEach(ds => ds.entities.forEach(ett => {
|
|
2636
|
-
ett.properties.forEach(prop => {
|
|
2637
|
-
// @ts-ignore
|
|
2638
|
-
if (isSysEnum(prop.defaultValue?.expression?.object?.namespace)) {
|
|
2639
|
-
const ty = prop.typeAnnotation;
|
|
2640
|
-
const memExp = prop.defaultValue.expression;
|
|
2641
|
-
memExp.__TypeAnnotation = ty;
|
|
2642
|
-
memExp.object.__TypeAnnotation = ty;
|
|
2643
|
-
memExp.property.__TypeAnnotation = ty;
|
|
2644
|
-
}
|
|
2645
|
-
});
|
|
2646
|
-
}));
|
|
2647
|
-
};
|
|
2648
|
-
fixEnumDefValTypesInEntity(naslNode);
|
|
2649
|
-
}
|
|
2661
|
+
// 重置优化统计信息
|
|
2662
|
+
(0, memory_optimization_1.resetOptimizationStats)();
|
|
2650
2663
|
const timeZoneArgumentIndexMap = new Map([
|
|
2651
2664
|
['ToString', 1],
|
|
2652
2665
|
['CurrDateTime', 0],
|
|
@@ -2695,17 +2708,19 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2695
2708
|
// Do not write redundant type annotation for TypeAnnotation concept.
|
|
2696
2709
|
return;
|
|
2697
2710
|
}
|
|
2698
|
-
//
|
|
2699
|
-
|
|
2711
|
+
// 集成内存优化:在标注过程中直接优化JSON,减少内存使用和处理时间
|
|
2712
|
+
(0, memory_optimization_1.optimizeJsonDuringAnnotation)(newJson);
|
|
2700
2713
|
let tyAnn = tyAnnToJSON(this.semEnv.getType(oldNd));
|
|
2701
|
-
if ((oldNd.concept === 'Variable' || oldNd.concept === 'Return' || oldNd.concept === 'Param')
|
|
2714
|
+
if ((oldNd.concept === 'Variable' || oldNd.concept === 'Return' || oldNd.concept === 'Param' || oldNd.concept === 'ParamWithGroup')
|
|
2702
2715
|
&& !oldNd.typeAnnotation
|
|
2703
2716
|
&& tyAnn?.typeKind !== 'typeParam') {
|
|
2704
2717
|
newJson.typeAnnotation = tyAnn;
|
|
2705
2718
|
}
|
|
2706
2719
|
// 原来的标注环节复制粘贴过来改写的,调整了顺序
|
|
2707
2720
|
// jsonSerializer 是 CallLogic,其余是 CallFunction。CallLogic 有好几个子类。
|
|
2708
|
-
|
|
2721
|
+
const isCallType1 = oldNd.concept === 'CallLogic' || oldNd.concept === 'CallConnector';
|
|
2722
|
+
const isCallFn = oldNd.concept === 'CallFunction';
|
|
2723
|
+
if (isCallType1 || isCallFn) {
|
|
2709
2724
|
const tzArgIdx = timeZoneArgumentIndexMap.get(oldNd.calleeName);
|
|
2710
2725
|
const args = oldNd.arguments;
|
|
2711
2726
|
const tzArg = args ? args[tzArgIdx] : undefined;
|
|
@@ -2718,9 +2733,9 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2718
2733
|
/**
|
|
2719
2734
|
* 特殊处理,不想去查两次类型, 因为是从函数签名上拿类型,所以直接合并在一起,先这样
|
|
2720
2735
|
* 应该主要是 Java 扩展库逻辑调用
|
|
2721
|
-
*/
|
|
2722
|
-
if (oldNd
|
|
2723
|
-
newJson.typeArguments = oldNd.__TypeArguments.map(tyAnnToJSON);
|
|
2736
|
+
*/ // @ts-ignore
|
|
2737
|
+
if (oldNd.__TypeArguments?.length && isCallType1) { // @ts-ignore
|
|
2738
|
+
newJson.typeArguments = oldNd.__TypeArguments.map(tyAnnToJSON);
|
|
2724
2739
|
newJson.typeAnnotation = tyAnn;
|
|
2725
2740
|
}
|
|
2726
2741
|
// 根据 https://projectmanage.netease-official.lcap.163yun.com/dashboard/FeatureDetail?id=2737356895760128&id1=null&iterationId=null&versionid=null&tab=info
|
|
@@ -2728,7 +2743,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2728
2743
|
// - 对argument.expression.typeAnnotation 无需做修改,保持为其实际类型
|
|
2729
2744
|
// - 对argument.typeAnnotation,为根据对应Collection的泛型参数的类型填写其类型
|
|
2730
2745
|
// 先不动这里,有空再调整
|
|
2731
|
-
if (
|
|
2746
|
+
if (isCallFn) {
|
|
2732
2747
|
if (oldNd.calleeNamespace === 'nasl.util') {
|
|
2733
2748
|
const calleeName = oldNd.calleeName;
|
|
2734
2749
|
const listFunctionParamIndexMaps = new Map(Object.entries({
|
|
@@ -2784,44 +2799,56 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
2784
2799
|
}
|
|
2785
2800
|
}
|
|
2786
2801
|
if (!tyAnn) {
|
|
2802
|
+
const isCallItfc = oldNd.concept === 'CallInterface' ||
|
|
2803
|
+
oldNd.concept === 'CallAuthInterface' ||
|
|
2804
|
+
oldNd.concept === 'CallMicroserviceInterface' ||
|
|
2805
|
+
oldNd.concept === 'CallGatewayInterface';
|
|
2806
|
+
if (isCallType1 || isCallFn || isCallItfc) {
|
|
2807
|
+
newJson.typeAnnotation = nasl_language_server_core_1.naslVoidTy.toJSON();
|
|
2808
|
+
}
|
|
2787
2809
|
return newJson;
|
|
2788
2810
|
}
|
|
2789
|
-
if (oldNd.concept === 'CallQueryComponent' /* && !oldNd.isAutoInfer() 直接覆盖得了,老版的 typeAnnotation 问题有点多 */) {
|
|
2811
|
+
if (oldNd.concept === 'CallQueryComponent' /* && !oldNd.isAutoInfer() 直接覆盖得了,老版的 typeAnnotation 问题有点多 */) {
|
|
2790
2812
|
newJson.typeAnnotation = tyAnn;
|
|
2791
2813
|
// 新类型标注标的是对的,所以不再需要原来的改法(即,把 T 变为 { list:T, total: Long }
|
|
2792
2814
|
}
|
|
2793
2815
|
// 如果节点本身有类型就不去在塞一遍了
|
|
2794
2816
|
// 有值而且没有类型再去设置
|
|
2795
2817
|
// 但是Identifier 和 MemberExpression 都用标注出来的因为本身是变量,有类型也需要覆盖一下
|
|
2796
|
-
else if (tyAnn && (oldNd.concept === 'Argument') && oldNd.getAncestor('Connector')?.concept === 'Connector') {
|
|
2818
|
+
else if (tyAnn && (oldNd.concept === 'Argument') && oldNd.getAncestor('Connector')?.concept === 'Connector') {
|
|
2797
2819
|
newJson.typeAnnotation = tyAnn;
|
|
2798
2820
|
}
|
|
2799
2821
|
else if (oldNd.concept === 'Identifier' || oldNd.concept === 'MemberExpression') {
|
|
2800
2822
|
// @ts-ignore 处理 Match,还是需要,因为后端翻译比较特殊
|
|
2801
|
-
const iName = getNameOfIdAndMemExpr(newJson);
|
|
2823
|
+
const iName = getNameOfIdAndMemExpr(newJson);
|
|
2802
2824
|
newJson.typeAnnotation = matchExprTyAnnMap.has(iName) ? matchExprTyAnnMap.get(iName) : tyAnn;
|
|
2803
2825
|
}
|
|
2804
2826
|
else if ((oldNd.concept === 'NewComposite') &&
|
|
2805
|
-
(oldNd.typeAnnotation?.typeKind === 'anonymousStructure' || oldNd.typeAnnotation?.typeKind === 'generic')) {
|
|
2827
|
+
(oldNd.typeAnnotation?.typeKind === 'anonymousStructure' || oldNd.typeAnnotation?.typeKind === 'generic')) {
|
|
2806
2828
|
newJson.typeAnnotation = tyAnn;
|
|
2807
2829
|
}
|
|
2808
2830
|
// 服务端需要默认值节点有类型来判断父节点是否是日期类型
|
|
2809
2831
|
else if (newJson.concept === 'DefaultValue') {
|
|
2810
|
-
//
|
|
2832
|
+
// v3.14.x 先改成这样,应该直接拿就行
|
|
2811
2833
|
newJson.typeAnnotation = tyAnn;
|
|
2812
2834
|
}
|
|
2813
2835
|
// 定义上不挂类型
|
|
2814
|
-
else if ((!oldNd.typeAnnotation) && !nasl_language_server_core_1.ReferenceManager.defConcept.includes(oldNd.concept)) {
|
|
2836
|
+
else if ((!oldNd.typeAnnotation) && !nasl_language_server_core_1.ReferenceManager.defConcept.includes(oldNd.concept)) {
|
|
2815
2837
|
newJson.typeAnnotation = tyAnn;
|
|
2816
2838
|
}
|
|
2817
2839
|
return newJson;
|
|
2818
2840
|
};
|
|
2819
2841
|
const json = NaslServer_1.toRaw(naslNode)._toJSON(doWork, preWork, postWork);
|
|
2820
2842
|
this.logger.timeEnd('app to AnnotatedJSON');
|
|
2821
|
-
//
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2843
|
+
// 输出内存优化统计信息
|
|
2844
|
+
const stats = (0, memory_optimization_1.getOptimizationStats)();
|
|
2845
|
+
console.log('内存优化统计', {
|
|
2846
|
+
节点处理数量: stats.totalCalls,
|
|
2847
|
+
删除的属性: stats.propertiesRemoved,
|
|
2848
|
+
删除的空数组: stats.emptyArraysRemoved,
|
|
2849
|
+
删除的undefined值: stats.undefinedValuesRemoved,
|
|
2850
|
+
总优化项: stats.propertiesRemoved + stats.emptyArraysRemoved + stats.undefinedValuesRemoved
|
|
2851
|
+
});
|
|
2825
2852
|
return json;
|
|
2826
2853
|
}
|
|
2827
2854
|
/**
|
|
@@ -3271,7 +3298,6 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
3271
3298
|
this.logger.timeEnd('语言服务变更');
|
|
3272
3299
|
}
|
|
3273
3300
|
catch (e) {
|
|
3274
|
-
console.log('error', e);
|
|
3275
3301
|
console.error('error', e);
|
|
3276
3302
|
this.logger.info('no "naslServer:nodeChange" event received');
|
|
3277
3303
|
}
|
|
@@ -3326,7 +3352,7 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
3326
3352
|
this.typerErrRecords.length = 0;
|
|
3327
3353
|
this.oqlRemoveNodesTsPath.clear();
|
|
3328
3354
|
this.semEnv.allocatedVEQNames.forEach(n => {
|
|
3329
|
-
this.semEnv.refMgr.
|
|
3355
|
+
this.semEnv.refMgr.gQNameDefs.delete(n);
|
|
3330
3356
|
});
|
|
3331
3357
|
this.semEnv.allocatedVEQNames.length = 0;
|
|
3332
3358
|
this.originProxyTargetNodes.clear();
|
|
@@ -3449,26 +3475,6 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
3449
3475
|
}
|
|
3450
3476
|
}
|
|
3451
3477
|
}
|
|
3452
|
-
/**
|
|
3453
|
-
* 获取节点引用
|
|
3454
|
-
*
|
|
3455
|
-
* @param {SyntaxNode} node 查询的节点
|
|
3456
|
-
* @param {SyntaxNode} [fileNode] 节点所属的文件节点,外部输入可以省去计算
|
|
3457
|
-
*/
|
|
3458
|
-
getReferences(node, fileNode = (0, service_1.getFileNode)(node)) {
|
|
3459
|
-
const refList = this.semEnv.refMgr.getReferences(this.semEnv, node)
|
|
3460
|
-
.map((item) => ({ node: item, fileNode: (0, service_1.getFileNode)(item) })) // 我搞不定了,再说吧……
|
|
3461
|
-
.filter((item) => item.fileNode && !item.fileNode.nodePath.includes('[-1]'));
|
|
3462
|
-
const fileNodeRefList = this.semEnv.refMgr.getReferences(this.semEnv, fileNode)
|
|
3463
|
-
.map((item) => ({ node: item, fileNode: (0, service_1.getFileNode)(item) })) // 我搞不定了,再说吧……
|
|
3464
|
-
.filter((item) => item.fileNode && !item.fileNode.nodePath.includes('[-1]'));
|
|
3465
|
-
// 引用要包含自身
|
|
3466
|
-
refList.push({ node: node, fileNode });
|
|
3467
|
-
return [
|
|
3468
|
-
...refList,
|
|
3469
|
-
...fileNodeRefList,
|
|
3470
|
-
];
|
|
3471
|
-
}
|
|
3472
3478
|
/**
|
|
3473
3479
|
* 获取节点引用,不包括自己
|
|
3474
3480
|
*
|
|
@@ -3622,14 +3628,20 @@ let NaslServer = NaslServer_1 = class NaslServer {
|
|
|
3622
3628
|
uniqueViewLikes.forEach((viewLike) => {
|
|
3623
3629
|
// 删除时,这些节点可能已经不在了,先用个 ?.
|
|
3624
3630
|
viewLike?.getElementLogicRoot();
|
|
3631
|
+
viewLike.concept === 'View' && viewLike?.getSubLogics();
|
|
3625
3632
|
});
|
|
3626
3633
|
uniqueLogicLikes.forEach((ctxLogic) => {
|
|
3627
3634
|
ctxLogic?.getSubLogics();
|
|
3628
3635
|
});
|
|
3629
3636
|
uniqueProcessV2s.forEach((ctxProcessV2) => {
|
|
3630
3637
|
ctxProcessV2?.getVariablesRoot();
|
|
3638
|
+
ctxProcessV2?.getElementLogicRoot();
|
|
3639
|
+
ctxProcessV2?.getSubLogics();
|
|
3631
3640
|
});
|
|
3632
3641
|
}
|
|
3642
|
+
async getClient() {
|
|
3643
|
+
return (0, nasl_server_client_1.getNaslServerClient)(this);
|
|
3644
|
+
}
|
|
3633
3645
|
};
|
|
3634
3646
|
exports.NaslServer = NaslServer;
|
|
3635
3647
|
__decorate([
|