@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.
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-insiders.20220311";
103
+ ts.version = ts.versionMajorMinor + ".0-insiders.20220315";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -1468,6 +1468,159 @@ var ts;
1468
1468
  return createMultiMap();
1469
1469
  }
1470
1470
  ts.createUnderscoreEscapedMultiMap = createUnderscoreEscapedMultiMap;
1471
+ /**
1472
+ * Creates a Set with custom equality and hash code functionality. This is useful when you
1473
+ * want to use something looser than object identity - e.g. "has the same span".
1474
+ *
1475
+ * If `equals(a, b)`, it must be the case that `getHashCode(a) === getHashCode(b)`.
1476
+ * The converse is not required.
1477
+ *
1478
+ * To facilitate a perf optimization (lazy allocation of bucket arrays), `TElement` is
1479
+ * assumed not to be an array type.
1480
+ */
1481
+ function createSet(getHashCode, equals) {
1482
+ var multiMap = new ts.Map();
1483
+ var size = 0;
1484
+ function getElementIterator() {
1485
+ var valueIt = multiMap.values();
1486
+ var arrayIt;
1487
+ return {
1488
+ next: function () {
1489
+ while (true) {
1490
+ if (arrayIt) {
1491
+ var n = arrayIt.next();
1492
+ if (!n.done) {
1493
+ return { value: n.value };
1494
+ }
1495
+ arrayIt = undefined;
1496
+ }
1497
+ else {
1498
+ var n = valueIt.next();
1499
+ if (n.done) {
1500
+ return { value: undefined, done: true };
1501
+ }
1502
+ if (!isArray(n.value)) {
1503
+ return { value: n.value };
1504
+ }
1505
+ arrayIt = arrayIterator(n.value);
1506
+ }
1507
+ }
1508
+ }
1509
+ };
1510
+ }
1511
+ var set = {
1512
+ has: function (element) {
1513
+ var hash = getHashCode(element);
1514
+ if (!multiMap.has(hash))
1515
+ return false;
1516
+ var candidates = multiMap.get(hash);
1517
+ if (!isArray(candidates))
1518
+ return equals(candidates, element);
1519
+ for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
1520
+ var candidate = candidates_1[_i];
1521
+ if (equals(candidate, element)) {
1522
+ return true;
1523
+ }
1524
+ }
1525
+ return false;
1526
+ },
1527
+ add: function (element) {
1528
+ var hash = getHashCode(element);
1529
+ if (multiMap.has(hash)) {
1530
+ var values = multiMap.get(hash);
1531
+ if (isArray(values)) {
1532
+ if (!contains(values, element, equals)) {
1533
+ values.push(element);
1534
+ size++;
1535
+ }
1536
+ }
1537
+ else {
1538
+ var value = values;
1539
+ if (!equals(value, element)) {
1540
+ multiMap.set(hash, [value, element]);
1541
+ size++;
1542
+ }
1543
+ }
1544
+ }
1545
+ else {
1546
+ multiMap.set(hash, element);
1547
+ size++;
1548
+ }
1549
+ return this;
1550
+ },
1551
+ delete: function (element) {
1552
+ var hash = getHashCode(element);
1553
+ if (!multiMap.has(hash))
1554
+ return false;
1555
+ var candidates = multiMap.get(hash);
1556
+ if (isArray(candidates)) {
1557
+ for (var i = 0; i < candidates.length; i++) {
1558
+ if (equals(candidates[i], element)) {
1559
+ if (candidates.length === 1) {
1560
+ multiMap.delete(hash);
1561
+ }
1562
+ else if (candidates.length === 2) {
1563
+ multiMap.set(hash, candidates[1 - i]);
1564
+ }
1565
+ else {
1566
+ unorderedRemoveItemAt(candidates, i);
1567
+ }
1568
+ size--;
1569
+ return true;
1570
+ }
1571
+ }
1572
+ }
1573
+ else {
1574
+ var candidate = candidates;
1575
+ if (equals(candidate, element)) {
1576
+ multiMap.delete(hash);
1577
+ size--;
1578
+ return true;
1579
+ }
1580
+ }
1581
+ return false;
1582
+ },
1583
+ clear: function () {
1584
+ multiMap.clear();
1585
+ size = 0;
1586
+ },
1587
+ get size() {
1588
+ return size;
1589
+ },
1590
+ forEach: function (action) {
1591
+ for (var _i = 0, _a = arrayFrom(multiMap.values()); _i < _a.length; _i++) {
1592
+ var elements = _a[_i];
1593
+ if (isArray(elements)) {
1594
+ for (var _b = 0, elements_1 = elements; _b < elements_1.length; _b++) {
1595
+ var element = elements_1[_b];
1596
+ action(element, element);
1597
+ }
1598
+ }
1599
+ else {
1600
+ var element = elements;
1601
+ action(element, element);
1602
+ }
1603
+ }
1604
+ },
1605
+ keys: function () {
1606
+ return getElementIterator();
1607
+ },
1608
+ values: function () {
1609
+ return getElementIterator();
1610
+ },
1611
+ entries: function () {
1612
+ var it = getElementIterator();
1613
+ return {
1614
+ next: function () {
1615
+ var n = it.next();
1616
+ return n.done ? n : { value: [n.value, n.value] };
1617
+ }
1618
+ };
1619
+ },
1620
+ };
1621
+ return set;
1622
+ }
1623
+ ts.createSet = createSet;
1471
1624
  /**
1472
1625
  * Tests whether a value is an array.
1473
1626
  */
@@ -1861,8 +2014,8 @@ var ts;
1861
2014
  var maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
1862
2015
  var bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
1863
2016
  var bestCandidate;
1864
- for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
1865
- var candidate = candidates_1[_i];
2017
+ for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
2018
+ var candidate = candidates_2[_i];
1866
2019
  var candidateName = getName(candidate);
1867
2020
  if (candidateName !== undefined && Math.abs(candidateName.length - name.length) <= maximumLengthDifference) {
1868
2021
  if (candidateName === name) {
@@ -14797,6 +14950,10 @@ var ts;
14797
14950
  }
14798
14951
  }
14799
14952
  ts.isAnyImportSyntax = isAnyImportSyntax;
