@typescript-deploys/pr-build 4.6.0-pr-47183-2 → 4.6.0-pr-47400-2

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.
@@ -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-insiders.20211217";
92
+ ts.version = ts.versionMajorMinor + ".0-insiders.20220113";
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
  }
@@ -19779,16 +19780,6 @@ var ts;
19779
19780
  (symlinkedDirectories || (symlinkedDirectories = new ts.Map())).set(symlinkPath, real);
19780
19781
  }
19781
19782
  },
19782
- setSymlinkedDirectoryFromSymlinkedFile: function (symlink, real) {
19783
- this.setSymlinkedFile(ts.toPath(symlink, cwd, getCanonicalFileName), real);
19784
- var _a = guessDirectorySymlink(real, symlink, cwd, getCanonicalFileName) || ts.emptyArray, commonResolved = _a[0], commonOriginal = _a[1];
19785
- if (commonResolved && commonOriginal) {
19786
- this.setSymlinkedDirectory(commonOriginal, {
19787
- real: commonResolved,
19788
- realPath: ts.toPath(commonResolved, cwd, getCanonicalFileName),
19789
- });
19790
- }
19791
- },
19792
19783
  setSymlinksFromResolutions: function (files, typeReferenceDirectives) {
19793
19784
  var _this = this;
19794
19785
  var _a;
@@ -20756,9 +20747,40 @@ var ts;
20756
20747
  }
20757
20748
  ts.isFunctionExpressionOrArrowFunction = isFunctionExpressionOrArrowFunction;
20758
20749
  function escapeSnippetText(text) {
20759
- return text.replace(/\$/gm, "\\$");
20750
+ return text.replace(/\$/gm, function () { return "\\$"; });
20760
20751
  }
20761
20752
  ts.escapeSnippetText = escapeSnippetText;
20753
+ function isNumericLiteralName(name) {
20754
+ // The intent of numeric names is that
20755
+ // - they are names with text in a numeric form, and that
20756
+ // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
20757
+ // acquired by applying the abstract 'ToNumber' operation on the name's text.
20758
+ //
20759
+ // The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name.
20760
+ // In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold.
20761
+ //
20762
+ // Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)'
20763
+ // according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'.
20764
+ // Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names
20765
+ // because their 'ToString' representation is not equal to their original text.
20766
+ // This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1.
20767
+ //
20768
+ // Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'.
20769
+ // The '+' prefix operator is equivalent here to applying the abstract ToNumber operation.
20770
+ // Applying the 'toString()' method on a number gives us the abstract ToString operation on a number.
20771
+ //
20772
+ // Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional.
20773
+ // This is desired behavior, because when indexing with them as numeric entities, you are indexing
20774
+ // with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively.
20775
+ return (+name).toString() === name;
20776
+ }
20777
+ ts.isNumericLiteralName = isNumericLiteralName;
20778
+ function createPropertyNameNodeForIdentifierOrLiteral(name, target, singleQuote, stringNamed) {
20779
+ return ts.isIdentifierText(name, target) ? ts.factory.createIdentifier(name) :
20780
+ !stringNamed && isNumericLiteralName(name) && +name >= 0 ? ts.factory.createNumericLiteral(+name) :
20781
+ ts.factory.createStringLiteral(name, !!singleQuote);
20782
+ }
20783
+ ts.createPropertyNameNodeForIdentifierOrLiteral = createPropertyNameNodeForIdentifierOrLiteral;
20762
20784
  function isThisTypeParameter(type) {
20763
20785
  return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
20764
20786
  }
@@ -22231,7 +22253,7 @@ var ts;
22231
22253
  result.push(createModifier(144 /* ReadonlyKeyword */));
22232
22254
  if (flags & 256 /* Async */)
22233
22255
  result.push(createModifier(131 /* AsyncKeyword */));
22234
- return result;
22256
+ return result.length ? result : undefined;
22235
22257
  }
22236
22258
  //
22237
22259
  // Names
@@ -26188,32 +26210,36 @@ var ts;
26188
26210
  }
26189
26211
  function updateModifiers(node, modifiers) {
26190
26212
  var _a;
26213
+ var modifierArray;
26191
26214
  if (typeof modifiers === "number") {
26192
- modifiers = createModifiersFromModifierFlags(modifiers);
26193
- }
26194
- return ts.isParameter(node) ? updateParameterDeclaration(node, node.decorators, modifiers, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) :
26195
- ts.isPropertySignature(node) ? updatePropertySignature(node, modifiers, node.name, node.questionToken, node.type) :
26196
- ts.isPropertyDeclaration(node) ? updatePropertyDeclaration(node, node.decorators, modifiers, node.name, (_a = node.questionToken) !== null && _a !== void 0 ? _a : node.exclamationToken, node.type, node.initializer) :
26197
- ts.isMethodSignature(node) ? updateMethodSignature(node, modifiers, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) :
26198
- ts.isMethodDeclaration(node) ? updateMethodDeclaration(node, node.decorators, modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) :
26199
- ts.isConstructorDeclaration(node) ? updateConstructorDeclaration(node, node.decorators, modifiers, node.parameters, node.body) :
26200
- ts.isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, node.decorators, modifiers, node.name, node.parameters, node.type, node.body) :
26201
- ts.isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, node.decorators, modifiers, node.name, node.parameters, node.body) :
26202
- ts.isIndexSignatureDeclaration(node) ? updateIndexSignature(node, node.decorators, modifiers, node.parameters, node.type) :
26203
- ts.isFunctionExpression(node) ? updateFunctionExpression(node, modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26204
- ts.isArrowFunction(node) ? updateArrowFunction(node, modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) :
26205
- ts.isClassExpression(node) ? updateClassExpression(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) :
26206
- ts.isVariableStatement(node) ? updateVariableStatement(node, modifiers, node.declarationList) :
26207
- ts.isFunctionDeclaration(node) ? updateFunctionDeclaration(node, node.decorators, modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26208
- ts.isClassDeclaration(node) ? updateClassDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) :
26209
- ts.isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members) :
26210
- ts.isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, node.decorators, modifiers, node.name, node.typeParameters, node.type) :
26211
- ts.isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifiers, node.name, node.members) :
26212
- ts.isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifiers, node.name, node.body) :
26213
- ts.isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifiers, node.isTypeOnly, node.name, node.moduleReference) :
26214
- ts.isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifiers, node.importClause, node.moduleSpecifier, node.assertClause) :
26215
- ts.isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifiers, node.expression) :
26216
- ts.isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifiers, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
26215
+ modifierArray = createModifiersFromModifierFlags(modifiers);
26216
+ }
26217
+ else {
26218
+ modifierArray = modifiers;
26219
+ }
26220
+ return ts.isParameter(node) ? updateParameterDeclaration(node, node.decorators, modifierArray, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer) :
26221
+ ts.isPropertySignature(node) ? updatePropertySignature(node, modifierArray, node.name, node.questionToken, node.type) :
26222
+ ts.isPropertyDeclaration(node) ? updatePropertyDeclaration(node, node.decorators, modifierArray, node.name, (_a = node.questionToken) !== null && _a !== void 0 ? _a : node.exclamationToken, node.type, node.initializer) :
26223
+ ts.isMethodSignature(node) ? updateMethodSignature(node, modifierArray, node.name, node.questionToken, node.typeParameters, node.parameters, node.type) :
26224
+ ts.isMethodDeclaration(node) ? updateMethodDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body) :
26225
+ ts.isConstructorDeclaration(node) ? updateConstructorDeclaration(node, node.decorators, modifierArray, node.parameters, node.body) :
26226
+ ts.isGetAccessorDeclaration(node) ? updateGetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.type, node.body) :
26227
+ ts.isSetAccessorDeclaration(node) ? updateSetAccessorDeclaration(node, node.decorators, modifierArray, node.name, node.parameters, node.body) :
26228
+ ts.isIndexSignatureDeclaration(node) ? updateIndexSignature(node, node.decorators, modifierArray, node.parameters, node.type) :
26229
+ ts.isFunctionExpression(node) ? updateFunctionExpression(node, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26230
+ ts.isArrowFunction(node) ? updateArrowFunction(node, modifierArray, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body) :
26231
+ ts.isClassExpression(node) ? updateClassExpression(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
26232
+ ts.isVariableStatement(node) ? updateVariableStatement(node, modifierArray, node.declarationList) :
26233
+ ts.isFunctionDeclaration(node) ? updateFunctionDeclaration(node, node.decorators, modifierArray, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) :
26234
+ ts.isClassDeclaration(node) ? updateClassDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
26235
+ ts.isInterfaceDeclaration(node) ? updateInterfaceDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.heritageClauses, node.members) :
26236
+ ts.isTypeAliasDeclaration(node) ? updateTypeAliasDeclaration(node, node.decorators, modifierArray, node.name, node.typeParameters, node.type) :
26237
+ ts.isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifierArray, node.name, node.members) :
26238
+ ts.isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifierArray, node.name, node.body) :
26239
+ ts.isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.name, node.moduleReference) :
26240
+ ts.isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifierArray, node.importClause, node.moduleSpecifier, node.assertClause) :
26241
+ ts.isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifierArray, node.expression) :
26242
+ ts.isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
26217
26243
  ts.Debug.assertNever(node);
