typescript 5.3.0-dev.20230929 → 5.3.0-dev.20230930
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/lib/tsc.js +138 -30
- package/lib/tsserver.js +159 -45
- package/lib/typescript.d.ts +4 -1
- package/lib/typescript.js +156 -44
- package/lib/typingsInstaller.js +6 -5
- package/package.json +2 -2
package/lib/tsc.js
CHANGED
|
@@ -18,7 +18,7 @@ and limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
// src/compiler/corePublic.ts
|
|
20
20
|
var versionMajorMinor = "5.3";
|
|
21
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
21
|
+
var version = `${versionMajorMinor}.0-dev.20230930`;
|
|
22
22
|
|
|
23
23
|
// src/compiler/core.ts
|
|
24
24
|
var emptyArray = [];
|
|
@@ -6202,7 +6202,7 @@ var Diagnostics = {
|
|
|
6202
6202
|
An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2356, 1 /* Error */, "An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type_2356", "An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type."),
|
|
6203
6203
|
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access: diag(2357, 1 /* Error */, "The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access_2357", "The operand of an increment or decrement operator must be a variable or a property access."),
|
|
6204
6204
|
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: diag(2358, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358", "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter."),
|
|
6205
|
-
|
|
6205
|
+
The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_a_class_function_or_other_type_assignable_to_the_Function_interface_type_or_an_object_type_with_a_Symbol_hasInstance_method: diag(2359, 1 /* Error */, "The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_a_class_function_or_other_2359", "The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method."),
|
|
6206
6206
|
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2362, 1 /* Error */, "The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2362", "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
|
|
6207
6207
|
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type: diag(2363, 1 /* Error */, "The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type_2363", "The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type."),
|
|
6208
6208
|
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access: diag(2364, 1 /* Error */, "The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access_2364", "The left-hand side of an assignment expression must be a variable or a property access."),
|
|
@@ -6651,6 +6651,8 @@ var Diagnostics = {
|
|
|
6651
6651
|
Import_attributes_cannot_be_used_with_type_only_imports_or_exports: diag(2857, 1 /* Error */, "Import_attributes_cannot_be_used_with_type_only_imports_or_exports_2857", "Import attributes cannot be used with type-only imports or exports."),
|
|
6652
6652
|
Import_attribute_values_must_be_string_literal_expressions: diag(2858, 1 /* Error */, "Import_attribute_values_must_be_string_literal_expressions_2858", "Import attribute values must be string literal expressions."),
|
|
6653
6653
|
Excessive_complexity_comparing_types_0_and_1: diag(2859, 1 /* Error */, "Excessive_complexity_comparing_types_0_and_1_2859", "Excessive complexity comparing types '{0}' and '{1}'."),
|
|
6654
|
+
The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method: diag(2860, 1 /* Error */, "The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_2860", "The left-hand side of an 'instanceof' expression must be assignable to the first argument of the right-hand side's '[Symbol.hasInstance]' method."),
|
|
6655
|
+
An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_hand_side_of_an_instanceof_expression: diag(2861, 1 /* Error */, "An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_han_2861", "An object's '[Symbol.hasInstance]' method must return a boolean value for it to be used on the right-hand side of an 'instanceof' expression."),
|
|
6654
6656
|
Import_declaration_0_is_using_private_name_1: diag(4e3, 1 /* Error */, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
|
|
6655
6657
|
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, 1 /* Error */, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
|
|
6656
6658
|
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, 1 /* Error */, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
|
|
@@ -10813,7 +10815,14 @@ function isAccessor(node) {
|
|
|
10813
10815
|
function isAutoAccessorPropertyDeclaration(node) {
|
|
10814
10816
|
return isPropertyDeclaration(node) && hasAccessorModifier(node);
|
|
10815
10817
|
}
|
|
10816
|
-
function
|
|
10818
|
+
function isClassInstanceProperty(node) {
|
|
10819
|
+
if (isInJSFile(node) && isExpandoPropertyDeclaration(node)) {
|
|
10820
|
+
return (!isBindableStaticAccessExpression(node) || !isPrototypeAccess(node.expression)) && !isBindableStaticNameExpression(
|
|
10821
|
+
node,
|
|
10822
|
+
/*excludeThisKeyword*/
|
|
10823
|
+
true
|
|
10824
|
+
);
|
|
10825
|
+
}
|
|
10817
10826
|
return node.parent && isClassLike(node.parent) && isPropertyDeclaration(node) && !hasAccessorModifier(node);
|
|
10818
10827
|
}
|
|
10819
10828
|
function isMethodOrAccessor(node) {
|
|
@@ -13076,6 +13085,8 @@ function getInvokedExpression(node) {
|
|
|
13076
13085
|
case 286 /* JsxOpeningElement */:
|
|
13077
13086
|
case 285 /* JsxSelfClosingElement */:
|
|
13078
13087
|
return node.tagName;
|
|
13088
|
+
case 226 /* BinaryExpression */:
|
|
13089
|
+
return node.right;
|
|
13079
13090
|
default:
|
|
13080
13091
|
return node.expression;
|
|
13081
13092
|
}
|
|
@@ -15582,6 +15593,12 @@ function isRightSideOfAccessExpression(node) {
|
|
|
15582
15593
|
function isRightSideOfQualifiedNameOrPropertyAccessOrJSDocMemberName(node) {
|
|
15583
15594
|
return isQualifiedName(node.parent) && node.parent.right === node || isPropertyAccessExpression(node.parent) && node.parent.name === node || isJSDocMemberName(node.parent) && node.parent.right === node;
|
|
15584
15595
|
}
|
|
15596
|
+
function isInstanceOfExpression(node) {
|
|
15597
|
+
return isBinaryExpression(node) && node.operatorToken.kind === 104 /* InstanceOfKeyword */;
|
|
15598
|
+
}
|
|
15599
|
+
function isRightSideOfInstanceofExpression(node) {
|
|
15600
|
+
return isInstanceOfExpression(node.parent) && node === node.parent.right;
|
|
15601
|
+
}
|
|
15585
15602
|
function isEmptyObjectLiteral(expression) {
|
|
15586
15603
|
return expression.kind === 210 /* ObjectLiteralExpression */ && expression.properties.length === 0;
|
|
15587
15604
|
}
|
|
@@ -43069,9 +43086,8 @@ var CheckMode = /* @__PURE__ */ ((CheckMode3) => {
|
|
|
43069
43086
|
CheckMode3[CheckMode3["SkipContextSensitive"] = 4] = "SkipContextSensitive";
|
|
43070
43087
|
CheckMode3[CheckMode3["SkipGenericFunctions"] = 8] = "SkipGenericFunctions";
|
|
43071
43088
|
CheckMode3[CheckMode3["IsForSignatureHelp"] = 16] = "IsForSignatureHelp";
|
|
43072
|
-
CheckMode3[CheckMode3["
|
|
43073
|
-
CheckMode3[CheckMode3["
|
|
43074
|
-
CheckMode3[CheckMode3["TypeOnly"] = 128] = "TypeOnly";
|
|
43089
|
+
CheckMode3[CheckMode3["RestBindingElement"] = 32] = "RestBindingElement";
|
|
43090
|
+
CheckMode3[CheckMode3["TypeOnly"] = 64] = "TypeOnly";
|
|
43075
43091
|
return CheckMode3;
|
|
43076
43092
|
})(CheckMode || {});
|
|
43077
43093
|
var SignatureCheckMode = /* @__PURE__ */ ((SignatureCheckMode3) => {
|
|
@@ -43558,7 +43574,7 @@ function createTypeChecker(host) {
|
|
|
43558
43574
|
candidates,
|
|
43559
43575
|
/*argumentCount*/
|
|
43560
43576
|
void 0,
|
|
43561
|
-
|
|
43577
|
+
0 /* Normal */
|
|
43562
43578
|
));
|
|
43563
43579
|
for (const candidate of candidates) {
|
|
43564
43580
|
candidatesSet.add(candidate);
|
|
@@ -51593,7 +51609,7 @@ function createTypeChecker(host) {
|
|
|
51593
51609
|
return type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */) ? "" + type.value : void 0;
|
|
51594
51610
|
}
|
|
51595
51611
|
function getTypeForBindingElement(declaration) {
|
|
51596
|
-
const checkMode = declaration.dotDotDotToken ?
|
|
51612
|
+
const checkMode = declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
|
|
51597
51613
|
const parentType = getTypeForBindingElementParent(declaration.parent.parent, checkMode);
|
|
51598
51614
|
return parentType && getBindingElementTypeFromParentType(
|
|
51599
51615
|
declaration,
|
|
@@ -63760,7 +63776,7 @@ function createTypeChecker(host) {
|
|
|
63760
63776
|
if (!couldContainTypeVariables(target)) {
|
|
63761
63777
|
return;
|
|
63762
63778
|
}
|
|
63763
|
-
if (source === wildcardType) {
|
|
63779
|
+
if (source === wildcardType || source === blockedStringType) {
|
|
63764
63780
|
const savePropagationType = propagationType;
|
|
63765
63781
|
propagationType = source;
|
|
63766
63782
|
inferFromTypes(target, target);
|
|
@@ -63817,6 +63833,10 @@ function createTypeChecker(host) {
|
|
|
63817
63833
|
return;
|
|
63818
63834
|
}
|
|
63819
63835
|
if (!inference.isFixed) {
|
|
63836
|
+
const candidate = propagationType || source;
|
|
63837
|
+
if (candidate === blockedStringType) {
|
|
63838
|
+
return;
|
|
63839
|
+
}
|
|
63820
63840
|
if (inference.priority === void 0 || priority < inference.priority) {
|
|
63821
63841
|
inference.candidates = void 0;
|
|
63822
63842
|
inference.contraCandidates = void 0;
|
|
@@ -63824,7 +63844,6 @@ function createTypeChecker(host) {
|
|
|
63824
63844
|
inference.priority = priority;
|
|
63825
63845
|
}
|
|
63826
63846
|
if (priority === inference.priority) {
|
|
63827
|
-
const candidate = propagationType || source;
|
|
63828
63847
|
if (contravariant && !bivariant) {
|
|
63829
63848
|
if (!contains(inference.contraCandidates, candidate)) {
|
|
63830
63849
|
inference.contraCandidates = append(inference.contraCandidates, candidate);
|
|
@@ -64396,7 +64415,7 @@ function createTypeChecker(host) {
|
|
|
64396
64415
|
const constraint = getConstraintOfTypeParameter(inference.typeParameter);
|
|
64397
64416
|
if (constraint) {
|
|
64398
64417
|
const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper);
|
|
64399
|
-
if (!inferredType ||
|
|
64418
|
+
if (!inferredType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
|
|
64400
64419
|
inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint;
|
|
64401
64420
|
}
|
|
64402
64421
|
}
|
|
@@ -65247,7 +65266,10 @@ function createTypeChecker(host) {
|
|
|
65247
65266
|
let signature = links.effectsSignature;
|
|
65248
65267
|
if (signature === void 0) {
|
|
65249
65268
|
let funcType;
|
|
65250
|
-
if (node
|
|
65269
|
+
if (isBinaryExpression(node)) {
|
|
65270
|
+
const rightType = checkNonNullExpression(node.right);
|
|
65271
|
+
funcType = getSymbolHasInstanceMethodOfObjectType(rightType);
|
|
65272
|
+
} else if (node.parent.kind === 244 /* ExpressionStatement */) {
|
|
65251
65273
|
funcType = getTypeOfDottedName(
|
|
65252
65274
|
node.expression,
|
|
65253
65275
|
/*diagnostic*/
|
|
@@ -66271,7 +66293,22 @@ function createTypeChecker(host) {
|
|
|
66271
66293
|
}
|
|
66272
66294
|
return type;
|
|
66273
66295
|
}
|
|
66274
|
-
const
|
|
66296
|
+
const right = expr.right;
|
|
66297
|
+
const rightType = getTypeOfExpression(right);
|
|
66298
|
+
if (!isTypeDerivedFrom(rightType, globalObjectType)) {
|
|
66299
|
+
return type;
|
|
66300
|
+
}
|
|
66301
|
+
const signature = getEffectsSignature(expr);
|
|
66302
|
+
const predicate = signature && getTypePredicateOfSignature(signature);
|
|
66303
|
+
if (predicate && predicate.kind === 1 /* Identifier */ && predicate.parameterIndex === 0) {
|
|
66304
|
+
return getNarrowedType(
|
|
66305
|
+
type,
|
|
66306
|
+
predicate.type,
|
|
66307
|
+
assumeTrue,
|
|
66308
|
+
/*checkDerived*/
|
|
66309
|
+
true
|
|
66310
|
+
);
|
|
66311
|
+
}
|
|
66275
66312
|
if (!isTypeDerivedFrom(rightType, globalFunctionType)) {
|
|
66276
66313
|
return type;
|
|
66277
66314
|
}
|
|
@@ -66523,7 +66560,7 @@ function createTypeChecker(host) {
|
|
|
66523
66560
|
return type.flags & 2097152 /* Intersection */ ? some(type.types, isGenericTypeWithoutNullableConstraint) : !!(type.flags & 465829888 /* Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* Nullable */));
|
|
66524
66561
|
}
|
|
66525
66562
|
function hasContextualTypeWithNoGenericTypes(node, checkMode) {
|
|
66526
|
-
const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) && !((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) && (checkMode && checkMode &
|
|
66563
|
+
const contextualType = (isIdentifier(node) || isPropertyAccessExpression(node) || isElementAccessExpression(node)) && !((isJsxOpeningElement(node.parent) || isJsxSelfClosingElement(node.parent)) && node.parent.tagName === node) && (checkMode && checkMode & 32 /* RestBindingElement */ ? getContextualType(node, 8 /* SkipBindingPatterns */) : getContextualType(
|
|
66527
66564
|
node,
|
|
66528
66565
|
/*contextFlags*/
|
|
66529
66566
|
void 0
|
|
@@ -67283,7 +67320,7 @@ function createTypeChecker(host) {
|
|
|
67283
67320
|
function getContextualTypeForBindingElement(declaration, contextFlags) {
|
|
67284
67321
|
const parent = declaration.parent.parent;
|
|
67285
67322
|
const name = declaration.propertyName || declaration.name;
|
|
67286
|
-
const parentType = getContextualTypeForVariableLikeDeclaration(parent, contextFlags) || parent.kind !== 208 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ?
|
|
67323
|
+
const parentType = getContextualTypeForVariableLikeDeclaration(parent, contextFlags) || parent.kind !== 208 /* BindingElement */ && parent.initializer && checkDeclarationInitializer(parent, declaration.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */);
|
|
67287
67324
|
if (!parentType || isBindingPattern(name) || isComputedNonLiteralName(name))
|
|
67288
67325
|
return void 0;
|
|
67289
67326
|
if (parent.name.kind === 207 /* ArrayBindingPattern */) {
|
|
@@ -69266,7 +69303,7 @@ function createTypeChecker(host) {
|
|
|
69266
69303
|
}
|
|
69267
69304
|
return false;
|
|
69268
69305
|
}
|
|
69269
|
-
if (!(flags & 32 /* Static */) && ((_a = prop.declarations) == null ? void 0 : _a.some(
|
|
69306
|
+
if (!(flags & 32 /* Static */) && ((_a = prop.declarations) == null ? void 0 : _a.some(isClassInstanceProperty))) {
|
|
69270
69307
|
if (errorNode) {
|
|
69271
69308
|
error(errorNode, Diagnostics.Class_field_0_defined_by_the_parent_class_is_not_accessible_in_the_child_class_via_super, symbolToString(prop));
|
|
69272
69309
|
}
|
|
@@ -70129,7 +70166,9 @@ function createTypeChecker(host) {
|
|
|
70129
70166
|
checkExpression(node.template);
|
|
70130
70167
|
} else if (isJsxOpeningLikeElement(node)) {
|
|
70131
70168
|
checkExpression(node.attributes);
|
|
70132
|
-
} else if (node
|
|
70169
|
+
} else if (isBinaryExpression(node)) {
|
|
70170
|
+
checkExpression(node.left);
|
|
70171
|
+
} else if (isCallOrNewExpression(node)) {
|
|
70133
70172
|
forEach(node.arguments, (argument) => {
|
|
70134
70173
|
checkExpression(argument);
|
|
70135
70174
|
});
|
|
@@ -70202,6 +70241,8 @@ function createTypeChecker(host) {
|
|
|
70202
70241
|
}
|
|
70203
70242
|
} else if (node.kind === 170 /* Decorator */) {
|
|
70204
70243
|
argCount = getDecoratorArgumentCount(node, signature);
|
|
70244
|
+
} else if (node.kind === 226 /* BinaryExpression */) {
|
|
70245
|
+
argCount = 1;
|
|
70205
70246
|
} else if (isJsxOpeningLikeElement(node)) {
|
|
70206
70247
|
callIsIncomplete = node.attributes.end === node.end;
|
|
70207
70248
|
if (callIsIncomplete) {
|
|
@@ -70301,13 +70342,13 @@ function createTypeChecker(host) {
|
|
|
70301
70342
|
return voidType;
|
|
70302
70343
|
}
|
|
70303
70344
|
const thisArgumentType = checkExpression(thisArgumentNode);
|
|
70304
|
-
return isOptionalChainRoot(thisArgumentNode.parent) ? getNonNullableType(thisArgumentType) : isOptionalChain(thisArgumentNode.parent) ? removeOptionalTypeMarker(thisArgumentType) : thisArgumentType;
|
|
70345
|
+
return isRightSideOfInstanceofExpression(thisArgumentNode) ? thisArgumentType : isOptionalChainRoot(thisArgumentNode.parent) ? getNonNullableType(thisArgumentType) : isOptionalChain(thisArgumentNode.parent) ? removeOptionalTypeMarker(thisArgumentType) : thisArgumentType;
|
|
70305
70346
|
}
|
|
70306
70347
|
function inferTypeArguments(node, signature, args, checkMode, context) {
|
|
70307
70348
|
if (isJsxOpeningLikeElement(node)) {
|
|
70308
70349
|
return inferJsxTypeArguments(node, signature, checkMode, context);
|
|
70309
70350
|
}
|
|
70310
|
-
if (node.kind !== 170 /* Decorator */) {
|
|
70351
|
+
if (node.kind !== 170 /* Decorator */ && node.kind !== 226 /* BinaryExpression */) {
|
|
70311
70352
|
const skipBindingPatterns = every(signature.typeParameters, (p) => !!getDefaultFromTypeParameter(p));
|
|
70312
70353
|
const contextualType = getContextualType(node, skipBindingPatterns ? 8 /* SkipBindingPatterns */ : 0 /* None */);
|
|
70313
70354
|
if (contextualType) {
|
|
@@ -70344,7 +70385,7 @@ function createTypeChecker(host) {
|
|
|
70344
70385
|
}
|
|
70345
70386
|
for (let i = 0; i < argCount; i++) {
|
|
70346
70387
|
const arg = args[i];
|
|
70347
|
-
if (arg.kind !== 232 /* OmittedExpression */
|
|
70388
|
+
if (arg.kind !== 232 /* OmittedExpression */) {
|
|
70348
70389
|
const paramType = getTypeAtPosition(signature, i);
|
|
70349
70390
|
if (couldContainTypeVariables(paramType)) {
|
|
70350
70391
|
const argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
|
|
@@ -70636,6 +70677,9 @@ function createTypeChecker(host) {
|
|
|
70636
70677
|
}
|
|
70637
70678
|
}
|
|
70638
70679
|
function getThisArgumentOfCall(node) {
|
|
70680
|
+
if (node.kind === 226 /* BinaryExpression */) {
|
|
70681
|
+
return node.right;
|
|
70682
|
+
}
|
|
70639
70683
|
const expression = node.kind === 213 /* CallExpression */ ? node.expression : node.kind === 215 /* TaggedTemplateExpression */ ? node.tag : node.kind === 170 /* Decorator */ && !legacyDecorators ? node.expression : void 0;
|
|
70640
70684
|
if (expression) {
|
|
70641
70685
|
const callee = skipOuterExpressions(expression);
|
|
@@ -70664,6 +70708,9 @@ function createTypeChecker(host) {
|
|
|
70664
70708
|
if (node.kind === 170 /* Decorator */) {
|
|
70665
70709
|
return getEffectiveDecoratorArguments(node);
|
|
70666
70710
|
}
|
|
70711
|
+
if (node.kind === 226 /* BinaryExpression */) {
|
|
70712
|
+
return [node.left];
|
|
70713
|
+
}
|
|
70667
70714
|
if (isJsxOpeningLikeElement(node)) {
|
|
70668
70715
|
return node.attributes.properties.length > 0 || isJsxOpeningElement(node) && node.parent.children.length > 0 ? [node.attributes] : emptyArray;
|
|
70669
70716
|
}
|
|
@@ -70933,9 +70980,10 @@ function createTypeChecker(host) {
|
|
|
70933
70980
|
const isTaggedTemplate = node.kind === 215 /* TaggedTemplateExpression */;
|
|
70934
70981
|
const isDecorator2 = node.kind === 170 /* Decorator */;
|
|
70935
70982
|
const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
|
|
70983
|
+
const isInstanceof = node.kind === 226 /* BinaryExpression */;
|
|
70936
70984
|
const reportErrors2 = !isInferencePartiallyBlocked && !candidatesOutArray;
|
|
70937
70985
|
let typeArguments;
|
|
70938
|
-
if (!isDecorator2 && !isSuperCall(node)) {
|
|
70986
|
+
if (!isDecorator2 && !isInstanceof && !isSuperCall(node)) {
|
|
70939
70987
|
typeArguments = node.typeArguments;
|
|
70940
70988
|
if (isTaggedTemplate || isJsxOpeningOrSelfClosingElement || node.expression.kind !== 108 /* SuperKeyword */) {
|
|
70941
70989
|
forEach(typeArguments, checkSourceElement);
|
|
@@ -70947,7 +70995,6 @@ function createTypeChecker(host) {
|
|
|
70947
70995
|
const args = getEffectiveCallArguments(node);
|
|
70948
70996
|
const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
|
|
70949
70997
|
let argCheckMode = !isDecorator2 && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? 4 /* SkipContextSensitive */ : 0 /* Normal */;
|
|
70950
|
-
argCheckMode |= checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
|
|
70951
70998
|
let candidatesForArgumentError;
|
|
70952
70999
|
let candidateForArgumentArityError;
|
|
70953
71000
|
let candidateForTypeArgumentError;
|
|
@@ -70965,6 +71012,9 @@ function createTypeChecker(host) {
|
|
|
70965
71012
|
result = getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray, checkMode);
|
|
70966
71013
|
getNodeLinks(node).resolvedSignature = result;
|
|
70967
71014
|
if (reportErrors2) {
|
|
71015
|
+
if (!headMessage && isInstanceof) {
|
|
71016
|
+
headMessage = Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_assignable_to_the_first_argument_of_the_right_hand_side_s_Symbol_hasInstance_method;
|
|
71017
|
+
}
|
|
70968
71018
|
if (candidatesForArgumentError) {
|
|
70969
71019
|
if (candidatesForArgumentError.length === 1 || candidatesForArgumentError.length > 3) {
|
|
70970
71020
|
const last2 = candidatesForArgumentError[candidatesForArgumentError.length - 1];
|
|
@@ -71751,6 +71801,30 @@ function createTypeChecker(host) {
|
|
|
71751
71801
|
}
|
|
71752
71802
|
return resolveCall(node, signatures, candidatesOutArray, checkMode, 0 /* None */);
|
|
71753
71803
|
}
|
|
71804
|
+
function resolveInstanceofExpression(node, candidatesOutArray, checkMode) {
|
|
71805
|
+
const rightType = checkExpression(node.right);
|
|
71806
|
+
if (!isTypeAny(rightType)) {
|
|
71807
|
+
const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(rightType);
|
|
71808
|
+
if (hasInstanceMethodType) {
|
|
71809
|
+
const apparentType = getApparentType(hasInstanceMethodType);
|
|
71810
|
+
if (isErrorType(apparentType)) {
|
|
71811
|
+
return resolveErrorCall(node);
|
|
71812
|
+
}
|
|
71813
|
+
const callSignatures = getSignaturesOfType(apparentType, 0 /* Call */);
|
|
71814
|
+
const constructSignatures = getSignaturesOfType(apparentType, 1 /* Construct */);
|
|
71815
|
+
if (isUntypedFunctionCall(hasInstanceMethodType, apparentType, callSignatures.length, constructSignatures.length)) {
|
|
71816
|
+
return resolveUntypedCall(node);
|
|
71817
|
+
}
|
|
71818
|
+
if (callSignatures.length) {
|
|
71819
|
+
return resolveCall(node, callSignatures, candidatesOutArray, checkMode, 0 /* None */);
|
|
71820
|
+
}
|
|
71821
|
+
} else if (!(typeHasCallOrConstructSignatures(rightType) || isTypeSubtypeOf(rightType, globalFunctionType))) {
|
|
71822
|
+
error(node.right, Diagnostics.The_right_hand_side_of_an_instanceof_expression_must_be_either_of_type_any_a_class_function_or_other_type_assignable_to_the_Function_interface_type_or_an_object_type_with_a_Symbol_hasInstance_method);
|
|
71823
|
+
return resolveErrorCall(node);
|
|
71824
|
+
}
|
|
71825
|
+
}
|
|
71826
|
+
return anySignature;
|
|
71827
|
+
}
|
|
71754
71828
|
function isPotentiallyUncalledDecorator(decorator, signatures) {
|
|
71755
71829
|
return signatures.length && every(signatures, (signature) => signature.minArgumentCount === 0 && !signatureHasRestParameter(signature) && signature.parameters.length < getDecoratorArgumentCount(decorator, signature));
|
|
71756
71830
|
}
|
|
@@ -71767,6 +71841,8 @@ function createTypeChecker(host) {
|
|
|
71767
71841
|
case 286 /* JsxOpeningElement */:
|
|
71768
71842
|
case 285 /* JsxSelfClosingElement */:
|
|
71769
71843
|
return resolveJsxOpeningLikeElement(node, candidatesOutArray, checkMode);
|
|
71844
|
+
case 226 /* BinaryExpression */:
|
|
71845
|
+
return resolveInstanceofExpression(node, candidatesOutArray, checkMode);
|
|
71770
71846
|
}
|
|
71771
71847
|
Debug.assertNever(node, "Branch in 'resolveSignature' should be unreachable.");
|
|
71772
71848
|
}
|
|
@@ -73725,16 +73801,35 @@ function createTypeChecker(host) {
|
|
|
73725
73801
|
function isConstEnumSymbol(symbol) {
|
|
73726
73802
|
return (symbol.flags & 128 /* ConstEnum */) !== 0;
|
|
73727
73803
|
}
|
|
73728
|
-
function
|
|
73804
|
+
function getSymbolHasInstanceMethodOfObjectType(type) {
|
|
73805
|
+
const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
|
|
73806
|
+
const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
|
|
73807
|
+
if (hasInstanceProperty) {
|
|
73808
|
+
const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
|
|
73809
|
+
if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, 0 /* Call */).length !== 0) {
|
|
73810
|
+
return hasInstancePropertyType;
|
|
73811
|
+
}
|
|
73812
|
+
}
|
|
73813
|
+
}
|
|
73814
|
+
function checkInstanceOfExpression(left, right, leftType, rightType, checkMode) {
|
|
73729
73815
|
if (leftType === silentNeverType || rightType === silentNeverType) {
|
|
73730
73816
|
return silentNeverType;
|
|
73731
73817
|
}
|
|
73732
73818
|
if (!isTypeAny(leftType) && allTypesAssignableToKind(leftType, 402784252 /* Primitive */)) {
|
|
73733
73819
|
error(left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
|
73734
73820
|
}
|
|
73735
|
-
|
|
73736
|
-
|
|
73821
|
+
Debug.assert(isInstanceOfExpression(left.parent));
|
|
73822
|
+
const signature = getResolvedSignature(
|
|
73823
|
+
left.parent,
|
|
73824
|
+
/*candidatesOutArray*/
|
|
73825
|
+
void 0,
|
|
73826
|
+
checkMode
|
|
73827
|
+
);
|
|
73828
|
+
if (signature === resolvingSignature) {
|
|
73829
|
+
return silentNeverType;
|
|
73737
73830
|
}
|
|
73831
|
+
const returnType = getReturnTypeOfSignature(signature);
|
|
73832
|
+
checkTypeAssignableTo(returnType, booleanType, right, Diagnostics.An_object_s_Symbol_hasInstance_method_must_return_a_boolean_value_for_it_to_be_used_on_the_right_hand_side_of_an_instanceof_expression);
|
|
73738
73833
|
return booleanType;
|
|
73739
73834
|
}
|
|
73740
73835
|
function hasEmptyObjectIntersection(type) {
|
|
@@ -74272,7 +74367,7 @@ function createTypeChecker(host) {
|
|
|
74272
74367
|
case 36 /* ExclamationEqualsToken */:
|
|
74273
74368
|
case 37 /* EqualsEqualsEqualsToken */:
|
|
74274
74369
|
case 38 /* ExclamationEqualsEqualsToken */:
|
|
74275
|
-
if (!(checkMode && checkMode &
|
|
74370
|
+
if (!(checkMode && checkMode & 64 /* TypeOnly */)) {
|
|
74276
74371
|
if ((isLiteralExpressionOfObject(left) || isLiteralExpressionOfObject(right)) && // only report for === and !== in JS, not == or !=
|
|
74277
74372
|
(!isInJSFile(left) || (operator === 37 /* EqualsEqualsEqualsToken */ || operator === 38 /* ExclamationEqualsEqualsToken */))) {
|
|
74278
74373
|
const eqType = operator === 35 /* EqualsEqualsToken */ || operator === 37 /* EqualsEqualsEqualsToken */;
|
|
@@ -74283,7 +74378,7 @@ function createTypeChecker(host) {
|
|
|
74283
74378
|
}
|
|
74284
74379
|
return booleanType;
|
|
74285
74380
|
case 104 /* InstanceOfKeyword */:
|
|
74286
|
-
return checkInstanceOfExpression(left, right, leftType, rightType);
|
|
74381
|
+
return checkInstanceOfExpression(left, right, leftType, rightType, checkMode);
|
|
74287
74382
|
case 103 /* InKeyword */:
|
|
74288
74383
|
return checkInExpression(left, right, leftType, rightType);
|
|
74289
74384
|
case 56 /* AmpersandAmpersandToken */:
|
|
@@ -74920,7 +75015,7 @@ function createTypeChecker(host) {
|
|
|
74920
75015
|
}
|
|
74921
75016
|
}
|
|
74922
75017
|
const startInvocationCount = flowInvocationCount;
|
|
74923
|
-
const type = checkExpression(node,
|
|
75018
|
+
const type = checkExpression(node, 64 /* TypeOnly */);
|
|
74924
75019
|
if (flowInvocationCount !== startInvocationCount) {
|
|
74925
75020
|
const cache = flowTypeCache || (flowTypeCache = []);
|
|
74926
75021
|
cache[getNodeId(node)] = type;
|
|
@@ -77386,7 +77481,7 @@ function createTypeChecker(host) {
|
|
|
77386
77481
|
checkComputedPropertyName(node.propertyName);
|
|
77387
77482
|
}
|
|
77388
77483
|
const parent = node.parent.parent;
|
|
77389
|
-
const parentCheckMode = node.dotDotDotToken ?
|
|
77484
|
+
const parentCheckMode = node.dotDotDotToken ? 32 /* RestBindingElement */ : 0 /* Normal */;
|
|
77390
77485
|
const parentType = getTypeForBindingElementParent(parent, parentCheckMode);
|
|
77391
77486
|
const name = node.propertyName || node.name;
|
|
77392
77487
|
if (parentType && !isBindingPattern(name)) {
|
|
@@ -79603,7 +79698,7 @@ function createTypeChecker(host) {
|
|
|
79603
79698
|
}
|
|
79604
79699
|
if (isConstantVariable(symbol)) {
|
|
79605
79700
|
const declaration = symbol.valueDeclaration;
|
|
79606
|
-
if (declaration && !declaration.type && declaration.initializer && (!location || declaration !== location && isBlockScopedNameDeclaredBeforeUse(declaration, location))) {
|
|
79701
|
+
if (declaration && isVariableDeclaration(declaration) && !declaration.type && declaration.initializer && (!location || declaration !== location && isBlockScopedNameDeclaredBeforeUse(declaration, location))) {
|
|
79607
79702
|
return evaluate(declaration.initializer, declaration);
|
|
79608
79703
|
}
|
|
79609
79704
|
}
|
|
@@ -80695,6 +80790,12 @@ function createTypeChecker(host) {
|
|
|
80695
80790
|
case 234 /* AsExpression */:
|
|
80696
80791
|
case 217 /* ParenthesizedExpression */:
|
|
80697
80792
|
checkAssertionDeferred(node);
|
|
80793
|
+
break;
|
|
80794
|
+
case 226 /* BinaryExpression */:
|
|
80795
|
+
if (isInstanceOfExpression(node)) {
|
|
80796
|
+
resolveUntypedCall(node);
|
|
80797
|
+
}
|
|
80798
|
+
break;
|
|
80698
80799
|
}
|
|
80699
80800
|
currentNode = saveCurrentNode;
|
|
80700
80801
|
(_b = tracing) == null ? void 0 : _b.pop();
|
|
@@ -81311,6 +81412,13 @@ function createTypeChecker(host) {
|
|
|
81311
81412
|
case 102 /* ImportKeyword */:
|
|
81312
81413
|
case 105 /* NewKeyword */:
|
|
81313
81414
|
return isMetaProperty(node.parent) ? checkMetaPropertyKeyword(node.parent).symbol : void 0;
|
|
81415
|
+
case 104 /* InstanceOfKeyword */:
|
|
81416
|
+
if (isBinaryExpression(node.parent)) {
|
|
81417
|
+
const type = getTypeOfExpression(node.parent.right);
|
|
81418
|
+
const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(type);
|
|
81419
|
+
return (hasInstanceMethodType == null ? void 0 : hasInstanceMethodType.symbol) ?? type.symbol;
|
|
81420
|
+
}
|
|
81421
|
+
return void 0;
|
|
81314
81422
|
case 236 /* MetaProperty */:
|
|
81315
81423
|
return checkExpression(node).symbol;
|
|
81316
81424
|
case 295 /* JsxNamespacedName */:
|