typescript 5.7.0-dev.20240930 → 5.7.0-dev.20241002
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 +1350 -995
- package/lib/typescript.js +1351 -999
- package/package.json +17 -17
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.7";
|
|
21
|
-
var version = `${versionMajorMinor}.0-dev.
|
|
21
|
+
var version = `${versionMajorMinor}.0-dev.20241002`;
|
|
22
22
|
|
|
23
23
|
// src/compiler/core.ts
|
|
24
24
|
var emptyArray = [];
|
|
@@ -7567,7 +7567,7 @@ var Diagnostics = {
|
|
|
7567
7567
|
Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit: diag(9006, 1 /* Error */, "Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotati_9006", "Declaration emit for this file requires using private name '{0}' from module '{1}'. An explicit type annotation may unblock declaration emit."),
|
|
7568
7568
|
Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations: diag(9007, 1 /* Error */, "Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9007", "Function must have an explicit return type annotation with --isolatedDeclarations."),
|
|
7569
7569
|
Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations: diag(9008, 1 /* Error */, "Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations_9008", "Method must have an explicit return type annotation with --isolatedDeclarations."),
|
|
7570
|
-
|
|
7570
|
+
At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9009, 1 /* Error */, "At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9009", "At least one accessor must have an explicit type annotation with --isolatedDeclarations."),
|
|
7571
7571
|
Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9010, 1 /* Error */, "Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9010", "Variable must have an explicit type annotation with --isolatedDeclarations."),
|
|
7572
7572
|
Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9011, 1 /* Error */, "Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9011", "Parameter must have an explicit type annotation with --isolatedDeclarations."),
|
|
7573
7573
|
Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations: diag(9012, 1 /* Error */, "Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations_9012", "Property must have an explicit type annotation with --isolatedDeclarations."),
|
|
@@ -14196,9 +14196,6 @@ function isVariableLike(node) {
|
|
|
14196
14196
|
}
|
|
14197
14197
|
return false;
|
|
14198
14198
|
}
|
|
14199
|
-
function isVariableLikeOrAccessor(node) {
|
|
14200
|
-
return isVariableLike(node) || isAccessor(node);
|
|
14201
|
-
}
|
|
14202
14199
|
function isVariableDeclarationInVariableStatement(node) {
|
|
14203
14200
|
return node.parent.kind === 261 /* VariableDeclarationList */ && node.parent.parent.kind === 243 /* VariableStatement */;
|
|
14204
14201
|
}
|
|
@@ -19718,6 +19715,9 @@ function hasInferredType(node) {
|
|
|
19718
19715
|
case 260 /* VariableDeclaration */:
|
|
19719
19716
|
case 277 /* ExportAssignment */:
|
|
19720
19717
|
case 303 /* PropertyAssignment */:
|
|
19718
|
+
case 304 /* ShorthandPropertyAssignment */:
|
|
19719
|
+
case 341 /* JSDocParameterTag */:
|
|
19720
|
+
case 348 /* JSDocPropertyTag */:
|
|
19721
19721
|
return true;
|
|
19722
19722
|
default:
|
|
19723
19723
|
assertType(node);
|
|
@@ -19837,6 +19837,9 @@ function getNodeAtPosition(sourceFile, position, includeJSDoc) {
|
|
|
19837
19837
|
current = child;
|
|
19838
19838
|
}
|
|
19839
19839
|
}
|
|
19840
|
+
function isNewScopeNode(node) {
|
|
19841
|
+
return isFunctionLike(node) || isJSDocSignature(node) || isMappedTypeNode(node);
|
|
19842
|
+
}
|
|
19840
19843
|
|
|
19841
19844
|
// src/compiler/factory/baseNodeFactory.ts
|
|
19842
19845
|
function createBaseNodeFactory() {
|
|
@@ -26617,6 +26620,9 @@ function isJsxAttributes(node) {
|
|
|
26617
26620
|
function isJsxSpreadAttribute(node) {
|
|
26618
26621
|
return node.kind === 293 /* JsxSpreadAttribute */;
|
|
26619
26622
|
}
|
|
26623
|
+
function isJsxExpression(node) {
|
|
26624
|
+
return node.kind === 294 /* JsxExpression */;
|
|
26625
|
+
}
|
|
26620
26626
|
function isJsxNamespacedName(node) {
|
|
26621
26627
|
return node.kind === 295 /* JsxNamespacedName */;
|
|
26622
26628
|
}
|
|
@@ -41871,7 +41877,7 @@ function createBinder() {
|
|
|
41871
41877
|
var inStrictMode;
|
|
41872
41878
|
var inAssignmentPattern = false;
|
|
41873
41879
|
var symbolCount = 0;
|
|
41874
|
-
var
|
|
41880
|
+
var Symbol13;
|
|
41875
41881
|
var classifiableNames;
|
|
41876
41882
|
var unreachableFlow = createFlowNode(
|
|
41877
41883
|
1 /* Unreachable */,
|
|
@@ -41900,7 +41906,7 @@ function createBinder() {
|
|
|
41900
41906
|
inStrictMode = bindInStrictMode(file, opts);
|
|
41901
41907
|
classifiableNames = /* @__PURE__ */ new Set();
|
|
41902
41908
|
symbolCount = 0;
|
|
41903
|
-
|
|
41909
|
+
Symbol13 = objectAllocator.getSymbolConstructor();
|
|
41904
41910
|
Debug.attachFlowNodeDebugInfo(unreachableFlow);
|
|
41905
41911
|
Debug.attachFlowNodeDebugInfo(reportedUnreachableFlow);
|
|
41906
41912
|
if (!file.locals) {
|
|
@@ -41951,7 +41957,7 @@ function createBinder() {
|
|
|
41951
41957
|
}
|
|
41952
41958
|
function createSymbol(flags, name) {
|
|
41953
41959
|
symbolCount++;
|
|
41954
|
-
return new
|
|
41960
|
+
return new Symbol13(flags, name);
|
|
41955
41961
|
}
|
|
41956
41962
|
function addDeclarationToSymbol(symbol, node, symbolFlags) {
|
|
41957
41963
|
symbol.flags |= symbolFlags;
|
|
@@ -45908,7 +45914,7 @@ function createTypeChecker(host) {
|
|
|
45908
45914
|
};
|
|
45909
45915
|
var cancellationToken;
|
|
45910
45916
|
var scanner;
|
|
45911
|
-
var
|
|
45917
|
+
var Symbol13 = objectAllocator.getSymbolConstructor();
|
|
45912
45918
|
var Type7 = objectAllocator.getTypeConstructor();
|
|
45913
45919
|
var Signature5 = objectAllocator.getSignatureConstructor();
|
|
45914
45920
|
var typeCount = 0;
|
|
@@ -45942,17 +45948,7 @@ function createTypeChecker(host) {
|
|
|
45942
45948
|
var checkBinaryExpression = createCheckBinaryExpression();
|
|
45943
45949
|
var emitResolver = createResolver();
|
|
45944
45950
|
var nodeBuilder = createNodeBuilder();
|
|
45945
|
-
var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions,
|
|
45946
|
-
isEntityNameVisible,
|
|
45947
|
-
isExpandoFunctionDeclaration,
|
|
45948
|
-
getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration,
|
|
45949
|
-
requiresAddingImplicitUndefined,
|
|
45950
|
-
isUndefinedIdentifierExpression(node) {
|
|
45951
|
-
Debug.assert(isExpressionNode(node));
|
|
45952
|
-
return getSymbolAtLocation(node) === undefinedSymbol;
|
|
45953
|
-
},
|
|
45954
|
-
isDefinitelyReferenceToGlobalSymbolObject
|
|
45955
|
-
});
|
|
45951
|
+
var syntacticNodeBuilder = createSyntacticTypeNodeBuilder(compilerOptions, nodeBuilder.syntacticBuilderResolver);
|
|
45956
45952
|
var evaluate = createEvaluator({
|
|
45957
45953
|
evaluateElementAccessExpression,
|
|
45958
45954
|
evaluateEntityNameExpression
|
|
@@ -47097,7 +47093,7 @@ function createTypeChecker(host) {
|
|
|
47097
47093
|
}
|
|
47098
47094
|
function createSymbol(flags, name, checkFlags) {
|
|
47099
47095
|
symbolCount++;
|
|
47100
|
-
const symbol = new
|
|
47096
|
+
const symbol = new Symbol13(flags | 33554432 /* Transient */, name);
|
|
47101
47097
|
symbol.links = new SymbolLinks();
|
|
47102
47098
|
symbol.links.checkFlags = checkFlags || 0 /* None */;
|
|
47103
47099
|
return symbol;
|
|
@@ -50110,12 +50106,191 @@ function createTypeChecker(host) {
|
|
|
50110
50106
|
return getTypeFromTypeNode(node);
|
|
50111
50107
|
}
|
|
50112
50108
|
function createNodeBuilder() {
|
|
50109
|
+
const syntacticBuilderResolver = {
|
|
50110
|
+
evaluateEntityNameExpression,
|
|
50111
|
+
isExpandoFunctionDeclaration,
|
|
50112
|
+
hasLateBindableName,
|
|
50113
|
+
shouldRemoveDeclaration(context, node) {
|
|
50114
|
+
return !(context.internalFlags & 8 /* AllowUnresolvedNames */ && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & 1 /* Any */);
|
|
50115
|
+
},
|
|
50116
|
+
createRecoveryBoundary(context) {
|
|
50117
|
+
return createRecoveryBoundary(context);
|
|
50118
|
+
},
|
|
50119
|
+
isDefinitelyReferenceToGlobalSymbolObject,
|
|
50120
|
+
getAllAccessorDeclarations: getAllAccessorDeclarationsForDeclaration,
|
|
50121
|
+
requiresAddingImplicitUndefined(declaration, symbol, enclosingDeclaration) {
|
|
50122
|
+
var _a;
|
|
50123
|
+
switch (declaration.kind) {
|
|
50124
|
+
case 172 /* PropertyDeclaration */:
|
|
50125
|
+
case 171 /* PropertySignature */:
|
|
50126
|
+
case 348 /* JSDocPropertyTag */:
|
|
50127
|
+
symbol ?? (symbol = getSymbolOfDeclaration(declaration));
|
|
50128
|
+
const type = getTypeOfSymbol(symbol);
|
|
50129
|
+
return !!(symbol.flags & 4 /* Property */ && symbol.flags & 16777216 /* Optional */ && isOptionalDeclaration(declaration) && ((_a = symbol.links) == null ? void 0 : _a.mappedType) && containsNonMissingUndefinedType(type));
|
|
50130
|
+
case 169 /* Parameter */:
|
|
50131
|
+
case 341 /* JSDocParameterTag */:
|
|
50132
|
+
return requiresAddingImplicitUndefined(declaration, enclosingDeclaration);
|
|
50133
|
+
default:
|
|
50134
|
+
Debug.assertNever(declaration);
|
|
50135
|
+
}
|
|
50136
|
+
},
|
|
50137
|
+
isOptionalParameter,
|
|
50138
|
+
isUndefinedIdentifierExpression(node) {
|
|
50139
|
+
Debug.assert(isExpressionNode(node));
|
|
50140
|
+
return getSymbolAtLocation(node) === undefinedSymbol;
|
|
50141
|
+
},
|
|
50142
|
+
isEntityNameVisible(context, entityName, shouldComputeAliasToMakeVisible) {
|
|
50143
|
+
return isEntityNameVisible(entityName, context.enclosingDeclaration, shouldComputeAliasToMakeVisible);
|
|
50144
|
+
},
|
|
50145
|
+
serializeExistingTypeNode(context, typeNode, addUndefined) {
|
|
50146
|
+
return serializeExistingTypeNode(context, typeNode, !!addUndefined);
|
|
50147
|
+
},
|
|
50148
|
+
serializeReturnTypeForSignature(syntacticContext, signatureDeclaration) {
|
|
50149
|
+
const context = syntacticContext;
|
|
50150
|
+
const signature = getSignatureFromDeclaration(signatureDeclaration);
|
|
50151
|
+
const returnType = context.enclosingSymbolTypes.get(getSymbolId(getSymbolOfDeclaration(signatureDeclaration))) ?? instantiateType(getReturnTypeOfSignature(signature), context.mapper);
|
|
50152
|
+
return serializeInferredReturnTypeForSignature(context, signature, returnType);
|
|
50153
|
+
},
|
|
50154
|
+
serializeTypeOfExpression(syntacticContext, expr) {
|
|
50155
|
+
const context = syntacticContext;
|
|
50156
|
+
const type = instantiateType(getWidenedType(getRegularTypeOfExpression(expr)), context.mapper);
|
|
50157
|
+
return typeToTypeNodeHelper(type, context);
|
|
50158
|
+
},
|
|
50159
|
+
serializeTypeOfDeclaration(syntacticContext, declaration, symbol) {
|
|
50160
|
+
var _a;
|
|
50161
|
+
const context = syntacticContext;
|
|
50162
|
+
symbol ?? (symbol = getSymbolOfDeclaration(declaration));
|
|
50163
|
+
let type = (_a = context.enclosingSymbolTypes) == null ? void 0 : _a.get(getSymbolId(symbol));
|
|
50164
|
+
if (type === void 0) {
|
|
50165
|
+
type = symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */)) ? instantiateType(getWidenedLiteralType(getTypeOfSymbol(symbol)), context.mapper) : errorType;
|
|
50166
|
+
}
|
|
50167
|
+
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
|
|
50168
|
+
if (addUndefinedForParameter) {
|
|
50169
|
+
type = getOptionalType(type);
|
|
50170
|
+
}
|
|
50171
|
+
return serializeInferredTypeForDeclaration(symbol, context, type);
|
|
50172
|
+
},
|
|
50173
|
+
serializeNameOfParameter(context, parameter) {
|
|
50174
|
+
return parameterToParameterDeclarationName(getSymbolOfDeclaration(parameter), parameter, context);
|
|
50175
|
+
},
|
|
50176
|
+
serializeEntityName(syntacticContext, node) {
|
|
50177
|
+
const context = syntacticContext;
|
|
50178
|
+
const symbol = getSymbolAtLocation(
|
|
50179
|
+
node,
|
|
50180
|
+
/*ignoreErrors*/
|
|
50181
|
+
true
|
|
50182
|
+
);
|
|
50183
|
+
if (!symbol) return void 0;
|
|
50184
|
+
if (!isValueSymbolAccessible(symbol, context.enclosingDeclaration)) return void 0;
|
|
50185
|
+
return symbolToExpression(symbol, context, 111551 /* Value */ | 1048576 /* ExportValue */);
|
|
50186
|
+
},
|
|
50187
|
+
serializeTypeName(context, node, isTypeOf, typeArguments) {
|
|
50188
|
+
return serializeTypeName(context, node, isTypeOf, typeArguments);
|
|
50189
|
+
},
|
|
50190
|
+
getJsDocPropertyOverride(syntacticContext, jsDocTypeLiteral, jsDocProperty) {
|
|
50191
|
+
const context = syntacticContext;
|
|
50192
|
+
const name = isIdentifier(jsDocProperty.name) ? jsDocProperty.name : jsDocProperty.name.right;
|
|
50193
|
+
const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode2(context, jsDocTypeLiteral), name.escapedText);
|
|
50194
|
+
const overrideTypeNode = typeViaParent && jsDocProperty.typeExpression && getTypeFromTypeNode2(context, jsDocProperty.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : void 0;
|
|
50195
|
+
return overrideTypeNode;
|
|
50196
|
+
},
|
|
50197
|
+
enterNewScope(context, node) {
|
|
50198
|
+
if (isFunctionLike(node) || isJSDocSignature(node)) {
|
|
50199
|
+
const signature = getSignatureFromDeclaration(node);
|
|
50200
|
+
const expandedParams = getExpandedParameters(
|
|
50201
|
+
signature,
|
|
50202
|
+
/*skipUnionExpanding*/
|
|
50203
|
+
true
|
|
50204
|
+
)[0];
|
|
50205
|
+
return enterNewScope(context, node, expandedParams, signature.typeParameters);
|
|
50206
|
+
} else {
|
|
50207
|
+
const typeParameters = isConditionalTypeNode(node) ? getInferTypeParameters(node) : [getDeclaredTypeOfTypeParameter(getSymbolOfDeclaration(node.typeParameter))];
|
|
50208
|
+
return enterNewScope(
|
|
50209
|
+
context,
|
|
50210
|
+
node,
|
|
50211
|
+
/*expandedParams*/
|
|
50212
|
+
void 0,
|
|
50213
|
+
typeParameters
|
|
50214
|
+
);
|
|
50215
|
+
}
|
|
50216
|
+
},
|
|
50217
|
+
markNodeReuse(context, range, location) {
|
|
50218
|
+
return setTextRange2(context, range, location);
|
|
50219
|
+
},
|
|
50220
|
+
trackExistingEntityName(context, node) {
|
|
50221
|
+
return trackExistingEntityName(node, context);
|
|
50222
|
+
},
|
|
50223
|
+
trackComputedName(context, accessExpression) {
|
|
50224
|
+
trackComputedName(accessExpression, context.enclosingDeclaration, context);
|
|
50225
|
+
},
|
|
50226
|
+
getModuleSpecifierOverride(syntacticContext, parent, lit) {
|
|
50227
|
+
const context = syntacticContext;
|
|
50228
|
+
if (context.bundled || context.enclosingFile !== getSourceFileOfNode(lit)) {
|
|
50229
|
+
let name = lit.text;
|
|
50230
|
+
const nodeSymbol = getNodeLinks(parent).resolvedSymbol;
|
|
50231
|
+
const meaning = parent.isTypeOf ? 111551 /* Value */ : 788968 /* Type */;
|
|
50232
|
+
const parentSymbol = nodeSymbol && isSymbolAccessible(
|
|
50233
|
+
nodeSymbol,
|
|
50234
|
+
context.enclosingDeclaration,
|
|
50235
|
+
meaning,
|
|
50236
|
+
/*shouldComputeAliasesToMakeVisible*/
|
|
50237
|
+
false
|
|
50238
|
+
).accessibility === 0 /* Accessible */ && lookupSymbolChain(
|
|
50239
|
+
nodeSymbol,
|
|
50240
|
+
context,
|
|
50241
|
+
meaning,
|
|
50242
|
+
/*yieldModuleSymbol*/
|
|
50243
|
+
true
|
|
50244
|
+
)[0];
|
|
50245
|
+
if (parentSymbol && isExternalModuleSymbol(parentSymbol)) {
|
|
50246
|
+
name = getSpecifierForModuleSymbol(parentSymbol, context);
|
|
50247
|
+
} else {
|
|
50248
|
+
const targetFile = getExternalModuleFileFromDeclaration(parent);
|
|
50249
|
+
if (targetFile) {
|
|
50250
|
+
name = getSpecifierForModuleSymbol(targetFile.symbol, context);
|
|
50251
|
+
}
|
|
50252
|
+
}
|
|
50253
|
+
if (name.includes("/node_modules/")) {
|
|
50254
|
+
context.encounteredError = true;
|
|
50255
|
+
if (context.tracker.reportLikelyUnsafeImportRequiredError) {
|
|
50256
|
+
context.tracker.reportLikelyUnsafeImportRequiredError(name);
|
|
50257
|
+
}
|
|
50258
|
+
}
|
|
50259
|
+
return name;
|
|
50260
|
+
}
|
|
50261
|
+
},
|
|
50262
|
+
canReuseTypeNode(context, typeNode) {
|
|
50263
|
+
return canReuseTypeNode(context, typeNode);
|
|
50264
|
+
},
|
|
50265
|
+
canReuseTypeNodeAnnotation(syntacticContext, node, existing, symbol, requiresAddingUndefined) {
|
|
50266
|
+
var _a;
|
|
50267
|
+
const context = syntacticContext;
|
|
50268
|
+
if (context.enclosingDeclaration === void 0) return false;
|
|
50269
|
+
symbol ?? (symbol = getSymbolOfDeclaration(node));
|
|
50270
|
+
let type = (_a = context.enclosingSymbolTypes) == null ? void 0 : _a.get(getSymbolId(symbol));
|
|
50271
|
+
if (type === void 0) {
|
|
50272
|
+
if (symbol.flags & 98304 /* Accessor */) {
|
|
50273
|
+
type = node.kind === 178 /* SetAccessor */ ? getWriteTypeOfSymbol(symbol) : getTypeOfAccessors(symbol);
|
|
50274
|
+
} else if (isValueSignatureDeclaration(node)) {
|
|
50275
|
+
type = getReturnTypeOfSignature(getSignatureFromDeclaration(node));
|
|
50276
|
+
} else {
|
|
50277
|
+
type = getTypeOfSymbol(symbol);
|
|
50278
|
+
}
|
|
50279
|
+
}
|
|
50280
|
+
let annotationType = getTypeFromTypeNodeWithoutContext(existing);
|
|
50281
|
+
if (requiresAddingUndefined && annotationType) {
|
|
50282
|
+
annotationType = getOptionalType(annotationType, !isParameter(node));
|
|
50283
|
+
}
|
|
50284
|
+
return !!annotationType && typeNodeIsEquivalentToType(node, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type);
|
|
50285
|
+
}
|
|
50286
|
+
};
|
|
50113
50287
|
return {
|
|
50288
|
+
syntacticBuilderResolver,
|
|
50114
50289
|
typeToTypeNode: (type, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typeToTypeNodeHelper(type, context)),
|
|
50115
50290
|
typePredicateToTypePredicateNode: (typePredicate, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => typePredicateToTypePredicateNodeHelper(typePredicate, context)),
|
|
50116
|
-
|
|
50117
|
-
serializeTypeForDeclaration: (declaration,
|
|
50118
|
-
serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => serializeReturnTypeForSignature(
|
|
50291
|
+
serializeTypeForExpression: (expr, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfExpression(expr, context)),
|
|
50292
|
+
serializeTypeForDeclaration: (declaration, symbol, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeTypeOfDeclaration(declaration, symbol, context)),
|
|
50293
|
+
serializeReturnTypeForSignature: (signature, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => syntacticNodeBuilder.serializeReturnTypeForSignature(signature, getSymbolOfDeclaration(signature), context)),
|
|
50119
50294
|
indexInfoToIndexSignatureDeclaration: (indexInfo, enclosingDeclaration, flags, internalFlags, tracker) => withContext(enclosingDeclaration, flags, internalFlags, tracker, (context) => indexInfoToIndexSignatureDeclarationHelper(
|
|
50120
50295
|
indexInfo,
|
|
50121
50296
|
context,
|
|
@@ -50163,65 +50338,6 @@ function createTypeChecker(host) {
|
|
|
50163
50338
|
}
|
|
50164
50339
|
return range;
|
|
50165
50340
|
}
|
|
50166
|
-
function expressionOrTypeToTypeNode(context, expr, type, addUndefined) {
|
|
50167
|
-
const restoreFlags = saveRestoreFlags(context);
|
|
50168
|
-
if (expr && !(context.internalFlags & 2 /* NoSyntacticPrinter */)) {
|
|
50169
|
-
syntacticNodeBuilder.serializeTypeOfExpression(expr, context, addUndefined);
|
|
50170
|
-
}
|
|
50171
|
-
context.internalFlags |= 2 /* NoSyntacticPrinter */;
|
|
50172
|
-
const result = expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined);
|
|
50173
|
-
restoreFlags();
|
|
50174
|
-
return result;
|
|
50175
|
-
}
|
|
50176
|
-
function expressionOrTypeToTypeNodeHelper(context, expr, type, addUndefined) {
|
|
50177
|
-
if (expr) {
|
|
50178
|
-
const typeNode = isAssertionExpression(expr) ? expr.type : isJSDocTypeAssertion(expr) ? getJSDocTypeAssertionType(expr) : void 0;
|
|
50179
|
-
if (typeNode && !isConstTypeReference(typeNode)) {
|
|
50180
|
-
const result = tryReuseExistingTypeNode(context, typeNode, type, expr.parent, addUndefined);
|
|
50181
|
-
if (result) {
|
|
50182
|
-
return result;
|
|
50183
|
-
}
|
|
50184
|
-
}
|
|
50185
|
-
}
|
|
50186
|
-
if (addUndefined) {
|
|
50187
|
-
type = getOptionalType(type);
|
|
50188
|
-
}
|
|
50189
|
-
return typeToTypeNodeHelper(type, context);
|
|
50190
|
-
}
|
|
50191
|
-
function tryReuseExistingTypeNode(context, typeNode, type, host2, addUndefined) {
|
|
50192
|
-
const originalType = type;
|
|
50193
|
-
if (addUndefined) {
|
|
50194
|
-
type = getOptionalType(type, !isParameter(host2));
|
|
50195
|
-
}
|
|
50196
|
-
const clone = tryReuseExistingNonParameterTypeNode(context, typeNode, type, host2);
|
|
50197
|
-
if (clone) {
|
|
50198
|
-
if (addUndefined && containsNonMissingUndefinedType(type) && !someType(getTypeFromTypeNode2(context, typeNode), (t) => !!(t.flags & 32768 /* Undefined */))) {
|
|
50199
|
-
return factory.createUnionTypeNode([clone, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
|
|
50200
|
-
}
|
|
50201
|
-
return clone;
|
|
50202
|
-
}
|
|
50203
|
-
if (addUndefined && originalType !== type) {
|
|
50204
|
-
const cloneMissingUndefined = tryReuseExistingNonParameterTypeNode(context, typeNode, originalType, host2);
|
|
50205
|
-
if (cloneMissingUndefined) {
|
|
50206
|
-
return factory.createUnionTypeNode([cloneMissingUndefined, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
|
|
50207
|
-
}
|
|
50208
|
-
}
|
|
50209
|
-
return void 0;
|
|
50210
|
-
}
|
|
50211
|
-
function tryReuseExistingNonParameterTypeNode(context, existing, type, host2 = context.enclosingDeclaration, annotationType = getTypeFromTypeNode2(
|
|
50212
|
-
context,
|
|
50213
|
-
existing,
|
|
50214
|
-
/*noMappedTypes*/
|
|
50215
|
-
true
|
|
50216
|
-
)) {
|
|
50217
|
-
if (annotationType && typeNodeIsEquivalentToType(host2, type, annotationType) && existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type)) {
|
|
50218
|
-
const result = tryReuseExistingTypeNodeHelper(context, existing);
|
|
50219
|
-
if (result) {
|
|
50220
|
-
return result;
|
|
50221
|
-
}
|
|
50222
|
-
}
|
|
50223
|
-
return void 0;
|
|
50224
|
-
}
|
|
50225
50341
|
function symbolToNode(symbol, context, meaning) {
|
|
50226
50342
|
if (context.internalFlags & 1 /* WriteComputedProps */) {
|
|
50227
50343
|
if (symbol.valueDeclaration) {
|
|
@@ -50245,6 +50361,7 @@ function createTypeChecker(host) {
|
|
|
50245
50361
|
internalFlags: internalFlags || 0 /* None */,
|
|
50246
50362
|
tracker: void 0,
|
|
50247
50363
|
encounteredError: false,
|
|
50364
|
+
suppressReportInferenceFallback: false,
|
|
50248
50365
|
reportedDiagnostic: false,
|
|
50249
50366
|
visitedTypes: void 0,
|
|
50250
50367
|
symbolDepth: void 0,
|
|
@@ -50263,6 +50380,7 @@ function createTypeChecker(host) {
|
|
|
50263
50380
|
typeParameterNames: void 0,
|
|
50264
50381
|
typeParameterNamesByText: void 0,
|
|
50265
50382
|
typeParameterNamesByTextNextNameCount: void 0,
|
|
50383
|
+
enclosingSymbolTypes: /* @__PURE__ */ new Map(),
|
|
50266
50384
|
mapper: void 0
|
|
50267
50385
|
};
|
|
50268
50386
|
context.tracker = new SymbolTrackerImpl(context, tracker, moduleResolverHost);
|
|
@@ -50272,6 +50390,19 @@ function createTypeChecker(host) {
|
|
|
50272
50390
|
}
|
|
50273
50391
|
return context.encounteredError ? void 0 : resultingNode;
|
|
50274
50392
|
}
|
|
50393
|
+
function addSymbolTypeToContext(context, symbol, type) {
|
|
50394
|
+
const id = getSymbolId(symbol);
|
|
50395
|
+
const oldType = context.enclosingSymbolTypes.get(id);
|
|
50396
|
+
context.enclosingSymbolTypes.set(id, type);
|
|
50397
|
+
return restore;
|
|
50398
|
+
function restore() {
|
|
50399
|
+
if (oldType) {
|
|
50400
|
+
context.enclosingSymbolTypes.set(id, oldType);
|
|
50401
|
+
} else {
|
|
50402
|
+
context.enclosingSymbolTypes.delete(id);
|
|
50403
|
+
}
|
|
50404
|
+
}
|
|
50405
|
+
}
|
|
50275
50406
|
function saveRestoreFlags(context) {
|
|
50276
50407
|
const flags = context.flags;
|
|
50277
50408
|
const internalFlags = context.internalFlags;
|
|
@@ -50683,8 +50814,8 @@ function createTypeChecker(host) {
|
|
|
50683
50814
|
if (isInstantiationExpressionType) {
|
|
50684
50815
|
const instantiationExpressionType = type2;
|
|
50685
50816
|
const existing = instantiationExpressionType.node;
|
|
50686
|
-
if (isTypeQueryNode(existing)) {
|
|
50687
|
-
const typeNode =
|
|
50817
|
+
if (isTypeQueryNode(existing) && getTypeFromTypeNode2(context, existing) === type2) {
|
|
50818
|
+
const typeNode = syntacticNodeBuilder.tryReuseExistingTypeNode(context, existing);
|
|
50688
50819
|
if (typeNode) {
|
|
50689
50820
|
return typeNode;
|
|
50690
50821
|
}
|
|
@@ -51435,14 +51566,85 @@ function createTypeChecker(host) {
|
|
|
51435
51566
|
cleanup == null ? void 0 : cleanup();
|
|
51436
51567
|
return node;
|
|
51437
51568
|
}
|
|
51438
|
-
function
|
|
51439
|
-
|
|
51440
|
-
|
|
51441
|
-
|
|
51442
|
-
|
|
51443
|
-
|
|
51444
|
-
|
|
51445
|
-
|
|
51569
|
+
function createRecoveryBoundary(context) {
|
|
51570
|
+
if (cancellationToken && cancellationToken.throwIfCancellationRequested) {
|
|
51571
|
+
cancellationToken.throwIfCancellationRequested();
|
|
51572
|
+
}
|
|
51573
|
+
let trackedSymbols;
|
|
51574
|
+
let unreportedErrors;
|
|
51575
|
+
let hadError = false;
|
|
51576
|
+
const oldTracker = context.tracker;
|
|
51577
|
+
const oldTrackedSymbols = context.trackedSymbols;
|
|
51578
|
+
context.trackedSymbols = void 0;
|
|
51579
|
+
const oldEncounteredError = context.encounteredError;
|
|
51580
|
+
context.tracker = new SymbolTrackerImpl(context, {
|
|
51581
|
+
...oldTracker.inner,
|
|
51582
|
+
reportCyclicStructureError() {
|
|
51583
|
+
markError(() => oldTracker.reportCyclicStructureError());
|
|
51584
|
+
},
|
|
51585
|
+
reportInaccessibleThisError() {
|
|
51586
|
+
markError(() => oldTracker.reportInaccessibleThisError());
|
|
51587
|
+
},
|
|
51588
|
+
reportInaccessibleUniqueSymbolError() {
|
|
51589
|
+
markError(() => oldTracker.reportInaccessibleUniqueSymbolError());
|
|
51590
|
+
},
|
|
51591
|
+
reportLikelyUnsafeImportRequiredError(specifier) {
|
|
51592
|
+
markError(() => oldTracker.reportLikelyUnsafeImportRequiredError(specifier));
|
|
51593
|
+
},
|
|
51594
|
+
reportNonSerializableProperty(name) {
|
|
51595
|
+
markError(() => oldTracker.reportNonSerializableProperty(name));
|
|
51596
|
+
},
|
|
51597
|
+
reportPrivateInBaseOfClassExpression(propertyName) {
|
|
51598
|
+
markError(() => oldTracker.reportPrivateInBaseOfClassExpression(propertyName));
|
|
51599
|
+
},
|
|
51600
|
+
trackSymbol(sym, decl, meaning) {
|
|
51601
|
+
(trackedSymbols ?? (trackedSymbols = [])).push([sym, decl, meaning]);
|
|
51602
|
+
return false;
|
|
51603
|
+
},
|
|
51604
|
+
moduleResolverHost: context.tracker.moduleResolverHost
|
|
51605
|
+
}, context.tracker.moduleResolverHost);
|
|
51606
|
+
return {
|
|
51607
|
+
startRecoveryScope,
|
|
51608
|
+
finalizeBoundary,
|
|
51609
|
+
markError,
|
|
51610
|
+
hadError: () => hadError
|
|
51611
|
+
};
|
|
51612
|
+
function markError(unreportedError) {
|
|
51613
|
+
hadError = true;
|
|
51614
|
+
if (unreportedError) {
|
|
51615
|
+
(unreportedErrors ?? (unreportedErrors = [])).push(unreportedError);
|
|
51616
|
+
}
|
|
51617
|
+
}
|
|
51618
|
+
function startRecoveryScope() {
|
|
51619
|
+
const trackedSymbolsTop = (trackedSymbols == null ? void 0 : trackedSymbols.length) ?? 0;
|
|
51620
|
+
const unreportedErrorsTop = (unreportedErrors == null ? void 0 : unreportedErrors.length) ?? 0;
|
|
51621
|
+
return () => {
|
|
51622
|
+
hadError = false;
|
|
51623
|
+
if (trackedSymbols) {
|
|
51624
|
+
trackedSymbols.length = trackedSymbolsTop;
|
|
51625
|
+
}
|
|
51626
|
+
if (unreportedErrors) {
|
|
51627
|
+
unreportedErrors.length = unreportedErrorsTop;
|
|
51628
|
+
}
|
|
51629
|
+
};
|
|
51630
|
+
}
|
|
51631
|
+
function finalizeBoundary() {
|
|
51632
|
+
context.tracker = oldTracker;
|
|
51633
|
+
context.trackedSymbols = oldTrackedSymbols;
|
|
51634
|
+
context.encounteredError = oldEncounteredError;
|
|
51635
|
+
unreportedErrors == null ? void 0 : unreportedErrors.forEach((fn) => fn());
|
|
51636
|
+
if (hadError) {
|
|
51637
|
+
return false;
|
|
51638
|
+
}
|
|
51639
|
+
trackedSymbols == null ? void 0 : trackedSymbols.forEach(
|
|
51640
|
+
([symbol, enclosingDeclaration, meaning]) => context.tracker.trackSymbol(
|
|
51641
|
+
symbol,
|
|
51642
|
+
enclosingDeclaration,
|
|
51643
|
+
meaning
|
|
51644
|
+
)
|
|
51645
|
+
);
|
|
51646
|
+
return true;
|
|
51647
|
+
}
|
|
51446
51648
|
}
|
|
51447
51649
|
function enterNewScope(context, declaration, expandedParams, typeParameters, originalParameters, mapper) {
|
|
51448
51650
|
const cleanupContext = cloneNodeBuilderContext(context);
|
|
@@ -51585,7 +51787,7 @@ function createTypeChecker(host) {
|
|
|
51585
51787
|
return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
|
|
51586
51788
|
}
|
|
51587
51789
|
function typeToTypeNodeHelperWithPossibleReusableTypeNode(type, typeNode, context) {
|
|
51588
|
-
return typeNode &&
|
|
51790
|
+
return typeNode && getTypeFromTypeNode2(context, typeNode) === type && syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode) || typeToTypeNodeHelper(type, context);
|
|
51589
51791
|
}
|
|
51590
51792
|
function typeParameterToDeclaration(type, context, constraint = getConstraintOfTypeParameter(type)) {
|
|
51591
51793
|
const constraintNode = constraint && typeToTypeNodeHelperWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(type), context);
|
|
@@ -52207,35 +52409,34 @@ function createTypeChecker(host) {
|
|
|
52207
52409
|
}
|
|
52208
52410
|
return enclosingDeclaration;
|
|
52209
52411
|
}
|
|
52412
|
+
function serializeInferredTypeForDeclaration(symbol, context, type) {
|
|
52413
|
+
if (type.flags & 8192 /* UniqueESSymbol */ && type.symbol === symbol && (!context.enclosingDeclaration || some(symbol.declarations, (d) => getSourceFileOfNode(d) === context.enclosingFile))) {
|
|
52414
|
+
context.flags |= 1048576 /* AllowUniqueESSymbolType */;
|
|
52415
|
+
}
|
|
52416
|
+
const result = typeToTypeNodeHelper(type, context);
|
|
52417
|
+
return result;
|
|
52418
|
+
}
|
|
52210
52419
|
function serializeTypeForDeclaration(context, declaration, type, symbol) {
|
|
52211
|
-
var _a
|
|
52420
|
+
var _a;
|
|
52421
|
+
let result;
|
|
52212
52422
|
const addUndefinedForParameter = declaration && (isParameter(declaration) || isJSDocParameterTag(declaration)) && requiresAddingImplicitUndefined(declaration, context.enclosingDeclaration);
|
|
52213
|
-
const
|
|
52214
|
-
|
|
52215
|
-
|
|
52216
|
-
|
|
52217
|
-
|
|
52218
|
-
|
|
52219
|
-
|
|
52220
|
-
|
|
52221
|
-
if (declWithExistingAnnotation && !isFunctionLikeDeclaration(declWithExistingAnnotation) && !isGetAccessorDeclaration(declWithExistingAnnotation)) {
|
|
52222
|
-
const existing = getNonlocalEffectiveTypeAnnotationNode(declWithExistingAnnotation);
|
|
52223
|
-
const addUndefined = addUndefinedForParameter || !!(symbol.flags & 4 /* Property */ && symbol.flags & 16777216 /* Optional */ && isOptionalDeclaration(declWithExistingAnnotation) && ((_a = symbol.links) == null ? void 0 : _a.mappedType) && containsNonMissingUndefinedType(type));
|
|
52224
|
-
const result2 = !isTypePredicateNode(existing) && tryReuseExistingTypeNode(context, existing, type, declWithExistingAnnotation, addUndefined);
|
|
52225
|
-
if (result2) {
|
|
52226
|
-
restoreFlags();
|
|
52227
|
-
return result2;
|
|
52228
|
-
}
|
|
52423
|
+
const decl = declaration ?? symbol.valueDeclaration ?? getDeclarationWithTypeAnnotation(symbol) ?? ((_a = symbol.declarations) == null ? void 0 : _a[0]);
|
|
52424
|
+
if (decl) {
|
|
52425
|
+
if (isAccessor(decl)) {
|
|
52426
|
+
result = syntacticNodeBuilder.serializeTypeOfAccessor(decl, symbol, context);
|
|
52427
|
+
} else if (hasInferredType(decl) && !nodeIsSynthesized(decl) && !(getObjectFlags(type) & 196608 /* RequiresWidening */)) {
|
|
52428
|
+
const restore = addSymbolTypeToContext(context, symbol, type);
|
|
52429
|
+
result = syntacticNodeBuilder.serializeTypeOfDeclaration(decl, symbol, context);
|
|
52430
|
+
restore();
|
|
52229
52431
|
}
|
|
52230
52432
|
}
|
|
52231
|
-
if (
|
|
52232
|
-
|
|
52433
|
+
if (!result) {
|
|
52434
|
+
if (addUndefinedForParameter) {
|
|
52435
|
+
type = getOptionalType(type);
|
|
52436
|
+
}
|
|
52437
|
+
result = serializeInferredTypeForDeclaration(symbol, context, type);
|
|
52233
52438
|
}
|
|
52234
|
-
|
|
52235
|
-
const expr = decl && isDeclarationWithPossibleInnerTypeNodeReuse(decl) ? getPossibleTypeNodeReuseExpression(decl) : void 0;
|
|
52236
|
-
const result = expressionOrTypeToTypeNode(context, expr, type, addUndefinedForParameter);
|
|
52237
|
-
restoreFlags();
|
|
52238
|
-
return result;
|
|
52439
|
+
return result ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
52239
52440
|
}
|
|
52240
52441
|
function typeNodeIsEquivalentToType(annotatedDeclaration, type, typeFromTypeNode) {
|
|
52241
52442
|
if (typeFromTypeNode === type) {
|
|
@@ -52258,37 +52459,32 @@ function createTypeChecker(host) {
|
|
|
52258
52459
|
if (suppressAny) context.flags &= ~256 /* SuppressAnyReturnType */;
|
|
52259
52460
|
let returnTypeNode;
|
|
52260
52461
|
const returnType = getReturnTypeOfSignature(signature);
|
|
52261
|
-
if (
|
|
52262
|
-
if (signature.declaration && !(
|
|
52263
|
-
|
|
52462
|
+
if (!(suppressAny && isTypeAny(returnType))) {
|
|
52463
|
+
if (signature.declaration && !nodeIsSynthesized(signature.declaration)) {
|
|
52464
|
+
const declarationSymbol = getSymbolOfDeclaration(signature.declaration);
|
|
52465
|
+
const restore = addSymbolTypeToContext(context, declarationSymbol, returnType);
|
|
52466
|
+
returnTypeNode = syntacticNodeBuilder.serializeReturnTypeForSignature(signature.declaration, declarationSymbol, context);
|
|
52467
|
+
restore();
|
|
52468
|
+
}
|
|
52469
|
+
if (!returnTypeNode) {
|
|
52470
|
+
returnTypeNode = serializeInferredReturnTypeForSignature(context, signature, returnType);
|
|
52264
52471
|
}
|
|
52265
|
-
|
|
52266
|
-
|
|
52267
|
-
} else if (!suppressAny) {
|
|
52472
|
+
}
|
|
52473
|
+
if (!returnTypeNode && !suppressAny) {
|
|
52268
52474
|
returnTypeNode = factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
52269
52475
|
}
|
|
52270
52476
|
restoreFlags();
|
|
52271
52477
|
return returnTypeNode;
|
|
52272
52478
|
}
|
|
52273
|
-
function
|
|
52479
|
+
function serializeInferredReturnTypeForSignature(context, signature, returnType) {
|
|
52480
|
+
const oldSuppressReportInferenceFallback = context.suppressReportInferenceFallback;
|
|
52481
|
+
context.suppressReportInferenceFallback = true;
|
|
52274
52482
|
const typePredicate = getTypePredicateOfSignature(signature);
|
|
52275
|
-
const
|
|
52276
|
-
|
|
52277
|
-
|
|
52278
|
-
if (annotation) {
|
|
52279
|
-
const result = tryReuseExistingTypeNode(context, annotation, type, context.enclosingDeclaration);
|
|
52280
|
-
if (result) {
|
|
52281
|
-
return result;
|
|
52282
|
-
}
|
|
52283
|
-
}
|
|
52284
|
-
}
|
|
52285
|
-
if (typePredicate) {
|
|
52286
|
-
return typePredicateToTypePredicateNodeHelper(typePredicate, context);
|
|
52287
|
-
}
|
|
52288
|
-
const expr = signature.declaration && getPossibleTypeNodeReuseExpression(signature.declaration);
|
|
52289
|
-
return expressionOrTypeToTypeNode(context, expr, type);
|
|
52483
|
+
const returnTypeNode = typePredicate ? typePredicateToTypePredicateNodeHelper(context.mapper ? instantiateTypePredicate(typePredicate, context.mapper) : typePredicate, context) : typeToTypeNodeHelper(returnType, context);
|
|
52484
|
+
context.suppressReportInferenceFallback = oldSuppressReportInferenceFallback;
|
|
52485
|
+
return returnTypeNode;
|
|
52290
52486
|
}
|
|
52291
|
-
function trackExistingEntityName(node, context) {
|
|
52487
|
+
function trackExistingEntityName(node, context, enclosingDeclaration = context.enclosingDeclaration) {
|
|
52292
52488
|
let introducesError = false;
|
|
52293
52489
|
const leftmost = getFirstIdentifier(node);
|
|
52294
52490
|
if (isInJSFile(node) && (isExportsIdentifier(leftmost) || isModuleExportsAccessExpression(leftmost.parent) || isQualifiedName(leftmost.parent) && isModuleIdentifier(leftmost.parent.left) && isExportsIdentifier(leftmost.parent.right))) {
|
|
@@ -52339,7 +52535,7 @@ function createTypeChecker(host) {
|
|
|
52339
52535
|
if (
|
|
52340
52536
|
// Check for unusable parameters symbols
|
|
52341
52537
|
symAtLocation === unknownSymbol || // If the symbol is not found, but was not found in the original scope either we probably have an error, don't reuse the node
|
|
52342
|
-
symAtLocation === void 0 && sym !== void 0 || // If the symbol is found both in declaration scope and in current scope then it
|
|
52538
|
+
symAtLocation === void 0 && sym !== void 0 || // If the symbol is found both in declaration scope and in current scope then it should point to the same reference
|
|
52343
52539
|
symAtLocation && sym && !getSymbolIfSameReference(getExportSymbolOfValueSymbolIfExported(symAtLocation), sym)
|
|
52344
52540
|
) {
|
|
52345
52541
|
if (symAtLocation !== unknownSymbol) {
|
|
@@ -52360,7 +52556,7 @@ function createTypeChecker(host) {
|
|
|
52360
52556
|
if (!(sym.flags & 262144 /* TypeParameter */) && // Type parameters are visible in the current context if they are are resolvable
|
|
52361
52557
|
!isDeclarationName(node) && isSymbolAccessible(
|
|
52362
52558
|
sym,
|
|
52363
|
-
|
|
52559
|
+
enclosingDeclaration,
|
|
52364
52560
|
meaning,
|
|
52365
52561
|
/*shouldComputeAliasesToMakeVisible*/
|
|
52366
52562
|
false
|
|
@@ -52368,7 +52564,7 @@ function createTypeChecker(host) {
|
|
|
52368
52564
|
context.tracker.reportInferenceFallback(node);
|
|
52369
52565
|
introducesError = true;
|
|
52370
52566
|
} else {
|
|
52371
|
-
context.tracker.trackSymbol(sym,
|
|
52567
|
+
context.tracker.trackSymbol(sym, enclosingDeclaration, meaning);
|
|
52372
52568
|
}
|
|
52373
52569
|
return { introducesError, node: attachSymbolToLeftmostIdentifier(node) };
|
|
52374
52570
|
}
|
|
@@ -52412,6 +52608,15 @@ function createTypeChecker(host) {
|
|
|
52412
52608
|
return symbolToTypeNode(resolvedSymbol, context, meaning, typeArguments);
|
|
52413
52609
|
}
|
|
52414
52610
|
function canReuseTypeNode(context, existing) {
|
|
52611
|
+
const type = getTypeFromTypeNode2(
|
|
52612
|
+
context,
|
|
52613
|
+
existing,
|
|
52614
|
+
/*noMappedTypes*/
|
|
52615
|
+
true
|
|
52616
|
+
);
|
|
52617
|
+
if (!type) {
|
|
52618
|
+
return false;
|
|
52619
|
+
}
|
|
52415
52620
|
if (isInJSFile(existing)) {
|
|
52416
52621
|
if (isLiteralImportTypeNode(existing)) {
|
|
52417
52622
|
void getTypeFromImportTypeNode(existing);
|
|
@@ -52421,29 +52626,16 @@ function createTypeChecker(host) {
|
|
|
52421
52626
|
!(length(existing.typeArguments) >= getMinTypeArgumentCount(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(nodeSymbol))));
|
|
52422
52627
|
}
|
|
52423
52628
|
}
|
|
52424
|
-
if (isThisTypeNode(existing)) {
|
|
52425
|
-
if (context.mapper === void 0) return true;
|
|
52426
|
-
const type = getTypeFromTypeNode2(
|
|
52427
|
-
context,
|
|
52428
|
-
existing,
|
|
52429
|
-
/*noMappedTypes*/
|
|
52430
|
-
true
|
|
52431
|
-
);
|
|
52432
|
-
return !!type;
|
|
52433
|
-
}
|
|
52434
52629
|
if (isTypeReferenceNode(existing)) {
|
|
52435
52630
|
if (isConstTypeReference(existing)) return false;
|
|
52436
|
-
const type = getTypeFromTypeReference(existing);
|
|
52437
52631
|
const symbol = getNodeLinks(existing).resolvedSymbol;
|
|
52438
52632
|
if (!symbol) return false;
|
|
52439
52633
|
if (symbol.flags & 262144 /* TypeParameter */) {
|
|
52440
|
-
const
|
|
52441
|
-
|
|
52442
|
-
return false;
|
|
52443
|
-
}
|
|
52634
|
+
const declaredType = getDeclaredTypeOfSymbol(symbol);
|
|
52635
|
+
return !(context.mapper && getMappedType(declaredType, context.mapper) !== declaredType);
|
|
52444
52636
|
}
|
|
52445
52637
|
if (isInJSDoc(existing)) {
|
|
52446
|
-
return existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type) && !getIntendedTypeFromJSDocTypeReference(existing) && symbol.flags & 788968 /* Type
|
|
52638
|
+
return existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(existing, type) && !getIntendedTypeFromJSDocTypeReference(existing) && !!(symbol.flags & 788968 /* Type */);
|
|
52447
52639
|
}
|
|
52448
52640
|
}
|
|
52449
52641
|
if (isTypeOperatorNode(existing) && existing.operator === 158 /* UniqueKeyword */ && existing.type.kind === 155 /* SymbolKeyword */) {
|
|
@@ -52452,511 +52644,15 @@ function createTypeChecker(host) {
|
|
|
52452
52644
|
}
|
|
52453
52645
|
return true;
|
|
52454
52646
|
}
|
|
52455
|
-
function serializeExistingTypeNode(context, typeNode) {
|
|
52647
|
+
function serializeExistingTypeNode(context, typeNode, addUndefined) {
|
|
52456
52648
|
const type = getTypeFromTypeNode2(context, typeNode);
|
|
52457
|
-
|
|
52458
|
-
|
|
52459
|
-
|
|
52460
|
-
|
|
52461
|
-
cancellationToken.throwIfCancellationRequested();
|
|
52462
|
-
}
|
|
52463
|
-
let hadError = false;
|
|
52464
|
-
const { finalizeBoundary, startRecoveryScope } = createRecoveryBoundary();
|
|
52465
|
-
const transformed = visitNode(existing, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52466
|
-
if (!finalizeBoundary()) {
|
|
52467
|
-
return void 0;
|
|
52468
|
-
}
|
|
52469
|
-
context.approximateLength += existing.end - existing.pos;
|
|
52470
|
-
return transformed;
|
|
52471
|
-
function visitExistingNodeTreeSymbols(node) {
|
|
52472
|
-
if (hadError) return node;
|
|
52473
|
-
const recover = startRecoveryScope();
|
|
52474
|
-
const onExitNewScope = isNewScopeNode(node) ? onEnterNewScope(node) : void 0;
|
|
52475
|
-
const result = visitExistingNodeTreeSymbolsWorker(node);
|
|
52476
|
-
onExitNewScope == null ? void 0 : onExitNewScope();
|
|
52477
|
-
if (hadError) {
|
|
52478
|
-
if (isTypeNode(node) && !isTypePredicateNode(node)) {
|
|
52479
|
-
recover();
|
|
52480
|
-
return serializeExistingTypeNode(context, node);
|
|
52481
|
-
}
|
|
52482
|
-
return node;
|
|
52483
|
-
}
|
|
52484
|
-
return result ? setTextRange2(context, result, node) : void 0;
|
|
52485
|
-
}
|
|
52486
|
-
function createRecoveryBoundary() {
|
|
52487
|
-
let trackedSymbols;
|
|
52488
|
-
let unreportedErrors;
|
|
52489
|
-
const oldTracker = context.tracker;
|
|
52490
|
-
const oldTrackedSymbols = context.trackedSymbols;
|
|
52491
|
-
context.trackedSymbols = void 0;
|
|
52492
|
-
const oldEncounteredError = context.encounteredError;
|
|
52493
|
-
context.tracker = new SymbolTrackerImpl(context, {
|
|
52494
|
-
...oldTracker.inner,
|
|
52495
|
-
reportCyclicStructureError() {
|
|
52496
|
-
markError(() => oldTracker.reportCyclicStructureError());
|
|
52497
|
-
},
|
|
52498
|
-
reportInaccessibleThisError() {
|
|
52499
|
-
markError(() => oldTracker.reportInaccessibleThisError());
|
|
52500
|
-
},
|
|
52501
|
-
reportInaccessibleUniqueSymbolError() {
|
|
52502
|
-
markError(() => oldTracker.reportInaccessibleUniqueSymbolError());
|
|
52503
|
-
},
|
|
52504
|
-
reportLikelyUnsafeImportRequiredError(specifier) {
|
|
52505
|
-
markError(() => oldTracker.reportLikelyUnsafeImportRequiredError(specifier));
|
|
52506
|
-
},
|
|
52507
|
-
reportNonSerializableProperty(name) {
|
|
52508
|
-
markError(() => oldTracker.reportNonSerializableProperty(name));
|
|
52509
|
-
},
|
|
52510
|
-
trackSymbol(sym, decl, meaning) {
|
|
52511
|
-
(trackedSymbols ?? (trackedSymbols = [])).push([sym, decl, meaning]);
|
|
52512
|
-
return false;
|
|
52513
|
-
},
|
|
52514
|
-
moduleResolverHost: context.tracker.moduleResolverHost
|
|
52515
|
-
}, context.tracker.moduleResolverHost);
|
|
52516
|
-
return {
|
|
52517
|
-
startRecoveryScope: startRecoveryScope2,
|
|
52518
|
-
finalizeBoundary: finalizeBoundary2
|
|
52519
|
-
};
|
|
52520
|
-
function markError(unreportedError) {
|
|
52521
|
-
hadError = true;
|
|
52522
|
-
(unreportedErrors ?? (unreportedErrors = [])).push(unreportedError);
|
|
52523
|
-
}
|
|
52524
|
-
function startRecoveryScope2() {
|
|
52525
|
-
const trackedSymbolsTop = (trackedSymbols == null ? void 0 : trackedSymbols.length) ?? 0;
|
|
52526
|
-
const unreportedErrorsTop = (unreportedErrors == null ? void 0 : unreportedErrors.length) ?? 0;
|
|
52527
|
-
return () => {
|
|
52528
|
-
hadError = false;
|
|
52529
|
-
if (trackedSymbols) {
|
|
52530
|
-
trackedSymbols.length = trackedSymbolsTop;
|
|
52531
|
-
}
|
|
52532
|
-
if (unreportedErrors) {
|
|
52533
|
-
unreportedErrors.length = unreportedErrorsTop;
|
|
52534
|
-
}
|
|
52535
|
-
};
|
|
52536
|
-
}
|
|
52537
|
-
function finalizeBoundary2() {
|
|
52538
|
-
context.tracker = oldTracker;
|
|
52539
|
-
context.trackedSymbols = oldTrackedSymbols;
|
|
52540
|
-
context.encounteredError = oldEncounteredError;
|
|
52541
|
-
unreportedErrors == null ? void 0 : unreportedErrors.forEach((fn) => fn());
|
|
52542
|
-
if (hadError) {
|
|
52543
|
-
return false;
|
|
52544
|
-
}
|
|
52545
|
-
trackedSymbols == null ? void 0 : trackedSymbols.forEach(
|
|
52546
|
-
([symbol, enclosingDeclaration, meaning]) => context.tracker.trackSymbol(
|
|
52547
|
-
symbol,
|
|
52548
|
-
enclosingDeclaration,
|
|
52549
|
-
meaning
|
|
52550
|
-
)
|
|
52551
|
-
);
|
|
52552
|
-
return true;
|
|
52553
|
-
}
|
|
52554
|
-
}
|
|
52555
|
-
function onEnterNewScope(node) {
|
|
52556
|
-
return enterNewScope(context, node, getParametersInScope(node), getTypeParametersInScope(node));
|
|
52557
|
-
}
|
|
52558
|
-
function tryVisitSimpleTypeNode(node) {
|
|
52559
|
-
const innerNode = skipTypeParentheses(node);
|
|
52560
|
-
switch (innerNode.kind) {
|
|
52561
|
-
case 183 /* TypeReference */:
|
|
52562
|
-
return tryVisitTypeReference(innerNode);
|
|
52563
|
-
case 186 /* TypeQuery */:
|
|
52564
|
-
return tryVisitTypeQuery(innerNode);
|
|
52565
|
-
case 199 /* IndexedAccessType */:
|
|
52566
|
-
return tryVisitIndexedAccess(innerNode);
|
|
52567
|
-
case 198 /* TypeOperator */:
|
|
52568
|
-
const typeOperatorNode = innerNode;
|
|
52569
|
-
if (typeOperatorNode.operator === 143 /* KeyOfKeyword */) {
|
|
52570
|
-
return tryVisitKeyOf(typeOperatorNode);
|
|
52571
|
-
}
|
|
52572
|
-
}
|
|
52573
|
-
return visitNode(node, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52574
|
-
}
|
|
52575
|
-
function tryVisitIndexedAccess(node) {
|
|
52576
|
-
const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
|
|
52577
|
-
if (resultObjectType === void 0) {
|
|
52578
|
-
return void 0;
|
|
52579
|
-
}
|
|
52580
|
-
return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode));
|
|
52581
|
-
}
|
|
52582
|
-
function tryVisitKeyOf(node) {
|
|
52583
|
-
Debug.assertEqual(node.operator, 143 /* KeyOfKeyword */);
|
|
52584
|
-
const type = tryVisitSimpleTypeNode(node.type);
|
|
52585
|
-
if (type === void 0) {
|
|
52586
|
-
return void 0;
|
|
52587
|
-
}
|
|
52588
|
-
return factory.updateTypeOperatorNode(node, type);
|
|
52589
|
-
}
|
|
52590
|
-
function tryVisitTypeQuery(node) {
|
|
52591
|
-
const { introducesError, node: exprName } = trackExistingEntityName(node.exprName, context);
|
|
52592
|
-
if (!introducesError) {
|
|
52593
|
-
return factory.updateTypeQueryNode(
|
|
52594
|
-
node,
|
|
52595
|
-
exprName,
|
|
52596
|
-
visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode)
|
|
52597
|
-
);
|
|
52598
|
-
}
|
|
52599
|
-
const serializedName = serializeTypeName(
|
|
52600
|
-
context,
|
|
52601
|
-
node.exprName,
|
|
52602
|
-
/*isTypeOf*/
|
|
52603
|
-
true
|
|
52604
|
-
);
|
|
52605
|
-
if (serializedName) {
|
|
52606
|
-
return setTextRange2(context, serializedName, node.exprName);
|
|
52607
|
-
}
|
|
52608
|
-
}
|
|
52609
|
-
function tryVisitTypeReference(node) {
|
|
52610
|
-
if (canReuseTypeNode(context, node)) {
|
|
52611
|
-
const { introducesError, node: newName } = trackExistingEntityName(node.typeName, context);
|
|
52612
|
-
const typeArguments = visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52613
|
-
if (!introducesError) {
|
|
52614
|
-
const updated = factory.updateTypeReferenceNode(
|
|
52615
|
-
node,
|
|
52616
|
-
newName,
|
|
52617
|
-
typeArguments
|
|
52618
|
-
);
|
|
52619
|
-
return setTextRange2(context, updated, node);
|
|
52620
|
-
} else {
|
|
52621
|
-
const serializedName = serializeTypeName(
|
|
52622
|
-
context,
|
|
52623
|
-
node.typeName,
|
|
52624
|
-
/*isTypeOf*/
|
|
52625
|
-
false,
|
|
52626
|
-
typeArguments
|
|
52627
|
-
);
|
|
52628
|
-
if (serializedName) {
|
|
52629
|
-
return setTextRange2(context, serializedName, node.typeName);
|
|
52630
|
-
}
|
|
52631
|
-
}
|
|
52632
|
-
}
|
|
52633
|
-
}
|
|
52634
|
-
function visitExistingNodeTreeSymbolsWorker(node) {
|
|
52635
|
-
if (isJSDocTypeExpression(node)) {
|
|
52636
|
-
return visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52637
|
-
}
|
|
52638
|
-
if (isJSDocAllType(node) || node.kind === 319 /* JSDocNamepathType */) {
|
|
52639
|
-
return factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
52640
|
-
}
|
|
52641
|
-
if (isJSDocUnknownType(node)) {
|
|
52642
|
-
return factory.createKeywordTypeNode(159 /* UnknownKeyword */);
|
|
52643
|
-
}
|
|
52644
|
-
if (isJSDocNullableType(node)) {
|
|
52645
|
-
return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createLiteralTypeNode(factory.createNull())]);
|
|
52646
|
-
}
|
|
52647
|
-
if (isJSDocOptionalType(node)) {
|
|
52648
|
-
return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
|
|
52649
|
-
}
|
|
52650
|
-
if (isJSDocNonNullableType(node)) {
|
|
52651
|
-
return visitNode(node.type, visitExistingNodeTreeSymbols);
|
|
52652
|
-
}
|
|
52653
|
-
if (isJSDocVariadicType(node)) {
|
|
52654
|
-
return factory.createArrayTypeNode(visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
|
|
52655
|
-
}
|
|
52656
|
-
if (isJSDocTypeLiteral(node)) {
|
|
52657
|
-
return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, (t) => {
|
|
52658
|
-
const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier);
|
|
52659
|
-
const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode2(context, node), name.escapedText);
|
|
52660
|
-
const overrideTypeNode = typeViaParent && t.typeExpression && getTypeFromTypeNode2(context, t.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : void 0;
|
|
52661
|
-
return factory.createPropertySignature(
|
|
52662
|
-
/*modifiers*/
|
|
52663
|
-
void 0,
|
|
52664
|
-
name,
|
|
52665
|
-
t.isBracketed || t.typeExpression && isJSDocOptionalType(t.typeExpression.type) ? factory.createToken(58 /* QuestionToken */) : void 0,
|
|
52666
|
-
overrideTypeNode || t.typeExpression && visitNode(t.typeExpression.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
|
|
52667
|
-
);
|
|
52668
|
-
}));
|
|
52669
|
-
}
|
|
52670
|
-
if (isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.escapedText === "") {
|
|
52671
|
-
return setOriginalNode(factory.createKeywordTypeNode(133 /* AnyKeyword */), node);
|
|
52672
|
-
}
|
|
52673
|
-
if ((isExpressionWithTypeArguments(node) || isTypeReferenceNode(node)) && isJSDocIndexSignature(node)) {
|
|
52674
|
-
return factory.createTypeLiteralNode([factory.createIndexSignature(
|
|
52675
|
-
/*modifiers*/
|
|
52676
|
-
void 0,
|
|
52677
|
-
[factory.createParameterDeclaration(
|
|
52678
|
-
/*modifiers*/
|
|
52679
|
-
void 0,
|
|
52680
|
-
/*dotDotDotToken*/
|
|
52681
|
-
void 0,
|
|
52682
|
-
"x",
|
|
52683
|
-
/*questionToken*/
|
|
52684
|
-
void 0,
|
|
52685
|
-
visitNode(node.typeArguments[0], visitExistingNodeTreeSymbols, isTypeNode)
|
|
52686
|
-
)],
|
|
52687
|
-
visitNode(node.typeArguments[1], visitExistingNodeTreeSymbols, isTypeNode)
|
|
52688
|
-
)]);
|
|
52689
|
-
}
|
|
52690
|
-
if (isJSDocFunctionType(node)) {
|
|
52691
|
-
if (isJSDocConstructSignature(node)) {
|
|
52692
|
-
let newTypeNode;
|
|
52693
|
-
return factory.createConstructorTypeNode(
|
|
52694
|
-
/*modifiers*/
|
|
52695
|
-
void 0,
|
|
52696
|
-
visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
|
|
52697
|
-
mapDefined(node.parameters, (p, i) => p.name && isIdentifier(p.name) && p.name.escapedText === "new" ? (newTypeNode = p.type, void 0) : factory.createParameterDeclaration(
|
|
52698
|
-
/*modifiers*/
|
|
52699
|
-
void 0,
|
|
52700
|
-
getEffectiveDotDotDotForParameter(p),
|
|
52701
|
-
setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
|
|
52702
|
-
factory.cloneNode(p.questionToken),
|
|
52703
|
-
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
|
|
52704
|
-
/*initializer*/
|
|
52705
|
-
void 0
|
|
52706
|
-
)),
|
|
52707
|
-
visitNode(newTypeNode || node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
|
|
52708
|
-
);
|
|
52709
|
-
} else {
|
|
52710
|
-
return factory.createFunctionTypeNode(
|
|
52711
|
-
visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
|
|
52712
|
-
map(node.parameters, (p, i) => factory.createParameterDeclaration(
|
|
52713
|
-
/*modifiers*/
|
|
52714
|
-
void 0,
|
|
52715
|
-
getEffectiveDotDotDotForParameter(p),
|
|
52716
|
-
setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
|
|
52717
|
-
factory.cloneNode(p.questionToken),
|
|
52718
|
-
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
|
|
52719
|
-
/*initializer*/
|
|
52720
|
-
void 0
|
|
52721
|
-
)),
|
|
52722
|
-
visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
|
|
52723
|
-
);
|
|
52724
|
-
}
|
|
52725
|
-
}
|
|
52726
|
-
if (isThisTypeNode(node)) {
|
|
52727
|
-
if (canReuseTypeNode(context, node)) {
|
|
52728
|
-
return node;
|
|
52729
|
-
}
|
|
52730
|
-
hadError = true;
|
|
52731
|
-
return node;
|
|
52732
|
-
}
|
|
52733
|
-
if (isTypeParameterDeclaration(node)) {
|
|
52734
|
-
return factory.updateTypeParameterDeclaration(
|
|
52735
|
-
node,
|
|
52736
|
-
visitNodes2(node.modifiers, visitExistingNodeTreeSymbols, isModifier),
|
|
52737
|
-
setTextRange2(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node),
|
|
52738
|
-
visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode),
|
|
52739
|
-
visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode)
|
|
52740
|
-
);
|
|
52741
|
-
}
|
|
52742
|
-
if (isIndexedAccessTypeNode(node)) {
|
|
52743
|
-
const result = tryVisitIndexedAccess(node);
|
|
52744
|
-
if (!result) {
|
|
52745
|
-
hadError = true;
|
|
52746
|
-
return node;
|
|
52747
|
-
}
|
|
52748
|
-
return result;
|
|
52749
|
-
}
|
|
52750
|
-
if (isTypeReferenceNode(node)) {
|
|
52751
|
-
const result = tryVisitTypeReference(node);
|
|
52752
|
-
if (result) {
|
|
52753
|
-
return result;
|
|
52754
|
-
}
|
|
52755
|
-
hadError = true;
|
|
52756
|
-
return node;
|
|
52757
|
-
}
|
|
52758
|
-
if (isLiteralImportTypeNode(node)) {
|
|
52759
|
-
const nodeSymbol = getNodeLinks(node).resolvedSymbol;
|
|
52760
|
-
if (isInJSDoc(node) && nodeSymbol && // The import type resolved using jsdoc fallback logic
|
|
52761
|
-
(!node.isTypeOf && !(nodeSymbol.flags & 788968 /* Type */) || // The import type had type arguments autofilled by js fallback logic
|
|
52762
|
-
!(length(node.typeArguments) >= getMinTypeArgumentCount(getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(nodeSymbol))))) {
|
|
52763
|
-
return setTextRange2(context, typeToTypeNodeHelper(getTypeFromTypeNode2(context, node), context), node);
|
|
52764
|
-
}
|
|
52765
|
-
return factory.updateImportTypeNode(
|
|
52766
|
-
node,
|
|
52767
|
-
factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier2(node, node.argument.literal)),
|
|
52768
|
-
visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes),
|
|
52769
|
-
visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName),
|
|
52770
|
-
visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
|
|
52771
|
-
node.isTypeOf
|
|
52772
|
-
);
|
|
52773
|
-
}
|
|
52774
|
-
if (isNamedDeclaration(node) && node.name.kind === 167 /* ComputedPropertyName */ && !isLateBindableName(node.name)) {
|
|
52775
|
-
if (!hasDynamicName(node)) {
|
|
52776
|
-
return visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
52777
|
-
}
|
|
52778
|
-
if (!(context.internalFlags & 8 /* AllowUnresolvedNames */ && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & 1 /* Any */)) {
|
|
52779
|
-
return void 0;
|
|
52780
|
-
}
|
|
52781
|
-
}
|
|
52782
|
-
if (isFunctionLike(node) && !node.type || isPropertyDeclaration(node) && !node.type && !node.initializer || isPropertySignature(node) && !node.type && !node.initializer || isParameter(node) && !node.type && !node.initializer) {
|
|
52783
|
-
let visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
52784
|
-
if (visited === node) {
|
|
52785
|
-
visited = setTextRange2(context, factory.cloneNode(node), node);
|
|
52786
|
-
}
|
|
52787
|
-
visited.type = factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
52788
|
-
if (isParameter(node)) {
|
|
52789
|
-
visited.modifiers = void 0;
|
|
52790
|
-
}
|
|
52791
|
-
return visited;
|
|
52792
|
-
}
|
|
52793
|
-
if (isTypeQueryNode(node)) {
|
|
52794
|
-
const result = tryVisitTypeQuery(node);
|
|
52795
|
-
if (!result) {
|
|
52796
|
-
hadError = true;
|
|
52797
|
-
return node;
|
|
52798
|
-
}
|
|
52799
|
-
return result;
|
|
52800
|
-
}
|
|
52801
|
-
if (isComputedPropertyName(node) && isEntityNameExpression(node.expression)) {
|
|
52802
|
-
const { node: result, introducesError } = trackExistingEntityName(node.expression, context);
|
|
52803
|
-
if (!introducesError) {
|
|
52804
|
-
return factory.updateComputedPropertyName(node, result);
|
|
52805
|
-
} else {
|
|
52806
|
-
const type = getWidenedType(getRegularTypeOfExpression(node.expression));
|
|
52807
|
-
const computedPropertyNameType = typeToTypeNodeHelper(type, context);
|
|
52808
|
-
let literal;
|
|
52809
|
-
if (isLiteralTypeNode(computedPropertyNameType)) {
|
|
52810
|
-
literal = computedPropertyNameType.literal;
|
|
52811
|
-
} else {
|
|
52812
|
-
const evaluated = evaluateEntityNameExpression(node.expression);
|
|
52813
|
-
const literalNode = typeof evaluated.value === "string" ? factory.createStringLiteral(
|
|
52814
|
-
evaluated.value,
|
|
52815
|
-
/*isSingleQuote*/
|
|
52816
|
-
void 0
|
|
52817
|
-
) : typeof evaluated.value === "number" ? factory.createNumericLiteral(
|
|
52818
|
-
evaluated.value,
|
|
52819
|
-
/*numericLiteralFlags*/
|
|
52820
|
-
0
|
|
52821
|
-
) : void 0;
|
|
52822
|
-
if (!literalNode) {
|
|
52823
|
-
if (isImportTypeNode(computedPropertyNameType)) {
|
|
52824
|
-
trackComputedName(node.expression, context.enclosingDeclaration, context);
|
|
52825
|
-
}
|
|
52826
|
-
return node;
|
|
52827
|
-
}
|
|
52828
|
-
literal = literalNode;
|
|
52829
|
-
}
|
|
52830
|
-
if (literal.kind === 11 /* StringLiteral */ && isIdentifierText(literal.text, getEmitScriptTarget(compilerOptions))) {
|
|
52831
|
-
return factory.createIdentifier(literal.text);
|
|
52832
|
-
}
|
|
52833
|
-
if (literal.kind === 9 /* NumericLiteral */ && !literal.text.startsWith("-")) {
|
|
52834
|
-
return literal;
|
|
52835
|
-
}
|
|
52836
|
-
return factory.updateComputedPropertyName(node, literal);
|
|
52837
|
-
}
|
|
52838
|
-
}
|
|
52839
|
-
if (isTypePredicateNode(node)) {
|
|
52840
|
-
let parameterName;
|
|
52841
|
-
if (isIdentifier(node.parameterName)) {
|
|
52842
|
-
const { node: result, introducesError } = trackExistingEntityName(node.parameterName, context);
|
|
52843
|
-
hadError = hadError || introducesError;
|
|
52844
|
-
parameterName = result;
|
|
52845
|
-
} else {
|
|
52846
|
-
parameterName = factory.cloneNode(node.parameterName);
|
|
52847
|
-
}
|
|
52848
|
-
return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
|
|
52849
|
-
}
|
|
52850
|
-
if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) {
|
|
52851
|
-
const visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
52852
|
-
const clone = setTextRange2(context, visited === node ? factory.cloneNode(node) : visited, node);
|
|
52853
|
-
const flags = getEmitFlags(clone);
|
|
52854
|
-
setEmitFlags(clone, flags | (context.flags & 1024 /* MultilineObjectLiterals */ && isTypeLiteralNode(node) ? 0 : 1 /* SingleLine */));
|
|
52855
|
-
return clone;
|
|
52856
|
-
}
|
|
52857
|
-
if (isStringLiteral(node) && !!(context.flags & 268435456 /* UseSingleQuotesForStringLiteralType */) && !node.singleQuote) {
|
|
52858
|
-
const clone = factory.cloneNode(node);
|
|
52859
|
-
clone.singleQuote = true;
|
|
52860
|
-
return clone;
|
|
52861
|
-
}
|
|
52862
|
-
if (isConditionalTypeNode(node)) {
|
|
52863
|
-
const checkType = visitNode(node.checkType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52864
|
-
const disposeScope = onEnterNewScope(node);
|
|
52865
|
-
const extendType = visitNode(node.extendsType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52866
|
-
const trueType2 = visitNode(node.trueType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52867
|
-
disposeScope();
|
|
52868
|
-
const falseType2 = visitNode(node.falseType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
52869
|
-
return factory.updateConditionalTypeNode(
|
|
52870
|
-
node,
|
|
52871
|
-
checkType,
|
|
52872
|
-
extendType,
|
|
52873
|
-
trueType2,
|
|
52874
|
-
falseType2
|
|
52875
|
-
);
|
|
52876
|
-
}
|
|
52877
|
-
if (isTypeOperatorNode(node)) {
|
|
52878
|
-
if (node.operator === 158 /* UniqueKeyword */ && node.type.kind === 155 /* SymbolKeyword */) {
|
|
52879
|
-
if (!canReuseTypeNode(context, node)) {
|
|
52880
|
-
hadError = true;
|
|
52881
|
-
return node;
|
|
52882
|
-
}
|
|
52883
|
-
} else if (node.operator === 143 /* KeyOfKeyword */) {
|
|
52884
|
-
const result = tryVisitKeyOf(node);
|
|
52885
|
-
if (!result) {
|
|
52886
|
-
hadError = true;
|
|
52887
|
-
return node;
|
|
52888
|
-
}
|
|
52889
|
-
return result;
|
|
52890
|
-
}
|
|
52891
|
-
}
|
|
52892
|
-
return visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
52893
|
-
function visitEachChild2(node2, visitor) {
|
|
52894
|
-
const nonlocalNode = !context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(node2);
|
|
52895
|
-
return visitEachChild(
|
|
52896
|
-
node2,
|
|
52897
|
-
visitor,
|
|
52898
|
-
/*context*/
|
|
52899
|
-
void 0,
|
|
52900
|
-
nonlocalNode ? visitNodesWithoutCopyingPositions : void 0
|
|
52901
|
-
);
|
|
52902
|
-
}
|
|
52903
|
-
function visitNodesWithoutCopyingPositions(nodes, visitor, test, start, count) {
|
|
52904
|
-
let result = visitNodes2(nodes, visitor, test, start, count);
|
|
52905
|
-
if (result) {
|
|
52906
|
-
if (result.pos !== -1 || result.end !== -1) {
|
|
52907
|
-
if (result === nodes) {
|
|
52908
|
-
result = factory.createNodeArray(nodes.slice(), nodes.hasTrailingComma);
|
|
52909
|
-
}
|
|
52910
|
-
setTextRangePosEnd(result, -1, -1);
|
|
52911
|
-
}
|
|
52912
|
-
}
|
|
52913
|
-
return result;
|
|
52914
|
-
}
|
|
52915
|
-
function getEffectiveDotDotDotForParameter(p) {
|
|
52916
|
-
return p.dotDotDotToken || (p.type && isJSDocVariadicType(p.type) ? factory.createToken(26 /* DotDotDotToken */) : void 0);
|
|
52917
|
-
}
|
|
52918
|
-
function getNameForJSDocFunctionParameter(p, index) {
|
|
52919
|
-
return p.name && isIdentifier(p.name) && p.name.escapedText === "this" ? "this" : getEffectiveDotDotDotForParameter(p) ? `args` : `arg${index}`;
|
|
52920
|
-
}
|
|
52921
|
-
function rewriteModuleSpecifier2(parent, lit) {
|
|
52922
|
-
if (context.bundled || context.enclosingFile !== getSourceFileOfNode(lit)) {
|
|
52923
|
-
let name = lit.text;
|
|
52924
|
-
const nodeSymbol = getNodeLinks(node).resolvedSymbol;
|
|
52925
|
-
const meaning = parent.isTypeOf ? 111551 /* Value */ : 788968 /* Type */;
|
|
52926
|
-
const parentSymbol = nodeSymbol && isSymbolAccessible(
|
|
52927
|
-
nodeSymbol,
|
|
52928
|
-
context.enclosingDeclaration,
|
|
52929
|
-
meaning,
|
|
52930
|
-
/*shouldComputeAliasesToMakeVisible*/
|
|
52931
|
-
false
|
|
52932
|
-
).accessibility === 0 /* Accessible */ && lookupSymbolChain(
|
|
52933
|
-
nodeSymbol,
|
|
52934
|
-
context,
|
|
52935
|
-
meaning,
|
|
52936
|
-
/*yieldModuleSymbol*/
|
|
52937
|
-
true
|
|
52938
|
-
)[0];
|
|
52939
|
-
if (parentSymbol && isExternalModuleSymbol(parentSymbol)) {
|
|
52940
|
-
name = getSpecifierForModuleSymbol(parentSymbol, context);
|
|
52941
|
-
} else {
|
|
52942
|
-
const targetFile = getExternalModuleFileFromDeclaration(parent);
|
|
52943
|
-
if (targetFile) {
|
|
52944
|
-
name = getSpecifierForModuleSymbol(targetFile.symbol, context);
|
|
52945
|
-
}
|
|
52946
|
-
}
|
|
52947
|
-
if (name.includes("/node_modules/")) {
|
|
52948
|
-
context.encounteredError = true;
|
|
52949
|
-
if (context.tracker.reportLikelyUnsafeImportRequiredError) {
|
|
52950
|
-
context.tracker.reportLikelyUnsafeImportRequiredError(name);
|
|
52951
|
-
}
|
|
52952
|
-
}
|
|
52953
|
-
if (name !== lit.text) {
|
|
52954
|
-
return setOriginalNode(factory.createStringLiteral(name), lit);
|
|
52955
|
-
}
|
|
52956
|
-
}
|
|
52957
|
-
return visitNode(lit, visitExistingNodeTreeSymbols, isStringLiteral);
|
|
52649
|
+
if (addUndefined && !someType(type, (t) => !!(t.flags & 32768 /* Undefined */)) && canReuseTypeNode(context, typeNode)) {
|
|
52650
|
+
const clone = syntacticNodeBuilder.tryReuseExistingTypeNode(context, typeNode);
|
|
52651
|
+
if (clone) {
|
|
52652
|
+
return factory.createUnionTypeNode([clone, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
|
|
52958
52653
|
}
|
|
52959
52654
|
}
|
|
52655
|
+
return typeToTypeNodeHelper(type, context);
|
|
52960
52656
|
}
|
|
52961
52657
|
function symbolTableToDeclarationStatements(symbolTable, context) {
|
|
52962
52658
|
var _a;
|
|
@@ -53433,13 +53129,7 @@ function createTypeChecker(host) {
|
|
|
53433
53129
|
context.flags |= 8388608 /* InTypeAlias */;
|
|
53434
53130
|
const oldEnclosingDecl = context.enclosingDeclaration;
|
|
53435
53131
|
context.enclosingDeclaration = jsdocAliasDecl;
|
|
53436
|
-
const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) &&
|
|
53437
|
-
context,
|
|
53438
|
-
jsdocAliasDecl.typeExpression.type,
|
|
53439
|
-
aliasType,
|
|
53440
|
-
/*host*/
|
|
53441
|
-
void 0
|
|
53442
|
-
) || typeToTypeNodeHelper(aliasType, context);
|
|
53132
|
+
const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) && syntacticNodeBuilder.tryReuseExistingTypeNode(context, jsdocAliasDecl.typeExpression.type) || typeToTypeNodeHelper(aliasType, context);
|
|
53443
53133
|
addResult(
|
|
53444
53134
|
setSyntheticLeadingComments(
|
|
53445
53135
|
factory.createTypeAliasDeclaration(
|
|
@@ -53672,7 +53362,7 @@ function createTypeChecker(host) {
|
|
|
53672
53362
|
}
|
|
53673
53363
|
return cleanup(factory.createExpressionWithTypeArguments(
|
|
53674
53364
|
expr,
|
|
53675
|
-
map(e.typeArguments, (a) =>
|
|
53365
|
+
map(e.typeArguments, (a) => syntacticNodeBuilder.tryReuseExistingTypeNode(context, a) || typeToTypeNodeHelper(getTypeFromTypeNode2(context, a), context))
|
|
53676
53366
|
));
|
|
53677
53367
|
function cleanup(result2) {
|
|
53678
53368
|
context.enclosingDeclaration = oldEnclosing;
|
|
@@ -54159,7 +53849,7 @@ function createTypeChecker(host) {
|
|
|
54159
53849
|
}
|
|
54160
53850
|
function makeSerializePropertySymbol(createProperty2, methodKind, useAccessors) {
|
|
54161
53851
|
return function serializePropertySymbol(p, isStatic2, baseType) {
|
|
54162
|
-
var _a2, _b, _c, _d, _e;
|
|
53852
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
54163
53853
|
const modifierFlags = getDeclarationModifierFlagsFromSymbol(p);
|
|
54164
53854
|
const isPrivate = !!(modifierFlags & 2 /* Private */);
|
|
54165
53855
|
if (isStatic2 && p.flags & (788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */)) {
|
|
@@ -54189,6 +53879,7 @@ function createTypeChecker(host) {
|
|
|
54189
53879
|
});
|
|
54190
53880
|
Debug.assert(!!setter);
|
|
54191
53881
|
const paramSymbol = isFunctionLikeDeclaration(setter) ? getSignatureFromDeclaration(setter).parameters[0] : void 0;
|
|
53882
|
+
const setterDeclaration = (_b = p.declarations) == null ? void 0 : _b.find(isSetAccessor);
|
|
54192
53883
|
result.push(setTextRange2(
|
|
54193
53884
|
context,
|
|
54194
53885
|
factory.createSetAccessorDeclaration(
|
|
@@ -54202,39 +53893,28 @@ function createTypeChecker(host) {
|
|
|
54202
53893
|
paramSymbol ? parameterToParameterDeclarationName(paramSymbol, getEffectiveParameterDeclaration(paramSymbol), context) : "value",
|
|
54203
53894
|
/*questionToken*/
|
|
54204
53895
|
void 0,
|
|
54205
|
-
isPrivate ? void 0 : serializeTypeForDeclaration(
|
|
54206
|
-
context,
|
|
54207
|
-
/*declaration*/
|
|
54208
|
-
void 0,
|
|
54209
|
-
getWriteTypeOfSymbol(p),
|
|
54210
|
-
p
|
|
54211
|
-
)
|
|
53896
|
+
isPrivate ? void 0 : serializeTypeForDeclaration(context, setterDeclaration, getWriteTypeOfSymbol(p), p)
|
|
54212
53897
|
)],
|
|
54213
53898
|
/*body*/
|
|
54214
53899
|
void 0
|
|
54215
53900
|
),
|
|
54216
|
-
|
|
53901
|
+
setterDeclaration ?? firstPropertyLikeDecl
|
|
54217
53902
|
));
|
|
54218
53903
|
}
|
|
54219
53904
|
if (p.flags & 32768 /* GetAccessor */) {
|
|
54220
53905
|
const isPrivate2 = modifierFlags & 2 /* Private */;
|
|
53906
|
+
const getterDeclaration = (_c = p.declarations) == null ? void 0 : _c.find(isGetAccessor);
|
|
54221
53907
|
result.push(setTextRange2(
|
|
54222
53908
|
context,
|
|
54223
53909
|
factory.createGetAccessorDeclaration(
|
|
54224
53910
|
factory.createModifiersFromModifierFlags(flag),
|
|
54225
53911
|
name,
|
|
54226
53912
|
[],
|
|
54227
|
-
isPrivate2 ? void 0 : serializeTypeForDeclaration(
|
|
54228
|
-
context,
|
|
54229
|
-
/*declaration*/
|
|
54230
|
-
void 0,
|
|
54231
|
-
getTypeOfSymbol(p),
|
|
54232
|
-
p
|
|
54233
|
-
),
|
|
53913
|
+
isPrivate2 ? void 0 : serializeTypeForDeclaration(context, getterDeclaration, getTypeOfSymbol(p), p),
|
|
54234
53914
|
/*body*/
|
|
54235
53915
|
void 0
|
|
54236
53916
|
),
|
|
54237
|
-
|
|
53917
|
+
getterDeclaration ?? firstPropertyLikeDecl
|
|
54238
53918
|
));
|
|
54239
53919
|
}
|
|
54240
53920
|
return result;
|
|
@@ -54245,19 +53925,13 @@ function createTypeChecker(host) {
|
|
|
54245
53925
|
factory.createModifiersFromModifierFlags((isReadonlySymbol(p) ? 8 /* Readonly */ : 0) | flag),
|
|
54246
53926
|
name,
|
|
54247
53927
|
p.flags & 16777216 /* Optional */ ? factory.createToken(58 /* QuestionToken */) : void 0,
|
|
54248
|
-
isPrivate ? void 0 : serializeTypeForDeclaration(
|
|
54249
|
-
context,
|
|
54250
|
-
/*declaration*/
|
|
54251
|
-
void 0,
|
|
54252
|
-
getWriteTypeOfSymbol(p),
|
|
54253
|
-
p
|
|
54254
|
-
),
|
|
53928
|
+
isPrivate ? void 0 : serializeTypeForDeclaration(context, (_d = p.declarations) == null ? void 0 : _d.find(isSetAccessorDeclaration), getWriteTypeOfSymbol(p), p),
|
|
54255
53929
|
// TODO: https://github.com/microsoft/TypeScript/pull/32372#discussion_r328386357
|
|
54256
53930
|
// interface members can't have initializers, however class members _can_
|
|
54257
53931
|
/*initializer*/
|
|
54258
53932
|
void 0
|
|
54259
53933
|
),
|
|
54260
|
-
((
|
|
53934
|
+
((_e = p.declarations) == null ? void 0 : _e.find(or(isPropertyDeclaration, isVariableDeclaration))) || firstPropertyLikeDecl
|
|
54261
53935
|
);
|
|
54262
53936
|
}
|
|
54263
53937
|
if (p.flags & (8192 /* Method */ | 16 /* Function */)) {
|
|
@@ -54275,7 +53949,7 @@ function createTypeChecker(host) {
|
|
|
54275
53949
|
/*initializer*/
|
|
54276
53950
|
void 0
|
|
54277
53951
|
),
|
|
54278
|
-
((
|
|
53952
|
+
((_f = p.declarations) == null ? void 0 : _f.find(isFunctionLikeDeclaration)) || signatures[0] && signatures[0].declaration || p.declarations && p.declarations[0]
|
|
54279
53953
|
);
|
|
54280
53954
|
}
|
|
54281
53955
|
const results2 = [];
|
|
@@ -54318,7 +53992,7 @@ function createTypeChecker(host) {
|
|
|
54318
53992
|
return [];
|
|
54319
53993
|
}
|
|
54320
53994
|
if (baseSigs.length === signatures.length) {
|
|
54321
|
-
let
|
|
53995
|
+
let failed2 = false;
|
|
54322
53996
|
for (let i = 0; i < baseSigs.length; i++) {
|
|
54323
53997
|
if (!compareSignaturesIdentical(
|
|
54324
53998
|
signatures[i],
|
|
@@ -54331,11 +54005,11 @@ function createTypeChecker(host) {
|
|
|
54331
54005
|
true,
|
|
54332
54006
|
compareTypesIdentical
|
|
54333
54007
|
)) {
|
|
54334
|
-
|
|
54008
|
+
failed2 = true;
|
|
54335
54009
|
break;
|
|
54336
54010
|
}
|
|
54337
54011
|
}
|
|
54338
|
-
if (!
|
|
54012
|
+
if (!failed2) {
|
|
54339
54013
|
return [];
|
|
54340
54014
|
}
|
|
54341
54015
|
}
|
|
@@ -55508,7 +55182,7 @@ function createTypeChecker(host) {
|
|
|
55508
55182
|
/*reportErrors*/
|
|
55509
55183
|
false
|
|
55510
55184
|
) : unknownType;
|
|
55511
|
-
return addOptionality(
|
|
55185
|
+
return addOptionality(getWidenedLiteralTypeForInitializer(element, checkDeclarationInitializer(element, 0 /* Normal */, contextualType)));
|
|
55512
55186
|
}
|
|
55513
55187
|
if (isBindingPattern(element.name)) {
|
|
55514
55188
|
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors2);
|
|
@@ -75647,12 +75321,12 @@ function createTypeChecker(host) {
|
|
|
75647
75321
|
}
|
|
75648
75322
|
}
|
|
75649
75323
|
return result;
|
|
75650
|
-
function addImplementationSuccessElaboration(
|
|
75324
|
+
function addImplementationSuccessElaboration(failed2, diagnostic) {
|
|
75651
75325
|
var _a, _b;
|
|
75652
75326
|
const oldCandidatesForArgumentError = candidatesForArgumentError;
|
|
75653
75327
|
const oldCandidateForArgumentArityError = candidateForArgumentArityError;
|
|
75654
75328
|
const oldCandidateForTypeArgumentError = candidateForTypeArgumentError;
|
|
75655
|
-
const failedSignatureDeclarations = ((_b = (_a =
|
|
75329
|
+
const failedSignatureDeclarations = ((_b = (_a = failed2.declaration) == null ? void 0 : _a.symbol) == null ? void 0 : _b.declarations) || emptyArray;
|
|
75656
75330
|
const isOverload = failedSignatureDeclarations.length > 1;
|
|
75657
75331
|
const implDecl = isOverload ? find(failedSignatureDeclarations, (d) => isFunctionLikeDeclaration(d) && nodeIsPresent(d.body)) : void 0;
|
|
75658
75332
|
if (implDecl) {
|
|
@@ -79571,7 +79245,7 @@ function createTypeChecker(host) {
|
|
|
79571
79245
|
return createTupleType(elementTypes, elementFlags, type.target.readonly);
|
|
79572
79246
|
}
|
|
79573
79247
|
function widenTypeInferredFromInitializer(declaration, type) {
|
|
79574
|
-
const widened =
|
|
79248
|
+
const widened = getWidenedLiteralTypeForInitializer(declaration, type);
|
|
79575
79249
|
if (isInJSFile(declaration)) {
|
|
79576
79250
|
if (isEmptyLiteralType(widened)) {
|
|
79577
79251
|
reportImplicitAny(declaration, anyType);
|
|
@@ -79583,6 +79257,9 @@ function createTypeChecker(host) {
|
|
|
79583
79257
|
}
|
|
79584
79258
|
return widened;
|
|
79585
79259
|
}
|
|
79260
|
+
function getWidenedLiteralTypeForInitializer(declaration, type) {
|
|
79261
|
+
return getCombinedNodeFlagsCached(declaration) & 6 /* Constant */ || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
|
|
79262
|
+
}
|
|
79586
79263
|
function isLiteralOfContextualType(candidateType, contextualType) {
|
|
79587
79264
|
if (contextualType) {
|
|
79588
79265
|
if (contextualType.flags & 3145728 /* UnionOrIntersection */) {
|
|
@@ -86971,16 +86648,12 @@ function createTypeChecker(host) {
|
|
|
86971
86648
|
}
|
|
86972
86649
|
}
|
|
86973
86650
|
function createTypeOfDeclaration(declarationIn, enclosingDeclaration, flags, internalFlags, tracker) {
|
|
86974
|
-
const declaration = getParseTreeNode(declarationIn,
|
|
86651
|
+
const declaration = getParseTreeNode(declarationIn, hasInferredType);
|
|
86975
86652
|
if (!declaration) {
|
|
86976
86653
|
return factory.createToken(133 /* AnyKeyword */);
|
|
86977
86654
|
}
|
|
86978
86655
|
const symbol = getSymbolOfDeclaration(declaration);
|
|
86979
|
-
|
|
86980
|
-
return nodeBuilder.serializeTypeForDeclaration(declaration, type, symbol, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
|
|
86981
|
-
}
|
|
86982
|
-
function isDeclarationWithPossibleInnerTypeNodeReuse(declaration) {
|
|
86983
|
-
return isFunctionLike(declaration) || isExportAssignment(declaration) || isVariableLike(declaration);
|
|
86656
|
+
return nodeBuilder.serializeTypeForDeclaration(declaration, symbol, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
|
|
86984
86657
|
}
|
|
86985
86658
|
function getAllAccessorDeclarationsForDeclaration(accessor) {
|
|
86986
86659
|
accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration);
|
|
@@ -86997,52 +86670,19 @@ function createTypeChecker(host) {
|
|
|
86997
86670
|
getAccessor
|
|
86998
86671
|
};
|
|
86999
86672
|
}
|
|
87000
|
-
function getPossibleTypeNodeReuseExpression(declaration) {
|
|
87001
|
-
return isFunctionLike(declaration) && !isSetAccessor(declaration) ? getSingleReturnExpression(declaration) : isExportAssignment(declaration) ? declaration.expression : !!declaration.initializer ? declaration.initializer : isParameter(declaration) && isSetAccessor(declaration.parent) ? getSingleReturnExpression(getAllAccessorDeclarationsForDeclaration(declaration.parent).getAccessor) : void 0;
|
|
87002
|
-
}
|
|
87003
|
-
function getSingleReturnExpression(declaration) {
|
|
87004
|
-
let candidateExpr;
|
|
87005
|
-
if (declaration && !nodeIsMissing(declaration.body)) {
|
|
87006
|
-
if (getFunctionFlags(declaration) & 3 /* AsyncGenerator */) return void 0;
|
|
87007
|
-
const body = declaration.body;
|
|
87008
|
-
if (body && isBlock(body)) {
|
|
87009
|
-
forEachReturnStatement(body, (s) => {
|
|
87010
|
-
if (!candidateExpr) {
|
|
87011
|
-
candidateExpr = s.expression;
|
|
87012
|
-
} else {
|
|
87013
|
-
candidateExpr = void 0;
|
|
87014
|
-
return true;
|
|
87015
|
-
}
|
|
87016
|
-
});
|
|
87017
|
-
} else {
|
|
87018
|
-
candidateExpr = body;
|
|
87019
|
-
}
|
|
87020
|
-
}
|
|
87021
|
-
return candidateExpr;
|
|
87022
|
-
}
|
|
87023
86673
|
function createReturnTypeOfSignatureDeclaration(signatureDeclarationIn, enclosingDeclaration, flags, internalFlags, tracker) {
|
|
87024
86674
|
const signatureDeclaration = getParseTreeNode(signatureDeclarationIn, isFunctionLike);
|
|
87025
86675
|
if (!signatureDeclaration) {
|
|
87026
86676
|
return factory.createToken(133 /* AnyKeyword */);
|
|
87027
86677
|
}
|
|
87028
|
-
return nodeBuilder.serializeReturnTypeForSignature(
|
|
86678
|
+
return nodeBuilder.serializeReturnTypeForSignature(signatureDeclaration, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
|
|
87029
86679
|
}
|
|
87030
86680
|
function createTypeOfExpression(exprIn, enclosingDeclaration, flags, internalFlags, tracker) {
|
|
87031
86681
|
const expr = getParseTreeNode(exprIn, isExpression);
|
|
87032
86682
|
if (!expr) {
|
|
87033
86683
|
return factory.createToken(133 /* AnyKeyword */);
|
|
87034
86684
|
}
|
|
87035
|
-
|
|
87036
|
-
return nodeBuilder.expressionOrTypeToTypeNode(
|
|
87037
|
-
expr,
|
|
87038
|
-
type,
|
|
87039
|
-
/*addUndefined*/
|
|
87040
|
-
void 0,
|
|
87041
|
-
enclosingDeclaration,
|
|
87042
|
-
flags | 1024 /* MultilineObjectLiterals */,
|
|
87043
|
-
internalFlags,
|
|
87044
|
-
tracker
|
|
87045
|
-
);
|
|
86685
|
+
return nodeBuilder.serializeTypeForExpression(expr, enclosingDeclaration, flags | 1024 /* MultilineObjectLiterals */, internalFlags, tracker);
|
|
87046
86686
|
}
|
|
87047
86687
|
function hasGlobalName(name) {
|
|
87048
86688
|
return globals.has(escapeLeadingUnderscores(name));
|
|
@@ -87193,22 +86833,6 @@ function createTypeChecker(host) {
|
|
|
87193
86833
|
}
|
|
87194
86834
|
return void 0;
|
|
87195
86835
|
}
|
|
87196
|
-
function getNonlocalEffectiveReturnTypeAnnotationNode(node) {
|
|
87197
|
-
const direct = getEffectiveReturnTypeNode(node);
|
|
87198
|
-
if (direct) {
|
|
87199
|
-
return direct;
|
|
87200
|
-
}
|
|
87201
|
-
if (node.kind === 177 /* GetAccessor */) {
|
|
87202
|
-
const other = getAllAccessorDeclarationsForDeclaration(node).setAccessor;
|
|
87203
|
-
if (other) {
|
|
87204
|
-
const param = getSetAccessorValueParameter(other);
|
|
87205
|
-
if (param) {
|
|
87206
|
-
return getEffectiveTypeAnnotationNode(param);
|
|
87207
|
-
}
|
|
87208
|
-
}
|
|
87209
|
-
}
|
|
87210
|
-
return void 0;
|
|
87211
|
-
}
|
|
87212
86836
|
function createResolver() {
|
|
87213
86837
|
return {
|
|
87214
86838
|
getReferencedExportContainer,
|
|
@@ -89305,7 +88929,8 @@ var SymbolTrackerImpl = class _SymbolTrackerImpl {
|
|
|
89305
88929
|
}
|
|
89306
88930
|
reportInferenceFallback(node) {
|
|
89307
88931
|
var _a;
|
|
89308
|
-
if ((_a = this.inner) == null ? void 0 : _a.reportInferenceFallback) {
|
|
88932
|
+
if (((_a = this.inner) == null ? void 0 : _a.reportInferenceFallback) && !this.context.suppressReportInferenceFallback) {
|
|
88933
|
+
this.onDiagnosticReported();
|
|
89309
88934
|
this.inner.reportInferenceFallback(node);
|
|
89310
88935
|
}
|
|
89311
88936
|
}
|
|
@@ -112375,8 +112000,8 @@ function createGetIsolatedDeclarationErrors(resolver) {
|
|
|
112375
112000
|
[219 /* ArrowFunction */]: Diagnostics.Function_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
|
112376
112001
|
[174 /* MethodDeclaration */]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
|
112377
112002
|
[180 /* ConstructSignature */]: Diagnostics.Method_must_have_an_explicit_return_type_annotation_with_isolatedDeclarations,
|
|
112378
|
-
[177 /* GetAccessor */]: Diagnostics.
|
|
112379
|
-
[178 /* SetAccessor */]: Diagnostics.
|
|
112003
|
+
[177 /* GetAccessor */]: Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
|
112004
|
+
[178 /* SetAccessor */]: Diagnostics.At_least_one_accessor_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
|
112380
112005
|
[169 /* Parameter */]: Diagnostics.Parameter_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
|
112381
112006
|
[260 /* VariableDeclaration */]: Diagnostics.Variable_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
|
112382
112007
|
[172 /* PropertyDeclaration */]: Diagnostics.Property_must_have_an_explicit_type_annotation_with_isolatedDeclarations,
|
|
@@ -112944,7 +112569,7 @@ function transformDeclarations(context) {
|
|
|
112944
112569
|
);
|
|
112945
112570
|
}
|
|
112946
112571
|
}
|
|
112947
|
-
function ensureParameter(p, modifierMask
|
|
112572
|
+
function ensureParameter(p, modifierMask) {
|
|
112948
112573
|
let oldDiag;
|
|
112949
112574
|
if (!suppressNewDiagnosticContexts) {
|
|
112950
112575
|
oldDiag = getSymbolAccessibilityDiagnostic;
|
|
@@ -112958,7 +112583,6 @@ function transformDeclarations(context) {
|
|
|
112958
112583
|
resolver.isOptionalParameter(p) ? p.questionToken || factory2.createToken(58 /* QuestionToken */) : void 0,
|
|
112959
112584
|
ensureType(
|
|
112960
112585
|
p,
|
|
112961
|
-
type || p.type,
|
|
112962
112586
|
/*ignorePrivate*/
|
|
112963
112587
|
true
|
|
112964
112588
|
),
|
|
@@ -112983,44 +112607,34 @@ function transformDeclarations(context) {
|
|
|
112983
112607
|
}
|
|
112984
112608
|
return void 0;
|
|
112985
112609
|
}
|
|
112986
|
-
function ensureType(node,
|
|
112610
|
+
function ensureType(node, ignorePrivate) {
|
|
112987
112611
|
if (!ignorePrivate && hasEffectiveModifier(node, 2 /* Private */)) {
|
|
112988
112612
|
return;
|
|
112989
112613
|
}
|
|
112990
112614
|
if (shouldPrintWithInitializer(node)) {
|
|
112991
112615
|
return;
|
|
112992
112616
|
}
|
|
112993
|
-
|
|
112994
|
-
|
|
112995
|
-
return visitNode(type, visitDeclarationSubtree, isTypeNode);
|
|
112617
|
+
if (!isExportAssignment(node) && !isBindingElement(node) && node.type && (!isParameter(node) || !resolver.requiresAddingImplicitUndefined(node, enclosingDeclaration))) {
|
|
112618
|
+
return visitNode(node.type, visitDeclarationSubtree, isTypeNode);
|
|
112996
112619
|
}
|
|
112620
|
+
const oldErrorNameNode = errorNameNode;
|
|
112997
112621
|
errorNameNode = node.name;
|
|
112998
112622
|
let oldDiag;
|
|
112999
112623
|
if (!suppressNewDiagnosticContexts) {
|
|
113000
112624
|
oldDiag = getSymbolAccessibilityDiagnostic;
|
|
113001
|
-
|
|
112625
|
+
if (canProduceDiagnostics(node)) {
|
|
112626
|
+
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node);
|
|
112627
|
+
}
|
|
113002
112628
|
}
|
|
113003
112629
|
let typeNode;
|
|
113004
|
-
|
|
113005
|
-
|
|
113006
|
-
|
|
113007
|
-
|
|
113008
|
-
|
|
113009
|
-
|
|
113010
|
-
typeNode = resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
|
113011
|
-
break;
|
|
113012
|
-
case 262 /* FunctionDeclaration */:
|
|
113013
|
-
case 180 /* ConstructSignature */:
|
|
113014
|
-
case 173 /* MethodSignature */:
|
|
113015
|
-
case 174 /* MethodDeclaration */:
|
|
113016
|
-
case 177 /* GetAccessor */:
|
|
113017
|
-
case 179 /* CallSignature */:
|
|
113018
|
-
typeNode = resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
|
113019
|
-
break;
|
|
113020
|
-
default:
|
|
113021
|
-
Debug.assertNever(node);
|
|
112630
|
+
if (hasInferredType(node)) {
|
|
112631
|
+
typeNode = resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
|
112632
|
+
} else if (isFunctionLike(node)) {
|
|
112633
|
+
typeNode = resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, declarationEmitInternalNodeBuilderFlags, symbolTracker);
|
|
112634
|
+
} else {
|
|
112635
|
+
Debug.assertNever(node);
|
|
113022
112636
|
}
|
|
113023
|
-
errorNameNode =
|
|
112637
|
+
errorNameNode = oldErrorNameNode;
|
|
113024
112638
|
if (!suppressNewDiagnosticContexts) {
|
|
113025
112639
|
getSymbolAccessibilityDiagnostic = oldDiag;
|
|
113026
112640
|
}
|
|
@@ -113090,13 +112704,7 @@ function transformDeclarations(context) {
|
|
|
113090
112704
|
if (!isPrivate) {
|
|
113091
112705
|
const valueParameter = getSetAccessorValueParameter(input);
|
|
113092
112706
|
if (valueParameter) {
|
|
113093
|
-
|
|
113094
|
-
newValueParameter = ensureParameter(
|
|
113095
|
-
valueParameter,
|
|
113096
|
-
/*modifierMask*/
|
|
113097
|
-
void 0,
|
|
113098
|
-
accessorType
|
|
113099
|
-
);
|
|
112707
|
+
newValueParameter = ensureParameter(valueParameter);
|
|
113100
112708
|
}
|
|
113101
112709
|
}
|
|
113102
112710
|
if (!newValueParameter) {
|
|
@@ -113347,7 +112955,7 @@ function transformDeclarations(context) {
|
|
|
113347
112955
|
input,
|
|
113348
112956
|
ensureTypeParams(input, input.typeParameters),
|
|
113349
112957
|
updateParamsList(input, input.parameters),
|
|
113350
|
-
ensureType(input
|
|
112958
|
+
ensureType(input)
|
|
113351
112959
|
));
|
|
113352
112960
|
case 176 /* Constructor */: {
|
|
113353
112961
|
const ctor = factory2.createConstructorDeclaration(
|
|
@@ -113374,7 +112982,7 @@ function transformDeclarations(context) {
|
|
|
113374
112982
|
input.questionToken,
|
|
113375
112983
|
ensureTypeParams(input, input.typeParameters),
|
|
113376
112984
|
updateParamsList(input, input.parameters),
|
|
113377
|
-
ensureType(input
|
|
112985
|
+
ensureType(input),
|
|
113378
112986
|
/*body*/
|
|
113379
112987
|
void 0
|
|
113380
112988
|
);
|
|
@@ -113387,13 +112995,12 @@ function transformDeclarations(context) {
|
|
|
113387
112995
|
void 0
|
|
113388
112996
|
);
|
|
113389
112997
|
}
|
|
113390
|
-
const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, getAllAccessorDeclarations(isObjectLiteralExpression(input.parent) ? input.parent.properties : input.parent.members, input));
|
|
113391
112998
|
return cleanup(factory2.updateGetAccessorDeclaration(
|
|
113392
112999
|
input,
|
|
113393
113000
|
ensureModifiers(input),
|
|
113394
113001
|
input.name,
|
|
113395
113002
|
updateAccessorParamsList(input, hasEffectiveModifier(input, 2 /* Private */)),
|
|
113396
|
-
ensureType(input
|
|
113003
|
+
ensureType(input),
|
|
113397
113004
|
/*body*/
|
|
113398
113005
|
void 0
|
|
113399
113006
|
));
|
|
@@ -113426,7 +113033,7 @@ function transformDeclarations(context) {
|
|
|
113426
113033
|
ensureModifiers(input),
|
|
113427
113034
|
input.name,
|
|
113428
113035
|
input.questionToken,
|
|
113429
|
-
ensureType(input
|
|
113036
|
+
ensureType(input),
|
|
113430
113037
|
ensureNoInitializer(input)
|
|
113431
113038
|
));
|
|
113432
113039
|
case 171 /* PropertySignature */:
|
|
@@ -113441,7 +113048,7 @@ function transformDeclarations(context) {
|
|
|
113441
113048
|
ensureModifiers(input),
|
|
113442
113049
|
input.name,
|
|
113443
113050
|
input.questionToken,
|
|
113444
|
-
ensureType(input
|
|
113051
|
+
ensureType(input)
|
|
113445
113052
|
));
|
|
113446
113053
|
case 173 /* MethodSignature */: {
|
|
113447
113054
|
if (isPrivateIdentifier(input.name)) {
|
|
@@ -113457,7 +113064,7 @@ function transformDeclarations(context) {
|
|
|
113457
113064
|
input.questionToken,
|
|
113458
113065
|
ensureTypeParams(input, input.typeParameters),
|
|
113459
113066
|
updateParamsList(input, input.parameters),
|
|
113460
|
-
ensureType(input
|
|
113067
|
+
ensureType(input)
|
|
113461
113068
|
));
|
|
113462
113069
|
}
|
|
113463
113070
|
case 179 /* CallSignature */: {
|
|
@@ -113466,7 +113073,7 @@ function transformDeclarations(context) {
|
|
|
113466
113073
|
input,
|
|
113467
113074
|
ensureTypeParams(input, input.typeParameters),
|
|
113468
113075
|
updateParamsList(input, input.parameters),
|
|
113469
|
-
ensureType(input
|
|
113076
|
+
ensureType(input)
|
|
113470
113077
|
)
|
|
113471
113078
|
);
|
|
113472
113079
|
}
|
|
@@ -113489,7 +113096,7 @@ function transformDeclarations(context) {
|
|
|
113489
113096
|
input.name,
|
|
113490
113097
|
/*exclamationToken*/
|
|
113491
113098
|
void 0,
|
|
113492
|
-
ensureType(input
|
|
113099
|
+
ensureType(input),
|
|
113493
113100
|
ensureNoInitializer(input)
|
|
113494
113101
|
));
|
|
113495
113102
|
}
|
|
@@ -113613,11 +113220,12 @@ function transformDeclarations(context) {
|
|
|
113613
113220
|
errorNode: input
|
|
113614
113221
|
});
|
|
113615
113222
|
errorFallbackNode = input;
|
|
113223
|
+
const type = ensureType(input);
|
|
113616
113224
|
const varDecl = factory2.createVariableDeclaration(
|
|
113617
113225
|
newId,
|
|
113618
113226
|
/*exclamationToken*/
|
|
113619
113227
|
void 0,
|
|
113620
|
-
|
|
113228
|
+
type,
|
|
113621
113229
|
/*initializer*/
|
|
113622
113230
|
void 0
|
|
113623
113231
|
);
|
|
@@ -113714,7 +113322,7 @@ function transformDeclarations(context) {
|
|
|
113714
113322
|
input.name,
|
|
113715
113323
|
ensureTypeParams(input, input.typeParameters),
|
|
113716
113324
|
updateParamsList(input, input.parameters),
|
|
113717
|
-
ensureType(input
|
|
113325
|
+
ensureType(input),
|
|
113718
113326
|
/*body*/
|
|
113719
113327
|
void 0
|
|
113720
113328
|
));
|
|
@@ -113882,7 +113490,7 @@ function transformDeclarations(context) {
|
|
|
113882
113490
|
ensureModifiers(param),
|
|
113883
113491
|
param.name,
|
|
113884
113492
|
param.questionToken,
|
|
113885
|
-
ensureType(param
|
|
113493
|
+
ensureType(param),
|
|
113886
113494
|
ensureNoInitializer(param)
|
|
113887
113495
|
),
|
|
113888
113496
|
param
|
|
@@ -113903,11 +113511,7 @@ function transformDeclarations(context) {
|
|
|
113903
113511
|
elem.name,
|
|
113904
113512
|
/*questionOrExclamationToken*/
|
|
113905
113513
|
void 0,
|
|
113906
|
-
ensureType(
|
|
113907
|
-
elem,
|
|
113908
|
-
/*type*/
|
|
113909
|
-
void 0
|
|
113910
|
-
),
|
|
113514
|
+
ensureType(elem),
|
|
113911
113515
|
/*initializer*/
|
|
113912
113516
|
void 0
|
|
113913
113517
|
));
|
|
@@ -114058,11 +113662,7 @@ function transformDeclarations(context) {
|
|
|
114058
113662
|
e.name,
|
|
114059
113663
|
/*exclamationToken*/
|
|
114060
113664
|
void 0,
|
|
114061
|
-
ensureType(
|
|
114062
|
-
e,
|
|
114063
|
-
/*type*/
|
|
114064
|
-
void 0
|
|
114065
|
-
),
|
|
113665
|
+
ensureType(e),
|
|
114066
113666
|
/*initializer*/
|
|
114067
113667
|
void 0
|
|
114068
113668
|
);
|
|
@@ -114112,18 +113712,6 @@ function transformDeclarations(context) {
|
|
|
114112
113712
|
}
|
|
114113
113713
|
return maskModifierFlags(node, mask, additions);
|
|
114114
113714
|
}
|
|
114115
|
-
function getTypeAnnotationFromAllAccessorDeclarations(node, accessors) {
|
|
114116
|
-
let accessorType = getTypeAnnotationFromAccessor(node);
|
|
114117
|
-
if (!accessorType && node !== accessors.firstAccessor) {
|
|
114118
|
-
accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor);
|
|
114119
|
-
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.firstAccessor);
|
|
114120
|
-
}
|
|
114121
|
-
if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) {
|
|
114122
|
-
accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor);
|
|
114123
|
-
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.secondAccessor);
|
|
114124
|
-
}
|
|
114125
|
-
return accessorType;
|
|
114126
|
-
}
|
|
114127
113715
|
function transformHeritageClauses(nodes) {
|
|
114128
113716
|
return factory2.createNodeArray(filter(
|
|
114129
113717
|
map(nodes, (clause) => factory2.updateHeritageClause(
|
|
@@ -114159,11 +113747,6 @@ function maskModifierFlags(node, modifierMask = 131071 /* All */ ^ 1 /* Public *
|
|
|
114159
113747
|
}
|
|
114160
113748
|
return flags;
|
|
114161
113749
|
}
|
|
114162
|
-
function getTypeAnnotationFromAccessor(accessor) {
|
|
114163
|
-
if (accessor) {
|
|
114164
|
-
return accessor.kind === 177 /* GetAccessor */ ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : void 0;
|
|
114165
|
-
}
|
|
114166
|
-
}
|
|
114167
113750
|
function canHaveLiteralInitializer(node) {
|
|
114168
113751
|
switch (node.kind) {
|
|
114169
113752
|
case 172 /* PropertyDeclaration */:
|
|
@@ -120174,7 +119757,7 @@ function resolveTripleslashReference(moduleName, containingFile) {
|
|
|
120174
119757
|
}
|
|
120175
119758
|
function computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, getCanonicalFileName) {
|
|
120176
119759
|
let commonPathComponents;
|
|
120177
|
-
const
|
|
119760
|
+
const failed2 = forEach(fileNames, (sourceFile) => {
|
|
120178
119761
|
const sourcePathComponents = getNormalizedPathComponents(sourceFile, currentDirectory);
|
|
120179
119762
|
sourcePathComponents.pop();
|
|
120180
119763
|
if (!commonPathComponents) {
|
|
@@ -120195,7 +119778,7 @@ function computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, ge
|
|
|
120195
119778
|
commonPathComponents.length = sourcePathComponents.length;
|
|
120196
119779
|
}
|
|
120197
119780
|
});
|
|
120198
|
-
if (
|
|
119781
|
+
if (failed2) {
|
|
120199
119782
|
return "";
|
|
120200
119783
|
}
|
|
120201
119784
|
if (!commonPathComponents) {
|
|
@@ -131427,39 +131010,518 @@ function writeConfigFile(sys2, reportDiagnostic, options, fileNames) {
|
|
|
131427
131010
|
}
|
|
131428
131011
|
|
|
131429
131012
|
// src/compiler/expressionToTypeNode.ts
|
|
131013
|
+
function syntacticResult(type, reportFallback = true) {
|
|
131014
|
+
return { type, reportFallback };
|
|
131015
|
+
}
|
|
131016
|
+
var notImplemented2 = syntacticResult(
|
|
131017
|
+
/*type*/
|
|
131018
|
+
void 0,
|
|
131019
|
+
/*reportFallback*/
|
|
131020
|
+
false
|
|
131021
|
+
);
|
|
131022
|
+
var alreadyReported = syntacticResult(
|
|
131023
|
+
/*type*/
|
|
131024
|
+
void 0,
|
|
131025
|
+
/*reportFallback*/
|
|
131026
|
+
false
|
|
131027
|
+
);
|
|
131028
|
+
var failed = syntacticResult(
|
|
131029
|
+
/*type*/
|
|
131030
|
+
void 0,
|
|
131031
|
+
/*reportFallback*/
|
|
131032
|
+
true
|
|
131033
|
+
);
|
|
131430
131034
|
function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
131431
131035
|
const strictNullChecks = getStrictOptionValue(options, "strictNullChecks");
|
|
131432
131036
|
return {
|
|
131433
|
-
typeFromExpression,
|
|
131434
131037
|
serializeTypeOfDeclaration,
|
|
131435
131038
|
serializeReturnTypeForSignature,
|
|
131436
|
-
serializeTypeOfExpression
|
|
131039
|
+
serializeTypeOfExpression,
|
|
131040
|
+
serializeTypeOfAccessor,
|
|
131041
|
+
tryReuseExistingTypeNode(context, existing) {
|
|
131042
|
+
if (!resolver.canReuseTypeNode(context, existing)) {
|
|
131043
|
+
return void 0;
|
|
131044
|
+
}
|
|
131045
|
+
return tryReuseExistingTypeNode(context, existing);
|
|
131046
|
+
}
|
|
131437
131047
|
};
|
|
131438
|
-
function
|
|
131439
|
-
return
|
|
131048
|
+
function reuseNode(context, node, range = node) {
|
|
131049
|
+
return node === void 0 ? void 0 : resolver.markNodeReuse(context, node.flags & 16 /* Synthesized */ ? node : factory.cloneNode(node), range ?? node);
|
|
131050
|
+
}
|
|
131051
|
+
function tryReuseExistingTypeNode(context, existing) {
|
|
131052
|
+
const { finalizeBoundary, startRecoveryScope, hadError, markError } = resolver.createRecoveryBoundary(context);
|
|
131053
|
+
const transformed = visitNode(existing, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131054
|
+
if (!finalizeBoundary()) {
|
|
131055
|
+
return void 0;
|
|
131056
|
+
}
|
|
131057
|
+
context.approximateLength += existing.end - existing.pos;
|
|
131058
|
+
return transformed;
|
|
131059
|
+
function visitExistingNodeTreeSymbols(node) {
|
|
131060
|
+
if (hadError()) return node;
|
|
131061
|
+
const recover = startRecoveryScope();
|
|
131062
|
+
const onExitNewScope = isNewScopeNode(node) ? resolver.enterNewScope(context, node) : void 0;
|
|
131063
|
+
const result = visitExistingNodeTreeSymbolsWorker(node);
|
|
131064
|
+
onExitNewScope == null ? void 0 : onExitNewScope();
|
|
131065
|
+
if (hadError()) {
|
|
131066
|
+
if (isTypeNode(node) && !isTypePredicateNode(node)) {
|
|
131067
|
+
recover();
|
|
131068
|
+
return resolver.serializeExistingTypeNode(context, node);
|
|
131069
|
+
}
|
|
131070
|
+
return node;
|
|
131071
|
+
}
|
|
131072
|
+
return result ? resolver.markNodeReuse(context, result, node) : void 0;
|
|
131073
|
+
}
|
|
131074
|
+
function tryVisitSimpleTypeNode(node) {
|
|
131075
|
+
const innerNode = skipTypeParentheses(node);
|
|
131076
|
+
switch (innerNode.kind) {
|
|
131077
|
+
case 183 /* TypeReference */:
|
|
131078
|
+
return tryVisitTypeReference(innerNode);
|
|
131079
|
+
case 186 /* TypeQuery */:
|
|
131080
|
+
return tryVisitTypeQuery(innerNode);
|
|
131081
|
+
case 199 /* IndexedAccessType */:
|
|
131082
|
+
return tryVisitIndexedAccess(innerNode);
|
|
131083
|
+
case 198 /* TypeOperator */:
|
|
131084
|
+
const typeOperatorNode = innerNode;
|
|
131085
|
+
if (typeOperatorNode.operator === 143 /* KeyOfKeyword */) {
|
|
131086
|
+
return tryVisitKeyOf(typeOperatorNode);
|
|
131087
|
+
}
|
|
131088
|
+
}
|
|
131089
|
+
return visitNode(node, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131090
|
+
}
|
|
131091
|
+
function tryVisitIndexedAccess(node) {
|
|
131092
|
+
const resultObjectType = tryVisitSimpleTypeNode(node.objectType);
|
|
131093
|
+
if (resultObjectType === void 0) {
|
|
131094
|
+
return void 0;
|
|
131095
|
+
}
|
|
131096
|
+
return factory.updateIndexedAccessTypeNode(node, resultObjectType, visitNode(node.indexType, visitExistingNodeTreeSymbols, isTypeNode));
|
|
131097
|
+
}
|
|
131098
|
+
function tryVisitKeyOf(node) {
|
|
131099
|
+
Debug.assertEqual(node.operator, 143 /* KeyOfKeyword */);
|
|
131100
|
+
const type = tryVisitSimpleTypeNode(node.type);
|
|
131101
|
+
if (type === void 0) {
|
|
131102
|
+
return void 0;
|
|
131103
|
+
}
|
|
131104
|
+
return factory.updateTypeOperatorNode(node, type);
|
|
131105
|
+
}
|
|
131106
|
+
function tryVisitTypeQuery(node) {
|
|
131107
|
+
const { introducesError, node: exprName } = resolver.trackExistingEntityName(context, node.exprName);
|
|
131108
|
+
if (!introducesError) {
|
|
131109
|
+
return factory.updateTypeQueryNode(
|
|
131110
|
+
node,
|
|
131111
|
+
exprName,
|
|
131112
|
+
visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode)
|
|
131113
|
+
);
|
|
131114
|
+
}
|
|
131115
|
+
const serializedName = resolver.serializeTypeName(
|
|
131116
|
+
context,
|
|
131117
|
+
node.exprName,
|
|
131118
|
+
/*isTypeOf*/
|
|
131119
|
+
true
|
|
131120
|
+
);
|
|
131121
|
+
if (serializedName) {
|
|
131122
|
+
return resolver.markNodeReuse(context, serializedName, node.exprName);
|
|
131123
|
+
}
|
|
131124
|
+
}
|
|
131125
|
+
function tryVisitTypeReference(node) {
|
|
131126
|
+
if (resolver.canReuseTypeNode(context, node)) {
|
|
131127
|
+
const { introducesError, node: newName } = resolver.trackExistingEntityName(context, node.typeName);
|
|
131128
|
+
const typeArguments = visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131129
|
+
if (!introducesError) {
|
|
131130
|
+
const updated = factory.updateTypeReferenceNode(
|
|
131131
|
+
node,
|
|
131132
|
+
newName,
|
|
131133
|
+
typeArguments
|
|
131134
|
+
);
|
|
131135
|
+
return resolver.markNodeReuse(context, updated, node);
|
|
131136
|
+
} else {
|
|
131137
|
+
const serializedName = resolver.serializeTypeName(
|
|
131138
|
+
context,
|
|
131139
|
+
node.typeName,
|
|
131140
|
+
/*isTypeOf*/
|
|
131141
|
+
false,
|
|
131142
|
+
typeArguments
|
|
131143
|
+
);
|
|
131144
|
+
if (serializedName) {
|
|
131145
|
+
return resolver.markNodeReuse(context, serializedName, node.typeName);
|
|
131146
|
+
}
|
|
131147
|
+
}
|
|
131148
|
+
}
|
|
131149
|
+
}
|
|
131150
|
+
function visitExistingNodeTreeSymbolsWorker(node) {
|
|
131151
|
+
var _a;
|
|
131152
|
+
if (isJSDocTypeExpression(node)) {
|
|
131153
|
+
return visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131154
|
+
}
|
|
131155
|
+
if (isJSDocAllType(node) || node.kind === 319 /* JSDocNamepathType */) {
|
|
131156
|
+
return factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131157
|
+
}
|
|
131158
|
+
if (isJSDocUnknownType(node)) {
|
|
131159
|
+
return factory.createKeywordTypeNode(159 /* UnknownKeyword */);
|
|
131160
|
+
}
|
|
131161
|
+
if (isJSDocNullableType(node)) {
|
|
131162
|
+
return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createLiteralTypeNode(factory.createNull())]);
|
|
131163
|
+
}
|
|
131164
|
+
if (isJSDocOptionalType(node)) {
|
|
131165
|
+
return factory.createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode), factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
|
|
131166
|
+
}
|
|
131167
|
+
if (isJSDocNonNullableType(node)) {
|
|
131168
|
+
return visitNode(node.type, visitExistingNodeTreeSymbols);
|
|
131169
|
+
}
|
|
131170
|
+
if (isJSDocVariadicType(node)) {
|
|
131171
|
+
return factory.createArrayTypeNode(visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
|
|
131172
|
+
}
|
|
131173
|
+
if (isJSDocTypeLiteral(node)) {
|
|
131174
|
+
return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, (t) => {
|
|
131175
|
+
const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier);
|
|
131176
|
+
const overrideTypeNode = resolver.getJsDocPropertyOverride(context, node, t);
|
|
131177
|
+
return factory.createPropertySignature(
|
|
131178
|
+
/*modifiers*/
|
|
131179
|
+
void 0,
|
|
131180
|
+
name,
|
|
131181
|
+
t.isBracketed || t.typeExpression && isJSDocOptionalType(t.typeExpression.type) ? factory.createToken(58 /* QuestionToken */) : void 0,
|
|
131182
|
+
overrideTypeNode || t.typeExpression && visitNode(t.typeExpression.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
|
|
131183
|
+
);
|
|
131184
|
+
}));
|
|
131185
|
+
}
|
|
131186
|
+
if (isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.escapedText === "") {
|
|
131187
|
+
return setOriginalNode(factory.createKeywordTypeNode(133 /* AnyKeyword */), node);
|
|
131188
|
+
}
|
|
131189
|
+
if ((isExpressionWithTypeArguments(node) || isTypeReferenceNode(node)) && isJSDocIndexSignature(node)) {
|
|
131190
|
+
return factory.createTypeLiteralNode([factory.createIndexSignature(
|
|
131191
|
+
/*modifiers*/
|
|
131192
|
+
void 0,
|
|
131193
|
+
[factory.createParameterDeclaration(
|
|
131194
|
+
/*modifiers*/
|
|
131195
|
+
void 0,
|
|
131196
|
+
/*dotDotDotToken*/
|
|
131197
|
+
void 0,
|
|
131198
|
+
"x",
|
|
131199
|
+
/*questionToken*/
|
|
131200
|
+
void 0,
|
|
131201
|
+
visitNode(node.typeArguments[0], visitExistingNodeTreeSymbols, isTypeNode)
|
|
131202
|
+
)],
|
|
131203
|
+
visitNode(node.typeArguments[1], visitExistingNodeTreeSymbols, isTypeNode)
|
|
131204
|
+
)]);
|
|
131205
|
+
}
|
|
131206
|
+
if (isJSDocFunctionType(node)) {
|
|
131207
|
+
if (isJSDocConstructSignature(node)) {
|
|
131208
|
+
let newTypeNode;
|
|
131209
|
+
return factory.createConstructorTypeNode(
|
|
131210
|
+
/*modifiers*/
|
|
131211
|
+
void 0,
|
|
131212
|
+
visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
|
|
131213
|
+
mapDefined(node.parameters, (p, i) => p.name && isIdentifier(p.name) && p.name.escapedText === "new" ? (newTypeNode = p.type, void 0) : factory.createParameterDeclaration(
|
|
131214
|
+
/*modifiers*/
|
|
131215
|
+
void 0,
|
|
131216
|
+
getEffectiveDotDotDotForParameter(p),
|
|
131217
|
+
resolver.markNodeReuse(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
|
|
131218
|
+
factory.cloneNode(p.questionToken),
|
|
131219
|
+
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
|
|
131220
|
+
/*initializer*/
|
|
131221
|
+
void 0
|
|
131222
|
+
)),
|
|
131223
|
+
visitNode(newTypeNode || node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
|
|
131224
|
+
);
|
|
131225
|
+
} else {
|
|
131226
|
+
return factory.createFunctionTypeNode(
|
|
131227
|
+
visitNodes2(node.typeParameters, visitExistingNodeTreeSymbols, isTypeParameterDeclaration),
|
|
131228
|
+
map(node.parameters, (p, i) => factory.createParameterDeclaration(
|
|
131229
|
+
/*modifiers*/
|
|
131230
|
+
void 0,
|
|
131231
|
+
getEffectiveDotDotDotForParameter(p),
|
|
131232
|
+
resolver.markNodeReuse(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p),
|
|
131233
|
+
factory.cloneNode(p.questionToken),
|
|
131234
|
+
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode),
|
|
131235
|
+
/*initializer*/
|
|
131236
|
+
void 0
|
|
131237
|
+
)),
|
|
131238
|
+
visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode) || factory.createKeywordTypeNode(133 /* AnyKeyword */)
|
|
131239
|
+
);
|
|
131240
|
+
}
|
|
131241
|
+
}
|
|
131242
|
+
if (isThisTypeNode(node)) {
|
|
131243
|
+
if (resolver.canReuseTypeNode(context, node)) {
|
|
131244
|
+
return node;
|
|
131245
|
+
}
|
|
131246
|
+
markError();
|
|
131247
|
+
return node;
|
|
131248
|
+
}
|
|
131249
|
+
if (isTypeParameterDeclaration(node)) {
|
|
131250
|
+
const { node: newName } = resolver.trackExistingEntityName(context, node.name);
|
|
131251
|
+
return factory.updateTypeParameterDeclaration(
|
|
131252
|
+
node,
|
|
131253
|
+
visitNodes2(node.modifiers, visitExistingNodeTreeSymbols, isModifier),
|
|
131254
|
+
// resolver.markNodeReuse(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node),
|
|
131255
|
+
newName,
|
|
131256
|
+
visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode),
|
|
131257
|
+
visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode)
|
|
131258
|
+
);
|
|
131259
|
+
}
|
|
131260
|
+
if (isIndexedAccessTypeNode(node)) {
|
|
131261
|
+
const result = tryVisitIndexedAccess(node);
|
|
131262
|
+
if (!result) {
|
|
131263
|
+
markError();
|
|
131264
|
+
return node;
|
|
131265
|
+
}
|
|
131266
|
+
return result;
|
|
131267
|
+
}
|
|
131268
|
+
if (isTypeReferenceNode(node)) {
|
|
131269
|
+
const result = tryVisitTypeReference(node);
|
|
131270
|
+
if (result) {
|
|
131271
|
+
return result;
|
|
131272
|
+
}
|
|
131273
|
+
markError();
|
|
131274
|
+
return node;
|
|
131275
|
+
}
|
|
131276
|
+
if (isLiteralImportTypeNode(node)) {
|
|
131277
|
+
if (((_a = node.attributes) == null ? void 0 : _a.token) === 132 /* AssertKeyword */) {
|
|
131278
|
+
markError();
|
|
131279
|
+
return node;
|
|
131280
|
+
}
|
|
131281
|
+
if (!resolver.canReuseTypeNode(context, node)) {
|
|
131282
|
+
return resolver.serializeExistingTypeNode(context, node);
|
|
131283
|
+
}
|
|
131284
|
+
return factory.updateImportTypeNode(
|
|
131285
|
+
node,
|
|
131286
|
+
factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier2(node, node.argument.literal)),
|
|
131287
|
+
visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes),
|
|
131288
|
+
visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName),
|
|
131289
|
+
visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
|
|
131290
|
+
node.isTypeOf
|
|
131291
|
+
);
|
|
131292
|
+
}
|
|
131293
|
+
if (isNamedDeclaration(node) && node.name.kind === 167 /* ComputedPropertyName */ && !resolver.hasLateBindableName(node)) {
|
|
131294
|
+
if (!hasDynamicName(node)) {
|
|
131295
|
+
return visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
131296
|
+
}
|
|
131297
|
+
if (resolver.shouldRemoveDeclaration(context, node)) {
|
|
131298
|
+
return void 0;
|
|
131299
|
+
}
|
|
131300
|
+
}
|
|
131301
|
+
if (isFunctionLike(node) && !node.type || isPropertyDeclaration(node) && !node.type && !node.initializer || isPropertySignature(node) && !node.type && !node.initializer || isParameter(node) && !node.type && !node.initializer) {
|
|
131302
|
+
let visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
131303
|
+
if (visited === node) {
|
|
131304
|
+
visited = resolver.markNodeReuse(context, factory.cloneNode(node), node);
|
|
131305
|
+
}
|
|
131306
|
+
visited.type = factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131307
|
+
if (isParameter(node)) {
|
|
131308
|
+
visited.modifiers = void 0;
|
|
131309
|
+
}
|
|
131310
|
+
return visited;
|
|
131311
|
+
}
|
|
131312
|
+
if (isTypeQueryNode(node)) {
|
|
131313
|
+
const result = tryVisitTypeQuery(node);
|
|
131314
|
+
if (!result) {
|
|
131315
|
+
markError();
|
|
131316
|
+
return node;
|
|
131317
|
+
}
|
|
131318
|
+
return result;
|
|
131319
|
+
}
|
|
131320
|
+
if (isComputedPropertyName(node) && isEntityNameExpression(node.expression)) {
|
|
131321
|
+
const { node: result, introducesError } = resolver.trackExistingEntityName(context, node.expression);
|
|
131322
|
+
if (!introducesError) {
|
|
131323
|
+
return factory.updateComputedPropertyName(node, result);
|
|
131324
|
+
} else {
|
|
131325
|
+
const computedPropertyNameType = resolver.serializeTypeOfExpression(context, node.expression);
|
|
131326
|
+
let literal;
|
|
131327
|
+
if (isLiteralTypeNode(computedPropertyNameType)) {
|
|
131328
|
+
literal = computedPropertyNameType.literal;
|
|
131329
|
+
} else {
|
|
131330
|
+
const evaluated = resolver.evaluateEntityNameExpression(node.expression);
|
|
131331
|
+
const literalNode = typeof evaluated.value === "string" ? factory.createStringLiteral(
|
|
131332
|
+
evaluated.value,
|
|
131333
|
+
/*isSingleQuote*/
|
|
131334
|
+
void 0
|
|
131335
|
+
) : typeof evaluated.value === "number" ? factory.createNumericLiteral(
|
|
131336
|
+
evaluated.value,
|
|
131337
|
+
/*numericLiteralFlags*/
|
|
131338
|
+
0
|
|
131339
|
+
) : void 0;
|
|
131340
|
+
if (!literalNode) {
|
|
131341
|
+
if (isImportTypeNode(computedPropertyNameType)) {
|
|
131342
|
+
resolver.trackComputedName(context, node.expression);
|
|
131343
|
+
}
|
|
131344
|
+
return node;
|
|
131345
|
+
}
|
|
131346
|
+
literal = literalNode;
|
|
131347
|
+
}
|
|
131348
|
+
if (literal.kind === 11 /* StringLiteral */ && isIdentifierText(literal.text, getEmitScriptTarget(options))) {
|
|
131349
|
+
return factory.createIdentifier(literal.text);
|
|
131350
|
+
}
|
|
131351
|
+
if (literal.kind === 9 /* NumericLiteral */ && !literal.text.startsWith("-")) {
|
|
131352
|
+
return literal;
|
|
131353
|
+
}
|
|
131354
|
+
return factory.updateComputedPropertyName(node, literal);
|
|
131355
|
+
}
|
|
131356
|
+
}
|
|
131357
|
+
if (isTypePredicateNode(node)) {
|
|
131358
|
+
let parameterName;
|
|
131359
|
+
if (isIdentifier(node.parameterName)) {
|
|
131360
|
+
const { node: result, introducesError } = resolver.trackExistingEntityName(context, node.parameterName);
|
|
131361
|
+
if (introducesError) markError();
|
|
131362
|
+
parameterName = result;
|
|
131363
|
+
} else {
|
|
131364
|
+
parameterName = factory.cloneNode(node.parameterName);
|
|
131365
|
+
}
|
|
131366
|
+
return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode));
|
|
131367
|
+
}
|
|
131368
|
+
if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) {
|
|
131369
|
+
const visited = visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
131370
|
+
const clone = resolver.markNodeReuse(context, visited === node ? factory.cloneNode(node) : visited, node);
|
|
131371
|
+
const flags = getEmitFlags(clone);
|
|
131372
|
+
setEmitFlags(clone, flags | (context.flags & 1024 /* MultilineObjectLiterals */ && isTypeLiteralNode(node) ? 0 : 1 /* SingleLine */));
|
|
131373
|
+
return clone;
|
|
131374
|
+
}
|
|
131375
|
+
if (isStringLiteral(node) && !!(context.flags & 268435456 /* UseSingleQuotesForStringLiteralType */) && !node.singleQuote) {
|
|
131376
|
+
const clone = factory.cloneNode(node);
|
|
131377
|
+
clone.singleQuote = true;
|
|
131378
|
+
return clone;
|
|
131379
|
+
}
|
|
131380
|
+
if (isConditionalTypeNode(node)) {
|
|
131381
|
+
const checkType = visitNode(node.checkType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131382
|
+
const disposeScope = resolver.enterNewScope(context, node);
|
|
131383
|
+
const extendType = visitNode(node.extendsType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131384
|
+
const trueType = visitNode(node.trueType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131385
|
+
disposeScope();
|
|
131386
|
+
const falseType = visitNode(node.falseType, visitExistingNodeTreeSymbols, isTypeNode);
|
|
131387
|
+
return factory.updateConditionalTypeNode(
|
|
131388
|
+
node,
|
|
131389
|
+
checkType,
|
|
131390
|
+
extendType,
|
|
131391
|
+
trueType,
|
|
131392
|
+
falseType
|
|
131393
|
+
);
|
|
131394
|
+
}
|
|
131395
|
+
if (isTypeOperatorNode(node)) {
|
|
131396
|
+
if (node.operator === 158 /* UniqueKeyword */ && node.type.kind === 155 /* SymbolKeyword */) {
|
|
131397
|
+
if (!resolver.canReuseTypeNode(context, node)) {
|
|
131398
|
+
markError();
|
|
131399
|
+
return node;
|
|
131400
|
+
}
|
|
131401
|
+
} else if (node.operator === 143 /* KeyOfKeyword */) {
|
|
131402
|
+
const result = tryVisitKeyOf(node);
|
|
131403
|
+
if (!result) {
|
|
131404
|
+
markError();
|
|
131405
|
+
return node;
|
|
131406
|
+
}
|
|
131407
|
+
return result;
|
|
131408
|
+
}
|
|
131409
|
+
}
|
|
131410
|
+
return visitEachChild2(node, visitExistingNodeTreeSymbols);
|
|
131411
|
+
function visitEachChild2(node2, visitor) {
|
|
131412
|
+
const nonlocalNode = !context.enclosingFile || context.enclosingFile !== getSourceFileOfNode(node2);
|
|
131413
|
+
return visitEachChild(
|
|
131414
|
+
node2,
|
|
131415
|
+
visitor,
|
|
131416
|
+
/*context*/
|
|
131417
|
+
void 0,
|
|
131418
|
+
nonlocalNode ? visitNodesWithoutCopyingPositions : void 0
|
|
131419
|
+
);
|
|
131420
|
+
}
|
|
131421
|
+
function visitNodesWithoutCopyingPositions(nodes, visitor, test, start, count) {
|
|
131422
|
+
let result = visitNodes2(nodes, visitor, test, start, count);
|
|
131423
|
+
if (result) {
|
|
131424
|
+
if (result.pos !== -1 || result.end !== -1) {
|
|
131425
|
+
if (result === nodes) {
|
|
131426
|
+
result = factory.createNodeArray(nodes.slice(), nodes.hasTrailingComma);
|
|
131427
|
+
}
|
|
131428
|
+
setTextRangePosEnd(result, -1, -1);
|
|
131429
|
+
}
|
|
131430
|
+
}
|
|
131431
|
+
return result;
|
|
131432
|
+
}
|
|
131433
|
+
function getEffectiveDotDotDotForParameter(p) {
|
|
131434
|
+
return p.dotDotDotToken || (p.type && isJSDocVariadicType(p.type) ? factory.createToken(26 /* DotDotDotToken */) : void 0);
|
|
131435
|
+
}
|
|
131436
|
+
function getNameForJSDocFunctionParameter(p, index) {
|
|
131437
|
+
return p.name && isIdentifier(p.name) && p.name.escapedText === "this" ? "this" : getEffectiveDotDotDotForParameter(p) ? `args` : `arg${index}`;
|
|
131438
|
+
}
|
|
131439
|
+
function rewriteModuleSpecifier2(parent, lit) {
|
|
131440
|
+
const newName = resolver.getModuleSpecifierOverride(context, parent, lit);
|
|
131441
|
+
if (newName) {
|
|
131442
|
+
return setOriginalNode(factory.createStringLiteral(newName), lit);
|
|
131443
|
+
}
|
|
131444
|
+
return visitNode(lit, visitExistingNodeTreeSymbols, isStringLiteral);
|
|
131445
|
+
}
|
|
131446
|
+
}
|
|
131447
|
+
}
|
|
131448
|
+
function serializeExistingTypeNode(typeNode, context, addUndefined) {
|
|
131449
|
+
if (!typeNode) return void 0;
|
|
131450
|
+
let result;
|
|
131451
|
+
if ((!addUndefined || canAddUndefined(typeNode)) && resolver.canReuseTypeNode(context, typeNode)) {
|
|
131452
|
+
result = tryReuseExistingTypeNode(context, typeNode);
|
|
131453
|
+
if (result !== void 0) {
|
|
131454
|
+
result = addUndefinedIfNeeded(
|
|
131455
|
+
result,
|
|
131456
|
+
addUndefined,
|
|
131457
|
+
/*owner*/
|
|
131458
|
+
void 0,
|
|
131459
|
+
context
|
|
131460
|
+
);
|
|
131461
|
+
}
|
|
131462
|
+
}
|
|
131463
|
+
return result;
|
|
131464
|
+
}
|
|
131465
|
+
function serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol, requiresAddingUndefined, useFallback = requiresAddingUndefined !== void 0) {
|
|
131466
|
+
if (!declaredType) return void 0;
|
|
131467
|
+
if (!resolver.canReuseTypeNodeAnnotation(context, node, declaredType, symbol, requiresAddingUndefined)) {
|
|
131468
|
+
if (!requiresAddingUndefined || !resolver.canReuseTypeNodeAnnotation(
|
|
131469
|
+
context,
|
|
131470
|
+
node,
|
|
131471
|
+
declaredType,
|
|
131472
|
+
symbol,
|
|
131473
|
+
/*requiresAddingUndefined*/
|
|
131474
|
+
false
|
|
131475
|
+
)) {
|
|
131476
|
+
return void 0;
|
|
131477
|
+
}
|
|
131478
|
+
}
|
|
131479
|
+
let result;
|
|
131480
|
+
if (!requiresAddingUndefined || canAddUndefined(declaredType)) {
|
|
131481
|
+
result = serializeExistingTypeNode(declaredType, context, requiresAddingUndefined);
|
|
131482
|
+
}
|
|
131483
|
+
if (result !== void 0 || !useFallback) {
|
|
131484
|
+
return result;
|
|
131485
|
+
}
|
|
131486
|
+
context.tracker.reportInferenceFallback(node);
|
|
131487
|
+
return resolver.serializeExistingTypeNode(context, declaredType, requiresAddingUndefined) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131488
|
+
}
|
|
131489
|
+
function serializeExistingTypeNodeWithFallback(typeNode, context, addUndefined, targetNode) {
|
|
131490
|
+
if (!typeNode) return void 0;
|
|
131491
|
+
const result = serializeExistingTypeNode(typeNode, context, addUndefined);
|
|
131492
|
+
if (result !== void 0) {
|
|
131493
|
+
return result;
|
|
131494
|
+
}
|
|
131495
|
+
context.tracker.reportInferenceFallback(targetNode ?? typeNode);
|
|
131496
|
+
return resolver.serializeExistingTypeNode(context, typeNode, addUndefined) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131497
|
+
}
|
|
131498
|
+
function serializeTypeOfAccessor(accessor, symbol, context) {
|
|
131499
|
+
return typeFromAccessor(accessor, symbol, context) ?? inferAccessorType(accessor, resolver.getAllAccessorDeclarations(accessor), context, symbol);
|
|
131440
131500
|
}
|
|
131441
131501
|
function serializeTypeOfExpression(expr, context, addUndefined, preserveLiterals) {
|
|
131442
|
-
|
|
131502
|
+
const result = typeFromExpression(
|
|
131443
131503
|
expr,
|
|
131444
131504
|
context,
|
|
131445
131505
|
/*isConstContext*/
|
|
131446
131506
|
false,
|
|
131447
131507
|
addUndefined,
|
|
131448
131508
|
preserveLiterals
|
|
131449
|
-
)
|
|
131509
|
+
);
|
|
131510
|
+
return result.type !== void 0 ? result.type : inferExpressionType(expr, context, result.reportFallback);
|
|
131450
131511
|
}
|
|
131451
|
-
function serializeTypeOfDeclaration(node, context) {
|
|
131512
|
+
function serializeTypeOfDeclaration(node, symbol, context) {
|
|
131452
131513
|
switch (node.kind) {
|
|
131453
|
-
case 171 /* PropertySignature */:
|
|
131454
|
-
return serializeExistingTypeAnnotation(getEffectiveTypeAnnotationNode(node));
|
|
131455
131514
|
case 169 /* Parameter */:
|
|
131456
|
-
|
|
131515
|
+
case 341 /* JSDocParameterTag */:
|
|
131516
|
+
return typeFromParameter(node, symbol, context);
|
|
131457
131517
|
case 260 /* VariableDeclaration */:
|
|
131458
|
-
return typeFromVariable(node, context);
|
|
131518
|
+
return typeFromVariable(node, symbol, context);
|
|
131519
|
+
case 171 /* PropertySignature */:
|
|
131520
|
+
case 348 /* JSDocPropertyTag */:
|
|
131459
131521
|
case 172 /* PropertyDeclaration */:
|
|
131460
|
-
return typeFromProperty(node, context);
|
|
131522
|
+
return typeFromProperty(node, symbol, context);
|
|
131461
131523
|
case 208 /* BindingElement */:
|
|
131462
|
-
return inferTypeOfDeclaration(node, context);
|
|
131524
|
+
return inferTypeOfDeclaration(node, symbol, context);
|
|
131463
131525
|
case 277 /* ExportAssignment */:
|
|
131464
131526
|
return serializeTypeOfExpression(
|
|
131465
131527
|
node.expression,
|
|
@@ -131472,17 +131534,39 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131472
131534
|
case 211 /* PropertyAccessExpression */:
|
|
131473
131535
|
case 212 /* ElementAccessExpression */:
|
|
131474
131536
|
case 226 /* BinaryExpression */:
|
|
131475
|
-
return
|
|
131537
|
+
return typeFromExpandoProperty(node, symbol, context);
|
|
131476
131538
|
case 303 /* PropertyAssignment */:
|
|
131477
|
-
|
|
131539
|
+
case 304 /* ShorthandPropertyAssignment */:
|
|
131540
|
+
return typeFromPropertyAssignment(node, symbol, context);
|
|
131478
131541
|
default:
|
|
131479
131542
|
Debug.assertNever(node, `Node needs to be an inferrable node, found ${Debug.formatSyntaxKind(node.kind)}`);
|
|
131480
131543
|
}
|
|
131481
131544
|
}
|
|
131482
|
-
function
|
|
131545
|
+
function typeFromPropertyAssignment(node, symbol, context) {
|
|
131546
|
+
const typeAnnotation = getEffectiveTypeAnnotationNode(node);
|
|
131547
|
+
let result;
|
|
131548
|
+
if (typeAnnotation && resolver.canReuseTypeNodeAnnotation(context, node, typeAnnotation, symbol)) {
|
|
131549
|
+
result = serializeExistingTypeNode(typeAnnotation, context);
|
|
131550
|
+
}
|
|
131551
|
+
if (!result && node.kind === 303 /* PropertyAssignment */) {
|
|
131552
|
+
const initializer = node.initializer;
|
|
131553
|
+
const type = isJSDocTypeAssertion(initializer) ? getJSDocTypeAssertionType(initializer) : initializer.kind === 234 /* AsExpression */ || initializer.kind === 216 /* TypeAssertionExpression */ ? initializer.type : void 0;
|
|
131554
|
+
if (type && !isConstTypeReference(type)) {
|
|
131555
|
+
result = serializeExistingTypeNode(type, context);
|
|
131556
|
+
}
|
|
131557
|
+
}
|
|
131558
|
+
return result ?? inferTypeOfDeclaration(
|
|
131559
|
+
node,
|
|
131560
|
+
symbol,
|
|
131561
|
+
context,
|
|
131562
|
+
/*reportFallback*/
|
|
131563
|
+
false
|
|
131564
|
+
);
|
|
131565
|
+
}
|
|
131566
|
+
function serializeReturnTypeForSignature(node, symbol, context) {
|
|
131483
131567
|
switch (node.kind) {
|
|
131484
131568
|
case 177 /* GetAccessor */:
|
|
131485
|
-
return
|
|
131569
|
+
return serializeTypeOfAccessor(node, symbol, context);
|
|
131486
131570
|
case 174 /* MethodDeclaration */:
|
|
131487
131571
|
case 262 /* FunctionDeclaration */:
|
|
131488
131572
|
case 180 /* ConstructSignature */:
|
|
@@ -131497,45 +131581,50 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131497
131581
|
case 219 /* ArrowFunction */:
|
|
131498
131582
|
case 317 /* JSDocFunctionType */:
|
|
131499
131583
|
case 323 /* JSDocSignature */:
|
|
131500
|
-
return createReturnFromSignature(node, context);
|
|
131584
|
+
return createReturnFromSignature(node, symbol, context);
|
|
131501
131585
|
default:
|
|
131502
131586
|
Debug.assertNever(node, `Node needs to be an inferrable node, found ${Debug.formatSyntaxKind(node.kind)}`);
|
|
131503
131587
|
}
|
|
131504
131588
|
}
|
|
131505
|
-
function
|
|
131589
|
+
function getTypeAnnotationFromAccessor(accessor) {
|
|
131506
131590
|
if (accessor) {
|
|
131507
|
-
return accessor.kind === 177 /* GetAccessor */ ?
|
|
131591
|
+
return accessor.kind === 177 /* GetAccessor */ ? isInJSFile(accessor) && getJSDocType(accessor) || getEffectiveReturnTypeNode(accessor) : getEffectiveSetAccessorTypeAnnotationNode(accessor);
|
|
131508
131592
|
}
|
|
131509
131593
|
}
|
|
131510
131594
|
function getTypeAnnotationFromAllAccessorDeclarations(node, accessors) {
|
|
131511
|
-
let accessorType =
|
|
131595
|
+
let accessorType = getTypeAnnotationFromAccessor(node);
|
|
131512
131596
|
if (!accessorType && node !== accessors.firstAccessor) {
|
|
131513
|
-
accessorType =
|
|
131597
|
+
accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor);
|
|
131514
131598
|
}
|
|
131515
131599
|
if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) {
|
|
131516
|
-
accessorType =
|
|
131600
|
+
accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor);
|
|
131517
131601
|
}
|
|
131518
131602
|
return accessorType;
|
|
131519
131603
|
}
|
|
131520
|
-
function typeFromAccessor(node, context) {
|
|
131604
|
+
function typeFromAccessor(node, symbol, context) {
|
|
131521
131605
|
const accessorDeclarations = resolver.getAllAccessorDeclarations(node);
|
|
131522
131606
|
const accessorType = getTypeAnnotationFromAllAccessorDeclarations(node, accessorDeclarations);
|
|
131523
|
-
if (accessorType) {
|
|
131524
|
-
return
|
|
131607
|
+
if (accessorType && !isTypePredicateNode(accessorType)) {
|
|
131608
|
+
return withNewScope(context, node, () => serializeTypeAnnotationOfDeclaration(accessorType, context, node, symbol) ?? inferTypeOfDeclaration(node, symbol, context));
|
|
131525
131609
|
}
|
|
131526
131610
|
if (accessorDeclarations.getAccessor) {
|
|
131527
|
-
return
|
|
131611
|
+
return withNewScope(context, accessorDeclarations.getAccessor, () => createReturnFromSignature(
|
|
131612
|
+
accessorDeclarations.getAccessor,
|
|
131613
|
+
/*symbol*/
|
|
131614
|
+
void 0,
|
|
131615
|
+
context
|
|
131616
|
+
));
|
|
131528
131617
|
}
|
|
131529
|
-
return
|
|
131618
|
+
return void 0;
|
|
131530
131619
|
}
|
|
131531
|
-
function typeFromVariable(node, context) {
|
|
131620
|
+
function typeFromVariable(node, symbol, context) {
|
|
131621
|
+
var _a;
|
|
131532
131622
|
const declaredType = getEffectiveTypeAnnotationNode(node);
|
|
131623
|
+
let resultType = failed;
|
|
131533
131624
|
if (declaredType) {
|
|
131534
|
-
|
|
131535
|
-
}
|
|
131536
|
-
|
|
131537
|
-
if (node.initializer) {
|
|
131538
|
-
if (!resolver.isExpandoFunctionDeclaration(node)) {
|
|
131625
|
+
resultType = syntacticResult(serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol));
|
|
131626
|
+
} else if (node.initializer && (((_a = symbol.declarations) == null ? void 0 : _a.length) === 1 || countWhere(symbol.declarations, isVariableDeclaration) === 1)) {
|
|
131627
|
+
if (!resolver.isExpandoFunctionDeclaration(node) && !isContextuallyTyped(node)) {
|
|
131539
131628
|
resultType = typeFromExpression(
|
|
131540
131629
|
node.initializer,
|
|
131541
131630
|
context,
|
|
@@ -131547,71 +131636,119 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131547
131636
|
);
|
|
131548
131637
|
}
|
|
131549
131638
|
}
|
|
131550
|
-
return resultType
|
|
131639
|
+
return resultType.type !== void 0 ? resultType.type : inferTypeOfDeclaration(node, symbol, context, resultType.reportFallback);
|
|
131551
131640
|
}
|
|
131552
|
-
function typeFromParameter(node, context) {
|
|
131641
|
+
function typeFromParameter(node, symbol, context) {
|
|
131553
131642
|
const parent = node.parent;
|
|
131554
131643
|
if (parent.kind === 178 /* SetAccessor */) {
|
|
131555
|
-
return
|
|
131644
|
+
return serializeTypeOfAccessor(
|
|
131645
|
+
parent,
|
|
131646
|
+
/*symbol*/
|
|
131647
|
+
void 0,
|
|
131648
|
+
context
|
|
131649
|
+
);
|
|
131556
131650
|
}
|
|
131557
131651
|
const declaredType = getEffectiveTypeAnnotationNode(node);
|
|
131558
|
-
const addUndefined = resolver.requiresAddingImplicitUndefined(node, context.enclosingDeclaration);
|
|
131559
|
-
let resultType;
|
|
131652
|
+
const addUndefined = resolver.requiresAddingImplicitUndefined(node, symbol, context.enclosingDeclaration);
|
|
131653
|
+
let resultType = failed;
|
|
131560
131654
|
if (declaredType) {
|
|
131561
|
-
resultType =
|
|
131655
|
+
resultType = syntacticResult(serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol, addUndefined));
|
|
131656
|
+
} else if (isParameter(node) && node.initializer && isIdentifier(node.name) && !isContextuallyTyped(node)) {
|
|
131657
|
+
resultType = typeFromExpression(
|
|
131658
|
+
node.initializer,
|
|
131659
|
+
context,
|
|
131660
|
+
/*isConstContext*/
|
|
131661
|
+
void 0,
|
|
131662
|
+
addUndefined
|
|
131663
|
+
);
|
|
131664
|
+
}
|
|
131665
|
+
return resultType.type !== void 0 ? resultType.type : inferTypeOfDeclaration(node, symbol, context, resultType.reportFallback);
|
|
131666
|
+
}
|
|
131667
|
+
function typeFromExpandoProperty(node, symbol, context) {
|
|
131668
|
+
const declaredType = getEffectiveTypeAnnotationNode(node);
|
|
131669
|
+
let result;
|
|
131670
|
+
if (declaredType) {
|
|
131671
|
+
result = serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol);
|
|
131672
|
+
}
|
|
131673
|
+
const oldSuppressReportInferenceFallback = context.suppressReportInferenceFallback;
|
|
131674
|
+
context.suppressReportInferenceFallback = true;
|
|
131675
|
+
const resultType = result ?? inferTypeOfDeclaration(
|
|
131676
|
+
node,
|
|
131677
|
+
symbol,
|
|
131678
|
+
context,
|
|
131679
|
+
/*reportFallback*/
|
|
131680
|
+
false
|
|
131681
|
+
);
|
|
131682
|
+
context.suppressReportInferenceFallback = oldSuppressReportInferenceFallback;
|
|
131683
|
+
return resultType;
|
|
131684
|
+
}
|
|
131685
|
+
function typeFromProperty(node, symbol, context) {
|
|
131686
|
+
const declaredType = getEffectiveTypeAnnotationNode(node);
|
|
131687
|
+
const requiresAddingUndefined = resolver.requiresAddingImplicitUndefined(node, symbol, context.enclosingDeclaration);
|
|
131688
|
+
let resultType = failed;
|
|
131689
|
+
if (declaredType) {
|
|
131690
|
+
resultType = syntacticResult(serializeTypeAnnotationOfDeclaration(declaredType, context, node, symbol, requiresAddingUndefined));
|
|
131562
131691
|
} else {
|
|
131563
|
-
|
|
131692
|
+
const initializer = isPropertyDeclaration(node) ? node.initializer : void 0;
|
|
131693
|
+
if (initializer && !isContextuallyTyped(node)) {
|
|
131694
|
+
const isReadonly = isDeclarationReadonly(node);
|
|
131564
131695
|
resultType = typeFromExpression(
|
|
131565
|
-
|
|
131696
|
+
initializer,
|
|
131566
131697
|
context,
|
|
131567
131698
|
/*isConstContext*/
|
|
131568
131699
|
void 0,
|
|
131569
|
-
|
|
131700
|
+
requiresAddingUndefined,
|
|
131701
|
+
isReadonly
|
|
131570
131702
|
);
|
|
131571
131703
|
}
|
|
131572
131704
|
}
|
|
131573
|
-
return resultType
|
|
131705
|
+
return resultType.type !== void 0 ? resultType.type : inferTypeOfDeclaration(node, symbol, context, resultType.reportFallback);
|
|
131574
131706
|
}
|
|
131575
|
-
function
|
|
131576
|
-
|
|
131577
|
-
|
|
131578
|
-
return serializeExistingTypeAnnotation(declaredType);
|
|
131707
|
+
function inferTypeOfDeclaration(node, symbol, context, reportFallback = true) {
|
|
131708
|
+
if (reportFallback) {
|
|
131709
|
+
context.tracker.reportInferenceFallback(node);
|
|
131579
131710
|
}
|
|
131580
|
-
|
|
131581
|
-
|
|
131582
|
-
const isReadonly = isDeclarationReadonly(node);
|
|
131583
|
-
resultType = typeFromExpression(
|
|
131584
|
-
node.initializer,
|
|
131585
|
-
context,
|
|
131586
|
-
/*isConstContext*/
|
|
131587
|
-
void 0,
|
|
131588
|
-
/*requiresAddingUndefined*/
|
|
131589
|
-
void 0,
|
|
131590
|
-
isReadonly
|
|
131591
|
-
);
|
|
131711
|
+
if (context.noInferenceFallback === true) {
|
|
131712
|
+
return factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131592
131713
|
}
|
|
131593
|
-
return
|
|
131714
|
+
return resolver.serializeTypeOfDeclaration(context, node, symbol);
|
|
131594
131715
|
}
|
|
131595
|
-
function
|
|
131596
|
-
|
|
131597
|
-
|
|
131598
|
-
|
|
131599
|
-
|
|
131600
|
-
context.
|
|
131601
|
-
|
|
131716
|
+
function inferExpressionType(node, context, reportFallback = true, requiresAddingUndefined) {
|
|
131717
|
+
Debug.assert(!requiresAddingUndefined);
|
|
131718
|
+
if (reportFallback) {
|
|
131719
|
+
context.tracker.reportInferenceFallback(node);
|
|
131720
|
+
}
|
|
131721
|
+
if (context.noInferenceFallback === true) {
|
|
131722
|
+
return factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131723
|
+
}
|
|
131724
|
+
return resolver.serializeTypeOfExpression(context, node) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131602
131725
|
}
|
|
131603
|
-
function inferReturnTypeOfSignatureSignature(node, context) {
|
|
131604
|
-
|
|
131605
|
-
|
|
131726
|
+
function inferReturnTypeOfSignatureSignature(node, context, reportFallback) {
|
|
131727
|
+
if (reportFallback) {
|
|
131728
|
+
context.tracker.reportInferenceFallback(node);
|
|
131729
|
+
}
|
|
131730
|
+
if (context.noInferenceFallback === true) {
|
|
131731
|
+
return factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131732
|
+
}
|
|
131733
|
+
return resolver.serializeReturnTypeForSignature(context, node) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131606
131734
|
}
|
|
131607
|
-
function inferAccessorType(node, allAccessors, context) {
|
|
131735
|
+
function inferAccessorType(node, allAccessors, context, symbol, reportFallback = true) {
|
|
131608
131736
|
if (node.kind === 177 /* GetAccessor */) {
|
|
131609
|
-
return createReturnFromSignature(node, context);
|
|
131737
|
+
return createReturnFromSignature(node, symbol, context, reportFallback);
|
|
131610
131738
|
} else {
|
|
131611
|
-
|
|
131612
|
-
|
|
131739
|
+
if (reportFallback) {
|
|
131740
|
+
context.tracker.reportInferenceFallback(node);
|
|
131741
|
+
}
|
|
131742
|
+
const result = allAccessors.getAccessor && createReturnFromSignature(allAccessors.getAccessor, symbol, context, reportFallback);
|
|
131743
|
+
return result ?? resolver.serializeTypeOfDeclaration(context, node, symbol) ?? factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
131613
131744
|
}
|
|
131614
131745
|
}
|
|
131746
|
+
function withNewScope(context, node, fn) {
|
|
131747
|
+
const cleanup = resolver.enterNewScope(context, node);
|
|
131748
|
+
const result = fn();
|
|
131749
|
+
cleanup();
|
|
131750
|
+
return result;
|
|
131751
|
+
}
|
|
131615
131752
|
function typeFromTypeAssertion(expression, type, context, requiresAddingUndefined) {
|
|
131616
131753
|
if (isConstTypeReference(type)) {
|
|
131617
131754
|
return typeFromExpression(
|
|
@@ -131622,10 +131759,7 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131622
131759
|
requiresAddingUndefined
|
|
131623
131760
|
);
|
|
131624
131761
|
}
|
|
131625
|
-
|
|
131626
|
-
context.tracker.reportInferenceFallback(type);
|
|
131627
|
-
}
|
|
131628
|
-
return serializeExistingTypeAnnotation(type);
|
|
131762
|
+
return syntacticResult(serializeExistingTypeNodeWithFallback(type, context, requiresAddingUndefined));
|
|
131629
131763
|
}
|
|
131630
131764
|
function typeFromExpression(node, context, isConstContext = false, requiresAddingUndefined = false, preserveLiterals = false) {
|
|
131631
131765
|
switch (node.kind) {
|
|
@@ -131636,14 +131770,19 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131636
131770
|
return typeFromExpression(node.expression, context, isConstContext, requiresAddingUndefined);
|
|
131637
131771
|
case 80 /* Identifier */:
|
|
131638
131772
|
if (resolver.isUndefinedIdentifierExpression(node)) {
|
|
131639
|
-
return
|
|
131773
|
+
return syntacticResult(createUndefinedTypeNode());
|
|
131640
131774
|
}
|
|
131641
131775
|
break;
|
|
131642
131776
|
case 106 /* NullKeyword */:
|
|
131643
|
-
|
|
131777
|
+
if (strictNullChecks) {
|
|
131778
|
+
return syntacticResult(addUndefinedIfNeeded(factory.createLiteralTypeNode(factory.createNull()), requiresAddingUndefined, node, context));
|
|
131779
|
+
} else {
|
|
131780
|
+
return syntacticResult(factory.createKeywordTypeNode(133 /* AnyKeyword */));
|
|
131781
|
+
}
|
|
131644
131782
|
case 219 /* ArrowFunction */:
|
|
131645
131783
|
case 218 /* FunctionExpression */:
|
|
131646
|
-
|
|
131784
|
+
Debug.type(node);
|
|
131785
|
+
return withNewScope(context, node, () => typeFromFunctionLikeExpression(node, context));
|
|
131647
131786
|
case 216 /* TypeAssertionExpression */:
|
|
131648
131787
|
case 234 /* AsExpression */:
|
|
131649
131788
|
const asExpression = node;
|
|
@@ -131651,43 +131790,73 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131651
131790
|
case 224 /* PrefixUnaryExpression */:
|
|
131652
131791
|
const unaryExpression = node;
|
|
131653
131792
|
if (isPrimitiveLiteralValue(unaryExpression)) {
|
|
131654
|
-
|
|
131655
|
-
|
|
131656
|
-
|
|
131657
|
-
|
|
131658
|
-
|
|
131659
|
-
|
|
131793
|
+
return typeFromPrimitiveLiteral(
|
|
131794
|
+
unaryExpression.operator === 40 /* PlusToken */ ? unaryExpression.operand : unaryExpression,
|
|
131795
|
+
unaryExpression.operand.kind === 10 /* BigIntLiteral */ ? 163 /* BigIntKeyword */ : 150 /* NumberKeyword */,
|
|
131796
|
+
context,
|
|
131797
|
+
isConstContext || preserveLiterals,
|
|
131798
|
+
requiresAddingUndefined
|
|
131799
|
+
);
|
|
131660
131800
|
}
|
|
131661
131801
|
break;
|
|
131662
|
-
case
|
|
131663
|
-
return
|
|
131802
|
+
case 209 /* ArrayLiteralExpression */:
|
|
131803
|
+
return typeFromArrayLiteral(node, context, isConstContext, requiresAddingUndefined);
|
|
131804
|
+
case 210 /* ObjectLiteralExpression */:
|
|
131805
|
+
return typeFromObjectLiteral(node, context, isConstContext, requiresAddingUndefined);
|
|
131806
|
+
case 231 /* ClassExpression */:
|
|
131807
|
+
return syntacticResult(inferExpressionType(
|
|
131808
|
+
node,
|
|
131809
|
+
context,
|
|
131810
|
+
/*reportFallback*/
|
|
131811
|
+
true,
|
|
131812
|
+
requiresAddingUndefined
|
|
131813
|
+
));
|
|
131664
131814
|
case 228 /* TemplateExpression */:
|
|
131665
131815
|
if (!isConstContext && !preserveLiterals) {
|
|
131666
|
-
return
|
|
131816
|
+
return syntacticResult(factory.createKeywordTypeNode(154 /* StringKeyword */));
|
|
131667
131817
|
}
|
|
131668
131818
|
break;
|
|
131669
|
-
|
|
131670
|
-
|
|
131671
|
-
|
|
131672
|
-
|
|
131673
|
-
|
|
131674
|
-
|
|
131675
|
-
|
|
131676
|
-
|
|
131677
|
-
|
|
131678
|
-
|
|
131679
|
-
|
|
131680
|
-
|
|
131681
|
-
|
|
131682
|
-
|
|
131819
|
+
default:
|
|
131820
|
+
let typeKind;
|
|
131821
|
+
let primitiveNode = node;
|
|
131822
|
+
switch (node.kind) {
|
|
131823
|
+
case 9 /* NumericLiteral */:
|
|
131824
|
+
typeKind = 150 /* NumberKeyword */;
|
|
131825
|
+
break;
|
|
131826
|
+
case 15 /* NoSubstitutionTemplateLiteral */:
|
|
131827
|
+
primitiveNode = factory.createStringLiteral(node.text);
|
|
131828
|
+
typeKind = 154 /* StringKeyword */;
|
|
131829
|
+
break;
|
|
131830
|
+
case 11 /* StringLiteral */:
|
|
131831
|
+
typeKind = 154 /* StringKeyword */;
|
|
131832
|
+
break;
|
|
131833
|
+
case 10 /* BigIntLiteral */:
|
|
131834
|
+
typeKind = 163 /* BigIntKeyword */;
|
|
131835
|
+
break;
|
|
131836
|
+
case 112 /* TrueKeyword */:
|
|
131837
|
+
case 97 /* FalseKeyword */:
|
|
131838
|
+
typeKind = 136 /* BooleanKeyword */;
|
|
131839
|
+
break;
|
|
131840
|
+
}
|
|
131841
|
+
if (typeKind) {
|
|
131842
|
+
return typeFromPrimitiveLiteral(primitiveNode, typeKind, context, isConstContext || preserveLiterals, requiresAddingUndefined);
|
|
131843
|
+
}
|
|
131683
131844
|
}
|
|
131684
|
-
return
|
|
131845
|
+
return failed;
|
|
131685
131846
|
}
|
|
131686
131847
|
function typeFromFunctionLikeExpression(fnNode, context) {
|
|
131687
|
-
const
|
|
131688
|
-
|
|
131689
|
-
|
|
131690
|
-
|
|
131848
|
+
const oldNoInferenceFallback = context.noInferenceFallback;
|
|
131849
|
+
context.noInferenceFallback = true;
|
|
131850
|
+
createReturnFromSignature(
|
|
131851
|
+
fnNode,
|
|
131852
|
+
/*symbol*/
|
|
131853
|
+
void 0,
|
|
131854
|
+
context
|
|
131855
|
+
);
|
|
131856
|
+
reuseTypeParameters(fnNode.typeParameters, context);
|
|
131857
|
+
fnNode.parameters.map((p) => ensureParameter(p, context));
|
|
131858
|
+
context.noInferenceFallback = oldNoInferenceFallback;
|
|
131859
|
+
return notImplemented2;
|
|
131691
131860
|
}
|
|
131692
131861
|
function canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext) {
|
|
131693
131862
|
if (!isConstContext) {
|
|
@@ -131702,18 +131871,38 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131702
131871
|
}
|
|
131703
131872
|
return true;
|
|
131704
131873
|
}
|
|
131705
|
-
function typeFromArrayLiteral(arrayLiteral, context, isConstContext) {
|
|
131874
|
+
function typeFromArrayLiteral(arrayLiteral, context, isConstContext, requiresAddingUndefined) {
|
|
131706
131875
|
if (!canGetTypeFromArrayLiteral(arrayLiteral, context, isConstContext)) {
|
|
131707
|
-
|
|
131876
|
+
if (requiresAddingUndefined || isDeclaration(walkUpParenthesizedExpressions(arrayLiteral).parent)) {
|
|
131877
|
+
return alreadyReported;
|
|
131878
|
+
}
|
|
131879
|
+
return syntacticResult(inferExpressionType(
|
|
131880
|
+
arrayLiteral,
|
|
131881
|
+
context,
|
|
131882
|
+
/*reportFallback*/
|
|
131883
|
+
false,
|
|
131884
|
+
requiresAddingUndefined
|
|
131885
|
+
));
|
|
131708
131886
|
}
|
|
131709
|
-
|
|
131887
|
+
const oldNoInferenceFallback = context.noInferenceFallback;
|
|
131888
|
+
context.noInferenceFallback = true;
|
|
131889
|
+
const elementTypesInfo = [];
|
|
131710
131890
|
for (const element of arrayLiteral.elements) {
|
|
131711
131891
|
Debug.assert(element.kind !== 230 /* SpreadElement */);
|
|
131712
|
-
if (element.kind
|
|
131713
|
-
|
|
131892
|
+
if (element.kind === 232 /* OmittedExpression */) {
|
|
131893
|
+
elementTypesInfo.push(
|
|
131894
|
+
createUndefinedTypeNode()
|
|
131895
|
+
);
|
|
131896
|
+
} else {
|
|
131897
|
+
const expressionType = typeFromExpression(element, context, isConstContext);
|
|
131898
|
+
const elementType = expressionType.type !== void 0 ? expressionType.type : inferExpressionType(element, context, expressionType.reportFallback);
|
|
131899
|
+
elementTypesInfo.push(elementType);
|
|
131714
131900
|
}
|
|
131715
131901
|
}
|
|
131716
|
-
|
|
131902
|
+
const tupleType = factory.createTupleTypeNode(elementTypesInfo);
|
|
131903
|
+
tupleType.emitNode = { flags: 1, autoGenerate: void 0, internalFlags: 0 };
|
|
131904
|
+
context.noInferenceFallback = oldNoInferenceFallback;
|
|
131905
|
+
return notImplemented2;
|
|
131717
131906
|
}
|
|
131718
131907
|
function canGetTypeFromObjectLiteral(objectLiteral, context) {
|
|
131719
131908
|
let result = true;
|
|
@@ -131744,64 +131933,214 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131744
131933
|
}
|
|
131745
131934
|
return result;
|
|
131746
131935
|
}
|
|
131747
|
-
function typeFromObjectLiteral(objectLiteral, context, isConstContext) {
|
|
131748
|
-
if (!canGetTypeFromObjectLiteral(objectLiteral, context))
|
|
131749
|
-
|
|
131936
|
+
function typeFromObjectLiteral(objectLiteral, context, isConstContext, requiresAddingUndefined) {
|
|
131937
|
+
if (!canGetTypeFromObjectLiteral(objectLiteral, context)) {
|
|
131938
|
+
if (requiresAddingUndefined || isDeclaration(walkUpParenthesizedExpressions(objectLiteral).parent)) {
|
|
131939
|
+
return alreadyReported;
|
|
131940
|
+
}
|
|
131941
|
+
return syntacticResult(inferExpressionType(
|
|
131942
|
+
objectLiteral,
|
|
131943
|
+
context,
|
|
131944
|
+
/*reportFallback*/
|
|
131945
|
+
false,
|
|
131946
|
+
requiresAddingUndefined
|
|
131947
|
+
));
|
|
131948
|
+
}
|
|
131949
|
+
const oldNoInferenceFallback = context.noInferenceFallback;
|
|
131950
|
+
context.noInferenceFallback = true;
|
|
131951
|
+
const properties = [];
|
|
131952
|
+
const oldFlags = context.flags;
|
|
131953
|
+
context.flags |= 4194304 /* InObjectTypeLiteral */;
|
|
131750
131954
|
for (const prop of objectLiteral.properties) {
|
|
131751
131955
|
Debug.assert(!isShorthandPropertyAssignment(prop) && !isSpreadAssignment(prop));
|
|
131752
131956
|
const name = prop.name;
|
|
131957
|
+
let newProp;
|
|
131753
131958
|
switch (prop.kind) {
|
|
131754
131959
|
case 174 /* MethodDeclaration */:
|
|
131755
|
-
|
|
131960
|
+
newProp = withNewScope(context, prop, () => typeFromObjectLiteralMethod(prop, name, context, isConstContext));
|
|
131756
131961
|
break;
|
|
131757
131962
|
case 303 /* PropertyAssignment */:
|
|
131758
|
-
|
|
131963
|
+
newProp = typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext);
|
|
131759
131964
|
break;
|
|
131760
131965
|
case 178 /* SetAccessor */:
|
|
131761
131966
|
case 177 /* GetAccessor */:
|
|
131762
|
-
|
|
131967
|
+
newProp = typeFromObjectLiteralAccessor(prop, name, context);
|
|
131763
131968
|
break;
|
|
131764
131969
|
}
|
|
131970
|
+
if (newProp) {
|
|
131971
|
+
setCommentRange(newProp, prop);
|
|
131972
|
+
properties.push(newProp);
|
|
131973
|
+
}
|
|
131765
131974
|
}
|
|
131766
|
-
|
|
131975
|
+
context.flags = oldFlags;
|
|
131976
|
+
const typeNode = factory.createTypeLiteralNode(properties);
|
|
131977
|
+
if (!(context.flags & 1024 /* MultilineObjectLiterals */)) {
|
|
131978
|
+
setEmitFlags(typeNode, 1 /* SingleLine */);
|
|
131979
|
+
}
|
|
131980
|
+
context.noInferenceFallback = oldNoInferenceFallback;
|
|
131981
|
+
return notImplemented2;
|
|
131767
131982
|
}
|
|
131768
131983
|
function typeFromObjectLiteralPropertyAssignment(prop, name, context, isConstContext) {
|
|
131769
|
-
|
|
131984
|
+
const modifiers = isConstContext ? [factory.createModifier(148 /* ReadonlyKeyword */)] : [];
|
|
131985
|
+
const expressionResult = typeFromExpression(prop.initializer, context, isConstContext);
|
|
131986
|
+
const typeNode = expressionResult.type !== void 0 ? expressionResult.type : inferTypeOfDeclaration(
|
|
131987
|
+
prop,
|
|
131988
|
+
/*symbol*/
|
|
131989
|
+
void 0,
|
|
131990
|
+
context,
|
|
131991
|
+
expressionResult.reportFallback
|
|
131992
|
+
);
|
|
131993
|
+
return factory.createPropertySignature(
|
|
131994
|
+
modifiers,
|
|
131995
|
+
reuseNode(context, name),
|
|
131996
|
+
/*questionToken*/
|
|
131997
|
+
void 0,
|
|
131998
|
+
typeNode
|
|
131999
|
+
);
|
|
131770
132000
|
}
|
|
131771
132001
|
function ensureParameter(p, context) {
|
|
131772
|
-
return
|
|
132002
|
+
return factory.updateParameterDeclaration(
|
|
132003
|
+
p,
|
|
132004
|
+
[],
|
|
132005
|
+
reuseNode(context, p.dotDotDotToken),
|
|
132006
|
+
resolver.serializeNameOfParameter(context, p),
|
|
132007
|
+
resolver.isOptionalParameter(p) ? factory.createToken(58 /* QuestionToken */) : void 0,
|
|
132008
|
+
typeFromParameter(
|
|
132009
|
+
p,
|
|
132010
|
+
/*symbol*/
|
|
132011
|
+
void 0,
|
|
132012
|
+
context
|
|
132013
|
+
),
|
|
132014
|
+
// Ignore private param props, since this type is going straight back into a param
|
|
132015
|
+
/*initializer*/
|
|
132016
|
+
void 0
|
|
132017
|
+
);
|
|
131773
132018
|
}
|
|
131774
|
-
function reuseTypeParameters(typeParameters) {
|
|
131775
|
-
return
|
|
131776
|
-
(tp) =>
|
|
131777
|
-
|
|
132019
|
+
function reuseTypeParameters(typeParameters, context) {
|
|
132020
|
+
return typeParameters == null ? void 0 : typeParameters.map(
|
|
132021
|
+
(tp) => {
|
|
132022
|
+
var _a;
|
|
132023
|
+
return factory.updateTypeParameterDeclaration(
|
|
132024
|
+
tp,
|
|
132025
|
+
(_a = tp.modifiers) == null ? void 0 : _a.map((m) => reuseNode(context, m)),
|
|
132026
|
+
reuseNode(context, tp.name),
|
|
132027
|
+
serializeExistingTypeNodeWithFallback(tp.constraint, context),
|
|
132028
|
+
serializeExistingTypeNodeWithFallback(tp.default, context)
|
|
132029
|
+
);
|
|
132030
|
+
}
|
|
132031
|
+
);
|
|
131778
132032
|
}
|
|
131779
|
-
function typeFromObjectLiteralMethod(method, name, context) {
|
|
131780
|
-
const returnType = createReturnFromSignature(
|
|
131781
|
-
|
|
131782
|
-
|
|
131783
|
-
|
|
132033
|
+
function typeFromObjectLiteralMethod(method, name, context, isConstContext) {
|
|
132034
|
+
const returnType = createReturnFromSignature(
|
|
132035
|
+
method,
|
|
132036
|
+
/*symbol*/
|
|
132037
|
+
void 0,
|
|
132038
|
+
context
|
|
132039
|
+
);
|
|
132040
|
+
const typeParameters = reuseTypeParameters(method.typeParameters, context);
|
|
132041
|
+
const parameters = method.parameters.map((p) => ensureParameter(p, context));
|
|
132042
|
+
if (isConstContext) {
|
|
132043
|
+
return factory.createPropertySignature(
|
|
132044
|
+
[factory.createModifier(148 /* ReadonlyKeyword */)],
|
|
132045
|
+
reuseNode(context, name),
|
|
132046
|
+
reuseNode(context, method.questionToken),
|
|
132047
|
+
factory.createFunctionTypeNode(
|
|
132048
|
+
typeParameters,
|
|
132049
|
+
parameters,
|
|
132050
|
+
returnType
|
|
132051
|
+
)
|
|
132052
|
+
);
|
|
132053
|
+
} else {
|
|
132054
|
+
if (isIdentifier(name) && name.escapedText === "new") {
|
|
132055
|
+
name = factory.createStringLiteral("new");
|
|
132056
|
+
}
|
|
132057
|
+
return factory.createMethodSignature(
|
|
132058
|
+
[],
|
|
132059
|
+
reuseNode(context, name),
|
|
132060
|
+
reuseNode(context, method.questionToken),
|
|
132061
|
+
typeParameters,
|
|
132062
|
+
parameters,
|
|
132063
|
+
returnType
|
|
132064
|
+
);
|
|
132065
|
+
}
|
|
131784
132066
|
}
|
|
131785
132067
|
function typeFromObjectLiteralAccessor(accessor, name, context) {
|
|
131786
132068
|
const allAccessors = resolver.getAllAccessorDeclarations(accessor);
|
|
131787
|
-
const getAccessorType = allAccessors.getAccessor &&
|
|
131788
|
-
const setAccessorType = allAccessors.setAccessor &&
|
|
132069
|
+
const getAccessorType = allAccessors.getAccessor && getTypeAnnotationFromAccessor(allAccessors.getAccessor);
|
|
132070
|
+
const setAccessorType = allAccessors.setAccessor && getTypeAnnotationFromAccessor(allAccessors.setAccessor);
|
|
131789
132071
|
if (getAccessorType !== void 0 && setAccessorType !== void 0) {
|
|
131790
|
-
|
|
131791
|
-
|
|
131792
|
-
|
|
131793
|
-
|
|
131794
|
-
|
|
131795
|
-
|
|
132072
|
+
return withNewScope(context, accessor, () => {
|
|
132073
|
+
const parameters = accessor.parameters.map((p) => ensureParameter(p, context));
|
|
132074
|
+
if (isGetAccessor(accessor)) {
|
|
132075
|
+
return factory.updateGetAccessorDeclaration(
|
|
132076
|
+
accessor,
|
|
132077
|
+
[],
|
|
132078
|
+
reuseNode(context, name),
|
|
132079
|
+
parameters,
|
|
132080
|
+
serializeExistingTypeNodeWithFallback(getAccessorType, context),
|
|
132081
|
+
/*body*/
|
|
132082
|
+
void 0
|
|
132083
|
+
);
|
|
132084
|
+
} else {
|
|
132085
|
+
return factory.updateSetAccessorDeclaration(
|
|
132086
|
+
accessor,
|
|
132087
|
+
[],
|
|
132088
|
+
reuseNode(context, name),
|
|
132089
|
+
parameters,
|
|
132090
|
+
/*body*/
|
|
132091
|
+
void 0
|
|
132092
|
+
);
|
|
132093
|
+
}
|
|
132094
|
+
});
|
|
131796
132095
|
} else if (allAccessors.firstAccessor === accessor) {
|
|
131797
|
-
const foundType = getAccessorType
|
|
131798
|
-
const propertyType = foundType
|
|
131799
|
-
|
|
132096
|
+
const foundType = getAccessorType ? withNewScope(context, allAccessors.getAccessor, () => serializeExistingTypeNodeWithFallback(getAccessorType, context)) : setAccessorType ? withNewScope(context, allAccessors.setAccessor, () => serializeExistingTypeNodeWithFallback(setAccessorType, context)) : void 0;
|
|
132097
|
+
const propertyType = foundType ?? inferAccessorType(
|
|
132098
|
+
accessor,
|
|
132099
|
+
allAccessors,
|
|
132100
|
+
context,
|
|
132101
|
+
/*symbol*/
|
|
132102
|
+
void 0
|
|
132103
|
+
);
|
|
132104
|
+
const propertySignature = factory.createPropertySignature(
|
|
132105
|
+
allAccessors.setAccessor === void 0 ? [factory.createModifier(148 /* ReadonlyKeyword */)] : [],
|
|
132106
|
+
reuseNode(context, name),
|
|
132107
|
+
/*questionToken*/
|
|
132108
|
+
void 0,
|
|
132109
|
+
propertyType
|
|
132110
|
+
);
|
|
132111
|
+
return propertySignature;
|
|
131800
132112
|
}
|
|
131801
|
-
return false;
|
|
131802
132113
|
}
|
|
131803
|
-
function
|
|
131804
|
-
|
|
132114
|
+
function createUndefinedTypeNode() {
|
|
132115
|
+
if (strictNullChecks) {
|
|
132116
|
+
return factory.createKeywordTypeNode(157 /* UndefinedKeyword */);
|
|
132117
|
+
} else {
|
|
132118
|
+
return factory.createKeywordTypeNode(133 /* AnyKeyword */);
|
|
132119
|
+
}
|
|
132120
|
+
}
|
|
132121
|
+
function typeFromPrimitiveLiteral(node, baseType, context, preserveLiterals, requiresAddingUndefined) {
|
|
132122
|
+
let result;
|
|
132123
|
+
if (preserveLiterals) {
|
|
132124
|
+
if (node.kind === 224 /* PrefixUnaryExpression */ && node.operator === 40 /* PlusToken */) {
|
|
132125
|
+
result = factory.createLiteralTypeNode(reuseNode(context, node.operand));
|
|
132126
|
+
}
|
|
132127
|
+
result = factory.createLiteralTypeNode(reuseNode(context, node));
|
|
132128
|
+
} else {
|
|
132129
|
+
result = factory.createKeywordTypeNode(baseType);
|
|
132130
|
+
}
|
|
132131
|
+
return syntacticResult(addUndefinedIfNeeded(result, requiresAddingUndefined, node, context));
|
|
132132
|
+
}
|
|
132133
|
+
function addUndefinedIfNeeded(node, addUndefined, owner, context) {
|
|
132134
|
+
const parentDeclaration = owner && walkUpParenthesizedExpressions(owner).parent;
|
|
132135
|
+
const optionalDeclaration = parentDeclaration && isDeclaration(parentDeclaration) && isOptionalDeclaration(parentDeclaration);
|
|
132136
|
+
if (!strictNullChecks || !(addUndefined || optionalDeclaration)) return node;
|
|
132137
|
+
if (!canAddUndefined(node)) {
|
|
132138
|
+
context.tracker.reportInferenceFallback(node);
|
|
132139
|
+
}
|
|
132140
|
+
if (isUnionTypeNode(node)) {
|
|
132141
|
+
return factory.createUnionTypeNode([...node.types, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
|
|
132142
|
+
}
|
|
132143
|
+
return factory.createUnionTypeNode([node, factory.createKeywordTypeNode(157 /* UndefinedKeyword */)]);
|
|
131805
132144
|
}
|
|
131806
132145
|
function canAddUndefined(node) {
|
|
131807
132146
|
if (!strictNullChecks) return true;
|
|
@@ -131816,24 +132155,28 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131816
132155
|
}
|
|
131817
132156
|
return false;
|
|
131818
132157
|
}
|
|
131819
|
-
function createReturnFromSignature(fn, context) {
|
|
131820
|
-
let returnType;
|
|
131821
|
-
const returnTypeNode = getEffectiveReturnTypeNode(fn);
|
|
132158
|
+
function createReturnFromSignature(fn, symbol, context, reportFallback = true) {
|
|
132159
|
+
let returnType = failed;
|
|
132160
|
+
const returnTypeNode = isJSDocConstructSignature(fn) ? getEffectiveTypeAnnotationNode(fn.parameters[0]) : getEffectiveReturnTypeNode(fn);
|
|
131822
132161
|
if (returnTypeNode) {
|
|
131823
|
-
returnType =
|
|
131824
|
-
}
|
|
131825
|
-
if (!returnType && isValueSignatureDeclaration(fn)) {
|
|
132162
|
+
returnType = syntacticResult(serializeTypeAnnotationOfDeclaration(returnTypeNode, context, fn, symbol));
|
|
132163
|
+
} else if (isValueSignatureDeclaration(fn)) {
|
|
131826
132164
|
returnType = typeFromSingleReturnExpression(fn, context);
|
|
131827
132165
|
}
|
|
131828
|
-
return returnType
|
|
132166
|
+
return returnType.type !== void 0 ? returnType.type : inferReturnTypeOfSignatureSignature(fn, context, reportFallback && returnType.reportFallback && !returnTypeNode);
|
|
131829
132167
|
}
|
|
131830
132168
|
function typeFromSingleReturnExpression(declaration, context) {
|
|
131831
132169
|
let candidateExpr;
|
|
131832
132170
|
if (declaration && !nodeIsMissing(declaration.body)) {
|
|
131833
|
-
|
|
132171
|
+
const flags = getFunctionFlags(declaration);
|
|
132172
|
+
if (flags & 3 /* AsyncGenerator */) return failed;
|
|
131834
132173
|
const body = declaration.body;
|
|
131835
132174
|
if (body && isBlock(body)) {
|
|
131836
132175
|
forEachReturnStatement(body, (s) => {
|
|
132176
|
+
if (s.parent !== body) {
|
|
132177
|
+
candidateExpr = void 0;
|
|
132178
|
+
return true;
|
|
132179
|
+
}
|
|
131837
132180
|
if (!candidateExpr) {
|
|
131838
132181
|
candidateExpr = s.expression;
|
|
131839
132182
|
} else {
|
|
@@ -131846,9 +132189,21 @@ function createSyntacticTypeNodeBuilder(options, resolver) {
|
|
|
131846
132189
|
}
|
|
131847
132190
|
}
|
|
131848
132191
|
if (candidateExpr) {
|
|
131849
|
-
|
|
132192
|
+
if (isContextuallyTyped(candidateExpr)) {
|
|
132193
|
+
const type = isJSDocTypeAssertion(candidateExpr) ? getJSDocTypeAssertionType(candidateExpr) : isAsExpression(candidateExpr) || isTypeAssertionExpression(candidateExpr) ? candidateExpr.type : void 0;
|
|
132194
|
+
if (type && !isConstTypeReference(type)) {
|
|
132195
|
+
return syntacticResult(serializeExistingTypeNode(type, context));
|
|
132196
|
+
}
|
|
132197
|
+
} else {
|
|
132198
|
+
return typeFromExpression(candidateExpr, context);
|
|
132199
|
+
}
|
|
131850
132200
|
}
|
|
131851
|
-
return
|
|
132201
|
+
return failed;
|
|
132202
|
+
}
|
|
132203
|
+
function isContextuallyTyped(node) {
|
|
132204
|
+
return findAncestor(node.parent, (n) => {
|
|
132205
|
+
return isCallExpression(n) || !isFunctionLikeDeclaration(n) && !!getEffectiveTypeAnnotationNode(n) || isJsxElement(n) || isJsxExpression(n);
|
|
132206
|
+
});
|
|
131852
132207
|
}
|
|
131853
132208
|
}
|
|
131854
132209
|
|