typescript 4.7.0-dev.20220311 → 4.7.0-dev.20220314

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-dev.20220311";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220314";
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) {
@@ -2099,13 +2252,15 @@ var ts;
2099
2252
  for (var _i = 0; _i < arguments.length; _i++) {
2100
2253
  args[_i] = arguments[_i];
2101
2254
  }
2255
+ var lastResult;
2102
2256
  for (var _a = 0, fs_1 = fs; _a < fs_1.length; _a++) {
2103
2257
  var f = fs_1[_a];
2104
- if (f.apply(void 0, args)) {
2105
- return true;
2258
+ lastResult = f.apply(void 0, args);
2259
+ if (lastResult) {
2260
+ return lastResult;
2106
2261
  }
2107
2262
  }
2108
- return false;
2263
+ return lastResult;
2109
2264
  };
2110
2265
  }
2111
2266
  ts.or = or;
@@ -5125,6 +5280,21 @@ var ts;
5125
5280
  ModuleResolutionKind[ModuleResolutionKind["Node12"] = 3] = "Node12";
5126
5281
  ModuleResolutionKind[ModuleResolutionKind["NodeNext"] = 99] = "NodeNext";
5127
5282
  })(ModuleResolutionKind = ts.ModuleResolutionKind || (ts.ModuleResolutionKind = {}));
5283
+ var ModuleDetectionKind;
5284
+ (function (ModuleDetectionKind) {
5285
+ /**
5286
+ * Files with imports, exports and/or import.meta are considered modules
5287
+ */
5288
+ ModuleDetectionKind[ModuleDetectionKind["Legacy"] = 1] = "Legacy";
5289
+ /**
5290
+ * Legacy, but also files with jsx under react-jsx or react-jsxdev and esm mode files under moduleResolution: node12+
5291
+ */
5292
+ ModuleDetectionKind[ModuleDetectionKind["Auto"] = 2] = "Auto";
5293
+ /**
5294
+ * Consider all non-declaration files modules, regardless of present syntax
5295
+ */
5296
+ ModuleDetectionKind[ModuleDetectionKind["Force"] = 3] = "Force";
5297
+ })(ModuleDetectionKind = ts.ModuleDetectionKind || (ts.ModuleDetectionKind = {}));
5128
5298
  var WatchFileKind;
5129
5299
  (function (WatchFileKind) {
5130
5300
  WatchFileKind[WatchFileKind["FixedPollingInterval"] = 0] = "FixedPollingInterval";
@@ -8222,6 +8392,8 @@ var ts;
8222
8392
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8223
8393
  An_import_declaration_can_only_be_used_at_the_top_level_of_a_module: diag(1473, ts.DiagnosticCategory.Error, "An_import_declaration_can_only_be_used_at_the_top_level_of_a_module_1473", "An import declaration can only be used at the top level of a module."),
8224
8394
  An_export_declaration_can_only_be_used_at_the_top_level_of_a_module: diag(1474, ts.DiagnosticCategory.Error, "An_export_declaration_can_only_be_used_at_the_top_level_of_a_module_1474", "An export declaration can only be used at the top level of a module."),
8395
+ Control_what_method_is_used_to_detect_module_format_JS_files: diag(1475, ts.DiagnosticCategory.Message, "Control_what_method_is_used_to_detect_module_format_JS_files_1475", "Control what method is used to detect module-format JS files."),
8396
+ auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node12_as_modules: diag(1476, ts.DiagnosticCategory.Message, "auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_w_1476", "\"auto\": Treat files with imports, exports, import.meta, jsx (with jsx: react-jsx), or esm format (with module: node12+) as modules."),
8225
8397
  The_types_of_0_are_incompatible_between_these_types: diag(2200, ts.DiagnosticCategory.Error, "The_types_of_0_are_incompatible_between_these_types_2200", "The types of '{0}' are incompatible between these types."),
8226
8398
  The_types_returned_by_0_are_incompatible_between_these_types: diag(2201, ts.DiagnosticCategory.Error, "The_types_returned_by_0_are_incompatible_between_these_types_2201", "The types returned by '{0}' are incompatible between these types."),
8227
8399
  Call_signature_return_types_0_and_1_are_incompatible: diag(2202, ts.DiagnosticCategory.Error, "Call_signature_return_types_0_and_1_are_incompatible_2202", "Call signature return types '{0}' and '{1}' are incompatible.", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ true),
@@ -19731,6 +19903,61 @@ var ts;
19731
19903
  return scriptKind === 4 /* TSX */ || scriptKind === 2 /* JSX */ || scriptKind === 1 /* JS */ || scriptKind === 6 /* JSON */ ? 1 /* JSX */ : 0 /* Standard */;
19732
19904
  }
19733
19905
  ts.getLanguageVariant = getLanguageVariant;
19906
+ /**
19907
+ * This is a somewhat unavoidable full tree walk to locate a JSX tag - `import.meta` requires the same,
19908
+ * but we avoid that walk (or parts of it) if at all possible using the `PossiblyContainsImportMeta` node flag.
19909
+ * Unfortunately, there's no `NodeFlag` space to do the same for JSX.
19910
+ */
19911
+ function walkTreeForJSXTags(node) {
19912
+ if (!(node.transformFlags & 2 /* ContainsJsx */))
19913
+ return undefined;
19914
+ return ts.isJsxOpeningLikeElement(node) || ts.isJsxFragment(node) ? node : ts.forEachChild(node, walkTreeForJSXTags);
19915
+ }
19916
+ function isFileModuleFromUsingJSXTag(file) {
19917
+ // Excludes declaration files - they still require an explicit `export {}` or the like
19918
+ // for back compat purposes. (not that declaration files should contain JSX tags!)
19919
+ return !file.isDeclarationFile ? walkTreeForJSXTags(file) : undefined;
19920
+ }
19921
+ /**
19922
+ * Note that this requires file.impliedNodeFormat be set already; meaning it must be set very early on
19923
+ * in SourceFile construction.
19924
+ */
19925
+ function isFileForcedToBeModuleByFormat(file) {
19926
+ // Excludes declaration files - they still require an explicit `export {}` or the like
19927
+ // for back compat purposes.
19928
+ return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined;
19929
+ }
19930
+ function getSetExternalModuleIndicator(options) {
19931
+ // TODO: Should this callback be cached?
19932
+ switch (getEmitModuleDetectionKind(options)) {
19933
+ case ts.ModuleDetectionKind.Force:
19934
+ // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule
19935
+ return function (file) {
19936
+ file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file);
19937
+ };
19938
+ case ts.ModuleDetectionKind.Legacy:
19939
+ // Files are modules if they have imports, exports, or import.meta
19940
+ return function (file) {
19941
+ file.externalModuleIndicator = ts.isFileProbablyExternalModule(file);
19942
+ };
19943
+ case ts.ModuleDetectionKind.Auto:
19944
+ // If module is nodenext or node12, all esm format files are modules
19945
+ // If jsx is react-jsx or react-jsxdev then jsx tags force module-ness
19946
+ // otherwise, the presence of import or export statments (or import.meta) implies module-ness
19947
+ var checks = [ts.isFileProbablyExternalModule];
19948
+ if (options.jsx === 4 /* ReactJSX */ || options.jsx === 5 /* ReactJSXDev */) {
19949
+ checks.push(isFileModuleFromUsingJSXTag);
19950
+ }
19951
+ var moduleKind = getEmitModuleKind(options);
19952
+ if (moduleKind === ts.ModuleKind.Node12 || moduleKind === ts.ModuleKind.NodeNext) {
19953
+ checks.push(isFileForcedToBeModuleByFormat);
19954
+ }
19955
+ var combined_1 = ts.or.apply(void 0, checks);
19956
+ var callback = function (file) { return void (file.externalModuleIndicator = combined_1(file)); };
19957
+ return callback;
19958
+ }
19959
+ }
19960
+ ts.getSetExternalModuleIndicator = getSetExternalModuleIndicator;
19734
19961
  function getEmitScriptTarget(compilerOptions) {
19735
19962
  return compilerOptions.target ||
19736
19963
  (compilerOptions.module === ts.ModuleKind.Node12 && 7 /* ES2020 */) ||
@@ -19765,6 +19992,10 @@ var ts;
19765
19992
  return moduleResolution;
19766
19993
  }
