@lcap/nasl 2.20.0-beta.3 → 2.20.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/automate/engine/index.d.ts +1 -1
- package/out/automate/engine/index.js +2 -3
- package/out/automate/engine/index.js.map +1 -1
- package/out/automate/engine/uniqueName.d.ts +1 -1
- package/out/automate/engine/uniqueName.js +2 -2
- package/out/automate/engine/uniqueName.js.map +1 -1
- package/out/automate/engine/utils.js +4 -1
- package/out/automate/engine/utils.js.map +1 -1
- package/out/automate/template/myProcess.d.ts +1 -1
- package/out/automate/template/myProcess.js +2 -2
- package/out/automate/template/myProcess.js.map +1 -1
- package/out/bak/translator.js +14 -22
- package/out/bak/translator.js.map +1 -1
- package/out/common/BaseNode.js +4 -1
- package/out/common/BaseNode.js.map +1 -1
- package/out/common/Command.d.ts +1 -0
- package/out/common/Command.js +5 -1
- package/out/common/Command.js.map +1 -1
- package/out/concepts/App__.d.ts +4 -0
- package/out/concepts/App__.js +30 -6
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Assignee__.js +4 -3
- package/out/concepts/Assignee__.js.map +1 -1
- package/out/concepts/BatchAssignment__.js +3 -3
- package/out/concepts/BatchAssignment__.js.map +1 -1
- package/out/concepts/BindAttribute__.d.ts +7 -0
- package/out/concepts/BindAttribute__.js +271 -39
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.d.ts +7 -0
- package/out/concepts/BindDirective__.js +215 -16
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindStyle__.d.ts +7 -0
- package/out/concepts/BindStyle__.js +192 -2
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/CallFunction__.js +22 -8
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallInterface__.js +3 -2
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +3 -0
- package/out/concepts/CallLogic__.js +78 -89
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.js +20 -3
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/ConfigGroup__.d.ts +1 -0
- package/out/concepts/ConfigGroup__.js +13 -0
- package/out/concepts/ConfigGroup__.js.map +1 -1
- package/out/concepts/ConfigProperty__.d.ts +19 -0
- package/out/concepts/ConfigProperty__.js +63 -0
- package/out/concepts/ConfigProperty__.js.map +1 -1
- package/out/concepts/Configuration__.d.ts +1 -0
- package/out/concepts/Configuration__.js +13 -0
- package/out/concepts/Configuration__.js.map +1 -1
- package/out/concepts/DataSource__.js +11 -3
- package/out/concepts/DataSource__.js.map +1 -1
- package/out/concepts/Destination__.d.ts +1 -0
- package/out/concepts/Destination__.js +61 -7
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +9 -1
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/EnumItem__.d.ts +5 -5
- package/out/concepts/EnumItem__.js +6 -6
- package/out/concepts/Enum__.d.ts +20 -19
- package/out/concepts/Enum__.js +28 -1
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/ExternalDestination__.d.ts +1 -0
- package/out/concepts/ExternalDestination__.js +22 -4
- package/out/concepts/ExternalDestination__.js.map +1 -1
- package/out/concepts/ForEachStatement__.js +2 -0
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/Frontend__.d.ts +2 -1
- package/out/concepts/Frontend__.js.map +1 -1
- package/out/concepts/Identifier__.js +16 -5
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/InterfaceParam__.js +9 -1
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/JSBlock__.js +5 -1
- package/out/concepts/JSBlock__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +79 -79
- package/out/concepts/Logic__.js +30 -8
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/Match__.d.ts +2 -2
- package/out/concepts/Match__.js +29 -13
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.js +9 -0
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/Module__.d.ts +16 -0
- package/out/concepts/Module__.js +43 -0
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/NewComposite__.d.ts +3 -4
- package/out/concepts/NewComposite__.js +99 -116
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/NewList__.d.ts +1 -0
- package/out/concepts/NewList__.js +22 -2
- package/out/concepts/NewList__.js.map +1 -1
- package/out/concepts/NewMap__.d.ts +1 -0
- package/out/concepts/NewMap__.js +43 -11
- package/out/concepts/NewMap__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js +40 -12
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/Param__.js +10 -2
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +2 -1
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/ProcessOutcome__.js +1 -1
- package/out/concepts/ProcessOutcome__.js.map +1 -1
- package/out/concepts/ProcessOutcomes__.js +1 -1
- package/out/concepts/ProcessOutcomes__.js.map +1 -1
- package/out/concepts/Process__.js +1 -0
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/Return__.js +13 -2
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StringInterpolation__.js +14 -2
- package/out/concepts/StringInterpolation__.js.map +1 -1
- package/out/concepts/StringLiteral__.js +6 -6
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.js +9 -1
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.d.ts +6 -3
- package/out/concepts/TypeAnnotation__.js +67 -13
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/ValidationRule__.d.ts +1 -0
- package/out/concepts/ValidationRule__.js +53 -0
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.js +12 -1
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +1 -0
- package/out/concepts/ViewElement__.js +24 -1
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +1 -3
- package/out/concepts/View__.js +33 -12
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.collection.js +6 -1
- package/out/concepts/basics/stdlib/nasl.collection.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.configuration.js +3 -0
- package/out/concepts/basics/stdlib/nasl.configuration.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.core.d.ts +2 -0
- package/out/concepts/basics/stdlib/nasl.core.js +34 -0
- package/out/concepts/basics/stdlib/nasl.core.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +4 -2
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/basics/types/index.d.ts +1 -0
- package/out/concepts/basics/types/index.js +3 -1
- package/out/concepts/basics/types/index.js.map +1 -1
- package/out/concepts/index__.d.ts +0 -1
- package/out/concepts/index__.js +0 -1
- package/out/concepts/index__.js.map +1 -1
- package/out/enums/KEYWORDS.js +8 -0
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/generator/genBundleFiles.js +24 -5
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genReleaseBody.d.ts +3 -3
- package/out/generator/genReleaseBody.js +98 -23
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/generator/permission.d.ts +3 -10
- package/out/generator/permission.js +43 -21
- package/out/generator/permission.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/out/server/entity2LogicNamespace.js +2 -20
- package/out/server/entity2LogicNamespace.js.map +1 -1
- package/out/server/extendBaseNode.js +16 -5
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/formatTsUtils.d.ts +2 -1
- package/out/server/formatTsUtils.js +40 -10
- package/out/server/formatTsUtils.js.map +1 -1
- package/out/server/getLogics.d.ts +2 -2
- package/out/server/getLogics.js +3 -3
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.d.ts +1 -0
- package/out/server/getMemberIdentifier.js +27 -1
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/index.js +1 -0
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +7 -1
- package/out/server/naslServer.js +558 -62
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +109 -33
- package/out/server/translator.js.map +1 -1
- package/out/service/storage/init.js +22 -2
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genCreateBlock.js +1 -3
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +1 -3
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +2 -4
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +1 -1
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.js +2 -2
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genListViewBlock.js +7 -1
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genSelectBlock.js +1 -1
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genTableBlock.js +2 -2
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +2 -3
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/translator/index.js +4 -1
- package/out/translator/index.js.map +1 -1
- package/out/utils/traverse.js +8 -2
- package/out/utils/traverse.js.map +1 -1
- package/package.json +2 -2
- package/sandbox/stdlib/dist/nasl.logging.js +0 -0
- package/sandbox/stdlib/dist/nasl.util.js +0 -0
- package/sandbox/stdlib/nasl.collection.ts +1 -0
- package/sandbox/stdlib/nasl.core.ts +34 -0
- package/sandbox/stdlib/nasl.oql.ts +71 -15
- package/sandbox/stdlib/nasl.util.ts +9 -3
- package/src/automate/engine/dist/index.dev.js +517 -0
- package/src/automate/engine/index.js +2 -3
- package/src/automate/engine/uniqueName.js +2 -2
- package/src/automate/engine/utils.js +4 -2
- package/src/automate/template/myProcess.js +2 -2
- package/src/bak/translator.js +16 -25
- package/src/common/BaseNode.ts +3 -1
- package/src/common/Command.ts +4 -0
- package/src/common/dist/BaseNode.js +1101 -0
- package/src/concepts/App__.ts +36 -7
- package/src/concepts/Assignee__.ts +4 -3
- package/src/concepts/BatchAssignment__.ts +3 -3
- package/src/concepts/BindAttribute__.ts +301 -38
- package/src/concepts/BindDirective__.ts +205 -30
- package/src/concepts/BindStyle__.ts +188 -24
- package/src/concepts/CallFunction__.ts +55 -10
- package/src/concepts/CallInterface__.ts +3 -2
- package/src/concepts/CallLogic__.ts +110 -90
- package/src/concepts/CallQueryComponent__.ts +18 -3
- package/src/concepts/ConfigGroup__.ts +17 -4
- package/src/concepts/ConfigProperty__.ts +72 -4
- package/src/concepts/Configuration__.ts +14 -5
- package/src/concepts/DataSource__.ts +10 -3
- package/src/concepts/Destination__.ts +61 -7
- package/src/concepts/EntityProperty__.ts +7 -1
- package/src/concepts/EnumItem__.ts +6 -6
- package/src/concepts/Enum__.ts +22 -19
- package/src/concepts/ExternalDestination__.ts +29 -9
- package/src/concepts/ForEachStatement__.ts +2 -0
- package/src/concepts/Frontend__.ts +2 -1
- package/src/concepts/Identifier__.ts +16 -5
- package/src/concepts/InterfaceParam__.ts +7 -1
- package/src/concepts/JSBlock__.ts +3 -2
- package/src/concepts/Logic__.ts +110 -89
- package/src/concepts/Match__.ts +53 -14
- package/src/concepts/MemberExpression__.ts +6 -0
- package/src/concepts/Module__.ts +57 -0
- package/src/concepts/NewComposite__.ts +104 -131
- package/src/concepts/NewList__.ts +23 -2
- package/src/concepts/NewMap__.ts +48 -24
- package/src/concepts/OqlQueryComponent__.ts +40 -20
- package/src/concepts/Param__.ts +178 -176
- package/src/concepts/ProcessElement__.ts +2 -1
- package/src/concepts/ProcessOutcome__.ts +1 -1
- package/src/concepts/ProcessOutcomes__.ts +1 -1
- package/src/concepts/Process__.ts +1 -0
- package/src/concepts/Return__.ts +10 -2
- package/src/concepts/StringInterpolation__.ts +19 -7
- package/src/concepts/StringLiteral__.ts +7 -6
- package/src/concepts/StructureProperty__.ts +7 -1
- package/src/concepts/TypeAnnotation__.ts +102 -15
- package/src/concepts/ValidationRule__.ts +58 -9
- package/src/concepts/Variable__.ts +13 -1
- package/src/concepts/ViewElement__.ts +47 -2
- package/src/concepts/View__.ts +39 -18
- package/src/concepts/basics/stdlib/dist/nasl.util.js +1602 -0
- package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
- package/src/concepts/basics/stdlib/nasl.collection.ts +6 -1
- package/src/concepts/basics/stdlib/nasl.configuration.ts +3 -0
- package/src/concepts/basics/stdlib/nasl.core.ts +33 -2
- package/src/concepts/basics/stdlib/nasl.util.ts +4 -2
- package/src/concepts/basics/types/index.ts +1 -0
- package/src/concepts/dist/BindAttribute__.js +795 -0
- package/src/concepts/dist/BindEvent__.js +732 -0
- package/src/concepts/dist/CallFunction__.js +527 -0
- package/src/concepts/dist/CallLogic__.js +932 -0
- package/src/concepts/dist/Destination__.js +708 -0
- package/src/concepts/dist/ExternalDestination__.js +298 -0
- package/src/concepts/dist/Identifier__.js +311 -0
- package/src/concepts/dist/StringInterpolation__.js +231 -0
- package/src/concepts/dist/TypeAnnotation__.js +834 -0
- package/src/concepts/dist/ViewElement__.js +1692 -0
- package/src/concepts/dist/View__.js +1601 -0
- package/src/concepts/index__.ts +0 -1
- package/src/enums/KEYWORDS.ts +8 -0
- package/src/generator/dist/genBundleFiles.js +261 -0
- package/src/generator/dist/genMetaData.js +245 -0
- package/src/generator/dist/permission.js +405 -0
- package/src/generator/genBundleFiles.ts +24 -5
- package/src/generator/genReleaseBody.ts +77 -31
- package/src/generator/permission.ts +47 -21
- package/src/index.ts +1 -1
- package/src/server/entity2LogicNamespace.ts +2 -20
- package/src/server/extendBaseNode.ts +15 -5
- package/src/server/formatTsUtils.ts +41 -10
- package/src/server/getLogics.ts +4 -4
- package/src/server/getMemberIdentifier.ts +27 -1
- package/src/server/index.ts +2 -0
- package/src/server/naslServer.ts +555 -63
- package/src/server/translator.ts +96 -34
- package/src/service/storage/dist/init.js +579 -0
- package/src/service/storage/init.ts +23 -3
- package/src/templator/dist/genEditTableBlock.js +204 -0
- package/src/templator/dist/genGridViewBlock.js +265 -0
- package/src/templator/dist/genListViewBlock.js +84 -0
- package/src/templator/dist/genTableBlock.js +209 -0
- package/src/templator/dist/utils.js +527 -0
- package/src/templator/genCreateBlock.ts +1 -3
- package/src/templator/genCurdEditMultipleKeyBlock.ts +1 -3
- package/src/templator/genCurdMultipleKeyBlock.ts +2 -4
- package/src/templator/genGetBlock.ts +1 -1
- package/src/templator/genGridViewBlock.ts +3 -4
- package/src/templator/genListViewBlock.ts +9 -3
- package/src/templator/genSelectBlock.ts +1 -1
- package/src/templator/genTableBlock.ts +3 -3
- package/src/templator/genUpdateBlock.ts +2 -3
- package/src/translator/index.ts +3 -1
- package/src/utils/traverse.ts +10 -2
- package/ts-worker/lib/tsserver.js +10 -2
- package/ts-worker/package.json +1 -0
- package/ts-worker/webpack.config.js +11 -2
- package/out/concepts/ConstructArgument__.d.ts +0 -40
- package/out/concepts/ConstructArgument__.js +0 -108
- package/out/concepts/ConstructArgument__.js.map +0 -1
- package/out/concepts/Construct__.d.ts +0 -189
- package/out/concepts/Construct__.js +0 -340
- package/out/concepts/Construct__.js.map +0 -1
- package/out/templator/sql-parser/index.d.ts +0 -1
- package/out/templator/sql-parser/index.js +0 -228
- package/out/templator/sql-parser/index.js.map +0 -1
- package/out/templator/sql-parser/parser.js +0 -26664
- package/out/templator/sql-parser/parser.js.map +0 -1
package/out/server/naslServer.js
CHANGED
|
@@ -44,14 +44,17 @@ const diagnostic_1 = require("../manager/diagnostic");
|
|
|
44
44
|
const createUiTs_1 = __importDefault(require("./createUiTs"));
|
|
45
45
|
const coreTypeList_1 = require("../concepts/basics/types/coreTypeList");
|
|
46
46
|
const formatTsUtils_1 = require("./formatTsUtils");
|
|
47
|
+
const utils = __importStar(require("../utils"));
|
|
47
48
|
const naslStdlibMap_1 = __importDefault(require("./naslStdlibMap"));
|
|
48
49
|
const jsoner = __importStar(require("../service/storage/jsoner"));
|
|
49
50
|
const EventEmitter_1 = require("../common/EventEmitter");
|
|
51
|
+
const utils_1 = require("../utils");
|
|
50
52
|
const EmbeddedTSFileLineMap = {
|
|
51
53
|
Entity: 3,
|
|
52
54
|
};
|
|
53
55
|
const EmbeddedTSFileOffsetMap = {
|
|
54
56
|
Variable: 12,
|
|
57
|
+
ConfigProperty: 12,
|
|
55
58
|
};
|
|
56
59
|
let isChangeInterface = false; //判断是否导入接口
|
|
57
60
|
let actionArr = []; //用于导入接口收集更改的节点
|
|
@@ -102,6 +105,8 @@ class NaslServer {
|
|
|
102
105
|
changeStackList = [];
|
|
103
106
|
filesToCheck;
|
|
104
107
|
singleFileChangeIng;
|
|
108
|
+
// 包含组件逻辑调用的逻辑map
|
|
109
|
+
logicSetWithComponentLogic = new Set();
|
|
105
110
|
constructor() {
|
|
106
111
|
/// #if process.env.BUILD_TARGET === 'node'
|
|
107
112
|
if (globalThis.process) // For TS build
|
|
@@ -110,6 +115,7 @@ class NaslServer {
|
|
|
110
115
|
/// #endif
|
|
111
116
|
/// #if process.env.BUILD_TARGET !== 'node'
|
|
112
117
|
if (globalThis.window) // For TS build
|
|
118
|
+
/* !!!如果改动这里需要看下关联的对应文件:webpack/ts-worker/loader.js */
|
|
113
119
|
this.worker = new worker_threads_1.Worker('/ts-worker.js');
|
|
114
120
|
/// #endif
|
|
115
121
|
// 要Check的文件
|
|
@@ -316,6 +322,21 @@ class NaslServer {
|
|
|
316
322
|
}
|
|
317
323
|
});
|
|
318
324
|
}
|
|
325
|
+
module.configuration?.groups?.forEach((_group) => {
|
|
326
|
+
if (_group.name === 'custom') {
|
|
327
|
+
_group.properties.forEach((_property) => {
|
|
328
|
+
try {
|
|
329
|
+
const result = _property.toEmbeddedTSFile();
|
|
330
|
+
results.push(result);
|
|
331
|
+
// sourceMap都存在目录级别内容下,在页面层级下去找
|
|
332
|
+
_property.sourceMap = result.sourceMap;
|
|
333
|
+
this.file2NodeMap.set(result.filePath, _property);
|
|
334
|
+
}
|
|
335
|
+
catch (err) {
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
});
|
|
319
340
|
}
|
|
320
341
|
view2TSFile(viewsChildren, results) {
|
|
321
342
|
// 如果有子页面
|
|
@@ -698,6 +719,14 @@ class NaslServer {
|
|
|
698
719
|
const records = await this.getDiagnosticRecords(fileNames);
|
|
699
720
|
// diagnosticManager.pushAll(records);
|
|
700
721
|
}
|
|
722
|
+
/**
|
|
723
|
+
* 节点异常是只能挂载单个,如果已经了就不赋值了
|
|
724
|
+
*/
|
|
725
|
+
baseNodeAssignmentTsError(node, tsErrorDetail) {
|
|
726
|
+
if (node.tsErrorDetail)
|
|
727
|
+
return;
|
|
728
|
+
node.tsErrorDetail = tsErrorDetail;
|
|
729
|
+
}
|
|
701
730
|
/**
|
|
702
731
|
* 处理诊断结果
|
|
703
732
|
* @param records 结果
|
|
@@ -751,6 +780,42 @@ class NaslServer {
|
|
|
751
780
|
.map((diag) => this._resolveDiagnostic(diag, node, record))
|
|
752
781
|
.filter((diag) => !!diag);
|
|
753
782
|
record.semanticDiagnostics.push(...this._attachDiagnostics(node));
|
|
783
|
+
// 报错降级逻辑
|
|
784
|
+
record.semanticDiagnostics = record.semanticDiagnostics
|
|
785
|
+
.map((diagnostic) => {
|
|
786
|
+
// 错误降级如果属于草稿态的就降级
|
|
787
|
+
if (diagnostic?.node) {
|
|
788
|
+
let currentNode = diagnostic.node;
|
|
789
|
+
while (currentNode?.parentNode?.concept !== 'App') {
|
|
790
|
+
if (currentNode.parentKey?.toLowerCase()?.includes('playground')) {
|
|
791
|
+
// 草稿区降级
|
|
792
|
+
// 重置 图标和错误等级
|
|
793
|
+
diagnostic.severity = 'warning';
|
|
794
|
+
if (diagnostic.node?.tsErrorDetail) {
|
|
795
|
+
// 重置组件节点上的错误信息
|
|
796
|
+
diagnostic.node.tsErrorDetail.severity = 'warning';
|
|
797
|
+
}
|
|
798
|
+
record.suggestionDiagnostics.push(diagnostic);
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
else if (currentNode.concept === 'OqlQueryComponent') {
|
|
802
|
+
// OQL别名错误降级为警告
|
|
803
|
+
if (diagnostic.originalDiagnostic && diagnostic.originalDiagnostic?.text.includes('__OQL_ALIAS_WARNING__')) {
|
|
804
|
+
// 重置 图标和错误等级
|
|
805
|
+
diagnostic.severity = 'warning';
|
|
806
|
+
if (diagnostic.node?.tsErrorDetail) {
|
|
807
|
+
// 重置组件节点上的错误信息
|
|
808
|
+
diagnostic.node.tsErrorDetail.severity = 'warning';
|
|
809
|
+
}
|
|
810
|
+
record.suggestionDiagnostics.push(diagnostic);
|
|
811
|
+
return null;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
currentNode = currentNode.parentNode;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return diagnostic;
|
|
818
|
+
}).filter((diag) => !!diag);
|
|
754
819
|
// 建议诊断
|
|
755
820
|
// 实体下的建议不用展示,因为都是平台自己写的逻辑
|
|
756
821
|
// if (node instanceof Entity) {
|
|
@@ -764,11 +829,51 @@ class NaslServer {
|
|
|
764
829
|
// // logic在for循环中,不展示any提示
|
|
765
830
|
// record.suggestionDiagnostics = record.suggestionDiagnostics.filter((item) => !item.text.includes(`implicitly has an 'any' type, but a better type may be inferred from usage.`));
|
|
766
831
|
// }
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
832
|
+
// 处理后的警告异常提示信息
|
|
833
|
+
record.suggestionDiagnostics = record.suggestionDiagnostics.map((diag) => {
|
|
834
|
+
// 上面错误降级下来的
|
|
835
|
+
if (diag?.node) {
|
|
836
|
+
return diag;
|
|
837
|
+
// 一些已知警告的单独处理
|
|
838
|
+
}
|
|
839
|
+
else if ([`'__LogicEmpty' is declared but its value is never read.`,
|
|
840
|
+
`'__destinationEmpty__' is declared but its value is never read.`,
|
|
841
|
+
`'__devConfigValueEmpty' is declared but its value is never read.`,
|
|
842
|
+
`'__onlineConfigValueEmpty' is declared but its value is never read.`,
|
|
843
|
+
`'__UpdateNoProperty__' is declared but its value is never read.`].includes(diag.text)) {
|
|
844
|
+
return this._resolveDiagnostic(diag, node, record);
|
|
845
|
+
}
|
|
846
|
+
else if ((diag.text).includes(` is declared but its value is never read.`)) {
|
|
847
|
+
// 局部变量和输入变量未使用的警告
|
|
848
|
+
if ((node.concept === 'View' || node.concept === 'Logic') && node.parentNode.concept !== 'Module') {
|
|
849
|
+
const minRange = this._findMinRange(diag, node);
|
|
850
|
+
if (minRange) {
|
|
851
|
+
/**
|
|
852
|
+
* 如果节点是入参类型
|
|
853
|
+
* 而且不是foreach中
|
|
854
|
+
* 而且不是事件逻辑的入参
|
|
855
|
+
*/
|
|
856
|
+
if (minRange.node instanceof concepts_1.Param && minRange.node.parentNode.concept !== 'ForEachStatement' && !minRange.node.getAncestor('BindEvent')) {
|
|
857
|
+
const diagnostic = {
|
|
858
|
+
node: minRange.node,
|
|
859
|
+
severity: 'warning',
|
|
860
|
+
message: `未使用的输入参数${minRange.node.name}`,
|
|
861
|
+
};
|
|
862
|
+
return diagnostic;
|
|
863
|
+
}
|
|
864
|
+
else if (minRange.node instanceof concepts_1.Variable) {
|
|
865
|
+
const diagnostic = {
|
|
866
|
+
node: minRange.node,
|
|
867
|
+
severity: 'warning',
|
|
868
|
+
message: `未使用的变量${minRange.node.name}`,
|
|
869
|
+
};
|
|
870
|
+
return diagnostic;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
}).filter((diag) => !!diag);
|
|
772
877
|
record.suggestionDiagnostics.push(...this._attachSuggestionDiagnostics(node));
|
|
773
878
|
});
|
|
774
879
|
return records;
|
|
@@ -781,22 +886,6 @@ class NaslServer {
|
|
|
781
886
|
_attachSuggestionDiagnostics(fileNode) {
|
|
782
887
|
const diagnostics = [];
|
|
783
888
|
if (fileNode instanceof concepts_1.Logic || fileNode instanceof concepts_1.View) {
|
|
784
|
-
// 判断逻辑是否已经删除
|
|
785
|
-
if (fileNode instanceof concepts_1.Logic && fileNode.parentNode instanceof concepts_1.App && !fileNode.parentNode.logics.includes(fileNode))
|
|
786
|
-
return diagnostics;
|
|
787
|
-
// 判断页面是否已经删除
|
|
788
|
-
let removed = false;
|
|
789
|
-
let curNode = fileNode;
|
|
790
|
-
// 递归检查,防止从顶层页面开始删除影响子页面内容检查
|
|
791
|
-
while (curNode instanceof concepts_1.View && !removed) {
|
|
792
|
-
if (curNode.parentNode instanceof concepts_1.View && !curNode.parentNode.children.includes(curNode)
|
|
793
|
-
|| curNode.parentNode instanceof concepts_1.Frontend && !curNode.parentNode.views.includes(curNode)) {
|
|
794
|
-
removed = true;
|
|
795
|
-
}
|
|
796
|
-
curNode = curNode.parentNode;
|
|
797
|
-
}
|
|
798
|
-
if (removed)
|
|
799
|
-
return diagnostics;
|
|
800
889
|
fileNode?.sourceMap.forEach((value, node) => {
|
|
801
890
|
if (node instanceof concepts_1.Match) {
|
|
802
891
|
const { cases, expression } = node || {};
|
|
@@ -912,8 +1001,8 @@ class NaslServer {
|
|
|
912
1001
|
if (Array.isArray(body) && body.length) {
|
|
913
1002
|
const lastExpression = body[body.length - 1];
|
|
914
1003
|
diagnostic.node = lastExpression;
|
|
915
|
-
diagnostic.message =
|
|
916
|
-
lastExpression
|
|
1004
|
+
diagnostic.message = `匹配:该分支类型与多数类型不一致,将产生Union类型。当前类型:${typeAnnotation?.headTitle},多数类型:${maxTypeAnnotation?.headTitle}`;
|
|
1005
|
+
this.baseNodeAssignmentTsError(lastExpression, diagnostic);
|
|
917
1006
|
diagnostics.push(diagnostic);
|
|
918
1007
|
}
|
|
919
1008
|
});
|
|
@@ -921,31 +1010,232 @@ class NaslServer {
|
|
|
921
1010
|
}
|
|
922
1011
|
}
|
|
923
1012
|
}
|
|
1013
|
+
else if (node instanceof concepts_1.NewList && !node.typeAnnotation) {
|
|
1014
|
+
// 匿名函数返回值有可能是newList,需要过滤。代码来源:AnonymousFunction.__ts
|
|
1015
|
+
const grandParent = node.parentNode?.parentNode?.parentNode;
|
|
1016
|
+
if (grandParent instanceof concepts_1.CallLogic
|
|
1017
|
+
&& /dataSources\.[^.]+\.entities\.[^.]+\.logics/.test(grandParent.calleeNamespace)
|
|
1018
|
+
&& ['update', 'updateBy', 'createOrUpdate', 'batchUpdate'].includes(grandParent.calleeName)) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
const { items } = node || {};
|
|
1022
|
+
const typeAnnotationMap = {};
|
|
1023
|
+
// 最多数的类型
|
|
1024
|
+
let maxTypeAnnotationInfo = {
|
|
1025
|
+
typeAnnotation: null,
|
|
1026
|
+
count: 0,
|
|
1027
|
+
};
|
|
1028
|
+
if (Array.isArray(items)) {
|
|
1029
|
+
items.forEach((item) => {
|
|
1030
|
+
const typeAnnotation = item.__TypeAnnotation;
|
|
1031
|
+
// 仅处理有类型的情况,返回类型为void的情况由其他地方处理成报错
|
|
1032
|
+
if (typeAnnotation) {
|
|
1033
|
+
const sortedTypeKey = typeAnnotation.sortedTypeKey;
|
|
1034
|
+
if (!typeAnnotationMap[sortedTypeKey]) {
|
|
1035
|
+
typeAnnotationMap[sortedTypeKey] = {
|
|
1036
|
+
typeAnnotation,
|
|
1037
|
+
items: [],
|
|
1038
|
+
count: 0,
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
const typeAnnotationInfo = typeAnnotationMap[sortedTypeKey];
|
|
1042
|
+
typeAnnotationInfo.items.push(item);
|
|
1043
|
+
typeAnnotationInfo.count++;
|
|
1044
|
+
const { count } = typeAnnotationInfo;
|
|
1045
|
+
if (maxTypeAnnotationInfo.count < count) {
|
|
1046
|
+
maxTypeAnnotationInfo = {
|
|
1047
|
+
typeAnnotation,
|
|
1048
|
+
count,
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
const { typeAnnotation: maxTypeAnnotation, } = maxTypeAnnotationInfo;
|
|
1055
|
+
for (const sortedTypeKey in typeAnnotationMap) {
|
|
1056
|
+
const { typeAnnotation, items } = typeAnnotationMap[sortedTypeKey];
|
|
1057
|
+
if (maxTypeAnnotation?.sortedTypeKey !== typeAnnotation?.sortedTypeKey) {
|
|
1058
|
+
if (Array.isArray(items)) {
|
|
1059
|
+
items.forEach((item) => {
|
|
1060
|
+
const diagnostic = {
|
|
1061
|
+
node: item,
|
|
1062
|
+
severity: 'warning',
|
|
1063
|
+
message: `NewList期望的类型是${maxTypeAnnotation?.headTitle}`,
|
|
1064
|
+
};
|
|
1065
|
+
this.baseNodeAssignmentTsError(item, diagnostic);
|
|
1066
|
+
diagnostics.push(diagnostic);
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
else if (node instanceof concepts_1.NewMap && !node.typeAnnotation) {
|
|
1073
|
+
const { values } = node || {};
|
|
1074
|
+
const typeAnnotationMap = {};
|
|
1075
|
+
// 最多数的类型
|
|
1076
|
+
let maxTypeAnnotationInfo = {
|
|
1077
|
+
typeAnnotation: null,
|
|
1078
|
+
count: 0,
|
|
1079
|
+
};
|
|
1080
|
+
if (Array.isArray(values)) {
|
|
1081
|
+
values.forEach((value) => {
|
|
1082
|
+
if (!value)
|
|
1083
|
+
return;
|
|
1084
|
+
const typeAnnotation = value.__TypeAnnotation;
|
|
1085
|
+
// 仅处理有类型的情况,返回类型为void的情况由其他地方处理成报错
|
|
1086
|
+
if (typeAnnotation) {
|
|
1087
|
+
const sortedTypeKey = typeAnnotation.sortedTypeKey;
|
|
1088
|
+
if (!typeAnnotationMap[sortedTypeKey]) {
|
|
1089
|
+
typeAnnotationMap[sortedTypeKey] = {
|
|
1090
|
+
typeAnnotation,
|
|
1091
|
+
values: [],
|
|
1092
|
+
count: 0,
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
const typeAnnotationInfo = typeAnnotationMap[sortedTypeKey];
|
|
1096
|
+
typeAnnotationInfo.values.push(value);
|
|
1097
|
+
typeAnnotationInfo.count++;
|
|
1098
|
+
const { count } = typeAnnotationInfo;
|
|
1099
|
+
if (maxTypeAnnotationInfo.count < count) {
|
|
1100
|
+
maxTypeAnnotationInfo = {
|
|
1101
|
+
typeAnnotation,
|
|
1102
|
+
count,
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
const { typeAnnotation: maxTypeAnnotation, } = maxTypeAnnotationInfo;
|
|
1109
|
+
for (const sortedTypeKey in typeAnnotationMap) {
|
|
1110
|
+
const { typeAnnotation, values } = typeAnnotationMap[sortedTypeKey];
|
|
1111
|
+
if (maxTypeAnnotation?.sortedTypeKey !== typeAnnotation?.sortedTypeKey) {
|
|
1112
|
+
if (Array.isArray(values)) {
|
|
1113
|
+
values.forEach((value) => {
|
|
1114
|
+
const diagnostic = {
|
|
1115
|
+
node: value,
|
|
1116
|
+
severity: 'warning',
|
|
1117
|
+
message: `NewMap中values值所期望的类型是${maxTypeAnnotation?.headTitle}`,
|
|
1118
|
+
};
|
|
1119
|
+
this.baseNodeAssignmentTsError(value, diagnostic);
|
|
1120
|
+
diagnostics.push(diagnostic);
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
else if (node.concept === 'JSBlock') {
|
|
1127
|
+
// 初始js代码块先屏蔽掉
|
|
1128
|
+
if (node.code === `location.href = '/';`) {
|
|
1129
|
+
return null;
|
|
1130
|
+
}
|
|
1131
|
+
const diagnostic = {
|
|
1132
|
+
node,
|
|
1133
|
+
severity: 'warning',
|
|
1134
|
+
message: '不建议使用js代码块',
|
|
1135
|
+
};
|
|
1136
|
+
diagnostics.push(diagnostic);
|
|
1137
|
+
}
|
|
1138
|
+
else if (node.concept === 'Unparsed') {
|
|
1139
|
+
const diagnostic = {
|
|
1140
|
+
node,
|
|
1141
|
+
severity: 'warning',
|
|
1142
|
+
message: '不建议使用自定义表达式',
|
|
1143
|
+
};
|
|
1144
|
+
diagnostics.push(diagnostic);
|
|
1145
|
+
}
|
|
1146
|
+
else if (node instanceof concepts_1.CallQueryComponent) {
|
|
1147
|
+
// 可视化查询中不允许有复杂的数据结构
|
|
1148
|
+
const contentVariables = [];
|
|
1149
|
+
utils.traverse(({ node }) => {
|
|
1150
|
+
if (node?.parentNode?.concept !== 'MemberExpression') {
|
|
1151
|
+
if (node?.concept === 'MemberExpression') {
|
|
1152
|
+
contentVariables.push(node);
|
|
1153
|
+
}
|
|
1154
|
+
else if (node?.concept === 'Identifier') {
|
|
1155
|
+
// 因为要是父级是MemberExpression, 就放入了父级,子级就不需要了
|
|
1156
|
+
contentVariables.push(node);
|
|
1157
|
+
// QueryFromExpression QueryJoinExpression
|
|
1158
|
+
}
|
|
1159
|
+
else if (node?.concept === 'QueryFieldExpression' || node?.concept === 'QueryGroupByExpression') {
|
|
1160
|
+
contentVariables.push(node);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}, { node }, {
|
|
1164
|
+
mode: 'anyObject',
|
|
1165
|
+
excludedKeySet: new Set(['parentNode', '_events', 'globalDataMap', 'havingPlayground', 'wherePlayground']),
|
|
1166
|
+
});
|
|
1167
|
+
contentVariables?.forEach((variable) => {
|
|
1168
|
+
// 如果是复杂数据结构
|
|
1169
|
+
if (variable.__TypeAnnotation?.isComplexType()) {
|
|
1170
|
+
const diagnostic = {
|
|
1171
|
+
node,
|
|
1172
|
+
severity: 'warning',
|
|
1173
|
+
message: `数据查询中不可以使用复杂类型!当前类型:${variable.__TypeAnnotation?.typeChineseTitle}。`,
|
|
1174
|
+
};
|
|
1175
|
+
this.baseNodeAssignmentTsError(variable, diagnostic);
|
|
1176
|
+
diagnostics.push(diagnostic);
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
924
1180
|
});
|
|
925
1181
|
}
|
|
926
1182
|
return diagnostics;
|
|
927
1183
|
}
|
|
1184
|
+
// 是否包含组件逻辑
|
|
1185
|
+
hasComponentLogics(expression) {
|
|
1186
|
+
let flag = false;
|
|
1187
|
+
(0, utils_1.traverse)((current) => {
|
|
1188
|
+
const { node } = current || {};
|
|
1189
|
+
const { concept } = node || {};
|
|
1190
|
+
if (concept === 'CallLogic') {
|
|
1191
|
+
// 调用组件逻辑
|
|
1192
|
+
if (node.isComponentLogic) {
|
|
1193
|
+
flag = true;
|
|
1194
|
+
}
|
|
1195
|
+
else if (node.isViewLogic) { // 调用页面逻辑
|
|
1196
|
+
const logicNode = node.view?.logics?.find?.((viewLogic) => viewLogic.name === node.calleeName);
|
|
1197
|
+
if (logicNode) {
|
|
1198
|
+
if (this.logicSetWithComponentLogic.has(logicNode.nodePath)) {
|
|
1199
|
+
flag = true;
|
|
1200
|
+
}
|
|
1201
|
+
else {
|
|
1202
|
+
const logicItem = logicNode.body?.find?.((logicItem) => this.hasComponentLogics(logicItem));
|
|
1203
|
+
if (logicItem) {
|
|
1204
|
+
flag = true;
|
|
1205
|
+
this.logicSetWithComponentLogic.add(logicNode.nodePath);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}, {
|
|
1212
|
+
node: expression,
|
|
1213
|
+
}, {
|
|
1214
|
+
mode: 'anyObject',
|
|
1215
|
+
excludedKeySet: new Set([
|
|
1216
|
+
'parentNode',
|
|
1217
|
+
'sourceMap',
|
|
1218
|
+
'storageJSON',
|
|
1219
|
+
'tsErrorDetail',
|
|
1220
|
+
'NaslAnnotatedJSON',
|
|
1221
|
+
'calledFrom',
|
|
1222
|
+
'_events',
|
|
1223
|
+
'_collectingList',
|
|
1224
|
+
'_historyList',
|
|
1225
|
+
]),
|
|
1226
|
+
});
|
|
1227
|
+
return flag;
|
|
1228
|
+
}
|
|
928
1229
|
/**
|
|
929
1230
|
* 额外的诊断
|
|
930
1231
|
* @param fileNode 文件级别的节点
|
|
931
1232
|
* @returns 诊断结果
|
|
932
1233
|
*/
|
|
933
1234
|
_attachDiagnostics(fileNode) {
|
|
1235
|
+
// 每次诊断前先清空这个Set
|
|
1236
|
+
this.logicSetWithComponentLogic = new Set();
|
|
934
1237
|
const diagnostics = [];
|
|
935
1238
|
if (fileNode instanceof concepts_1.View) {
|
|
936
|
-
// 判断页面是否已经删除
|
|
937
|
-
let removed = false;
|
|
938
|
-
let curNode = fileNode;
|
|
939
|
-
// 递归检查,防止从顶层页面开始删除影响子页面内容检查
|
|
940
|
-
while (curNode instanceof concepts_1.View && !removed) {
|
|
941
|
-
if (curNode.parentNode instanceof concepts_1.View && !curNode.parentNode.children.includes(curNode)
|
|
942
|
-
|| curNode.parentNode instanceof concepts_1.Frontend && !curNode.parentNode.views.includes(curNode)) {
|
|
943
|
-
removed = true;
|
|
944
|
-
}
|
|
945
|
-
curNode = curNode.parentNode;
|
|
946
|
-
}
|
|
947
|
-
if (removed)
|
|
948
|
-
return diagnostics;
|
|
949
1239
|
fileNode?.sourceMap.forEach((value, node) => {
|
|
950
1240
|
if (node instanceof concepts_1.ViewElement && node.view === fileNode) {
|
|
951
1241
|
if (node.tag) {
|
|
@@ -990,7 +1280,13 @@ class NaslServer {
|
|
|
990
1280
|
if (node.logic && node.logic !== nodeIn.logic)
|
|
991
1281
|
return;
|
|
992
1282
|
// 跟变量无关的赋值过滤
|
|
993
|
-
|
|
1283
|
+
let jsCode = '';
|
|
1284
|
+
try {
|
|
1285
|
+
jsCode = nodeIn.toJS();
|
|
1286
|
+
}
|
|
1287
|
+
catch (err) {
|
|
1288
|
+
console.log(err);
|
|
1289
|
+
}
|
|
994
1290
|
if (!jsCode.includes(`${node.name} = `))
|
|
995
1291
|
return;
|
|
996
1292
|
// 页面局部变量
|
|
@@ -1027,7 +1323,7 @@ class NaslServer {
|
|
|
1027
1323
|
}
|
|
1028
1324
|
});
|
|
1029
1325
|
if (!msg)
|
|
1030
|
-
msg = '
|
|
1326
|
+
msg = '未设置类型或未赋值。直接赋值系统可以自动推断类型。';
|
|
1031
1327
|
const diagnostic = {
|
|
1032
1328
|
node,
|
|
1033
1329
|
severity: 'error',
|
|
@@ -1037,6 +1333,31 @@ class NaslServer {
|
|
|
1037
1333
|
diagnostics.push(diagnostic);
|
|
1038
1334
|
}
|
|
1039
1335
|
}
|
|
1336
|
+
else if (node instanceof concepts_1.BindAttribute || node instanceof concepts_1.BindDirective || node instanceof concepts_1.BindStyle) {
|
|
1337
|
+
if (Array.isArray(node.bindExpressions)) {
|
|
1338
|
+
const exp = node.bindExpressions.find((bindExpression) => this.hasComponentLogics(bindExpression));
|
|
1339
|
+
if (exp) {
|
|
1340
|
+
//const element: any = node.getAncestor('ViewElement');
|
|
1341
|
+
//const api = config.allNodesAPI[element?.tag];
|
|
1342
|
+
//const attr = api?.attrs?.find?.((attr) => {
|
|
1343
|
+
// return attr.name === node.name;
|
|
1344
|
+
//});
|
|
1345
|
+
const map = {
|
|
1346
|
+
BindAttribute: '属性',
|
|
1347
|
+
BindDirective: '指令',
|
|
1348
|
+
BindStyle: '样式属性',
|
|
1349
|
+
};
|
|
1350
|
+
//“${attr?.title || node.title || node.name}”
|
|
1351
|
+
const diagnostic = {
|
|
1352
|
+
node,
|
|
1353
|
+
severity: 'error',
|
|
1354
|
+
message: `${map[node.concept]}表达式不能绑定组件逻辑`,
|
|
1355
|
+
};
|
|
1356
|
+
node.tsErrorDetail = diagnostic;
|
|
1357
|
+
diagnostics.push(diagnostic);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1040
1361
|
else {
|
|
1041
1362
|
this.checkNodeError(node, diagnostics);
|
|
1042
1363
|
}
|
|
@@ -1107,9 +1428,6 @@ class NaslServer {
|
|
|
1107
1428
|
}
|
|
1108
1429
|
}
|
|
1109
1430
|
if (fileNode instanceof concepts_1.Logic) {
|
|
1110
|
-
// 判断逻辑是否已经删除
|
|
1111
|
-
if (fileNode.parentNode instanceof concepts_1.App && !fileNode.parentNode.logics.includes(fileNode))
|
|
1112
|
-
return diagnostics;
|
|
1113
1431
|
fileNode?.sourceMap.forEach((value, node) => {
|
|
1114
1432
|
//OQL支持返回复合类型数据了
|
|
1115
1433
|
// SqlQueryComponent内部返回值类型,如果是嵌套的就需要报错
|
|
@@ -1122,23 +1440,49 @@ class NaslServer {
|
|
|
1122
1440
|
// node.tsErrorDetail = diagnostic;
|
|
1123
1441
|
// diagnostics.push(diagnostic);
|
|
1124
1442
|
// }
|
|
1443
|
+
if (node instanceof concepts_1.OqlQueryComponent) {
|
|
1444
|
+
// 自动推导情况
|
|
1445
|
+
const typeAnnotation = (0, formatTsUtils_1.type2TypeAnnotation)(node.__nodeType);
|
|
1446
|
+
if (!node.typeAnnotation && typeAnnotation) {
|
|
1447
|
+
if (typeAnnotation.typeName === 'List' && typeAnnotation.typeKind === 'generic') {
|
|
1448
|
+
const typeArguments = typeAnnotation.typeArguments;
|
|
1449
|
+
if (typeArguments.length && typeArguments[0].isComplexType()) {
|
|
1450
|
+
const diagnostic = {
|
|
1451
|
+
node,
|
|
1452
|
+
severity: 'error',
|
|
1453
|
+
message: `SQL查询:返回类型不支持单个复杂类型 ${typeArguments[0].headTitle}。`,
|
|
1454
|
+
};
|
|
1455
|
+
node.tsErrorDetail = diagnostic;
|
|
1456
|
+
diagnostics.push(diagnostic);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1125
1461
|
if (node instanceof concepts_1.Return || node instanceof concepts_1.Variable) {
|
|
1126
1462
|
if (!node.typeAnnotation && !node.__TypeAnnotation) {
|
|
1127
1463
|
const nodeTypeName = node.concept === 'Return' ? '输出参数' : '局部变量';
|
|
1128
1464
|
let used = false;
|
|
1129
1465
|
fileNode?.sourceMap.forEach((valueIn, nodeIn) => {
|
|
1130
1466
|
if (!used && nodeIn
|
|
1131
|
-
&& (nodeIn instanceof concepts_1.BatchAssignment || (nodeIn instanceof concepts_1.Assignment && nodeIn.left?.name))
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1467
|
+
&& (nodeIn instanceof concepts_1.BatchAssignment || (nodeIn instanceof concepts_1.Assignment && nodeIn.left?.name))) {
|
|
1468
|
+
let jsCode = '';
|
|
1469
|
+
try {
|
|
1470
|
+
jsCode = nodeIn.toJS();
|
|
1471
|
+
}
|
|
1472
|
+
catch (err) {
|
|
1473
|
+
console.log(err);
|
|
1474
|
+
}
|
|
1475
|
+
if (jsCode.includes(`${node.name} = `)) {
|
|
1476
|
+
used = true;
|
|
1477
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1478
|
+
const diagnostic = {
|
|
1479
|
+
node: nodeIn,
|
|
1480
|
+
severity: 'error',
|
|
1481
|
+
message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
|
|
1482
|
+
};
|
|
1483
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
1484
|
+
diagnostics.push(diagnostic);
|
|
1485
|
+
}
|
|
1142
1486
|
}
|
|
1143
1487
|
}
|
|
1144
1488
|
});
|
|
@@ -1225,6 +1569,19 @@ class NaslServer {
|
|
|
1225
1569
|
}
|
|
1226
1570
|
});
|
|
1227
1571
|
}
|
|
1572
|
+
if (node instanceof concepts_1.MatchCase && node.getAncestor('Match')?.isExpression && node.body.length === 0) {
|
|
1573
|
+
// 如果不是其他就标红
|
|
1574
|
+
if ((node?.getIndexOfParent() !== (node.getAncestor('Match')?.cases?.length || 0) - 1)) {
|
|
1575
|
+
const diagnostic = {
|
|
1576
|
+
node,
|
|
1577
|
+
severity: 'error',
|
|
1578
|
+
message: '匹配分支:返回内容不能为空',
|
|
1579
|
+
titleTip: '返回内容不能为空',
|
|
1580
|
+
};
|
|
1581
|
+
node.tsErrorDetail = diagnostic;
|
|
1582
|
+
diagnostics.push(diagnostic);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1228
1585
|
// 如果节点是match的patterns 里的
|
|
1229
1586
|
if (node?.parentKey === 'patterns' && node.parentNode instanceof concepts_1.MatchCase) {
|
|
1230
1587
|
const matchNode = node.getAncestor('Match');
|
|
@@ -1300,11 +1657,58 @@ class NaslServer {
|
|
|
1300
1657
|
const diagnostic = {
|
|
1301
1658
|
node,
|
|
1302
1659
|
severity: 'error',
|
|
1303
|
-
message:
|
|
1660
|
+
message: `类型不匹配,传入类型:void`,
|
|
1304
1661
|
};
|
|
1305
1662
|
node.tsErrorDetail = diagnostic;
|
|
1306
1663
|
diagnostics.push(diagnostic);
|
|
1307
1664
|
}
|
|
1665
|
+
// newMap key或者value没填都要有报错
|
|
1666
|
+
if (node instanceof concepts_1.NewMap) {
|
|
1667
|
+
// 如果一项没有key 或者没有 value 就报错
|
|
1668
|
+
const findFlag = node.keys?.some((key, index) => !key || !node.values?.[index]);
|
|
1669
|
+
if (findFlag) {
|
|
1670
|
+
const diagnostic = {
|
|
1671
|
+
node,
|
|
1672
|
+
severity: 'error',
|
|
1673
|
+
message: `新建Map的key和value应该都必填`,
|
|
1674
|
+
};
|
|
1675
|
+
node.tsErrorDetail = diagnostic;
|
|
1676
|
+
diagnostics.push(diagnostic);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
// 赋值语句左右list 和 map等可以 必须都一样
|
|
1680
|
+
if (node instanceof concepts_1.Assignment && !node.tsErrorDetail) {
|
|
1681
|
+
const leftType = node.left?.__TypeAnnotation || {};
|
|
1682
|
+
const rightType = node.right?.__TypeAnnotation || {};
|
|
1683
|
+
// 如果左边节点是 泛型,而且 左边泛型的名字 和 右边一样, 而且是list 或者map 就强制报错
|
|
1684
|
+
// 而且右边原来没有报错
|
|
1685
|
+
if (leftType.typeKind === 'generic' && leftType.typeKind === rightType.typeKind && leftType.typeName === rightType.typeName && ['Map', 'List'].includes(leftType.typeName)) {
|
|
1686
|
+
if (!(node.right.tsErrorDetail) && leftType.sortedTypeKey !== rightType.sortedTypeKey) {
|
|
1687
|
+
const excludeList = [
|
|
1688
|
+
'nasl.collection.List<nasl.core.String>',
|
|
1689
|
+
'nasl.collection.List<nasl.core.Text>',
|
|
1690
|
+
'nasl.collection.List<nasl.core.Email>',
|
|
1691
|
+
'nasl.collection.Map<nasl.core.String, nasl.core.String>',
|
|
1692
|
+
'nasl.collection.Map<nasl.core.String, nasl.core.Text>',
|
|
1693
|
+
'nasl.collection.Map<nasl.core.String, nasl.core.Email>',
|
|
1694
|
+
];
|
|
1695
|
+
// 先特殊处理等 类型合并后就可以去掉了
|
|
1696
|
+
if (excludeList.includes(leftType.sortedTypeKey) && excludeList.includes(rightType.sortedTypeKey)) {
|
|
1697
|
+
return null;
|
|
1698
|
+
}
|
|
1699
|
+
else if (['nasl.collection.List<>'].includes(leftType.sortedTypeKey) || ['nasl.collection.List<>'].includes(rightType.sortedTypeKey)) {
|
|
1700
|
+
return null;
|
|
1701
|
+
}
|
|
1702
|
+
const diagnostic = {
|
|
1703
|
+
node: node.right,
|
|
1704
|
+
severity: 'error',
|
|
1705
|
+
message: `左右参数类型不一致!左边类型:${leftType.typeChineseTitle},右边类型:${rightType.typeChineseTitle}。`,
|
|
1706
|
+
};
|
|
1707
|
+
node.right.tsErrorDetail = diagnostic;
|
|
1708
|
+
diagnostics.push(diagnostic);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1308
1712
|
}
|
|
1309
1713
|
/* 接口导入查找 */
|
|
1310
1714
|
existStructureFix(semanticDiagnostics, node, that) {
|
|
@@ -1371,7 +1775,7 @@ class NaslServer {
|
|
|
1371
1775
|
*/
|
|
1372
1776
|
_resolveDiagnostic(diagnostic, fileNode, record) {
|
|
1373
1777
|
// 拓展模块中的翻译先过滤掉,因为有错用户也不能修改
|
|
1374
|
-
if (fileNode.module)
|
|
1778
|
+
if (fileNode.module && !(fileNode instanceof concepts_1.ConfigProperty))
|
|
1375
1779
|
return;
|
|
1376
1780
|
const minRange = this._findMinRange(diagnostic, fileNode);
|
|
1377
1781
|
const tsErrorDetail = {
|
|
@@ -1592,6 +1996,53 @@ class NaslServer {
|
|
|
1592
1996
|
refsList = [...methodRefs];
|
|
1593
1997
|
}
|
|
1594
1998
|
}
|
|
1999
|
+
if (node instanceof concepts_1.Process) {
|
|
2000
|
+
if (currentSource) {
|
|
2001
|
+
const code = currentSource.code;
|
|
2002
|
+
const prefix = '__ProcessIdentification__';
|
|
2003
|
+
let positions = [];
|
|
2004
|
+
let pos = code.indexOf(prefix);
|
|
2005
|
+
while (pos !== -1) {
|
|
2006
|
+
positions.push(pos);
|
|
2007
|
+
pos = code.indexOf(prefix, pos + prefix.length);
|
|
2008
|
+
}
|
|
2009
|
+
positions.shift();
|
|
2010
|
+
// 拿到标识下定义的const process = {...}
|
|
2011
|
+
positions = positions.map((position) => code.indexOf('const', position + prefix.length));
|
|
2012
|
+
const promises = positions.map((item) => this.references({
|
|
2013
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
2014
|
+
line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
|
|
2015
|
+
offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character + item),
|
|
2016
|
+
}));
|
|
2017
|
+
const results = await Promise.all(promises);
|
|
2018
|
+
results.forEach((constRefs) => {
|
|
2019
|
+
refsList = [...refsList, ...constRefs.refs];
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
if (node instanceof concepts_1.ProcessElement) {
|
|
2024
|
+
if (currentSource) {
|
|
2025
|
+
const code = currentSource.code;
|
|
2026
|
+
const prefix = '__ProcessIdentification__';
|
|
2027
|
+
let positions = [];
|
|
2028
|
+
let pos = code.indexOf(prefix);
|
|
2029
|
+
while (pos !== -1) {
|
|
2030
|
+
positions.push(pos);
|
|
2031
|
+
pos = code.indexOf(prefix, pos + prefix.length);
|
|
2032
|
+
}
|
|
2033
|
+
// 拿到标识下定义的const process = {...}
|
|
2034
|
+
positions = positions.map((position) => code.indexOf(`${node.name}:`, position + prefix.length));
|
|
2035
|
+
const promises = positions.map((item) => this.references({
|
|
2036
|
+
file: fileNode.getEmbeddedFilePath(),
|
|
2037
|
+
line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
|
|
2038
|
+
offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character + item),
|
|
2039
|
+
}));
|
|
2040
|
+
const results = await Promise.all(promises);
|
|
2041
|
+
results.forEach((constRefs) => {
|
|
2042
|
+
refsList = [...refsList, ...constRefs.refs];
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
1595
2046
|
// console.log(refsList, 'refsList');
|
|
1596
2047
|
return refsList;
|
|
1597
2048
|
}
|
|
@@ -2241,12 +2692,15 @@ class NaslServer {
|
|
|
2241
2692
|
// 如果没有sourceMap,就继续向上找 ,或者到module结束
|
|
2242
2693
|
// 如果 节点找到 app 或者module 停止 或者entity找到DataSource为止
|
|
2243
2694
|
// 如果当前节点是view就不要向上查找了
|
|
2695
|
+
// 配置参数的ConfigProperty也不需要向上找
|
|
2244
2696
|
while (!sourceMap
|
|
2245
2697
|
&& fileNode
|
|
2246
2698
|
&& !(fileNode.parentNode instanceof concepts_1.App)
|
|
2247
2699
|
&& !(fileNode.parentNode instanceof concepts_1.Module)
|
|
2248
2700
|
&& !(fileNode.parentNode instanceof concepts_1.DataSource)
|
|
2249
|
-
&& !(fileNode instanceof concepts_1.
|
|
2701
|
+
&& !(fileNode.parentNode instanceof concepts_1.Frontend)
|
|
2702
|
+
&& !(fileNode instanceof concepts_1.View)
|
|
2703
|
+
&& !(fileNode instanceof concepts_1.ConfigProperty)) {
|
|
2250
2704
|
fileNode = fileNode.parentNode;
|
|
2251
2705
|
sourceMap = fileNode?.sourceMap;
|
|
2252
2706
|
}
|
|
@@ -2334,7 +2788,7 @@ class NaslServer {
|
|
|
2334
2788
|
* @returns 不需要去查就可以返回类型的节点
|
|
2335
2789
|
*/
|
|
2336
2790
|
getCurrentNodeKnownTypeAnnotation(node) {
|
|
2337
|
-
if (node.concept === 'StringLiteral' || node.concept === 'BooleanLiteral' || node.concept === 'NullLiteral') {
|
|
2791
|
+
if (node.concept === 'StringLiteral' || node.concept === 'StringInterpolation' || node.concept === 'BooleanLiteral' || node.concept === 'NullLiteral') {
|
|
2338
2792
|
let type = 'String';
|
|
2339
2793
|
switch (node.concept) {
|
|
2340
2794
|
case 'NullLiteral':
|
|
@@ -2434,6 +2888,9 @@ class NaslServer {
|
|
|
2434
2888
|
'NewComposite',
|
|
2435
2889
|
'NewList',
|
|
2436
2890
|
'NewMap',
|
|
2891
|
+
'OqlQueryComponent',
|
|
2892
|
+
'QueryFieldExpression',
|
|
2893
|
+
'QueryGroupByExpression',
|
|
2437
2894
|
].includes(node.concept))
|
|
2438
2895
|
return;
|
|
2439
2896
|
// 要去ls那边获取的
|
|
@@ -2468,7 +2925,7 @@ class NaslServer {
|
|
|
2468
2925
|
}
|
|
2469
2926
|
fileDetail.offset = fileDetail.offset + indexOf;
|
|
2470
2927
|
}
|
|
2471
|
-
else if (node.concept === 'MemberExpression' || node.concept === 'Identifier') {
|
|
2928
|
+
else if (node.concept === 'MemberExpression' || node.concept === 'Identifier' || node.concept === 'QueryFieldExpression' || node.concept === 'QueryGroupByExpression') {
|
|
2472
2929
|
if (item.code.includes('.')) {
|
|
2473
2930
|
const codeArr = item.code?.split('.');
|
|
2474
2931
|
const lastLen = codeArr?.[codeArr.length - 1]?.length;
|
|
@@ -2479,7 +2936,12 @@ class NaslServer {
|
|
|
2479
2936
|
}
|
|
2480
2937
|
else if (node.concept === 'Match') {
|
|
2481
2938
|
// 去查return 后面的返回值,变成函数调用
|
|
2482
|
-
|
|
2939
|
+
if (item.code?.endsWith(';\n')) {
|
|
2940
|
+
fileDetail.line = item.range.end.line - 1;
|
|
2941
|
+
}
|
|
2942
|
+
else {
|
|
2943
|
+
fileDetail.line = item.range.end.line;
|
|
2944
|
+
}
|
|
2483
2945
|
const indexOf = item.code.indexOf('return __MatchExpressionFuntion');
|
|
2484
2946
|
let newCode = item.code.substring(0, indexOf);
|
|
2485
2947
|
newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
|
|
@@ -2492,6 +2954,9 @@ class NaslServer {
|
|
|
2492
2954
|
newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
|
|
2493
2955
|
fileDetail.offset = newCode.length + 'return '.length;
|
|
2494
2956
|
}
|
|
2957
|
+
else if (['OqlQueryComponent'].includes(node.concept)) {
|
|
2958
|
+
fileDetail.offset += 10;
|
|
2959
|
+
}
|
|
2495
2960
|
args.push(fileDetail);
|
|
2496
2961
|
});
|
|
2497
2962
|
console.time('请求');
|
|
@@ -2529,8 +2994,8 @@ class NaslServer {
|
|
|
2529
2994
|
// 直接从最后一项的返回值取,有就有没有就没有
|
|
2530
2995
|
if (node.body?.length) {
|
|
2531
2996
|
const last = node.body[node.body.length - 1];
|
|
2532
|
-
if (last
|
|
2533
|
-
types.set(node, last
|
|
2997
|
+
if (types.get(last)) {
|
|
2998
|
+
types.set(node, types.get(last));
|
|
2534
2999
|
}
|
|
2535
3000
|
}
|
|
2536
3001
|
}
|
|
@@ -2541,6 +3006,19 @@ class NaslServer {
|
|
|
2541
3006
|
// 因为node可能是经过处理的TypeAnnotation
|
|
2542
3007
|
node.__isCorrectTypeAnnotation = true;
|
|
2543
3008
|
if (value) {
|
|
3009
|
+
if (node instanceof concepts_1.OqlQueryComponent) {
|
|
3010
|
+
// 自动推导情况
|
|
3011
|
+
const typeAnnotation = value;
|
|
3012
|
+
if (!node.typeAnnotation && typeAnnotation) {
|
|
3013
|
+
if (typeAnnotation.typeName === 'List' && typeAnnotation.typeKind === 'generic') {
|
|
3014
|
+
const typeArguments = typeAnnotation.typeArguments;
|
|
3015
|
+
if (typeArguments.length && typeArguments[0].isComplexType()) {
|
|
3016
|
+
node.__TypeAnnotation = null;
|
|
3017
|
+
return;
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
2544
3022
|
if (value instanceof concepts_1.TypeAnnotation) {
|
|
2545
3023
|
node.__TypeAnnotation = Object.freeze(value);
|
|
2546
3024
|
}
|
|
@@ -2548,6 +3026,10 @@ class NaslServer {
|
|
|
2548
3026
|
node.__TypeAnnotation = Object.freeze(value.typeAnnotation);
|
|
2549
3027
|
}
|
|
2550
3028
|
}
|
|
3029
|
+
else {
|
|
3030
|
+
// 清空原来已经赋值上去的类型,可能原来有现在没有了
|
|
3031
|
+
node.__TypeAnnotation = null;
|
|
3032
|
+
}
|
|
2551
3033
|
}
|
|
2552
3034
|
catch (err) {
|
|
2553
3035
|
if (globalThis.window) {
|
|
@@ -2761,6 +3243,10 @@ class NaslServer {
|
|
|
2761
3243
|
jsonNode.typeAnnotation = value.toJSON();
|
|
2762
3244
|
}
|
|
2763
3245
|
}
|
|
3246
|
+
if (node instanceof concepts_1.NewComposite && node.typeAnnotation.typeKind === 'anonymousStructure') {
|
|
3247
|
+
const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
|
|
3248
|
+
jsonNode.typeAnnotation = value.toJSON();
|
|
3249
|
+
}
|
|
2764
3250
|
});
|
|
2765
3251
|
}
|
|
2766
3252
|
/**
|
|
@@ -2901,6 +3387,12 @@ class NaslServer {
|
|
|
2901
3387
|
// 如果是要删除的内容,就是当前的file节点,要关闭当前文件,就把内容置为空
|
|
2902
3388
|
if (fileNode === targetNode) {
|
|
2903
3389
|
outputFiles = [{ file: filePath, fileContent: '' }];
|
|
3390
|
+
// 去掉原来存储的当前节点的nasl内存的存储,和错误的存储
|
|
3391
|
+
// 已经删除的就不用在去check错误了
|
|
3392
|
+
// check就会去取类型啥的,没有必要
|
|
3393
|
+
this.diagnosticManager.deleteOwn(fileNode.id);
|
|
3394
|
+
// 删除文件同时删除ls存储nasl 的引用
|
|
3395
|
+
this.file2NodeMap.delete(filePath);
|
|
2904
3396
|
}
|
|
2905
3397
|
else {
|
|
2906
3398
|
// 如果是要删除logic一个小内容,要覆盖全部内容
|
|
@@ -2928,13 +3420,17 @@ class NaslServer {
|
|
|
2928
3420
|
line: EmbeddedTSFileLineMap[fileNode.concept] ?? 2,
|
|
2929
3421
|
offset: EmbeddedTSFileOffsetMap[fileNode.concept] ?? 6,
|
|
2930
3422
|
});
|
|
2931
|
-
|
|
3423
|
+
const files = new Set();
|
|
3424
|
+
newRefs.refs.forEach((ref) => {
|
|
3425
|
+
this.filesToCheck.add(ref.file);
|
|
3426
|
+
files.add(ref.file);
|
|
3427
|
+
});
|
|
2932
3428
|
// 唤起建立连接弹框
|
|
2933
3429
|
// 文件级别的建立连接采取提醒
|
|
2934
3430
|
if (action === 'create' && targetNode.__init) {
|
|
2935
3431
|
// 清除临时状态, 完成本次创建
|
|
2936
3432
|
delete targetNode.__init;
|
|
2937
|
-
if (fileNode === targetNode &&
|
|
3433
|
+
if (fileNode === targetNode && files.size > 1) {
|
|
2938
3434
|
const confirmParms = {
|
|
2939
3435
|
actionType: 'createEstablishConnection',
|
|
2940
3436
|
node: fileNode,
|