26218
26244
  }
26219
26245
  function asNodeArray(array) {
@@ -41462,9 +41488,7 @@ var ts;
41462
41488
  }
41463
41489
  }
41464
41490
  var failedLookupLocations = [];
41465
- var features = ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
41466
- ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
41467
- NodeResolutionFeatures.None;
41491
+ var features = getDefaultNodeResolutionFeatures(options);
41468
41492
  var moduleResolutionState = { compilerOptions: options, host: host, traceEnabled: traceEnabled, failedLookupLocations: failedLookupLocations, packageJsonInfoCache: cache, features: features, conditions: ["node", "require", "types"] };
41469
41493
  var resolved = primaryLookup();
41470
41494
  var primary = true;
@@ -41549,6 +41573,34 @@ var ts;
41549
41573
  }
41550
41574
  }
41551
41575
  ts.resolveTypeReferenceDirective = resolveTypeReferenceDirective;
41576
+ function getDefaultNodeResolutionFeatures(options) {
41577
+ return ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 ? NodeResolutionFeatures.Node12Default :
41578
+ ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext ? NodeResolutionFeatures.NodeNextDefault :
41579
+ NodeResolutionFeatures.None;
41580
+ }
41581
+ /**
41582
+ * @internal
41583
+ * Does not try `@types/${packageName}` - use a second pass if needed.
41584
+ */
41585
+ function resolvePackageNameToPackageJson(packageName, containingDirectory, options, host, cache) {
41586
+ var moduleResolutionState = {
41587
+ compilerOptions: options,
41588
+ host: host,
41589
+ traceEnabled: isTraceEnabled(options, host),
41590
+ failedLookupLocations: [],
41591
+ packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
41592
+ conditions: ts.emptyArray,
41593
+ features: NodeResolutionFeatures.None,
41594
+ };
41595
+ return ts.forEachAncestorDirectory(containingDirectory, function (ancestorDirectory) {
41596
+ if (ts.getBaseFileName(ancestorDirectory) !== "node_modules") {
41597
+ var nodeModulesFolder = ts.combinePaths(ancestorDirectory, "node_modules");
41598
+ var candidate = ts.combinePaths(nodeModulesFolder, packageName);
41599
+ return getPackageJsonInfo(candidate, /*onlyRecordFailures*/ false, moduleResolutionState);
41600
+ }
41601
+ });
41602
+ }
41603
+ ts.resolvePackageNameToPackageJson = resolvePackageNameToPackageJson;
41552
41604
  /**
41553
41605
  * Given a set of options, returns the set of type directive names
41554
41606
  * that should be included for this program automatically.
@@ -42122,11 +42174,6 @@ var ts;
42122
42174
  }
42123
42175
  ts.resolveJSModule = resolveJSModule;
42124
42176
  /* @internal */
42125
- function tryResolveJSModule(moduleName, initialDir, host) {
42126
- return tryResolveJSModuleWorker(moduleName, initialDir, host).resolvedModule;
42127
- }
42128
- ts.tryResolveJSModule = tryResolveJSModule;
42129
- /* @internal */
42130
42177
  var NodeResolutionFeatures;
42131
42178
  (function (NodeResolutionFeatures) {
42132
42179
  NodeResolutionFeatures[NodeResolutionFeatures["None"] = 0] = "None";
@@ -42434,6 +42481,97 @@ var ts;
42434
42481
  var versionPaths = packageInfo && packageInfo.versionPaths;
42435
42482
  return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths));
42436
42483
  }
42484
+ /* @internal */
42485
+ function getEntrypointsFromPackageJsonInfo(packageJsonInfo, options, host, cache, resolveJs) {
42486
+ if (!resolveJs && packageJsonInfo.resolvedEntrypoints !== undefined) {
42487
+ // Cached value excludes resolutions to JS files - those could be
42488
+ // cached separately, but they're used rarely.
42489
+ return packageJsonInfo.resolvedEntrypoints;
42490
+ }
42491
+ var entrypoints;
42492
+ var extensions = resolveJs ? Extensions.JavaScript : Extensions.TypeScript;
42493
+ var features = getDefaultNodeResolutionFeatures(options);
42494
+ var requireState = {
42495
+ compilerOptions: options,
42496
+ host: host,
42497
+ traceEnabled: isTraceEnabled(options, host),
42498
+ failedLookupLocations: [],
42499
+ packageJsonInfoCache: cache === null || cache === void 0 ? void 0 : cache.getPackageJsonInfoCache(),
42500
+ conditions: ["node", "require", "types"],
42501
+ features: features,
42502
+ };
42503
+ var requireResolution = loadNodeModuleFromDirectoryWorker(extensions, packageJsonInfo.packageDirectory,
42504
+ /*onlyRecordFailures*/ false, requireState, packageJsonInfo.packageJsonContent, packageJsonInfo.versionPaths);
42505
+ entrypoints = ts.append(entrypoints, requireResolution === null || requireResolution === void 0 ? void 0 : requireResolution.path);
42506
+ if (features & NodeResolutionFeatures.Exports && packageJsonInfo.packageJsonContent.exports) {
42507
+ for (var _i = 0, _a = [["node", "import", "types"], ["node", "require", "types"]]; _i < _a.length; _i++) {
42508
+ var conditions = _a[_i];
42509
+ var exportState = __assign(__assign({}, requireState), { failedLookupLocations: [], conditions: conditions });
42510
+ var exportResolutions = loadEntrypointsFromExportMap(packageJsonInfo, packageJsonInfo.packageJsonContent.exports, exportState, extensions);
42511
+ if (exportResolutions) {
42512
+ for (var _b = 0, exportResolutions_1 = exportResolutions; _b < exportResolutions_1.length; _b++) {
42513
+ var resolution = exportResolutions_1[_b];
42514
+ entrypoints = ts.appendIfUnique(entrypoints, resolution.path);
42515
+ }
42516
+ }
42517
+ }
42518
+ }
42519
+ return packageJsonInfo.resolvedEntrypoints = entrypoints || false;
42520
+ }
42521
+ ts.getEntrypointsFromPackageJsonInfo = getEntrypointsFromPackageJsonInfo;
42522
+ function loadEntrypointsFromExportMap(scope, exports, state, extensions) {
42523
+ var entrypoints;
42524
+ if (ts.isArray(exports)) {
42525
+ for (var _i = 0, exports_1 = exports; _i < exports_1.length; _i++) {
42526
+ var target = exports_1[_i];
42527
+ loadEntrypointsFromTargetExports(target);
42528
+ }
42529
+ }
42530
+ // eslint-disable-next-line no-null/no-null
42531
+ else if (typeof exports === "object" && exports !== null && allKeysStartWithDot(exports)) {
42532
+ for (var key in exports) {
42533
+ loadEntrypointsFromTargetExports(exports[key]);
42534
+ }
42535
+ }
42536
+ else {
42537
+ loadEntrypointsFromTargetExports(exports);
42538
+ }
42539
+ return entrypoints;
42540
+ function loadEntrypointsFromTargetExports(target) {
42541
+ var _a, _b;
42542
+ if (typeof target === "string" && ts.startsWith(target, "./") && target.indexOf("*") === -1) {
42543
+ var partsAfterFirst = ts.getPathComponents(target).slice(2);
42544
+ if (partsAfterFirst.indexOf("..") >= 0 || partsAfterFirst.indexOf(".") >= 0 || partsAfterFirst.indexOf("node_modules") >= 0) {
42545
+ return false;
42546
+ }
42547
+ var resolvedTarget = ts.combinePaths(scope.packageDirectory, target);
42548
+ var finalPath = ts.getNormalizedAbsolutePath(resolvedTarget, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a));
42549
+ var result = loadJSOrExactTSFileName(extensions, finalPath, /*recordOnlyFailures*/ false, state);
42550
+ if (result) {
42551
+ entrypoints = ts.appendIfUnique(entrypoints, result, function (a, b) { return a.path === b.path; });
42552
+ return true;
42553
+ }
42554
+ }
42555
+ else if (Array.isArray(target)) {
42556
+ for (var _i = 0, target_1 = target; _i < target_1.length; _i++) {
42557
+ var t = target_1[_i];
42558
+ var success = loadEntrypointsFromTargetExports(t);
42559
+ if (success) {
42560
+ return true;
42561
+ }
42562
+ }
42563
+ }
42564
+ // eslint-disable-next-line no-null/no-null
42565
+ else if (typeof target === "object" && target !== null) {
42566
+ return ts.forEach(ts.getOwnKeys(target), function (key) {
42567
+ if (key === "default" || ts.contains(state.conditions, key) || isApplicableVersionedTypesKey(state.conditions, key)) {
42568
+ loadEntrypointsFromTargetExports(target[key]);
42569
+ return true;
42570
+ }
42571
+ });
42572
+ }
42573
+ }
42574
+ }
42437
42575
  /**
42438
42576
  * A function for locating the package.json scope for a given path
42439
42577
  */
