typescript 4.7.0-dev.20220311 → 4.7.0-dev.20220312

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/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220311";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220312";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -1662,6 +1662,159 @@ var ts;
1662
1662
  return createMultiMap();
1663
1663
  }
1664
1664
  ts.createUnderscoreEscapedMultiMap = createUnderscoreEscapedMultiMap;
1665
+ /**
1666
+ * Creates a Set with custom equality and hash code functionality. This is useful when you
1667
+ * want to use something looser than object identity - e.g. "has the same span".
1668
+ *
1669
+ * If `equals(a, b)`, it must be the case that `getHashCode(a) === getHashCode(b)`.
1670
+ * The converse is not required.
1671
+ *
1672
+ * To facilitate a perf optimization (lazy allocation of bucket arrays), `TElement` is
1673
+ * assumed not to be an array type.
1674
+ */
1675
+ function createSet(getHashCode, equals) {
1676
+ var multiMap = new ts.Map();
1677
+ var size = 0;
1678
+ function getElementIterator() {
1679
+ var valueIt = multiMap.values();
1680
+ var arrayIt;
1681
+ return {
1682
+ next: function () {
1683
+ while (true) {
1684
+ if (arrayIt) {
1685
+ var n = arrayIt.next();
1686
+ if (!n.done) {
1687
+ return { value: n.value };
1688
+ }
1689
+ arrayIt = undefined;
1690
+ }
1691
+ else {
1692
+ var n = valueIt.next();
1693
+ if (n.done) {
1694
+ return { value: undefined, done: true };
1695
+ }
1696
+ if (!isArray(n.value)) {
1697
+ return { value: n.value };
1698
+ }
1699
+ arrayIt = arrayIterator(n.value);
1700
+ }
1701
+ }
1702
+ }
1703
+ };
1704
+ }
1705
+ var set = {
1706
+ has: function (element) {
1707
+ var hash = getHashCode(element);
1708
+ if (!multiMap.has(hash))
1709
+ return false;
1710
+ var candidates = multiMap.get(hash);
1711
+ if (!isArray(candidates))
1712
+ return equals(candidates, element);
1713
+ for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
1714
+ var candidate = candidates_1[_i];
1715
+ if (equals(candidate, element)) {
1716
+ return true;
1717
+ }
1718
+ }
1719
+ return false;
1720
+ },
1721
+ add: function (element) {
1722
+ var hash = getHashCode(element);
1723
+ if (multiMap.has(hash)) {
1724
+ var values = multiMap.get(hash);
1725
+ if (isArray(values)) {
1726
+ if (!contains(values, element, equals)) {
1727
+ values.push(element);
1728
+ size++;
1729
+ }
1730
+ }
1731
+ else {
1732
+ var value = values;
1733
+ if (!equals(value, element)) {
1734
+ multiMap.set(hash, [value, element]);
1735
+ size++;
1736
+ }
1737
+ }
1738
+ }
1739
+ else {
1740
+ multiMap.set(hash, element);
1741
+ size++;
1742
+ }
1743
+ return this;
1744
+ },
1745
+ delete: function (element) {
1746
+ var hash = getHashCode(element);
1747
+ if (!multiMap.has(hash))
1748
+ return false;
1749
+ var candidates = multiMap.get(hash);
1750
+ if (isArray(candidates)) {
1751
+ for (var i = 0; i < candidates.length; i++) {
1752
+ if (equals(candidates[i], element)) {
1753
+ if (candidates.length === 1) {
1754
+ multiMap.delete(hash);
1755
+ }
1756
+ else if (candidates.length === 2) {
1757
+ multiMap.set(hash, candidates[1 - i]);
1758
+ }
1759
+ else {
1760
+ unorderedRemoveItemAt(candidates, i);
1761
+ }
1762
+ size--;
1763
+ return true;
1764
+ }
1765
+ }
1766
+ }
1767
+ else {
1768
+ var candidate = candidates;
1769
+ if (equals(candidate, element)) {
1770
+ multiMap.delete(hash);
1771
+ size--;
1772
+ return true;
1773
+ }
1774
+ }
1775
+ return false;
1776
+ },
1777
+ clear: function () {
1778
+ multiMap.clear();
1779
+ size = 0;
1780
+ },
1781
+ get size() {
1782
+ return size;
1783
+ },
1784
+ forEach: function (action) {
1785
+ for (var _i = 0, _a = arrayFrom(multiMap.values()); _i < _a.length; _i++) {
1786
+ var elements = _a[_i];
1787
+ if (isArray(elements)) {
1788
+ for (var _b = 0, elements_1 = elements; _b < elements_1.length; _b++) {
1789
+ var element = elements_1[_b];
1790
+ action(element, element);
1791
+ }
1792
+ }
1793
+ else {
1794
+ var element = elements;
1795
+ action(element, element);
1796
+ }
1797
+ }
1798
+ },
1799
+ keys: function () {
1800
+ return getElementIterator();
1801
+ },
1802
+ values: function () {
1803
+ return getElementIterator();
1804
+ },
1805
+ entries: function () {
1806
+ var it = getElementIterator();
1807
+ return {
1808
+ next: function () {
1809
+ var n = it.next();
1810
+ return n.done ? n : { value: [n.value, n.value] };
1811
+ }
1812
+ };
1813
+ },
1814
+ };
1815
+ return set;
1816
+ }
1817
+ ts.createSet = createSet;
1665
1818
  /**
1666
1819
  * Tests whether a value is an array.
1667
1820
  */
@@ -2055,8 +2208,8 @@ var ts;
2055
2208
  var maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
2056
2209
  var bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
2057
2210
  var bestCandidate;
2058
- for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
2059
- var candidate = candidates_1[_i];
2211
+ for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
2212
+ var candidate = candidates_2[_i];
2060
2213
  var candidateName = getName(candidate);