14953
+ function isAnyImportOrBareOrAccessedRequire(node) {
14954
+ return isAnyImportSyntax(node) || isVariableDeclarationInitializedToBareOrAccessedRequire(node);
14955
+ }
14956
+ ts.isAnyImportOrBareOrAccessedRequire = isAnyImportOrBareOrAccessedRequire;
14800
14957
  function isLateVisibilityPaintedStatement(node) {
14801
14958
  switch (node.kind) {
14802
14959
  case 265 /* ImportDeclaration */:
@@ -16375,14 +16532,14 @@ var ts;
16375
16532
  }
16376
16533
  ts.isFunctionSymbol = isFunctionSymbol;
16377
16534
  function tryGetModuleSpecifierFromDeclaration(node) {
16378
- var _a, _b, _c;
16535
+ var _a, _b;
16379
16536
  switch (node.kind) {
16380
16537
  case 253 /* VariableDeclaration */:
16381
- return node.initializer.arguments[0].text;
16538
+ return (_a = ts.findAncestor(node.initializer, function (node) { return isRequireCall(node, /*requireStringLiteralLikeArgument*/ true); })) === null || _a === void 0 ? void 0 : _a.arguments[0];
16382
16539
  case 265 /* ImportDeclaration */:
16383
- return (_a = ts.tryCast(node.moduleSpecifier, ts.isStringLiteralLike)) === null || _a === void 0 ? void 0 : _a.text;
16540
+ return ts.tryCast(node.moduleSpecifier, ts.isStringLiteralLike);
16384
16541
  case 264 /* ImportEqualsDeclaration */:
16385
- 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;
16542
+ return ts.tryCast((_b = ts.tryCast(node.moduleReference, ts.isExternalModuleReference)) === null || _b === void 0 ? void 0 : _b.expression, ts.isStringLiteralLike);
16386
16543
  default:
16387
16544
  ts.Debug.assertNever(node);
16388
16545
  }
@@ -16909,21 +17066,28 @@ var ts;
16909
17066
  // export = <EntityNameExpression>
16910
17067
  // export default <EntityNameExpression>
16911
17068
  // module.exports = <EntityNameExpression>
16912
- // {<Identifier>}
16913
- // {name: <EntityNameExpression>}
17069
+ // module.exports.x = <EntityNameExpression>
17070
+ // const x = require("...")
17071
+ // const { x } = require("...")
17072
+ // const x = require("...").y
17073
+ // const { x } = require("...").y
16914
17074
  function isAliasSymbolDeclaration(node) {
16915
- return node.kind === 264 /* ImportEqualsDeclaration */ ||
17075
+ if (node.kind === 264 /* ImportEqualsDeclaration */ ||
16916
17076
  node.kind === 263 /* NamespaceExportDeclaration */ ||
16917
17077
  node.kind === 266 /* ImportClause */ && !!node.name ||
16918
17078
  node.kind === 267 /* NamespaceImport */ ||
16919
17079
  node.kind === 273 /* NamespaceExport */ ||
16920
17080
  node.kind === 269 /* ImportSpecifier */ ||
16921
17081
  node.kind === 274 /* ExportSpecifier */ ||
16922
- node.kind === 270 /* ExportAssignment */ && exportAssignmentIsAlias(node) ||
16923
- ts.isBinaryExpression(node) && getAssignmentDeclarationKind(node) === 2 /* ModuleExports */ && exportAssignmentIsAlias(node) ||
16924
- ts.isPropertyAccessExpression(node) && ts.isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === 63 /* EqualsToken */ && isAliasableExpression(node.parent.right) ||
16925
- node.kind === 296 /* ShorthandPropertyAssignment */ ||
16926
- node.kind === 295 /* PropertyAssignment */ && isAliasableExpression(node.initializer);
17082
+ node.kind === 270 /* ExportAssignment */ && exportAssignmentIsAlias(node)) {
17083
+ return true;
17084
+ }
17085
+ return isInJSFile(node) && (ts.isBinaryExpression(node) && getAssignmentDeclarationKind(node) === 2 /* ModuleExports */ && exportAssignmentIsAlias(node) ||
17086
+ ts.isPropertyAccessExpression(node)
17087
+ && ts.isBinaryExpression(node.parent)
17088
+ && node.parent.left === node
17089
+ && node.parent.operatorToken.kind === 63 /* EqualsToken */
17090
+ && isAliasableExpression(node.parent.right));
16927
17091
  }
16928
17092
  ts.isAliasSymbolDeclaration = isAliasSymbolDeclaration;
16929
17093
  function getAliasDeclarationFromName(node) {
@@ -16934,6 +17098,7 @@ var ts;
16934
17098
  case 274 /* ExportSpecifier */:
16935
17099
  case 270 /* ExportAssignment */:
16936
17100
  case 264 /* ImportEqualsDeclaration */:
17101
+ case 273 /* NamespaceExport */:
16937
17102
  return node.parent;
16938
17103
  case 160 /* QualifiedName */:
16939
17104
  do {
@@ -39281,6 +39446,13 @@ var ts;
39281
39446
  description: ts.Diagnostics.Allow_accessing_UMD_globals_from_modules,
39282
39447
  defaultValueDescription: false,
39283
39448
  },
39449
+ {
39450
+ name: "noDtsResolution",
39451
+ type: "boolean",
39452
+ affectsModuleResolution: true,
39453
+ category: ts.Diagnostics.Modules,
39454
+ defaultValueDescription: false,
39455
+ },
39284
39456
  // Source Maps
39285
39457
  {
39286
39458
  name: "sourceRoot",
@@ -41660,7 +41832,8 @@ var ts;
41660
41832
  Extensions[Extensions["JavaScript"] = 1] = "JavaScript";
41661
41833
  Extensions[Extensions["Json"] = 2] = "Json";
41662
41834
  Extensions[Extensions["TSConfig"] = 3] = "TSConfig";
41663
- Extensions[Extensions["DtsOnly"] = 4] = "DtsOnly"; /** Only '.d.ts' */
41835
+ Extensions[Extensions["DtsOnly"] = 4] = "DtsOnly";
41836
+ Extensions[Extensions["TypeScriptButNotDts"] = 5] = "TypeScriptButNotDts";
41664
41837
  })(Extensions || (Extensions = {}));
41665
41838
  /** Used with `Extensions.DtsOnly` to extract the path from TypeScript results. */
41666
41839
  function resolvedTypeScriptOnly(resolved) {
@@ -42605,7 +42778,21 @@ var ts;
42605
42778
  return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, initialDir, { moduleResolution: ts.ModuleResolutionKind.NodeJs, allowJs: true }, host, /*cache*/ undefined, jsOnlyExtensions, /*redirectedReferences*/ undefined);
42606
42779
  }
42607
42780
  function nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, lookupConfig) {
42608
- return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, ts.getDirectoryPath(containingFile), compilerOptions, host, cache, lookupConfig ? tsconfigExtensions : (compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions), redirectedReference);
42781
+ var extensions;
42782
+ if (lookupConfig) {
42783
+ extensions = tsconfigExtensions;
42784
+ }
42785
+ else if (compilerOptions.noDtsResolution) {
42786
+ extensions = [Extensions.TypeScriptButNotDts];
42787
+ if (compilerOptions.allowJs)
42788
+ extensions.push(Extensions.JavaScript);
42789
+ if (compilerOptions.resolveJsonModule)
42790
+ extensions.push(Extensions.Json);
42791
+ }
42792
+ else {
42793
+ extensions = compilerOptions.resolveJsonModule ? tsPlusJsonExtensions : tsExtensions;
42794
+ }
42795
+ return nodeModuleNameResolverWorker(NodeResolutionFeatures.None, moduleName, ts.getDirectoryPath(containingFile), compilerOptions, host, cache, extensions, redirectedReference);
42609
42796
  }
42610
42797
  ts.nodeModuleNameResolver = nodeModuleNameResolver;
42611
42798
  function nodeModuleNameResolverWorker(features, moduleName, containingDirectory, compilerOptions, host, cache, extensions, redirectedReference) {
@@ -42614,6 +42801,10 @@ var ts;
42614
42801
  var failedLookupLocations = [];
42615
42802
  // conditions are only used by the node12/nodenext resolver - there's no priority order in the list,
42616
42803
  //it's essentially a set (priority is determined by object insertion order in the object we look at).
42804
+ var conditions = features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"];
42805
+ if (compilerOptions.noDtsResolution) {
42806
+ conditions.pop();
42807
+ }
42617
42808
  var state = {
42618
42809
  compilerOptions: compilerOptions,
42619
42810
  host: host,
@@ -42621,7 +42812,7 @@ var ts;
42621
42812
  failedLookupLocations: failedLookupLocations,
42622
42813
  packageJsonInfoCache: cache,
42623
42814
  features: features,
42624
- conditions: features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"]
42815
+ conditions: conditions,
42625
42816
  };
42626
42817
  var result = ts.forEach(extensions, function (ext) { return tryResolve(ext); });
42627
42818
  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);
@@ -42829,20 +43020,22 @@ var ts;
42829
43020
  default: return tryExtension(".d.ts" /* Dts */);
42830
43021
  }
42831
43022
  case Extensions.TypeScript:
43023
+ case Extensions.TypeScriptButNotDts:
43024
+ var useDts = extensions === Extensions.TypeScript;
42832
43025
  switch (originalExtension) {
42833
43026
  case ".mjs" /* Mjs */:
42834
43027
  case ".mts" /* Mts */:
42835
43028
  case ".d.mts" /* Dmts */:
42836
- return tryExtension(".mts" /* Mts */) || tryExtension(".d.mts" /* Dmts */);
43029
+ return tryExtension(".mts" /* Mts */) || (useDts ? tryExtension(".d.mts" /* Dmts */) : undefined);
42837
43030
  case ".cjs" /* Cjs */:
42838
43031
  case ".cts" /* Cts */:
42839
43032
  case ".d.cts" /* Dcts */:
42840
- return tryExtension(".cts" /* Cts */) || tryExtension(".d.cts" /* Dcts */);
43033
+ return tryExtension(".cts" /* Cts */) || (useDts ? tryExtension(".d.cts" /* Dcts */) : undefined);
42841
43034
  case ".json" /* Json */:
42842
43035
  candidate += ".json" /* Json */;
42843
- return tryExtension(".d.ts" /* Dts */);
43036
+ return useDts ? tryExtension(".d.ts" /* Dts */) : undefined;
42844
43037
  default:
42845
- return tryExtension(".ts" /* Ts */) || tryExtension(".tsx" /* Tsx */) || tryExtension(".d.ts" /* Dts */);
43038
+ return tryExtension(".ts" /* Ts */) || tryExtension(".tsx" /* Tsx */) || (useDts ? tryExtension(".d.ts" /* Dts */) : undefined);
42846
43039
  }
42847
43040
  case Extensions.JavaScript:
42848
43041
  switch (originalExtension) {
@@ -43060,6 +43253,7 @@ var ts;
43060
43253
  switch (extensions) {
43061
43254
  case Extensions.JavaScript:
43062
43255
  case Extensions.Json:
43256
+ case Extensions.TypeScriptButNotDts:
43063
43257
  packageFile = readPackageJsonMainField(jsonContent, candidate, state);
43064
43258
  break;
43065
43259
  case Extensions.TypeScript:
@@ -43138,6 +43332,8 @@ var ts;
43138
43332
  return extension === ".json" /* Json */;
43139
43333
  case Extensions.TypeScript:
43140
43334
  return extension === ".ts" /* Ts */ || extension === ".tsx" /* Tsx */ || extension === ".d.ts" /* Dts */;
43335
+ case Extensions.TypeScriptButNotDts:
43336
+ return extension === ".ts" /* Ts */ || extension === ".tsx" /* Tsx */;
43141
43337
  case Extensions.DtsOnly:
43142
43338
  return extension === ".d.ts" /* Dts */;
43143
43339
  }
@@ -44607,7 +44803,6 @@ var ts;
44607
44803
  node = node.parent;
44608
44804
  }
44609
44805
  return !isStatementCondition(node) &&
44610
- !isLogicalAssignmentExpression(node.parent) &&
44611
44806
  !isLogicalExpression(node.parent) &&
44612
44807
  !(ts.isOptionalChain(node.parent) && node.parent.expression === node);
44613
44808
  }
@@ -46637,7 +46832,7 @@ var ts;
46637
46832
  checkStrictModeEvalOrArguments(node, node.name);
46638
46833
  }
46639
46834
  if (!ts.isBindingPattern(node.name)) {
46640
- if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node)) {
46835
+ if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node) && !(ts.getCombinedModifierFlags(node) & 1 /* Export */)) {
46641
46836
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
46642
46837
  }
46643
46838
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -55207,7 +55402,7 @@ var ts;
55207
55402
  }
55208
55403
  }
55209
55404
  var sourceTypes = ts.some(constructorTypes, function (t) { return !!(t.flags & ~98304 /* Nullable */); }) ? constructorTypes : types; // TODO: GH#18217
55210
- type = getUnionType(sourceTypes, 2 /* Subtype */);
55405
+ type = getUnionType(sourceTypes);
55211
55406
  }
55212
55407
  }
55213
55408
  var widened = getWidenedType(addOptionality(type, /*isProperty*/ false, definedInMethod && !definedInConstructor));
@@ -87541,8 +87736,8 @@ var ts;
87541
87736
  }
87542
87737
  else {
87543
87738
  var elements = name.elements;
87544
- for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
87545
- var element = elements_1[_i];
87739
+ for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87740
+ var element = elements_2[_i];
87546
87741
  if (!ts.isOmittedExpression(element)) {
87547
87742
  return checkESModuleMarker(element.name);
87548
87743
  }
@@ -87558,8 +87753,8 @@ var ts;
87558
87753
  }
87559
87754
  else {
87560
87755
  var elements = name.elements;
87561
- for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87562
- var element = elements_2[_i];
87756
+ for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
87757
+ var element = elements_3[_i];
87563
87758
  if (!ts.isOmittedExpression(element)) {
87564
87759
  checkGrammarNameInLetOrConstDeclarations(element.name);
87565
87760
  }
@@ -89813,8 +90008,8 @@ var ts;
89813
90008
  }