@@ -42490,7 +42628,7 @@ var ts;
42490
42628
  trace(host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath);
42491
42629
  }
42492
42630
  var versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
42493
- var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths };
42631
+ var result = { packageDirectory: packageDirectory, packageJsonContent: packageJsonContent, versionPaths: versionPaths, resolvedEntrypoints: undefined };
42494
42632
  (_b = state.packageJsonInfoCache) === null || _b === void 0 ? void 0 : _b.setPackageJsonInfo(packageJsonPath, result);
42495
42633
  return result;
42496
42634
  }
@@ -42787,8 +42925,8 @@ var ts;
42787
42925
  }
42788
42926
  return toSearchResult(/*value*/ undefined);
42789
42927
  }
42790
- for (var _d = 0, target_1 = target; _d < target_1.length; _d++) {
42791
- var elem = target_1[_d];
42928
+ for (var _d = 0, target_2 = target; _d < target_2.length; _d++) {
42929
+ var elem = target_2[_d];
42792
42930
  var result = loadModuleFromTargetImportOrExport(elem, subpath, pattern);
42793
42931
  if (result) {
42794
42932
  return result;
@@ -46827,6 +46965,7 @@ var ts;
46827
46965
  var location = ts.getParseTreeNode(locationIn);
46828
46966
  return location ? getTypeOfSymbolAtLocation(symbol, location) : errorType;
46829
46967
  },
46968
+ getTypeOfSymbol: getTypeOfSymbol,
46830
46969
  getSymbolsOfParameterPropertyDeclaration: function (parameterIn, parameterName) {
46831
46970
  var parameter = ts.getParseTreeNode(parameterIn, ts.isParameter);
46832
46971
  if (parameter === undefined)
@@ -49816,7 +49955,7 @@ var ts;
49816
49955
  if (!sigs || !sigs.length) {
49817
49956
  sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
49818
49957
  }
49819
- if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
49958
+ if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
49820
49959
  var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
49821
49960
  return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
49822
49961
  }
@@ -52020,8 +52159,8 @@ var ts;
52020
52159
  }
52021
52160
  else {
52022
52161
  if (parent && getExportsOfSymbol(parent)) {
52023
- var exports_1 = getExportsOfSymbol(parent);
52024
- ts.forEachEntry(exports_1, function (ex, name) {
52162
+ var exports_2 = getExportsOfSymbol(parent);
52163
+ ts.forEachEntry(exports_2, function (ex, name) {
52025
52164
  if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== "export=" /* ExportEquals */) {
52026
52165
  symbolName = ts.unescapeLeadingUnderscores(name);
52027
52166
  return true;
@@ -52182,7 +52321,7 @@ var ts;
52182
52321
  }
52183
52322
  var rawName = ts.unescapeLeadingUnderscores(symbol.escapedName);
52184
52323
  var stringNamed = !!ts.length(symbol.declarations) && ts.every(symbol.declarations, isStringNamed);
52185
- return createPropertyNameNodeForIdentifierOrLiteral(rawName, stringNamed, singleQuote);
52324
+ return ts.createPropertyNameNodeForIdentifierOrLiteral(rawName, ts.getEmitScriptTarget(compilerOptions), singleQuote, stringNamed);
52186
52325
  }
52187
52326
  // See getNameForSymbolFromNameType for a stringy equivalent
52188
52327
  function getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote) {
@@ -52190,24 +52329,19 @@ var ts;
52190
52329
  if (nameType) {
52191
52330
  if (nameType.flags & 384 /* StringOrNumberLiteral */) {
52192
52331
  var name = "" + nameType.value;
52193
- if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
52332
+ if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
52194
52333
  return ts.factory.createStringLiteral(name, !!singleQuote);
52195
52334
  }
52196
- if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
52335
+ if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
52197
52336
  return ts.factory.createComputedPropertyName(ts.factory.createNumericLiteral(+name));
52198
52337
  }
52199
- return createPropertyNameNodeForIdentifierOrLiteral(name);
52338
+ return ts.createPropertyNameNodeForIdentifierOrLiteral(name, ts.getEmitScriptTarget(compilerOptions));
52200
52339
  }
52201
52340
  if (nameType.flags & 8192 /* UniqueESSymbol */) {
52202
52341
  return ts.factory.createComputedPropertyName(symbolToExpression(nameType.symbol, context, 111551 /* Value */));
52203
52342
  }
52204
52343
  }
52205
52344
  }
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
52345
  function cloneNodeBuilderContext(context) {
52212
52346
  var initial = __assign({}, context);
52213
52347
  // Make type parameters created within this context not consume the name outside this context
@@ -53723,10 +53857,10 @@ var ts;
53723
53857
  if (nameType) {
53724
53858
  if (nameType.flags & 384 /* StringOrNumberLiteral */) {
53725
53859
  var name = "" + nameType.value;
53726
- if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !isNumericLiteralName(name)) {
53860
+ if (!ts.isIdentifierText(name, ts.getEmitScriptTarget(compilerOptions)) && !ts.isNumericLiteralName(name)) {
53727
53861
  return "\"" + ts.escapeString(name, 34 /* doubleQuote */) + "\"";
53728
53862
  }
53729
- if (isNumericLiteralName(name) && ts.startsWith(name, "-")) {
53863
+ if (ts.isNumericLiteralName(name) && ts.startsWith(name, "-")) {
53730
53864
  return "[" + name + "]";
53731
53865
  }
53732
53866
  return name;
@@ -57137,6 +57271,11 @@ var ts;
57137
57271
  return simplified !== type ? simplified : getConstraintOfType(type);
57138
57272
  }
57139
57273
  function getConstraintFromIndexedAccess(type) {
57274
+ if (isMappedTypeGenericIndexedAccess(type)) {
57275
+ // For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
57276
+ // we substitute an instantiation of E where P is replaced with X.
57277
+ return substituteIndexedMappedType(type.objectType, type.indexType);
57278
+ }
57140
57279
  var indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
57141
57280
  if (indexConstraint && indexConstraint !== type.indexType) {
57142
57281
  var indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint, type.accessFlags);
@@ -57341,6 +57480,11 @@ var ts;
57341
57480
  return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
57342
57481
  }
57343
57482
  if (t.flags & 8388608 /* IndexedAccess */) {
57483
+ if (isMappedTypeGenericIndexedAccess(t)) {
57484
+ // For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
57485
+ // we substitute an instantiation of E where P is replaced with X.
57486
+ return getBaseConstraint(substituteIndexedMappedType(t.objectType, t.indexType));
57487
+ }
57344
57488
  var baseObjectType = getBaseConstraint(t.objectType);
57345
57489
  var baseIndexType = getBaseConstraint(t.indexType);
57346
57490
  var baseIndexedAccess = baseObjectType && baseIndexType && getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, t.accessFlags);
@@ -57425,13 +57569,7 @@ var ts;
57425
57569
  * type itself.
57426
57570
  */
57427
57571
  function getApparentType(type) {
57428
- // We obtain the base constraint for all instantiable types, except indexed access types of the form
57429
- // { [P in K]: E }[X], where K is non-generic and X is generic. For those types, we instead substitute an
57430
- // instantiation of E where P is replaced with X. We do this because getBaseConstraintOfType directly
57431
- // lowers to an instantiation where X's constraint is substituted for X, which isn't always desirable.
57432
- var t = !(type.flags & 465829888 /* Instantiable */) ? type :
57433
- isMappedTypeGenericIndexedAccess(type) ? substituteIndexedMappedType(type.objectType, type.indexType) :
57434
- getBaseConstraintOfType(type) || unknownType;
57572
+ var t = !(type.flags & 465829888 /* Instantiable */) ? type : getBaseConstraintOfType(type) || unknownType;
57435
57573
  return ts.getObjectFlags(t) & 32 /* Mapped */ ? getApparentTypeOfMappedType(t) :
57436
57574
  t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
57437
57575
  t.flags & 402653316 /* StringLike */ ? globalStringType :
@@ -57713,7 +57851,7 @@ var ts;
57713
57851
  return symbol_1;
57714
57852
  }
57715
57853
  }
57716
- return globalObjectType === undefined ? undefined : getPropertyOfObjectType(globalObjectType, name);
57854
+ return getPropertyOfObjectType(globalObjectType, name);
57717
57855
  }
57718
57856
  if (type.flags & 3145728 /* UnionOrIntersection */) {
57719
57857
  return getPropertyOfUnionOrIntersectionType(type, name, skipObjectFunctionPropertyAugment);
@@ -57769,7 +57907,7 @@ var ts;
57769
57907
  // signature applies to types assignable to 'number' and numeric string literal types.
57770
57908
  return isTypeAssignableTo(source, target) ||
57771
57909
  target === stringType && isTypeAssignableTo(source, numberType) ||
57772
- target === numberType && !!(source.flags & 128 /* StringLiteral */) && isNumericLiteralName(source.value);
57910
+ target === numberType && !!(source.flags & 128 /* StringLiteral */) && ts.isNumericLiteralName(source.value);
57773
57911
  }
57774
57912
  function getIndexInfosOfStructuredType(type) {
57775
57913
  if (type.flags & 3670016 /* StructuredType */) {
@@ -60335,7 +60473,7 @@ var ts;
60335
60473
  getFlowTypeOfReference(accessExpression, propType) :
60336
60474
  propType;
60337
60475
  }
60338
- if (everyType(objectType, isTupleType) && isNumericLiteralName(propName) && +propName >= 0) {
60476
+ if (everyType(objectType, isTupleType) && ts.isNumericLiteralName(propName) && +propName >= 0) {
60339
60477
  if (accessNode && everyType(objectType, function (t) { return !t.target.hasRestElement; }) && !(accessFlags & 16 /* NoTupleBoundsCheck */)) {
60340
60478
  var indexNode = getIndexNodeForAccessExpression(accessNode);
60341
60479
  if (isTupleType(objectType)) {
@@ -60620,7 +60758,7 @@ var ts;
60620
60758
  return everyType(indexType, function (t) {
60621
60759
  if (t.flags & 384 /* StringOrNumberLiteral */) {
60622
60760
  var propName = getPropertyNameFromType(t);
60623
- if (isNumericLiteralName(propName)) {
60761
+ if (ts.isNumericLiteralName(propName)) {
60624
60762
  var index = +propName;
60625
60763
  return index >= 0 && index < limit;
60626
60764
  }
@@ -64095,6 +64233,17 @@ var ts;
64095
64233
  resetErrorInfo(saveErrorInfo);
64096
64234
  return result;
64097
64235
  }
64236
+ if (isMappedTypeGenericIndexedAccess(source)) {
64237
+ // For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
64238
+ // substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.
64239
+ var indexConstraint = getConstraintOfType(source.indexType);
64240
+ if (indexConstraint) {
64241
+ if (result = isRelatedTo(getIndexedAccessType(source.objectType, indexConstraint), target, 1 /* Source */, reportErrors)) {
64242
+ resetErrorInfo(saveErrorInfo);
64243
+ return result;
64244
+ }
64245
+ }
64246
+ }
64098
64247
  }
64099
64248
  }
64100
64249
  else if (source.flags & 4194304 /* Index */) {
@@ -64162,7 +64311,7 @@ var ts;
64162
64311
  else {
64163
64312
  // conditionals aren't related to one another via distributive constraint as it is much too inaccurate and allows way
64164
64313
  // more assignments than are desirable (since it maps the source check type to its constraint, it loses information)
64165
- var distributiveConstraint = getConstraintOfDistributiveConditionalType(source);
64314
+ var distributiveConstraint = hasNonCircularBaseConstraint(source) ? getConstraintOfDistributiveConditionalType(source) : undefined;
64166
64315
  if (distributiveConstraint) {
64167
64316
  if (result = isRelatedTo(distributiveConstraint, target, 1 /* Source */, reportErrors)) {
64168
64317
  resetErrorInfo(saveErrorInfo);
@@ -64708,7 +64857,7 @@ var ts;
64708
64857
  for (var _b = 0, _c = excludeProperties(properties, excludedProperties); _b < _c.length; _b++) {
64709
64858
  var targetProp = _c[_b];
64710
64859
  var name = targetProp.escapedName;
64711
- if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
64860
+ if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || ts.isNumericLiteralName(name) || name === "length")) {
64712
64861
  var sourceProp = getPropertyOfType(source, name);
64713
64862
  if (sourceProp && sourceProp !== targetProp) {
64714
64863
  var related = propertyRelatedTo(source, target, sourceProp, targetProp, getNonMissingTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
@@ -64781,7 +64930,8 @@ var ts;
64781
64930
  var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
64782
64931
  var sourceObjectFlags = ts.getObjectFlags(source);
64783
64932
  var targetObjectFlags = ts.getObjectFlags(target);
64784
- if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol) {
64933
+ if (sourceObjectFlags & 64 /* Instantiated */ && targetObjectFlags & 64 /* Instantiated */ && source.symbol === target.symbol ||
64934
+ sourceObjectFlags & 4 /* Reference */ && targetObjectFlags & 4 /* Reference */ && source.target === target.target) {
64785
64935
  // We have instantiations of the same anonymous type (which typically will be the type of a
64786
64936
  // method). Simply do a pairwise comparison of the signatures in the two signature lists instead
64787
64937
  // of the much more expensive N * M comparison matrix we explore below. We erase type parameters
@@ -65816,9 +65966,12 @@ var ts;
65816
65966
  * with no call or construct signatures.
65817
65967
  */
65818
65968
  function isObjectTypeWithInferableIndex(type) {
65819
- return type.flags & 2097152 /* Intersection */ ? ts.every(type.types, isObjectTypeWithInferableIndex) :
65820
- !!(type.symbol && (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0 &&
65821
- !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
65969
+ return type.flags & 2097152 /* Intersection */
65970
+ ? ts.every(type.types, isObjectTypeWithInferableIndex)
65971
+ : !!(type.symbol
65972
+ && (type.symbol.flags & (4096 /* ObjectLiteral */ | 2048 /* TypeLiteral */ | 384 /* Enum */ | 512 /* ValueModule */)) !== 0
65973
+ && !(type.symbol.flags & 32 /* Class */)
65974
+ && !typeHasCallOrConstructSignatures(type)) || !!(ts.getObjectFlags(type) & 1024 /* ReverseMapped */ && isObjectTypeWithInferableIndex(type.source));
65822
65975
  }
65823
65976
  function createSymbolWithType(source, type) {
65824
65977
  var symbol = createSymbol(source.flags, source.escapedName, ts.getCheckFlags(source) & 8 /* Readonly */);
@@ -67426,7 +67579,8 @@ var ts;
67426
67579
  return access.kind === 205 /* PropertyAccessExpression */ ? access.name.escapedText :
67427
67580
  access.kind === 206 /* ElementAccessExpression */ && ts.isStringOrNumericLiteralLike(access.argumentExpression) ? ts.escapeLeadingUnderscores(access.argumentExpression.text) :
67428
67581
  access.kind === 202 /* BindingElement */ && (propertyName = getDestructuringPropertyName(access)) ? ts.escapeLeadingUnderscores(propertyName) :
67429
- undefined;
67582
+ access.kind === 163 /* Parameter */ ? ("" + access.parent.parameters.indexOf(access)) :
67583
+ undefined;
67430
67584
  }
67431
67585
  function containsMatchingReference(source, target) {
67432
67586
  while (ts.isAccessExpression(source)) {
@@ -68766,13 +68920,14 @@ var ts;
68766
68920
  return result;
68767
68921
  }
68768
68922
  function getCandidateDiscriminantPropertyAccess(expr) {
68769
- if (ts.isBindingPattern(reference)) {
68770
- // When the reference is a binding pattern, we are narrowing a pesudo-reference in getNarrowedTypeOfSymbol.
68771
- // An identifier for a destructuring variable declared in the same binding pattern is a candidate.
68923
+ if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
68924
+ // When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
68925
+ // getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
68926
+ // parameter declared in the same parameter list is a candidate.
68772
68927
  if (ts.isIdentifier(expr)) {
68773
68928
  var symbol = getResolvedSymbol(expr);
68774
68929
  var declaration = symbol.valueDeclaration;
68775
- if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && reference === declaration.parent) {
68930
+ if (declaration && (ts.isBindingElement(declaration) || ts.isParameter(declaration)) && reference === declaration.parent && !declaration.initializer && !declaration.dotDotDotToken) {
68776
68931
  return declaration;
68777
68932
  }
68778
68933
  }
@@ -69574,42 +69729,78 @@ var ts;
69574
69729
  }
69575
69730
  }
69576
69731
  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
69732
  var declaration = symbol.valueDeclaration;
69601
- if (declaration && ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
69602
- var parent = declaration.parent.parent;
69603
- if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
69604
- var links = getNodeLinks(location);
69605
- if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
69606
- links.flags |= 268435456 /* InCheckIdentifier */;
69607
- var parentType = getTypeForBindingElementParent(parent);
69608
- links.flags &= ~268435456 /* InCheckIdentifier */;
69609
- if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
69610
- var pattern = declaration.parent;
69611
- var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
69612
- return getBindingElementTypeFromParentType(declaration, narrowedType);
69733
+ if (declaration) {
69734
+ // If we have a non-rest binding element with no initializer declared as a const variable or a const-like
69735
+ // parameter (a parameter for which there are no assignments in the function body), and if the parent type
69736
+ // for the destructuring is a union type, one or more of the binding elements may represent discriminant
69737
+ // properties, and we want the effects of conditional checks on such discriminants to affect the types of
69738
+ // other binding elements from the same destructuring. Consider:
69739
+ //
69740
+ // type Action =
69741
+ // | { kind: 'A', payload: number }
69742
+ // | { kind: 'B', payload: string };
69743
+ //
69744
+ // function f({ kind, payload }: Action) {
69745
+ // if (kind === 'A') {
69746
+ // payload.toFixed();
69747
+ // }
69748
+ // if (kind === 'B') {
69749
+ // payload.toUpperCase();
69750
+ // }
69751
+ // }
69752
+ //
69753
+ // Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
69754
+ // the binding pattern AST instance for '{ kind, payload }' as a pseudo-reference and narrow this reference
69755
+ // as if it occurred in the specified location. We then recompute the narrowed binding element type by
69756
+ // destructuring from the narrowed parent type.
69757
+ if (ts.isBindingElement(declaration) && !declaration.initializer && !declaration.dotDotDotToken && declaration.parent.elements.length >= 2) {
69758
+ var parent = declaration.parent.parent;
69759
+ if (parent.kind === 253 /* VariableDeclaration */ && ts.getCombinedNodeFlags(declaration) & 2 /* Const */ || parent.kind === 163 /* Parameter */) {
69760
+ var links = getNodeLinks(location);
69761
+ if (!(links.flags & 268435456 /* InCheckIdentifier */)) {
69762
+ links.flags |= 268435456 /* InCheckIdentifier */;
69763
+ var parentType = getTypeForBindingElementParent(parent);
69764
+ links.flags &= ~268435456 /* InCheckIdentifier */;
69765
+ if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
69766
+ var pattern = declaration.parent;
69767
+ var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
69768
+ return getBindingElementTypeFromParentType(declaration, narrowedType);
69769
+ }
69770
+ }
69771
+ }
69772
+ }
69773
+ // If we have a const-like parameter with no type annotation or initializer, and if the parameter is contextually
69774
+ // typed by a signature with a single rest parameter of a union of tuple types, one or more of the parameters may
69775
+ // represent discriminant tuple elements, and we want the effects of conditional checks on such discriminants to
69776
+ // affect the types of other parameters in the same parameter list. Consider:
69777
+ //
69778
+ // type Action = [kind: 'A', payload: number] | [kind: 'B', payload: string];
69779
+ //
69780
+ // const f: (...args: Action) => void = (kind, payload) => {
69781
+ // if (kind === 'A') {
69782
+ // payload.toFixed();
69783
+ // }
69784
+ // if (kind === 'B') {
69785
+ // payload.toUpperCase();
69786
+ // }
69787
+ // }
69788
+ //
69789
+ // Above, we want the conditional checks on 'kind' to affect the type of 'payload'. To facilitate this, we use
69790
+ // the arrow function AST node for '(kind, payload) => ...' as a pseudo-reference and narrow this reference as
69791
+ // if it occurred in the specified location. We then recompute the narrowed parameter type by indexing into the
69792
+ // narrowed tuple type.
69793
+ if (ts.isParameter(declaration) && !declaration.type && !declaration.initializer && !declaration.dotDotDotToken) {
69794
+ var func = declaration.parent;
69795
+ if (func.parameters.length >= 2 && isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
69796
+ var contextualSignature = getContextualSignature(func);
69797
+ if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
69798
+ var restType = getTypeOfSymbol(contextualSignature.parameters[0]);
69799
+ if (restType.flags & 1048576 /* Union */ && everyType(restType, isTupleType) && !isSymbolAssigned(symbol)) {
69800
+ var narrowedType = getFlowTypeOfReference(func, restType, restType, /*flowContainer*/ undefined, location.flowNode);
69801
+ var index = func.parameters.indexOf(declaration) - (ts.getThisParameter(func) ? 1 : 0);
69802
+ return getIndexedAccessType(narrowedType, getNumberLiteralType(index));
69803
+ }
69613
69804
  }
69614
69805
  }
69615
69806
  }
@@ -70750,7 +70941,7 @@ var ts;
70750
70941
  }
70751
70942
  if (isTupleType(t)) {
70752
70943
  var restType = getRestTypeOfTupleType(t);
70753
- if (restType && isNumericLiteralName(name) && +name >= 0) {
70944
+ if (restType && ts.isNumericLiteralName(name) && +name >= 0) {
70754
70945
  return restType;
70755
70946
  }
70756
70947
  }
@@ -71391,10 +71582,10 @@ var ts;
71391
71582
  case 161 /* ComputedPropertyName */:
71392
71583
  return isNumericComputedName(name);
71393
71584
  case 79 /* Identifier */:
71394
- return isNumericLiteralName(name.escapedText);
71585
+ return ts.isNumericLiteralName(name.escapedText);
71395
71586
  case 8 /* NumericLiteral */:
71396
71587
  case 10 /* StringLiteral */:
71397
- return isNumericLiteralName(name.text);
71588
+ return ts.isNumericLiteralName(name.text);
71398
71589
  default:
71399
71590
  return false;
71400
71591
  }
@@ -71404,30 +71595,6 @@ var ts;
71404
71595
  // but this behavior is consistent with checkIndexedAccess
71405
71596
  return isTypeAssignableToKind(checkComputedPropertyName(name), 296 /* NumberLike */);
71406
71597
  }
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
71598
  function checkComputedPropertyName(node) {
71432
71599
  var links = getNodeLinks(node.expression);
71433
71600
  if (!links.resolvedType) {
@@ -71463,7 +71630,7 @@ var ts;
71463
71630
  function isSymbolWithNumericName(symbol) {
71464
71631
  var _a;
71465
71632
  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));
71633
+ return ts.isNumericLiteralName(symbol.escapedName) || (firstDecl && ts.isNamedDeclaration(firstDecl) && isNumericName(firstDecl.name));
71467
71634
  }
71468
71635
  function isSymbolWithSymbolName(symbol) {
71469
71636
  var _a;
@@ -72686,6 +72853,9 @@ var ts;
72686
72853
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
72687
72854
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
72688
72855
  }
72856
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
72857
+ addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
72858
+ }
72689
72859
  }
72690
72860
  else {
72691
72861
  if (prop.declarations && getDeclarationNodeFlagsFromSymbol(prop) & 134217728 /* Deprecated */ && isUncalledFunctionReference(node, prop)) {
@@ -82401,7 +82571,7 @@ var ts;
82401
82571
  }
82402
82572
  else {
82403
82573
  var text = ts.getTextOfPropertyName(member.name);
82404
- if (isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
82574
+ if (ts.isNumericLiteralName(text) && !ts.isInfinityOrNaNString(text)) {
82405
82575
  error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
82406
82576
  }
82407
82577
  }
@@ -83195,9 +83365,9 @@ var ts;
83195
83365
  }
83196
83366
  }
83197
83367
  // Checks for export * conflicts
83198
- var exports_2 = getExportsOfModule(moduleSymbol);
83199
- if (exports_2) {
83200
- exports_2.forEach(function (_a, id) {
83368
+ var exports_3 = getExportsOfModule(moduleSymbol);
83369
+ if (exports_3) {
83370
+ exports_3.forEach(function (_a, id) {
83201
83371
  var declarations = _a.declarations, flags = _a.flags;
83202
83372
  if (id === "__export") {
83203
83373
  return;
@@ -92753,6 +92923,11 @@ var ts;
92753
92923
  ts.setSourceMapRange(statement, ts.moveRangePastModifiers(property));
92754
92924
  ts.setCommentRange(statement, property);
92755
92925
  ts.setOriginalNode(statement, property);
92926
+ // `setOriginalNode` *copies* the `emitNode` from `property`, so now both
92927
+ // `statement` and `expression` have a copy of the synthesized comments.
92928
+ // Drop the comments from expression to avoid printing them twice.
92929
+ ts.setSyntheticLeadingComments(expression, undefined);
92930
+ ts.setSyntheticTrailingComments(expression, undefined);
92756
92931
  statements.push(statement);
92757
92932
  }
92758
92933
  }
@@ -109007,7 +109182,7 @@ var ts;
109007
109182
  emitPlaceholder(hint, node, snippet);
109008
109183
  break;
109009
109184
  case 0 /* TabStop */:
109010
- emitTabStop(snippet);
109185
+ emitTabStop(hint, node, snippet);
109011
109186
  break;
109012
109187
  }
109013
109188
  }
@@ -109017,7 +109192,10 @@ var ts;
109017
109192
  nonEscapingWrite("}"); // `}`
109018
109193
  // `${2:...}`
109019
109194
  }
109020
- function emitTabStop(snippet) {
109195
+ function emitTabStop(hint, node, snippet) {
109196
+ // A tab stop should only be attached to an empty node, i.e. a node that doesn't emit any text.
109197
+ ts.Debug.assert(node.kind === 235 /* EmptyStatement */, "A tab stop cannot be attached to a node of kind " + ts.Debug.formatSyntaxKind(node.kind) + ".");
109198
+ ts.Debug.assert(hint !== 5 /* EmbeddedStatement */, "A tab stop cannot be attached to an embedded statement.");
109021
109199
  nonEscapingWrite("$" + snippet.order);
109022
109200
  }
109023
109201
  //
@@ -119090,28 +119268,37 @@ var ts;
119090
119268
  useCaseSensitiveFileNames: (_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host),
119091
119269
  };
119092
119270
  }
119093
- function updateModuleSpecifier(compilerOptions, importingSourceFileName, toFileName, host, oldImportSpecifier) {
119094
- var res = getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
119271
+ // `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
119272
+ // Because when this is called by the file renamer, `importingSourceFile` is the file being renamed,
119273
+ // while `importingSourceFileName` its *new* name. We need a source file just to get its
119274
+ // `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.
119275
+ function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, oldImportSpecifier) {
119276
+ var res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier, importingSourceFileName, host), {});
119095
119277
  if (res === oldImportSpecifier)
119096
119278
  return undefined;
119097
119279
  return res;
119098
119280
  }
119099
119281
  moduleSpecifiers_1.updateModuleSpecifier = updateModuleSpecifier;
119100
- // Note: importingSourceFile is just for usesJsExtensionOnImports
119282
+ // `importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`?
119283
+ // Because when this is called by the declaration emitter, `importingSourceFile` is the implementation
119284
+ // file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the
119285
+ // one currently being produced; the latter to the one being imported). We need an implementation file
119286
+ // just to get its `impliedNodeFormat` and to detect certain preferences from existing import module
119287
+ // specifiers.
119101
119288
  function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host) {
119102
- return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
119289
+ return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getPreferences(host, {}, compilerOptions, importingSourceFile), {});
119103
119290
  }
119104
119291
  moduleSpecifiers_1.getModuleSpecifier = getModuleSpecifier;
119105
- function getNodeModulesPackageName(compilerOptions, importingSourceFileName, nodeModulesFileName, host, preferences) {
119106
- var info = getInfo(importingSourceFileName, host);
119107
- var modulePaths = getAllModulePaths(importingSourceFileName, nodeModulesFileName, host, preferences);
119108
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions, /*packageNameOnly*/ true); });
119292
+ function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences) {
119293
+ var info = getInfo(importingSourceFile.path, host);
119294
+ var modulePaths = getAllModulePaths(importingSourceFile.path, nodeModulesFileName, host, preferences);
119295
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, /*packageNameOnly*/ true); });
119109
119296
  }
119110
119297
  moduleSpecifiers_1.getNodeModulesPackageName = getNodeModulesPackageName;
119111
- function getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, preferences, userPreferences) {
119298
+ function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, preferences, userPreferences) {
119112
119299
  var info = getInfo(importingSourceFileName, host);
119113
119300
  var modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host, userPreferences);
119114
- return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions); }) ||
119301
+ return ts.firstDefined(modulePaths, function (modulePath) { return tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions); }) ||
119115
119302
  getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
119116
119303
  }
