@typescript-deploys/pr-build 4.7.0-pr-47657-5 → 4.7.0-pr-48264-3

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.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-insiders.20220311";
297
+ ts.version = ts.versionMajorMinor + ".0-insiders.20220315";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -1662,6 +1662,159 @@ var ts;
1662
1662
  return createMultiMap();
1663
1663
  }
1664
1664
  ts.createUnderscoreEscapedMultiMap = createUnderscoreEscapedMultiMap;
1665
+ /**
1666
+ * Creates a Set with custom equality and hash code functionality. This is useful when you
1667
+ * want to use something looser than object identity - e.g. "has the same span".
1668
+ *
1669
+ * If `equals(a, b)`, it must be the case that `getHashCode(a) === getHashCode(b)`.
1670
+ * The converse is not required.
1671
+ *
1672
+ * To facilitate a perf optimization (lazy allocation of bucket arrays), `TElement` is
1673
+ * assumed not to be an array type.
1674
+ */
1675
+ function createSet(getHashCode, equals) {
1676
+ var multiMap = new ts.Map();
1677
+ var size = 0;
1678
+ function getElementIterator() {
1679
+ var valueIt = multiMap.values();
1680
+ var arrayIt;
1681
+ return {
1682
+ next: function () {
1683
+ while (true) {
1684
+ if (arrayIt) {
1685
+ var n = arrayIt.next();
1686
+ if (!n.done) {
1687
+ return { value: n.value };
1688
+ }
1689
+ arrayIt = undefined;
1690
+ }
1691
+ else {
1692
+ var n = valueIt.next();
1693
+ if (n.done) {
1694
+ return { value: undefined, done: true };
1695
+ }
1696
+ if (!isArray(n.value)) {
1697
+ return { value: n.value };
1698
+ }
1699
+ arrayIt = arrayIterator(n.value);
1700
+ }
1701
+ }
1702
+ }
1703
+ };
1704
+ }
1705
+ var set = {
1706
+ has: function (element) {
1707
+ var hash = getHashCode(element);
1708
+ if (!multiMap.has(hash))
1709
+ return false;
1710
+ var candidates = multiMap.get(hash);
1711
+ if (!isArray(candidates))
1712
+ return equals(candidates, element);
1713
+ for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
1714
+ var candidate = candidates_1[_i];
1715
+ if (equals(candidate, element)) {
1716
+ return true;
1717
+ }
1718
+ }
1719
+ return false;
1720
+ },
1721
+ add: function (element) {
1722
+ var hash = getHashCode(element);
1723
+ if (multiMap.has(hash)) {
1724
+ var values = multiMap.get(hash);
1725
+ if (isArray(values)) {
1726
+ if (!contains(values, element, equals)) {
1727
+ values.push(element);
1728
+ size++;
1729
+ }
1730
+ }
1731
+ else {
1732
+ var value = values;
1733
+ if (!equals(value, element)) {
1734
+ multiMap.set(hash, [value, element]);
1735
+ size++;
1736
+ }
1737
+ }
1738
+ }
1739
+ else {
1740
+ multiMap.set(hash, element);
1741
+ size++;
1742
+ }
1743
+ return this;
1744
+ },
1745
+ delete: function (element) {
1746
+ var hash = getHashCode(element);
1747
+ if (!multiMap.has(hash))
1748
+ return false;
1749
+ var candidates = multiMap.get(hash);
1750
+ if (isArray(candidates)) {
1751
+ for (var i = 0; i < candidates.length; i++) {
1752
+ if (equals(candidates[i], element)) {
1753
+ if (candidates.length === 1) {
1754
+ multiMap.delete(hash);
1755
+ }
1756
+ else if (candidates.length === 2) {
1757
+ multiMap.set(hash, candidates[1 - i]);
1758
+ }
1759
+ else {
1760
+ unorderedRemoveItemAt(candidates, i);
1761
+ }
1762
+ size--;
1763
+ return true;
1764
+ }
1765
+ }
1766
+ }
1767
+ else {
1768
+ var candidate = candidates;
1769
+ if (equals(candidate, element)) {
1770
+ multiMap.delete(hash);
1771
+ size--;
1772
+ return true;
1773
+ }
1774
+ }
1775
+ return false;
1776
+ },
1777
+ clear: function () {
1778
+ multiMap.clear();
1779
+ size = 0;
1780
+ },
1781
+ get size() {
1782
+ return size;
1783
+ },
1784
+ forEach: function (action) {
1785
+ for (var _i = 0, _a = arrayFrom(multiMap.values()); _i < _a.length; _i++) {
1786
+ var elements = _a[_i];
1787
+ if (isArray(elements)) {
1788
+ for (var _b = 0, elements_1 = elements; _b < elements_1.length; _b++) {
1789
+ var element = elements_1[_b];
1790
+ action(element, element);
1791
+ }
1792
+ }
1793
+ else {
1794
+ var element = elements;
1795
+ action(element, element);
1796
+ }
1797
+ }
1798
+ },
1799
+ keys: function () {
1800
+ return getElementIterator();
1801
+ },
1802
+ values: function () {
1803
+ return getElementIterator();
1804
+ },
1805
+ entries: function () {
1806
+ var it = getElementIterator();
1807
+ return {
1808
+ next: function () {
1809
+ var n = it.next();
1810
+ return n.done ? n : { value: [n.value, n.value] };
1811
+ }
1812
+ };
1813
+ },
1814
+ };
1815
+ return set;
1816
+ }
1817
+ ts.createSet = createSet;
1665
1818
  /**
1666
1819
  * Tests whether a value is an array.
1667
1820
  */
@@ -2055,8 +2208,8 @@ var ts;
2055
2208
  var maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
2056
2209
  var bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
2057
2210
  var bestCandidate;
2058
- for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
2059
- var candidate = candidates_1[_i];
2211
+ for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
2212
+ var candidate = candidates_2[_i];
2060
2213
  var candidateName = getName(candidate);
2061
2214
  if (candidateName !== undefined && Math.abs(candidateName.length - name.length) <= maximumLengthDifference) {
2062
2215
  if (candidateName === name) {
@@ -14991,6 +15144,10 @@ var ts;
14991
15144
  }
14992
15145
  }
14993
15146
  ts.isAnyImportSyntax = isAnyImportSyntax;