19767
19994
  ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind;
19995
+ function getEmitModuleDetectionKind(options) {
19996
+ return options.moduleDetection || ts.ModuleDetectionKind.Auto;
19997
+ }
19998
+ ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind;
19768
19999
  function hasJsonModuleEmitEnabled(options) {
19769
20000
  switch (getEmitModuleKind(options)) {
19770
20001
  case ts.ModuleKind.CommonJS:
@@ -29935,6 +30166,36 @@ var ts;
29935
30166
  text.charCodeAt(start + 3) !== 47 /* slash */;
29936
30167
  }
29937
30168
  ts.isJSDocLikeText = isJSDocLikeText;
30169
+ /*@internal*/
30170
+ function isFileProbablyExternalModule(sourceFile) {
30171
+ // Try to use the first top-level import/export when available, then
30172
+ // fall back to looking for an 'import.meta' somewhere in the tree if necessary.
30173
+ return ts.forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) ||
30174
+ getImportMetaIfNecessary(sourceFile);
30175
+ }
30176
+ ts.isFileProbablyExternalModule = isFileProbablyExternalModule;
30177
+ function isAnExternalModuleIndicatorNode(node) {
30178
+ return hasModifierOfKind(node, 93 /* ExportKeyword */)
30179
+ || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
30180
+ || ts.isImportDeclaration(node)
30181
+ || ts.isExportAssignment(node)
30182
+ || ts.isExportDeclaration(node) ? node : undefined;
30183
+ }
30184
+ function getImportMetaIfNecessary(sourceFile) {
30185
+ return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
30186
+ walkTreeForImportMeta(sourceFile) :
30187
+ undefined;
30188
+ }
30189
+ function walkTreeForImportMeta(node) {
30190
+ return isImportMeta(node) ? node : forEachChild(node, walkTreeForImportMeta);
30191
+ }
30192
+ /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */
30193
+ function hasModifierOfKind(node, kind) {
30194
+ return ts.some(node.modifiers, function (m) { return m.kind === kind; });
30195
+ }
30196
+ function isImportMeta(node) {
30197
+ return ts.isMetaProperty(node) && node.keywordToken === 100 /* ImportKeyword */ && node.name.escapedText === "meta";
30198
+ }
29938
30199
  /**
29939
30200
  * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
29940
30201
  * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
@@ -30516,17 +30777,25 @@ var ts;
30516
30777
  children.unshift(n);
30517
30778
  }
30518
30779
  }
30519
- function createSourceFile(fileName, sourceText, languageVersion, setParentNodes, scriptKind) {
30780
+ function setExternalModuleIndicator(sourceFile) {
30781
+ sourceFile.externalModuleIndicator = isFileProbablyExternalModule(sourceFile);
30782
+ }
30783
+ function createSourceFile(fileName, sourceText, languageVersionOrOptions, setParentNodes, scriptKind) {
30520
30784
  if (setParentNodes === void 0) { setParentNodes = false; }
30521
30785
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("parse" /* Parse */, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
30522
30786
  ts.performance.mark("beforeParse");
30523
30787
  var result;
30524
30788
  ts.perfLogger.logStartParseSourceFile(fileName);
30789
+ var _a = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions : { languageVersion: languageVersionOrOptions }, languageVersion = _a.languageVersion, overrideSetExternalModuleIndicator = _a.setExternalModuleIndicator, format = _a.impliedNodeFormat;
30525
30790
  if (languageVersion === 100 /* JSON */) {
30526
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, 6 /* JSON */);
30791
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, 6 /* JSON */, ts.noop);
30527
30792
  }
