@lcap/nasl 1.0.0-alpha.13 → 1.0.0-alpha.16
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 +73 -25
- package/out/automate/engine/index.js.map +1 -1
- package/out/automate/engine/utils.js +7 -6
- package/out/automate/engine/utils.js.map +1 -1
- package/out/common/BaseNode.d.ts +5 -4
- package/out/common/BaseNode.js +48 -41
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/App__.d.ts +18 -1
- package/out/concepts/App__.js +64 -24
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Argument__.js +2 -2
- package/out/concepts/Argument__.js.map +1 -1
- package/out/concepts/Assignee__.d.ts +190 -0
- package/out/concepts/Assignee__.js +264 -0
- package/out/concepts/Assignee__.js.map +1 -0
- package/out/concepts/BinaryExpression__.js +6 -6
- package/out/concepts/BinaryExpression__.js.map +1 -1
- package/out/concepts/BindAttribute__.d.ts +19 -0
- package/out/concepts/BindAttribute__.js +36 -2
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.js +21 -1
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindEvent__.d.ts +1 -0
- package/out/concepts/BindEvent__.js +38 -14
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/CallFunction__.js +20 -7
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallInterface__.d.ts +11 -8
- package/out/concepts/CallInterface__.js +160 -23
- package/out/concepts/CallInterface__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +1 -0
- package/out/concepts/CallLogic__.js +17 -7
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +5 -1
- package/out/concepts/CallQueryComponent__.js +15 -11
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Comment__.js +6 -2
- package/out/concepts/Comment__.js.map +1 -1
- package/out/concepts/ConfigGroup__.js +1 -1
- package/out/concepts/ConfigGroup__.js.map +1 -1
- package/out/concepts/ConfigProperty__.js +1 -1
- package/out/concepts/ConfigProperty__.js.map +1 -1
- package/out/concepts/Configuration__.js +1 -1
- package/out/concepts/Configuration__.js.map +1 -1
- package/out/concepts/Destination__.d.ts +11 -0
- package/out/concepts/Destination__.js +59 -19
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/End__.js +10 -2
- package/out/concepts/End__.js.map +1 -1
- package/out/concepts/EntityProperty__.d.ts +7 -0
- package/out/concepts/EntityProperty__.js +60 -3
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +4 -1
- package/out/concepts/Entity__.js +29 -12
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Enum__.d.ts +4 -0
- package/out/concepts/Enum__.js +9 -6
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/Event__.js +1 -1
- package/out/concepts/Event__.js.map +1 -1
- package/out/concepts/ForEachStatement__.js +8 -12
- package/out/concepts/ForEachStatement__.js.map +1 -1
- package/out/concepts/Function__.js +5 -5
- package/out/concepts/Function__.js.map +1 -1
- package/out/concepts/Identifier__.js +26 -24
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/IfStatement__.js +2 -2
- package/out/concepts/IfStatement__.js.map +1 -1
- package/out/concepts/InterfaceParam__.d.ts +2 -0
- package/out/concepts/InterfaceParam__.js +41 -21
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/Interface__.d.ts +3 -0
- package/out/concepts/Interface__.js +105 -9
- package/out/concepts/Interface__.js.map +1 -1
- package/out/concepts/LogicItem__.d.ts +2 -1
- package/out/concepts/LogicItem__.js +14 -0
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +3 -0
- package/out/concepts/Logic__.js +57 -16
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.js +13 -6
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/Module__.d.ts +6 -0
- package/out/concepts/Module__.js +18 -8
- package/out/concepts/Module__.js.map +1 -1
- package/out/concepts/Namespace__.d.ts +4 -0
- package/out/concepts/Namespace__.js +23 -12
- package/out/concepts/Namespace__.js.map +1 -1
- package/out/concepts/Param__.d.ts +2 -1
- package/out/concepts/Param__.js +35 -22
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessComponent__.js +2 -2
- package/out/concepts/ProcessComponent__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +20 -18
- 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/Process__.d.ts +6 -1
- package/out/concepts/Process__.js +18 -14
- package/out/concepts/Process__.js.map +1 -1
- package/out/concepts/QueryAggregateExpression__.js +1 -1
- package/out/concepts/QueryAggregateExpression__.js.map +1 -1
- package/out/concepts/QueryFromExpression__.js +1 -1
- package/out/concepts/QueryFromExpression__.js.map +1 -1
- package/out/concepts/QueryJoinExpression__.js +2 -2
- package/out/concepts/QueryJoinExpression__.js.map +1 -1
- package/out/concepts/QuerySelectExpression__.js +1 -1
- package/out/concepts/QuerySelectExpression__.js.map +1 -1
- package/out/concepts/Return__.d.ts +1 -0
- package/out/concepts/Return__.js +38 -25
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/SqlQueryComponent__.js +1 -1
- package/out/concepts/SqlQueryComponent__.js.map +1 -1
- package/out/concepts/StringLiteral__.d.ts +1 -1
- package/out/concepts/StringLiteral__.js +2 -2
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.d.ts +5 -4
- package/out/concepts/StructureProperty__.js +54 -31
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/Structure__.d.ts +1 -0
- package/out/concepts/Structure__.js +18 -5
- package/out/concepts/Structure__.js.map +1 -1
- package/out/concepts/SwitchCase__.js +3 -3
- package/out/concepts/SwitchCase__.js.map +1 -1
- package/out/concepts/SwitchStatement__.js +1 -1
- package/out/concepts/SwitchStatement__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.d.ts +3 -5
- package/out/concepts/TypeAnnotation__.js +36 -14
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/UnaryExpression__.js +4 -2
- package/out/concepts/UnaryExpression__.js.map +1 -1
- package/out/concepts/ValidationRule__.d.ts +1 -0
- package/out/concepts/ValidationRule__.js +27 -1
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.d.ts +1 -0
- package/out/concepts/Variable__.js +38 -25
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewComponent__.js +5 -5
- package/out/concepts/ViewComponent__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +7 -1
- package/out/concepts/ViewElement__.js +154 -117
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +4 -0
- package/out/concepts/View__.js +38 -25
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/WhileStatement__.js +1 -1
- package/out/concepts/WhileStatement__.js.map +1 -1
- package/out/concepts/basics/stdlib/index.js +3 -1
- package/out/concepts/basics/stdlib/index.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.auth.d.ts +3 -0
- package/out/concepts/basics/stdlib/nasl.auth.js +30 -0
- package/out/concepts/basics/stdlib/nasl.auth.js.map +1 -0
- package/out/concepts/basics/stdlib/nasl.browser copy.d.ts +3 -0
- package/out/concepts/basics/stdlib/nasl.browser copy.js +70 -0
- package/out/concepts/basics/stdlib/nasl.browser copy.js.map +1 -0
- package/out/concepts/basics/stdlib/nasl.browser.js +6 -35
- package/out/concepts/basics/stdlib/nasl.browser.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.configuration.d.ts +3 -0
- package/out/concepts/basics/stdlib/nasl.configuration.js +25 -0
- package/out/concepts/basics/stdlib/nasl.configuration.js.map +1 -0
- package/out/concepts/basics/stdlib/nasl.util.js +49 -41
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.validation.js +26 -20
- package/out/concepts/basics/stdlib/nasl.validation.js.map +1 -1
- package/out/concepts/basics/types/coreTypeList.js +11 -11
- package/out/concepts/basics/types/coreTypeList.js.map +1 -1
- package/out/concepts/index__.d.ts +1 -0
- package/out/concepts/index__.js +1 -0
- package/out/concepts/index__.js.map +1 -1
- package/out/enums/KEYWORDS.js +1 -1
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/generator/genBundleFiles.d.ts +1 -0
- package/out/generator/genBundleFiles.js +122 -93
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/manager/diagnostic.d.ts +1 -1
- package/out/server/createUiTs.d.ts +1 -0
- package/out/server/createUiTs.js +19 -2
- package/out/server/createUiTs.js.map +1 -1
- package/out/server/entity2LogicNamespace.js +24 -9
- package/out/server/entity2LogicNamespace.js.map +1 -1
- package/out/server/getExtensionModules.js +2 -0
- package/out/server/getExtensionModules.js.map +1 -1
- package/out/server/getLogics.js +40 -56
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.d.ts +4 -0
- package/out/server/getMemberIdentifier.js +90 -48
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/getProcesses.d.ts +2 -2
- package/out/server/getProcesses.js +34 -11
- package/out/server/getProcesses.js.map +1 -1
- package/out/server/index.js +4 -0
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +11 -30
- package/out/server/naslServer.js +410 -199
- package/out/server/naslServer.js.map +1 -1
- package/out/server/process2LogicNamespace.d.ts +10 -0
- package/out/server/process2LogicNamespace.js +16 -0
- package/out/server/process2LogicNamespace.js.map +1 -1
- package/out/server/translator.d.ts +22 -3
- package/out/server/translator.js +336 -130
- package/out/server/translator.js.map +1 -1
- package/out/service/storage/init.js +29 -15
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genCreateBlock.js +5 -5
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +9 -13
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.js +7 -7
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genEditTableBlock.js +2 -2
- package/out/templator/genEditTableBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +4 -2
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.d.ts +1 -1
- package/out/templator/genGridViewBlock.js +3 -3
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genQueryComponent.d.ts +2 -0
- package/out/templator/genQueryComponent.js +1 -0
- package/out/templator/genQueryComponent.js.map +1 -1
- package/out/templator/genTableBlock.d.ts +1 -1
- package/out/templator/genTableBlock.js +3 -3
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +7 -7
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.d.ts +3 -1
- package/out/templator/utils.js +2 -1
- package/out/templator/utils.js.map +1 -1
- package/out/utils/index.d.ts +6 -0
- package/out/utils/index.js +20 -1
- package/out/utils/index.js.map +1 -1
- package/package.json +2 -1
- package/src/automate/engine/index.js +73 -25
- package/src/automate/engine/utils.js +7 -6
- package/src/common/BaseNode.ts +51 -42
- package/src/concepts/App__.ts +104 -26
- package/src/concepts/Argument__.ts +3 -2
- package/src/concepts/Assignee__.ts +437 -0
- package/src/concepts/BinaryExpression__.ts +7 -6
- package/src/concepts/BindAttribute__.ts +51 -2
- package/src/concepts/BindDirective__.ts +20 -1
- package/src/concepts/BindEvent__.ts +39 -16
- package/src/concepts/CallFunction__.ts +21 -8
- package/src/concepts/CallInterface__.ts +161 -42
- package/src/concepts/CallLogic__.ts +21 -9
- package/src/concepts/CallQueryComponent__.ts +15 -13
- package/src/concepts/Comment__.ts +6 -2
- package/src/concepts/ConfigGroup__.ts +1 -1
- package/src/concepts/ConfigProperty__.ts +1 -1
- package/src/concepts/Configuration__.ts +1 -1
- package/src/concepts/Destination__.ts +57 -19
- package/src/concepts/End__.ts +9 -11
- package/src/concepts/EntityProperty__.ts +56 -3
- package/src/concepts/Entity__.ts +33 -20
- package/src/concepts/Enum__.ts +8 -7
- package/src/concepts/Event__.ts +1 -1
- package/src/concepts/ForEachStatement__.ts +8 -13
- package/src/concepts/Function__.ts +5 -5
- package/src/concepts/Identifier__.ts +31 -26
- package/src/concepts/IfStatement__.ts +2 -2
- package/src/concepts/InterfaceParam__.ts +39 -20
- package/src/concepts/Interface__.ts +103 -9
- package/src/concepts/LogicItem__.ts +16 -1
- package/src/concepts/Logic__.ts +60 -18
- package/src/concepts/MemberExpression__.ts +18 -6
- package/src/concepts/Module__.ts +19 -8
- package/src/concepts/Namespace__.ts +24 -12
- package/src/concepts/Param__.ts +34 -23
- package/src/concepts/ProcessComponent__.ts +2 -2
- package/src/concepts/ProcessElement__.ts +51 -50
- package/src/concepts/ProcessOutcome__.ts +1 -1
- package/src/concepts/Process__.ts +32 -28
- package/src/concepts/QueryAggregateExpression__.ts +1 -1
- package/src/concepts/QueryFromExpression__.ts +1 -1
- package/src/concepts/QueryJoinExpression__.ts +2 -2
- package/src/concepts/QuerySelectExpression__.ts +1 -1
- package/src/concepts/Return__.ts +35 -25
- package/src/concepts/SqlQueryComponent__.ts +1 -1
- package/src/concepts/StringLiteral__.ts +2 -2
- package/src/concepts/StructureProperty__.ts +49 -29
- package/src/concepts/Structure__.ts +17 -5
- package/src/concepts/SwitchCase__.ts +3 -3
- package/src/concepts/SwitchStatement__.ts +1 -1
- package/src/concepts/TypeAnnotation__.ts +34 -12
- package/src/concepts/UnaryExpression__.ts +4 -2
- package/src/concepts/ValidationRule__.ts +24 -1
- package/src/concepts/Variable__.ts +35 -24
- package/src/concepts/ViewComponent__.ts +5 -5
- package/src/concepts/ViewElement__.ts +168 -113
- package/src/concepts/View__.ts +44 -25
- package/src/concepts/WhileStatement__.ts +1 -1
- package/src/concepts/basics/stdlib/index.ts +3 -1
- package/src/concepts/basics/stdlib/nasl.auth.ts +26 -0
- package/src/concepts/basics/stdlib/nasl.browser.ts +7 -41
- package/src/concepts/basics/stdlib/nasl.configuration.ts +21 -0
- package/src/concepts/basics/stdlib/nasl.util.ts +49 -41
- package/src/concepts/basics/stdlib/nasl.validation.ts +17 -11
- package/src/concepts/basics/types/coreTypeList.ts +11 -11
- package/src/concepts/index__.ts +1 -0
- package/src/enums/KEYWORDS.ts +1 -1
- package/src/generator/genBundleFiles.ts +131 -112
- package/src/manager/diagnostic.ts +1 -1
- package/src/server/createUiTs.ts +22 -4
- package/src/server/entity2LogicNamespace.ts +25 -9
- package/src/server/getExtensionModules.ts +2 -0
- package/src/server/getLogics.ts +42 -58
- package/src/server/getMemberIdentifier.ts +88 -46
- package/src/server/getProcesses.ts +32 -9
- package/src/server/index.ts +12 -1
- package/src/server/naslServer.ts +422 -215
- package/src/server/process2LogicNamespace.ts +17 -1
- package/src/server/translator.ts +392 -134
- package/src/service/storage/init.ts +27 -16
- package/src/templator/genCreateBlock.ts +5 -5
- package/src/templator/genCurdEditMultipleKeyBlock.ts +25 -26
- package/src/templator/genCurdMultipleKeyBlock.ts +7 -7
- package/src/templator/genEditTableBlock.ts +2 -2
- package/src/templator/genGetBlock.ts +5 -7
- package/src/templator/genGridViewBlock.ts +4 -7
- package/src/templator/genQueryComponent.ts +1 -0
- package/src/templator/genTableBlock.ts +4 -7
- package/src/templator/genUpdateBlock.ts +7 -8
- package/src/templator/utils.ts +2 -1
- package/src/utils/index.ts +19 -0
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { CallLogic, BindEvent, App, Namespace, Entity, BaseNode, Logic, Param, TypeAnnotation, Return, Process, ProcessElement } from '..';
|
|
2
2
|
import { genLaunchProcess, genUserTaskLogic } from './getProcesses';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 给调用逻辑用
|
|
6
|
+
* @param process
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
4
9
|
export function process2LogicNamespace(process: Process) {
|
|
5
10
|
const children: Array<Namespace> = [];
|
|
6
11
|
process.elements.forEach((e) => {
|
|
@@ -22,6 +27,7 @@ export function process2LogicNamespace(process: Process) {
|
|
|
22
27
|
}
|
|
23
28
|
children.push(ns);
|
|
24
29
|
ns.path = `app.processes.${process.name}.elements.${e.name}`;
|
|
30
|
+
ns.expanded = true;
|
|
25
31
|
}
|
|
26
32
|
});
|
|
27
33
|
const launchLogic = genLaunchProcess(process);
|
|
@@ -32,6 +38,9 @@ export function process2LogicNamespace(process: Process) {
|
|
|
32
38
|
});
|
|
33
39
|
ns.path = `app.processes.${process.name}.logics`;
|
|
34
40
|
const api = `/api/${process.name}/${launchLogic.name}`;
|
|
41
|
+
launchLogic.getNamespace = function() {
|
|
42
|
+
return ns.path;
|
|
43
|
+
}
|
|
35
44
|
launchLogic.getPath = function() {
|
|
36
45
|
return api;
|
|
37
46
|
}
|
|
@@ -50,7 +59,11 @@ interface processTreeFragment {
|
|
|
50
59
|
logics: Array<Logic>,
|
|
51
60
|
}>
|
|
52
61
|
}
|
|
53
|
-
|
|
62
|
+
/**
|
|
63
|
+
* 给侧边栏树形用
|
|
64
|
+
* @param process
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
54
67
|
export function processToTreeFragment(process: Process) {
|
|
55
68
|
const fragment: processTreeFragment = {
|
|
56
69
|
level: 'processTreeFragment',
|
|
@@ -66,6 +79,7 @@ export function processToTreeFragment(process: Process) {
|
|
|
66
79
|
l.params.forEach(p => {
|
|
67
80
|
p.readonly = true;
|
|
68
81
|
})
|
|
82
|
+
l.parentNode = process;
|
|
69
83
|
fragment.elements.push({
|
|
70
84
|
level: 'processTreeElementFragment',
|
|
71
85
|
id: e.id,
|
|
@@ -76,6 +90,8 @@ export function processToTreeFragment(process: Process) {
|
|
|
76
90
|
});
|
|
77
91
|
|
|
78
92
|
const launchLogic = genLaunchProcess(process);
|
|
93
|
+
launchLogic.parentNode = process;
|
|
94
|
+
|
|
79
95
|
fragment.logics.push(launchLogic);
|
|
80
96
|
launchLogic.parentKey = 'readonly'
|
|
81
97
|
return fragment;
|
package/src/server/translator.ts
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
import naslServer from './naslServer';
|
|
2
|
-
|
|
2
|
+
import {
|
|
3
|
+
Module,
|
|
4
|
+
BaseNode,
|
|
5
|
+
App,
|
|
6
|
+
Structure,
|
|
7
|
+
Logic,
|
|
8
|
+
Entity,
|
|
9
|
+
TypeAnnotation,
|
|
10
|
+
MemberExpression,
|
|
11
|
+
EntityProperty,
|
|
12
|
+
EntityIndex,
|
|
13
|
+
View,
|
|
14
|
+
Destination,
|
|
15
|
+
Enum,
|
|
16
|
+
BindEvent,
|
|
17
|
+
QueryFromExpression,
|
|
18
|
+
QueryJoinExpression,
|
|
19
|
+
QueryFieldExpression,
|
|
20
|
+
Identifier,
|
|
21
|
+
CallLogic,
|
|
22
|
+
EnumItem,
|
|
23
|
+
Param,
|
|
24
|
+
Process,
|
|
25
|
+
Interface,
|
|
26
|
+
Argument,
|
|
27
|
+
ViewElement,
|
|
28
|
+
BindAttribute,
|
|
29
|
+
Assignment,
|
|
30
|
+
CallQueryComponent,
|
|
31
|
+
Role,
|
|
32
|
+
Configuration,
|
|
33
|
+
CallInterface,
|
|
34
|
+
Return,
|
|
35
|
+
ProcessElement,
|
|
36
|
+
NullLiteral,
|
|
37
|
+
SwitchCase,
|
|
38
|
+
WhileStatement,
|
|
39
|
+
IfStatement,
|
|
40
|
+
UnaryExpression,
|
|
41
|
+
ForEachStatement,
|
|
42
|
+
CallFunction,
|
|
43
|
+
} from '../concepts';
|
|
44
|
+
import { SourceMapItem } from '../translator';
|
|
45
|
+
import { Diagnostic } from '../manager/diagnostic';
|
|
46
|
+
export interface MinRange {
|
|
47
|
+
node: BaseNode;
|
|
48
|
+
item: SourceMapItem;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function transformType(tsType: string): string {
|
|
3
52
|
if (tsType === 'string' || tsType === 'String')
|
|
4
53
|
return '字符串';
|
|
5
54
|
else if (tsType === 'number')
|
|
@@ -24,8 +73,12 @@ export function transformType(tsType: string): string {
|
|
|
24
73
|
return '枚举';
|
|
25
74
|
else if (tsType === 'views')
|
|
26
75
|
return '页面';
|
|
76
|
+
else if (tsType === 'void')
|
|
77
|
+
return '无返回值';
|
|
27
78
|
else if (tsType === '__elements')
|
|
28
79
|
return '页面元素';
|
|
80
|
+
else if (tsType === 'extensions')
|
|
81
|
+
return '拓展模块';
|
|
29
82
|
else if (tsType === 'Promise<void>')
|
|
30
83
|
return '未知类型';
|
|
31
84
|
else if (tsType.startsWith('{') && tsType.endsWith('}'))
|
|
@@ -39,154 +92,239 @@ export function transformType(tsType: string): string {
|
|
|
39
92
|
tsStr += index === 0 ? transformType(item) : ' | ' + transformType(item);
|
|
40
93
|
});
|
|
41
94
|
return tsStr;
|
|
95
|
+
} else if (tsType.includes(' & ')) {
|
|
96
|
+
const types = tsType.split(' & ');
|
|
97
|
+
let tsStr = '';
|
|
98
|
+
types.forEach((item, index) => {
|
|
99
|
+
tsStr += index === 0 ? transformType(item) : ' | ' + transformType(item);
|
|
100
|
+
});
|
|
101
|
+
return tsStr;
|
|
102
|
+
} else if (tsType.includes(' | ')) {
|
|
103
|
+
const types = tsType.split(' | ');
|
|
104
|
+
let tsStr = '';
|
|
105
|
+
types.forEach((item, index) => {
|
|
106
|
+
tsStr += index === 0 ? transformType(item) : ' | ' + transformType(item);
|
|
107
|
+
});
|
|
108
|
+
return tsStr;
|
|
42
109
|
} else {
|
|
43
110
|
return tsType;
|
|
44
111
|
}
|
|
45
112
|
}
|
|
46
113
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
114
|
+
const NAMESPACE_CONCEPT_MAP: Record<string, string> = {
|
|
115
|
+
entities: '实体',
|
|
116
|
+
structures: '数据结构',
|
|
117
|
+
enums: '枚举',
|
|
118
|
+
logics: '逻辑',
|
|
119
|
+
interfaces: '接口',
|
|
120
|
+
views: '页面',
|
|
121
|
+
elements: '元素',
|
|
122
|
+
processes: '流程',
|
|
123
|
+
roles: '角色',
|
|
124
|
+
extensions: '扩展模块',
|
|
125
|
+
apis: '接口应用',
|
|
126
|
+
components: '扩展组件',
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
function transformNamespace(tsNamespace: string): string {
|
|
130
|
+
for (const key in NAMESPACE_CONCEPT_MAP) {
|
|
131
|
+
const value = NAMESPACE_CONCEPT_MAP[key];
|
|
132
|
+
if (tsNamespace.endsWith(key))
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
return tsNamespace;
|
|
54
136
|
}
|
|
55
137
|
|
|
56
|
-
|
|
138
|
+
function transformMethod(tsMethod: string): string {
|
|
57
139
|
if (tsMethod === 'forEach')
|
|
58
140
|
return 'ForEach';
|
|
59
|
-
|
|
141
|
+
else
|
|
142
|
+
return tsMethod;
|
|
60
143
|
}
|
|
144
|
+
|
|
145
|
+
function transformIdentifier(identifier: string): string {
|
|
146
|
+
if (NAMESPACE_CONCEPT_MAP[identifier])
|
|
147
|
+
return NAMESPACE_CONCEPT_MAP[identifier];
|
|
148
|
+
else
|
|
149
|
+
return ` ${transformType(identifier)} 上的`;
|
|
150
|
+
}
|
|
151
|
+
|
|
61
152
|
export function outOriginalvalue(value: string) {
|
|
62
153
|
return value;
|
|
63
154
|
}
|
|
64
155
|
|
|
156
|
+
const TS_RULES: Array<{
|
|
157
|
+
re: RegExp;
|
|
158
|
+
result: string;
|
|
159
|
+
transforms?: Array<(str: string) => string>;
|
|
160
|
+
}> = [
|
|
161
|
+
{
|
|
162
|
+
re: /Type '(.+?)' is not assignable to type '(.+?)'/,
|
|
163
|
+
result: '左右参数类型不一致!左边类型:$2,右边类型:$1。',
|
|
164
|
+
transforms: [transformType, transformType],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
re: /Argument of type '(.+?)' is not assignable to parameter of type '(.+?)'/,
|
|
168
|
+
result: '参数类型不一致!传入类型:$1,接收类型:$2。',
|
|
169
|
+
transforms: [transformType, transformType],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
re: /Type '(.+?)' does not satisfy the constraint '(.+?)'/,
|
|
173
|
+
result: '参数类型不一致!传入类型:$1,接收类型:$2。',
|
|
174
|
+
transforms: [transformType, transformType],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
re: /This condition will always return '(.+?)' since the types '(.+?)' and '(.+?)' have no overlap/,
|
|
178
|
+
result: '左右参数类型不一致!左边类型:$2,右边类型:$3。',
|
|
179
|
+
transforms: [transformType, transformType, transformType],
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
re: /Type '(.+?)' is missing the following properties from type '(.+?)'/,
|
|
183
|
+
result: '类型不一致!左边类型:$2,右边类型:$1。',
|
|
184
|
+
transforms: [transformType, transformType],
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
re: /Property '(.+?)' is missing in type '(.+?)' but required in type '(.+?)'/,
|
|
188
|
+
result: '类型不一致!左边类型:$3,右边类型:$2。',
|
|
189
|
+
transforms: [outOriginalvalue, transformType, transformType],
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
re: /Expression expected/,
|
|
193
|
+
result: '表达式不能为空。',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
re: /Cannot find name '__(?:IDENTIFIER|LEFT|RIGHT)__'/,
|
|
197
|
+
result: '表达式不能为空。',
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
re: /Cannot find name '__(?:QueryFieldExpression)__'/,
|
|
201
|
+
result: '数据查询:实体字段不能为空。',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
re: /Cannot find name '__(?:WHERE_MULTIPLE_CONDITION)__'/,
|
|
205
|
+
result: '数据查询:筛选条件不能有多个表达式。',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
re: /Cannot find name '__(?:HAVING_MULTIPLE_CONDITION)__'/,
|
|
209
|
+
result: '数据查询:聚合属性过滤不能有多个表达式。',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
re: /Cannot find name '__(?:EMPTY_AGGREGATE_NAME)__'/,
|
|
213
|
+
result: '数据查询:聚合函数名称不能为空。',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
re: /Cannot find name '__(?:EMPTY_AGGREGATE_ALIAS)__'/,
|
|
217
|
+
result: '数据查询:聚合函数别名不能为空。',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
re: /No value exists in scope for the shorthand property '__(?:IDENTIFIER|LEFT|RIGHT)__'. Either declare one or provide an initializer./,
|
|
221
|
+
result: '用户任务未关联页面',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
re: /'(.+?)' is declared but its value is never read/,
|
|
225
|
+
result: "已添加'$1',但从来没有使用过。",
|
|
226
|
+
transforms: [transformType, transformType],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
re: /'(.+?)' has no exported member(?: named)? '(.+?)'/,
|
|
230
|
+
result: '找不到$1 $2。',
|
|
231
|
+
transforms: [transformNamespace, transformType],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
re: /Unreachable code detected\./,
|
|
235
|
+
result: '逻辑中有未使用的。',
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
re: /Property '__slice' does not exist on type '(.+?)'/,
|
|
239
|
+
result: 'For Each:循环列表:参数类型不匹配!所需类型:数组、集合等,提供类型:$1',
|
|
240
|
+
transforms: [transformType],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
re: /Property '(.+?)' does not exist on type 'typeof (.+?)'/,
|
|
244
|
+
result: '找不到$2 $1。',
|
|
245
|
+
transforms: [transformMethod, transformIdentifier],
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
re: /Property '(.+?)' does not exist on type '(.+?)'/,
|
|
249
|
+
result: '找不到$2 $1。',
|
|
250
|
+
transforms: [transformMethod, transformIdentifier],
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
re: /Cannot find name '(.+?)'. Did you mean '(.+?)'\?/,
|
|
254
|
+
result: '找不到 $1。',
|
|
255
|
+
transforms: [outOriginalvalue, outOriginalvalue],
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
re: /Expected (.+?) type arguments, but got (.+?)/,
|
|
259
|
+
result: '预期 $1 个类型参数,但传入了 $2 个。',
|
|
260
|
+
transforms: [outOriginalvalue, outOriginalvalue],
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
re: /Expected (.+?) arguments, but got (.+?)./,
|
|
264
|
+
result: '预期 $1 个参数,但传入了 $2 个。',
|
|
265
|
+
transforms: [outOriginalvalue, outOriginalvalue],
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
re: /The (.+?)-hand side of an arithmetic operation must be of type (.+?). type./,
|
|
269
|
+
result: '表达式错误!',
|
|
270
|
+
transforms: [outOriginalvalue, outOriginalvalue],
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
re: /Operator '(.+?)' cannot be applied to types '(.+?)' and '(.+?)'./,
|
|
274
|
+
result: '符号:$1 参数类型不匹配!所需类型:基础类型>$2,提供类型:$3。',
|
|
275
|
+
transforms: [outOriginalvalue, transformType, transformType],
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
re: /Object is possibly 'undefined'./,
|
|
279
|
+
result: '所选择的内容未定义。',
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
re: /Cannot find name '(.+?)'./,
|
|
283
|
+
result: '所选择的内容 $1 未定义。',
|
|
284
|
+
transforms: [outOriginalvalue],
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
re: /Duplicate identifier '(.+?)'./,
|
|
288
|
+
result: '当前内容中有重复的 $1,可能会影响使用。',
|
|
289
|
+
transforms: [outOriginalvalue],
|
|
290
|
+
},
|
|
291
|
+
];
|
|
292
|
+
|
|
293
|
+
const POST_RULES: Array<{
|
|
294
|
+
re: RegExp;
|
|
295
|
+
result: string;
|
|
296
|
+
transforms?: Array<(str: string) => string>;
|
|
297
|
+
}> = [
|
|
298
|
+
{
|
|
299
|
+
re: /__IDENTIFIER__/g,
|
|
300
|
+
result: 'undefined',
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
re: /Integer|"Integer"/g,
|
|
304
|
+
result: '整数',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
re: /Long|"Long"/g,
|
|
308
|
+
result: '长整数',
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
re: /Double|"Double"/g,
|
|
312
|
+
result: '小数',
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
re: /never/g,
|
|
316
|
+
result: '不接受任何类型',
|
|
317
|
+
},
|
|
318
|
+
];
|
|
319
|
+
Object.keys(NAMESPACE_CONCEPT_MAP).forEach((key) => {
|
|
320
|
+
POST_RULES.push({
|
|
321
|
+
re: new RegExp(key, 'g'),
|
|
322
|
+
result: NAMESPACE_CONCEPT_MAP[key],
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
65
326
|
export function translateDiagnosticMessage(message: string) {
|
|
66
|
-
const
|
|
67
|
-
re: RegExp;
|
|
68
|
-
result: string;
|
|
69
|
-
transforms?: Array<(str: string) => string>;
|
|
70
|
-
}> = [
|
|
71
|
-
{
|
|
72
|
-
re: /^Type '(.+?)' is not assignable to type '(.+?)'\./,
|
|
73
|
-
result: '左右参数类型不一致!左边类型:$2,右边类型:$1。',
|
|
74
|
-
transforms: [transformType, transformType],
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
re: /^Argument of type '(.+?)' is not assignable to parameter of type '(.+?)'\./,
|
|
78
|
-
result: '参数类型不一致!传入类型:$1,接收类型:$2。',
|
|
79
|
-
transforms: [transformType, transformType],
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
re: /^This condition will always return 'false' since the types '(.+?)' and '(.+?)' have no overlap\.$/,
|
|
83
|
-
result: '类型不一致!左边类型:$1,右边类型:$2。',
|
|
84
|
-
transforms: [transformType, transformType],
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
re: /^Type '(.+?)' is missing the following properties from type '(.+?)'/,
|
|
88
|
-
result: '类型不一致!左边类型:$2,右边类型:$1。',
|
|
89
|
-
transforms: [transformType, transformType],
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
re: /^Property '(.+?)' is missing in type '(.+?)' but required in type '(.+?)'./,
|
|
93
|
-
result: '类型不一致!左边类型:$3,右边类型:$2。',
|
|
94
|
-
transforms: [outOriginalvalue, transformType, transformType],
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
re: /^Expression expected\.$/,
|
|
98
|
-
result: '表达式不能为空。',
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
re: /^Cannot find name '__(?:IDENTIFIER|LEFT|RIGHT)__'\.$/,
|
|
102
|
-
result: '表达式不能为空。',
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
re: /^Cannot find name '__(?:QueryFieldExpression)__'\.$/,
|
|
106
|
-
result: '实体字段不能为空。',
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
re: /^Cannot find name '__(?:WHERE_MULTIPLE_CONDITION)__'\.$/,
|
|
110
|
-
result: '筛选条件不能有多个表达式。',
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
re: /^Cannot find name '__(?:HAVING_MULTIPLE_CONDITION)__'\.$/,
|
|
114
|
-
result: '聚合属性过滤不能有多个表达式。',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
re: /^Cannot find name '__(?:EMPTY_AGGREGATE_NAME)__'\.$/,
|
|
118
|
-
result: '聚合函数名称不能为空。',
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
re: /^Cannot find name '__(?:EMPTY_AGGREGATE_ALIAS)__'\.$/,
|
|
122
|
-
result: '聚合函数别名不能为空。',
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
re: /^'(.+?)' is declared but its value is never read\.$/,
|
|
126
|
-
result: "已添加'$1',但从来没有使用过。",
|
|
127
|
-
transforms: [transformType, transformType],
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
re: /'(.+?)' has no exported member(?: named)? '(.+?)'/,
|
|
131
|
-
result: "找不到数据结构 '$2'。",
|
|
132
|
-
transforms: [transformType, transformNamespace],
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
re: /^Unreachable code detected\.$/,
|
|
136
|
-
result: '逻辑中有未使用的。',
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
re: /Property '__slice' does not exist on type '(.+?)'./,
|
|
140
|
-
result: 'For Each:循环列表:参数类型不匹配!所需类型:基础类型>字符串、数组、集合等,提供类型:$1',
|
|
141
|
-
transforms: [transformType],
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
re: /Property '(.+?)' does not exist on type 'typeof logics'./,
|
|
145
|
-
result: '逻辑上找不到 $1 未找到。',
|
|
146
|
-
transforms: [outOriginalvalue],
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
re: /Property '(.+?)' does not exist on type 'typeof (.+?)'./,
|
|
150
|
-
result: '$2 上找不到 $1。',
|
|
151
|
-
transforms: [transformMethod, transformType],
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
re: /Property '(.+?)' does not exist on type '(.+?)'./,
|
|
155
|
-
result: '$2 上找不到 $1。',
|
|
156
|
-
transforms: [transformMethod, transformType],
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
re: /Cannot find name '(.+?)'. Did you mean '(.+?)'\?/,
|
|
160
|
-
result: '找不到 $1,您是想要 $2 吗?',
|
|
161
|
-
transforms: [outOriginalvalue, outOriginalvalue],
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
re: /Expected (.+?) arguments, but got (.+?)./,
|
|
165
|
-
result: '预期 $1 个参数,但传入了 $2 个。',
|
|
166
|
-
transforms: [outOriginalvalue, outOriginalvalue],
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
re: /The (.+?)-hand side of an arithmetic operation must be of type (.+?). type./,
|
|
170
|
-
result: '表达式错误!',
|
|
171
|
-
transforms: [outOriginalvalue, outOriginalvalue],
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
re: /Operator '(.+?)' cannot be applied to types '(.+?)' and '(.+?)'./,
|
|
175
|
-
result: '符号 $1 左右类型不匹配!左侧 $2,右侧 $3。',
|
|
176
|
-
transforms: [outOriginalvalue, transformType, transformType],
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
re: /Object is possibly 'undefined'./,
|
|
180
|
-
result: '所选择的内容未定义。',
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
re: /Cannot find name '(.+?)'./,
|
|
184
|
-
result: '所选择的内容 $1 未定义。',
|
|
185
|
-
transforms: [outOriginalvalue],
|
|
186
|
-
},
|
|
187
|
-
];
|
|
188
|
-
|
|
189
|
-
for (const rule of translateRules) {
|
|
327
|
+
for (const rule of TS_RULES) {
|
|
190
328
|
const cap = rule.re.exec(message);
|
|
191
329
|
if (cap) {
|
|
192
330
|
return rule.result.replace(/\$(\d+)/g, (m, index) => rule.transforms[index - 1](cap[index]));
|
|
@@ -194,3 +332,123 @@ export function translateDiagnosticMessage(message: string) {
|
|
|
194
332
|
}
|
|
195
333
|
return message;
|
|
196
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* 节点和ts 报错结合,转成更精准的ts报错
|
|
337
|
+
* @param minRange
|
|
338
|
+
* @param tsErrorDetail 报错具体信息
|
|
339
|
+
* @returns
|
|
340
|
+
*/
|
|
341
|
+
export function naslNodeTranslateMessage(minRange: MinRange, tsErrorDetail: Diagnostic) {
|
|
342
|
+
const text = tsErrorDetail.originalDiagnostic.text;
|
|
343
|
+
let node = minRange.node;
|
|
344
|
+
// 有一些节点报错信息不向外暴露,缺失一些原生标签等等的展示
|
|
345
|
+
if (node instanceof View || node instanceof ViewElement) {
|
|
346
|
+
if (text.startsWith(`'nasl.ui' has no exported member named `)) {
|
|
347
|
+
return null;
|
|
348
|
+
} else if (text.startsWith(`Property '`) && text.includes(`does not exist on type 'typeof ui'.`)) {
|
|
349
|
+
return null;
|
|
350
|
+
} else if (text.startsWith(`Namespace 'nasl.ui' has no exported member `)) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// 处理bindevent参数没传递的报错
|
|
355
|
+
if (/Expected (.+?) arguments, but got (.+?)./.exec(text)) {
|
|
356
|
+
// bindevent本身现在就不传参数
|
|
357
|
+
if (node instanceof BindEvent) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 因为缺少参数时候有可能有特殊情况,因为原本少的多了就会找到 callLogic上,
|
|
363
|
+
// 但是只少一个的时候就会找到准确的Argument上 需要特殊处理, ui层就可以统一处理
|
|
364
|
+
if (/Expected (.+?) arguments, but got (.+?)./.exec(text) && node.getAncestor('CallLogic')) {
|
|
365
|
+
node = node.getAncestor('CallLogic');
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (node instanceof Argument) {
|
|
369
|
+
// if (/Type '(.+?)' is not assignable to type '(.+?)'./.exec(text)) {
|
|
370
|
+
// }
|
|
371
|
+
// Argument在callInterface上的报错放到内部
|
|
372
|
+
if (node.expression) {
|
|
373
|
+
node = node.expression;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// 处理一些复制过来的内容 Identifier或者MemberExpression内容缺失,错误要像上冒
|
|
378
|
+
if (node instanceof Identifier || node instanceof MemberExpression) {
|
|
379
|
+
if (node.parentNode instanceof MemberExpression) {
|
|
380
|
+
let parentNode: BaseNode = node;
|
|
381
|
+
while (parentNode && parentNode.parentNode instanceof MemberExpression) {
|
|
382
|
+
parentNode = parentNode.parentNode;
|
|
383
|
+
}
|
|
384
|
+
node = parentNode || node;
|
|
385
|
+
|
|
386
|
+
let str = tsErrorDetail.message;
|
|
387
|
+
str = (node as any).constructor.nodeTitle + ':' + str;
|
|
388
|
+
tsErrorDetail.message = str;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// 类型报错的,需要放到上一级
|
|
393
|
+
if (/'(.+?)' has no exported member(?: named)? '(.+?)'/.exec(text) || /Property '(.+?)' does not exist on type '(.+?)'./.exec(text)) {
|
|
394
|
+
if (node instanceof TypeAnnotation) {
|
|
395
|
+
// 变量type的报错放到内部
|
|
396
|
+
node = node.parentNode;
|
|
397
|
+
let str = tsErrorDetail.message;
|
|
398
|
+
str = (node as any).constructor.nodeTitle + ':' + str;
|
|
399
|
+
tsErrorDetail.message = str;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* 所有问题的报错处理具体信息
|
|
405
|
+
*/
|
|
406
|
+
if (/^Cannot find name '__(?:IDENTIFIER|LEFT|RIGHT)__'\.$/.exec(text)) {
|
|
407
|
+
if (node instanceof IfStatement || node instanceof SwitchCase || node instanceof WhileStatement) {
|
|
408
|
+
tsErrorDetail.message = (node as any).constructor.nodeTitle + ':参数不能为空!所需类型:基础类型>布尔值';
|
|
409
|
+
} else if (node instanceof ForEachStatement) {
|
|
410
|
+
tsErrorDetail.message = 'For Each:结束值:不能为空!所需类型:基础类型>整数';
|
|
411
|
+
} else if (node instanceof UnaryExpression) {
|
|
412
|
+
tsErrorDetail.message = '!:参数不能为空!';
|
|
413
|
+
} else if (node instanceof Assignment) {
|
|
414
|
+
tsErrorDetail.message = '赋值:参数不能为空!';
|
|
415
|
+
} else if ((node instanceof Argument && node.parentNode instanceof CallInterface) || node instanceof CallInterface) {
|
|
416
|
+
tsErrorDetail.message = '调用接口:逻辑不能为空!';
|
|
417
|
+
} else if ((node instanceof Argument && node.parentNode instanceof CallFunction) || node instanceof CallFunction) {
|
|
418
|
+
tsErrorDetail.message = '调用函数:逻辑不能为空!';
|
|
419
|
+
} else if ((node instanceof Argument && node.parentNode instanceof CallLogic) || node instanceof CallLogic) {
|
|
420
|
+
tsErrorDetail.message = '调用逻辑:逻辑不能为空!';
|
|
421
|
+
} else if (node instanceof Identifier) {
|
|
422
|
+
// 根据父级内容推断当前缺少啥
|
|
423
|
+
const identifierToString = (node: Identifier) => {
|
|
424
|
+
let str = tsErrorDetail.message;
|
|
425
|
+
if (node.parentNode instanceof Assignment) {
|
|
426
|
+
str = '赋值:参数不能为空!';
|
|
427
|
+
} else if (node.parentNode instanceof Argument && node.parentNode.parentNode instanceof CallLogic) {
|
|
428
|
+
str = '调用逻辑:逻辑不能为空!';
|
|
429
|
+
} else {
|
|
430
|
+
str = (node.parentNode as any).constructor.nodeTitle + ':' + str;
|
|
431
|
+
tsErrorDetail.message = str;
|
|
432
|
+
}
|
|
433
|
+
return str;
|
|
434
|
+
};
|
|
435
|
+
tsErrorDetail.message = identifierToString(node);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
// 左右类型不一致的,把上级信息带上
|
|
439
|
+
if (/^Type '(.+?)' is not assignable to type '(.+?)'\./.exec(text) || /^This condition will always return '(.+?)' since the types '(.+?)' and '(.+?)' have no overlap./.exec(text)) {
|
|
440
|
+
let str = tsErrorDetail.message;
|
|
441
|
+
str = (node.parentNode as any).constructor.nodeTitle + ':' + str;
|
|
442
|
+
tsErrorDetail.message = str;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
for (const rule of POST_RULES) {
|
|
446
|
+
if (rule.re.test(tsErrorDetail.message))
|
|
447
|
+
tsErrorDetail.message = tsErrorDetail.message.replace(rule.re, rule.result);
|
|
448
|
+
}
|
|
449
|
+
node.tsErrorDetail = tsErrorDetail;
|
|
450
|
+
return {
|
|
451
|
+
node,
|
|
452
|
+
...tsErrorDetail,
|
|
453
|
+
};
|
|
454
|
+
}
|