15147
+ function isAnyImportOrBareOrAccessedRequire(node) {
15148
+ return isAnyImportSyntax(node) || isVariableDeclarationInitializedToBareOrAccessedRequire(node);
15149
+ }
15150
+ ts.isAnyImportOrBareOrAccessedRequire = isAnyImportOrBareOrAccessedRequire;
14994
15151
  function isLateVisibilityPaintedStatement(node) {
14995
15152
  switch (node.kind) {
14996
15153
  case 265 /* ImportDeclaration */:
@@ -16569,14 +16726,14 @@ var ts;
16569
16726
  }
16570
16727
  ts.isFunctionSymbol = isFunctionSymbol;
16571
16728
  function tryGetModuleSpecifierFromDeclaration(node) {
16572
- var _a, _b, _c;
16729
+ var _a, _b;
16573
16730
  switch (node.kind) {
16574
16731
  case 253 /* VariableDeclaration */:
16575
- return node.initializer.arguments[0].text;
16732
+ return (_a = ts.findAncestor(node.initializer, function (node) { return isRequireCall(node, /*requireStringLiteralLikeArgument*/ true); })) === null || _a === void 0 ? void 0 : _a.arguments[0];
16576
16733
  case 265 /* ImportDeclaration */:
16577
- return (_a = ts.tryCast(node.moduleSpecifier, ts.isStringLiteralLike)) === null || _a === void 0 ? void 0 : _a.text;
16734
+ return ts.tryCast(node.moduleSpecifier, ts.isStringLiteralLike);
16578
16735
  case 264 /* ImportEqualsDeclaration */:
16579
- return (_c = ts.tryCast((_b = ts.tryCast(node.moduleReference, ts.isExternalModuleReference)) === null || _b === void 0 ? void 0 : _b.expression, ts.isStringLiteralLike)) === null || _c === void 0 ? void 0 : _c.text;
16736
+ return ts.tryCast((_b = ts.tryCast(node.moduleReference, ts.isExternalModuleReference)) === null || _b === void 0 ? void 0 : _b.expression, ts.isStringLiteralLike);
16580
16737
  default:
16581
16738
  ts.Debug.assertNever(node);
16582
16739
  }
@@ -17103,21 +17260,28 @@ var ts;
17103
17260
  // export = <EntityNameExpression>
17104
17261
  // export default <EntityNameExpression>
17105
17262
  // module.exports = <EntityNameExpression>
17106
- // {<Identifier>}
17107
- // {name: <EntityNameExpression>}
17263
+ // module.exports.x = <EntityNameExpression>
17264
+ // const x = require("...")
17265
+ // const { x } = require("...")
17266
+ // const x = require("...").y
17267
+ // const { x } = require("...").y
17108
17268
  function isAliasSymbolDeclaration(node) {
17109
- return node.kind === 264 /* ImportEqualsDeclaration */ ||
17269
+ if (node.kind === 264 /* ImportEqualsDeclaration */ ||
17110
17270
  node.kind === 263 /* NamespaceExportDeclaration */ ||
17111
17271
  node.kind === 266 /* ImportClause */ && !!node.name ||
17112
17272
  node.kind === 267 /* NamespaceImport */ ||
17113
17273
  node.kind === 273 /* NamespaceExport */ ||
17114
17274
  node.kind === 269 /* ImportSpecifier */ ||
17115
17275
  node.kind === 274 /* ExportSpecifier */ ||
17116
- node.kind === 270 /* ExportAssignment */ && exportAssignmentIsAlias(node) ||
17117
- ts.isBinaryExpression(node) && getAssignmentDeclarationKind(node) === 2 /* ModuleExports */ && exportAssignmentIsAlias(node) ||
17118
- ts.isPropertyAccessExpression(node) && ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 63 /* EqualsToken */ && isAliasableExpression(node.parent.right) ||
17119
- node.kind === 296 /* ShorthandPropertyAssignment */ ||
17120
- node.kind === 295 /* PropertyAssignment */ && isAliasableExpression(node.initializer);
17276
+ node.kind === 270 /* ExportAssignment */ && exportAssignmentIsAlias(node)) {
17277
+ return true;
17278
+ }
17279
+ return isInJSFile(node) && (ts.isBinaryExpression(node) && getAssignmentDeclarationKind(node) === 2 /* ModuleExports */ && exportAssignmentIsAlias(node) ||
17280
+ ts.isPropertyAccessExpression(node)
17281
+ && ts.isBinaryExpression(node.parent)
17282
+ && node.parent.left === node
17283
+ && node.parent.operatorToken.kind === 63 /* EqualsToken */
17284
+ && isAliasableExpression(node.parent.right));
17121
17285
  }
17122
17286
  ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration;
17123
17287
  function getAliasDeclarationFromName(node) {
@@ -17128,6 +17292,7 @@ var ts;
17128
17292
  case 274 /* ExportSpecifier */:
17129
17293
  case 270 /* ExportAssignment */:
17130
17294
  case 264 /* ImportEqualsDeclaration */:
17295
+ case 273 /* NamespaceExport */:
17131
17296
  return node.parent;
17132
17297
  case 160 /* QualifiedName */:
17133
17298
  do {
@@ -39475,6 +39640,13 @@ var ts;
39475
39640
  description: ts.Diagnostics.Allow_accessing_UMD_globals_from_modules,
39476
39641
  defaultValueDescription: false,
39477
39642
  },
39643
+ {
39644
+ name: "noDtsResolution",
39645
+ type: "boolean",
39646
+ affectsModuleResolution: true,
39647
+ category: ts.Diagnostics.Modules,
39648
+ defaultValueDescription: false,
39649
+ },
39478
39650
  // Source Maps
39479
39651
  {
39480
39652
  name: "sourceRoot",
@@ -41854,7 +42026,8 @@ var ts;
41854
42026
  Extensions[Extensions["JavaScript"] = 1] = "JavaScript";
41855
42027
  Extensions[Extensions["Json"] = 2] = "Json";
41856
42028
  Extensions[Extensions["TSConfig"] = 3] = "TSConfig";
41857
- Extensions[Extensions["DtsOnly"] = 4] = "DtsOnly"; /** Only '.d.ts' */
42029
+ Extensions[Extensions["DtsOnly"] = 4] = "DtsOnly";
42030
+ Extensions[Extensions["TypeScriptButNotDts"] = 5] = "TypeScriptButNotDts";
41858
42031
  })(Extensions || (Extensions = {}));
41859
42032
  /** Used with `Extensions.DtsOnly` to extract the path from TypeScript results. */
41860
42033
  function resolvedTypeScriptOnly(resolved) {
@@ -42799,7 +42972,21 @@ var ts;
42799
42972
  return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined);
42800
42973
  }
42801
42974
  function nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, lookupConfig) {
42802
- return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, ts.getDirectoryPath(containingFile), compilerOptions, host, cache, lookupConfig ? tsconfigExtensions : (compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions), redirectedReference);
42975
+ var extensions;
42976
+ if (lookupConfig) {
42977
+ extensions = tsconfigExtensions;
42978
+ }
42979
+ else if (compilerOptions.noDtsResolution) {
42980
+ extensions = [Extensions.TypeScriptButNotDts];
42981
+ if (compilerOptions.allowJs)
42982
+ extensions.push(Extensions.JavaScript);
42983
+ if (compilerOptions.resolveJsonModule)
42984
+ extensions.push(Extensions.Json);
42985
+ }
42986
+ else {
42987
+ extensions = compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions;
42988
+ }
42989
+ return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, ts.getDirectoryPath(containingFile), compilerOptions, host, cache, extensions, redirectedReference);
42803
42990
  }
42804
42991
  ts.nodeModuleNameResolver = nodeModuleNameResolver;
42805
42992
  function nodeModuleNameResolverWorker(features, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference) {
@@ -42808,6 +42995,10 @@ var ts;
42808
42995
  var failedLookupLocations = [];
42809
42996
  // conditions are only used by the node12/nodenext resolver - there's no priority order in the list,
42810
42997
  //it's essentially a set (priority is determined by object insertion order in the object we look at).
42998
+ var conditions = features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"];
42999
+ if (compilerOptions.noDtsResolution) {
43000
+ conditions.pop();
43001
+ }
42811
43002
  var state = {
42812
43003
  compilerOptions: compilerOptions,
42813
43004
  host: host,
@@ -42815,7 +43006,7 @@ var ts;
42815
43006
  failedLookupLocations: failedLookupLocations,
42816
43007
  packageJsonInfoCache: cache,
42817
43008
  features: features,
42818
- conditions: features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"]
43009
+ conditions: conditions,
42819
43010
  };
42820
43011
  var result = ts.forEach(extensions, function (ext) { return tryResolve(ext); });
42821
43012
  return createResolvedModuleWithFailedLookupLocations((_a = result === null || result === void 0 ? void 0 : result.value) === null || _a === void 0 ? void 0 : _a.resolved, (_b = result === null || result === void 0 ? void 0 : result.value) === null || _b === void 0 ? void 0 : _b.isExternalLibraryImport, failedLookupLocations, state.resultFromCache);
@@ -43023,20 +43214,22 @@ var ts;
43023
43214
  default: return tryExtension(".d.ts" /* Dts */);
43024
43215
  }
43025
43216
  case Extensions.TypeScript:
43217
+ case Extensions.TypeScriptButNotDts:
43218
+ var useDts = extensions === Extensions.TypeScript;
43026
43219
  switch (originalExtension) {
43027
43220
  case ".mjs" /* Mjs */:
43028
43221
  case ".mts" /* Mts */:
43029
43222
  case ".d.mts" /* Dmts */:
43030
- return tryExtension(".mts" /* Mts */) || tryExtension(".d.mts" /* Dmts */);
43223
+ return tryExtension(".mts" /* Mts */) || (useDts ? tryExtension(".d.mts" /* Dmts */) : undefined);
43031
43224
  case ".cjs" /* Cjs */:
43032
43225
  case ".cts" /* Cts */:
43033
43226
  case ".d.cts" /* Dcts */:
43034
- return tryExtension(".cts" /* Cts */) || tryExtension(".d.cts" /* Dcts */);
43227
+ return tryExtension(".cts" /* Cts */) || (useDts ? tryExtension(".d.cts" /* Dcts */) : undefined);
43035
43228
  case ".json" /* Json */:
43036
43229
  candidate += ".json" /* Json */;
43037
- return tryExtension(".d.ts" /* Dts */);
43230
+ return useDts ? tryExtension(".d.ts" /* Dts */) : undefined;
43038
43231
  default:
43039
- return tryExtension(".ts" /* Ts */) || tryExtension(".tsx" /* Tsx */) || tryExtension(".d.ts" /* Dts */);
43232
+ return tryExtension(".ts" /* Ts */) || tryExtension(".tsx" /* Tsx */) || (useDts ? tryExtension(".d.ts" /* Dts */) : undefined);
43040
43233
  }
43041
43234
  case Extensions.JavaScript:
43042
43235
  switch (originalExtension) {
@@ -43254,6 +43447,7 @@ var ts;
43254
43447
  switch (extensions) {
43255
43448
  case Extensions.JavaScript:
43256
43449
  case Extensions.Json:
43450
+ case Extensions.TypeScriptButNotDts:
43257
43451
  packageFile = readPackageJsonMainField(jsonContent, candidate, state);
43258
43452
  break;
43259
43453
  case Extensions.TypeScript:
@@ -43332,6 +43526,8 @@ var ts;
43332
43526
  return extension === ".json" /* Json */;
43333
43527
  case Extensions.TypeScript:
43334
43528
  return extension === ".ts" /* Ts */ || extension === ".tsx" /* Tsx */ || extension === ".d.ts" /* Dts */;
43529
+ case Extensions.TypeScriptButNotDts:
43530
+ return extension === ".ts" /* Ts */ || extension === ".tsx" /* Tsx */;
43335
43531
  case Extensions.DtsOnly:
43336
43532
  return extension === ".d.ts" /* Dts */;
43337
43533
  }
@@ -44801,7 +44997,6 @@ var ts;
44801
44997
  node = node.parent;
44802
44998
  }
44803
44999
  return !isStatementCondition(node) &&
44804
- !isLogicalAssignmentExpression(node.parent) &&
44805
45000
  !isLogicalExpression(node.parent) &&
44806
45001
  !(ts.isOptionalChain(node.parent) && node.parent.expression === node);
44807
45002
  }
@@ -46831,7 +47026,7 @@ var ts;
46831
47026
  checkStrictModeEvalOrArguments(node, node.name);
46832
47027
  }
46833
47028
  if (!ts.isBindingPattern(node.name)) {
46834
- if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node)) {
47029
+ if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
46835
47030
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
46836
47031
  }
46837
47032
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -55401,7 +55596,7 @@ var ts;
55401
55596
  }
55402
55597
  }
55403
55598
  var sourceTypes = ts.some(constructorTypes, function (t) { return !!(t.flags & ~98304 /* Nullable */); }) ? constructorTypes : types; // TODO: GH#18217
55404
- type = getUnionType(sourceTypes, 2 /* Subtype */);
55599
+ type = getUnionType(sourceTypes);
55405
55600
  }
55406
55601
  }
55407
55602
  var widened = getWidenedType(addOptionality(type, /*isProperty*/ false, definedInMethod && !definedInConstructor));
@@ -87735,8 +87930,8 @@ var ts;
87735
87930
  }
87736
87931
  else {
87737
87932
  var elements = name.elements;
87738
- for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
87739
- var element = elements_1[_i];
87933
+ for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87934
+ var element = elements_2[_i];
87740
87935
  if (!ts.isOmittedExpression(element)) {
87741
87936
  return checkESModuleMarker(element.name);
87742
87937
  }
@@ -87752,8 +87947,8 @@ var ts;
87752
87947
  }
87753
87948
  else {
87754
87949
  var elements = name.elements;
87755
- for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87756
- var element = elements_2[_i];
87950
+ for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
87951
+ var element = elements_3[_i];
87757
87952
  if (!ts.isOmittedExpression(element)) {
87758
87953
  checkGrammarNameInLetOrConstDeclarations(element.name);
87759
87954
  }
@@ -90007,8 +90202,8 @@ var ts;
90007
90202
  }