30528
30793
  else {
30529
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind);
30794
+ var setIndicator = format === undefined ? overrideSetExternalModuleIndicator : function (file) {
30795
+ file.impliedNodeFormat = format;
30796
+ return (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file);
30797
+ };
30798
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator);
30530
30799
  }
30531
30800
  ts.perfLogger.logStopParseSourceFile();
30532
30801
  ts.performance.mark("afterParse");
@@ -30712,7 +30981,7 @@ var ts;
30712
30981
  // Note: any errors at the end of the file that do not precede a regular node, should get
30713
30982
  // attached to the EOF token.
30714
30983
  var parseErrorBeforeNextFinishedNode = false;
30715
- function parseSourceFile(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes, scriptKind) {
30984
+ function parseSourceFile(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes, scriptKind, setExternalModuleIndicatorOverride) {
30716
30985
  var _a;
30717
30986
  if (setParentNodes === void 0) { setParentNodes = false; }
30718
30987
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
@@ -30728,7 +30997,7 @@ var ts;
30728
30997
  return result_3;
30729
30998
  }
30730
30999
  initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind);
30731
- var result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind);
31000
+ var result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator);
30732
31001
  clearState();
30733
31002
  return result;
30734
31003
  }
@@ -30812,7 +31081,7 @@ var ts;
30812
31081
  endOfFileToken = parseExpectedToken(1 /* EndOfFileToken */, ts.Diagnostics.Unexpected_token);
30813
31082
  }
30814
31083
  // Set source file so that errors will be reported with this file name
30815
- var sourceFile = createSourceFile(fileName, 2 /* ES2015 */, 6 /* JSON */, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags);
31084
+ var sourceFile = createSourceFile(fileName, 2 /* ES2015 */, 6 /* JSON */, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags, ts.noop);
30816
31085
  if (setParentNodes) {
30817
31086
  fixupParentReferences(sourceFile);
30818
31087
  }
@@ -30886,7 +31155,7 @@ var ts;
30886
31155
  notParenthesizedArrow = undefined;
30887
31156
  topLevel = true;
30888
31157
  }
30889
- function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind) {
31158
+ function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicator) {
30890
31159
  var isDeclarationFile = isDeclarationFileName(fileName);
30891
31160
  if (isDeclarationFile) {
30892
31161
  contextFlags |= 8388608 /* Ambient */;
@@ -30897,7 +31166,7 @@ var ts;
30897
31166
  var statements = parseList(0 /* SourceElements */, parseStatement);
30898
31167
  ts.Debug.assert(token() === 1 /* EndOfFileToken */);
30899
31168
  var endOfFileToken = addJSDocComment(parseTokenNode());
30900
- var sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags);
31169
+ var sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags, setExternalModuleIndicator);
30901
31170
  // A member of ReadonlyArray<T> isn't assignable to a member of T[] (and prevents a direct cast) - but this is where we set up those members so they can be readonly in the future
30902
31171
  processCommentPragmas(sourceFile, sourceText);
30903
31172
  processPragmasIntoFields(sourceFile, reportPragmaDiagnostic);
@@ -31034,25 +31303,30 @@ var ts;
31034
31303
  ts.setParentRecursive(rootNode, /*incremental*/ true);
31035
31304
  }
31036
31305
  Parser.fixupParentReferences = fixupParentReferences;
31037
- function createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, flags) {
31306
+ function createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, flags, setExternalModuleIndicator) {
31038
31307
  // code from createNode is inlined here so createNode won't have to deal with special case of creating source files
31039
31308
  // this is quite rare comparing to other nodes and createNode should be as fast as possible
31040
31309
  var sourceFile = factory.createSourceFile(statements, endOfFileToken, flags);
31041
31310
  ts.setTextRangePosWidth(sourceFile, 0, sourceText.length);
31042
- setExternalModuleIndicator(sourceFile);
31311
+ setFields(sourceFile);
31043
31312
  // If we parsed this as an external module, it may contain top-level await
31044
31313
  if (!isDeclarationFile && isExternalModule(sourceFile) && sourceFile.transformFlags & 16777216 /* ContainsPossibleTopLevelAwait */) {
31045
31314
  sourceFile = reparseTopLevelAwait(sourceFile);
31315
+ setFields(sourceFile);
31046
31316
  }
31047
- sourceFile.text = sourceText;
31048
- sourceFile.bindDiagnostics = [];
31049
- sourceFile.bindSuggestionDiagnostics = undefined;
31050
- sourceFile.languageVersion = languageVersion;
31051
- sourceFile.fileName = fileName;
31052
- sourceFile.languageVariant = ts.getLanguageVariant(scriptKind);
31053
- sourceFile.isDeclarationFile = isDeclarationFile;
31054
- sourceFile.scriptKind = scriptKind;
31055
31317
  return sourceFile;
31318
+ function setFields(sourceFile) {
31319
+ sourceFile.text = sourceText;
31320
+ sourceFile.bindDiagnostics = [];
31321
+ sourceFile.bindSuggestionDiagnostics = undefined;
31322
+ sourceFile.languageVersion = languageVersion;
31323
+ sourceFile.fileName = fileName;
31324
+ sourceFile.languageVariant = ts.getLanguageVariant(scriptKind);
31325
+ sourceFile.isDeclarationFile = isDeclarationFile;
31326
+ sourceFile.scriptKind = scriptKind;
31327
+ setExternalModuleIndicator(sourceFile);
31328
+ sourceFile.setExternalModuleIndicator = setExternalModuleIndicator;
31329
+ }
31056
31330
  }