2061
2214
  if (candidateName !== undefined && Math.abs(candidateName.length - name.length) <= maximumLengthDifference) {
2062
2215
  if (candidateName === name) {
@@ -2293,13 +2446,15 @@ var ts;
2293
2446
  for (var _i = 0; _i < arguments.length; _i++) {
2294
2447
  args[_i] = arguments[_i];
2295
2448
  }
2449
+ var lastResult;
2296
2450
  for (var _a = 0, fs_1 = fs; _a < fs_1.length; _a++) {
2297
2451
  var f = fs_1[_a];
2298
- if (f.apply(void 0, args)) {
2299
- return true;
2452
+ lastResult = f.apply(void 0, args);
2453
+ if (lastResult) {
2454
+ return lastResult;
2300
2455
  }
2301
2456
  }
2302
- return false;
2457
+ return lastResult;
2303
2458
  };
2304
2459
  }
2305
2460
  ts.or = or;
@@ -5319,6 +5474,21 @@ var ts;
5319
5474
  ModuleResolutionKind[ModuleResolutionKind["Node12"] = 3] = "Node12";
5320
5475
  ModuleResolutionKind[ModuleResolutionKind["NodeNext"] = 99] = "NodeNext";
5321
5476
  })(ModuleResolutionKind = ts.ModuleResolutionKind || (ts.ModuleResolutionKind = {}));
5477
+ var ModuleDetectionKind;
5478
+ (function (ModuleDetectionKind) {
5479
+ /**
5480
+ * Files with imports, exports and/or import.meta are considered modules
5481
+ */
5482
+ ModuleDetectionKind[ModuleDetectionKind["Legacy"] = 1] = "Legacy";
5483
+ /**
5484
+ * Legacy, but also files with jsx under react-jsx or react-jsxdev and esm mode files under moduleResolution: node12+
5485
+ */
5486
+ ModuleDetectionKind[ModuleDetectionKind["Auto"] = 2] = "Auto";
5487
+ /**
5488
+ * Consider all non-declaration files modules, regardless of present syntax
5489
+ */
5490
+ ModuleDetectionKind[ModuleDetectionKind["Force"] = 3] = "Force";
5491
+ })(ModuleDetectionKind = ts.ModuleDetectionKind || (ts.ModuleDetectionKind = {}));
5322
5492
  var WatchFileKind;
5323
5493
  (function (WatchFileKind) {
5324
5494
  WatchFileKind[WatchFileKind["FixedPollingInterval"] = 0] = "FixedPollingInterval";
@@ -8416,6 +8586,8 @@ var ts;
8416
8586
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8417
8587
  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."),
8418
8588
  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."),
8589
+ 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."),
8590
+ 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."),
8419
8591
  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."),
8420
8592
  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."),
8421
8593
  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),
@@ -19925,6 +20097,61 @@ var ts;
19925
20097
  return scriptKind === 4 /* TSX */ || scriptKind === 2 /* JSX */ || scriptKind === 1 /* JS */ || scriptKind === 6 /* JSON */ ? 1 /* JSX */ : 0 /* Standard */;
19926
20098
  }
19927
20099
  ts.getLanguageVariant = getLanguageVariant;
20100
+ /**
20101
+ * This is a somewhat unavoidable full tree walk to locate a JSX tag - `import.meta` requires the same,
20102
+ * but we avoid that walk (or parts of it) if at all possible using the `PossiblyContainsImportMeta` node flag.
20103
+ * Unfortunately, there's no `NodeFlag` space to do the same for JSX.
20104
+ */
20105
+ function walkTreeForJSXTags(node) {
20106
+ if (!(node.transformFlags & 2 /* ContainsJsx */))
20107
+ return undefined;
20108
+ return ts.isJsxOpeningLikeElement(node) || ts.isJsxFragment(node) ? node : ts.forEachChild(node, walkTreeForJSXTags);
20109
+ }
20110
+ function isFileModuleFromUsingJSXTag(file) {
20111
+ // Excludes declaration files - they still require an explicit `export {}` or the like
20112
+ // for back compat purposes. (not that declaration files should contain JSX tags!)
20113
+ return !file.isDeclarationFile ? walkTreeForJSXTags(file) : undefined;
20114
+ }
20115
+ /**
20116
+ * Note that this requires file.impliedNodeFormat be set already; meaning it must be set very early on
20117
+ * in SourceFile construction.
20118
+ */
20119
+ function isFileForcedToBeModuleByFormat(file) {
20120
+ // Excludes declaration files - they still require an explicit `export {}` or the like
20121
+ // for back compat purposes.
20122
+ return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined;
20123
+ }
20124
+ function getSetExternalModuleIndicator(options) {
20125
+ // TODO: Should this callback be cached?
20126
+ switch (getEmitModuleDetectionKind(options)) {
20127
+ case ts.ModuleDetectionKind.Force:
20128
+ // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule
20129
+ return function (file) {
20130
+ file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file);
20131
+ };
20132
+ case ts.ModuleDetectionKind.Legacy:
20133
+ // Files are modules if they have imports, exports, or import.meta
20134
+ return function (file) {
20135
+ file.externalModuleIndicator = ts.isFileProbablyExternalModule(file);
20136
+ };
20137
+ case ts.ModuleDetectionKind.Auto:
20138
+ // If module is nodenext or node12, all esm format files are modules
20139
+ // If jsx is react-jsx or react-jsxdev then jsx tags force module-ness
20140
+ // otherwise, the presence of import or export statments (or import.meta) implies module-ness
20141
+ var checks = [ts.isFileProbablyExternalModule];
20142
+ if (options.jsx === 4 /* ReactJSX */ || options.jsx === 5 /* ReactJSXDev */) {
20143
+ checks.push(isFileModuleFromUsingJSXTag);
20144
+ }
20145
+ var moduleKind = getEmitModuleKind(options);
20146
+ if (moduleKind === ts.ModuleKind.Node12 || moduleKind === ts.ModuleKind.NodeNext) {
20147
+ checks.push(isFileForcedToBeModuleByFormat);
20148
+ }
20149
+ var combined_1 = ts.or.apply(void 0, checks);
20150
+ var callback = function (file) { return void (file.externalModuleIndicator = combined_1(file)); };
20151
+ return callback;
20152
+ }
20153
+ }
20154
+ ts.getSetExternalModuleIndicator = getSetExternalModuleIndicator;
19928
20155
  function getEmitScriptTarget(compilerOptions) {
19929
20156
  return compilerOptions.target ||
19930
20157
  (compilerOptions.module === ts.ModuleKind.Node12 && 7 /* ES2020 */) ||
@@ -19959,6 +20186,10 @@ var ts;
19959
20186
  return moduleResolution;
19960
20187
  }