89814
90009
  function bindingOrAssignmentPatternAssignsToName(pattern, escapedName) {
89815
90010
  var elements = ts.getElementsOfBindingOrAssignmentPattern(pattern);
89816
- for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
89817
- var element = elements_3[_i];
90011
+ for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
90012
+ var element = elements_4[_i];
89818
90013
  if (bindingOrAssignmentElementAssignsToName(element, escapedName)) {
89819
90014
  return true;
89820
90015
  }
@@ -95432,8 +95627,8 @@ var ts;
95432
95627
  function chunkObjectLiteralElements(elements) {
95433
95628
  var chunkObject;
95434
95629
  var objects = [];
95435
- for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
95436
- var e = elements_4[_i];
95630
+ for (var _i = 0, elements_5 = elements; _i < elements_5.length; _i++) {
95631
+ var e = elements_5[_i];
95437
95632
  if (e.kind === 297 /* SpreadAssignment */) {
95438
95633
  if (chunkObject) {
95439
95634
  objects.push(factory.createObjectLiteralExpression(chunkObject));
@@ -126834,6 +127029,20 @@ var ts;
126834
127029
  return !!location.parent && ts.isImportOrExportSpecifier(location.parent) && location.parent.propertyName === location;
126835
127030
  }
126836
127031
  ts.isImportOrExportSpecifierName = isImportOrExportSpecifierName;
127032
+ /**
127033
+ * Returns true if `node` is the declaration of `n` in:
127034
+ * - `import n from "m"`
127035
+ * - `import * as n from "m"`
127036
+ * - `import n = require("m")`
127037
+ * - `const n = require("m")`
127038
+ */
127039
+ function isFreelyNameableImport(node) {
127040
+ return node.kind === 266 /* ImportClause */
127041
+ || node.kind === 267 /* NamespaceImport */
127042
+ || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
127043
+ || ts.isVariableDeclarationInitializedToRequire(node);
127044
+ }
127045
+ ts.isFreelyNameableImport = isFreelyNameableImport;
126837
127046
  function getScriptKind(fileName, host) {
126838
127047
  // First check to see if the script kind was specified by the host. Chances are the host
126839
127048
  // may override the default script kind for the file extension.
@@ -135848,6 +136057,29 @@ var ts;
135848
136057
  }
135849
136058
  }
135850
136059
  Core.eachSymbolReferenceInFile = eachSymbolReferenceInFile;
136060
+ function getTopMostDeclarationNamesInFile(declarationName, sourceFile) {
136061
+ var candidates = ts.filter(getPossibleSymbolReferenceNodes(sourceFile, declarationName), function (name) { return !!ts.getDeclarationFromName(name); });
136062
+ return candidates.reduce(function (topMost, decl) {
136063
+ var depth = getDepth(decl);
136064
+ if (!ts.some(topMost.declarationNames) || depth === topMost.depth) {
136065
+ topMost.declarationNames.push(decl);
136066
+ }
136067
+ else if (depth < topMost.depth) {
136068
+ topMost.declarationNames = [decl];
136069
+ }
136070
+ topMost.depth = depth;
136071
+ return topMost;
136072
+ }, { depth: Infinity, declarationNames: [] }).declarationNames;
136073
+ function getDepth(declaration) {
136074
+ var depth = 0;
136075
+ while (declaration) {
136076
+ declaration = ts.getContainerNode(declaration);
136077
+ depth++;
136078
+ }
136079
+ return depth;
136080
+ }
136081
+ }
136082
+ Core.getTopMostDeclarationNamesInFile = getTopMostDeclarationNamesInFile;
135851
136083
  function someSignatureUsage(signature, sourceFiles, checker, cb) {
135852
136084
  if (!signature.name || !ts.isIdentifier(signature.name))
135853
136085
  return false;
@@ -137480,7 +137712,9 @@ var ts;
137480
137712
  (function (ts) {
137481
137713
  var GoToDefinition;
137482
137714
  (function (GoToDefinition) {
137483
- function getDefinitionAtPosition(program, sourceFile, position) {
137715
+ function getDefinitionAtPosition(program, sourceFile, position, aliasesOnly) {
137716
+ var _a;
137717
+ var _b;
137484
137718
  var resolvedRef = getReferenceAtPosition(sourceFile, position, program);
137485
137719
  var fileReferenceDefinition = resolvedRef && [getDefinitionInfoForFileReference(resolvedRef.reference.fileName, resolvedRef.fileName, resolvedRef.unverified)] || ts.emptyArray;
137486
137720
  if (resolvedRef === null || resolvedRef === void 0 ? void 0 : resolvedRef.file) {
@@ -137503,17 +137737,50 @@ var ts;
137503
137737
  }
137504
137738
  if (ts.isStaticModifier(node) && ts.isClassStaticBlockDeclaration(node.parent)) {
137505
137739
  var classDecl = node.parent.parent;
137506
- var symbol_1 = getSymbol(classDecl, typeChecker);
137740
+ var _c = getSymbol(classDecl, typeChecker), symbol_1 = _c.symbol, isAliasTarget_1 = _c.isAliasTarget, failedAliasResolution_1 = _c.failedAliasResolution;
137741
+ if (aliasesOnly && !isAliasTarget_1)
137742
+ return undefined;
137507
137743
  var staticBlocks = ts.filter(classDecl.members, ts.isClassStaticBlockDeclaration);
137508
137744
  var containerName_1 = symbol_1 ? typeChecker.symbolToString(symbol_1, classDecl) : "";
137509
137745
  var sourceFile_1 = node.getSourceFile();
137510
137746
  return ts.map(staticBlocks, function (staticBlock) {
137511
137747
  var pos = ts.moveRangePastModifiers(staticBlock).pos;
137512
137748
  pos = ts.skipTrivia(sourceFile_1.text, pos);
137513
- return createDefinitionInfoFromName(typeChecker, staticBlock, "constructor" /* constructorImplementationElement */, "static {}", containerName_1, { start: pos, length: "static".length });
137749
+ return createDefinitionInfoFromName(typeChecker, staticBlock, "constructor" /* constructorImplementationElement */, "static {}", containerName_1, isAliasTarget_1, failedAliasResolution_1, { start: pos, length: "static".length });
137514
137750
  });
137515
137751
  }
137516
- var symbol = getSymbol(node, typeChecker);
137752
+ var _d = getSymbol(node, typeChecker), symbol = _d.symbol, isAliasTarget = _d.isAliasTarget, failedAliasResolution = _d.failedAliasResolution;
137753
+ var fallbackNode = node;
137754
+ if (aliasesOnly && failedAliasResolution) {
137755
+ // We couldn't resolve the specific import, try on the module specifier.
137756
+ var importDeclaration = ts.findAncestor(node, ts.isAnyImportOrBareOrAccessedRequire);
137757
+ var moduleSpecifier = importDeclaration && ts.tryGetModuleSpecifierFromDeclaration(importDeclaration);
137758
+ if (moduleSpecifier) {
137759
+ (_a = getSymbol(moduleSpecifier, typeChecker), symbol = _a.symbol, isAliasTarget = _a.isAliasTarget, failedAliasResolution = _a.failedAliasResolution);
137760
+ fallbackNode = moduleSpecifier;
137761
+ }
137762
+ }
137763
+ if (!symbol && ts.isModuleSpecifierLike(fallbackNode)) {
137764
+ // We couldn't resolve the module specifier as an external module, but it could
137765
+ // be that module resolution succeeded but the target was not a module.
137766
+ var ref = (_b = sourceFile.resolvedModules) === null || _b === void 0 ? void 0 : _b.get(fallbackNode.text, ts.getModeForUsageLocation(sourceFile, fallbackNode));
137767
+ if (ref) {
137768
+ return [{
137769
+ name: fallbackNode.text,
137770
+ fileName: ref.resolvedFileName,
137771
+ containerName: undefined,
137772
+ containerKind: undefined,
137773
+ kind: "script" /* scriptElement */,
137774
+ textSpan: ts.createTextSpan(0, 0),
137775
+ isAliasTarget: true,
137776
+ failedAliasResolution: failedAliasResolution,
137777
+ isAmbient: ts.isDeclarationFileName(ref.resolvedFileName),
137778
+ unverified: fallbackNode !== node,
137779
+ }];
137780
+ }
137781
+ }
137782
+ if (aliasesOnly && !isAliasTarget)
137783
+ return undefined;
137517
137784
  // Could not find a symbol e.g. node is string or number keyword,
137518
137785
  // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
137519
137786
  if (!symbol) {
@@ -137522,14 +137789,14 @@ var ts;
137522
137789
  var calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
137523
137790
  // Don't go to the component constructor definition for a JSX element, just go to the component definition.
137524
137791
  if (calledDeclaration && !(ts.isJsxOpeningLikeElement(node.parent) && isConstructorLike(calledDeclaration))) {
137525
- var sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
137792
+ var sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration, isAliasTarget, failedAliasResolution);
137526
137793
  // For a function, if this is the original function definition, return just sigInfo.
137527
137794
  // If this is the original constructor definition, parent is the class.
137528
137795
  if (typeChecker.getRootSymbols(symbol).some(function (s) { return symbolMatchesSignature(s, calledDeclaration); })) {
137529
137796
  return [sigInfo];
137530
137797
  }
137531
137798
  else {
137532
- var defs = getDefinitionFromSymbol(typeChecker, symbol, node, calledDeclaration) || ts.emptyArray;
137799
+ var defs = getDefinitionFromSymbol(typeChecker, symbol, node, isAliasTarget, failedAliasResolution, calledDeclaration) || ts.emptyArray;
137533
137800
  // For a 'super()' call, put the signature first, else put the variable first.
137534
137801
  return node.kind === 106 /* SuperKeyword */ ? __spreadArray([sigInfo], defs, true) : __spreadArray(__spreadArray([], defs, true), [sigInfo], false);
137535
137802
  }
@@ -137541,7 +137808,7 @@ var ts;
137541
137808
  // assignment. This case and others are handled by the following code.
137542
137809
  if (node.parent.kind === 296 /* ShorthandPropertyAssignment */) {
137543
137810
  var shorthandSymbol_1 = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
137544
- 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;
137811
+ 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;
137545
137812
  return ts.concatenate(definitions, getDefinitionFromObjectLiteralElement(typeChecker, node) || ts.emptyArray);
137546
137813
  }
137547
137814
  // If the node is the name of a BindingElement within an ObjectBindingPattern instead of just returning the
@@ -137564,7 +137831,7 @@ var ts;
137564
137831
  return prop && getDefinitionFromSymbol(typeChecker, prop, node);
137565
137832
  });
137566
137833
  }
137567
- return ts.concatenate(fileReferenceDefinition, getDefinitionFromObjectLiteralElement(typeChecker, node) || getDefinitionFromSymbol(typeChecker, symbol, node));
137834
+ return ts.concatenate(fileReferenceDefinition, getDefinitionFromObjectLiteralElement(typeChecker, node) || getDefinitionFromSymbol(typeChecker, symbol, node, isAliasTarget, failedAliasResolution));
137568
137835
  }
137569
137836
  GoToDefinition.getDefinitionAtPosition = getDefinitionAtPosition;
137570
137837
  /**
@@ -137662,24 +137929,24 @@ var ts;
137662
137929
  return undefined;
137663
137930
  }
137664
137931
  if (ts.isImportMeta(node.parent) && node.parent.name === node) {
137665
- return definitionFromType(typeChecker.getTypeAtLocation(node.parent), typeChecker, node.parent);
137932
+ return definitionFromType(typeChecker.getTypeAtLocation(node.parent), typeChecker, node.parent, /*isAliasTarget*/ false, /*failedAliasResolution*/ false);
137666
137933
  }
137667
- var symbol = getSymbol(node, typeChecker);
137934
+ var _a = getSymbol(node, typeChecker), symbol = _a.symbol, isAliasTarget = _a.isAliasTarget, failedAliasResolution = _a.failedAliasResolution;
137668
137935
  if (!symbol)
137669
137936
  return undefined;
137670
137937
  var typeAtLocation = typeChecker.getTypeOfSymbolAtLocation(symbol, node);
137671
137938
  var returnType = tryGetReturnTypeOfFunction(symbol, typeAtLocation, typeChecker);
137672
- var fromReturnType = returnType && definitionFromType(returnType, typeChecker, node);
137939
+ var fromReturnType = returnType && definitionFromType(returnType, typeChecker, node, isAliasTarget, failedAliasResolution);
137673
137940
  // If a function returns 'void' or some other type with no definition, just return the function definition.
137674
- var typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node);
137941
+ var typeDefinitions = fromReturnType && fromReturnType.length !== 0 ? fromReturnType : definitionFromType(typeAtLocation, typeChecker, node, isAliasTarget, failedAliasResolution);
137675
137942
  return typeDefinitions.length ? typeDefinitions
137676
- : !(symbol.flags & 111551 /* Value */) && symbol.flags & 788968 /* Type */ ? getDefinitionFromSymbol(typeChecker, ts.skipAlias(symbol, typeChecker), node)
137943
+ : !(symbol.flags & 111551 /* Value */) && symbol.flags & 788968 /* Type */ ? getDefinitionFromSymbol(typeChecker, ts.skipAlias(symbol, typeChecker), node, isAliasTarget, failedAliasResolution)
137677
137944
  : undefined;
137678
137945
  }
137679
137946
  GoToDefinition.getTypeDefinitionAtPosition = getTypeDefinitionAtPosition;
137680
- function definitionFromType(type, checker, node) {
137947
+ function definitionFromType(type, checker, node, isAliasTarget, failedAliasResolution) {
137681
137948
  return ts.flatMap(type.isUnion() && !(type.flags & 32 /* Enum */) ? type.types : [type], function (t) {
137682
- return t.symbol && getDefinitionFromSymbol(checker, t.symbol, node);
137949
+ return t.symbol && getDefinitionFromSymbol(checker, t.symbol, node, isAliasTarget, failedAliasResolution);
137683
137950
  });
137684
137951
  }
137685
137952
  function tryGetReturnTypeOfFunction(symbol, type, checker) {
@@ -137694,8 +137961,8 @@ var ts;
137694
137961
  }
137695
137962
  return undefined;
137696
137963
  }
137697
- function getDefinitionAndBoundSpan(program, sourceFile, position) {
137698
- var definitions = getDefinitionAtPosition(program, sourceFile, position);
137964
+ function getDefinitionAndBoundSpan(program, sourceFile, position, aliasesOnly) {
137965
+ var definitions = getDefinitionAtPosition(program, sourceFile, position, aliasesOnly);
137699
137966
  if (!definitions || definitions.length === 0) {
137700
137967
  return undefined;
137701
137968
  }
@@ -137721,13 +137988,17 @@ var ts;
137721
137988
  // get the aliased symbol instead. This allows for goto def on an import e.g.
137722
137989
  // import {A, B} from "mod";
137723
137990
  // to jump to the implementation directly.
137991
+ var failedAliasResolution = false;
137724
137992
  if ((symbol === null || symbol === void 0 ? void 0 : symbol.declarations) && symbol.flags & 2097152 /* Alias */ && shouldSkipAlias(node, symbol.declarations[0])) {
137725
137993
  var aliased = checker.getAliasedSymbol(symbol);
137726
137994
  if (aliased.declarations) {
137727
- return aliased;
137995
+ return { symbol: aliased, isAliasTarget: true };
137996
+ }
137997
+ else {
137998
+ failedAliasResolution = true;
137728
137999
  }
137729
138000
  }
137730
- return symbol;
138001
+ return { symbol: symbol, isAliasTarget: !!(symbol && ts.isExternalModuleSymbol(symbol)), failedAliasResolution: failedAliasResolution };
137731
138002
  }
137732
138003
  // Go to the original declaration for cases:
137733
138004
  //
@@ -137741,26 +138012,45 @@ var ts;
137741
138012
  if (node.parent === declaration) {
137742
138013
  return true;
137743
138014
  }
137744
- switch (declaration.kind) {
137745
- case 266 /* ImportClause */:
137746
- case 264 /* ImportEqualsDeclaration */:
137747
- return true;
137748
- case 269 /* ImportSpecifier */:
137749
- return declaration.parent.kind === 268 /* NamedImports */;
137750
- case 202 /* BindingElement */:
137751
- case 253 /* VariableDeclaration */:
137752
- return ts.isInJSFile(declaration) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(declaration);
137753
- default:
137754
- return false;
138015
+ if (declaration.kind === 267 /* NamespaceImport */) {
138016
+ return false;
137755
138017
  }
138018
+ return true;
138019
+ }
138020
+ /**
138021
+ * ```ts
138022
+ * function f() {}
138023
+ * f.foo = 0;
138024
+ * ```
138025
+ *
138026
+ * Here, `f` has two declarations: the function declaration, and the identifier in the next line.
138027
+ * The latter is a declaration for `f` because it gives `f` the `SymbolFlags.Namespace` meaning so
138028
+ * it can contain `foo`. However, that declaration is pretty uninteresting and not intuitively a
138029
+ * "definition" for `f`. Ideally, the question we'd like to answer is "what SymbolFlags does this
138030
+ * declaration contribute to the symbol for `f`?" If the answer is just `Namespace` and the
138031
+ * declaration looks like an assignment, that declaration is in no sense a definition for `f`.
138032
+ * But that information is totally lost during binding and/or symbol merging, so we need to do
138033
+ * our best to reconstruct it or use other heuristics. This function (and the logic around its
138034
+ * calling) covers our tests but feels like a hack, and it would be great if someone could come
138035
+ * up with a more precise definition of what counts as a definition.
138036
+ */
138037
+ function isExpandoDeclaration(node) {
138038
+ if (!ts.isAssignmentDeclaration(node))
138039
+ return false;
138040
+ var containingAssignment = ts.findAncestor(node, function (p) {
138041
+ if (ts.isAssignmentExpression(p))
138042
+ return true;
138043
+ if (!ts.isAssignmentDeclaration(p))
138044
+ return "quit";
138045
+ return false;
138046
+ });
138047
+ return !!containingAssignment && ts.getAssignmentDeclarationKind(containingAssignment) === 5 /* Property */;
137756
138048
  }
137757
- function getDefinitionFromSymbol(typeChecker, symbol, node, declarationNode) {
137758
- // There are cases when you extend a function by adding properties to it afterwards,
137759
- // we want to strip those extra properties.
137760
- // For deduping purposes, we also want to exclude any declarationNodes if provided.
137761
- var filteredDeclarations = ts.filter(symbol.declarations, function (d) { return d !== declarationNode && (!ts.isAssignmentDeclaration(d) || d === symbol.valueDeclaration); })
137762
- || undefined;
137763
- return getConstructSignatureDefinition() || getCallSignatureDefinition() || ts.map(filteredDeclarations, function (declaration) { return createDefinitionInfo(declaration, typeChecker, symbol, node); });
138049
+ function getDefinitionFromSymbol(typeChecker, symbol, node, isAliasTarget, failedAliasResolution, excludeDeclaration) {
138050
+ var filteredDeclarations = ts.filter(symbol.declarations, function (d) { return d !== excludeDeclaration; });
138051
+ var withoutExpandos = ts.filter(filteredDeclarations, function (d) { return !isExpandoDeclaration(d); });
138052
+ var results = ts.some(withoutExpandos) ? withoutExpandos : filteredDeclarations;
138053
+ return getConstructSignatureDefinition() || getCallSignatureDefinition() || ts.map(results, function (declaration) { return createDefinitionInfo(declaration, typeChecker, symbol, node, isAliasTarget, failedAliasResolution); });
137764
138054
  function getConstructSignatureDefinition() {
137765
138055
  // Applicable only if we are in a new expression, or we are on a constructor declaration
137766
138056
  // and in either case the symbol has a construct signature definition, i.e. class
@@ -137784,26 +138074,27 @@ var ts;
137784
138074
  return declarations.length
137785
138075
  ? declarationsWithBody.length !== 0
137786
138076
  ? declarationsWithBody.map(function (x) { return createDefinitionInfo(x, typeChecker, symbol, node); })
137787
- : [createDefinitionInfo(ts.last(declarations), typeChecker, symbol, node)]
138077
+ : [createDefinitionInfo(ts.last(declarations), typeChecker, symbol, node, isAliasTarget, failedAliasResolution)]
137788
138078
  : undefined;
137789
138079
  }
137790
138080
  }
137791
138081
  /** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */
137792
- function createDefinitionInfo(declaration, checker, symbol, node) {
138082
+ function createDefinitionInfo(declaration, checker, symbol, node, isAliasTarget, failedAliasResolution) {
137793
138083
  var symbolName = checker.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
137794
138084
  var symbolKind = ts.SymbolDisplay.getSymbolKind(checker, symbol, node);
137795
138085
  var containerName = symbol.parent ? checker.symbolToString(symbol.parent, node) : "";
137796
- return createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName);
138086
+ return createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName, isAliasTarget, failedAliasResolution);
137797
138087
  }
138088
+ GoToDefinition.createDefinitionInfo = createDefinitionInfo;
137798
138089
  /** Creates a DefinitionInfo directly from the name of a declaration. */
137799
- function createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName, textSpan) {
138090
+ function createDefinitionInfoFromName(checker, declaration, symbolKind, symbolName, containerName, isAliasTarget, failedAliasResolution, textSpan) {
137800
138091
  var sourceFile = declaration.getSourceFile();
137801
138092
  if (!textSpan) {
137802
138093
  var name = ts.getNameOfDeclaration(declaration) || declaration;
137803
138094
  textSpan = ts.createTextSpanFromNode(name, sourceFile);
137804
138095
  }
137805
138096
  return __assign(__assign({ fileName: sourceFile.fileName, textSpan: textSpan, kind: symbolKind, name: symbolName, containerKind: undefined, // TODO: GH#18217
137806
- containerName: containerName }, ts.FindAllReferences.toContextSpan(textSpan, sourceFile, ts.FindAllReferences.getContextNode(declaration))), { isLocal: !isDefinitionVisible(checker, declaration) });
138097
+ containerName: containerName }, ts.FindAllReferences.toContextSpan(textSpan, sourceFile, ts.FindAllReferences.getContextNode(declaration))), { isLocal: !isDefinitionVisible(checker, declaration), isAmbient: !!(declaration.flags & 8388608 /* Ambient */), isAliasTarget: isAliasTarget, failedAliasResolution: failedAliasResolution });
137807
138098
  }
137808
138099
  function isDefinitionVisible(checker, declaration) {
137809
138100
  if (checker.isDeclarationVisible(declaration))
@@ -137836,8 +138127,8 @@ var ts;
137836
138127
  return false;
137837
138128
  }
137838
138129
  }