31057
31331
  function setContextFlag(val, flag) {
31058
31332
  if (val) {
@@ -36535,35 +36809,6 @@ var ts;
36535
36809
  var node = factory.createExportAssignment(decorators, modifiers, isExportEquals, expression);
36536
36810
  return withJSDoc(finishNode(node, pos), hasJSDoc);
36537
36811
  }
36538
- function setExternalModuleIndicator(sourceFile) {
36539
- // Try to use the first top-level import/export when available, then
36540
- // fall back to looking for an 'import.meta' somewhere in the tree if necessary.
36541
- sourceFile.externalModuleIndicator =
36542
- ts.forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) ||
36543
- getImportMetaIfNecessary(sourceFile);
36544
- }
36545
- function isAnExternalModuleIndicatorNode(node) {
36546
- return hasModifierOfKind(node, 93 /* ExportKeyword */)
36547
- || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
36548
- || ts.isImportDeclaration(node)
36549
- || ts.isExportAssignment(node)
36550
- || ts.isExportDeclaration(node) ? node : undefined;
36551
- }
36552
- function getImportMetaIfNecessary(sourceFile) {
36553
- return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
36554
- walkTreeForExternalModuleIndicators(sourceFile) :
36555
- undefined;
36556
- }
36557
- function walkTreeForExternalModuleIndicators(node) {
36558
- return isImportMeta(node) ? node : forEachChild(node, walkTreeForExternalModuleIndicators);
36559
- }
36560
- /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */
36561
- function hasModifierOfKind(node, kind) {
36562
- return ts.some(node.modifiers, function (m) { return m.kind === kind; });
36563
- }
36564
- function isImportMeta(node) {
36565
- return ts.isMetaProperty(node) && node.keywordToken === 100 /* ImportKeyword */ && node.name.escapedText === "meta";
36566
- }
36567
36812
  var ParsingContext;
36568
36813
  (function (ParsingContext) {
36569
36814
  ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements";
@@ -36606,7 +36851,7 @@ var ts;
36606
36851
  scanner.setText(content, start, length);
36607
36852
  currentToken = scanner.scan();
36608
36853
  var jsDocTypeExpression = parseJSDocTypeExpression();
36609
- var sourceFile = createSourceFile("file.js", 99 /* Latest */, 1 /* JS */, /*isDeclarationFile*/ false, [], factory.createToken(1 /* EndOfFileToken */), 0 /* None */);
36854
+ var sourceFile = createSourceFile("file.js", 99 /* Latest */, 1 /* JS */, /*isDeclarationFile*/ false, [], factory.createToken(1 /* EndOfFileToken */), 0 /* None */, ts.noop);
36610
36855
  var diagnostics = ts.attachFileToDiagnostics(parseDiagnostics, sourceFile);
36611
36856
  if (jsDocDiagnostics) {
36612
36857
  sourceFile.jsDocDiagnostics = ts.attachFileToDiagnostics(jsDocDiagnostics, sourceFile);
@@ -37567,7 +37812,7 @@ var ts;
37567
37812
  if (sourceFile.statements.length === 0) {
37568
37813
  // If we don't have any statements in the current source file, then there's no real
37569
37814
  // way to incrementally parse. So just do a full parse instead.
37570
- return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind);
37815
+ return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
37571
37816
  }
37572
37817
  // Make sure we're not trying to incrementally update a source file more than once. Once
37573
37818
  // we do an update the original source file is considered unusable from that point onwards.
@@ -37624,7 +37869,7 @@ var ts;
37624
37869
  // inconsistent tree. Setting the parents on the new tree should be very fast. We
37625
37870
  // will immediately bail out of walking any subtrees when we can see that their parents
37626
37871
  // are already correct.
37627
- var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind);
37872
+ var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
37628
37873
  result.commentDirectives = getNewCommentDirectives(sourceFile.commentDirectives, result.commentDirectives, changeRange.span.start, ts.textSpanEnd(changeRange.span), delta, oldText, newText, aggressiveChecks);
37629
37874
  result.impliedNodeFormat = sourceFile.impliedNodeFormat;
37630
37875
  return result;
@@ -39540,6 +39785,18 @@ var ts;
39540
39785
  description: ts.Diagnostics.Specify_a_list_of_language_service_plugins_to_include,
39541
39786
  category: ts.Diagnostics.Editor_Support,
39542
39787
  },
39788
+ {
39789
+ name: "moduleDetection",
39790
+ type: new ts.Map(ts.getEntries({
39791
+ auto: ts.ModuleDetectionKind.Auto,
39792
+ legacy: ts.ModuleDetectionKind.Legacy,
39793
+ force: ts.ModuleDetectionKind.Force,
39794
+ })),
39795
+ affectsModuleResolution: true,
39796
+ description: ts.Diagnostics.Control_what_method_is_used_to_detect_module_format_JS_files,
39797
+ category: ts.Diagnostics.Language_and_Environment,
39798
+ defaultValueDescription: ts.Diagnostics.auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node12_as_modules,
39799
+ }
39543
39800
  ];
39544
39801
  /* @internal */
39545
39802
  ts.optionDeclarations = __spreadArray(__spreadArray([], ts.commonOptionsWithBuild, true), commandOptionsWithoutBuild, true);
@@ -63493,7 +63750,8 @@ var ts;
63493
63750
  return true;
63494
63751
  }
63495
63752
  }
63496
- else {
63753
+ else if (!((source.flags | target.flags) & (3145728 /* UnionOrIntersection */ | 8388608 /* IndexedAccess */ | 16777216 /* Conditional */ | 33554432 /* Substitution */))) {
63754
+ // We have excluded types that may simplify to other forms, so types must have identical flags
63497
63755
  if (source.flags !== target.flags)
63498
63756
  return false;
63499
63757
  if (source.flags & 67358815 /* Singleton */)
@@ -69569,7 +69827,7 @@ var ts;
69569
69827
  return result;
69570
69828
  }
69571
69829
  function getCandidateDiscriminantPropertyAccess(expr) {
69572
- if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
69830
+ if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference) || ts.isObjectLiteralMethod(reference)) {
69573
69831
  // When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
69574
69832
  // getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
69575
69833
  // parameter declared in the same parameter list is a candidate.
@@ -76541,6 +76799,9 @@ var ts;
76541
76799
  assignBindingElementTypes(declaration.name, links.type);
76542
76800
  }