19961
20188
  ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind;
20189
+ function getEmitModuleDetectionKind(options) {
20190
+ return options.moduleDetection || ts.ModuleDetectionKind.Auto;
20191
+ }
20192
+ ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind;
19962
20193
  function hasJsonModuleEmitEnabled(options) {
19963
20194
  switch (getEmitModuleKind(options)) {
19964
20195
  case ts.ModuleKind.CommonJS:
@@ -30129,6 +30360,36 @@ var ts;
30129
30360
  text.charCodeAt(start + 3) !== 47 /* slash */;
30130
30361
  }
30131
30362
  ts.isJSDocLikeText = isJSDocLikeText;
30363
+ /*@internal*/
30364
+ function isFileProbablyExternalModule(sourceFile) {
30365
+ // Try to use the first top-level import/export when available, then
30366
+ // fall back to looking for an 'import.meta' somewhere in the tree if necessary.
30367
+ return ts.forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) ||
30368
+ getImportMetaIfNecessary(sourceFile);
30369
+ }
30370
+ ts.isFileProbablyExternalModule = isFileProbablyExternalModule;
30371
+ function isAnExternalModuleIndicatorNode(node) {
30372
+ return hasModifierOfKind(node, 93 /* ExportKeyword */)
30373
+ || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
30374
+ || ts.isImportDeclaration(node)
30375
+ || ts.isExportAssignment(node)
30376
+ || ts.isExportDeclaration(node) ? node : undefined;
30377
+ }
30378
+ function getImportMetaIfNecessary(sourceFile) {
30379
+ return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
30380
+ walkTreeForImportMeta(sourceFile) :
30381
+ undefined;
30382
+ }
30383
+ function walkTreeForImportMeta(node) {
30384
+ return isImportMeta(node) ? node : forEachChild(node, walkTreeForImportMeta);
30385
+ }
30386
+ /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */
30387
+ function hasModifierOfKind(node, kind) {
30388
+ return ts.some(node.modifiers, function (m) { return m.kind === kind; });
30389
+ }
30390
+ function isImportMeta(node) {
30391
+ return ts.isMetaProperty(node) && node.keywordToken === 100 /* ImportKeyword */ && node.name.escapedText === "meta";
30392
+ }
30132
30393
  /**
30133
30394
  * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
30134
30395
  * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
@@ -30710,17 +30971,25 @@ var ts;
30710
30971
  children.unshift(n);
30711
30972
  }
30712
30973
  }
30713
- function createSourceFile(fileName, sourceText, languageVersion, setParentNodes, scriptKind) {
30974
+ function setExternalModuleIndicator(sourceFile) {
30975
+ sourceFile.externalModuleIndicator = isFileProbablyExternalModule(sourceFile);
30976
+ }
30977
+ function createSourceFile(fileName, sourceText, languageVersionOrOptions, setParentNodes, scriptKind) {
30714
30978
  if (setParentNodes === void 0) { setParentNodes = false; }
30715
30979
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("parse" /* Parse */, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
30716
30980
  ts.performance.mark("beforeParse");
30717
30981
  var result;
30718
30982
  ts.perfLogger.logStartParseSourceFile(fileName);
30983
+ var _a = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions : { languageVersion: languageVersionOrOptions }, languageVersion = _a.languageVersion, overrideSetExternalModuleIndicator = _a.setExternalModuleIndicator, format = _a.impliedNodeFormat;
30719
30984
  if (languageVersion === 100 /* JSON */) {
30720
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, 6 /* JSON */);
30985
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, 6 /* JSON */, ts.noop);
30721
30986
  }
30722
30987
  else {
30723
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind);
30988
+ var setIndicator = format === undefined ? overrideSetExternalModuleIndicator : function (file) {
30989
+ file.impliedNodeFormat = format;
30990
+ return (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file);
30991
+ };
30992
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator);
30724
30993
  }
30725
30994
  ts.perfLogger.logStopParseSourceFile();
30726
30995
  ts.performance.mark("afterParse");
@@ -30906,7 +31175,7 @@ var ts;
30906
31175
  // Note: any errors at the end of the file that do not precede a regular node, should get
30907
31176
  // attached to the EOF token.
30908
31177
  var parseErrorBeforeNextFinishedNode = false;
30909
- function parseSourceFile(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes, scriptKind) {
31178
+ function parseSourceFile(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes, scriptKind, setExternalModuleIndicatorOverride) {
30910
31179
  var _a;
30911
31180
  if (setParentNodes === void 0) { setParentNodes = false; }
30912
31181
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
@@ -30922,7 +31191,7 @@ var ts;
30922
31191
  return result_3;
30923
31192
  }
30924
31193
  initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind);
30925
- var result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind);
31194
+ var result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator);
30926
31195
  clearState();
30927
31196
  return result;
30928
31197
  }
@@ -31006,7 +31275,7 @@ var ts;
31006
31275
  endOfFileToken = parseExpectedToken(1 /* EndOfFileToken */, ts.Diagnostics.Unexpected_token);
31007
31276
  }
31008
31277
  // Set source file so that errors will be reported with this file name
