@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.
Files changed (168) hide show
  1. package/README.md +85 -0
  2. package/out/checker.d.ts +1 -1
  3. package/out/checker.d.ts.map +1 -1
  4. package/out/checker.js +94 -18
  5. package/out/checker.js.map +1 -1
  6. package/out/index.d.ts +4 -2
  7. package/out/index.d.ts.map +1 -1
  8. package/out/index.js +6 -2
  9. package/out/index.js.map +1 -1
  10. package/out/module/graph.js +6 -6
  11. package/out/module/graph.js.map +1 -1
  12. package/out/module/module.d.ts.map +1 -1
  13. package/out/module/module.js +3 -6
  14. package/out/module/module.js.map +1 -1
  15. package/out/query/context-variable-query.d.ts +31 -0
  16. package/out/query/context-variable-query.d.ts.map +1 -0
  17. package/out/query/context-variable-query.js +105 -0
  18. package/out/query/context-variable-query.js.map +1 -0
  19. package/out/query/index.d.ts +2 -0
  20. package/out/query/index.d.ts.map +1 -0
  21. package/out/query/index.js +18 -0
  22. package/out/query/index.js.map +1 -0
  23. package/out/reference-manager/builtin-q-name.d.ts +2 -2
  24. package/out/reference-manager/builtin-q-name.d.ts.map +1 -1
  25. package/out/reference-manager/builtin-q-name.js +16 -12
  26. package/out/reference-manager/builtin-q-name.js.map +1 -1
  27. package/out/reference-manager/collect-q-name.d.ts +4 -4
  28. package/out/reference-manager/collect-q-name.d.ts.map +1 -1
  29. package/out/reference-manager/collect-q-name.js +39 -31
  30. package/out/reference-manager/collect-q-name.js.map +1 -1
  31. package/out/reference-manager/get-q-name.d.ts +0 -2
  32. package/out/reference-manager/get-q-name.d.ts.map +1 -1
  33. package/out/reference-manager/get-q-name.js +58 -57
  34. package/out/reference-manager/get-q-name.js.map +1 -1
  35. package/out/reference-manager/reference-manager.d.ts +33 -18
  36. package/out/reference-manager/reference-manager.d.ts.map +1 -1
  37. package/out/reference-manager/reference-manager.js +249 -157
  38. package/out/reference-manager/reference-manager.js.map +1 -1
  39. package/out/reference-manager/remove-q-name.d.ts +30 -29
  40. package/out/reference-manager/remove-q-name.d.ts.map +1 -1
  41. package/out/reference-manager/remove-q-name.js +72 -61
  42. package/out/reference-manager/remove-q-name.js.map +1 -1
  43. package/out/reference-manager/rename-q-name.d.ts +4 -2
  44. package/out/reference-manager/rename-q-name.d.ts.map +1 -1
  45. package/out/reference-manager/rename-q-name.js +45 -31
  46. package/out/reference-manager/rename-q-name.js.map +1 -1
  47. package/out/reference-manager/symbol-type.d.ts +7 -3
  48. package/out/reference-manager/symbol-type.d.ts.map +1 -1
  49. package/out/reference-manager/symbol-type.js +18 -11
  50. package/out/reference-manager/symbol-type.js.map +1 -1
  51. package/out/reference-manager/update-nasl-fragment.d.ts +2 -1
  52. package/out/reference-manager/update-nasl-fragment.d.ts.map +1 -1
  53. package/out/reference-manager/update-nasl-fragment.js +18 -9
  54. package/out/reference-manager/update-nasl-fragment.js.map +1 -1
  55. package/out/symbol/graph.js +2 -2
  56. package/out/symbol/graph.js.map +1 -1
  57. package/out/typer/collectGlobalDefs.d.ts +1 -1
  58. package/out/typer/collectGlobalDefs.d.ts.map +1 -1
  59. package/out/typer/collectGlobalDefs.js +2 -2
  60. package/out/typer/collectGlobalDefs.js.map +1 -1
  61. package/out/typer/component-def-manager/component-def-manager.d.ts +33 -5
  62. package/out/typer/component-def-manager/component-def-manager.d.ts.map +1 -1
  63. package/out/typer/component-def-manager/component-def-manager.js +101 -21
  64. package/out/typer/component-def-manager/component-def-manager.js.map +1 -1
  65. package/out/typer/component-def-manager/utils.d.ts.map +1 -1
  66. package/out/typer/component-def-manager/utils.js +44 -15
  67. package/out/typer/component-def-manager/utils.js.map +1 -1
  68. package/out/typer/dispatch-all.d.ts +2 -2
  69. package/out/typer/dispatch-all.d.ts.map +1 -1
  70. package/out/typer/dispatch-all.js +5 -9
  71. package/out/typer/dispatch-all.js.map +1 -1
  72. package/out/typer/dispatch-def.d.ts +1 -1
  73. package/out/typer/dispatch-def.d.ts.map +1 -1
  74. package/out/typer/dispatch-def.js +16 -11
  75. package/out/typer/dispatch-def.js.map +1 -1
  76. package/out/typer/dispatch-expr.d.ts +6 -3
  77. package/out/typer/dispatch-expr.d.ts.map +1 -1
  78. package/out/typer/dispatch-expr.js +300 -178
  79. package/out/typer/dispatch-expr.js.map +1 -1
  80. package/out/typer/dispatch-process.d.ts +0 -1
  81. package/out/typer/dispatch-process.d.ts.map +1 -1
  82. package/out/typer/dispatch-process.js +38 -18
  83. package/out/typer/dispatch-process.js.map +1 -1
  84. package/out/typer/dispatch-stmt.d.ts.map +1 -1
  85. package/out/typer/dispatch-stmt.js +25 -10
  86. package/out/typer/dispatch-stmt.js.map +1 -1
  87. package/out/typer/dispatch-view.d.ts +1 -1
  88. package/out/typer/dispatch-view.d.ts.map +1 -1
  89. package/out/typer/dispatch-view.js +224 -158
  90. package/out/typer/dispatch-view.js.map +1 -1
  91. package/out/typer/helper.d.ts +0 -2
  92. package/out/typer/helper.d.ts.map +1 -1
  93. package/out/typer/helper.js +4 -19
  94. package/out/typer/helper.js.map +1 -1
  95. package/out/typer/incremental-update.d.ts +21 -42
  96. package/out/typer/incremental-update.d.ts.map +1 -1
  97. package/out/typer/incremental-update.js +218 -295
  98. package/out/typer/incremental-update.js.map +1 -1
  99. package/out/typer/index.d.ts +3 -2
  100. package/out/typer/index.d.ts.map +1 -1
  101. package/out/typer/index.js +3 -2
  102. package/out/typer/index.js.map +1 -1
  103. package/out/typer/nasl-predicate.d.ts +1 -2
  104. package/out/typer/nasl-predicate.d.ts.map +1 -1
  105. package/out/typer/overload-helper.d.ts +12 -0
  106. package/out/typer/overload-helper.d.ts.map +1 -0
  107. package/out/typer/overload-helper.js +110 -0
  108. package/out/typer/overload-helper.js.map +1 -0
  109. package/out/typer/sem-diag.d.ts +4 -0
  110. package/out/typer/sem-diag.d.ts.map +1 -1
  111. package/out/typer/sem-diag.js +9 -1
  112. package/out/typer/sem-diag.js.map +1 -1
  113. package/out/typer/solver.d.ts +39 -26
  114. package/out/typer/solver.d.ts.map +1 -1
  115. package/out/typer/solver.js +212 -435
  116. package/out/typer/solver.js.map +1 -1
  117. package/out/typer/subster.d.ts +2 -4
  118. package/out/typer/subster.d.ts.map +1 -1
  119. package/out/typer/subster.js +97 -59
  120. package/out/typer/subster.js.map +1 -1
  121. package/out/typer/topo-sort.d.ts.map +1 -1
  122. package/out/typer/topo-sort.js +9 -2
  123. package/out/typer/topo-sort.js.map +1 -1
  124. package/out/typer/type-hint-manager/type-hint-manager.d.ts +9 -4
  125. package/out/typer/type-hint-manager/type-hint-manager.d.ts.map +1 -1
  126. package/out/typer/type-hint-manager/type-hint-manager.js +8 -4
  127. package/out/typer/type-hint-manager/type-hint-manager.js.map +1 -1
  128. package/out/typer/type-manager.d.ts +8 -2
  129. package/out/typer/type-manager.d.ts.map +1 -1
  130. package/out/typer/type-manager.js +18 -11
  131. package/out/typer/type-manager.js.map +1 -1
  132. package/out/typer/type-predicate.d.ts +21 -3
  133. package/out/typer/type-predicate.d.ts.map +1 -1
  134. package/out/typer/type-predicate.js +143 -34
  135. package/out/typer/type-predicate.js.map +1 -1
  136. package/out/typer/typer.d.ts +25 -8
  137. package/out/typer/typer.d.ts.map +1 -1
  138. package/out/typer/typer.js +68 -71
  139. package/out/typer/typer.js.map +1 -1
  140. package/out/typer/unifier.d.ts +0 -3
  141. package/out/typer/unifier.d.ts.map +1 -1
  142. package/out/typer/unifier.js +57 -67
  143. package/out/typer/unifier.js.map +1 -1
  144. package/out/utils/nasl-type-manipulation.d.ts +1 -0
  145. package/out/utils/nasl-type-manipulation.d.ts.map +1 -1
  146. package/out/utils/nasl-type-manipulation.js +3 -1
  147. package/out/utils/nasl-type-manipulation.js.map +1 -1
  148. package/out/utils/parseTsClassType.d.ts +2 -3
  149. package/out/utils/parseTsClassType.d.ts.map +1 -1
  150. package/out/utils/parseTsClassType.js +43 -60
  151. package/out/utils/parseTsClassType.js.map +1 -1
  152. package/out/utils/string.d.ts +4 -0
  153. package/out/utils/string.d.ts.map +1 -0
  154. package/out/utils/string.js +29 -0
  155. package/out/utils/string.js.map +1 -0
  156. package/out/utils/type-operator.d.ts +2 -2
  157. package/out/utils/type-operator.d.ts.map +1 -1
  158. package/out/utils/type-operator.js +16 -14
  159. package/out/utils/type-operator.js.map +1 -1
  160. package/package.json +16 -7
  161. package/out/utils/vue-hack.d.ts +0 -25
  162. package/out/utils/vue-hack.d.ts.map +0 -1
  163. package/out/utils/vue-hack.js +0 -33
  164. package/out/utils/vue-hack.js.map +0 -1
  165. package/out/utils/vue.d.ts +0 -2
  166. package/out/utils/vue.d.ts.map +0 -1
  167. package/out/utils/vue.js +0 -10
  168. 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",
@@ -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,EAA4B,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAIhE,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,M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AAK,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 typer_1 = require("./typer");
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, typer_1.createOnPush)(diagnostics, finalNode, diagnostic);
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 || param?.spread || (nasl_concepts_1.asserts.isInterfaceParam(param) && !param.required);
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
- if (!param)
717
- return;
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
- const argType = yield* checkNode(arg);
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
- yield* checkNode(node);
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 typer_1.naslLongTy;
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':