76543
76801
  }
76802
+ else if (type) {
76803
+ ts.Debug.assertEqual(links.type, type, "Parameter symbol already has a cached type which differs from newly assigned type");
76804
+ }
76544
76805
  }
76545
76806
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76546
76807
  // the destructured type into the contained binding elements.
@@ -87433,8 +87694,8 @@ var ts;
87433
87694
  }
87434
87695
  else {
87435
87696
  var elements = name.elements;
87436
- for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
87437
- var element = elements_1[_i];
87697
+ for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87698
+ var element = elements_2[_i];
87438
87699
  if (!ts.isOmittedExpression(element)) {
87439
87700
  return checkESModuleMarker(element.name);
87440
87701
  }
@@ -87450,8 +87711,8 @@ var ts;
87450
87711
  }
87451
87712
  else {
87452
87713
  var elements = name.elements;
87453
- for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87454
- var element = elements_2[_i];
87714
+ for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
87715
+ var element = elements_3[_i];
87455
87716
  if (!ts.isOmittedExpression(element)) {
87456
87717
  checkGrammarNameInLetOrConstDeclarations(element.name);
87457
87718
  }
@@ -89705,8 +89966,8 @@ var ts;
89705
89966
  }
89706
89967
  function bindingOrAssignmentPatternAssignsToName(pattern, escapedName) {
89707
89968
  var elements = ts.getElementsOfBindingOrAssignmentPattern(pattern);
89708
- for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
89709
- var element = elements_3[_i];
89969
+ for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
89970
+ var element = elements_4[_i];
89710
89971
  if (bindingOrAssignmentElementAssignsToName(element, escapedName)) {
89711
89972
  return true;
89712
89973
  }
@@ -95324,8 +95585,8 @@ var ts;
95324
95585
  function chunkObjectLiteralElements(elements) {
95325
95586
  var chunkObject;
95326
95587
  var objects = [];
95327
- for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
95328
- var e = elements_4[_i];
95588
+ for (var _i = 0, elements_5 = elements; _i < elements_5.length; _i++) {
95589
+ var e = elements_5[_i];
95329
95590
  if (e.kind === 297 /* SpreadAssignment */) {
95330
95591
  if (chunkObject) {
95331
95592
  objects.push(factory.createObjectLiteralExpression(chunkObject));
@@ -114346,7 +114607,7 @@ var ts;
114346
114607
  var existingDirectories = new ts.Map();
114347
114608
  var getCanonicalFileName = ts.createGetCanonicalFileName(system.useCaseSensitiveFileNames);
114348
114609
  var computeHash = ts.maybeBind(system, system.createHash) || ts.generateDjb2Hash;
114349
- function getSourceFile(fileName, languageVersion, onError) {
114610
+ function getSourceFile(fileName, languageVersionOrOptions, onError) {
114350
114611
  var text;
114351
114612
  try {
114352
114613
  ts.performance.mark("beforeIORead");
@@ -114360,7 +114621,7 @@ var ts;
114360
114621
  }
114361
114622
  text = "";
114362
114623
  }
114363
- return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined;
114624
+ return text !== undefined ? ts.createSourceFile(fileName, text, languageVersionOrOptions, setParentNodes) : undefined;
114364
114625
  }
114365
114626
  function directoryExists(directoryPath) {
114366
114627
  if (existingDirectories.has(directoryPath)) {
@@ -115766,8 +116027,8 @@ var ts;
115766
116027
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
115767
116028
  var oldSourceFile = oldSourceFiles_2[_i];
115768
116029
  var newSourceFile = host.getSourceFileByPath
115769
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, ts.getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile)
115770
- : host.getSourceFile(oldSourceFile.fileName, ts.getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
116030
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
116031
+ : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
115771
116032
  if (!newSourceFile) {
115772
116033
  return 0 /* Not */;
115773
116034
  }
@@ -115798,7 +116059,6 @@ var ts;
115798
116059
  newSourceFile.originalFileName = oldSourceFile.originalFileName;
115799
116060
  newSourceFile.resolvedPath = oldSourceFile.resolvedPath;
115800
116061
  newSourceFile.fileName = oldSourceFile.fileName;
115801
- newSourceFile.impliedNodeFormat = oldSourceFile.impliedNodeFormat;
115802
116062
  var packageName = oldProgram.sourceFileToPackageName.get(oldSourceFile.path);
115803
116063
  if (packageName !== undefined) {
115804
116064
  // If there are 2 different source files for the same package name and at least one of them changes,
@@ -116717,6 +116977,17 @@ var ts;
116717
116977
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116718
116978
  return result;
116719
116979
  }
116980
+ function getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options) {
116981
+ // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache
116982
+ // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way
116983
+ // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront.
116984
+ var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
116985
+ return {
116986
+ languageVersion: ts.getEmitScriptTarget(options),
116987
+ impliedNodeFormat: impliedNodeFormat,
116988
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
116989
+ };
116990
+ }
116720
116991
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
116721
116992
  var path = toPath(fileName);
116722
116993
  if (useSourceOfProjectReferenceRedirect) {
@@ -116804,7 +117075,7 @@ var ts;
116804
117075
  }
116805
117076
  }
116806
117077
  // We haven't looked for this file, do so now and cache result
116807
- var file = host.getSourceFile(fileName, ts.getEmitScriptTarget(options), function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]); }, shouldCreateNewSourceFile);
117078
+ var file = host.getSourceFile(fileName, getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options), function (hostErrorMessage) { return addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, ts.Diagnostics.Cannot_read_file_0_Colon_1, [fileName, hostErrorMessage]); }, shouldCreateNewSourceFile);
116808
117079
  if (packageId) {
116809
117080
  var packageIdKey = ts.packageIdToString(packageId);
116810
117081
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
@@ -116832,10 +117103,6 @@ var ts;
116832
117103
  file.path = path;
116833
117104
  file.resolvedPath = toPath(fileName);
116834
117105
  file.originalFileName = originalFileName;
116835
- // It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache
116836
- // and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way
116837
- // to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront.
116838
- file.impliedNodeFormat = getImpliedNodeFormatForFile(file.resolvedPath, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
116839
117106
  addFileIncludeReason(file, reason);
116840
117107
  if (host.useCaseSensitiveFileNames()) {
116841
117108
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -117337,7 +117604,7 @@ var ts;
117337
117604
  }
117338
117605
  else if (firstNonAmbientExternalModuleSourceFile && languageVersion < 2 /* ES2015 */ && options.module === ts.ModuleKind.None) {
117339
117606
  // We cannot use createDiagnosticFromNode because nodes do not have parents yet
117340
- var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117607
+ var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117341
117608
  programDiagnostics.add(ts.createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none));
117342
117609
  }
117343
117610
  // Cannot specify module gen that isn't amd or system with --out
@@ -117346,7 +117613,7 @@ var ts;
117346
117613
  createDiagnosticForOptionName(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile", "module");
117347
117614
  }
117348
117615
  else if (options.module === undefined && firstNonAmbientExternalModuleSourceFile) {
117349
- var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117616
+ var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117350
117617
  programDiagnostics.add(ts.createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile"));
117351
117618
  }
117352
117619
  }
@@ -121608,7 +121875,7 @@ var ts;
121608
121875
  var useCaseSensitiveFileNames = host.useCaseSensitiveFileNames();
121609
121876
  var hostGetNewLine = ts.memoize(function () { return host.getNewLine(); });
121610
121877
  return {
121611
- getSourceFile: function (fileName, languageVersion, onError) {
121878
+ getSourceFile: function (fileName, languageVersionOrOptions, onError) {
121612
121879
  var text;
121613
121880
  try {
121614
121881
  ts.performance.mark("beforeIORead");
@@ -121622,7 +121889,7 @@ var ts;
121622
121889
  }
121623
121890
  text = "";
121624
121891
  }
121625
- return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion) : undefined;
121892
+ return text !== undefined ? ts.createSourceFile(fileName, text, languageVersionOrOptions) : undefined;
121626
121893
  },
121627
121894
  getDefaultLibLocation: ts.maybeBind(host, host.getDefaultLibLocation),
121628
121895
  getDefaultLibFileName: function (options) { return host.getDefaultLibFileName(options); },
@@ -122090,7 +122357,7 @@ var ts;
122090
122357
  }