31009
- var sourceFile = createSourceFile(fileName, 2 /* ES2015 */, 6 /* JSON */, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags);
31278
+ var sourceFile = createSourceFile(fileName, 2 /* ES2015 */, 6 /* JSON */, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags, ts.noop);
31010
31279
  if (setParentNodes) {
31011
31280
  fixupParentReferences(sourceFile);
31012
31281
  }
@@ -31080,7 +31349,7 @@ var ts;
31080
31349
  notParenthesizedArrow = undefined;
31081
31350
  topLevel = true;
31082
31351
  }
31083
- function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind) {
31352
+ function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicator) {
31084
31353
  var isDeclarationFile = isDeclarationFileName(fileName);
31085
31354
  if (isDeclarationFile) {
31086
31355
  contextFlags |= 8388608 /* Ambient */;
@@ -31091,7 +31360,7 @@ var ts;
31091
31360
  var statements = parseList(0 /* SourceElements */, parseStatement);
31092
31361
  ts.Debug.assert(token() === 1 /* EndOfFileToken */);
31093
31362
  var endOfFileToken = addJSDocComment(parseTokenNode());
31094
- var sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags);
31363
+ var sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags, setExternalModuleIndicator);
31095
31364
  // 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
31096
31365
  processCommentPragmas(sourceFile, sourceText);
31097
31366
  processPragmasIntoFields(sourceFile, reportPragmaDiagnostic);
@@ -31228,25 +31497,30 @@ var ts;
31228
31497
  ts.setParentRecursive(rootNode, /*incremental*/ true);
31229
31498
  }
31230
31499
  Parser.fixupParentReferences = fixupParentReferences;
31231
- function createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, flags) {
31500
+ function createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, flags, setExternalModuleIndicator) {
31232
31501
  // code from createNode is inlined here so createNode won't have to deal with special case of creating source files
31233
31502
  // this is quite rare comparing to other nodes and createNode should be as fast as possible
31234
31503
  var sourceFile = factory.createSourceFile(statements, endOfFileToken, flags);
31235
31504
  ts.setTextRangePosWidth(sourceFile, 0, sourceText.length);
31236
- setExternalModuleIndicator(sourceFile);
31505
+ setFields(sourceFile);
31237
31506
  // If we parsed this as an external module, it may contain top-level await
31238
31507
  if (!isDeclarationFile && isExternalModule(sourceFile) && sourceFile.transformFlags & 16777216 /* ContainsPossibleTopLevelAwait */) {
31239
31508
  sourceFile = reparseTopLevelAwait(sourceFile);
31509
+ setFields(sourceFile);
31240
31510
  }
31241
- sourceFile.text = sourceText;
31242
- sourceFile.bindDiagnostics = [];
31243
- sourceFile.bindSuggestionDiagnostics = undefined;
31244
- sourceFile.languageVersion = languageVersion;
31245
- sourceFile.fileName = fileName;
31246
- sourceFile.languageVariant = ts.getLanguageVariant(scriptKind);
31247
- sourceFile.isDeclarationFile = isDeclarationFile;
31248
- sourceFile.scriptKind = scriptKind;
31249
31511
  return sourceFile;
31512
+ function setFields(sourceFile) {
31513
+ sourceFile.text = sourceText;
31514
+ sourceFile.bindDiagnostics = [];
31515
+ sourceFile.bindSuggestionDiagnostics = undefined;
31516
+ sourceFile.languageVersion = languageVersion;
31517
+ sourceFile.fileName = fileName;
31518
+ sourceFile.languageVariant = ts.getLanguageVariant(scriptKind);
31519
+ sourceFile.isDeclarationFile = isDeclarationFile;
31520
+ sourceFile.scriptKind = scriptKind;
31521
+ setExternalModuleIndicator(sourceFile);
31522
+ sourceFile.setExternalModuleIndicator = setExternalModuleIndicator;
31523
+ }
31250
31524
  }
31251
31525
  function setContextFlag(val, flag) {
31252
31526
  if (val) {
@@ -36729,35 +37003,6 @@ var ts;
36729
37003
  var node = factory.createExportAssignment(decorators, modifiers, isExportEquals, expression);
36730
37004
  return withJSDoc(finishNode(node, pos), hasJSDoc);
36731
37005
  }
36732
- function setExternalModuleIndicator(sourceFile) {
36733
- // Try to use the first top-level import/export when available, then
36734
- // fall back to looking for an 'import.meta' somewhere in the tree if necessary.
36735
- sourceFile.externalModuleIndicator =
36736
- ts.forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) ||
36737
- getImportMetaIfNecessary(sourceFile);
36738
- }
36739
- function isAnExternalModuleIndicatorNode(node) {
36740
- return hasModifierOfKind(node, 93 /* ExportKeyword */)
36741
- || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
36742
- || ts.isImportDeclaration(node)
36743
- || ts.isExportAssignment(node)
36744
- || ts.isExportDeclaration(node) ? node : undefined;
36745
- }
36746
- function getImportMetaIfNecessary(sourceFile) {
36747
- return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
36748
- walkTreeForExternalModuleIndicators(sourceFile) :
36749
- undefined;
36750
- }
36751
- function walkTreeForExternalModuleIndicators(node) {
36752
- return isImportMeta(node) ? node : forEachChild(node, walkTreeForExternalModuleIndicators);
36753
- }
36754
- /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */
36755
- function hasModifierOfKind(node, kind) {
36756
- return ts.some(node.modifiers, function (m) { return m.kind === kind; });
36757
- }
36758
- function isImportMeta(node) {
36759
- return ts.isMetaProperty(node) && node.keywordToken === 100 /* ImportKeyword */ && node.name.escapedText === "meta";
36760
- }
36761
37006
  var ParsingContext;