90008
90203
  function bindingOrAssignmentPatternAssignsToName(pattern, escapedName) {
90009
90204
  var elements = ts.getElementsOfBindingOrAssignmentPattern(pattern);
90010
- for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
90011
- var element = elements_3[_i];
90205
+ for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
90206
+ var element = elements_4[_i];
90012
90207
  if (bindingOrAssignmentElementAssignsToName(element, escapedName)) {
90013
90208
  return true;
90014
90209
  }
@@ -95626,8 +95821,8 @@ var ts;
95626
95821
  function chunkObjectLiteralElements(elements) {
95627
95822
  var chunkObject;
95628
95823
  var objects = [];
95629
- for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
95630
- var e = elements_4[_i];
95824
+ for (var _i = 0, elements_5 = elements; _i < elements_5.length; _i++) {
95825
+ var e = elements_5[_i];
95631
95826
  if (e.kind === 297 /* SpreadAssignment */) {
95632
95827
  if (chunkObject) {
95633
95828
  objects.push(factory.createObjectLiteralExpression(chunkObject));
@@ -127445,6 +127640,20 @@ var ts;
127445
127640
  return !!location.parent && ts.isImportOrExportSpecifier(location.parent) && location.parent.propertyName === location;
127446
127641
  }
127447
127642
  ts.isImportOrExportSpecifierName = isImportOrExportSpecifierName;
127643
+ /**
127644
+ * Returns true if `node` is the declaration of `n` in:
127645
+ * - `import n from "m"`
127646
+ * - `import * as n from "m"`
127647
+ * - `import n = require("m")`
127648
+ * - `const n = require("m")`
127649
+ */
127650
+ function isFreelyNameableImport(node) {
127651
+ return node.kind === 266 /* ImportClause */
127652
+ || node.kind === 267 /* NamespaceImport */
127653
+ || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
127654
+ || ts.isVariableDeclarationInitializedToRequire(node);
127655
+ }
127656
+ ts.isFreelyNameableImport = isFreelyNameableImport;
127448
127657
  function getScriptKind(fileName, host) {
127449
127658
  // First check to see if the script kind was specified by the host. Chances are the host
127450
127659
  // may override the default script kind for the file extension.
@@ -136459,6 +136668,29 @@ var ts;
136459
136668
  }
136460
136669
  }
136461
136670
  Core.eachSymbolReferenceInFile = eachSymbolReferenceInFile;
136671
+ function getTopMostDeclarationNamesInFile(declarationName, sourceFile) {
136672
+ var candidates = ts.filter(getPossibleSymbolReferenceNodes(sourceFile, declarationName), function (name) { return !!ts.getDeclarationFromName(name); });
136673
+ return candidates.reduce(function (topMost, decl) {
136674
+ var depth = getDepth(decl);
136675
+ if (!ts.some(topMost.declarationNames) || depth === topMost.depth) {
136676
+ topMost.declarationNames.push(decl);
136677
+ }
136678
+ else if (depth < topMost.depth) {
136679
+ topMost.declarationNames = [decl];
136680
+ }
136681
+ topMost.depth = depth;
136682
+ return topMost;
136683
+ }, { depth: Infinity, declarationNames: [] }).declarationNames;
136684
+ function getDepth(declaration) {
136685
+ var depth = 0;
136686
+ while (declaration) {
136687
+ declaration = ts.getContainerNode(declaration);
136688
+ depth++;
136689
+ }
136690
+ return depth;
136691
+ }
136692
+ }
136693
+ Core.getTopMostDeclarationNamesInFile = getTopMostDeclarationNamesInFile;
136462
136694
  function someSignatureUsage(signature, sourceFiles, checker, cb) {
136463
136695
  if (!signature.name || !ts.isIdentifier(signature.name))
136464
136696
  return false;
@@ -138091,7 +138323,9 @@ var ts;
138091
138323
  (function (ts) {
138092
138324
  var GoToDefinition;
138093
138325
  (function (GoToDefinition) {
138094
- function getDefinitionAtPosition(program, sourceFile, position) {
138326
+ function getDefinitionAtPosition(program, sourceFile, position, aliasesOnly) {
138327
+ var _a;
138328
+ var _b;
138095
138329
  var resolvedRef = getReferenceAtPosition(sourceFile, position, program);
138096
138330
  var fileReferenceDefinition = resolvedRef && [getDefinitionInfoForFileReference(resolvedRef.reference.fileName, resolvedRef.fileName, resolvedRef.unverified)] || ts.emptyArray;
138097
138331
  if (resolvedRef === null || resolvedRef === void 0 ? void 0 : resolvedRef.file) {
@@ -138114,17 +138348,50 @@ var ts;
138114
138348
  }
138115
138349
  if (ts.isStaticModifier(node) && ts.isClassStaticBlockDeclaration(node.parent)) {
138116
138350
  var classDecl = node.parent.parent;
138117
- var symbol_1 = getSymbol(classDecl, typeChecker);
138351
+ var _c = getSymbol(classDecl, typeChecker), symbol_1 = _c.symbol, isAliasTarget_1 = _c.isAliasTarget, failedAliasResolution_1 = _c.failedAliasResolution;
138352
+ if (aliasesOnly && !isAliasTarget_1)
138353
+ return undefined;
138118
138354
  var staticBlocks = ts.filter(classDecl.members, ts.isClassStaticBlockDeclaration);
138119
138355
  var containerName_1 = symbol_1 ? typeChecker.symbolToString(symbol_1, classDecl) : "";
138120
138356
  var sourceFile_1 = node.getSourceFile();
138121
138357
  return ts.map(staticBlocks, function (staticBlock) {
138122
138358
  var pos = ts.moveRangePastModifiers(staticBlock).pos;
138123
138359
  pos = ts.skipTrivia(sourceFile_1.text, pos);
138124
- return createDefinitionInfoFromName(typeChecker, staticBlock, "constructor" /* constructorImplementationElement */, "static {}", containerName_1, { start: pos, length: "static".length });
138360
+ return createDefinitionInfoFromName(typeChecker, staticBlock, "constructor" /* constructorImplementationElement */, "static {}", containerName_1, isAliasTarget_1, failedAliasResolution_1, { start: pos, length: "static".length });
138125
138361
  });
138126
138362
  }
138127
- var symbol = getSymbol(node, typeChecker);
138363
+ var _d = getSymbol(node, typeChecker), symbol = _d.symbol, isAliasTarget = _d.isAliasTarget, failedAliasResolution = _d.failedAliasResolution;
138364
+ var fallbackNode = node;
138365
+ if (aliasesOnly && failedAliasResolution) {
138366
+ // We couldn't resolve the specific import, try on the module specifier.
138367
+ var importDeclaration = ts.findAncestor(node, ts.isAnyImportOrBareOrAccessedRequire);
138368
+ var moduleSpecifier = importDeclaration && ts.tryGetModuleSpecifierFromDeclaration(importDeclaration);
138369
+ if (moduleSpecifier) {
138370
+ (_a = getSymbol(moduleSpecifier, typeChecker), symbol = _a.symbol, isAliasTarget = _a.isAliasTarget, failedAliasResolution = _a.failedAliasResolution);
138371
+ fallbackNode = moduleSpecifier;
138372
+ }
138373
+ }
138374
+ if (!symbol && ts.isModuleSpecifierLike(fallbackNode)) {
138375
+ // We couldn't resolve the module specifier as an external module, but it could
138376
+ // be that module resolution succeeded but the target was not a module.
138377
+ var ref = (_b = sourceFile.resolvedModules) === null || _b === void 0 ? void 0 : _b.get(fallbackNode.text, ts.getModeForUsageLocation(sourceFile, fallbackNode));
138378
+ if (ref) {
138379
+ return [{
138380
+ name: fallbackNode.text,
138381
+ fileName: ref.resolvedFileName,
138382
+ containerName: undefined,
138383
+ containerKind: undefined,
138384
+ kind: "script" /* scriptElement */,
138385
+ textSpan: ts.createTextSpan(0, 0),
138386
+ isAliasTarget: true,
138387
+ failedAliasResolution: failedAliasResolution,
138388
+ isAmbient: ts.isDeclarationFileName(ref.resolvedFileName),
138389
+ unverified: fallbackNode !== node,
138390
+ }];
138391
+ }
138392
+ }
138393
+ if (aliasesOnly && !isAliasTarget)
138394
+ return undefined;
138128
138395
  // Could not find a symbol e.g. node is string or number keyword,
138129
138396
  // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
138130
138397
  if (!symbol) {
@@ -138133,14 +138400,14 @@ var ts;
138133
138400
  var calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
138134
138401
  // Don't go to the component constructor definition for a JSX element, just go to the component definition.
138135
138402
  if (calledDeclaration && !(ts.isJsxOpeningLikeElement(node.parent) && isConstructorLike(calledDeclaration))) {
138136
- var sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
138403
+ var sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration, isAliasTarget, failedAliasResolution);
138137
138404
  // For a function, if this is the original function definition, return just sigInfo.
138138
138405
  // If this is the original constructor definition, parent is the class.
138139
138406
  if (typeChecker.getRootSymbols(symbol).some(function (s) { return symbolMatchesSignature(s, calledDeclaration); })) {
138140
138407
  return [sigInfo];
138141
138408
  }
138142
138409
  else {
138143
- var defs = getDefinitionFromSymbol(typeChecker, symbol, node, calledDeclaration) || ts.emptyArray;
138410
+ var defs = getDefinitionFromSymbol(typeChecker, symbol, node, isAliasTarget, failedAliasResolution, calledDeclaration) || ts.emptyArray;
138144
138411
  // For a 'super()' call, put the signature first, else put the variable first.
138145
138412
  return node.kind === 106 /* SuperKeyword */ ? __spreadArray([sigInfo], defs, true) : __spreadArray(__spreadArray([], defs, true), [sigInfo], false);
138146
138413
  }
@@ -138152,7 +138419,7 @@ var ts;
138152
138419
  // assignment. This case and others are handled by the following code.
138153
138420
  if (node.parent.kind === 296 /* ShorthandPropertyAssignment */) {
138154
138421
  var shorthandSymbol_1 = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
138155
- var definitions = (shorthandSymbol_1 === null || shorthandSymbol_1 === void 0 ? void 0 : shorthandSymbol_1.declarations) ? shorthandSymbol_1.declarations.map(function (decl) { return createDefinitionInfo(decl, typeChecker, shorthandSymbol_1, node); }) : ts.emptyArray;
138422
+ var definitions = (shorthandSymbol_1 === null || shorthandSymbol_1 === void 0 ? void 0 : shorthandSymbol_1.declarations) ? shorthandSymbol_1.declarations.map(function (decl) { return createDefinitionInfo(decl, typeChecker, shorthandSymbol_1, node, isAliasTarget, failedAliasResolution); }) : ts.emptyArray;
138156
138423
  return ts.concatenate(definitions, getDefinitionFromObjectLiteralElement(typeChecker, node) || ts.emptyArray);
138157
138424
  }
138158
138425
  // If the node is the name of a BindingElement within an ObjectBindingPattern instead of just returning the
@@ -138175,7 +138442,7 @@ var ts;
138175
138442
  return prop && getDefinitionFromSymbol(typeChecker, prop, node);
138176
138443
  });
138177
138444
  }
138178
- return ts.concatenate(fileReferenceDefinition, getDefinitionFromObjectLiteralElement(typeChecker, node) || getDefinitionFromSymbol(typeChecker, symbol, node));
138445
+ return ts.concatenate(fileReferenceDefinition, getDefinitionFromObjectLiteralElement(typeChecker, node) || getDefinitionFromSymbol(typeChecker, symbol, node, isAliasTarget, failedAliasResolution));
138179
138446
  }
138180
138447
  GoToDefinition.getDefinitionAtPosition = getDefinitionAtPosition;
138181
138448
  /**
@@ -138273,24 +138540,24 @@ var ts;
138273
138540
  return undefined;
138274
138541
  }
138275
138542
  if (ts.isImportMeta(node.parent) && node.parent.name === node) {
138276
- return definitionFromType(typeChecker.getTypeAtLocation(node.parent), typeChecker, node.parent);
138543
+ return definitionFromType(typeChecker.getTypeAtLocation(node.parent), typeChecker, node.parent, /*isAliasTarget*/ false, /*failedAliasResolution*/ false);
138277
138544
  }
138278
- var symbol = getSymbol(node, typeChecker);
138545
+ var _a = getSymbol(node, typeChecker), symbol = _a.symbol, isAliasTarget = _a.isAliasTarget, failedAliasResolution = _a.failedAliasResolution;
138279
138546
  if (!symbol)
138280
138547
  return undefined;
138281
138548
  var typeAtLocation = typeChecker.getTypeOfSymbolAtLocation(symbol, node);
138282
138549
  var returnType = tryGetReturnTypeOfFunction(symbol, typeAtLocation, typeChecker);
138283
- var fromReturnType = returnType && definitionFromType(returnType, typeChecker, node);
138550
+ var fromReturnType = returnType && definitionFromType(returnType, typeChecker, node, isAliasTarget, failedAliasResolution);
138284
138551
  // If a function returns 'void' or some other type with no definition, just return the function definition.
138285
- var typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
138552
+ var typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node, isAliasTarget, failedAliasResolution);
138286
138553
  return typeDefinitions.length ? typeDefinitions
138287
- : !(symbol.flags & 111551 /* Value */) && symbol.flags & 788968 /* Type */ ? getDefinitionFromSymbol(typeChecker, ts.skipAlias(symbol, typeChecker), node)
138554
+ : !(symbol.flags & 111551 /* Value */) && symbol.flags & 788968 /* Type */ ? getDefinitionFromSymbol(typeChecker, ts.skipAlias(symbol, typeChecker), node, isAliasTarget, failedAliasResolution)
138288
138555
  : undefined;
138289
138556
  }
138290
138557
  GoToDefinition.getTypeDefinitionAtPosition = getTypeDefinitionAtPosition;
138291
- function definitionFromType(type, checker, node) {
138558
+ function definitionFromType(type, checker, node, isAliasTarget, failedAliasResolution) {
138292
138559
  return ts.flatMap(type.isUnion() && !(type.flags & 32 /* Enum */) ? type.types : [type], function (t) {
138293
- return t.symbol && getDefinitionFromSymbol(checker, t.symbol, node);
138560
+ return t.symbol && getDefinitionFromSymbol(checker, t.symbol, node, isAliasTarget, failedAliasResolution);
138294
138561
  });
138295
138562
  }
138296
138563
  function tryGetReturnTypeOfFunction(symbol, type, checker) {
@@ -138305,8 +138572,8 @@ var ts;
138305
138572
  }
138306
138573
  return undefined;
138307
138574
  }
138308
- function getDefinitionAndBoundSpan(program, sourceFile, position) {
138309
- var definitions = getDefinitionAtPosition(program, sourceFile, position);
138575
+ function getDefinitionAndBoundSpan(program, sourceFile, position, aliasesOnly) {
138576
+ var definitions = getDefinitionAtPosition(program, sourceFile, position, aliasesOnly);
138310
138577
  if (!definitions || definitions.length === 0) {
138311
138578
  return undefined;
138312
138579
  }
@@ -138332,13 +138599,17 @@ var ts;
138332
138599
  // get the aliased symbol instead. This allows for goto def on an import e.g.
138333
138600
  // import {A, B} from "mod";
138334
138601
  // to jump to the implementation directly.
138602
+ var failedAliasResolution = false;
138335
138603
  if ((symbol === null || symbol === void 0 ? void 0 : symbol.declarations) && symbol.flags & 2097152 /* Alias */ && shouldSkipAlias(node, symbol.declarations[0])) {
138336
138604
  var aliased = checker.getAliasedSymbol(symbol);
138337
138605
  if (aliased.declarations) {
138338
- return aliased;
138606
+ return { symbol: aliased, isAliasTarget: true };
138607
+ }
138608
+ else {
138609
+ failedAliasResolution = true;
138339
138610
  }
138340
138611
  }
138341
- return symbol;
138612
+ return { symbol: symbol, isAliasTarget: !!(symbol && ts.isExternalModuleSymbol(symbol)), failedAliasResolution: failedAliasResolution };
138342
138613
  }
138343
138614
  // Go to the original declaration for cases:
138344
138615
  //
@@ -138352,26 +138623,45 @@ var ts;
138352
138623
  if (node.parent === declaration) {
138353
138624
  return true;
138354
138625
  }
138355
- switch (declaration.kind) {
138356
- case 266 /* ImportClause */:
138357
- case 264 /* ImportEqualsDeclaration */:
138358
- return true;
138359
- case 269 /* ImportSpecifier */:
138360
- return declaration.parent.kind === 268 /* NamedImports */;
138361
- case 202 /* BindingElement */:
138362
- case 253 /* VariableDeclaration */:
138363
- return ts.isInJSFile(declaration) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(declaration);
138364
- default:
138365
- return false;
138626
+ if (declaration.kind === 267 /* NamespaceImport */) {
138627
+ return false;
138366
138628
  }
138629
+ return true;
138630
+ }
138631
+ /**
138632
+ * ```ts
138633
+ * function f() {}
138634
+ * f.foo = 0;
138635
+ * ```
138636
+ *
138637
+ * Here, `f` has two declarations: the function declaration, and the identifier in the next line.
138638
+ * The latter is a declaration for `f` because it gives `f` the `SymbolFlags.Namespace` meaning so
138639
+ * it can contain `foo`. However, that declaration is pretty uninteresting and not intuitively a
138640
+ * "definition" for `f`. Ideally, the question we'd like to answer is "what SymbolFlags does this
138641
+ * declaration contribute to the symbol for `f`?" If the answer is just `Namespace` and the
138642
+ * declaration looks like an assignment, that declaration is in no sense a definition for `f`.
138643
+ * But that information is totally lost during binding and/or symbol merging, so we need to do
138644
+ * our best to reconstruct it or use other heuristics. This function (and the logic around its
138645
+ * calling) covers our tests but feels like a hack, and it would be great if someone could come
138646
+ * up with a more precise definition of what counts as a definition.
138647
+ */
138648
+ function isExpandoDeclaration(node) {
138649
+ if (!ts.isAssignmentDeclaration(node))
138650
+ return false;
138651
+ var containingAssignment = ts.findAncestor(node, function (p) {
138652
+ if (ts.isAssignmentExpression(p))
138653
+ return true;
138654
+ if (!ts.isAssignmentDeclaration(p))
138655
+ return "quit";
138656
+ return false;
138657
+ });
138658
+ return !!containingAssignment && ts.getAssignmentDeclarationKind(containingAssignment) === 5 /* Property */;
138367
138659
  }
138368
- function getDefinitionFromSymbol(typeChecker, symbol, node, declarationNode) {
138369
- // There are cases when you extend a function by adding properties to it afterwards,
138370
- // we want to strip those extra properties.
138371
- // For deduping purposes, we also want to exclude any declarationNodes if provided.
138372
- var filteredDeclarations = ts.filter(symbol.declarations, function (d) { return d !== declarationNode && (!ts.isAssignmentDeclaration(d) || d === symbol.valueDeclaration); })
138373
- || undefined;
138374
- return getConstructSignatureDefinition() || getCallSignatureDefinition() || ts.map(filteredDeclarations, function (declaration) { return createDefinitionInfo(declaration, typeChecker, symbol, node); });
138660
+ function getDefinitionFromSymbol(typeChecker, symbol, node, isAliasTarget, failedAliasResolution, excludeDeclaration) {
138661
+ var filteredDeclarations = ts.filter(symbol.declarations, function (d) { return d !== excludeDeclaration; });
138662
+ var withoutExpandos = ts.filter(filteredDeclarations, function (d) { return !isExpandoDeclaration(d); });
138663
+ var results = ts.some(withoutExpandos) ? withoutExpandos : filteredDeclarations;
138664
+ return getConstructSignatureDefinition() || getCallSignatureDefinition() || ts.map(results, function (declaration) { return createDefinitionInfo(declaration, typeChecker, symbol, node, isAliasTarget, failedAliasResolution); });
138375
138665
  function getConstructSignatureDefinition() {
138376
138666
  // Applicable only if we are in a new expression, or we are on a constructor declaration
138377
138667
  // and in either case the symbol has a construct signature definition, i.e. class
@@ -138395,26 +138685,27 @@ var ts;
138395
138685
  return declarations.length
138396
138686
  ? declarationsWithBody.length !== 0
138397
138687
  ? declarationsWithBody.map(function (x) { return createDefinitionInfo(x, typeChecker, symbol, node); })
138398
- : [createDefinitionInfo(ts.last(declarations), typeChecker, symbol, node)]
138688
+ : [createDefinitionInfo(ts.last(declarations), typeChecker, symbol, node, isAliasTarget, failedAliasResolution)]
138399
138689
  : undefined;
138400
138690
  }
138401
138691
  }
138402
138692
  /** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */
138403
- function createDefinitionInfo(declaration, checker, symbol, node) {
138693
+ function createDefinitionInfo(declaration, checker, symbol, node, isAliasTarget, failedAliasResolution) {
138404
138694
  var symbolName = checker.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
138405
138695
  var symbolKind = ts.SymbolDisplay.getSymbolKind(checker, symbol, node);
138406
138696
  var containerName = symbol.parent ? checker.symbolToString(symbol.parent, node) : "";
138407
- return createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName);
138697
+ return createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName, isAliasTarget, failedAliasResolution);
138408
138698
  }
138699
+ GoToDefinition.createDefinitionInfo = createDefinitionInfo;
138409
138700
  /** Creates a DefinitionInfo directly from the name of a declaration. */
138410
- function createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName, textSpan) {
138701
+ function createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName, isAliasTarget, failedAliasResolution, textSpan) {
138411
138702
  var sourceFile = declaration.getSourceFile();
138412
138703
  if (!textSpan) {
138413
138704
  var name = ts.getNameOfDeclaration(declaration) || declaration;
138414
138705
  textSpan = ts.createTextSpanFromNode(name, sourceFile);
138415
138706
  }
138416
138707
  return __assign(__assign({ fileName: sourceFile.fileName, textSpan: textSpan, kind: symbolKind, name: symbolName, containerKind: undefined, // TODO: GH#18217
138417
- containerName: containerName }, ts.FindAllReferences.toContextSpan(textSpan, sourceFile, ts.FindAllReferences.getContextNode(declaration))), { isLocal: !isDefinitionVisible(checker, declaration) });
138708
+ containerName: containerName }, ts.FindAllReferences.toContextSpan(textSpan, sourceFile, ts.FindAllReferences.getContextNode(declaration))), { isLocal: !isDefinitionVisible(checker, declaration), isAmbient: !!(declaration.flags & 8388608 /* Ambient */), isAliasTarget: isAliasTarget, failedAliasResolution: failedAliasResolution });
138418
138709
  }