119117
119304
  function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences) {
@@ -119178,7 +119365,7 @@ var ts;
119178
119365
  var relativeSpecifiers;
119179
119366
  for (var _i = 0, modulePaths_1 = modulePaths; _i < modulePaths_1.length; _i++) {
119180
119367
  var modulePath = modulePaths_1[_i];
119181
- var specifier = tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions);
119368
+ var specifier = tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions);
119182
119369
  nodeModulesSpecifiers = ts.append(nodeModulesSpecifiers, specifier);
119183
119370
  if (specifier && modulePath.isRedirect) {
119184
119371
  // If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
@@ -119570,7 +119757,7 @@ var ts;
119570
119757
  ? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions)
119571
119758
  : ts.removeFileExtension(relativePath);
119572
119759
  }
119573
- function tryGetModuleNameAsNodeModule(_a, _b, host, options, packageNameOnly) {
119760
+ function tryGetModuleNameAsNodeModule(_a, _b, importingSourceFile, host, options, packageNameOnly) {
119574
119761
  var path = _a.path, isRedirect = _a.isRedirect;
119575
119762
  var getCanonicalFileName = _b.getCanonicalFileName, sourceDirectory = _b.sourceDirectory;
119576
119763
  if (!host.fileExists || !host.readFile) {
@@ -119633,11 +119820,19 @@ var ts;
119633
119820
  var moduleFileToTry = path;
119634
119821
  if (host.fileExists(packageJsonPath)) {
119635
119822
  var packageJsonContent = JSON.parse(host.readFile(packageJsonPath));
119636
- // TODO: Inject `require` or `import` condition based on the intended import mode
119637
119823
  if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12 || ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
119638
- var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
119824
+ // `conditions` *could* be made to go against `importingSourceFile.impliedNodeFormat` if something wanted to generate
119825
+ // an ImportEqualsDeclaration in an ESM-implied file or an ImportCall in a CJS-implied file. But since this function is
119826
+ // usually called to conjure an import out of thin air, we don't have an existing usage to call `getModeForUsageAtIndex`
119827
+ // with, so for now we just stick with the mode of the file.
119828
+ var conditions = ["node", importingSourceFile.impliedNodeFormat === ts.ModuleKind.ESNext ? "import" : "require", "types"];
119829
+ var fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string"
119830
+ ? tryGetModuleNameFromExports(options, path, packageRootPath, ts.getPackageNameFromTypesPackageName(packageJsonContent.name), packageJsonContent.exports, conditions)
119831
+ : undefined;
119639
119832
  if (fromExports) {
119640
- var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
119833
+ var withJsExtension = !ts.hasTSFileExtension(fromExports.moduleFileToTry)
119834
+ ? fromExports
119835
+ : { moduleFileToTry: ts.removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
119641
119836
  return __assign(__assign({}, withJsExtension), { verbatimFromExports: true });
119642
119837
  }
119643
119838
  if (packageJsonContent.exports) {
@@ -119743,8 +119938,8 @@ var ts;
119743
119938
  }
119744
119939
  function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
119745
119940
  return ts.firstDefined(rootDirs, function (rootDir) {
119746
- var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName); // TODO: GH#18217
119747
- return isPathRelativeToParent(relativePath) ? undefined : relativePath;
119941
+ var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
119942
+ return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath;
119748
119943
  });
119749
119944
  }
119750
119945
  function removeExtensionAndIndexPostFix(fileName, ending, options) {
@@ -119863,7 +120058,7 @@ var ts;
119863
120058
  }
119864
120059
  ts.getLocaleTimeString = getLocaleTimeString;
119865
120060
  /**
119866
- * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic
120061
+ * Create a function that reports watch status by writing to the system and handles the formatting of the diagnostic
119867
120062
  */
119868
120063
  function createWatchStatusReporter(system, pretty) {
119869
120064
  return pretty ?
@@ -119924,7 +120119,7 @@ var ts;
119924
120119
  ts.Diagnostics.Found_0_errors_Watching_for_file_changes;
119925
120120
  }
119926
120121
  ts.getWatchErrorSummaryDiagnosticMessage = getWatchErrorSummaryDiagnosticMessage;
119927
- function getErrorSummaryText(errorCount, filesInError, newLine) {
120122
+ function getErrorSummaryText(errorCount, filesInError, newLine, host) {
119928
120123
  if (errorCount === 0)
119929
120124
  return "";
119930
120125
  var nonNilFiles = filesInError.filter(function (fileInError) { return fileInError !== undefined; });
@@ -119939,10 +120134,10 @@ var ts;
119939
120134
  distinctFileNamesWithLines.length === 1 ?
119940
120135
  ts.Diagnostics.Found_0_errors_in_1_file :
119941
120136
  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) : "");
120137
+ return "" + newLine + ts.flattenDiagnosticMessageText(d.messageText, newLine) + newLine + newLine + (errorCount > 1 ? createTabularErrorsDisplay(nonNilFiles, host) : "");
119943
120138
  }
119944
120139
  ts.getErrorSummaryText = getErrorSummaryText;
119945
- function createTabularErrorsDisplay(filesInError) {
120140
+ function createTabularErrorsDisplay(filesInError, host) {
119946
120141
  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
120142
  if (distinctFiles.length === 0)
119948
120143
  return "";
@@ -119961,7 +120156,8 @@ var ts;
119961
120156
  var leftPadding = errorCountDigitsLength < leftPaddingGoal ?
119962
120157
  " ".repeat(leftPaddingGoal - errorCountDigitsLength)
119963
120158
  : "";
119964
- tabularData += "" + leftPadding + errorCount + " " + file.fileName + ":" + file.line + "\n";
120159
+ var relativePath = ts.getRelativePathFromDirectory(host.getCurrentDirectory(), file.fileName, /* ignoreCase */ false);
120160
+ tabularData += "" + leftPadding + errorCount + " " + relativePath + ":" + file.line + "\n";
119965
120161
  });
119966
120162
  return tabularData;
119967
120163
  }
@@ -120379,7 +120575,7 @@ var ts;
120379
120575
  var system = input.system || ts.sys;
120380
120576
  var host = input.host || (input.host = ts.createIncrementalCompilerHost(input.options, system));
120381
120577
  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);
