@lcap/nasl-language-server-core 4.4.0-beta.6 → 4.4.0-beta.8
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 +60 -1
- package/out/checker.js.map +1 -1
- package/out/typer/collectGlobalDefs.d.ts.map +1 -1
- package/out/typer/collectGlobalDefs.js +25 -2
- package/out/typer/collectGlobalDefs.js.map +1 -1
- package/out/typer/dispatch-expr.d.ts.map +1 -1
- package/out/typer/dispatch-expr.js +84 -82
- 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 +25 -23
- package/out/typer/dispatch-stmt.js.map +1 -1
- package/out/typer/subster.d.ts.map +1 -1
- package/out/typer/subster.js +103 -28
- package/out/typer/subster.js.map +1 -1
- package/out/typer/type-predicate.d.ts +1 -0
- package/out/typer/type-predicate.d.ts.map +1 -1
- package/out/typer/type-predicate.js +5 -2
- package/out/typer/type-predicate.js.map +1 -1
- package/out/typer/typer.d.ts +9 -0
- package/out/typer/typer.d.ts.map +1 -1
- package/out/typer/typer.js +71 -14
- package/out/typer/typer.js.map +1 -1
- package/out/typer/unifier.d.ts +9 -0
- package/out/typer/unifier.d.ts.map +1 -1
- package/out/typer/unifier.js +43 -1
- package/out/typer/unifier.js.map +1 -1
- package/package.json +5 -5
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,EAC4C,QAAQ,EAC5B,IAAI,EAQ+E,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,EA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;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,eAAe;oCA2hJpB,OAAO;sDAPW,gBAAgB,EAAE;;;;sBAhBjD,UAAU,GAAG,SAAS;;;8BA4Df,UAAU;2BAyBb,UAAU;;;iBAW3B,MAAM;kBACL,MAAM;kBACN,MAAM;qBACH,MAAM;;kBA7iJF,UAAU,WAAW,MAAM,YAAY,YAAY;sCA+qD/B,IAAI,GAAG,QAAQ;2CA+5FxC,UAAU,gBACV,CAAC,YAAY,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,gBAC/C,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,KACzC,kBAAkB,GAAG,IAAI;EAgD7B;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;AAMD,eAAO,MAAM,6BAA6B,aAC9B,UAAU,+DAGnB,MAAM,gBAAgB,CAyCxB,CAAC;AAMF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
package/out/checker.js
CHANGED
|
@@ -14,6 +14,8 @@ const lodash_1 = require("lodash");
|
|
|
14
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
|
+
const regeExp = new nasl_utils_1.ExpressionLexer();
|
|
18
|
+
regeExp.profile = nasl_utils_1.profiles.js;
|
|
17
19
|
var Severity;
|
|
18
20
|
(function (Severity) {
|
|
19
21
|
Severity["WARN"] = "warning";
|
|
@@ -3393,6 +3395,7 @@ function createErrorDiagnoser(context) {
|
|
|
3393
3395
|
function* checkSwitchCase(node) {
|
|
3394
3396
|
if (!(0, nasl_concepts_1.isLastNode)(node)) {
|
|
3395
3397
|
if (ensureNodeKeyExists(node, 'test')) {
|
|
3398
|
+
yield* rejectNullLiteral(node.test);
|
|
3396
3399
|
yield* checkNode(node.test);
|
|
3397
3400
|
}
|
|
3398
3401
|
}
|
|
@@ -3558,7 +3561,7 @@ function createErrorDiagnoser(context) {
|
|
|
3558
3561
|
error(node, '字符串');
|
|
3559
3562
|
}
|
|
3560
3563
|
const MAX_LENGTH = 2 ** 16;
|
|
3561
|
-
if (node.value.length
|
|
3564
|
+
if (node.value.length > MAX_LENGTH) {
|
|
3562
3565
|
// 插值内部的字符串过长时要报错在插值节点上有红框
|
|
3563
3566
|
error(node.parentNode?.concept === 'StringInterpolation' ? node.parentNode : node, `存在过长文本,当前长度:${node.value.length},最大长度:${MAX_LENGTH}。建议使用变量拆分文本后再拼接。`);
|
|
3564
3567
|
}
|
|
@@ -3717,7 +3720,59 @@ function createErrorDiagnoser(context) {
|
|
|
3717
3720
|
}
|
|
3718
3721
|
return type;
|
|
3719
3722
|
}
|
|
3723
|
+
/**
|
|
3724
|
+
* 获取正则表达式错误的中文消息
|
|
3725
|
+
*/
|
|
3726
|
+
function getRegexErrorMessage(errorId) {
|
|
3727
|
+
const errors = nasl_utils_1.referenceContent?.errors;
|
|
3728
|
+
return errors?.[errorId] || `正则表达式错误: ${errorId}`;
|
|
3729
|
+
}
|
|
3730
|
+
/**
|
|
3731
|
+
* 检查正则表达式标志符
|
|
3732
|
+
*/
|
|
3733
|
+
function checkRegexFlags(flags, targetNode) {
|
|
3734
|
+
const VALID_FLAGS = new Set(['g', 'i', 'm', 's', 'u', 'y']);
|
|
3735
|
+
const flagCounts = new Map();
|
|
3736
|
+
for (const flag of flags) {
|
|
3737
|
+
if (!VALID_FLAGS.has(flag)) {
|
|
3738
|
+
error(targetNode, `正则表达式标志符 "${flag}" 无效`);
|
|
3739
|
+
continue;
|
|
3740
|
+
}
|
|
3741
|
+
const count = (flagCounts.get(flag) || 0) + 1;
|
|
3742
|
+
flagCounts.set(flag, count);
|
|
3743
|
+
if (count > 1) {
|
|
3744
|
+
error(targetNode, `正则表达式标志符 "${flag}" 重复`);
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
}
|
|
3748
|
+
/**
|
|
3749
|
+
* 检查正则表达式语法和标志符
|
|
3750
|
+
*/
|
|
3720
3751
|
function checkNewRegex(node) {
|
|
3752
|
+
// 检查正则表达式模式语法
|
|
3753
|
+
if (nasl_concepts_1.asserts.isStringLiteral(node.pattern)) {
|
|
3754
|
+
const targetNode = node.kind === 'static' ? node : node.pattern;
|
|
3755
|
+
try {
|
|
3756
|
+
regeExp.parse(`/${node.pattern.value}/`);
|
|
3757
|
+
const parseErrors = regeExp.errors;
|
|
3758
|
+
if (Array.isArray(parseErrors) && parseErrors.length > 0) {
|
|
3759
|
+
parseErrors.forEach((errToken) => {
|
|
3760
|
+
const errorId = errToken?.error?.id;
|
|
3761
|
+
if (errorId) {
|
|
3762
|
+
error(targetNode, getRegexErrorMessage(errorId));
|
|
3763
|
+
}
|
|
3764
|
+
});
|
|
3765
|
+
}
|
|
3766
|
+
}
|
|
3767
|
+
catch (e) {
|
|
3768
|
+
error(targetNode, '正则表达式解析失败');
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
// 检查正则表达式标志符
|
|
3772
|
+
if (nasl_concepts_1.asserts.isStringLiteral(node.flags)) {
|
|
3773
|
+
const targetNode = node.kind === 'static' ? node : node.flags;
|
|
3774
|
+
checkRegexFlags(node.flags.value, targetNode);
|
|
3775
|
+
}
|
|
3721
3776
|
return env.getType(node);
|
|
3722
3777
|
}
|
|
3723
3778
|
/**
|
|
@@ -4130,6 +4185,10 @@ function createErrorDiagnoser(context) {
|
|
|
4130
4185
|
*/
|
|
4131
4186
|
function* checkUnaryExpression(node) {
|
|
4132
4187
|
if (ensureNodeKeyExists(node, 'argument')) {
|
|
4188
|
+
const isCandidate = ['!'].includes(node.operator);
|
|
4189
|
+
if (isCandidate) {
|
|
4190
|
+
yield* rejectNullLiteral(node.argument);
|
|
4191
|
+
}
|
|
4133
4192
|
yield* checkNode(node.argument);
|
|
4134
4193
|
}
|
|
4135
4194
|
return env.getType(node);
|