122091
122358
  return directoryStructureHost.fileExists(fileName);
122092
122359
  }
122093
- function getVersionedSourceFileByPath(fileName, path, languageVersion, onError, shouldCreateNewSourceFile) {
122360
+ function getVersionedSourceFileByPath(fileName, path, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
122094
122361
  var hostSourceFile = sourceFilesCache.get(path);
122095
122362
  // No source file on the host
122096
122363
  if (isFileMissingOnHost(hostSourceFile)) {
@@ -122098,7 +122365,7 @@ var ts;
122098
122365
  }
122099
122366
  // Create new source file if requested or the versions dont match
122100
122367
  if (hostSourceFile === undefined || shouldCreateNewSourceFile || isFilePresenceUnknownOnHost(hostSourceFile)) {
122101
- var sourceFile = getNewSourceFile(fileName, languageVersion, onError);
122368
+ var sourceFile = getNewSourceFile(fileName, languageVersionOrOptions, onError);
122102
122369
  if (hostSourceFile) {
122103
122370
  if (sourceFile) {
122104
122371
  // Set the source file and create file watcher now that file was present on the disk
@@ -133786,9 +134053,15 @@ var ts;
133786
134053
  });
133787
134054
  return JSON.stringify(bucketInfoArray, undefined, 2);
133788
134055
  }
134056
+ function getCompilationSettings(settingsOrHost) {
134057
+ if (typeof settingsOrHost.getCompilationSettings === "function") {
134058
+ return settingsOrHost.getCompilationSettings();
134059
+ }
134060
+ return settingsOrHost;
134061
+ }
133789
134062
  function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
133790
134063
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
133791
- var key = getKeyForCompilationSettings(compilationSettings);
134064
+ var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
133792
134065
  return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
133793
134066
  }
133794
134067
  function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
@@ -133796,20 +134069,28 @@ var ts;
133796
134069
  }
133797
134070
  function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
133798
134071
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
133799
- var key = getKeyForCompilationSettings(compilationSettings);
134072
+ var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
133800
134073
  return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
133801
134074
  }
133802
134075
  function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
133803
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
134076
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
133804
134077
  }
133805
134078
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
133806
134079
  var entry = isDocumentRegistryEntry(bucketEntry) ? bucketEntry : bucketEntry.get(ts.Debug.checkDefined(scriptKind, "If there are more than one scriptKind's for same document the scriptKind should be provided"));
133807
134080
  ts.Debug.assert(scriptKind === undefined || !entry || entry.sourceFile.scriptKind === scriptKind, "Script kind should match provided ScriptKind:" + scriptKind + " and sourceFile.scriptKind: " + (entry === null || entry === void 0 ? void 0 : entry.sourceFile.scriptKind) + ", !entry: " + !entry);
133808
134081
  return entry;
133809
134082
  }