138419
138710
  function isDefinitionVisible(checker, declaration) {
138420
138711
  if (checker.isDeclarationVisible(declaration))
@@ -138447,8 +138738,8 @@ var ts;
138447
138738
  return false;
138448
138739
  }
138449
138740
  }
138450
- function createDefinitionFromSignatureDeclaration(typeChecker, decl) {
138451
- return createDefinitionInfo(decl, typeChecker, decl.symbol, decl);
138741
+ function createDefinitionFromSignatureDeclaration(typeChecker, decl, isAliasTarget, failedAliasResolution) {
138742
+ return createDefinitionInfo(decl, typeChecker, decl.symbol, decl, isAliasTarget, failedAliasResolution);
138452
138743
  }
138453
138744
  function findReferenceInPosition(refs, pos) {
138454
138745
  return ts.find(refs, function (ref) { return ts.textRangeContainsPositionInclusive(ref, pos); });
@@ -138463,6 +138754,7 @@ var ts;
138463
138754
  containerName: undefined,
138464
138755
  containerKind: undefined,
138465
138756
  unverified: unverified,
138757
+ isAliasTarget: true,
138466
138758
  };
138467
138759
  }
138468
138760
  /** Returns a CallLikeExpression where `node` is the target being invoked. */
@@ -141516,41 +141808,6 @@ var ts;
141516
141808
  if (ts.scanner.getToken() === 1 /* EndOfFileToken */) {
141517
141809
  break;
141518
141810
  }