137839
- function createDefinitionFromSignatureDeclaration(typeChecker, decl) {
137840
- return createDefinitionInfo(decl, typeChecker, decl.symbol, decl);
138130
+ function createDefinitionFromSignatureDeclaration(typeChecker, decl, isAliasTarget, failedAliasResolution) {
138131
+ return createDefinitionInfo(decl, typeChecker, decl.symbol, decl, isAliasTarget, failedAliasResolution);
137841
138132
  }
137842
138133
  function findReferenceInPosition(refs, pos) {
137843
138134
  return ts.find(refs, function (ref) { return ts.textRangeContainsPositionInclusive(ref, pos); });
@@ -137852,6 +138143,7 @@ var ts;
137852
138143
  containerName: undefined,
137853
138144
  containerKind: undefined,
137854
138145
  unverified: unverified,
138146
+ isAliasTarget: true,
137855
138147
  };
137856
138148
  }
137857
138149
  /** Returns a CallLikeExpression where `node` is the target being invoked. */
@@ -140905,41 +141197,6 @@ var ts;
140905
141197
  if (ts.scanner.getToken() === 1 /* EndOfFileToken */) {
140906
141198
  break;
140907
141199
  }
140908
- if (ts.scanner.getToken() === 15 /* TemplateHead */) {
140909
- var stack = [ts.scanner.getToken()];
140910
- var token = ts.scanner.scan();
140911
- loop: while (ts.length(stack)) {
140912
- switch (token) {
140913
- case 1 /* EndOfFileToken */:
140914
- break loop;
140915
- case 100 /* ImportKeyword */:
140916
- tryConsumeImport();
140917
- break;
140918
- case 15 /* TemplateHead */:
140919
- stack.push(token);
140920
- break;
140921
- case 18 /* OpenBraceToken */:
140922
- if (ts.length(stack)) {
140923
- stack.push(token);
140924
- }
140925
- break;
140926
- case 19 /* CloseBraceToken */:
140927
- if (ts.length(stack)) {
140928
- if (ts.lastOrUndefined(stack) === 15 /* TemplateHead */) {
140929
- if (ts.scanner.reScanTemplateToken(/* isTaggedTemplate */ false) === 17 /* TemplateTail */) {
140930
- stack.pop();
140931
- }
140932
- }
140933
- else {
140934
- stack.pop();
140935
- }
140936
- }
140937
- break;
140938
- }
140939
- token = ts.scanner.scan();
140940
- }
140941
- nextToken();
140942
- }
140943
141200
  // check if at least one of alternative have moved scanner forward