133810
- function acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, acquiring, scriptKind) {
134083
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
134084
+ var _a, _b, _c, _d;
133811
134085
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
134086
+ var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
134087
+ var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
133812
134088
  var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
134089
+ var sourceFileOptions = {
134090
+ languageVersion: scriptTarget,
134091
+ impliedNodeFormat: host && ts.getImpliedNodeFormatForFile(path, (_d = (_c = (_b = (_a = host.getCompilerHost) === null || _a === void 0 ? void 0 : _a.call(host)) === null || _b === void 0 ? void 0 : _b.getModuleResolutionCache) === null || _c === void 0 ? void 0 : _c.call(_b)) === null || _d === void 0 ? void 0 : _d.getPackageJsonInfoCache(), host, compilationSettings),
134092
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
134093
+ };
133813
134094
  var oldBucketCount = buckets.size;
133814
134095
  var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
133815
134096
  if (ts.tracing) {
@@ -133843,7 +134124,7 @@ var ts;
133843
134124
  }
133844
134125
  if (!entry) {
133845
134126
  // Have never seen this file with these settings. Create a new source file for it.
133846
- var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, /*setNodeParents*/ false, scriptKind);
134127
+ var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
133847
134128
  if (externalCache) {
133848
134129
  externalCache.setDocument(key, path, sourceFile);
133849
134130
  }
@@ -142287,7 +142568,7 @@ var ts;
142287
142568
  continue;
142288
142569
  var module_1 = ts.getResolvedModule(sourceFile, moduleSpecifier.text, ts.getModeForUsageLocation(sourceFile, moduleSpecifier));
142289
142570
  var resolvedFile = module_1 && program.getSourceFile(module_1.resolvedFileName);
142290
- if (resolvedFile && resolvedFile.externalModuleIndicator && ts.isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) {
142571
+ if (resolvedFile && resolvedFile.externalModuleIndicator && resolvedFile.externalModuleIndicator !== true && ts.isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) {
142291
142572
  diags.push(ts.createDiagnosticForNode(name, ts.Diagnostics.Import_may_be_converted_to_a_default_import));
142292
142573
  }
142293
142574
  }
@@ -143203,19 +143484,7 @@ var ts;
143203
143484
  options.suppressOutputPathCheck = true;
143204
143485
  // Filename can be non-ts file.
143205
143486
  options.allowNonTsExtensions = true;
143206
- // if jsx is specified then treat file as .tsx
143207
- var inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
143208
- var sourceFile = ts.createSourceFile(inputFileName, input, ts.getEmitScriptTarget(options));
143209
- if (transpileOptions.moduleName) {
143210
- sourceFile.moduleName = transpileOptions.moduleName;
143211
- }
143212
- if (transpileOptions.renamedDependencies) {
143213
- sourceFile.renamedDependencies = new ts.Map(ts.getEntries(transpileOptions.renamedDependencies));
143214
- }
143215
143487
  var newLine = ts.getNewLineCharacter(options);
143216
- // Output
143217
- var outputText;
143218
- var sourceMapText;
143219
143488
  // Create a compilerHost object to allow the compiler to read and write files
143220
143489
  var compilerHost = {
143221
143490
  getSourceFile: function (fileName) { return fileName === ts.normalizePath(inputFileName) ? sourceFile : undefined; },
@@ -143239,6 +143508,22 @@ var ts;
143239
143508
  directoryExists: function () { return true; },
143240
143509
  getDirectories: function () { return []; }
143241
143510
  };
143511
+ // if jsx is specified then treat file as .tsx
143512
+ var inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
143513
+ var sourceFile = ts.createSourceFile(inputFileName, input, {
143514
+ languageVersion: ts.getEmitScriptTarget(options),
143515
+ impliedNodeFormat: ts.getImpliedNodeFormatForFile(ts.toPath(inputFileName, "", compilerHost.getCanonicalFileName), /*cache*/ undefined, compilerHost, options),
143516
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
143517
+ });
143518
+ if (transpileOptions.moduleName) {
143519
+ sourceFile.moduleName = transpileOptions.moduleName;
143520
+ }
143521
+ if (transpileOptions.renamedDependencies) {
143522
+ sourceFile.renamedDependencies = new ts.Map(ts.getEntries(transpileOptions.renamedDependencies));
143523
+ }
143524
+ // Output
143525
+ var outputText;
143526
+ var sourceMapText;
143242
143527
  var program = ts.createProgram([inputFileName], options, compilerHost);
143243
143528
  if (transpileOptions.reportDiagnostics) {
143244
143529
  ts.addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile));
@@ -159751,7 +160036,7 @@ var ts;
159751
160036
  for (var i = 1;; i++) {
159752
160037
  var name = ts.combinePaths(inDirectory, newModuleName + extension);
159753
160038
  if (!host.fileExists(name))
159754
- return newModuleName; // TODO: GH#18217
160039
+ return newModuleName;
159755
160040
  newModuleName = moduleName + "." + i;
159756
160041
  }
159757
160042
  }
@@ -162111,6 +162396,7 @@ var ts;
162111
162396
  this.host = host;
162112
162397
  }
162113
162398
  SyntaxTreeCache.prototype.getCurrentSourceFile = function (fileName) {
162399
+ var _a, _b, _c, _d, _e, _f, _g, _h;
162114
162400
  var scriptSnapshot = this.host.getScriptSnapshot(fileName);
162115
162401
  if (!scriptSnapshot) {
162116
162402
  // The host does not know about this file.
@@ -162121,7 +162407,12 @@ var ts;
162121
162407
  var sourceFile;
162122
162408
  if (this.currentFileName !== fileName) {
162123
162409
  // This is a new file, just parse it
162124
- sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, 99 /* Latest */, version, /*setNodeParents*/ true, scriptKind);
162410
+ var options = {
162411
+ languageVersion: 99 /* Latest */,
162412
+ impliedNodeFormat: ts.getImpliedNodeFormatForFile(ts.toPath(fileName, this.host.getCurrentDirectory(), ((_c = (_b = (_a = this.host).getCompilerHost) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.getCanonicalFileName) || ts.hostGetCanonicalFileName(this.host)), (_h = (_g = (_f = (_e = (_d = this.host).getCompilerHost) === null || _e === void 0 ? void 0 : _e.call(_d)) === null || _f === void 0 ? void 0 : _f.getModuleResolutionCache) === null || _g === void 0 ? void 0 : _g.call(_f)) === null || _h === void 0 ? void 0 : _h.getPackageJsonInfoCache(), this.host, this.host.getCompilationSettings()),
162413
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(this.host.getCompilationSettings())
162414
+ };
162415
+ sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, options, version, /*setNodeParents*/ true, scriptKind);
162125
162416
  }
162126
162417
  else if (this.currentFileVersion !== version) {
162127
162418
  // This is the same file, just a newer version. Incrementally parse the file.
@@ -162143,8 +162434,8 @@ var ts;
162143
162434
  sourceFile.version = version;
162144
162435
  sourceFile.scriptSnapshot = scriptSnapshot;
162145
162436
  }
162146
- function createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, setNodeParents, scriptKind) {
162147
- var sourceFile = ts.createSourceFile(fileName, ts.getSnapshotText(scriptSnapshot), scriptTarget, setNodeParents, scriptKind);
162437
+ function createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTargetOrOptions, version, setNodeParents, scriptKind) {
162438
+ var sourceFile = ts.createSourceFile(fileName, ts.getSnapshotText(scriptSnapshot), scriptTargetOrOptions, setNodeParents, scriptKind);
162148
162439
  setSourceFileFields(sourceFile, scriptSnapshot, version);
162149
162440
  return sourceFile;
162150
162441
  }