120578
+ 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
120579
  if (input.afterProgramEmitAndDiagnostics)
120384
120580
  input.afterProgramEmitAndDiagnostics(builderProgram);
120385
120581
  return exitStatus;
@@ -122853,14 +123049,8 @@ var ts;
122853
123049
  var possibleSearchDirs = new ts.Set(fileNames.map(ts.getDirectoryPath));
122854
123050
  possibleSearchDirs.add(projectRootPath);
122855
123051
  possibleSearchDirs.forEach(function (searchDir) {
122856
- var packageJsonPath = ts.combinePaths(searchDir, "package.json");
122857
- getTypingNamesFromJson(packageJsonPath, filesToWatch);
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);
123052
+ getTypingNames(searchDir, "bower.json", "bower_components", filesToWatch);
123053
+ getTypingNames(searchDir, "package.json", "node_modules", filesToWatch);
122864
123054
  });
122865
123055
  if (!typeAcquisition.disableFilenameBasedTypeAcquisition) {
122866
123056
  getTypingNamesFromSourceFileNames(fileNames);
@@ -122909,16 +123099,100 @@ var ts;
122909
123099
  ts.forEach(typingNames, addInferredTyping);
122910
123100
  }
122911
123101
  /**
122912
- * Get the typing info from common package manager json files like package.json or bower.json
123102
+ * Adds inferred typings from manifest/module pairs (think package.json + node_modules)
123103
+ *
123104
+ * @param projectRootPath is the path to the directory where to look for package.json, bower.json and other typing information
123105
+ * @param manifestName is the name of the manifest (package.json or bower.json)
123106
+ * @param modulesDirName is the directory name for modules (node_modules or bower_components). Should be lowercase!
123107
+ * @param filesToWatch are the files to watch for changes. We will push things into this array.
122913
123108
  */