140944
141201
  if (tryConsumeDeclare() ||
140945
141202
  tryConsumeImport() ||
@@ -150885,9 +151142,10 @@ var ts;
150885
151142
  // 2. add "member3" to the second import statement's import list
150886
151143
  // and it is up to the user to decide which one fits best.
150887
151144
  return ts.firstDefined(existingImports, function (_a) {
151145
+ var _b;
150888
151146
  var declaration = _a.declaration;
150889
151147
  var namespacePrefix = getNamespaceLikeImportText(declaration);
150890
- var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
151148
+ var moduleSpecifier = (_b = ts.tryGetModuleSpecifierFromDeclaration(declaration)) === null || _b === void 0 ? void 0 : _b.text;
150891
151149
  if (namespacePrefix && moduleSpecifier) {
150892
151150
  var moduleSymbol = getTargetModuleFromNamespaceLikeImport(declaration, checker);
150893
151151
  if (moduleSymbol && moduleSymbol.exports.has(ts.escapeLeadingUnderscores(symbolName))) {
@@ -151063,8 +151321,9 @@ var ts;
151063
151321
  return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
151064
151322
  }
151065
151323
  function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
151324
+ var _b;
151066
151325
  var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
151067
- var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
151326
+ var moduleSpecifier = (_b = ts.tryGetModuleSpecifierFromDeclaration(declaration)) === null || _b === void 0 ? void 0 : _b.text;
151068
151327
  if (moduleSpecifier) {
151069
151328
  var addAsTypeOnly = useRequire
151070
151329
  ? 4 /* NotAllowed */
@@ -162873,9 +163132,9 @@ var ts;
162873
163132
  synchronizeHostData();
162874
163133
  return ts.GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position);
162875
163134
  }
162876
- function getDefinitionAndBoundSpan(fileName, position) {
163135
+ function getDefinitionAndBoundSpan(fileName, position, aliasesOnly) {
162877
163136
  synchronizeHostData();
162878
- return ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position);
163137
+ return ts.GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position, aliasesOnly);
162879
163138
  }
162880
163139
  function getTypeDefinitionAtPosition(fileName, position) {
162881
163140
  synchronizeHostData();
@@ -166044,6 +166303,9 @@ var ts;
166044
166303
  CommandTypes["SignatureHelp"] = "signatureHelp";
166045
166304
  /* @internal */
166046
166305
  CommandTypes["SignatureHelpFull"] = "signatureHelp-full";
166306
+ CommandTypes["SourceDefinitionAndBoundSpan"] = "sourceDefinitionAndBoundSpan";
166307
+ /* @internal */
166308
+ CommandTypes["SourceDefinitionAndBoundSpanFull"] = "sourceDefinitionAndBoundSpan-full";
166047
166309
  CommandTypes["Status"] = "status";
166048
166310
  CommandTypes["TypeDefinition"] = "typeDefinition";
166049
166311
  CommandTypes["ProjectInfo"] = "projectInfo";
@@ -166913,6 +167175,7 @@ var ts;
166913
167175
  ProjectKind[ProjectKind["Configured"] = 1] = "Configured";
166914
167176
  ProjectKind[ProjectKind["External"] = 2] = "External";
166915
167177
  ProjectKind[ProjectKind["AutoImportProvider"] = 3] = "AutoImportProvider";
167178
+ ProjectKind[ProjectKind["Auxiliary"] = 4] = "Auxiliary";
166916
167179
  })(ProjectKind = server.ProjectKind || (server.ProjectKind = {}));
166917
167180
  /* @internal */
166918
167181
  function countEachFileTypes(infos, includeSizes) {
@@ -168358,6 +168621,17 @@ var ts;
168358
168621
  Project.prototype.getIncompleteCompletionsCache = function () {
168359
168622
  return this.projectService.getIncompleteCompletionsCache();
168360
168623
  };
168624
+ Project.prototype.withAuxiliaryProjectForFiles = function (fileNames, cb) {
168625
+ 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 });
168626
+ var project = new AuxiliaryProject(this.projectService, this.documentRegistry, options);
168627
+ for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
168628
+ var fileName = fileNames_1[_i];
168629
+ project.addRoot(this.getScriptInfo(fileName));
168630
+ }
168631
+ project.updateGraph();
168632
+ cb(project);
168633
+ project.close();
168634
+ };
168361
168635
  return Project;