36762
37007
  (function (ParsingContext) {
36763
37008
  ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements";
@@ -36800,7 +37045,7 @@ var ts;
36800
37045
  scanner.setText(content, start, length);
36801
37046
  currentToken = scanner.scan();
36802
37047
  var jsDocTypeExpression = parseJSDocTypeExpression();
36803
- var sourceFile = createSourceFile("file.js", 99 /* Latest */, 1 /* JS */, /*isDeclarationFile*/ false, [], factory.createToken(1 /* EndOfFileToken */), 0 /* None */);
37048
+ var sourceFile = createSourceFile("file.js", 99 /* Latest */, 1 /* JS */, /*isDeclarationFile*/ false, [], factory.createToken(1 /* EndOfFileToken */), 0 /* None */, ts.noop);
36804
37049
  var diagnostics = ts.attachFileToDiagnostics(parseDiagnostics, sourceFile);
36805
37050
  if (jsDocDiagnostics) {
36806
37051
  sourceFile.jsDocDiagnostics = ts.attachFileToDiagnostics(jsDocDiagnostics, sourceFile);
@@ -37761,7 +38006,7 @@ var ts;
37761
38006
  if (sourceFile.statements.length === 0) {
37762
38007
  // If we don't have any statements in the current source file, then there's no real
37763
38008
  // way to incrementally parse. So just do a full parse instead.
37764
- return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind);
38009
+ return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
37765
38010
  }
37766
38011
  // Make sure we're not trying to incrementally update a source file more than once. Once
37767
38012
  // we do an update the original source file is considered unusable from that point onwards.
@@ -37818,7 +38063,7 @@ var ts;
37818
38063
  // inconsistent tree. Setting the parents on the new tree should be very fast. We
37819
38064
  // will immediately bail out of walking any subtrees when we can see that their parents
37820
38065
  // are already correct.
37821
- var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind);
38066
+ var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
37822
38067
  result.commentDirectives = getNewCommentDirectives(sourceFile.commentDirectives, result.commentDirectives, changeRange.span.start, ts.textSpanEnd(changeRange.span), delta, oldText, newText, aggressiveChecks);
37823
38068
  result.impliedNodeFormat = sourceFile.impliedNodeFormat;
37824
38069
  return result;
@@ -39734,6 +39979,18 @@ var ts;
39734
39979
  description: ts.Diagnostics.Specify_a_list_of_language_service_plugins_to_include,
39735
39980
  category: ts.Diagnostics.Editor_Support,
39736
39981
  },
39982
+ {
39983
+ name: "moduleDetection",
39984
+ type: new ts.Map(ts.getEntries({
39985
+ auto: ts.ModuleDetectionKind.Auto,
39986
+ legacy: ts.ModuleDetectionKind.Legacy,
39987
+ force: ts.ModuleDetectionKind.Force,
39988
+ })),
39989
+ affectsModuleResolution: true,
39990
+ description: ts.Diagnostics.Control_what_method_is_used_to_detect_module_format_JS_files,
39991
+ category: ts.Diagnostics.Language_and_Environment,
39992
+ 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,
39993
+ }
39737
39994
  ];
39738
39995
  /* @internal */
39739
39996
  ts.optionDeclarations = __spreadArray(__spreadArray([], ts.commonOptionsWithBuild, true), commandOptionsWithoutBuild, true);
@@ -63687,7 +63944,8 @@ var ts;
63687
63944
  return true;
63688
63945
  }
63689
63946
  }
63690
- else {
63947
+ else if (!((source.flags | target.flags) & (3145728 /* UnionOrIntersection */ | 8388608 /* IndexedAccess */ | 16777216 /* Conditional */ | 33554432 /* Substitution */))) {
63948
+ // We have excluded types that may simplify to other forms, so types must have identical flags
63691
63949
  if (source.flags !== target.flags)
63692
63950
  return false;
63693
63951
  if (source.flags & 67358815 /* Singleton */)
@@ -69763,7 +70021,7 @@ var ts;
69763
70021
  return result;
69764
70022
  }
69765
70023
  function getCandidateDiscriminantPropertyAccess(expr) {
69766
- if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
70024
+ if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference) || ts.isObjectLiteralMethod(reference)) {
69767
70025
  // When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
69768
70026
  // getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
69769
70027
  // parameter declared in the same parameter list is a candidate.
@@ -76735,6 +76993,9 @@ var ts;
76735
76993
  assignBindingElementTypes(declaration.name, links.type);
76736
76994
  }
76737
76995
  }
76996
+ else if (type) {
76997
+ ts.Debug.assertEqual(links.type, type, "Parameter symbol already has a cached type which differs from newly assigned type");
76998
+ }
76738
76999
  }
76739
77000
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76740
77001
  // the destructured type into the contained binding elements.
@@ -87627,8 +87888,8 @@ var ts;
87627
87888
  }
87628
87889
  else {
87629
87890
  var elements = name.elements;
87630
- for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
87631
- var element = elements_1[_i];
87891
+ for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87892
+ var element = elements_2[_i];
87632
87893
  if (!ts.isOmittedExpression(element)) {
87633
87894
  return checkESModuleMarker(element.name);
87634
87895
  }
@@ -87644,8 +87905,8 @@ var ts;
87644
87905
  }
87645
87906
  else {
87646
87907
  var elements = name.elements;
87647
- for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87648
- var element = elements_2[_i];
87908
+ for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
87909
+ var element = elements_3[_i];
87649
87910
  if (!ts.isOmittedExpression(element)) {
87650
87911
  checkGrammarNameInLetOrConstDeclarations(element.name);
87651
87912
  }
@@ -89899,8 +90160,8 @@ var ts;
89899
90160
  }