141519
- if (ts.scanner.getToken() === 15 /* TemplateHead */) {
141520
- var stack = [ts.scanner.getToken()];
141521
- var token = ts.scanner.scan();
141522
- loop: while (ts.length(stack)) {
141523
- switch (token) {
141524
- case 1 /* EndOfFileToken */:
141525
- break loop;
141526
- case 100 /* ImportKeyword */:
141527
- tryConsumeImport();
141528
- break;
141529
- case 15 /* TemplateHead */:
141530
- stack.push(token);
141531
- break;
141532
- case 18 /* OpenBraceToken */:
141533
- if (ts.length(stack)) {
141534
- stack.push(token);
141535
- }
141536
- break;
141537
- case 19 /* CloseBraceToken */:
141538
- if (ts.length(stack)) {
141539
- if (ts.lastOrUndefined(stack) === 15 /* TemplateHead */) {
141540
- if (ts.scanner.reScanTemplateToken(/* isTaggedTemplate */ false) === 17 /* TemplateTail */) {
141541
- stack.pop();
141542
- }
141543
- }
141544
- else {
141545
- stack.pop();
141546
- }
141547
- }
141548
- break;
141549
- }
141550
- token = ts.scanner.scan();
141551
- }
141552
- nextToken();
141553
- }
141554
141811
  // check if at least one of alternative have moved scanner forward