122914
- function getTypingNamesFromJson(jsonPath, filesToWatch) {
122915
- if (!host.fileExists(jsonPath)) {
123109
+ function getTypingNames(projectRootPath, manifestName, modulesDirName, filesToWatch) {
123110
+ // First, we check the manifests themselves. They're not
123111
+ // _required_, but they allow us to do some filtering when dealing
123112
+ // with big flat dep directories.
123113
+ var manifestPath = ts.combinePaths(projectRootPath, manifestName);
123114
+ var manifest;
123115
+ var manifestTypingNames;
123116
+ if (host.fileExists(manifestPath)) {
123117
+ filesToWatch.push(manifestPath);
123118
+ manifest = ts.readConfigFile(manifestPath, function (path) { return host.readFile(path); }).config;
123119
+ manifestTypingNames = ts.flatMap([manifest.dependencies, manifest.devDependencies, manifest.optionalDependencies, manifest.peerDependencies], ts.getOwnKeys);
123120
+ addInferredTypings(manifestTypingNames, "Typing names in '" + manifestPath + "' dependencies");
123121
+ }
123122
+ // Now we scan the directories for typing information in
123123
+ // already-installed dependencies (if present). Note that this
123124
+ // step happens regardless of whether a manifest was present,
123125
+ // which is certainly a valid configuration, if an unusual one.
123126
+ var packagesFolderPath = ts.combinePaths(projectRootPath, modulesDirName);
123127
+ filesToWatch.push(packagesFolderPath);
123128
+ if (!host.directoryExists(packagesFolderPath)) {
122916
123129
  return;
122917
123130
  }
122918
- filesToWatch.push(jsonPath);
122919
- var jsonConfig = ts.readConfigFile(jsonPath, function (path) { return host.readFile(path); }).config;
122920
- var jsonTypingNames = ts.flatMap([jsonConfig.dependencies, jsonConfig.devDependencies, jsonConfig.optionalDependencies, jsonConfig.peerDependencies], ts.getOwnKeys);
122921
- addInferredTypings(jsonTypingNames, "Typing names in '" + jsonPath + "' dependencies");
123131
+ // There's two cases we have to take into account here:
123132
+ // 1. If manifest is undefined, then we're not using a manifest.
123133
+ // That means that we should scan _all_ dependencies at the top
123134
+ // level of the modulesDir.
123135
+ // 2. If manifest is defined, then we can do some special
123136
+ // filtering to reduce the amount of scanning we need to do.
123137
+ //
123138
+ // Previous versions of this algorithm checked for a `_requiredBy`
123139
+ // field in the package.json, but that field is only present in
123140
+ // `npm@>=3 <7`.
123141
+ // Package names that do **not** provide their own typings, so
123142
+ // we'll look them up.
123143
+ var packageNames = [];
123144
+ var dependencyManifestNames = manifestTypingNames
123145
+ // This is #1 described above.
123146
+ ? manifestTypingNames.map(function (typingName) { return ts.combinePaths(packagesFolderPath, typingName, manifestName); })
123147
+ // And #2. Depth = 3 because scoped packages look like `node_modules/@foo/bar/package.json`
123148
+ : host.readDirectory(packagesFolderPath, [".json" /* Json */], /*excludes*/ undefined, /*includes*/ undefined, /*depth*/ 3)
123149
+ .filter(function (manifestPath) {
123150
+ if (ts.getBaseFileName(manifestPath) !== manifestName) {
123151
+ return false;
123152
+ }
123153
+ // It's ok to treat
123154
+ // `node_modules/@foo/bar/package.json` as a manifest,
123155
+ // but not `node_modules/jquery/nested/package.json`.
123156
+ // We only assume depth 3 is ok for formally scoped
123157
+ // packages. So that needs this dance here.
123158
+ var pathComponents = ts.getPathComponents(ts.normalizePath(manifestPath));
123159
+ var isScoped = pathComponents[pathComponents.length - 3][0] === "@";
123160
+ return isScoped && pathComponents[pathComponents.length - 4].toLowerCase() === modulesDirName || // `node_modules/@foo/bar`
123161
+ !isScoped && pathComponents[pathComponents.length - 3].toLowerCase() === modulesDirName; // `node_modules/foo`
123162
+ });
123163
+ if (log)
123164
+ log("Searching for typing names in " + packagesFolderPath + "; all files: " + JSON.stringify(dependencyManifestNames));
123165
+ // Once we have the names of things to look up, we iterate over
123166
+ // and either collect their included typings, or add them to the
123167
+ // list of typings we need to look up separately.
123168
+ for (var _i = 0, dependencyManifestNames_1 = dependencyManifestNames; _i < dependencyManifestNames_1.length; _i++) {
123169
+ var manifestPath_1 = dependencyManifestNames_1[_i];
123170
+ var normalizedFileName = ts.normalizePath(manifestPath_1);
123171
+ var result_1 = ts.readConfigFile(normalizedFileName, function (path) { return host.readFile(path); });
123172
+ var manifest_1 = result_1.config;
123173
+ // If the package has its own d.ts typings, those will take precedence. Otherwise the package name will be used
123174
+ // to download d.ts files from DefinitelyTyped
123175
+ if (!manifest_1.name) {
123176
+ continue;
123177
+ }
123178
+ var ownTypes = manifest_1.types || manifest_1.typings;
123179
+ if (ownTypes) {
123180
+ var absolutePath = ts.getNormalizedAbsolutePath(ownTypes, ts.getDirectoryPath(normalizedFileName));
123181
+ if (host.fileExists(absolutePath)) {
123182
+ if (log)
123183
+ log(" Package '" + manifest_1.name + "' provides its own types.");
123184
+ inferredTypings.set(manifest_1.name, absolutePath);
123185
+ }
123186
+ else {
123187
+ if (log)
123188
+ log(" Package '" + manifest_1.name + "' provides its own types but they are missing.");
123189
+ }
123190
+ }
123191
+ else {
123192
+ packageNames.push(manifest_1.name);
123193
+ }
123194
+ }
123195
+ addInferredTypings(packageNames, " Found package names");
122922
123196
  }
122923
123197
  /**
122924
123198
  * Infer typing names from given file names. For example, the file name "jquery-min.2.3.4.js"
@@ -122944,55 +123218,6 @@ var ts;
122944
123218
  addInferredTyping("react");
122945
123219
  }
122946
123220
  }
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
123221
  }
122997
123222
  JsTyping.discoverTypings = discoverTypings;
122998
123223
  var NameValidationResult;