89900
90161
  function bindingOrAssignmentPatternAssignsToName(pattern, escapedName) {
89901
90162
  var elements = ts.getElementsOfBindingOrAssignmentPattern(pattern);
89902
- for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
89903
- var element = elements_3[_i];
90163
+ for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
90164
+ var element = elements_4[_i];
89904
90165
  if (bindingOrAssignmentElementAssignsToName(element, escapedName)) {
89905
90166
  return true;
89906
90167
  }
@@ -95518,8 +95779,8 @@ var ts;
95518
95779
  function chunkObjectLiteralElements(elements) {
95519
95780
  var chunkObject;
95520
95781
  var objects = [];
95521
- for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
95522
- var e = elements_4[_i];
95782
+ for (var _i = 0, elements_5 = elements; _i < elements_5.length; _i++) {
95783
+ var e = elements_5[_i];
95523
95784
  if (e.kind === 297 /* SpreadAssignment */) {
95524
95785
  if (chunkObject) {
95525
95786
  objects.push(factory.createObjectLiteralExpression(chunkObject));
@@ -114540,7 +114801,7 @@ var ts;
114540
114801
  var existingDirectories = new ts.Map();
114541
114802
  var getCanonicalFileName = ts.createGetCanonicalFileName(system.useCaseSensitiveFileNames);
114542
114803
  var computeHash = ts.maybeBind(system, system.createHash) || ts.generateDjb2Hash;
114543
- function getSourceFile(fileName, languageVersion, onError) {
114804
+ function getSourceFile(fileName, languageVersionOrOptions, onError) {
114544
114805
  var text;
114545
114806
  try {
114546
114807
  ts.performance.mark("beforeIORead");
@@ -114554,7 +114815,7 @@ var ts;
114554
114815
  }
114555
114816
  text = "";
114556
114817
  }
114557
- return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined;
114818
+ return text !== undefined ? ts.createSourceFile(fileName, text, languageVersionOrOptions, setParentNodes) : undefined;
114558
114819
  }
114559
114820
  function directoryExists(directoryPath) {
114560
114821
  if (existingDirectories.has(directoryPath)) {
@@ -115960,8 +116221,8 @@ var ts;
115960
116221
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
115961
116222
  var oldSourceFile = oldSourceFiles_2[_i];
115962
116223
  var newSourceFile = host.getSourceFileByPath
115963
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, ts.getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile)
115964
- : host.getSourceFile(oldSourceFile.fileName, ts.getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
116224
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
116225
+ : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
115965
116226
  if (!newSourceFile) {
115966
116227
  return 0 /* Not */;
115967
116228
  }
@@ -115992,7 +116253,6 @@ var ts;
115992
116253
  newSourceFile.originalFileName = oldSourceFile.originalFileName;
115993
116254
  newSourceFile.resolvedPath = oldSourceFile.resolvedPath;
115994
116255
  newSourceFile.fileName = oldSourceFile.fileName;
115995
- newSourceFile.impliedNodeFormat = oldSourceFile.impliedNodeFormat;
115996
116256
  var packageName = oldProgram.sourceFileToPackageName.get(oldSourceFile.path);
115997
116257
  if (packageName !== undefined) {
115998
116258
  // If there are 2 different source files for the same package name and at least one of them changes,
@@ -116911,6 +117171,17 @@ var ts;
116911
117171
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116912
117172
  return result;
116913
117173
  }
117174
+ function getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options) {
117175
+ // 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
117176
+ // 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
117177
+ // 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.
117178
+ var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
117179
+ return {
117180
+ languageVersion: ts.getEmitScriptTarget(options),
117181
+ impliedNodeFormat: impliedNodeFormat,
117182
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
117183
+ };
117184
+ }
116914
117185
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
116915
117186
  var path = toPath(fileName);
116916
117187
  if (useSourceOfProjectReferenceRedirect) {
@@ -116998,7 +117269,7 @@ var ts;
116998
117269
  }
116999
117270
  }
117000
117271
  // We haven't looked for this file, do so now and cache result
117001
- 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);
117272
+ 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);
117002
117273
  if (packageId) {
117003
117274
  var packageIdKey = ts.packageIdToString(packageId);
117004
117275
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
@@ -117026,10 +117297,6 @@ var ts;
117026
117297
  file.path = path;
117027
117298
  file.resolvedPath = toPath(fileName);
117028
117299
  file.originalFileName = originalFileName;
117029
- // 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
117030
- // 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
117031
- // 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.
117032
- file.impliedNodeFormat = getImpliedNodeFormatForFile(file.resolvedPath, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
117033
117300
  addFileIncludeReason(file, reason);
117034
117301
  if (host.useCaseSensitiveFileNames()) {
117035
117302
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -117531,7 +117798,7 @@ var ts;
117531
117798
  }
117532
117799
  else if (firstNonAmbientExternalModuleSourceFile && languageVersion < 2 /* ES2015 */ && options.module === ts.ModuleKind.None) {
117533
117800
  // We cannot use createDiagnosticFromNode because nodes do not have parents yet
117534
- var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117801
+ var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117535
117802
  programDiagnostics.add(ts.createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none));
117536
117803
  }
117537
117804
  // Cannot specify module gen that isn't amd or system with --out
@@ -117540,7 +117807,7 @@ var ts;
117540
117807
  createDiagnosticForOptionName(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile", "module");
117541
117808
  }
117542
117809
  else if (options.module === undefined && firstNonAmbientExternalModuleSourceFile) {
117543
- var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117810
+ var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117544
117811
  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"));
117545
117812
  }
117546
117813
  }
@@ -121802,7 +122069,7 @@ var ts;
121802
122069
  var useCaseSensitiveFileNames = host.useCaseSensitiveFileNames();
121803
122070
  var hostGetNewLine = ts.memoize(function () { return host.getNewLine(); });
121804
122071
  return {
121805
- getSourceFile: function (fileName, languageVersion, onError) {
122072
+ getSourceFile: function (fileName, languageVersionOrOptions, onError) {
121806
122073
  var text;
121807
122074
  try {
121808
122075
  ts.performance.mark("beforeIORead");
@@ -121816,7 +122083,7 @@ var ts;
121816
122083
  }
121817
122084
  text = "";
121818
122085
  }
121819
- return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion) : undefined;
122086
+ return text !== undefined ? ts.createSourceFile(fileName, text, languageVersionOrOptions) : undefined;
121820
122087
  },
121821
122088
  getDefaultLibLocation: ts.maybeBind(host, host.getDefaultLibLocation),
121822
122089
  getDefaultLibFileName: function (options) { return host.getDefaultLibFileName(options); },
@@ -122284,7 +122551,7 @@ var ts;
122284
122551
  }
122285
122552
  return directoryStructureHost.fileExists(fileName);
122286
122553
  }
122287
- function getVersionedSourceFileByPath(fileName, path, languageVersion, onError, shouldCreateNewSourceFile) {
122554
+ function getVersionedSourceFileByPath(fileName, path, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
122288
122555
  var hostSourceFile = sourceFilesCache.get(path);
122289
122556
  // No source file on the host
122290
122557
  if (isFileMissingOnHost(hostSourceFile)) {
@@ -122292,7 +122559,7 @@ var ts;
122292
122559
  }
122293
122560
  // Create new source file if requested or the versions dont match
122294
122561
  if (hostSourceFile === undefined || shouldCreateNewSourceFile || isFilePresenceUnknownOnHost(hostSourceFile)) {
122295
- var sourceFile = getNewSourceFile(fileName, languageVersion, onError);
122562
+ var sourceFile = getNewSourceFile(fileName, languageVersionOrOptions, onError);
122296
122563
  if (hostSourceFile) {
122297
122564
  if (sourceFile) {
122298
122565
  // Set the source file and create file watcher now that file was present on the disk
@@ -134397,9 +134664,15 @@ var ts;
134397
134664
  });
134398
134665
  return JSON.stringify(bucketInfoArray, undefined, 2);
134399
134666
  }
134667
+ function getCompilationSettings(settingsOrHost) {
134668
+ if (typeof settingsOrHost.getCompilationSettings === "function") {
134669
+ return settingsOrHost.getCompilationSettings();
134670
+ }
134671
+ return settingsOrHost;
134672
+ }
134400
134673
  function acquireDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
134401
134674
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
134402
- var key = getKeyForCompilationSettings(compilationSettings);
134675
+ var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
134403
134676
  return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
134404
134677
  }
134405
134678
  function acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
@@ -134407,20 +134680,28 @@ var ts;
134407
134680
  }
134408
134681
  function updateDocument(fileName, compilationSettings, scriptSnapshot, version, scriptKind) {
134409
134682
  var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
134410
- var key = getKeyForCompilationSettings(compilationSettings);
134683
+ var key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings));
134411
134684
  return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind);