168362
168636
  }());
168363
168637
  server.Project = Project;
@@ -168469,6 +168743,22 @@ var ts;
168469
168743
  return InferredProject;
168470
168744
  }(Project));
168471
168745
  server.InferredProject = InferredProject;
168746
+ var AuxiliaryProject = /** @class */ (function (_super) {
168747
+ __extends(AuxiliaryProject, _super);
168748
+ function AuxiliaryProject(projectService, documentRegistry, parentCompilerOptions) {
168749
+ var _this = this;
168750
+ 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 });
168751
+ _this = _super.call(this, "js-analysis", ProjectKind.Auxiliary, projectService, documentRegistry,
168752
+ /*hasExplicitListOfFiles*/ false,
168753
+ /*lastFileExceededProgramSize*/ undefined, options,
168754
+ /*compileOnSaveEnabled*/ false,
168755
+ /*watchOptions*/ undefined, projectService.host,
168756
+ /*currentDirectory*/ undefined) || this;
168757
+ return _this;
168758
+ }
168759
+ return AuxiliaryProject;
168760
+ }(Project));
168761
+ server.AuxiliaryProject = AuxiliaryProject;
168472
168762
  var AutoImportProviderProject = /** @class */ (function (_super) {
168473
168763
  __extends(AutoImportProviderProject, _super);
168474
168764
  /*@internal*/
@@ -170357,8 +170647,8 @@ var ts;
170357
170647
  this.projectToSizeMap.set(name, 0);
170358
170648
  this.projectToSizeMap.forEach(function (val) { return (availableSpace -= (val || 0)); });
170359
170649
  var totalNonTsFileSize = 0;
170360
- for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
170361
- var f = fileNames_1[_i];
170650
+ for (var _i = 0, fileNames_2 = fileNames; _i < fileNames_2.length; _i++) {
170651
+ var f = fileNames_2[_i];
170362
170652
  var fileName = propertyReader.getFileName(f);
170363
170653
  if (ts.hasTSFileExtension(fileName)) {
170364
170654
  continue;
@@ -172714,15 +173004,23 @@ var ts;
172714
173004
  return ts.deduplicate(outputs, ts.equateValues);
172715
173005
  }
172716
173006
  ;
173007
+ function createDocumentSpanSet() {
173008
+ return ts.createSet(function (_a) {
173009
+ var textSpan = _a.textSpan;
173010
+ return textSpan.start + 100003 * textSpan.length;
173011
+ }, ts.documentSpansEqual);
173012
+ }
172717
173013
  function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
172718
173014
  var providePrefixAndSuffixTextForRename = _a.providePrefixAndSuffixTextForRename;
172719
173015
  var outputs = [];
173016
+ var seen = createDocumentSpanSet();
172720
173017
  combineProjectOutputWorker(projects, defaultProject, initialLocation, function (project, location, tryAddToTodo) {
172721
173018
  var projectOutputs = project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
172722
173019
  if (projectOutputs) {
172723
173020
  for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
172724
173021
  var output = projectOutputs_1[_i];
172725
- if (!ts.contains(outputs, output, ts.documentSpansEqual) && !tryAddToTodo(project, documentSpanLocation(output))) {
173022
+ if (!seen.has(output) && !tryAddToTodo(project, documentSpanLocation(output))) {
173023
+ seen.add(output);
172726
173024
  outputs.push(output);
172727
173025
  }
172728
173026
  }
@@ -173063,6 +173361,12 @@ var ts;
173063
173361
  _a[server.CommandNames.DefinitionAndBoundSpanFull] = function (request) {
173064
173362
  return _this.requiredResponse(_this.getDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false));
173065
173363
  },
173364
+ // [CommandNames.SourceDefinitionAndBoundSpan]: (request: protocol.SourceDefinitionAndBoundSpanRequest) => {
173365
+ // return this.requiredResponse(this.getSourceDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ true));
173366
+ // },
173367
+ // [CommandNames.SourceDefinitionAndBoundSpanFull]: (request: protocol.SourceDefinitionAndBoundSpanRequest) => {
173368
+ // return this.requiredResponse(this.getSourceDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false));
173369
+ // },
173066
173370
  _a[server.CommandNames.EmitOutput] = function (request) {
173067
173371
  return _this.requiredResponse(_this.getEmitOutput(request.arguments));
173068
173372
  },
@@ -173799,10 +174103,34 @@ var ts;
173799
174103
  Session.prototype.mapDefinitionInfoLocations = function (definitions, project) {
173800
174104
  return definitions.map(function (info) {
173801
174105
  var newDocumentSpan = getMappedDocumentSpan(info, project);
173802
- return !newDocumentSpan ? info : __assign(__assign(__assign({}, newDocumentSpan), { containerKind: info.containerKind, containerName: info.containerName, kind: info.kind, name: info.name }), info.unverified && { unverified: info.unverified });
174106
+ 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 });
173803
174107
  });
173804
174108
  };
173805
174109
  Session.prototype.getDefinitionAndBoundSpan = function (args, simplifiedResult) {
174110
+ // const { file, project } = this.getFileAndProject(args);
174111
+ // const position = this.getPositionInFile(args, file);
174112
+ // const scriptInfo = Debug.checkDefined(project.getScriptInfo(file));
174113
+ // const unmappedDefinitionAndBoundSpan = project.getLanguageService().getDefinitionAndBoundSpan(file, position);
174114
+ // if (!unmappedDefinitionAndBoundSpan || !unmappedDefinitionAndBoundSpan.definitions) {
174115
+ // return {
174116
+ // definitions: emptyArray,
174117
+ // textSpan: undefined! // TODO: GH#18217
174118
+ // };
174119
+ // }
174120
+ // const definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan.definitions, project);
174121
+ // const { textSpan } = unmappedDefinitionAndBoundSpan;
174122
+ // if (simplifiedResult) {
174123
+ // return {
174124
+ // definitions: this.mapDefinitionInfo(definitions, project),
174125
+ // textSpan: toProtocolTextSpan(textSpan, scriptInfo)
174126
+ // };
174127
+ // }
174128
+ // return {
174129
+ // definitions: definitions.map(Session.mapToOriginalLocation),
174130
+ // textSpan,
174131
+ // };
174132
+ // }
174133
+ // private getSourceDefinitionAndBoundSpan(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.DefinitionInfoAndBoundSpan | DefinitionInfoAndBoundSpan {
173806
174134
  var _a = this.getFileAndProject(args), file = _a.file, project = _a.project;
173807
174135
  var position = this.getPositionInFile(args, file);
173808
174136
  var scriptInfo = ts.Debug.checkDefined(project.getScriptInfo(file));
@@ -173813,7 +174141,31 @@ var ts;
173813
174141
  textSpan: undefined // TODO: GH#18217
173814
174142
  };
173815
174143
  }
173816
- var definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan.definitions, project);
174144
+ var definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan.definitions, project).slice();
174145
+ var needsJsResolution = !ts.some(definitions, function (d) { return !!d.isAliasTarget && !d.isAmbient; }) || ts.some(definitions, function (d) { return !!d.failedAliasResolution; });
174146
+ if (needsJsResolution) {
174147
+ project.withAuxiliaryProjectForFiles([file], function (auxiliaryProject) {
174148
+ var ls = auxiliaryProject.getLanguageService();
174149
+ var jsDefinitions = ls.getDefinitionAndBoundSpan(file, position, /*aliasesOnly*/ true);
174150
+ if (ts.some(jsDefinitions === null || jsDefinitions === void 0 ? void 0 : jsDefinitions.definitions)) {
174151
+ for (var _i = 0, _a = jsDefinitions.definitions; _i < _a.length; _i++) {
174152
+ var jsDefinition = _a[_i];
174153
+ if (jsDefinition.unverified) {
174154
+ var refined = tryRefineDefinition(jsDefinition, project.getLanguageService().getProgram(), ls.getProgram());
174155
+ if (ts.some(refined)) {
174156
+ for (var _b = 0, _c = refined || server.emptyArray; _b < _c.length; _b++) {
174157
+ var def = _c[_b];
174158
+ ts.pushIfUnique(definitions, def, ts.documentSpansEqual);
174159
+ }
174160
+ continue;
174161
+ }
174162
+ }
174163
+ ts.pushIfUnique(definitions, jsDefinition, ts.documentSpansEqual);
174164
+ }
174165
+ }
174166
+ });
174167
+ }
174168
+ definitions = definitions.filter(function (d) { return !d.isAmbient && !d.failedAliasResolution; });
173817
174169
  var textSpan = unmappedDefinitionAndBoundSpan.textSpan;
