typescript 4.6.0-dev.20220104 → 4.6.0-dev.20220108
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/lib.es2022.error.d.ts +50 -3
- package/lib/tsc.js +112 -80
- package/lib/tsserver.js +376 -228
- package/lib/tsserverlibrary.d.ts +5 -3
- package/lib/tsserverlibrary.js +347 -227
- package/lib/typescript.d.ts +4 -3
- package/lib/typescript.js +343 -226
- package/lib/typescriptServices.d.ts +4 -3
- package/lib/typescriptServices.js +343 -226
- package/lib/typingsInstaller.js +273 -190
- package/package.json +1 -1
package/lib/typingsInstaller.js
CHANGED
|
@@ -89,7 +89,7 @@ var ts;
|
|
|
89
89
|
// The following is baselined as a literal template type without intervention
|
|
90
90
|
/** The version of the TypeScript compiler release */
|
|
91
91
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
92
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
92
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20220108";
|
|
93
93
|
/* @internal */
|
|
94
94
|
var Comparison;
|
|
95
95
|
(function (Comparison) {
|
|
@@ -14445,7 +14445,8 @@ var ts;
|
|
|
14445
14445
|
Float64Array: ["at"],
|
|
14446
14446
|
BigInt64Array: ["at"],
|
|
14447
14447
|
BigUint64Array: ["at"],
|
|
14448
|
-
ObjectConstructor: ["hasOwn"]
|
|
14448
|
+
ObjectConstructor: ["hasOwn"],
|
|
14449
|
+
Error: ["cause"]
|
|
14449
14450
|
}
|
|
14450
14451
|
};
|
|
14451
14452
|
}
|
|
@@ -20756,9 +20757,40 @@ var ts;
|
|
|
20756
20757
|
}
|
|
20757
20758
|
ts.isFunctionExpressionOrArrowFunction = isFunctionExpressionOrArrowFunction;
|
|
20758
20759
|
function escapeSnippetText(text) {
|
|
20759
|
-
return text.replace(/\$/gm, "\\$");
|
|
20760
|
+
return text.replace(/\$/gm, function () { return "\\$"; });
|
|
20760
20761
|
}
|
|
20761
20762
|
ts.escapeSnippetText = escapeSnippetText;
|
|
20763
|
+
function isNumericLiteralName(name) {
|
|
20764
|
+
// The intent of numeric names is that
|
|
20765
|
+
// - they are names with text in a numeric form, and that
|
|
20766
|
+
// - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
|
|
20767
|
+
// acquired by applying the abstract 'ToNumber' operation on the name's text.
|
|
20768
|
+
//
|
|
20769
|
+
// The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
|
|
20770
|
+
// In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
|
|
20771
|
+
//
|
|
20772
|
+
// Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
|
|
20773
|
+
// according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
|
|
20774
|
+
// Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
|
|
20775
|
+
// because their 'ToString' representation is not equal to their original text.
|
|
20776
|
+
// This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
|
|
20777
|
+
//
|
|
20778
|
+
// Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
|
|
20779
|
+
// The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
|
|
20780
|
+
// Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
|
|
20781
|
+
//
|
|
20782
|
+
// Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
|
|
20783
|
+
// This is desired behavior, because when indexing with them as numeric entities, you are indexing
|
|
20784
|
+
// with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
|
|
20785
|
+
return (+name).toString() === name;
|
|
20786
|
+
}
|
|
20787
|
+
ts.isNumericLiteralName = isNumericLiteralName;
|
|
20788
|
+
function createPropertyNameNodeForIdentifierOrLiteral(name, target, singleQuote, stringNamed) {
|
|
20789
|
+
return ts.isIdentifierText(name, target) ? ts.factory.createIdentifier(name) :
|
|
20790
|
+
!stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
|
|
20791
|
+
ts.factory.createStringLiteral(name, !!singleQuote);
|
|
20792
|
+
}
|
|
20793
|
+
ts.createPropertyNameNodeForIdentifierOrLiteral = createPropertyNameNodeForIdentifierOrLiteral;
|
|
20762
20794
|
function isThisTypeParameter(type) {
|
|
20763
20795
|
return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
|
|
20764
20796
|
}
|
|
@@ -22231,7 +22263,7 @@ var ts;
|
|
|
22231
22263
|
result.push(createModifier(144 /* ReadonlyKeyword */));
|
|
22232
22264
|
if (flags & 256 /* Async */)
|
|
22233
22265
|
result.push(createModifier(131 /* AsyncKeyword */));
|
|
22234
|
-
return result;
|
|
22266
|
+
return result.length ? result : undefined;
|
|
22235
22267
|
}
|
|
22236
22268
|
//
|
|
22237
22269
|
// Names
|
|
@@ -26188,32 +26220,36 @@ var ts;
|
|
|
26188
26220
|
}
|
|
26189
26221
|
function updateModifiers(node, modifiers) {
|
|
26190
26222
|
var _a;
|
|
26223
|
+
var modifierArray;
|
|
26191
26224
|
if (typeof modifiers === "number") {
|
|
26192
|
-
|
|
26193
|
-
}
|
|
26194
|
-
|
|
26195
|
-
|
|
26196
|
-
|
|
26197
|
-
|
|
26198
|
-
|
|
26199
|
-
|
|
26200
|
-
|
|
26201
|
-
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
|
|
26205
|
-
|
|
26206
|
-
|
|
26207
|
-
|
|
26208
|
-
|
|
26209
|
-
|
|
26210
|
-
|
|
26211
|
-
|
|
26212
|
-
|
|
26213
|
-
|
|
26214
|
-
|
|
26215
|
-
|
|
26216
|
-
|
|
26225
|
+
modifierArray = createModifiersFromModifierFlags(modifiers);
|
|
26226
|
+
}
|
|
26227
|
+
else {
|
|
26228
|
+
modifierArray = modifiers;
|
|
26229
|
+
}
|
|
26230
|
+
return ts.isParameter(node) ? updateParameterDeclaration(node, node.decorators, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) :
|
|
26231
|
+
ts.isPropertySignature(node) ? updatePropertySignature(node, modifierArray, node.name, node.questionToken, node.type) :
|
|
26232
|
+
ts.isPropertyDeclaration(node) ? updatePropertyDeclaration(node, node.decorators, modifierArray, node.name, (_a = node.questionToken) !== null && _a !== void 0 ? _a : node.exclamationToken, node.type, node.initializer) :
|
|
26233
|
+
ts.isMethodSignature(node) ? updateMethodSignature(node, modifierArray, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) :
|
|
26234
|
+
ts.isMethodDeclaration(node) ? updateMethodDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26235
|
+
ts.isConstructorDeclaration(node) ? updateConstructorDeclaration(node, node.decorators, modifierArray, node.parameters, node.body) :
|
|
26236
|
+
ts.isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.type, node.body) :
|
|
26237
|
+
ts.isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.body) :
|
|
26238
|
+
ts.isIndexSignatureDeclaration(node) ? updateIndexSignature(node, node.decorators, modifierArray, node.parameters, node.type) :
|
|
26239
|
+
ts.isFunctionExpression(node) ? updateFunctionExpression(node, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26240
|
+
ts.isArrowFunction(node) ? updateArrowFunction(node, modifierArray, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) :
|
|
26241
|
+
ts.isClassExpression(node) ? updateClassExpression(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26242
|
+
ts.isVariableStatement(node) ? updateVariableStatement(node, modifierArray, node.declarationList) :
|
|
26243
|
+
ts.isFunctionDeclaration(node) ? updateFunctionDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
|
|
26244
|
+
ts.isClassDeclaration(node) ? updateClassDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26245
|
+
ts.isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
|
|
26246
|
+
ts.isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.type) :
|
|
26247
|
+
ts.isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifierArray, node.name, node.members) :
|
|
26248
|
+
ts.isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifierArray, node.name, node.body) :
|
|
26249
|
+
ts.isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.name, node.moduleReference) :
|
|
26250
|
+
ts.isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifierArray, node.importClause, node.moduleSpecifier, node.assertClause) :
|
|
26251
|
+
ts.isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifierArray, node.expression) :
|
|
26252
|
+
ts.isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
|
|
26217
26253
|
ts.Debug.assertNever(node);
|
|
26218
26254
|
}
|
|
26219
26255
|
function asNodeArray(array) {
|
|
@@ -46827,6 +46863,7 @@ var ts;
|
|
|
46827
46863
|
var location = ts.getParseTreeNode(locationIn);
|
|
46828
46864
|
return location ? getTypeOfSymbolAtLocation(symbol, location) : errorType;
|
|
46829
46865
|
},
|
|
46866
|
+
getTypeOfSymbol: getTypeOfSymbol,
|
|
46830
46867
|
getSymbolsOfParameterPropertyDeclaration: function (parameterIn, parameterName) {
|
|
46831
46868
|
var parameter = ts.getParseTreeNode(parameterIn, ts.isParameter);
|
|
46832
46869
|
if (parameter === undefined)
|
|
@@ -52182,7 +52219,7 @@ var ts;
|
|
|
52182
52219
|
}
|
|
52183
52220
|
var rawName = ts.unescapeLeadingUnderscores(symbol.escapedName);
|
|
52184
52221
|
var stringNamed = !!ts.length(symbol.declarations) && ts.every(symbol.declarations, isStringNamed);
|
|
52185
|
-
return createPropertyNameNodeForIdentifierOrLiteral(rawName,
|
|
52222
|
+
return ts.createPropertyNameNodeForIdentifierOrLiteral(rawName, ts.getEmitScriptTarget(compilerOptions), singleQuote, stringNamed);
|
|
52186
52223
|
}
|
|
52187
52224
|
// See getNameForSymbolFromNameType for a stringy equivalent
|
|
52188
52225
|
function getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote) {
|
|
@@ -52190,24 +52227,19 @@ var ts;
|
|
|
52190
52227
|
if (nameType) {
|
|
52191
52228
|
if (nameType.flags & 384 /* StringOrNumberLiteral */) {
|
|
52192
52229
|
var name = "" + nameType.value;
|
|
52193
|
-
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
|
|
52230
|
+
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
|
|
52194
52231
|
return ts.factory.createStringLiteral(name, !!singleQuote);
|
|
52195
52232
|
}
|
|
52196
|
-
if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
52233
|
+
if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
52197
52234
|
return ts.factory.createComputedPropertyName(ts.factory.createNumericLiteral(+name));
|
|
52198
52235
|
}
|
|
52199
|
-
return createPropertyNameNodeForIdentifierOrLiteral(name);
|
|
52236
|
+
return ts.createPropertyNameNodeForIdentifierOrLiteral(name, ts.getEmitScriptTarget(compilerOptions));
|
|
52200
52237
|
}
|
|
52201
52238
|
if (nameType.flags & 8192 /* UniqueESSymbol */) {
|
|
52202
52239
|
return ts.factory.createComputedPropertyName(symbolToExpression(nameType.symbol, context, 111551 /* Value */));
|
|
52203
52240
|
}
|
|
52204
52241
|
}
|
|
52205
52242
|
}
|
|
52206
|
-
function createPropertyNameNodeForIdentifierOrLiteral(name, stringNamed, singleQuote) {
|
|
52207
|
-
return ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) ? ts.factory.createIdentifier(name) :
|
|
52208
|
-
!stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
|
|
52209
|
-
ts.factory.createStringLiteral(name, !!singleQuote);
|
|
52210
|
-
}
|
|
52211
52243
|
function cloneNodeBuilderContext(context) {
|
|
52212
52244
|
var initial = __assign({}, context);
|
|
52213
52245
|
// Make type parameters created within this context not consume the name outside this context
|
|
@@ -53723,10 +53755,10 @@ var ts;
|
|
|
53723
53755
|
if (nameType) {
|
|
53724
53756
|
if (nameType.flags & 384 /* StringOrNumberLiteral */) {
|
|
53725
53757
|
var name = "" + nameType.value;
|
|
53726
|
-
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
|
|
53758
|
+
if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
|
|
53727
53759
|
return "\"" + ts.escapeString(name, 34 /* doubleQuote */) + "\"";
|
|
53728
53760
|
}
|
|
53729
|
-
if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
53761
|
+
if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
|
|
53730
53762
|
return "[" + name + "]";
|
|
53731
53763
|
}
|
|
53732
53764
|
return name;
|
|
@@ -57769,7 +57801,7 @@ var ts;
|
|
|
57769
57801
|
// signature applies to types assignable to 'number' and numeric string literal types.
|
|
57770
57802
|
return isTypeAssignableTo(source, target) ||
|
|
57771
57803
|
target === stringType && isTypeAssignableTo(source, numberType) ||
|
|
57772
|
-
target === numberType && !!(source.flags & 128 /* StringLiteral */) && isNumericLiteralName(source.value);
|
|
57804
|
+
target === numberType && !!(source.flags & 128 /* StringLiteral */) && ts.isNumericLiteralName(source.value);
|
|
57773
57805
|
}
|
|
57774
57806
|
function getIndexInfosOfStructuredType(type) {
|
|
57775
57807
|
if (type.flags & 3670016 /* StructuredType */) {
|
|
@@ -60335,7 +60367,7 @@ var ts;
|
|
|
60335
60367
|
getFlowTypeOfReference(accessExpression, propType) :
|
|
60336
60368
|
propType;
|
|
60337
60369
|
}
|
|
60338
|
-
if (everyType(objectType, isTupleType) && isNumericLiteralName(propName) && +propName >= 0) {
|
|
60370
|
+
if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
|
|
60339
60371
|
if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
|
|
60340
60372
|
var indexNode = getIndexNodeForAccessExpression(accessNode);
|
|
60341
60373
|
if (isTupleType(objectType)) {
|
|
@@ -60620,7 +60652,7 @@ var ts;
|
|
|
60620
60652
|
return everyType(indexType, function (t) {
|
|
60621
60653
|
if (t.flags & 384 /* StringOrNumberLiteral */) {
|
|
60622
60654
|
var propName = getPropertyNameFromType(t);
|
|
60623
|
-
if (isNumericLiteralName(propName)) {
|
|
60655
|
+
if (ts.isNumericLiteralName(propName)) {
|
|
60624
60656
|
var index = +propName;
|
|
60625
60657
|
return index >= 0 && index < limit;
|
|
60626
60658
|
}
|
|
@@ -64162,7 +64194,7 @@ var ts;
|
|
|
64162
64194
|
else {
|
|
64163
64195
|
// conditionals aren't related to one another via distributive constraint as it is much too inaccurate and allows way
|
|
64164
64196
|
// more assignments than are desirable (since it maps the source check type to its constraint, it loses information)
|
|
64165
|
-
var distributiveConstraint = getConstraintOfDistributiveConditionalType(source);
|
|
64197
|
+
var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
|
|
64166
64198
|
if (distributiveConstraint) {
|
|
64167
64199
|
if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
|
|
64168
64200
|
resetErrorInfo(saveErrorInfo);
|
|
@@ -64708,7 +64740,7 @@ var ts;
|
|
|
64708
64740
|
for (var _b = 0, _c = excludeProperties(properties, excludedProperties); _b < _c.length; _b++) {
|
|
64709
64741
|
var targetProp = _c[_b];
|
|
64710
64742
|
var name = targetProp.escapedName;
|
|
64711
|
-
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
|
|
64743
|
+
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || ts.isNumericLiteralName(name) || name === "length")) {
|
|
64712
64744
|
var sourceProp = getPropertyOfType(source, name);
|
|
64713
64745
|
if (sourceProp && sourceProp !== targetProp) {
|
|
64714
64746
|
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getNonMissingTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
|
|
@@ -64781,7 +64813,8 @@ var ts;
|
|
|
64781
64813
|
var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
|
|
64782
64814
|
var sourceObjectFlags = ts.getObjectFlags(source);
|
|
64783
64815
|
var targetObjectFlags = ts.getObjectFlags(target);
|
|
64784
|
-
if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol
|
|
64816
|
+
if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol ||
|
|
64817
|
+
sourceObjectFlags & 4 /* Reference */ && targetObjectFlags & 4 /* Reference */ && source.target === target.target) {
|
|
64785
64818
|
// We have instantiations of the same anonymous type (which typically will be the type of a
|
|
64786
64819
|
// method). Simply do a pairwise comparison of the signatures in the two signature lists instead
|
|
64787
64820
|
// of the much more expensive N * M comparison matrix we explore below. We erase type parameters
|
|
@@ -65816,9 +65849,12 @@ var ts;
|
|
|
65816
65849
|
* with no call or construct signatures.
|
|
65817
65850
|
*/
|
|
65818
65851
|
function isObjectTypeWithInferableIndex(type) {
|
|
65819
|
-
return type.flags & 2097152 /* Intersection */
|
|
65820
|
-
|
|
65821
|
-
|
|
65852
|
+
return type.flags & 2097152 /* Intersection */
|
|
65853
|
+
? ts.every(type.types, isObjectTypeWithInferableIndex)
|
|
65854
|
+
: !!(type.symbol
|
|
65855
|
+
&& (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0
|
|
65856
|
+
&& !(type.symbol.flags & 32 /* Class */)
|
|
65857
|
+
&& !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
|
|
65822
65858
|
}
|
|
65823
65859
|
function createSymbolWithType(source, type) {
|
|
65824
65860
|
var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
|
|
@@ -67426,7 +67462,8 @@ var ts;
|
|
|
67426
67462
|
return access.kind === 205 /* PropertyAccessExpression */ ? access.name.escapedText :
|
|
67427
67463
|
access.kind === 206 /* ElementAccessExpression */ && ts.isStringOrNumericLiteralLike(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
|
|
67428
67464
|
access.kind === 202 /* BindingElement */ && (propertyName = getDestructuringPropertyName(access)) ? ts.escapeLeadingUnderscores(propertyName) :
|
|
67429
|
-
|
|
67465
|
+
access.kind === 163 /* Parameter */ ? ("" + access.parent.parameters.indexOf(access)) :
|
|
67466
|
+
undefined;
|
|
67430
67467
|
}
|
|
67431
67468
|
function containsMatchingReference(source, target) {
|
|
67432
67469
|
while (ts.isAccessExpression(source)) {
|
|
@@ -68766,13 +68803,14 @@ var ts;
|
|
|
68766
68803
|
return result;
|
|
68767
68804
|
}
|
|
68768
68805
|
function getCandidateDiscriminantPropertyAccess(expr) {
|
|
68769
|
-
if (ts.isBindingPattern(reference)) {
|
|
68770
|
-
// When the reference is a binding pattern, we are narrowing a pesudo-reference in
|
|
68771
|
-
// An identifier for a destructuring variable declared in the same binding pattern
|
|
68806
|
+
if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
|
|
68807
|
+
// When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
|
|
68808
|
+
// getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
|
|
68809
|
+
// parameter declared in the same parameter list is a candidate.
|
|
68772
68810
|
if (ts.isIdentifier(expr)) {
|
|
68773
68811
|
var symbol = getResolvedSymbol(expr);
|
|
68774
68812
|
var declaration = symbol.valueDeclaration;
|
|
68775
|
-
if (declaration && ts.isBindingElement(declaration) &&
|
|
68813
|
+
if (declaration && (ts.isBindingElement(declaration) || ts.isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
68776
68814
|
return declaration;
|
|
68777
68815
|
}
|
|
68778
68816
|
}
|
|
@@ -69574,42 +69612,78 @@ var ts;
|
|
|
69574
69612
|
}
|
|
69575
69613
|
}
|
|
69576
69614
|
function getNarrowedTypeOfSymbol(symbol, location) {
|
|
69577
|
-
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69578
|
-
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69579
|
-
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69580
|
-
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69581
|
-
// other binding elements from the same destructuring. Consider:
|
|
69582
|
-
//
|
|
69583
|
-
// type Action =
|
|
69584
|
-
// | { kind: 'A', payload: number }
|
|
69585
|
-
// | { kind: 'B', payload: string };
|
|
69586
|
-
//
|
|
69587
|
-
// function f1({ kind, payload }: Action) {
|
|
69588
|
-
// if (kind === 'A') {
|
|
69589
|
-
// payload.toFixed();
|
|
69590
|
-
// }
|
|
69591
|
-
// if (kind === 'B') {
|
|
69592
|
-
// payload.toUpperCase();
|
|
69593
|
-
// }
|
|
69594
|
-
// }
|
|
69595
|
-
//
|
|
69596
|
-
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69597
|
-
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69598
|
-
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69599
|
-
// destructuring from the narrowed parent type.
|
|
69600
69615
|
var declaration = symbol.valueDeclaration;
|
|
69601
|
-
if (declaration
|
|
69602
|
-
|
|
69603
|
-
|
|
69604
|
-
|
|
69605
|
-
|
|
69606
|
-
|
|
69607
|
-
|
|
69608
|
-
|
|
69609
|
-
|
|
69610
|
-
|
|
69611
|
-
|
|
69612
|
-
|
|
69616
|
+
if (declaration) {
|
|
69617
|
+
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
|
|
69618
|
+
// parameter (a parameter for which there are no assignments in the function body), and if the parent type
|
|
69619
|
+
// for the destructuring is a union type, one or more of the binding elements may represent discriminant
|
|
69620
|
+
// properties, and we want the effects of conditional checks on such discriminants to affect the types of
|
|
69621
|
+
// other binding elements from the same destructuring. Consider:
|
|
69622
|
+
//
|
|
69623
|
+
// type Action =
|
|
69624
|
+
// | { kind: 'A', payload: number }
|
|
69625
|
+
// | { kind: 'B', payload: string };
|
|
69626
|
+
//
|
|
69627
|
+
// function f({ kind, payload }: Action) {
|
|
69628
|
+
// if (kind === 'A') {
|
|
69629
|
+
// payload.toFixed();
|
|
69630
|
+
// }
|
|
69631
|
+
// if (kind === 'B') {
|
|
69632
|
+
// payload.toUpperCase();
|
|
69633
|
+
// }
|
|
69634
|
+
// }
|
|
69635
|
+
//
|
|
69636
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69637
|
+
// the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
|
|
69638
|
+
// as if it occurred in the specified location. We then recompute the narrowed binding element type by
|
|
69639
|
+
// destructuring from the narrowed parent type.
|
|
69640
|
+
if (ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
|
|
69641
|
+
var parent = declaration.parent.parent;
|
|
69642
|
+
if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
|
|
69643
|
+
var links = getNodeLinks(location);
|
|
69644
|
+
if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
|
|
69645
|
+
links.flags |= 268435456 /* InCheckIdentifier */;
|
|
69646
|
+
var parentType = getTypeForBindingElementParent(parent);
|
|
69647
|
+
links.flags &= ~268435456 /* InCheckIdentifier */;
|
|
69648
|
+
if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
|
|
69649
|
+
var pattern = declaration.parent;
|
|
69650
|
+
var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
|
|
69651
|
+
return getBindingElementTypeFromParentType(declaration, narrowedType);
|
|
69652
|
+
}
|
|
69653
|
+
}
|
|
69654
|
+
}
|
|
69655
|
+
}
|
|
69656
|
+
// If we have a const-like parameter with no type annotation or initializer, and if the parameter is contextually
|
|
69657
|
+
// typed by a signature with a single rest parameter of a union of tuple types, one or more of the parameters may
|
|
69658
|
+
// represent discriminant tuple elements, and we want the effects of conditional checks on such discriminants to
|
|
69659
|
+
// affect the types of other parameters in the same parameter list. Consider:
|
|
69660
|
+
//
|
|
69661
|
+
// type Action = [kind: 'A', payload: number] | [kind: 'B', payload: string];
|
|
69662
|
+
//
|
|
69663
|
+
// const f: (...args: Action) => void = (kind, payload) => {
|
|
69664
|
+
// if (kind === 'A') {
|
|
69665
|
+
// payload.toFixed();
|
|
69666
|
+
// }
|
|
69667
|
+
// if (kind === 'B') {
|
|
69668
|
+
// payload.toUpperCase();
|
|
69669
|
+
// }
|
|
69670
|
+
// }
|
|
69671
|
+
//
|
|
69672
|
+
// Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
|
|
69673
|
+
// the arrow function AST node for '(kind, payload) => ...' as a pseudo-reference and narrow this reference as
|
|
69674
|
+
// if it occurred in the specified location. We then recompute the narrowed parameter type by indexing into the
|
|
69675
|
+
// narrowed tuple type.
|
|
69676
|
+
if (ts.isParameter(declaration) && !declaration.type && !declaration.initializer && !declaration.dotDotDotToken) {
|
|
69677
|
+
var func = declaration.parent;
|
|
69678
|
+
if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
|
|
69679
|
+
var contextualSignature = getContextualSignature(func);
|
|
69680
|
+
if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
|
|
69681
|
+
var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
|
|
69682
|
+
if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
|
|
69683
|
+
var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
|
|
69684
|
+
var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
|
|
69685
|
+
return getIndexedAccessType(narrowedType, getNumberLiteralType(index));
|
|
69686
|
+
}
|
|
69613
69687
|
}
|
|
69614
69688
|
}
|
|
69615
69689
|
}
|
|
@@ -70750,7 +70824,7 @@ var ts;
|
|
|
70750
70824
|
}
|
|
70751
70825
|
if (isTupleType(t)) {
|
|
70752
70826
|
var restType = getRestTypeOfTupleType(t);
|
|
70753
|
-
if (restType && isNumericLiteralName(name) && +name >= 0) {
|
|
70827
|
+
if (restType && ts.isNumericLiteralName(name) && +name >= 0) {
|
|
70754
70828
|
return restType;
|
|
70755
70829
|
}
|
|
70756
70830
|
}
|
|
@@ -71391,10 +71465,10 @@ var ts;
|
|
|
71391
71465
|
case 161 /* ComputedPropertyName */:
|
|
71392
71466
|
return isNumericComputedName(name);
|
|
71393
71467
|
case 79 /* Identifier */:
|
|
71394
|
-
return isNumericLiteralName(name.escapedText);
|
|
71468
|
+
return ts.isNumericLiteralName(name.escapedText);
|
|
71395
71469
|
case 8 /* NumericLiteral */:
|
|
71396
71470
|
case 10 /* StringLiteral */:
|
|
71397
|
-
return isNumericLiteralName(name.text);
|
|
71471
|
+
return ts.isNumericLiteralName(name.text);
|
|
71398
71472
|
default:
|
|
71399
71473
|
return false;
|
|
71400
71474
|
}
|
|
@@ -71404,30 +71478,6 @@ var ts;
|
|
|
71404
71478
|
// but this behavior is consistent with checkIndexedAccess
|
|
71405
71479
|
return isTypeAssignableToKind(checkComputedPropertyName(name), 296 /* NumberLike */);
|
|
71406
71480
|
}
|
|
71407
|
-
function isNumericLiteralName(name) {
|
|
71408
|
-
// The intent of numeric names is that
|
|
71409
|
-
// - they are names with text in a numeric form, and that
|
|
71410
|
-
// - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
|
|
71411
|
-
// acquired by applying the abstract 'ToNumber' operation on the name's text.
|
|
71412
|
-
//
|
|
71413
|
-
// The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
|
|
71414
|
-
// In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
|
|
71415
|
-
//
|
|
71416
|
-
// Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
|
|
71417
|
-
// according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
|
|
71418
|
-
// Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
|
|
71419
|
-
// because their 'ToString' representation is not equal to their original text.
|
|
71420
|
-
// This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
|
|
71421
|
-
//
|
|
71422
|
-
// Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
|
|
71423
|
-
// The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
|
|
71424
|
-
// Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
|
|
71425
|
-
//
|
|
71426
|
-
// Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
|
|
71427
|
-
// This is desired behavior, because when indexing with them as numeric entities, you are indexing
|
|
71428
|
-
// with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
|
|
71429
|
-
return (+name).toString() === name;
|
|
71430
|
-
}
|
|
71431
71481
|
function checkComputedPropertyName(node) {
|
|
71432
71482
|
var links = getNodeLinks(node.expression);
|
|
71433
71483
|
if (!links.resolvedType) {
|
|
@@ -71463,7 +71513,7 @@ var ts;
|
|
|
71463
71513
|
function isSymbolWithNumericName(symbol) {
|
|
71464
71514
|
var _a;
|
|
71465
71515
|
var firstDecl = (_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a[0];
|
|
71466
|
-
return isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
|
|
71516
|
+
return ts.isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
|
|
71467
71517
|
}
|
|
71468
71518
|
function isSymbolWithSymbolName(symbol) {
|
|
71469
71519
|
var _a;
|
|
@@ -82401,7 +82451,7 @@ var ts;
|
|
|
82401
82451
|
}
|
|
82402
82452
|
else {
|
|
82403
82453
|
var text = ts.getTextOfPropertyName(member.name);
|
|
82404
|
-
if (isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
|
|
82454
|
+
if (ts.isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
|
|
82405
82455
|
error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
|
82406
82456
|
}
|
|
82407
82457
|
}
|
|
@@ -109007,7 +109057,7 @@ var ts;
|
|
|
109007
109057
|
emitPlaceholder(hint, node, snippet);
|
|
109008
109058
|
break;
|
|
109009
109059
|
case 0 /* TabStop */:
|
|
109010
|
-
emitTabStop(snippet);
|
|
109060
|
+
emitTabStop(hint, node, snippet);
|
|
109011
109061
|
break;
|
|
109012
109062
|
}
|
|
109013
109063
|
}
|
|
@@ -109017,7 +109067,10 @@ var ts;
|
|
|
109017
109067
|
nonEscapingWrite("}"); // `}`
|
|
109018
109068
|
// `${2:...}`
|
|
109019
109069
|
}
|
|
109020
|
-
function emitTabStop(snippet) {
|
|
109070
|
+
function emitTabStop(hint, node, snippet) {
|
|
109071
|
+
// A tab stop should only be attached to an empty node, i.e. a node that doesn't emit any text.
|
|
109072
|
+
ts.Debug.assert(node.kind === 235 /* EmptyStatement */, "A tab stop cannot be attached to a node of kind " + ts.Debug.formatSyntaxKind(node.kind) + ".");
|
|
109073
|
+
ts.Debug.assert(hint !== 5 /* EmbeddedStatement */, "A tab stop cannot be attached to an embedded statement.");
|
|
109021
109074
|
nonEscapingWrite("$" + snippet.order);
|
|
109022
109075
|
}
|
|
109023
109076
|
//
|
|
@@ -119863,7 +119916,7 @@ var ts;
|
|
|
119863
119916
|
}
|
|
119864
119917
|
ts.getLocaleTimeString = getLocaleTimeString;
|
|
119865
119918
|
/**
|
|
119866
|
-
* Create a function that reports watch status by writing to the system and handles the
|
|
119919
|
+
* Create a function that reports watch status by writing to the system and handles the formatting of the diagnostic
|
|
119867
119920
|
*/
|
|
119868
119921
|
function createWatchStatusReporter(system, pretty) {
|
|
119869
119922
|
return pretty ?
|
|
@@ -119924,7 +119977,7 @@ var ts;
|
|
|
119924
119977
|
ts.Diagnostics.Found_0_errors_Watching_for_file_changes;
|
|
119925
119978
|
}
|
|
119926
119979
|
ts.getWatchErrorSummaryDiagnosticMessage = getWatchErrorSummaryDiagnosticMessage;
|
|
119927
|
-
function getErrorSummaryText(errorCount, filesInError, newLine) {
|
|
119980
|
+
function getErrorSummaryText(errorCount, filesInError, newLine, host) {
|
|
119928
119981
|
if (errorCount === 0)
|
|
119929
119982
|
return "";
|
|
119930
119983
|
var nonNilFiles = filesInError.filter(function (fileInError) { return fileInError !== undefined; });
|
|
@@ -119939,10 +119992,10 @@ var ts;
|
|
|
119939
119992
|
distinctFileNamesWithLines.length === 1 ?
|
|
119940
119993
|
ts.Diagnostics.Found_0_errors_in_1_file :
|
|
119941
119994
|
ts.Diagnostics.Found_0_errors_in_1_files, errorCount, distinctFileNamesWithLines.length);
|
|
119942
|
-
return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles) : "");
|
|
119995
|
+
return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "");
|
|
119943
119996
|
}
|
|
119944
119997
|
ts.getErrorSummaryText = getErrorSummaryText;
|
|
119945
|
-
function createTabularErrorsDisplay(filesInError) {
|
|
119998
|
+
function createTabularErrorsDisplay(filesInError, host) {
|
|
119946
119999
|
var distinctFiles = filesInError.filter(function (value, index, self) { return index === self.findIndex(function (file) { return (file === null || file === void 0 ? void 0 : file.fileName) === (value === null || value === void 0 ? void 0 : value.fileName); }); });
|
|
119947
120000
|
if (distinctFiles.length === 0)
|
|
119948
120001
|
return "";
|
|
@@ -119961,7 +120014,8 @@ var ts;
|
|
|
119961
120014
|
var leftPadding = errorCountDigitsLength < leftPaddingGoal ?
|
|
119962
120015
|
" ".repeat(leftPaddingGoal - errorCountDigitsLength)
|
|
119963
120016
|
: "";
|
|
119964
|
-
|
|
120017
|
+
var relativePath = ts.getRelativePathFromDirectory(host.getCurrentDirectory(), file.fileName, /* ignoreCase */ false);
|
|
120018
|
+
tabularData += "" + leftPadding + errorCount + " " + relativePath + ":" + file.line + "\n";
|
|
119965
120019
|
});
|
|
119966
120020
|
return tabularData;
|
|
119967
120021
|
}
|
|
@@ -120379,7 +120433,7 @@ var ts;
|
|
|
120379
120433
|
var system = input.system || ts.sys;
|
|
120380
120434
|
var host = input.host || (input.host = ts.createIncrementalCompilerHost(input.options, system));
|
|
120381
120435
|
var builderProgram = ts.createIncrementalProgram(input);
|
|
120382
|
-
var exitStatus = emitFilesAndReportErrorsAndGetExitStatus(builderProgram, input.reportDiagnostic || createDiagnosticReporter(system), function (s) { return host.trace && host.trace(s); }, input.reportErrorSummary || input.options.pretty ? function (errorCount, filesInError) { return system.write(getErrorSummaryText(errorCount, filesInError, system.newLine)); } : undefined);
|
|
120436
|
+
var exitStatus = emitFilesAndReportErrorsAndGetExitStatus(builderProgram, input.reportDiagnostic || createDiagnosticReporter(system), function (s) { return host.trace && host.trace(s); }, input.reportErrorSummary || input.options.pretty ? function (errorCount, filesInError) { return system.write(getErrorSummaryText(errorCount, filesInError, system.newLine, host)); } : undefined);
|
|
120383
120437
|
if (input.afterProgramEmitAndDiagnostics)
|
|
120384
120438
|
input.afterProgramEmitAndDiagnostics(builderProgram);
|
|
120385
120439
|
return exitStatus;
|
|
@@ -122853,14 +122907,8 @@ var ts;
|
|
|
122853
122907
|
var possibleSearchDirs = new ts.Set(fileNames.map(ts.getDirectoryPath));
|
|
122854
122908
|
possibleSearchDirs.add(projectRootPath);
|
|
122855
122909
|
possibleSearchDirs.forEach(function (searchDir) {
|
|
122856
|
-
|
|
122857
|
-
|
|
122858
|
-
var bowerJsonPath = ts.combinePaths(searchDir, "bower.json");
|
|
122859
|
-
getTypingNamesFromJson(bowerJsonPath, filesToWatch);
|
|
122860
|
-
var bowerComponentsPath = ts.combinePaths(searchDir, "bower_components");
|
|
122861
|
-
getTypingNamesFromPackagesFolder(bowerComponentsPath, filesToWatch);
|
|
122862
|
-
var nodeModulesPath = ts.combinePaths(searchDir, "node_modules");
|
|
122863
|
-
getTypingNamesFromPackagesFolder(nodeModulesPath, filesToWatch);
|
|
122910
|
+
getTypingNames(searchDir, "bower.json", "bower_components", filesToWatch);
|
|
122911
|
+
getTypingNames(searchDir, "package.json", "node_modules", filesToWatch);
|
|
122864
122912
|
});
|
|
122865
122913
|
if (!typeAcquisition.disableFilenameBasedTypeAcquisition) {
|
|
122866
122914
|
getTypingNamesFromSourceFileNames(fileNames);
|
|
@@ -122909,16 +122957,100 @@ var ts;
|
|
|
122909
122957
|
ts.forEach(typingNames, addInferredTyping);
|
|
122910
122958
|
}
|
|
122911
122959
|
/**
|
|
122912
|
-
*
|
|
122960
|
+
* Adds inferred typings from manifest/module pairs (think package.json + node_modules)
|
|
122961
|
+
*
|
|
122962
|
+
* @param projectRootPath is the path to the directory where to look for package.json, bower.json and other typing information
|
|
122963
|
+
* @param manifestName is the name of the manifest (package.json or bower.json)
|
|
122964
|
+
* @param modulesDirName is the directory name for modules (node_modules or bower_components). Should be lowercase!
|
|
122965
|
+
* @param filesToWatch are the files to watch for changes. We will push things into this array.
|
|
122913
122966
|
*/
|
|
122914
|
-
function
|
|
122915
|
-
|
|
122967
|
+
function getTypingNames(projectRootPath, manifestName, modulesDirName, filesToWatch) {
|
|
122968
|
+
// First, we check the manifests themselves. They're not
|
|
122969
|
+
// _required_, but they allow us to do some filtering when dealing
|
|
122970
|
+
// with big flat dep directories.
|
|
122971
|
+
var manifestPath = ts.combinePaths(projectRootPath, manifestName);
|
|
122972
|
+
var manifest;
|
|
122973
|
+
var manifestTypingNames;
|
|
122974
|
+
if (host.fileExists(manifestPath)) {
|
|
122975
|
+
filesToWatch.push(manifestPath);
|
|
122976
|
+
manifest = ts.readConfigFile(manifestPath, function (path) { return host.readFile(path); }).config;
|
|
122977
|
+
manifestTypingNames = ts.flatMap([manifest.dependencies, manifest.devDependencies, manifest.optionalDependencies, manifest.peerDependencies], ts.getOwnKeys);
|
|
122978
|
+
addInferredTypings(manifestTypingNames, "Typing names in '" + manifestPath + "' dependencies");
|
|
122979
|
+
}
|
|
122980
|
+
// Now we scan the directories for typing information in
|
|
122981
|
+
// already-installed dependencies (if present). Note that this
|
|
122982
|
+
// step happens regardless of whether a manifest was present,
|
|
122983
|
+
// which is certainly a valid configuration, if an unusual one.
|
|
122984
|
+
var packagesFolderPath = ts.combinePaths(projectRootPath, modulesDirName);
|
|
122985
|
+
filesToWatch.push(packagesFolderPath);
|
|
122986
|
+
if (!host.directoryExists(packagesFolderPath)) {
|
|
122916
122987
|
return;
|
|
122917
122988
|
}
|
|
122918
|
-
|
|
122919
|
-
|
|
122920
|
-
|
|
122921
|
-
|
|
122989
|
+
// There's two cases we have to take into account here:
|
|
122990
|
+
// 1. If manifest is undefined, then we're not using a manifest.
|
|
122991
|
+
// That means that we should scan _all_ dependencies at the top
|
|
122992
|
+
// level of the modulesDir.
|
|
122993
|
+
// 2. If manifest is defined, then we can do some special
|
|
122994
|
+
// filtering to reduce the amount of scanning we need to do.
|
|
122995
|
+
//
|
|
122996
|
+
// Previous versions of this algorithm checked for a `_requiredBy`
|
|
122997
|
+
// field in the package.json, but that field is only present in
|
|
122998
|
+
// `npm@>=3 <7`.
|
|
122999
|
+
// Package names that do **not** provide their own typings, so
|
|
123000
|
+
// we'll look them up.
|
|
123001
|
+
var packageNames = [];
|
|
123002
|
+
var dependencyManifestNames = manifestTypingNames
|
|
123003
|
+
// This is #1 described above.
|
|
123004
|
+
? manifestTypingNames.map(function (typingName) { return ts.combinePaths(packagesFolderPath, typingName, manifestName); })
|
|
123005
|
+
// And #2. Depth = 3 because scoped packages look like `node_modules/@foo/bar/package.json`
|
|
123006
|
+
: host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 3)
|
|
123007
|
+
.filter(function (manifestPath) {
|
|
123008
|
+
if (ts.getBaseFileName(manifestPath) !== manifestName) {
|
|
123009
|
+
return false;
|
|
123010
|
+
}
|
|
123011
|
+
// It's ok to treat
|
|
123012
|
+
// `node_modules/@foo/bar/package.json` as a manifest,
|
|
123013
|
+
// but not `node_modules/jquery/nested/package.json`.
|
|
123014
|
+
// We only assume depth 3 is ok for formally scoped
|
|
123015
|
+
// packages. So that needs this dance here.
|
|
123016
|
+
var pathComponents = ts.getPathComponents(ts.normalizePath(manifestPath));
|
|
123017
|
+
var isScoped = pathComponents[pathComponents.length - 3][0] === "@";
|
|
123018
|
+
return isScoped && pathComponents[pathComponents.length - 4].toLowerCase() === modulesDirName || // `node_modules/@foo/bar`
|
|
123019
|
+
!isScoped && pathComponents[pathComponents.length - 3].toLowerCase() === modulesDirName; // `node_modules/foo`
|
|
123020
|
+
});
|
|
123021
|
+
if (log)
|
|
123022
|
+
log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(dependencyManifestNames));
|
|
123023
|
+
// Once we have the names of things to look up, we iterate over
|
|
123024
|
+
// and either collect their included typings, or add them to the
|
|
123025
|
+
// list of typings we need to look up separately.
|
|
123026
|
+
for (var _i = 0, dependencyManifestNames_1 = dependencyManifestNames; _i < dependencyManifestNames_1.length; _i++) {
|
|
123027
|
+
var manifestPath_1 = dependencyManifestNames_1[_i];
|
|
123028
|
+
var normalizedFileName = ts.normalizePath(manifestPath_1);
|
|
123029
|
+
var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
|
|
123030
|
+
var manifest_1 = result_1.config;
|
|
123031
|
+
// If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
|
|
123032
|
+
// to download d.ts files from DefinitelyTyped
|
|
123033
|
+
if (!manifest_1.name) {
|
|
123034
|
+
continue;
|
|
123035
|
+
}
|
|
123036
|
+
var ownTypes = manifest_1.types || manifest_1.typings;
|
|
123037
|
+
if (ownTypes) {
|
|
123038
|
+
var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
|
|
123039
|
+
if (host.fileExists(absolutePath)) {
|
|
123040
|
+
if (log)
|
|
123041
|
+
log(" Package '" + manifest_1.name + "' provides its own types.");
|
|
123042
|
+
inferredTypings.set(manifest_1.name, absolutePath);
|
|
123043
|
+
}
|
|
123044
|
+
else {
|
|
123045
|
+
if (log)
|
|
123046
|
+
log(" Package '" + manifest_1.name + "' provides its own types but they are missing.");
|
|
123047
|
+
}
|
|
123048
|
+
}
|
|
123049
|
+
else {
|
|
123050
|
+
packageNames.push(manifest_1.name);
|
|
123051
|
+
}
|
|
123052
|
+
}
|
|
123053
|
+
addInferredTypings(packageNames, " Found package names");
|
|
122922
123054
|
}
|
|
122923
123055
|
/**
|
|
122924
123056
|
* Infer typing names from given file names. For example, the file name "jquery-min.2.3.4.js"
|
|
@@ -122944,55 +123076,6 @@ var ts;
|
|
|
122944
123076
|
addInferredTyping("react");
|
|
122945
123077
|
}
|
|
122946
123078
|
}
|
|
122947
|
-
/**
|
|
122948
|
-
* Infer typing names from packages folder (ex: node_module, bower_components)
|
|
122949
|
-
* @param packagesFolderPath is the path to the packages folder
|
|
122950
|
-
*/
|
|
122951
|
-
function getTypingNamesFromPackagesFolder(packagesFolderPath, filesToWatch) {
|
|
122952
|
-
filesToWatch.push(packagesFolderPath);
|
|
122953
|
-
// Todo: add support for ModuleResolutionHost too
|
|
122954
|
-
if (!host.directoryExists(packagesFolderPath)) {
|
|
122955
|
-
return;
|
|
122956
|
-
}
|
|
122957
|
-
// depth of 2, so we access `node_modules/foo` but not `node_modules/foo/bar`
|
|
122958
|
-
var fileNames = host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 2);
|
|
122959
|
-
if (log)
|
|
122960
|
-
log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(fileNames));
|
|
122961
|
-
var packageNames = [];
|
|
122962
|
-
for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
|
|
122963
|
-
var fileName = fileNames_1[_i];
|
|
122964
|
-
var normalizedFileName = ts.normalizePath(fileName);
|
|
122965
|
-
var baseFileName = ts.getBaseFileName(normalizedFileName);
|
|
122966
|
-
if (baseFileName !== "package.json" && baseFileName !== "bower.json") {
|
|
122967
|
-
continue;
|
|
122968
|
-
}
|
|
122969
|
-
var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
|
|
122970
|
-
var packageJson = result_1.config;
|
|
122971
|
-
// npm 3's package.json contains a "_requiredBy" field
|
|
122972
|
-
// we should include all the top level module names for npm 2, and only module names whose
|
|
122973
|
-
// "_requiredBy" field starts with "#" or equals "/" for npm 3.
|
|
122974
|
-
if (baseFileName === "package.json" && packageJson._requiredBy &&
|
|
122975
|
-
ts.filter(packageJson._requiredBy, function (r) { return r[0] === "#" || r === "/"; }).length === 0) {
|
|
122976
|
-
continue;
|
|
122977
|
-
}
|
|
122978
|
-
// If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
|
|
122979
|
-
// to download d.ts files from DefinitelyTyped
|
|
122980
|
-
if (!packageJson.name) {
|
|
122981
|
-
continue;
|
|
122982
|
-
}
|
|
122983
|
-
var ownTypes = packageJson.types || packageJson.typings;
|
|
122984
|
-
if (ownTypes) {
|
|
122985
|
-
var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
|
|
122986
|
-
if (log)
|
|
122987
|
-
log(" Package '" + packageJson.name + "' provides its own types.");
|
|
122988
|
-
inferredTypings.set(packageJson.name, absolutePath);
|
|
122989
|
-
}
|
|
122990
|
-
else {
|
|
122991
|
-
packageNames.push(packageJson.name);
|
|
122992
|
-
}
|
|
122993
|
-
}
|
|
122994
|
-
addInferredTypings(packageNames, " Found package names");
|
|
122995
|
-
}
|
|
122996
123079
|
}
|
|
122997
123080
|
JsTyping.discoverTypings = discoverTypings;
|
|
122998
123081
|
var NameValidationResult;
|