@lcap/nasl-language-server-core 4.4.1-rc.1 → 4.5.0-beta.1
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 +20 -116
- package/out/checker.js.map +1 -1
- package/out/typer/collectGlobalDefs.d.ts.map +1 -1
- package/out/typer/collectGlobalDefs.js +55 -7
- package/out/typer/collectGlobalDefs.js.map +1 -1
- package/out/typer/component-def-manager/component-def-manager.d.ts +65 -7
- package/out/typer/component-def-manager/component-def-manager.d.ts.map +1 -1
- package/out/typer/component-def-manager/component-def-manager.js +400 -8
- package/out/typer/component-def-manager/component-def-manager.js.map +1 -1
- package/out/typer/dispatch-view.d.ts.map +1 -1
- package/out/typer/dispatch-view.js +326 -142
- package/out/typer/dispatch-view.js.map +1 -1
- package/out/typer/subster.d.ts.map +1 -1
- package/out/typer/subster.js +49 -29
- package/out/typer/subster.js.map +1 -1
- package/out/typer/type-predicate.d.ts +14 -1
- package/out/typer/type-predicate.d.ts.map +1 -1
- package/out/typer/type-predicate.js +330 -14
- package/out/typer/type-predicate.js.map +1 -1
- package/out/typer/typer.d.ts +2 -0
- package/out/typer/typer.d.ts.map +1 -1
- package/out/typer/typer.js +2 -0
- package/out/typer/typer.js.map +1 -1
- package/out/typer/unifier.d.ts +8 -0
- package/out/typer/unifier.d.ts.map +1 -1
- package/out/typer/unifier.js +52 -0
- package/out/typer/unifier.js.map +1 -1
- package/package.json +7 -7
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,EAGT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACgE,cAAc,EAGpF,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAA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Q;2CAiyGxC,UAAU,gBACV,CAAC,YAAY,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,gBAC/C,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,qBACvB,MAAM,EAAE,oBACT,CAAC,YAAY,EAAE,UAAU,KAAK,UAAU,EAAE,KAC3D,kBAAkB,GAAG,IAAI;EAwF7B;AAqED,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
|
@@ -257,7 +257,7 @@ function createErrorDiagnoser(context) {
|
|
|
257
257
|
let env = context.env;
|
|
258
258
|
let isDebug = context.debug;
|
|
259
259
|
// 严格模式
|
|
260
|
-
let
|
|
260
|
+
let isAIStrictMode = context.isAIStrictMode;
|
|
261
261
|
// 引用管理器
|
|
262
262
|
let referenceManager = env.refMgr;
|
|
263
263
|
// 检查共享数据是否有更新
|
|
@@ -792,24 +792,27 @@ function createErrorDiagnoser(context) {
|
|
|
792
792
|
return false;
|
|
793
793
|
}
|
|
794
794
|
/**
|
|
795
|
-
* 获取 ViewElement
|
|
796
|
-
*
|
|
795
|
+
* 获取 ViewElement 的数据源类型
|
|
796
|
+
* 基于 __ViewElementTV 中存储的 role === 'dataItem' 查找,优先返回有自有数据源的 dataItem。
|
|
797
797
|
*/
|
|
798
798
|
function getDataSourceTypeAnnotation(viewElement) {
|
|
799
|
-
// 向上查找定义了数据源类型的祖先组件
|
|
800
799
|
let currentNode = viewElement;
|
|
801
800
|
let depth = 0;
|
|
802
801
|
const maxSearchDepth = 5;
|
|
803
802
|
while (currentNode?.concept === 'ViewElement' && depth <= maxSearchDepth) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
803
|
+
if (currentNode.__ViewElementTV?.length) {
|
|
804
|
+
// 优先查找有自有数据源的 dataItem(如动态列的 T1)
|
|
805
|
+
for (const tv of currentNode.__ViewElementTV) {
|
|
806
|
+
if (tv.role === 'dataItem' && tv.hasOwnDataSource && tv.renamed) {
|
|
807
|
+
return tv.renamed;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
// 兜底查找无自有数据源的 dataItem(如子组件继承的 T)
|
|
811
|
+
for (const tv of currentNode.__ViewElementTV) {
|
|
812
|
+
if (tv.role === 'dataItem' && tv.renamed) {
|
|
813
|
+
return tv.renamed;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
813
816
|
}
|
|
814
817
|
currentNode = currentNode.parentNode;
|
|
815
818
|
depth++;
|
|
@@ -899,7 +902,7 @@ function createErrorDiagnoser(context) {
|
|
|
899
902
|
continue;
|
|
900
903
|
}
|
|
901
904
|
// 严格模式非必填也需要有Argument占位
|
|
902
|
-
if (
|
|
905
|
+
if (isAIStrictMode || !isNonRequiredParam(param)) {
|
|
903
906
|
minArgsCount++; // 如果参数有默认值,则跳过
|
|
904
907
|
}
|
|
905
908
|
}
|
|
@@ -1018,7 +1021,7 @@ function createErrorDiagnoser(context) {
|
|
|
1018
1021
|
}
|
|
1019
1022
|
else if (argsLen < minArgsCount) {
|
|
1020
1023
|
let msg = `传入参数的个数 ${argsLen} 与 ${getExpressionNodeName(node.concept)} 定义的参数个数 ${paramsLen} 不符。`;
|
|
1021
|
-
if (
|
|
1024
|
+
if (isAIStrictMode) {
|
|
1022
1025
|
msg += `可选参数和默认值参数必须用 undefined 占位`;
|
|
1023
1026
|
}
|
|
1024
1027
|
error(node, msg);
|
|
@@ -1777,7 +1780,7 @@ function createErrorDiagnoser(context) {
|
|
|
1777
1780
|
const decimalPlaces = value?.split('.')[1]?.length || 0;
|
|
1778
1781
|
if (decimalPlaces > +scale) {
|
|
1779
1782
|
error(node, `实体字段${node.name}默认值的小数位数不能大于设置的小数位数${scale},否则将会按照小数位数自动截断`, {
|
|
1780
|
-
severity:
|
|
1783
|
+
severity: isAIStrictMode ? Severity.ERROR : Severity.WARN,
|
|
1781
1784
|
});
|
|
1782
1785
|
}
|
|
1783
1786
|
}
|
|
@@ -4313,97 +4316,6 @@ function createErrorDiagnoser(context) {
|
|
|
4313
4316
|
}
|
|
4314
4317
|
return env.getType(node);
|
|
4315
4318
|
}
|
|
4316
|
-
/**
|
|
4317
|
-
* 递归检查赋值类型不兼容问题
|
|
4318
|
-
* 检查左侧类型(Decimal/Long)是否与右侧联合类型(Union<Decimal, Long>)不兼容
|
|
4319
|
-
* @param leftType 左侧类型
|
|
4320
|
-
* @param rightType 右侧类型
|
|
4321
|
-
* @param context 上下文信息,用于生成错误消息
|
|
4322
|
-
* @param allowImplicitConversion 是否允许隐式类型转换(仅对直接的基础类型赋值允许,复杂类型内部不允许)
|
|
4323
|
-
* @returns 所有类型不兼容的错误信息数组
|
|
4324
|
-
*/
|
|
4325
|
-
function checkAssignmentTypeIncompatibility(leftType, rightType, context = {}, allowImplicitConversion = true) {
|
|
4326
|
-
if (!leftType || !rightType)
|
|
4327
|
-
return [];
|
|
4328
|
-
const errors = [];
|
|
4329
|
-
// 先检查 Decimal/Long vs Union<Decimal, Long> 的情况(需要先于其他检查)
|
|
4330
|
-
// 这种情况应该报错,即使允许隐式转换
|
|
4331
|
-
if (allowImplicitConversion) {
|
|
4332
|
-
const isLeftPrimitive = leftType.typeKind === 'primitive';
|
|
4333
|
-
const isLeftDecimalOrLong = isLeftPrimitive && (leftType.typeName === 'Decimal' || leftType.typeName === 'Long');
|
|
4334
|
-
if (isLeftDecimalOrLong && (0, type_predicate_1.isDecimalUnionLongTy)(rightType)) {
|
|
4335
|
-
const prefix = context.prefix || '赋值';
|
|
4336
|
-
const fieldInfo = context.fieldName ? `字段 ${context.fieldName} ` : '';
|
|
4337
|
-
errors.push(`${prefix}:${fieldInfo}类型不匹配,不能将 ${(0, type_manager_1.showUserLevelType)(rightType)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftType)} 类型。`);
|
|
4338
|
-
return errors; // 找到基本类型错误后直接返回,不再检查嵌套
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
// 检查基础类型是否严格相等(不允许隐式转换)
|
|
4342
|
-
const isLeftPrimitive = leftType.typeKind === 'primitive';
|
|
4343
|
-
const isRightPrimitive = rightType.typeKind === 'primitive';
|
|
4344
|
-
if (isLeftPrimitive && isRightPrimitive) {
|
|
4345
|
-
// 如果不允许隐式转换,则要求类型完全相等
|
|
4346
|
-
if (!allowImplicitConversion) {
|
|
4347
|
-
if (leftType.typeName !== rightType.typeName || leftType.typeNamespace !== rightType.typeNamespace) {
|
|
4348
|
-
const prefix = context.prefix || '赋值';
|
|
4349
|
-
const fieldInfo = context.fieldName ? `字段 ${context.fieldName} ` : '';
|
|
4350
|
-
errors.push(`${prefix}:${fieldInfo}类型不匹配,不能将 ${(0, type_manager_1.showUserLevelType)(rightType)} 赋值给 ${(0, type_manager_1.showUserLevelType)(leftType)} 类型。`);
|
|
4351
|
-
return errors;
|
|
4352
|
-
}
|
|
4353
|
-
// 类型完全相等,没有错误,继续检查其他情况
|
|
4354
|
-
}
|
|
4355
|
-
else {
|
|
4356
|
-
// 允许隐式转换的情况下,检查是否通过 isSubTy 检查(允许隐式转换)
|
|
4357
|
-
if ((0, type_predicate_1.isSubTy)(env, rightType, leftType)) {
|
|
4358
|
-
// 类型兼容(允许隐式转换),没有错误,继续检查其他情况
|
|
4359
|
-
}
|
|
4360
|
-
// 如果 isSubTy 返回 false,继续检查其他不兼容的情况
|
|
4361
|
-
}
|
|
4362
|
-
}
|
|
4363
|
-
// 2. 检查 List 类型(包括嵌套):List<T> vs List<Union<...>>
|
|
4364
|
-
if (leftType.typeKind === 'generic' &&
|
|
4365
|
-
leftType.typeName === 'List' &&
|
|
4366
|
-
rightType.typeKind === 'generic' &&
|
|
4367
|
-
rightType.typeName === 'List' &&
|
|
4368
|
-
leftType.typeArguments?.[0] &&
|
|
4369
|
-
rightType.typeArguments?.[0]) {
|
|
4370
|
-
// 递归检查 List 的元素类型,嵌套类型内部不允许隐式转换
|
|
4371
|
-
return checkAssignmentTypeIncompatibility(leftType.typeArguments[0], rightType.typeArguments[0], { ...context, prefix: context.prefix || '赋值' }, false // 嵌套类型内部不允许隐式转换
|
|
4372
|
-
);
|
|
4373
|
-
}
|
|
4374
|
-
// 3. 检查 Map 类型(包括嵌套):Map<K, V> vs Map<K, Union<...>>
|
|
4375
|
-
if (leftType.typeKind === 'generic' &&
|
|
4376
|
-
leftType.typeName === 'Map' &&
|
|
4377
|
-
rightType.typeKind === 'generic' &&
|
|
4378
|
-
rightType.typeName === 'Map' &&
|
|
4379
|
-
leftType.typeArguments?.length === 2 &&
|
|
4380
|
-
rightType.typeArguments?.length === 2) {
|
|
4381
|
-
// 递归检查 Map 的值类型(第二个类型参数),嵌套类型内部不允许隐式转换
|
|
4382
|
-
const valueTypeErrors = checkAssignmentTypeIncompatibility(leftType.typeArguments[1], rightType.typeArguments[1], { ...context, prefix: context.prefix || '赋值' }, false // 嵌套类型内部不允许隐式转换
|
|
4383
|
-
);
|
|
4384
|
-
errors.push(...valueTypeErrors);
|
|
4385
|
-
// 也检查键类型(第一个类型参数),嵌套类型内部不允许隐式转换
|
|
4386
|
-
const keyTypeErrors = checkAssignmentTypeIncompatibility(leftType.typeArguments[0], rightType.typeArguments[0], { ...context, prefix: context.prefix || '赋值' }, false // 嵌套类型内部不允许隐式转换
|
|
4387
|
-
);
|
|
4388
|
-
errors.push(...keyTypeErrors);
|
|
4389
|
-
return errors;
|
|
4390
|
-
}
|
|
4391
|
-
// 4. 检查匿名结构体:递归检查每个字段,收集所有字段的错误
|
|
4392
|
-
if ((0, type_predicate_1.isAnonymousTy)(leftType) && (0, type_predicate_1.isAnonymousTy)(rightType)) {
|
|
4393
|
-
const leftProps = leftType.properties ?? [];
|
|
4394
|
-
const rightProps = rightType.properties ?? [];
|
|
4395
|
-
for (const leftProp of leftProps) {
|
|
4396
|
-
const rightProp = rightProps.find(p => p.name === leftProp.name);
|
|
4397
|
-
if (rightProp && leftProp.typeAnnotation && rightProp.typeAnnotation) {
|
|
4398
|
-
// 匿名结构体的字段类型检查不允许隐式转换
|
|
4399
|
-
const fieldErrors = checkAssignmentTypeIncompatibility(leftProp.typeAnnotation, rightProp.typeAnnotation, { prefix: context.prefix || '赋值', fieldName: leftProp.name }, false // 复杂类型内部不允许隐式转换
|
|
4400
|
-
);
|
|
4401
|
-
errors.push(...fieldErrors); // 收集所有字段的错误,不提前返回
|
|
4402
|
-
}
|
|
4403
|
-
}
|
|
4404
|
-
}
|
|
4405
|
-
return errors;
|
|
4406
|
-
}
|
|
4407
4319
|
/**
|
|
4408
4320
|
* 检查 赋值语句
|
|
4409
4321
|
* @param node
|
|
@@ -4415,14 +4327,6 @@ function createErrorDiagnoser(context) {
|
|
|
4415
4327
|
if (ensureNodeKeyExists(node, 'right')) {
|
|
4416
4328
|
yield* checkNode(node.right);
|
|
4417
4329
|
}
|
|
4418
|
-
// 使用统一的类型兼容性检查
|
|
4419
|
-
const leftType = env.getType(node.left);
|
|
4420
|
-
const rightType = env.getType(node.right);
|
|
4421
|
-
const errorMessages = checkAssignmentTypeIncompatibility(leftType, rightType);
|
|
4422
|
-
// 报告所有错误
|
|
4423
|
-
errorMessages.forEach(errorMessage => {
|
|
4424
|
-
error(node, errorMessage);
|
|
4425
|
-
});
|
|
4426
4330
|
if (nasl_concepts_1.asserts.isMemberExpression(node.left)) {
|
|
4427
4331
|
reportCurrentItemModification(node.left, node);
|
|
4428
4332
|
}
|
|
@@ -4488,7 +4392,7 @@ function createErrorDiagnoser(context) {
|
|
|
4488
4392
|
error(args[i], '当前参数无效,不可用。');
|
|
4489
4393
|
}
|
|
4490
4394
|
}
|
|
4491
|
-
if (
|
|
4395
|
+
if (isAIStrictMode) {
|
|
4492
4396
|
yield* checkCallExpressionParameters(node, ref);
|
|
4493
4397
|
}
|
|
4494
4398
|
}
|