134412
134685
  }
134413
134686
  function updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind) {
134414
- return acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
134687
+ return acquireOrUpdateDocument(fileName, path, getCompilationSettings(compilationSettings), key, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
134415
134688
  }
134416
134689
  function getDocumentRegistryEntry(bucketEntry, scriptKind) {
134417
134690
  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"));
134418
134691
  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);
134419
134692
  return entry;
134420
134693
  }
134421
- function acquireOrUpdateDocument(fileName, path, compilationSettings, key, scriptSnapshot, version, acquiring, scriptKind) {
134694
+ function acquireOrUpdateDocument(fileName, path, compilationSettingsOrHost, key, scriptSnapshot, version, acquiring, scriptKind) {
134695
+ var _a, _b, _c, _d;
134422
134696
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
134697
+ var compilationSettings = getCompilationSettings(compilationSettingsOrHost);
134698
+ var host = compilationSettingsOrHost === compilationSettings ? undefined : compilationSettingsOrHost;
134423
134699
  var scriptTarget = scriptKind === 6 /* JSON */ ? 100 /* JSON */ : ts.getEmitScriptTarget(compilationSettings);
134700
+ var sourceFileOptions = {
134701
+ languageVersion: scriptTarget,
134702
+ 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),
134703
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(compilationSettings)
134704
+ };
134424
134705
  var oldBucketCount = buckets.size;
134425
134706
  var bucket = ts.getOrUpdate(buckets, key, function () { return new ts.Map(); });
134426
134707
  if (ts.tracing) {
@@ -134454,7 +134735,7 @@ var ts;
134454
134735
  }
134455
134736
  if (!entry) {
134456
134737
  // Have never seen this file with these settings. Create a new source file for it.
134457
- var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, /*setNodeParents*/ false, scriptKind);
134738
+ var sourceFile = ts.createLanguageServiceSourceFile(fileName, scriptSnapshot, sourceFileOptions, version, /*setNodeParents*/ false, scriptKind);
134458
134739
  if (externalCache) {
134459
134740
  externalCache.setDocument(key, path, sourceFile);
134460
134741
  }
@@ -142898,7 +143179,7 @@ var ts;
142898
143179
  continue;
142899
143180
  var module_1 = ts.getResolvedModule(sourceFile, moduleSpecifier.text, ts.getModeForUsageLocation(sourceFile, moduleSpecifier));
142900
143181
  var resolvedFile = module_1 && program.getSourceFile(module_1.resolvedFileName);
142901
- if (resolvedFile && resolvedFile.externalModuleIndicator && ts.isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) {
143182
+ if (resolvedFile && resolvedFile.externalModuleIndicator && resolvedFile.externalModuleIndicator !== true && ts.isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) {
142902
143183
  diags.push(ts.createDiagnosticForNode(name, ts.Diagnostics.Import_may_be_converted_to_a_default_import));
142903
143184
  }
142904
143185
  }
@@ -143814,19 +144095,7 @@ var ts;
143814
144095
  options.suppressOutputPathCheck = true;
143815
144096
  // Filename can be non-ts file.
143816
144097
  options.allowNonTsExtensions = true;
143817
- // if jsx is specified then treat file as .tsx
143818
- var inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
143819
- var sourceFile = ts.createSourceFile(inputFileName, input, ts.getEmitScriptTarget(options));
143820
- if (transpileOptions.moduleName) {
143821
- sourceFile.moduleName = transpileOptions.moduleName;
143822
- }
143823
- if (transpileOptions.renamedDependencies) {
143824
- sourceFile.renamedDependencies = new ts.Map(ts.getEntries(transpileOptions.renamedDependencies));
143825
- }
143826
144098
  var newLine = ts.getNewLineCharacter(options);
143827
- // Output
143828
- var outputText;
143829
- var sourceMapText;
143830
144099
  // Create a compilerHost object to allow the compiler to read and write files
143831
144100
  var compilerHost = {
143832
144101
  getSourceFile: function (fileName) { return fileName === ts.normalizePath(inputFileName) ? sourceFile : undefined; },
@@ -143850,6 +144119,22 @@ var ts;
143850
144119
  directoryExists: function () { return true; },
143851
144120
  getDirectories: function () { return []; }
143852
144121
  };
144122
+ // if jsx is specified then treat file as .tsx
144123
+ var inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
144124
+ var sourceFile = ts.createSourceFile(inputFileName, input, {
144125
+ languageVersion: ts.getEmitScriptTarget(options),
144126
+ impliedNodeFormat: ts.getImpliedNodeFormatForFile(ts.toPath(inputFileName, "", compilerHost.getCanonicalFileName), /*cache*/ undefined, compilerHost, options),
144127
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
144128
+ });
144129
+ if (transpileOptions.moduleName) {
144130
+ sourceFile.moduleName = transpileOptions.moduleName;
144131
+ }
144132
+ if (transpileOptions.renamedDependencies) {
144133
+ sourceFile.renamedDependencies = new ts.Map(ts.getEntries(transpileOptions.renamedDependencies));
144134
+ }
144135
+ // Output
144136
+ var outputText;
144137
+ var sourceMapText;
143853
144138
  var program = ts.createProgram([inputFileName], options, compilerHost);
143854
144139
  if (transpileOptions.reportDiagnostics) {
143855
144140
  ts.addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile));