141555
141812
  if (tryConsumeDeclare() ||
141556
141813
  tryConsumeImport() ||
@@ -151496,9 +151753,10 @@ var ts;
151496
151753
  // 2. add "member3" to the second import statement's import list
151497
151754
  // and it is up to the user to decide which one fits best.
151498
151755
  return ts.firstDefined(existingImports, function (_a) {
151756
+ var _b;
151499
151757
  var declaration = _a.declaration;
151500
151758
  var namespacePrefix = getNamespaceLikeImportText(declaration);
151501
- var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
151759
+ var moduleSpecifier = (_b = ts.tryGetModuleSpecifierFromDeclaration(declaration)) === null || _b === void 0 ? void 0 : _b.text;
151502
151760
  if (namespacePrefix && moduleSpecifier) {
151503
151761
  var moduleSymbol = getTargetModuleFromNamespaceLikeImport(declaration, checker);
151504
151762
  if (moduleSymbol && moduleSymbol.exports.has(ts.escapeLeadingUnderscores(symbolName))) {
@@ -151674,8 +151932,9 @@ var ts;
151674
151932
  return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
151675
151933
  }
151676
151934
  function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
151935
+ var _b;
151677
151936
  var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
151678
- var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
151937
+ var moduleSpecifier = (_b = ts.tryGetModuleSpecifierFromDeclaration(declaration)) === null || _b === void 0 ? void 0 : _b.text;
151679
151938
  if (moduleSpecifier) {
151680
151939
  var addAsTypeOnly = useRequire
151681
151940
  ? 4 /* NotAllowed */
@@ -163484,9 +163743,9 @@ var ts;
163484
163743
  synchronizeHostData();
163485
163744
  return ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position);
163486
163745
  }
163487
- function getDefinitionAndBoundSpan(fileName, position) {
163746
+ function getDefinitionAndBoundSpan(fileName, position, aliasesOnly) {
163488
163747
  synchronizeHostData();
163489
- return ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position);
163748
+ return ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position, aliasesOnly);
163490
163749
  }
163491
163750
  function getTypeDefinitionAtPosition(fileName, position) {
163492
163751
  synchronizeHostData();
@@ -166238,6 +166497,9 @@ var ts;
166238
166497
  CommandTypes["SignatureHelp"] = "signatureHelp";
166239
166498
  /* @internal */
166240
166499
  CommandTypes["SignatureHelpFull"] = "signatureHelp-full";
166500
+ CommandTypes["SourceDefinitionAndBoundSpan"] = "sourceDefinitionAndBoundSpan";
166501
+ /* @internal */
166502
+ CommandTypes["SourceDefinitionAndBoundSpanFull"] = "sourceDefinitionAndBoundSpan-full";
166241
166503
  CommandTypes["Status"] = "status";
166242
166504
  CommandTypes["TypeDefinition"] = "typeDefinition";
166243
166505
  CommandTypes["ProjectInfo"] = "projectInfo";
@@ -167107,6 +167369,7 @@ var ts;
167107
167369
  ProjectKind[ProjectKind["Configured"] = 1] = "Configured";
167108
167370
  ProjectKind[ProjectKind["External"] = 2] = "External";
167109
167371
  ProjectKind[ProjectKind["AutoImportProvider"] = 3] = "AutoImportProvider";
167372
+ ProjectKind[ProjectKind["Auxiliary"] = 4] = "Auxiliary";
167110
167373
  })(ProjectKind = server.ProjectKind || (server.ProjectKind = {}));
167111
167374
  /* @internal */
167112
167375
  function countEachFileTypes(infos, includeSizes) {
@@ -168552,6 +168815,17 @@ var ts;
168552
168815
  Project.prototype.getIncompleteCompletionsCache = function () {
168553
168816
  return this.projectService.getIncompleteCompletionsCache();
168554
168817
  };
168818
+ Project.prototype.withAuxiliaryProjectForFiles = function (fileNames, cb) {
168819
+ var options = __assign(__assign({}, this.getCompilerOptions()), { noDtsResolution: true, allowJs: true, maxNodeModuleJsDepth: 3, diagnostics: false, skipLibCheck: true, sourceMap: false, types: ts.emptyArray, lib: ts.emptyArray, noLib: true });
168820
+ var project = new AuxiliaryProject(this.projectService, this.documentRegistry, options);
168821
+ for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
168822
+ var fileName = fileNames_1[_i];
168823
+ project.addRoot(this.getScriptInfo(fileName));
168824
+ }
168825
+ project.updateGraph();
168826
+ cb(project);
168827
+ project.close();
168828
+ };
168555
168829
  return Project;
168556
168830
  }());
168557
168831
  server.Project = Project;
@@ -168663,6 +168937,22 @@ var ts;
168663
168937
  return InferredProject;
168664
168938
  }(Project));
168665
168939
  server.InferredProject = InferredProject;
