@lcap/nasl-language-server-core 3.14.0-rc.4 → 3.14.0-rc.6
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/README.md +85 -0
- package/out/checker.d.ts +1 -1
- package/out/checker.d.ts.map +1 -1
- package/out/checker.js +94 -18
- package/out/checker.js.map +1 -1
- package/out/index.d.ts +4 -2
- package/out/index.d.ts.map +1 -1
- package/out/index.js +6 -2
- package/out/index.js.map +1 -1
- package/out/module/graph.js +6 -6
- package/out/module/graph.js.map +1 -1
- package/out/module/module.d.ts.map +1 -1
- package/out/module/module.js +3 -6
- package/out/module/module.js.map +1 -1
- package/out/query/context-variable-query.d.ts +31 -0
- package/out/query/context-variable-query.d.ts.map +1 -0
- package/out/query/context-variable-query.js +105 -0
- package/out/query/context-variable-query.js.map +1 -0
- package/out/query/index.d.ts +2 -0
- package/out/query/index.d.ts.map +1 -0
- package/out/query/index.js +18 -0
- package/out/query/index.js.map +1 -0
- package/out/reference-manager/builtin-q-name.d.ts +2 -2
- package/out/reference-manager/builtin-q-name.d.ts.map +1 -1
- package/out/reference-manager/builtin-q-name.js +16 -12
- package/out/reference-manager/builtin-q-name.js.map +1 -1
- package/out/reference-manager/collect-q-name.d.ts +4 -4
- package/out/reference-manager/collect-q-name.d.ts.map +1 -1
- package/out/reference-manager/collect-q-name.js +39 -31
- package/out/reference-manager/collect-q-name.js.map +1 -1
- package/out/reference-manager/get-q-name.d.ts +0 -2
- package/out/reference-manager/get-q-name.d.ts.map +1 -1
- package/out/reference-manager/get-q-name.js +58 -57
- package/out/reference-manager/get-q-name.js.map +1 -1
- package/out/reference-manager/reference-manager.d.ts +33 -18
- package/out/reference-manager/reference-manager.d.ts.map +1 -1
- package/out/reference-manager/reference-manager.js +249 -157
- package/out/reference-manager/reference-manager.js.map +1 -1
- package/out/reference-manager/remove-q-name.d.ts +30 -29
- package/out/reference-manager/remove-q-name.d.ts.map +1 -1
- package/out/reference-manager/remove-q-name.js +72 -61
- package/out/reference-manager/remove-q-name.js.map +1 -1
- package/out/reference-manager/rename-q-name.d.ts +4 -2
- package/out/reference-manager/rename-q-name.d.ts.map +1 -1
- package/out/reference-manager/rename-q-name.js +45 -31
- package/out/reference-manager/rename-q-name.js.map +1 -1
- package/out/reference-manager/symbol-type.d.ts +7 -3
- package/out/reference-manager/symbol-type.d.ts.map +1 -1
- package/out/reference-manager/symbol-type.js +18 -11
- package/out/reference-manager/symbol-type.js.map +1 -1
- package/out/reference-manager/update-nasl-fragment.d.ts +2 -1
- package/out/reference-manager/update-nasl-fragment.d.ts.map +1 -1
- package/out/reference-manager/update-nasl-fragment.js +18 -9
- package/out/reference-manager/update-nasl-fragment.js.map +1 -1
- package/out/symbol/graph.js +2 -2
- package/out/symbol/graph.js.map +1 -1
- package/out/typer/collectGlobalDefs.d.ts +1 -1
- package/out/typer/collectGlobalDefs.d.ts.map +1 -1
- package/out/typer/collectGlobalDefs.js +2 -2
- package/out/typer/collectGlobalDefs.js.map +1 -1
- package/out/typer/component-def-manager/component-def-manager.d.ts +33 -5
- package/out/typer/component-def-manager/component-def-manager.d.ts.map +1 -1
- package/out/typer/component-def-manager/component-def-manager.js +101 -21
- package/out/typer/component-def-manager/component-def-manager.js.map +1 -1
- package/out/typer/component-def-manager/utils.d.ts.map +1 -1
- package/out/typer/component-def-manager/utils.js +44 -15
- package/out/typer/component-def-manager/utils.js.map +1 -1
- package/out/typer/dispatch-all.d.ts +2 -2
- package/out/typer/dispatch-all.d.ts.map +1 -1
- package/out/typer/dispatch-all.js +5 -9
- package/out/typer/dispatch-all.js.map +1 -1
- package/out/typer/dispatch-def.d.ts +1 -1
- package/out/typer/dispatch-def.d.ts.map +1 -1
- package/out/typer/dispatch-def.js +16 -11
- package/out/typer/dispatch-def.js.map +1 -1
- package/out/typer/dispatch-expr.d.ts +6 -3
- package/out/typer/dispatch-expr.d.ts.map +1 -1
- package/out/typer/dispatch-expr.js +300 -178
- package/out/typer/dispatch-expr.js.map +1 -1
- package/out/typer/dispatch-process.d.ts +0 -1
- package/out/typer/dispatch-process.d.ts.map +1 -1
- package/out/typer/dispatch-process.js +38 -18
- package/out/typer/dispatch-process.js.map +1 -1
- package/out/typer/dispatch-stmt.d.ts.map +1 -1
- package/out/typer/dispatch-stmt.js +25 -10
- package/out/typer/dispatch-stmt.js.map +1 -1
- package/out/typer/dispatch-view.d.ts +1 -1
- package/out/typer/dispatch-view.d.ts.map +1 -1
- package/out/typer/dispatch-view.js +224 -158
- package/out/typer/dispatch-view.js.map +1 -1
- package/out/typer/helper.d.ts +0 -2
- package/out/typer/helper.d.ts.map +1 -1
- package/out/typer/helper.js +4 -19
- package/out/typer/helper.js.map +1 -1
- package/out/typer/incremental-update.d.ts +21 -42
- package/out/typer/incremental-update.d.ts.map +1 -1
- package/out/typer/incremental-update.js +218 -295
- package/out/typer/incremental-update.js.map +1 -1
- package/out/typer/index.d.ts +3 -2
- package/out/typer/index.d.ts.map +1 -1
- package/out/typer/index.js +3 -2
- package/out/typer/index.js.map +1 -1
- package/out/typer/nasl-predicate.d.ts +1 -2
- package/out/typer/nasl-predicate.d.ts.map +1 -1
- package/out/typer/overload-helper.d.ts +12 -0
- package/out/typer/overload-helper.d.ts.map +1 -0
- package/out/typer/overload-helper.js +110 -0
- package/out/typer/overload-helper.js.map +1 -0
- package/out/typer/sem-diag.d.ts +4 -0
- package/out/typer/sem-diag.d.ts.map +1 -1
- package/out/typer/sem-diag.js +9 -1
- package/out/typer/sem-diag.js.map +1 -1
- package/out/typer/solver.d.ts +39 -26
- package/out/typer/solver.d.ts.map +1 -1
- package/out/typer/solver.js +212 -435
- package/out/typer/solver.js.map +1 -1
- package/out/typer/subster.d.ts +2 -4
- package/out/typer/subster.d.ts.map +1 -1
- package/out/typer/subster.js +97 -59
- package/out/typer/subster.js.map +1 -1
- package/out/typer/topo-sort.d.ts.map +1 -1
- package/out/typer/topo-sort.js +9 -2
- package/out/typer/topo-sort.js.map +1 -1
- package/out/typer/type-hint-manager/type-hint-manager.d.ts +9 -4
- package/out/typer/type-hint-manager/type-hint-manager.d.ts.map +1 -1
- package/out/typer/type-hint-manager/type-hint-manager.js +8 -4
- package/out/typer/type-hint-manager/type-hint-manager.js.map +1 -1
- package/out/typer/type-manager.d.ts +8 -2
- package/out/typer/type-manager.d.ts.map +1 -1
- package/out/typer/type-manager.js +18 -11
- package/out/typer/type-manager.js.map +1 -1
- package/out/typer/type-predicate.d.ts +21 -3
- package/out/typer/type-predicate.d.ts.map +1 -1
- package/out/typer/type-predicate.js +143 -34
- package/out/typer/type-predicate.js.map +1 -1
- package/out/typer/typer.d.ts +25 -8
- package/out/typer/typer.d.ts.map +1 -1
- package/out/typer/typer.js +68 -71
- package/out/typer/typer.js.map +1 -1
- package/out/typer/unifier.d.ts +0 -3
- package/out/typer/unifier.d.ts.map +1 -1
- package/out/typer/unifier.js +57 -67
- package/out/typer/unifier.js.map +1 -1
- package/out/utils/nasl-type-manipulation.d.ts +1 -0
- package/out/utils/nasl-type-manipulation.d.ts.map +1 -1
- package/out/utils/nasl-type-manipulation.js +3 -1
- package/out/utils/nasl-type-manipulation.js.map +1 -1
- package/out/utils/parseTsClassType.d.ts +2 -3
- package/out/utils/parseTsClassType.d.ts.map +1 -1
- package/out/utils/parseTsClassType.js +43 -60
- package/out/utils/parseTsClassType.js.map +1 -1
- package/out/utils/string.d.ts +4 -0
- package/out/utils/string.d.ts.map +1 -0
- package/out/utils/string.js +29 -0
- package/out/utils/string.js.map +1 -0
- package/out/utils/type-operator.d.ts +2 -2
- package/out/utils/type-operator.d.ts.map +1 -1
- package/out/utils/type-operator.js +16 -14
- package/out/utils/type-operator.js.map +1 -1
- package/package.json +16 -7
- package/out/utils/vue-hack.d.ts +0 -25
- package/out/utils/vue-hack.d.ts.map +0 -1
- package/out/utils/vue-hack.js +0 -33
- package/out/utils/vue-hack.js.map +0 -1
- package/out/utils/vue.d.ts +0 -2
- package/out/utils/vue.d.ts.map +0 -1
- package/out/utils/vue.js +0 -10
- package/out/utils/vue.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
1
|
# Nasl Language Server
|
|
2
2
|
|
|
3
3
|
Nasl 语言服务
|
|
4
|
+
|
|
5
|
+
## 描述
|
|
6
|
+
|
|
7
|
+
NetEase Application Specific Language (NASL) 语言服务器核心包,提供 NASL 语言的类型检查、语法分析和其他语言服务功能。
|
|
8
|
+
|
|
9
|
+
## 技术栈
|
|
10
|
+
|
|
11
|
+
### 核心技术
|
|
12
|
+
- **TypeScript 5.4.4** - 主要开发语言
|
|
13
|
+
- **Node.js 18+** - 运行环境
|
|
14
|
+
|
|
15
|
+
### 主要依赖
|
|
16
|
+
- **@lcap/nasl-concepts** - NASL 概念定义
|
|
17
|
+
- **@lcap/nasl-types** - NASL 类型系统
|
|
18
|
+
- **@lcap/nasl-utils** - NASL 工具库
|
|
19
|
+
- **decimal.js** - 精确数值计算
|
|
20
|
+
- **json5** - JSON5 格式支持
|
|
21
|
+
- **lodash** - 实用工具库
|
|
22
|
+
- **mnemonist** - 数据结构库
|
|
23
|
+
|
|
24
|
+
### 开发工具
|
|
25
|
+
- **Vitest 3.2.4** - 现代测试框架
|
|
26
|
+
- **Chai 4.3.7** - 断言库
|
|
27
|
+
- **Mocha** - 传统测试框架(通过 @lcap/nasl-test-toolkit)
|
|
28
|
+
|
|
29
|
+
## 开发
|
|
30
|
+
|
|
31
|
+
### 构建
|
|
32
|
+
```bash
|
|
33
|
+
# 清理输出目录
|
|
34
|
+
npm run clear
|
|
35
|
+
|
|
36
|
+
# 构建项目
|
|
37
|
+
npm run build
|
|
38
|
+
|
|
39
|
+
# 监听模式构建
|
|
40
|
+
npm run watch
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 测试
|
|
44
|
+
|
|
45
|
+
#### Vitest 测试(推荐)
|
|
46
|
+
```bash
|
|
47
|
+
# 运行所有 Vitest 测试
|
|
48
|
+
npm run test:vite
|
|
49
|
+
|
|
50
|
+
# 监听模式运行测试
|
|
51
|
+
npm run test:watch
|
|
52
|
+
|
|
53
|
+
# 启动测试 UI 界面
|
|
54
|
+
npm run test:ui
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Mocha 测试 (遗留)
|
|
58
|
+
|
|
59
|
+
注意:
|
|
60
|
+
- Mocha 测试框架已经废弃,对于新的单元测试的编写,请使用 Vitest 测试框架。
|
|
61
|
+
- Mocha 测试框架的测试用例,请迁移到 Vitest 测试框架。请参考 [TESTING_MIGRATION.md](./tests/TESTING_MIGRATION.md) 文件,让LLM自动化地完成迁移。
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 运行标准 Mocha 测试套件
|
|
65
|
+
npm run test
|
|
66
|
+
|
|
67
|
+
# 运行应用测试
|
|
68
|
+
npm run test:apps
|
|
69
|
+
|
|
70
|
+
# 运行 CI 测试
|
|
71
|
+
npm run test:ci
|
|
72
|
+
|
|
73
|
+
# 更新测试快照
|
|
74
|
+
npm run test:update
|
|
75
|
+
|
|
76
|
+
# 运行性能测试
|
|
77
|
+
npm run test:perf
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 其他工具
|
|
81
|
+
```bash
|
|
82
|
+
# 压缩测试数据
|
|
83
|
+
npm run compress-test-data
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 许可证
|
|
87
|
+
|
|
88
|
+
MIT
|
package/out/checker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SyntaxNode, App, BaseNode } from '@lcap/nasl-concepts';
|
|
2
2
|
import { TypeAnnotation } from '@lcap/nasl-concepts';
|
|
3
|
-
import { type SemEnv } from './typer';
|
|
3
|
+
import { type SemEnv } from './typer/typer';
|
|
4
4
|
import { Diagnostic as NaslTypeDiagnostic } from '@lcap/nasl-types';
|
|
5
5
|
export declare enum Severity {
|
|
6
6
|
WARN = "warning",
|
package/out/checker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAU0F,GAAG,EAMvG,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACgE,cAAc,EAEpF,MAAM,qBAAqB,CAAC;AAS7B,OAAO,
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAU0F,GAAG,EAMvG,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACgE,cAAc,EAEpF,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAMpE,oBAAY,QAAQ;IAClB,IAAI,YAAY;IAChB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AAEnE,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAMF,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAEpE,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;AAMrE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAqBF,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,GAAG,CAAC;IACT,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,yBAAyB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC/C,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAuPF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,eAAe;oCA2kIpB,OAAO;sDAPW,gBAAgB,EAAE;;;;sBAfjD,UAAU,GAAG,SAAS;;;8BA2Df,UAAU;2BAsBb,UAAU;;kBAtmInB,UAAU,WAAW,MAAM,YAAY,YAAY;EAwnIzE;AAGD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACrC,mBAAmB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,qBAAqB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,6BAA6B,aAAc,UAAU,sCAAoC,MAAM,gBAAgB,CAmC3H,CAAA;AAMD,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/out/checker.js
CHANGED
|
@@ -6,10 +6,11 @@ const nasl_concepts_1 = require("@lcap/nasl-concepts");
|
|
|
6
6
|
const service_1 = require("@lcap/nasl-concepts/service");
|
|
7
7
|
const file_node_cache_1 = require("./utils/file-node-cache");
|
|
8
8
|
const nasl_utils_1 = require("@lcap/nasl-utils");
|
|
9
|
-
const
|
|
9
|
+
const sem_diag_1 = require("./typer/sem-diag");
|
|
10
10
|
const type_predicate_1 = require("./typer/type-predicate");
|
|
11
11
|
const type_manager_1 = require("./typer/type-manager");
|
|
12
12
|
const nasl_predicate_1 = require("./typer/nasl-predicate");
|
|
13
|
+
const helper_1 = require("./typer/helper");
|
|
13
14
|
var Severity;
|
|
14
15
|
(function (Severity) {
|
|
15
16
|
Severity["WARN"] = "warning";
|
|
@@ -301,11 +302,20 @@ function createErrorDiagnoser(context) {
|
|
|
301
302
|
currentNode = currentNode.parentNode;
|
|
302
303
|
}
|
|
303
304
|
const finalNode = memberExpression ?? node;
|
|
304
|
-
(0,
|
|
305
|
+
(0, helper_1.createOnPush)(diagnostics, finalNode, diagnostic);
|
|
305
306
|
finalNode.tsErrorDetail = diagnostic;
|
|
306
307
|
}
|
|
307
308
|
else { }
|
|
308
309
|
}
|
|
310
|
+
function scopedError(node, message, context) {
|
|
311
|
+
const scope = node?.constructor?.nodeTitle;
|
|
312
|
+
if (scope) {
|
|
313
|
+
error(node, `${scope}:${message}`, context);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
error(node, message, context);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
309
319
|
/**
|
|
310
320
|
* 获取当前错误信息
|
|
311
321
|
* @param node
|
|
@@ -581,7 +591,7 @@ function createErrorDiagnoser(context) {
|
|
|
581
591
|
* @returns
|
|
582
592
|
*/
|
|
583
593
|
function isNonRequiredParam(param) {
|
|
584
|
-
return param?.defaultValue?.expression || param?.defaultExpression || param?.optional ||
|
|
594
|
+
return param?.defaultValue?.expression || param?.defaultExpression || param?.optional || (nasl_concepts_1.asserts.isInterfaceParam(param) && !param.required);
|
|
585
595
|
}
|
|
586
596
|
/**
|
|
587
597
|
* 确定函数签名中所需的最小参数数量
|
|
@@ -591,6 +601,9 @@ function createErrorDiagnoser(context) {
|
|
|
591
601
|
let minArgsCount = 0;
|
|
592
602
|
for (let i = 0; i < paramLen; i++) {
|
|
593
603
|
const param = params[i];
|
|
604
|
+
if (param?.spread) {
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
594
607
|
if (!isNonRequiredParam(param)) {
|
|
595
608
|
minArgsCount++; // 如果参数有默认值,则跳过
|
|
596
609
|
}
|
|
@@ -713,13 +726,17 @@ function createErrorDiagnoser(context) {
|
|
|
713
726
|
}
|
|
714
727
|
yield* (0, nasl_utils_1.wrapForEachToGenerator)(args, function* (arg, index) {
|
|
715
728
|
const param = params?.[index];
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
const isParamRequired = !(hasSpreadParam && index > spreadParamIndex) && !isNonRequiredParam(param);
|
|
729
|
+
// 若 param 的定义不存在,则默认是必填的。
|
|
730
|
+
const isParamRequired = param ? !isNonRequiredParam(param) : true;
|
|
719
731
|
arg.paramRequired = isParamRequired;
|
|
732
|
+
// 即便是 param 的定义不存在,也需要检查 arg。这样可以检查出 arg 是否引用了一些未定义的变量
|
|
733
|
+
const argType = yield* checkNode(arg);
|
|
734
|
+
if (!param) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
720
737
|
const paramType = param.typeAnnotation ??
|
|
721
738
|
(nasl_concepts_1.asserts.isTypeAnnotation(param) ? param : env.getType(param));
|
|
722
|
-
|
|
739
|
+
// 检查高阶函数参数个数是否匹配
|
|
723
740
|
if (paramType?.typeKind === 'function' && argType?.typeKind === 'function') {
|
|
724
741
|
const argTypeArgs = argType?.typeArguments || [];
|
|
725
742
|
const paramTypeArgs = paramType?.typeArguments || [];
|
|
@@ -1147,13 +1164,14 @@ function createErrorDiagnoser(context) {
|
|
|
1147
1164
|
}
|
|
1148
1165
|
}
|
|
1149
1166
|
/**
|
|
1150
|
-
*
|
|
1167
|
+
* 检查【局部】变量
|
|
1151
1168
|
* @param node
|
|
1152
1169
|
*/
|
|
1153
1170
|
function* checkVariable(node) {
|
|
1154
1171
|
yield* checkNode(node.defaultValue);
|
|
1155
1172
|
// 前面加了报错,省点时间,报错不用那么精确
|
|
1156
1173
|
// yield* checkVariableType(node);
|
|
1174
|
+
yield* checkNode(node.typeAnnotation);
|
|
1157
1175
|
}
|
|
1158
1176
|
/**
|
|
1159
1177
|
* 检查 前端全局变量
|
|
@@ -1562,6 +1580,30 @@ function createErrorDiagnoser(context) {
|
|
|
1562
1580
|
error(node, message);
|
|
1563
1581
|
}
|
|
1564
1582
|
}
|
|
1583
|
+
const relationEntity = node.relationEntity;
|
|
1584
|
+
const relationNamespace = node.relationNamespace;
|
|
1585
|
+
const relationProperty = node.relationProperty;
|
|
1586
|
+
if (relationEntity && relationNamespace && relationProperty) {
|
|
1587
|
+
const releationEntityQName = `${relationNamespace}.${relationEntity}`;
|
|
1588
|
+
const releationEntityPropertyQName = `${releationEntityQName}.properties.${relationProperty}`;
|
|
1589
|
+
const entityEntityDef = env.refMgr.queryQNameDef(releationEntityQName);
|
|
1590
|
+
const entityPropertyDef = env.refMgr.queryQNameDef(releationEntityPropertyQName);
|
|
1591
|
+
if (entityPropertyDef) {
|
|
1592
|
+
const equal = (0, type_predicate_1.isEqualTy)(env, entityPropertyDef.typeAnnotation, node.typeAnnotation);
|
|
1593
|
+
if (equal) {
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
const content = (0, sem_diag_1.mkIncompatibleTyErr)(env, entityPropertyDef.typeAnnotation, node.typeAnnotation);
|
|
1597
|
+
const message = `关联属性${content}`;
|
|
1598
|
+
error(node, message);
|
|
1599
|
+
}
|
|
1600
|
+
else {
|
|
1601
|
+
const message = entityEntityDef
|
|
1602
|
+
? `找不到 ${relationEntity} 上的 ${relationProperty}`
|
|
1603
|
+
: `找不到实体 ${relationEntity}`;
|
|
1604
|
+
error(node, message);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1565
1607
|
}
|
|
1566
1608
|
/**
|
|
1567
1609
|
* 检查 枚举
|
|
@@ -1678,6 +1720,7 @@ function createErrorDiagnoser(context) {
|
|
|
1678
1720
|
yield* checkNode(node.defaultValue);
|
|
1679
1721
|
// 前面加了报错,省点时间,报错不用那么精确
|
|
1680
1722
|
// yield* checkVariableType(node);
|
|
1723
|
+
yield* checkNode(node.typeAnnotation);
|
|
1681
1724
|
}
|
|
1682
1725
|
/**
|
|
1683
1726
|
* 检查 接口
|
|
@@ -1878,6 +1921,17 @@ function createErrorDiagnoser(context) {
|
|
|
1878
1921
|
...(node.variables || []),
|
|
1879
1922
|
...(node.logics || []),
|
|
1880
1923
|
]);
|
|
1924
|
+
if (node.params?.length) {
|
|
1925
|
+
yield* checkParams(node.params);
|
|
1926
|
+
yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.params, function* (node) {
|
|
1927
|
+
yield* checkNode(node);
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
if (node.variables?.length) {
|
|
1931
|
+
yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.variables, function* (node) {
|
|
1932
|
+
yield* checkNode(node);
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1881
1935
|
// 组件元素
|
|
1882
1936
|
if (node.elements?.length) {
|
|
1883
1937
|
yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.elements, function* (node) {
|
|
@@ -2230,7 +2284,8 @@ function createErrorDiagnoser(context) {
|
|
|
2230
2284
|
yield* checkNode(node.bind);
|
|
2231
2285
|
if (node.processDefinitions?.length) {
|
|
2232
2286
|
yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.processDefinitions, function* (node) {
|
|
2233
|
-
|
|
2287
|
+
// 现有流程版本 [v1, v2],加个 v3 后,变成了 [proxy(v1), proxy(v2), v3],无法理解
|
|
2288
|
+
yield* checkNode(toRaw(node));
|
|
2234
2289
|
});
|
|
2235
2290
|
}
|
|
2236
2291
|
if (node?.subLogics?.length) {
|
|
@@ -2768,6 +2823,9 @@ function createErrorDiagnoser(context) {
|
|
|
2768
2823
|
if (node.calleeName === 'Clear' && type?.typeKind === 'union') {
|
|
2769
2824
|
error(node, `传入类型错误,接收类型:非union类型`);
|
|
2770
2825
|
}
|
|
2826
|
+
if (node.calleeName === 'ListSort' || node.calleeName === 'ListSortAsync') {
|
|
2827
|
+
checkListSort(node);
|
|
2828
|
+
}
|
|
2771
2829
|
if (node.typeArguments?.length) {
|
|
2772
2830
|
yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.typeArguments, function* (node) {
|
|
2773
2831
|
yield* checkNode(node);
|
|
@@ -2811,6 +2869,23 @@ function createErrorDiagnoser(context) {
|
|
|
2811
2869
|
}
|
|
2812
2870
|
}
|
|
2813
2871
|
return type;
|
|
2872
|
+
function checkListSort(nd) {
|
|
2873
|
+
for (let i = 1; i < nd.arguments.length; i++) {
|
|
2874
|
+
const expr = nd.arguments[i].expression;
|
|
2875
|
+
let resTy;
|
|
2876
|
+
if (expr?.concept === 'AnonymousFunction') {
|
|
2877
|
+
resTy = env.getType(expr.body);
|
|
2878
|
+
}
|
|
2879
|
+
else if (expr?.concept === 'SubLogic') {
|
|
2880
|
+
resTy = env.getType(expr.returns?.[0]);
|
|
2881
|
+
}
|
|
2882
|
+
const byTy = resTy?.properties?.find((prop) => prop.name === 'by')?.typeAnnotation;
|
|
2883
|
+
if (byTy?.typeKind === 'union') {
|
|
2884
|
+
// 这里使用 node.arguments[i] 则无红框,猜测是 ListSort 的特殊交互导致的问题
|
|
2885
|
+
error(node, (0, sem_diag_1.mkIncompatibleTyErr)(env, byTy, '非 union 的基础类型:如字符串、整数、布尔等'));
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2814
2889
|
}
|
|
2815
2890
|
/**
|
|
2816
2891
|
* 检查 调用逻辑
|
|
@@ -3229,21 +3304,13 @@ function createErrorDiagnoser(context) {
|
|
|
3229
3304
|
/**
|
|
3230
3305
|
* 参考类型检查器的 {@link tpIdentifier}方法
|
|
3231
3306
|
*/
|
|
3232
|
-
return
|
|
3307
|
+
return type_manager_1.naslLongTy;
|
|
3233
3308
|
}
|
|
3234
3309
|
else if (node.name === 'it') {
|
|
3235
3310
|
return env.getType(node);
|
|
3236
3311
|
}
|
|
3237
3312
|
else {
|
|
3238
3313
|
const { name } = node;
|
|
3239
|
-
// 之前有一些脏数据,先兼容
|
|
3240
|
-
// if (['true', 'false'].includes(name)) {
|
|
3241
|
-
// return new TypeAnnotation({
|
|
3242
|
-
// typeKind: 'primitive',
|
|
3243
|
-
// typeName: 'Boolean',
|
|
3244
|
-
// typeNamespace: 'nasl.core',
|
|
3245
|
-
// });
|
|
3246
|
-
// }
|
|
3247
3314
|
if (
|
|
3248
3315
|
// name 是 A.B.C
|
|
3249
3316
|
name?.split('.')?.length > 1
|
|
@@ -3258,6 +3325,13 @@ function createErrorDiagnoser(context) {
|
|
|
3258
3325
|
return errorType;
|
|
3259
3326
|
}
|
|
3260
3327
|
}
|
|
3328
|
+
if (node.namespace === 'app.enums' &&
|
|
3329
|
+
node.parentNode?.concept !== 'MemberExpression' &&
|
|
3330
|
+
node.parentNode?.concept !== 'SelectMembers') {
|
|
3331
|
+
// 判断枚举类是否直接被使用
|
|
3332
|
+
scopedError(node, `${node.toNaturalTS()} 枚举类不能直接使用,请取它的枚举项`);
|
|
3333
|
+
return errorType;
|
|
3334
|
+
}
|
|
3261
3335
|
// 检查使用范围
|
|
3262
3336
|
yield* checkScopeOfUse(node, ref);
|
|
3263
3337
|
return env.getType(node);
|
|
@@ -3942,6 +4016,8 @@ function createErrorDiagnoser(context) {
|
|
|
3942
4016
|
return yield* checkBackendVariable(node);
|
|
3943
4017
|
case 'Param':
|
|
3944
4018
|
return yield* checkParam(node);
|
|
4019
|
+
case 'ParamWithGroup':
|
|
4020
|
+
return yield* checkParam(node);
|
|
3945
4021
|
case 'Return':
|
|
3946
4022
|
return yield* checkReturn(node);
|
|
3947
4023
|
case 'DefaultValue':
|