@@ -160362,7 +160647,7 @@ var ts;
160362
160647
  for (var i = 1;; i++) {
160363
160648
  var name = ts.combinePaths(inDirectory, newModuleName + extension);
160364
160649
  if (!host.fileExists(name))
160365
- return newModuleName; // TODO: GH#18217
160650
+ return newModuleName;
160366
160651
  newModuleName = moduleName + "." + i;
160367
160652
  }
160368
160653
  }
@@ -162722,6 +163007,7 @@ var ts;
162722
163007
  this.host = host;
162723
163008
  }
162724
163009
  SyntaxTreeCache.prototype.getCurrentSourceFile = function (fileName) {
163010
+ var _a, _b, _c, _d, _e, _f, _g, _h;
162725
163011
  var scriptSnapshot = this.host.getScriptSnapshot(fileName);
162726
163012
  if (!scriptSnapshot) {
162727
163013
  // The host does not know about this file.
@@ -162732,7 +163018,12 @@ var ts;
162732
163018
  var sourceFile;
162733
163019
  if (this.currentFileName !== fileName) {
162734
163020
  // This is a new file, just parse it
162735
- sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, 99 /* Latest */, version, /*setNodeParents*/ true, scriptKind);
163021
+ var options = {
163022
+ languageVersion: 99 /* Latest */,
163023
+ 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()),
163024
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(this.host.getCompilationSettings())
163025
+ };
163026
+ sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, options, version, /*setNodeParents*/ true, scriptKind);
162736
163027
  }
162737
163028
  else if (this.currentFileVersion !== version) {
162738
163029
  // This is the same file, just a newer version. Incrementally parse the file.
@@ -162754,8 +163045,8 @@ var ts;
162754
163045
  sourceFile.version = version;
162755
163046
  sourceFile.scriptSnapshot = scriptSnapshot;
162756
163047
  }
162757
- function createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, setNodeParents, scriptKind) {
162758
- var sourceFile = ts.createSourceFile(fileName, ts.getSnapshotText(scriptSnapshot), scriptTarget, setNodeParents, scriptKind);
163048
+ function createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTargetOrOptions, version, setNodeParents, scriptKind) {
163049
+ var sourceFile = ts.createSourceFile(fileName, ts.getSnapshotText(scriptSnapshot), scriptTargetOrOptions, setNodeParents, scriptKind);
162759
163050
  setSourceFileFields(sourceFile, scriptSnapshot, version);
162760
163051
  return sourceFile;
162761
163052
  }
@@ -162803,8 +163094,13 @@ var ts;
162803
163094
  return newSourceFile;
162804
163095
  }
162805
163096
  }
163097
+ var options = {
163098
+ languageVersion: sourceFile.languageVersion,
163099
+ impliedNodeFormat: sourceFile.impliedNodeFormat,
163100
+ setExternalModuleIndicator: sourceFile.setExternalModuleIndicator,
163101
+ };
162806
163102
  // Otherwise, just create a new source file.
162807
- return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, /*setNodeParents*/ true, sourceFile.scriptKind);
163103
+ return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, options, version, /*setNodeParents*/ true, sourceFile.scriptKind);
162808
163104
  }
162809
163105
  ts.updateLanguageServiceSourceFile = updateLanguageServiceSourceFile;
162810
163106
  var NoopCancellationToken = {
@@ -163148,7 +163444,7 @@ var ts;
163148
163444
  // file's script kind, i.e. in one project some file is treated as ".ts"
163149
163445
  // and in another as ".js"
163150
163446
  if (hostFileInformation.scriptKind === oldSourceFile.scriptKind) {
163151
- return documentRegistry.updateDocumentWithKey(fileName, path, newSettings, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
163447
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
163152
163448
  }
163153
163449
  else {
163154
163450
  // Release old source file and fall through to aquire new file with new script kind
@@ -163158,7 +163454,7 @@ var ts;
163158
163454
  // We didn't already have the file. Fall through and acquire it from the registry.
163159
163455
  }
163160
163456
  // Could not find this file in the old program, create a new SourceFile for it.
163161
- return documentRegistry.acquireDocumentWithKey(fileName, path, newSettings, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
163457
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
163162
163458
  }
163163
163459
  }
163164
163460
  // TODO: GH#18217 frequently asserted as defined