168940
+ var AuxiliaryProject = /** @class */ (function (_super) {
168941
+ __extends(AuxiliaryProject, _super);
168942
+ function AuxiliaryProject(projectService, documentRegistry, parentCompilerOptions) {
168943
+ var _this = this;
168944
+ var options = __assign(__assign({}, parentCompilerOptions), { resolveJsOnly: true, allowJs: true, maxNodeModuleJsDepth: 3, diagnostics: false, skipLibCheck: true, sourceMap: false, types: ts.emptyArray, lib: ts.emptyArray, noLib: true });
168945
+ _this = _super.call(this, "js-analysis", ProjectKind.Auxiliary, projectService, documentRegistry,
168946
+ /*hasExplicitListOfFiles*/ false,
168947
+ /*lastFileExceededProgramSize*/ undefined, options,
168948
+ /*compileOnSaveEnabled*/ false,
168949
+ /*watchOptions*/ undefined, projectService.host,
168950
+ /*currentDirectory*/ undefined) || this;
168951
+ return _this;
168952
+ }
168953
+ return AuxiliaryProject;
168954
+ }(Project));
168955
+ server.AuxiliaryProject = AuxiliaryProject;
168666
168956
  var AutoImportProviderProject = /** @class */ (function (_super) {
168667
168957
  __extends(AutoImportProviderProject, _super);
168668
168958
  /*@internal*/
@@ -170551,8 +170841,8 @@ var ts;
170551
170841
  this.projectToSizeMap.set(name, 0);
170552
170842
  this.projectToSizeMap.forEach(function (val) { return (availableSpace -= (val || 0)); });
170553
170843
  var totalNonTsFileSize = 0;
170554
- for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
170555
- var f = fileNames_1[_i];
170844
+ for (var _i = 0, fileNames_2 = fileNames; _i < fileNames_2.length; _i++) {
170845
+ var f = fileNames_2[_i];
170556
170846
  var fileName = propertyReader.getFileName(f);
170557
170847
  if (ts.hasTSFileExtension(fileName)) {
170558
170848
  continue;
@@ -172908,15 +173198,23 @@ var ts;
172908
173198
  return ts.deduplicate(outputs, ts.equateValues);
172909
173199
  }
172910
173200
  ;
173201
+ function createDocumentSpanSet() {
173202
+ return ts.createSet(function (_a) {
173203
+ var textSpan = _a.textSpan;
173204
+ return textSpan.start + 100003 * textSpan.length;
173205
+ }, ts.documentSpansEqual);
173206
+ }
172911
173207
  function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
172912
173208
  var providePrefixAndSuffixTextForRename = _a.providePrefixAndSuffixTextForRename;
172913
173209
  var outputs = [];
173210
+ var seen = createDocumentSpanSet();
172914
173211
  combineProjectOutputWorker(projects, defaultProject, initialLocation, function (project, location, tryAddToTodo) {
172915
173212
  var projectOutputs = project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
172916
173213
  if (projectOutputs) {
172917
173214
  for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
172918
173215
  var output = projectOutputs_1[_i];
172919
- if (!ts.contains(outputs, output, ts.documentSpansEqual) && !tryAddToTodo(project, documentSpanLocation(output))) {
173216
+ if (!seen.has(output) && !tryAddToTodo(project, documentSpanLocation(output))) {
173217
+ seen.add(output);
172920
173218
  outputs.push(output);
172921
173219
  }
172922
173220
  }
@@ -173257,6 +173555,12 @@ var ts;
173257
173555
  _a[server.CommandNames.DefinitionAndBoundSpanFull] = function (request) {
173258
173556
  return _this.requiredResponse(_this.getDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false));
173259
173557
  },
173558
+ // [CommandNames.SourceDefinitionAndBoundSpan]: (request: protocol.SourceDefinitionAndBoundSpanRequest) => {
173559
+ // return this.requiredResponse(this.getSourceDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ true));
173560
+ // },
173561
+ // [CommandNames.SourceDefinitionAndBoundSpanFull]: (request: protocol.SourceDefinitionAndBoundSpanRequest) => {
173562
+ // return this.requiredResponse(this.getSourceDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false));
173563
+ // },
173260
173564
  _a[server.CommandNames.EmitOutput] = function (request) {
173261
173565
  return _this.requiredResponse(_this.getEmitOutput(request.arguments));
173262
173566
  },
@@ -173993,10 +174297,34 @@ var ts;
173993
174297
  Session.prototype.mapDefinitionInfoLocations = function (definitions, project) {
173994
174298
  return definitions.map(function (info) {
173995
174299
  var newDocumentSpan = getMappedDocumentSpan(info, project);
173996
- return !newDocumentSpan ? info : __assign(__assign(__assign({}, newDocumentSpan), { containerKind: info.containerKind, containerName: info.containerName, kind: info.kind, name: info.name }), info.unverified && { unverified: info.unverified });
174300
+ return !newDocumentSpan ? info : __assign(__assign(__assign({}, newDocumentSpan), { containerKind: info.containerKind, containerName: info.containerName, kind: info.kind, name: info.name, isAliasTarget: info.isAliasTarget, failedAliasResolution: info.failedAliasResolution }), info.unverified && { unverified: info.unverified });
173997
174301
  });
173998
174302
  };
173999
174303
  Session.prototype.getDefinitionAndBoundSpan = function (args, simplifiedResult) {
174304
+ // const { file, project } = this.getFileAndProject(args);
174305
+ // const position = this.getPositionInFile(args, file);
174306
+ // const scriptInfo = Debug.checkDefined(project.getScriptInfo(file));
174307
+ // const unmappedDefinitionAndBoundSpan = project.getLanguageService().getDefinitionAndBoundSpan(file, position);
174308
+ // if (!unmappedDefinitionAndBoundSpan || !unmappedDefinitionAndBoundSpan.definitions) {
174309
+ // return {
174310
+ // definitions: emptyArray,
174311
+ // textSpan: undefined! // TODO: GH#18217
174312
+ // };
174313
+ // }
174314
+ // const definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan.definitions, project);
174315
+ // const { textSpan } = unmappedDefinitionAndBoundSpan;
174316
+ // if (simplifiedResult) {
174317
+ // return {
174318
+ // definitions: this.mapDefinitionInfo(definitions, project),
174319
+ // textSpan: toProtocolTextSpan(textSpan, scriptInfo)
174320
+ // };
174321
+ // }
174322
+ // return {
174323
+ // definitions: definitions.map(Session.mapToOriginalLocation),
174324
+ // textSpan,
174325
+ // };
174326
+ // }
174327
+ // private getSourceDefinitionAndBoundSpan(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.DefinitionInfoAndBoundSpan | DefinitionInfoAndBoundSpan {
174000
174328
  var _a = this.getFileAndProject(args), file = _a.file, project = _a.project;
174001
174329
  var position = this.getPositionInFile(args, file);
174002
174330
  var scriptInfo = ts.Debug.checkDefined(project.getScriptInfo(file));
@@ -174007,7 +174335,31 @@ var ts;
174007
174335
  textSpan: undefined // TODO: GH#18217
174008
174336
  };
174009
174337
  }
174010
- var definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan.definitions, project);
174338
+ var definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan.definitions, project).slice();
174339
+ var needsJsResolution = !ts.some(definitions, function (d) { return !!d.isAliasTarget && !d.isAmbient; }) || ts.some(definitions, function (d) { return !!d.failedAliasResolution; });
174340
+ if (needsJsResolution) {
174341
+ project.withAuxiliaryProjectForFiles([file], function (auxiliaryProject) {
174342
+ var ls = auxiliaryProject.getLanguageService();
174343
+ var jsDefinitions = ls.getDefinitionAndBoundSpan(file, position, /*aliasesOnly*/ true);
174344
+ if (ts.some(jsDefinitions === null || jsDefinitions === void 0 ? void 0 : jsDefinitions.definitions)) {
174345
+ for (var _i = 0, _a = jsDefinitions.definitions; _i < _a.length; _i++) {
174346
+ var jsDefinition = _a[_i];
174347
+ if (jsDefinition.unverified) {
174348
+ var refined = tryRefineDefinition(jsDefinition, project.getLanguageService().getProgram(), ls.getProgram());
174349
+ if (ts.some(refined)) {
174350
+ for (var _b = 0, _c = refined || server.emptyArray; _b < _c.length; _b++) {
174351
+ var def = _c[_b];
174352
+ ts.pushIfUnique(definitions, def, ts.documentSpansEqual);
174353
+ }
174354
+ continue;
174355
+ }
174356
+ }
174357
+ ts.pushIfUnique(definitions, jsDefinition, ts.documentSpansEqual);
174358
+ }
174359
+ }
174360
+ });
174361
+ }
174362
+ definitions = definitions.filter(function (d) { return !d.isAmbient && !d.failedAliasResolution; });
174011
174363
  var textSpan = unmappedDefinitionAndBoundSpan.textSpan;
174012
174364
  if (simplifiedResult) {
174013
174365
  return {
@@ -174019,6 +174371,32 @@ var ts;
174019
174371
  definitions: definitions.map(Session.mapToOriginalLocation),
174020
174372
  textSpan: textSpan,
174021
174373
  };
174374
+ function tryRefineDefinition(definition, program, auxiliaryProgram) {
174375
+ var _a, _b;
174376
+ var fileToSearch = auxiliaryProgram.getSourceFile(definition.fileName);
174377
+ if (!fileToSearch) {
174378
+ return undefined;
174379
+ }
174380
+ var initialNode = ts.getTouchingPropertyName(program.getSourceFile(file), position);
174381
+ var symbol = program.getTypeChecker().getSymbolAtLocation(initialNode);
174382
+ if (!symbol || !symbol.declarations || ts.some(symbol.declarations, ts.isFreelyNameableImport)) {
174383
+ return undefined;
174384
+ }
174385
+ var nameToSearch = ((_b = (_a = ts.find(symbol.declarations, ts.isImportSpecifier)) === null || _a === void 0 ? void 0 : _a.propertyName) === null || _b === void 0 ? void 0 : _b.text) || symbol.name;
174386
+ return searchForDeclaration(nameToSearch, fileToSearch, auxiliaryProgram);
174387
+ }
174388
+ function searchForDeclaration(declarationName, fileToSearch, auxiliaryProgram) {
174389
+ var matches = ts.FindAllReferences.Core.getTopMostDeclarationNamesInFile(declarationName, fileToSearch);
174390
+ return ts.mapDefined(matches, function (match) {
174391
+ var symbol = auxiliaryProgram.getTypeChecker().getSymbolAtLocation(match);
174392
+ var decl = ts.getDeclarationFromName(match);
174393
+ if (symbol && decl) {
174394
+ // I think the last argument to this is supposed to be the start node, but it doesn't seem important.
174395
+ // Callers internal to GoToDefinition already get confused about this.
174396
+ return ts.GoToDefinition.createDefinitionInfo(decl, auxiliaryProgram.getTypeChecker(), symbol, decl);
174397
+ }
174398
+ });
174399
+ }
174022
174400
  };
174023
174401
  Session.prototype.getEmitOutput = function (args) {
174024
174402
  var _a = this.getFileAndProject(args), file = _a.file, project = _a.project;
@@ -174300,6 +174678,7 @@ var ts;
174300
174678
  var projects = this.getProjects(args);
174301
174679
  var fileName = args.file;
174302
174680
  var references = [];
174681
+ var seen = createDocumentSpanSet();
174303
174682
  forEachProjectInProjects(projects, /*path*/ undefined, function (project) {
174304
174683
  if (project.getCancellationToken().isCancellationRequested())
174305
174684
  return;
@@ -174307,8 +174686,9 @@ var ts;
174307
174686
  if (projectOutputs) {
174308
174687
  for (var _i = 0, projectOutputs_3 = projectOutputs; _i < projectOutputs_3.length; _i++) {
174309
174688
  var referenceEntry = projectOutputs_3[_i];
174310
- if (!ts.contains(references, referenceEntry, ts.documentSpansEqual)) {
174689
+ if (!seen.has(referenceEntry)) {
174311
174690
  references.push(referenceEntry);
174691
+ seen.add(referenceEntry);
174312
174692
  }
174313
174693
  }
174314
174694
  }