@lcap/nasl-language-server-core 4.4.0-beta.4 → 4.4.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/checker.d.ts.map +1 -1
- package/out/checker.js +83 -2
- package/out/checker.js.map +1 -1
- package/out/reference-manager/reference-manager.d.ts +2 -2
- package/out/reference-manager/reference-manager.d.ts.map +1 -1
- package/out/reference-manager/reference-manager.js +2 -2
- package/out/reference-manager/reference-manager.js.map +1 -1
- package/out/reference-manager/view-elem-logic.d.ts +3 -3
- package/out/reference-manager/view-elem-logic.d.ts.map +1 -1
- package/out/reference-manager/view-elem-logic.js +17 -0
- package/out/reference-manager/view-elem-logic.js.map +1 -1
- package/out/symbol/traverse/concepts/index.d.ts +1 -1
- package/out/symbol/traverse/concepts/index.d.ts.map +1 -1
- package/out/typer/dispatch-call.d.ts.map +1 -1
- package/out/typer/dispatch-call.js +6 -0
- package/out/typer/dispatch-call.js.map +1 -1
- package/out/typer/dispatch-def.d.ts.map +1 -1
- package/out/typer/dispatch-def.js +3 -1
- package/out/typer/dispatch-def.js.map +1 -1
- package/out/typer/dispatch-expr.d.ts +2 -1
- package/out/typer/dispatch-expr.d.ts.map +1 -1
- package/out/typer/dispatch-expr.js +95 -21
- package/out/typer/dispatch-expr.js.map +1 -1
- package/out/typer/dispatch-stmt.d.ts.map +1 -1
- package/out/typer/dispatch-stmt.js +29 -15
- package/out/typer/dispatch-stmt.js.map +1 -1
- package/out/typer/dispatch-view.d.ts.map +1 -1
- package/out/typer/dispatch-view.js +0 -4
- package/out/typer/dispatch-view.js.map +1 -1
- package/out/typer/incremental-update.d.ts +4 -0
- package/out/typer/incremental-update.d.ts.map +1 -1
- package/out/typer/incremental-update.js +81 -2
- package/out/typer/incremental-update.js.map +1 -1
- package/out/typer/oql-checker/chain-call-transformer.d.ts.map +1 -1
- package/out/typer/oql-checker/chain-call-transformer.js +17 -4
- package/out/typer/oql-checker/chain-call-transformer.js.map +1 -1
- package/out/typer/oql-checker/ts-parser.d.ts.map +1 -1
- package/out/typer/oql-checker/ts-parser.js +157 -21
- package/out/typer/oql-checker/ts-parser.js.map +1 -1
- package/out/typer/overload-helper.d.ts.map +1 -1
- package/out/typer/overload-helper.js +5 -0
- package/out/typer/overload-helper.js.map +1 -1
- package/out/typer/subster.d.ts +1 -1
- package/out/typer/subster.d.ts.map +1 -1
- package/out/typer/subster.js +7 -3
- package/out/typer/subster.js.map +1 -1
- package/out/typer/type-predicate.d.ts.map +1 -1
- package/out/typer/type-predicate.js +38 -2
- package/out/typer/type-predicate.js.map +1 -1
- package/out/typer/typer.d.ts +22 -2
- package/out/typer/typer.d.ts.map +1 -1
- package/out/typer/typer.js +117 -16
- package/out/typer/typer.js.map +1 -1
- package/out/typer/unifier.d.ts +1 -1
- package/out/typer/unifier.d.ts.map +1 -1
- package/out/typer/unifier.js +8 -4
- package/out/typer/unifier.js.map +1 -1
- package/package.json +6 -6
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,EAU2G,GAAG,EAMxH,QAAQ,EAET,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACgE,cAAc,EAGpF,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOpE,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;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AAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/out/checker.js
CHANGED
|
@@ -10,8 +10,8 @@ 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 service_2 = require("@lcap/nasl-concepts/service");
|
|
13
|
-
const asserts_1 = require("@lcap/nasl-concepts/asserts");
|
|
14
13
|
const lodash_1 = require("lodash");
|
|
14
|
+
const asserts_1 = require("@lcap/nasl-concepts/asserts");
|
|
15
15
|
const helper_1 = require("./typer/helper");
|
|
16
16
|
const semantic_rules_1 = require("./semantic-rules");
|
|
17
17
|
var Severity;
|
|
@@ -321,7 +321,30 @@ function createErrorDiagnoser(context) {
|
|
|
321
321
|
}
|
|
322
322
|
const finalNode = memberExpression ?? node;
|
|
323
323
|
(0, helper_1.createOnPush)(diagnostics, finalNode, diagnostic);
|
|
324
|
-
|
|
324
|
+
const aggregationFields = {
|
|
325
|
+
assignmentLine: 'assignmentLines',
|
|
326
|
+
};
|
|
327
|
+
const nodeDiagnostics = diagnostics.get(finalNode);
|
|
328
|
+
if (nodeDiagnostics && nodeDiagnostics.length > 0) {
|
|
329
|
+
// 构建最终的 tsErrorDetail,合并所有上下文信息
|
|
330
|
+
const aggregatedContext = {};
|
|
331
|
+
// 对每个需要聚合的字段进行收集
|
|
332
|
+
for (const [singleField, arrayField] of Object.entries(aggregationFields)) {
|
|
333
|
+
const values = nodeDiagnostics
|
|
334
|
+
.map(d => d[singleField])
|
|
335
|
+
.filter((val) => val !== undefined);
|
|
336
|
+
if (values.length > 0) {
|
|
337
|
+
aggregatedContext[arrayField] = values;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
finalNode.tsErrorDetail = {
|
|
341
|
+
...diagnostic,
|
|
342
|
+
...aggregatedContext,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
finalNode.tsErrorDetail = diagnostic;
|
|
347
|
+
}
|
|
325
348
|
}
|
|
326
349
|
else { }
|
|
327
350
|
}
|
|
@@ -2941,15 +2964,27 @@ function createErrorDiagnoser(context) {
|
|
|
2941
2964
|
}
|
|
2942
2965
|
return type;
|
|
2943
2966
|
function checkListSort(nd) {
|
|
2967
|
+
const parTy = env.getType(nd.arguments?.[0]);
|
|
2968
|
+
let paramType = '未知类型';
|
|
2969
|
+
if (parTy?.typeName === 'List') {
|
|
2970
|
+
paramType = (0, type_manager_1.showUserLevelType)(parTy.typeArguments?.[0] || type_manager_1.naslAnyTy);
|
|
2971
|
+
}
|
|
2972
|
+
const expectTy = `{ by: (item: ${paramType}) => 未知类型, asc: 布尔值 }`;
|
|
2944
2973
|
for (let i = 1; i < nd.arguments.length; i++) {
|
|
2945
2974
|
const expr = nd.arguments[i].expression;
|
|
2946
2975
|
let resTy;
|
|
2947
2976
|
if (expr?.concept === 'AnonymousFunction') {
|
|
2948
2977
|
resTy = env.getType(expr.body);
|
|
2978
|
+
if (!nasl_concepts_1.asserts.isNewComposite(expr.body)) {
|
|
2979
|
+
error(nd.arguments[i], (0, sem_diag_1.mkIncompatibleTyErr)(env, env.getType(expr) || type_manager_1.naslAnyTy, expectTy));
|
|
2980
|
+
}
|
|
2949
2981
|
}
|
|
2950
2982
|
else if (expr?.concept === 'SubLogic') {
|
|
2951
2983
|
resTy = env.getType(expr.returns?.[0]);
|
|
2952
2984
|
}
|
|
2985
|
+
else {
|
|
2986
|
+
error(nd.arguments[i], (0, sem_diag_1.mkIncompatibleTyErr)(env, env.getType(expr) || type_manager_1.naslAnyTy, expectTy));
|
|
2987
|
+
}
|
|
2953
2988
|
const byTy = resTy?.properties?.find((prop) => prop.name === 'by')?.typeAnnotation;
|
|
2954
2989
|
if (byTy?.typeKind === 'union') {
|
|
2955
2990
|
// 这里使用 node.arguments[i] 则无红框,猜测是 ListSort 的特殊交互导致的问题
|
|
@@ -3031,6 +3066,7 @@ function createErrorDiagnoser(context) {
|
|
|
3031
3066
|
*/
|
|
3032
3067
|
function* checkIfStatement(node) {
|
|
3033
3068
|
if (ensureNodeKeyExists(node, 'test')) {
|
|
3069
|
+
yield* rejectNullLiteral(node.test);
|
|
3034
3070
|
yield* checkNode(node.test);
|
|
3035
3071
|
}
|
|
3036
3072
|
// then
|
|
@@ -3046,12 +3082,32 @@ function createErrorDiagnoser(context) {
|
|
|
3046
3082
|
});
|
|
3047
3083
|
}
|
|
3048
3084
|
}
|
|
3085
|
+
/**
|
|
3086
|
+
* 检查 条件表达式
|
|
3087
|
+
* @param node
|
|
3088
|
+
*/
|
|
3089
|
+
function* checkIfExpression(node) {
|
|
3090
|
+
if (ensureNodeKeyExists(node, 'condition')) {
|
|
3091
|
+
yield* rejectNullLiteral(node.condition);
|
|
3092
|
+
yield* checkNode(node.condition);
|
|
3093
|
+
}
|
|
3094
|
+
// then
|
|
3095
|
+
if (ensureNodeKeyExists(node, 'consequent')) {
|
|
3096
|
+
yield* checkNode(node.consequent);
|
|
3097
|
+
}
|
|
3098
|
+
// else
|
|
3099
|
+
if (ensureNodeKeyExists(node, 'alternate')) {
|
|
3100
|
+
yield* checkNode(node.alternate);
|
|
3101
|
+
}
|
|
3102
|
+
return env.getType(node);
|
|
3103
|
+
}
|
|
3049
3104
|
/**
|
|
3050
3105
|
* 检查 匹配
|
|
3051
3106
|
* @param node
|
|
3052
3107
|
*/
|
|
3053
3108
|
function* checkMatch(node) {
|
|
3054
3109
|
if (ensureNodeKeyExists(node, 'expression')) {
|
|
3110
|
+
yield* rejectNullLiteral(node.expression);
|
|
3055
3111
|
yield* checkNode(node.expression);
|
|
3056
3112
|
}
|
|
3057
3113
|
if (node.cases?.length) {
|
|
@@ -3350,6 +3406,7 @@ function createErrorDiagnoser(context) {
|
|
|
3350
3406
|
*/
|
|
3351
3407
|
function* checkWhileStatement(node) {
|
|
3352
3408
|
if (ensureNodeKeyExists(node, 'test')) {
|
|
3409
|
+
yield* rejectNullLiteral(node.test);
|
|
3353
3410
|
yield* checkNode(node.test);
|
|
3354
3411
|
}
|
|
3355
3412
|
if (node.body?.length) {
|
|
@@ -3469,6 +3526,11 @@ function createErrorDiagnoser(context) {
|
|
|
3469
3526
|
if (typeof node.value !== 'string') {
|
|
3470
3527
|
error(node, '字符串');
|
|
3471
3528
|
}
|
|
3529
|
+
const MAX_LENGTH = 2 ** 16;
|
|
3530
|
+
if (node.value.length >= MAX_LENGTH) {
|
|
3531
|
+
// 插值内部的字符串过长时要报错在插值节点上有红框
|
|
3532
|
+
error(node.parentNode?.concept === 'StringInterpolation' ? node.parentNode : node, `存在过长文本,当前长度:${node.value.length},最大长度:${MAX_LENGTH}。建议使用变量拆分文本后再拼接。`);
|
|
3533
|
+
}
|
|
3472
3534
|
return env.getType(node);
|
|
3473
3535
|
}
|
|
3474
3536
|
/**
|
|
@@ -4003,10 +4065,17 @@ function createErrorDiagnoser(context) {
|
|
|
4003
4065
|
*/
|
|
4004
4066
|
function* checkBinaryExpression(node) {
|
|
4005
4067
|
yield* semantic_rules_1.ExtraSemanticRules.rejectFileTypes(node, env, error);
|
|
4068
|
+
const isCandidate = ['+', '-', '*', '/', '%', '>', '<', '>=', '<='].includes(node.operator);
|
|
4006
4069
|
if (ensureNodeKeyExists(node, 'left')) {
|
|
4070
|
+
if (isCandidate) {
|
|
4071
|
+
yield* rejectNullLiteral(node.left);
|
|
4072
|
+
}
|
|
4007
4073
|
yield* checkNode(node.left);
|
|
4008
4074
|
}
|
|
4009
4075
|
if (ensureNodeKeyExists(node, 'right')) {
|
|
4076
|
+
if (isCandidate) {
|
|
4077
|
+
yield* rejectNullLiteral(node.right);
|
|
4078
|
+
}
|
|
4010
4079
|
yield* checkNode(node.right);
|
|
4011
4080
|
}
|
|
4012
4081
|
return env.getType(node);
|
|
@@ -4019,6 +4088,7 @@ function createErrorDiagnoser(context) {
|
|
|
4019
4088
|
error(node, '表达式不能为空!');
|
|
4020
4089
|
}
|
|
4021
4090
|
yield* (0, nasl_utils_1.wrapForEachToGenerator)(node.expressions, function* (node) {
|
|
4091
|
+
yield* rejectNullLiteral(node);
|
|
4022
4092
|
yield* checkNode(node);
|
|
4023
4093
|
});
|
|
4024
4094
|
return env.getType(node);
|
|
@@ -4208,6 +4278,15 @@ function createErrorDiagnoser(context) {
|
|
|
4208
4278
|
error(node, `无返回值的${node?.constructor?.nodeTitle}${node.calleeName} 不能在${parentNode?.constructor?.nodeTitle}中作为表达式使用。`);
|
|
4209
4279
|
}
|
|
4210
4280
|
}
|
|
4281
|
+
/**
|
|
4282
|
+
* 检查 不允许使用 null 字面量
|
|
4283
|
+
* @param node
|
|
4284
|
+
*/
|
|
4285
|
+
function* rejectNullLiteral(node) {
|
|
4286
|
+
if (node.concept === 'NullLiteral') {
|
|
4287
|
+
error(node, `此处不允许使用 null`);
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4211
4290
|
function* dispatchNode(node) {
|
|
4212
4291
|
try {
|
|
4213
4292
|
// 调用表达式
|
|
@@ -4354,6 +4433,8 @@ function createErrorDiagnoser(context) {
|
|
|
4354
4433
|
return yield* checkBlock(node);
|
|
4355
4434
|
case 'IfStatement':
|
|
4356
4435
|
return yield* checkIfStatement(node);
|
|
4436
|
+
case 'IfExpression':
|
|
4437
|
+
return yield* checkIfExpression(node);
|
|
4357
4438
|
case 'Match':
|
|
4358
4439
|
return yield* checkMatch(node);
|
|
4359
4440
|
case 'MatchCase':
|