@@ -162192,8 +162483,13 @@ var ts;
162192
162483
  return newSourceFile;
162193
162484
  }
162194
162485
  }
162486
+ var options = {
162487
+ languageVersion: sourceFile.languageVersion,
162488
+ impliedNodeFormat: sourceFile.impliedNodeFormat,
162489
+ setExternalModuleIndicator: sourceFile.setExternalModuleIndicator,
162490
+ };
162195
162491
  // Otherwise, just create a new source file.
162196
- return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents*/ true, sourceFile.scriptKind);
162492
+ return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, options, version, /*setNodeParents*/ true, sourceFile.scriptKind);
162197
162493
  }
162198
162494
  ts.updateLanguageServiceSourceFile = updateLanguageServiceSourceFile;
162199
162495
  var NoopCancellationToken = {
@@ -162537,7 +162833,7 @@ var ts;
162537
162833
  // file's script kind, i.e. in one project some file is treated as ".ts"
162538
162834
  // and in another as ".js"
162539
162835
  if (hostFileInformation.scriptKind === oldSourceFile.scriptKind) {
162540
- return documentRegistry.updateDocumentWithKey(fileName, path, newSettings, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
162836
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
162541
162837
  }
162542
162838
  else {
162543
162839
  // Release old source file and fall through to aquire new file with new script kind
@@ -162547,7 +162843,7 @@ var ts;
162547
162843
  // We didn't already have the file. Fall through and acquire it from the registry.
162548
162844
  }
162549
162845
  // Could not find this file in the old program, create a new SourceFile for it.
162550
- return documentRegistry.acquireDocumentWithKey(fileName, path, newSettings, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
162846
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
162551
162847
  }
162552
162848
  }
162553
162849
  // TODO: GH#18217 frequently asserted as defined
@@ -168094,6 +168390,10 @@ var ts;
168094
168390
  this.packageJsonsForAutoImport = new ts.Set(packageJsons.map(function (p) { return p.fileName; }));
168095
168391
  return packageJsons;
168096
168392
  };
168393
+ /* @internal */
168394
+ Project.prototype.getPackageJsonCache = function () {
168395
+ return this.projectService.packageJsonCache;
168396
+ };
168097
168397
  /*@internal*/
168098
168398
  Project.prototype.getCachedExportInfoMap = function () {
168099
168399
  return this.exportMapCache || (this.exportMapCache = ts.createCacheableExportInfoMap(this));
@@ -172532,15 +172832,23 @@ var ts;
172532
172832
  return ts.deduplicate(outputs, ts.equateValues);
172533
172833
  }
172534
172834
  ;
172835
+ function createDocumentSpanSet() {
172836
+ return ts.createSet(function (_a) {
172837
+ var textSpan = _a.textSpan;
172838
+ return textSpan.start + 100003 * textSpan.length;
172839
+ }, ts.documentSpansEqual);
172840
+ }
172535
172841
  function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
172536
172842
  var providePrefixAndSuffixTextForRename = _a.providePrefixAndSuffixTextForRename;
172537
172843
  var outputs = [];
172844
+ var seen = createDocumentSpanSet();
172538
172845
  combineProjectOutputWorker(projects, defaultProject, initialLocation, function (project, location, tryAddToTodo) {
172539
172846
  var projectOutputs = project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
172540
172847
  if (projectOutputs) {
172541
172848
  for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
172542
172849
  var output = projectOutputs_1[_i];
172543
- if (!ts.contains(outputs, output, ts.documentSpansEqual) && !tryAddToTodo(project, documentSpanLocation(output))) {
172850
+ if (!seen.has(output) && !tryAddToTodo(project, documentSpanLocation(output))) {
172851
+ seen.add(output);
172544
172852
  outputs.push(output);
172545
172853
  }
172546
172854
  }
@@ -173924,6 +174232,7 @@ var ts;
173924
174232
  var projects = this.getProjects(args);
173925
174233
  var fileName = args.file;
173926
174234
  var references = [];
174235
+ var seen = createDocumentSpanSet();
173927
174236
  forEachProjectInProjects(projects, /*path*/ undefined, function (project) {
173928
174237
  if (project.getCancellationToken().isCancellationRequested())
173929
174238
  return;
@@ -173931,8 +174240,9 @@ var ts;
173931
174240
  if (projectOutputs) {
173932
174241
  for (var _i = 0, projectOutputs_3 = projectOutputs; _i < projectOutputs_3.length; _i++) {
173933
174242
  var referenceEntry = projectOutputs_3[_i];
173934
- if (!ts.contains(references, referenceEntry, ts.documentSpansEqual)) {
174243
+ if (!seen.has(referenceEntry)) {
173935
174244
  references.push(referenceEntry);
174245
+ seen.add(referenceEntry);
173936
174246
  }
173937
174247
  }
173938
174248
  }