173818
174170
  if (simplifiedResult) {
173819
174171
  return {
@@ -173825,6 +174177,32 @@ var ts;
173825
174177
  definitions: definitions.map(Session.mapToOriginalLocation),
173826
174178
  textSpan: textSpan,
173827
174179
  };
174180
+ function tryRefineDefinition(definition, program, auxiliaryProgram) {
174181
+ var _a, _b;
174182
+ var fileToSearch = auxiliaryProgram.getSourceFile(definition.fileName);
174183
+ if (!fileToSearch) {
174184
+ return undefined;
174185
+ }
174186
+ var initialNode = ts.getTouchingPropertyName(program.getSourceFile(file), position);
174187
+ var symbol = program.getTypeChecker().getSymbolAtLocation(initialNode);
174188
+ if (!symbol || !symbol.declarations || ts.some(symbol.declarations, ts.isFreelyNameableImport)) {
174189
+ return undefined;
174190
+ }
174191
+ 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;
174192
+ return searchForDeclaration(nameToSearch, fileToSearch, auxiliaryProgram);
174193
+ }
174194
+ function searchForDeclaration(declarationName, fileToSearch, auxiliaryProgram) {
174195
+ var matches = ts.FindAllReferences.Core.getTopMostDeclarationNamesInFile(declarationName, fileToSearch);
174196
+ return ts.mapDefined(matches, function (match) {
174197
+ var symbol = auxiliaryProgram.getTypeChecker().getSymbolAtLocation(match);
174198
+ var decl = ts.getDeclarationFromName(match);
174199
+ if (symbol && decl) {
174200
+ // I think the last argument to this is supposed to be the start node, but it doesn't seem important.
174201
+ // Callers internal to GoToDefinition already get confused about this.
174202
+ return ts.GoToDefinition.createDefinitionInfo(decl, auxiliaryProgram.getTypeChecker(), symbol, decl);
174203
+ }
174204
+ });
174205
+ }
173828
174206
  };
173829
174207
  Session.prototype.getEmitOutput = function (args) {
173830
174208
  var _a = this.getFileAndProject(args), file = _a.file, project = _a.project;
@@ -174106,6 +174484,7 @@ var ts;
174106
174484
  var projects = this.getProjects(args);
174107
174485
  var fileName = args.file;
174108
174486
  var references = [];
174487
+ var seen = createDocumentSpanSet();
174109
174488
  forEachProjectInProjects(projects, /*path*/ undefined, function (project) {
174110
174489
  if (project.getCancellationToken().isCancellationRequested())
174111
174490
  return;
@@ -174113,8 +174492,9 @@ var ts;
174113
174492
  if (projectOutputs) {
174114
174493
  for (var _i = 0, projectOutputs_3 = projectOutputs; _i < projectOutputs_3.length; _i++) {
174115
174494
  var referenceEntry = projectOutputs_3[_i];
174116
- if (!ts.contains(references, referenceEntry, ts.documentSpansEqual)) {
174495
+ if (!seen.has(referenceEntry)) {
174117
174496
  references.push(referenceEntry);
174497
+ seen.add(referenceEntry);
174118
174498
  }
174119
174499
  }
174120
174500
  }