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.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = ts.versionMajorMinor + ".0-dev.20220311";
92
+ ts.version = ts.versionMajorMinor + ".0-dev.20220314";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -1457,6 +1457,159 @@ var ts;
1457
1457
  return createMultiMap();
1458
1458
  }
1459
1459
  ts.createUnderscoreEscapedMultiMap = createUnderscoreEscapedMultiMap;
1460
+ /**
1461
+ * Creates a Set with custom equality and hash code functionality. This is useful when you
1462
+ * want to use something looser than object identity - e.g. "has the same span".
1463
+ *
1464
+ * If `equals(a, b)`, it must be the case that `getHashCode(a) === getHashCode(b)`.
1465
+ * The converse is not required.
1466
+ *
1467
+ * To facilitate a perf optimization (lazy allocation of bucket arrays), `TElement` is
1468
+ * assumed not to be an array type.
1469
+ */
1470
+ function createSet(getHashCode, equals) {
1471
+ var multiMap = new ts.Map();
1472
+ var size = 0;
1473
+ function getElementIterator() {
1474
+ var valueIt = multiMap.values();
1475
+ var arrayIt;
1476
+ return {
1477
+ next: function () {
1478
+ while (true) {
1479
+ if (arrayIt) {
1480
+ var n = arrayIt.next();
1481
+ if (!n.done) {
1482
+ return { value: n.value };
1483
+ }
1484
+ arrayIt = undefined;
1485
+ }
1486
+ else {
1487
+ var n = valueIt.next();
1488
+ if (n.done) {
1489
+ return { value: undefined, done: true };
1490
+ }
1491
+ if (!isArray(n.value)) {
1492
+ return { value: n.value };
1493
+ }
1494
+ arrayIt = arrayIterator(n.value);
1495
+ }
1496
+ }
1497
+ }
1498
+ };
1499
+ }
1500
+ var set = {
1501
+ has: function (element) {
1502
+ var hash = getHashCode(element);
1503
+ if (!multiMap.has(hash))
1504
+ return false;
1505
+ var candidates = multiMap.get(hash);
1506
+ if (!isArray(candidates))
1507
+ return equals(candidates, element);
1508
+ for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
1509
+ var candidate = candidates_1[_i];
1510
+ if (equals(candidate, element)) {
1511
+ return true;
1512
+ }
1513
+ }
1514
+ return false;
1515
+ },
1516
+ add: function (element) {
1517
+ var hash = getHashCode(element);
1518
+ if (multiMap.has(hash)) {
1519
+ var values = multiMap.get(hash);
1520
+ if (isArray(values)) {
1521
+ if (!contains(values, element, equals)) {
1522
+ values.push(element);
1523
+ size++;
1524
+ }
1525
+ }
1526
+ else {
1527
+ var value = values;
1528
+ if (!equals(value, element)) {
1529
+ multiMap.set(hash, [value, element]);
1530
+ size++;
1531
+ }
1532
+ }
1533
+ }
1534
+ else {
1535
+ multiMap.set(hash, element);
1536
+ size++;
1537
+ }
1538
+ return this;
1539
+ },
1540
+ delete: function (element) {
1541
+ var hash = getHashCode(element);
1542
+ if (!multiMap.has(hash))
1543
+ return false;
1544
+ var candidates = multiMap.get(hash);
1545
+ if (isArray(candidates)) {
1546
+ for (var i = 0; i < candidates.length; i++) {
1547
+ if (equals(candidates[i], element)) {
1548
+ if (candidates.length === 1) {
1549
+ multiMap.delete(hash);
1550
+ }
1551
+ else if (candidates.length === 2) {
1552
+ multiMap.set(hash, candidates[1 - i]);
1553
+ }
1554
+ else {
1555
+ unorderedRemoveItemAt(candidates, i);
1556
+ }
1557
+ size--;
1558
+ return true;
1559
+ }
1560
+ }
1561
+ }
1562
+ else {
1563
+ var candidate = candidates;
1564
+ if (equals(candidate, element)) {
1565
+ multiMap.delete(hash);
1566
+ size--;
1567
+ return true;
1568
+ }
1569
+ }
1570
+ return false;
1571
+ },
1572
+ clear: function () {
1573
+ multiMap.clear();
1574
+ size = 0;
1575
+ },
1576
+ get size() {
1577
+ return size;
1578
+ },
1579
+ forEach: function (action) {
1580
+ for (var _i = 0, _a = arrayFrom(multiMap.values()); _i < _a.length; _i++) {
1581
+ var elements = _a[_i];
1582
+ if (isArray(elements)) {
1583
+ for (var _b = 0, elements_1 = elements; _b < elements_1.length; _b++) {
1584
+ var element = elements_1[_b];
1585
+ action(element, element);
1586
+ }
1587
+ }
1588
+ else {
1589
+ var element = elements;
1590
+ action(element, element);
1591
+ }
1592
+ }
1593
+ },
1594
+ keys: function () {
1595
+ return getElementIterator();
1596
+ },
1597
+ values: function () {
1598
+ return getElementIterator();
1599
+ },
1600
+ entries: function () {
1601
+ var it = getElementIterator();
1602
+ return {
1603
+ next: function () {
1604
+ var n = it.next();
1605
+ return n.done ? n : { value: [n.value, n.value] };
1606
+ }
1607
+ };
1608
+ },
1609
+ };
1610
+ return set;
1611
+ }
1612
+ ts.createSet = createSet;
1460
1613
  /**
1461
1614
  * Tests whether a value is an array.
1462
1615
  */
@@ -1850,8 +2003,8 @@ var ts;
1850
2003
  var maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
1851
2004
  var bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result is worse than this, don't bother.
1852
2005
  var bestCandidate;
1853
- for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
1854
- var candidate = candidates_1[_i];
2006
+ for (var _i = 0, candidates_2 = candidates; _i < candidates_2.length; _i++) {
2007
+ var candidate = candidates_2[_i];
1855
2008
  var candidateName = getName(candidate);
1856
2009
  if (candidateName !== undefined && Math.abs(candidateName.length - name.length) <= maximumLengthDifference) {
1857
2010
  if (candidateName === name) {
@@ -2088,13 +2241,15 @@ var ts;
2088
2241
  for (var _i = 0; _i < arguments.length; _i++) {
2089
2242
  args[_i] = arguments[_i];
2090
2243
  }
2244
+ var lastResult;
2091
2245
  for (var _a = 0, fs_1 = fs; _a < fs_1.length; _a++) {
2092
2246
  var f = fs_1[_a];
2093
- if (f.apply(void 0, args)) {
2094
- return true;
2247
+ lastResult = f.apply(void 0, args);
2248
+ if (lastResult) {
2249
+ return lastResult;
2095
2250
  }
2096
2251
  }
2097
- return false;
2252
+ return lastResult;
2098
2253
  };
2099
2254
  }
2100
2255
  ts.or = or;
@@ -5114,6 +5269,21 @@ var ts;
5114
5269
  ModuleResolutionKind[ModuleResolutionKind["Node12"] = 3] = "Node12";
5115
5270
  ModuleResolutionKind[ModuleResolutionKind["NodeNext"] = 99] = "NodeNext";
5116
5271
  })(ModuleResolutionKind = ts.ModuleResolutionKind || (ts.ModuleResolutionKind = {}));
5272
+ var ModuleDetectionKind;
5273
+ (function (ModuleDetectionKind) {
5274
+ /**
5275
+ * Files with imports, exports and/or import.meta are considered modules
5276
+ */
5277
+ ModuleDetectionKind[ModuleDetectionKind["Legacy"] = 1] = "Legacy";
5278
+ /**
5279
+ * Legacy, but also files with jsx under react-jsx or react-jsxdev and esm mode files under moduleResolution: node12+
5280
+ */
5281
+ ModuleDetectionKind[ModuleDetectionKind["Auto"] = 2] = "Auto";
5282
+ /**
5283
+ * Consider all non-declaration files modules, regardless of present syntax
5284
+ */
5285
+ ModuleDetectionKind[ModuleDetectionKind["Force"] = 3] = "Force";
5286
+ })(ModuleDetectionKind = ts.ModuleDetectionKind || (ts.ModuleDetectionKind = {}));
5117
5287
  var WatchFileKind;
5118
5288
  (function (WatchFileKind) {
5119
5289
  WatchFileKind[WatchFileKind["FixedPollingInterval"] = 0] = "FixedPollingInterval";
@@ -8211,6 +8381,8 @@ var ts;
8211
8381
  catch_or_finally_expected: diag(1472, ts.DiagnosticCategory.Error, "catch_or_finally_expected_1472", "'catch' or 'finally' expected."),
8212
8382
  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."),
8213
8383
  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."),
8384
+ 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."),
8385
+ 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."),
8214
8386
  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."),
8215
8387
  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."),
8216
8388
  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),
@@ -19720,6 +19892,61 @@ var ts;
19720
19892
  return scriptKind === 4 /* TSX */ || scriptKind === 2 /* JSX */ || scriptKind === 1 /* JS */ || scriptKind === 6 /* JSON */ ? 1 /* JSX */ : 0 /* Standard */;
19721
19893
  }
19722
19894
  ts.getLanguageVariant = getLanguageVariant;
19895
+ /**
19896
+ * This is a somewhat unavoidable full tree walk to locate a JSX tag - `import.meta` requires the same,
19897
+ * but we avoid that walk (or parts of it) if at all possible using the `PossiblyContainsImportMeta` node flag.
19898
+ * Unfortunately, there's no `NodeFlag` space to do the same for JSX.
19899
+ */
19900
+ function walkTreeForJSXTags(node) {
19901
+ if (!(node.transformFlags & 2 /* ContainsJsx */))
19902
+ return undefined;
19903
+ return ts.isJsxOpeningLikeElement(node) || ts.isJsxFragment(node) ? node : ts.forEachChild(node, walkTreeForJSXTags);
19904
+ }
19905
+ function isFileModuleFromUsingJSXTag(file) {
19906
+ // Excludes declaration files - they still require an explicit `export {}` or the like
19907
+ // for back compat purposes. (not that declaration files should contain JSX tags!)
19908
+ return !file.isDeclarationFile ? walkTreeForJSXTags(file) : undefined;
19909
+ }
19910
+ /**
19911
+ * Note that this requires file.impliedNodeFormat be set already; meaning it must be set very early on
19912
+ * in SourceFile construction.
19913
+ */
19914
+ function isFileForcedToBeModuleByFormat(file) {
19915
+ // Excludes declaration files - they still require an explicit `export {}` or the like
19916
+ // for back compat purposes.
19917
+ return file.impliedNodeFormat === ts.ModuleKind.ESNext && !file.isDeclarationFile ? true : undefined;
19918
+ }
19919
+ function getSetExternalModuleIndicator(options) {
19920
+ // TODO: Should this callback be cached?
19921
+ switch (getEmitModuleDetectionKind(options)) {
19922
+ case ts.ModuleDetectionKind.Force:
19923
+ // All non-declaration files are modules, declaration files still do the usual isFileProbablyExternalModule
19924
+ return function (file) {
19925
+ file.externalModuleIndicator = !file.isDeclarationFile || ts.isFileProbablyExternalModule(file);
19926
+ };
19927
+ case ts.ModuleDetectionKind.Legacy:
19928
+ // Files are modules if they have imports, exports, or import.meta
19929
+ return function (file) {
19930
+ file.externalModuleIndicator = ts.isFileProbablyExternalModule(file);
19931
+ };
19932
+ case ts.ModuleDetectionKind.Auto:
19933
+ // If module is nodenext or node12, all esm format files are modules
19934
+ // If jsx is react-jsx or react-jsxdev then jsx tags force module-ness
19935
+ // otherwise, the presence of import or export statments (or import.meta) implies module-ness
19936
+ var checks = [ts.isFileProbablyExternalModule];
19937
+ if (options.jsx === 4 /* ReactJSX */ || options.jsx === 5 /* ReactJSXDev */) {
19938
+ checks.push(isFileModuleFromUsingJSXTag);
19939
+ }
19940
+ var moduleKind = getEmitModuleKind(options);
19941
+ if (moduleKind === ts.ModuleKind.Node12 || moduleKind === ts.ModuleKind.NodeNext) {
19942
+ checks.push(isFileForcedToBeModuleByFormat);
19943
+ }
19944
+ var combined_1 = ts.or.apply(void 0, checks);
19945
+ var callback = function (file) { return void (file.externalModuleIndicator = combined_1(file)); };
19946
+ return callback;
19947
+ }
19948
+ }
19949
+ ts.getSetExternalModuleIndicator = getSetExternalModuleIndicator;
19723
19950
  function getEmitScriptTarget(compilerOptions) {
19724
19951
  return compilerOptions.target ||
19725
19952
  (compilerOptions.module === ts.ModuleKind.Node12 && 7 /* ES2020 */) ||
@@ -19754,6 +19981,10 @@ var ts;
19754
19981
  return moduleResolution;
19755
19982
  }
19756
19983
  ts.getEmitModuleResolutionKind = getEmitModuleResolutionKind;
19984
+ function getEmitModuleDetectionKind(options) {
19985
+ return options.moduleDetection || ts.ModuleDetectionKind.Auto;
19986
+ }
19987
+ ts.getEmitModuleDetectionKind = getEmitModuleDetectionKind;
19757
19988
  function hasJsonModuleEmitEnabled(options) {
19758
19989
  switch (getEmitModuleKind(options)) {
19759
19990
  case ts.ModuleKind.CommonJS:
@@ -29924,6 +30155,36 @@ var ts;
29924
30155
  text.charCodeAt(start + 3) !== 47 /* slash */;
29925
30156
  }
29926
30157
  ts.isJSDocLikeText = isJSDocLikeText;
30158
+ /*@internal*/
30159
+ function isFileProbablyExternalModule(sourceFile) {
30160
+ // Try to use the first top-level import/export when available, then
30161
+ // fall back to looking for an 'import.meta' somewhere in the tree if necessary.
30162
+ return ts.forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) ||
30163
+ getImportMetaIfNecessary(sourceFile);
30164
+ }
30165
+ ts.isFileProbablyExternalModule = isFileProbablyExternalModule;
30166
+ function isAnExternalModuleIndicatorNode(node) {
30167
+ return hasModifierOfKind(node, 93 /* ExportKeyword */)
30168
+ || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
30169
+ || ts.isImportDeclaration(node)
30170
+ || ts.isExportAssignment(node)
30171
+ || ts.isExportDeclaration(node) ? node : undefined;
30172
+ }
30173
+ function getImportMetaIfNecessary(sourceFile) {
30174
+ return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
30175
+ walkTreeForImportMeta(sourceFile) :
30176
+ undefined;
30177
+ }
30178
+ function walkTreeForImportMeta(node) {
30179
+ return isImportMeta(node) ? node : forEachChild(node, walkTreeForImportMeta);
30180
+ }
30181
+ /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */
30182
+ function hasModifierOfKind(node, kind) {
30183
+ return ts.some(node.modifiers, function (m) { return m.kind === kind; });
30184
+ }
30185
+ function isImportMeta(node) {
30186
+ return ts.isMetaProperty(node) && node.keywordToken === 100 /* ImportKeyword */ && node.name.escapedText === "meta";
30187
+ }
29927
30188
  /**
29928
30189
  * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
29929
30190
  * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
@@ -30505,17 +30766,25 @@ var ts;
30505
30766
  children.unshift(n);
30506
30767
  }
30507
30768
  }
30508
- function createSourceFile(fileName, sourceText, languageVersion, setParentNodes, scriptKind) {
30769
+ function setExternalModuleIndicator(sourceFile) {
30770
+ sourceFile.externalModuleIndicator = isFileProbablyExternalModule(sourceFile);
30771
+ }
30772
+ function createSourceFile(fileName, sourceText, languageVersionOrOptions, setParentNodes, scriptKind) {
30509
30773
  if (setParentNodes === void 0) { setParentNodes = false; }
30510
30774
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("parse" /* Parse */, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
30511
30775
  ts.performance.mark("beforeParse");
30512
30776
  var result;
30513
30777
  ts.perfLogger.logStartParseSourceFile(fileName);
30778
+ var _a = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions : { languageVersion: languageVersionOrOptions }, languageVersion = _a.languageVersion, overrideSetExternalModuleIndicator = _a.setExternalModuleIndicator, format = _a.impliedNodeFormat;
30514
30779
  if (languageVersion === 100 /* JSON */) {
30515
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, 6 /* JSON */);
30780
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, 6 /* JSON */, ts.noop);
30516
30781
  }
30517
30782
  else {
30518
- result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind);
30783
+ var setIndicator = format === undefined ? overrideSetExternalModuleIndicator : function (file) {
30784
+ file.impliedNodeFormat = format;
30785
+ return (overrideSetExternalModuleIndicator || setExternalModuleIndicator)(file);
30786
+ };
30787
+ result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind, setIndicator);
30519
30788
  }
30520
30789
  ts.perfLogger.logStopParseSourceFile();
30521
30790
  ts.performance.mark("afterParse");
@@ -30701,7 +30970,7 @@ var ts;
30701
30970
  // Note: any errors at the end of the file that do not precede a regular node, should get
30702
30971
  // attached to the EOF token.
30703
30972
  var parseErrorBeforeNextFinishedNode = false;
30704
- function parseSourceFile(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes, scriptKind) {
30973
+ function parseSourceFile(fileName, sourceText, languageVersion, syntaxCursor, setParentNodes, scriptKind, setExternalModuleIndicatorOverride) {
30705
30974
  var _a;
30706
30975
  if (setParentNodes === void 0) { setParentNodes = false; }
30707
30976
  scriptKind = ts.ensureScriptKind(fileName, scriptKind);
@@ -30717,7 +30986,7 @@ var ts;
30717
30986
  return result_3;
30718
30987
  }
30719
30988
  initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind);
30720
- var result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind);
30989
+ var result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicatorOverride || setExternalModuleIndicator);
30721
30990
  clearState();
30722
30991
  return result;
30723
30992
  }
@@ -30801,7 +31070,7 @@ var ts;
30801
31070
  endOfFileToken = parseExpectedToken(1 /* EndOfFileToken */, ts.Diagnostics.Unexpected_token);
30802
31071
  }
30803
31072
  // Set source file so that errors will be reported with this file name
30804
- var sourceFile = createSourceFile(fileName, 2 /* ES2015 */, 6 /* JSON */, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags);
31073
+ var sourceFile = createSourceFile(fileName, 2 /* ES2015 */, 6 /* JSON */, /*isDeclaration*/ false, statements, endOfFileToken, sourceFlags, ts.noop);
30805
31074
  if (setParentNodes) {
30806
31075
  fixupParentReferences(sourceFile);
30807
31076
  }
@@ -30875,7 +31144,7 @@ var ts;
30875
31144
  notParenthesizedArrow = undefined;
30876
31145
  topLevel = true;
30877
31146
  }
30878
- function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind) {
31147
+ function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicator) {
30879
31148
  var isDeclarationFile = isDeclarationFileName(fileName);
30880
31149
  if (isDeclarationFile) {
30881
31150
  contextFlags |= 8388608 /* Ambient */;
@@ -30886,7 +31155,7 @@ var ts;
30886
31155
  var statements = parseList(0 /* SourceElements */, parseStatement);
30887
31156
  ts.Debug.assert(token() === 1 /* EndOfFileToken */);
30888
31157
  var endOfFileToken = addJSDocComment(parseTokenNode());
30889
- var sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags);
31158
+ var sourceFile = createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, sourceFlags, setExternalModuleIndicator);
30890
31159
  // 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
30891
31160
  processCommentPragmas(sourceFile, sourceText);
30892
31161
  processPragmasIntoFields(sourceFile, reportPragmaDiagnostic);
@@ -31023,25 +31292,30 @@ var ts;
31023
31292
  ts.setParentRecursive(rootNode, /*incremental*/ true);
31024
31293
  }
31025
31294
  Parser.fixupParentReferences = fixupParentReferences;
31026
- function createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, flags) {
31295
+ function createSourceFile(fileName, languageVersion, scriptKind, isDeclarationFile, statements, endOfFileToken, flags, setExternalModuleIndicator) {
31027
31296
  // code from createNode is inlined here so createNode won't have to deal with special case of creating source files
31028
31297
  // this is quite rare comparing to other nodes and createNode should be as fast as possible
31029
31298
  var sourceFile = factory.createSourceFile(statements, endOfFileToken, flags);
31030
31299
  ts.setTextRangePosWidth(sourceFile, 0, sourceText.length);
31031
- setExternalModuleIndicator(sourceFile);
31300
+ setFields(sourceFile);
31032
31301
  // If we parsed this as an external module, it may contain top-level await
31033
31302
  if (!isDeclarationFile && isExternalModule(sourceFile) && sourceFile.transformFlags & 16777216 /* ContainsPossibleTopLevelAwait */) {
31034
31303
  sourceFile = reparseTopLevelAwait(sourceFile);
31304
+ setFields(sourceFile);
31035
31305
  }
31036
- sourceFile.text = sourceText;
31037
- sourceFile.bindDiagnostics = [];
31038
- sourceFile.bindSuggestionDiagnostics = undefined;
31039
- sourceFile.languageVersion = languageVersion;
31040
- sourceFile.fileName = fileName;
31041
- sourceFile.languageVariant = ts.getLanguageVariant(scriptKind);
31042
- sourceFile.isDeclarationFile = isDeclarationFile;
31043
- sourceFile.scriptKind = scriptKind;
31044
31306
  return sourceFile;
31307
+ function setFields(sourceFile) {
31308
+ sourceFile.text = sourceText;
31309
+ sourceFile.bindDiagnostics = [];
31310
+ sourceFile.bindSuggestionDiagnostics = undefined;
31311
+ sourceFile.languageVersion = languageVersion;
31312
+ sourceFile.fileName = fileName;
31313
+ sourceFile.languageVariant = ts.getLanguageVariant(scriptKind);
31314
+ sourceFile.isDeclarationFile = isDeclarationFile;
31315
+ sourceFile.scriptKind = scriptKind;
31316
+ setExternalModuleIndicator(sourceFile);
31317
+ sourceFile.setExternalModuleIndicator = setExternalModuleIndicator;
31318
+ }
31045
31319
  }
31046
31320
  function setContextFlag(val, flag) {
31047
31321
  if (val) {
@@ -36524,35 +36798,6 @@ var ts;
36524
36798
  var node = factory.createExportAssignment(decorators, modifiers, isExportEquals, expression);
36525
36799
  return withJSDoc(finishNode(node, pos), hasJSDoc);
36526
36800
  }
36527
- function setExternalModuleIndicator(sourceFile) {
36528
- // Try to use the first top-level import/export when available, then
36529
- // fall back to looking for an 'import.meta' somewhere in the tree if necessary.
36530
- sourceFile.externalModuleIndicator =
36531
- ts.forEach(sourceFile.statements, isAnExternalModuleIndicatorNode) ||
36532
- getImportMetaIfNecessary(sourceFile);
36533
- }
36534
- function isAnExternalModuleIndicatorNode(node) {
36535
- return hasModifierOfKind(node, 93 /* ExportKeyword */)
36536
- || ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
36537
- || ts.isImportDeclaration(node)
36538
- || ts.isExportAssignment(node)
36539
- || ts.isExportDeclaration(node) ? node : undefined;
36540
- }
36541
- function getImportMetaIfNecessary(sourceFile) {
36542
- return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
36543
- walkTreeForExternalModuleIndicators(sourceFile) :
36544
- undefined;
36545
- }
36546
- function walkTreeForExternalModuleIndicators(node) {
36547
- return isImportMeta(node) ? node : forEachChild(node, walkTreeForExternalModuleIndicators);
36548
- }
36549
- /** Do not use hasModifier inside the parser; it relies on parent pointers. Use this instead. */
36550
- function hasModifierOfKind(node, kind) {
36551
- return ts.some(node.modifiers, function (m) { return m.kind === kind; });
36552
- }
36553
- function isImportMeta(node) {
36554
- return ts.isMetaProperty(node) && node.keywordToken === 100 /* ImportKeyword */ && node.name.escapedText === "meta";
36555
- }
36556
36801
  var ParsingContext;
36557
36802
  (function (ParsingContext) {
36558
36803
  ParsingContext[ParsingContext["SourceElements"] = 0] = "SourceElements";
@@ -36595,7 +36840,7 @@ var ts;
36595
36840
  scanner.setText(content, start, length);
36596
36841
  currentToken = scanner.scan();
36597
36842
  var jsDocTypeExpression = parseJSDocTypeExpression();
36598
- var sourceFile = createSourceFile("file.js", 99 /* Latest */, 1 /* JS */, /*isDeclarationFile*/ false, [], factory.createToken(1 /* EndOfFileToken */), 0 /* None */);
36843
+ var sourceFile = createSourceFile("file.js", 99 /* Latest */, 1 /* JS */, /*isDeclarationFile*/ false, [], factory.createToken(1 /* EndOfFileToken */), 0 /* None */, ts.noop);
36599
36844
  var diagnostics = ts.attachFileToDiagnostics(parseDiagnostics, sourceFile);
36600
36845
  if (jsDocDiagnostics) {
36601
36846
  sourceFile.jsDocDiagnostics = ts.attachFileToDiagnostics(jsDocDiagnostics, sourceFile);
@@ -37556,7 +37801,7 @@ var ts;
37556
37801
  if (sourceFile.statements.length === 0) {
37557
37802
  // If we don't have any statements in the current source file, then there's no real
37558
37803
  // way to incrementally parse. So just do a full parse instead.
37559
- return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind);
37804
+ return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
37560
37805
  }
37561
37806
  // Make sure we're not trying to incrementally update a source file more than once. Once
37562
37807
  // we do an update the original source file is considered unusable from that point onwards.
@@ -37613,7 +37858,7 @@ var ts;
37613
37858
  // inconsistent tree. Setting the parents on the new tree should be very fast. We
37614
37859
  // will immediately bail out of walking any subtrees when we can see that their parents
37615
37860
  // are already correct.
37616
- var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind);
37861
+ var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /*setParentNodes*/ true, sourceFile.scriptKind, sourceFile.setExternalModuleIndicator);
37617
37862
  result.commentDirectives = getNewCommentDirectives(sourceFile.commentDirectives, result.commentDirectives, changeRange.span.start, ts.textSpanEnd(changeRange.span), delta, oldText, newText, aggressiveChecks);
37618
37863
  result.impliedNodeFormat = sourceFile.impliedNodeFormat;
37619
37864
  return result;
@@ -39529,6 +39774,18 @@ var ts;
39529
39774
  description: ts.Diagnostics.Specify_a_list_of_language_service_plugins_to_include,
39530
39775
  category: ts.Diagnostics.Editor_Support,
39531
39776
  },
39777
+ {
39778
+ name: "moduleDetection",
39779
+ type: new ts.Map(ts.getEntries({
39780
+ auto: ts.ModuleDetectionKind.Auto,
39781
+ legacy: ts.ModuleDetectionKind.Legacy,
39782
+ force: ts.ModuleDetectionKind.Force,
39783
+ })),
39784
+ affectsModuleResolution: true,
39785
+ description: ts.Diagnostics.Control_what_method_is_used_to_detect_module_format_JS_files,
39786
+ category: ts.Diagnostics.Language_and_Environment,
39787
+ 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,
39788
+ }
39532
39789
  ];
39533
39790
  /* @internal */
39534
39791
  ts.optionDeclarations = __spreadArray(__spreadArray([], ts.commonOptionsWithBuild, true), commandOptionsWithoutBuild, true);
@@ -63482,7 +63739,8 @@ var ts;
63482
63739
  return true;
63483
63740
  }
63484
63741
  }
63485
- else {
63742
+ else if (!((source.flags | target.flags) & (3145728 /* UnionOrIntersection */ | 8388608 /* IndexedAccess */ | 16777216 /* Conditional */ | 33554432 /* Substitution */))) {
63743
+ // We have excluded types that may simplify to other forms, so types must have identical flags
63486
63744
  if (source.flags !== target.flags)
63487
63745
  return false;
63488
63746
  if (source.flags & 67358815 /* Singleton */)
@@ -69558,7 +69816,7 @@ var ts;
69558
69816
  return result;
69559
69817
  }
69560
69818
  function getCandidateDiscriminantPropertyAccess(expr) {
69561
- if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference)) {
69819
+ if (ts.isBindingPattern(reference) || ts.isFunctionExpressionOrArrowFunction(reference) || ts.isObjectLiteralMethod(reference)) {
69562
69820
  // When the reference is a binding pattern or function or arrow expression, we are narrowing a pesudo-reference in
69563
69821
  // getNarrowedTypeOfSymbol. An identifier for a destructuring variable declared in the same binding pattern or
69564
69822
  // parameter declared in the same parameter list is a candidate.
@@ -76530,6 +76788,9 @@ var ts;
76530
76788
  assignBindingElementTypes(declaration.name, links.type);
76531
76789
  }
76532
76790
  }
76791
+ else if (type) {
76792
+ ts.Debug.assertEqual(links.type, type, "Parameter symbol already has a cached type which differs from newly assigned type");
76793
+ }
76533
76794
  }
76534
76795
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76535
76796
  // the destructured type into the contained binding elements.
@@ -87422,8 +87683,8 @@ var ts;
87422
87683
  }
87423
87684
  else {
87424
87685
  var elements = name.elements;
87425
- for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
87426
- var element = elements_1[_i];
87686
+ for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87687
+ var element = elements_2[_i];
87427
87688
  if (!ts.isOmittedExpression(element)) {
87428
87689
  return checkESModuleMarker(element.name);
87429
87690
  }
@@ -87439,8 +87700,8 @@ var ts;
87439
87700
  }
87440
87701
  else {
87441
87702
  var elements = name.elements;
87442
- for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
87443
- var element = elements_2[_i];
87703
+ for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
87704
+ var element = elements_3[_i];
87444
87705
  if (!ts.isOmittedExpression(element)) {
87445
87706
  checkGrammarNameInLetOrConstDeclarations(element.name);
87446
87707
  }
@@ -89694,8 +89955,8 @@ var ts;
89694
89955
  }
89695
89956
  function bindingOrAssignmentPatternAssignsToName(pattern, escapedName) {
89696
89957
  var elements = ts.getElementsOfBindingOrAssignmentPattern(pattern);
89697
- for (var _i = 0, elements_3 = elements; _i < elements_3.length; _i++) {
89698
- var element = elements_3[_i];
89958
+ for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
89959
+ var element = elements_4[_i];
89699
89960
  if (bindingOrAssignmentElementAssignsToName(element, escapedName)) {
89700
89961
  return true;
89701
89962
  }
@@ -95313,8 +95574,8 @@ var ts;
95313
95574
  function chunkObjectLiteralElements(elements) {
95314
95575
  var chunkObject;
95315
95576
  var objects = [];
95316
- for (var _i = 0, elements_4 = elements; _i < elements_4.length; _i++) {
95317
- var e = elements_4[_i];
95577
+ for (var _i = 0, elements_5 = elements; _i < elements_5.length; _i++) {
95578
+ var e = elements_5[_i];
95318
95579
  if (e.kind === 297 /* SpreadAssignment */) {
95319
95580
  if (chunkObject) {
95320
95581
  objects.push(factory.createObjectLiteralExpression(chunkObject));
@@ -114335,7 +114596,7 @@ var ts;
114335
114596
  var existingDirectories = new ts.Map();
114336
114597
  var getCanonicalFileName = ts.createGetCanonicalFileName(system.useCaseSensitiveFileNames);
114337
114598
  var computeHash = ts.maybeBind(system, system.createHash) || ts.generateDjb2Hash;
114338
- function getSourceFile(fileName, languageVersion, onError) {
114599
+ function getSourceFile(fileName, languageVersionOrOptions, onError) {
114339
114600
  var text;
114340
114601
  try {
114341
114602
  ts.performance.mark("beforeIORead");
@@ -114349,7 +114610,7 @@ var ts;
114349
114610
  }
114350
114611
  text = "";
114351
114612
  }
114352
- return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined;
114613
+ return text !== undefined ? ts.createSourceFile(fileName, text, languageVersionOrOptions, setParentNodes) : undefined;
114353
114614
  }
114354
114615
  function directoryExists(directoryPath) {
114355
114616
  if (existingDirectories.has(directoryPath)) {
@@ -115755,8 +116016,8 @@ var ts;
115755
116016
  for (var _i = 0, oldSourceFiles_2 = oldSourceFiles; _i < oldSourceFiles_2.length; _i++) {
115756
116017
  var oldSourceFile = oldSourceFiles_2[_i];
115757
116018
  var newSourceFile = host.getSourceFileByPath
115758
- ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, ts.getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile)
115759
- : host.getSourceFile(oldSourceFile.fileName, ts.getEmitScriptTarget(options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
116019
+ ? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.resolvedPath, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile)
116020
+ : host.getSourceFile(oldSourceFile.fileName, getCreateSourceFileOptions(oldSourceFile.fileName, moduleResolutionCache, host, options), /*onError*/ undefined, shouldCreateNewSourceFile); // TODO: GH#18217
115760
116021
  if (!newSourceFile) {
115761
116022
  return 0 /* Not */;
115762
116023
  }
@@ -115787,7 +116048,6 @@ var ts;
115787
116048
  newSourceFile.originalFileName = oldSourceFile.originalFileName;
115788
116049
  newSourceFile.resolvedPath = oldSourceFile.resolvedPath;
115789
116050
  newSourceFile.fileName = oldSourceFile.fileName;
115790
- newSourceFile.impliedNodeFormat = oldSourceFile.impliedNodeFormat;
115791
116051
  var packageName = oldProgram.sourceFileToPackageName.get(oldSourceFile.path);
115792
116052
  if (packageName !== undefined) {
115793
116053
  // If there are 2 different source files for the same package name and at least one of them changes,
@@ -116706,6 +116966,17 @@ var ts;
116706
116966
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
116707
116967
  return result;
116708
116968
  }
116969
+ function getCreateSourceFileOptions(fileName, moduleResolutionCache, host, options) {
116970
+ // 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
116971
+ // 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
116972
+ // 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.
116973
+ var impliedNodeFormat = getImpliedNodeFormatForFile(toPath(fileName), moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
116974
+ return {
116975
+ languageVersion: ts.getEmitScriptTarget(options),
116976
+ impliedNodeFormat: impliedNodeFormat,
116977
+ setExternalModuleIndicator: ts.getSetExternalModuleIndicator(options)
116978
+ };
116979
+ }
116709
116980
  function findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId) {
116710
116981
  var path = toPath(fileName);
116711
116982
  if (useSourceOfProjectReferenceRedirect) {
@@ -116793,7 +117064,7 @@ var ts;
116793
117064
  }
116794
117065
  }
116795
117066
  // We haven't looked for this file, do so now and cache result
116796
- 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);
117067
+ 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);
116797
117068
  if (packageId) {
116798
117069
  var packageIdKey = ts.packageIdToString(packageId);
116799
117070
  var fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
@@ -116821,10 +117092,6 @@ var ts;
116821
117092
  file.path = path;
116822
117093
  file.resolvedPath = toPath(fileName);
116823
117094
  file.originalFileName = originalFileName;
116824
- // 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
116825
- // 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
116826
- // 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.
116827
- file.impliedNodeFormat = getImpliedNodeFormatForFile(file.resolvedPath, moduleResolutionCache === null || moduleResolutionCache === void 0 ? void 0 : moduleResolutionCache.getPackageJsonInfoCache(), host, options);
116828
117095
  addFileIncludeReason(file, reason);
116829
117096
  if (host.useCaseSensitiveFileNames()) {
116830
117097
  var pathLowerCase = ts.toFileNameLowerCase(path);
@@ -117326,7 +117593,7 @@ var ts;
117326
117593
  }
117327
117594
  else if (firstNonAmbientExternalModuleSourceFile && languageVersion < 2 /* ES2015 */ && options.module === ts.ModuleKind.None) {
117328
117595
  // We cannot use createDiagnosticFromNode because nodes do not have parents yet
117329
- var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117596
+ var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117330
117597
  programDiagnostics.add(ts.createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none));
117331
117598
  }
117332
117599
  // Cannot specify module gen that isn't amd or system with --out
@@ -117335,7 +117602,7 @@ var ts;
117335
117602
  createDiagnosticForOptionName(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile", "module");
117336
117603
  }
117337
117604
  else if (options.module === undefined && firstNonAmbientExternalModuleSourceFile) {
117338
- var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117605
+ var span = ts.getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator);
117339
117606
  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"));
117340
117607
  }
117341
117608
  }
@@ -121597,7 +121864,7 @@ var ts;
121597
121864
  var useCaseSensitiveFileNames = host.useCaseSensitiveFileNames();
121598
121865
  var hostGetNewLine = ts.memoize(function () { return host.getNewLine(); });
121599
121866
  return {
121600
- getSourceFile: function (fileName, languageVersion, onError) {
121867
+ getSourceFile: function (fileName, languageVersionOrOptions, onError) {
121601
121868
  var text;
121602
121869
  try {
121603
121870
  ts.performance.mark("beforeIORead");
@@ -121611,7 +121878,7 @@ var ts;
121611
121878
  }
121612
121879
  text = "";
121613
121880
  }
121614
- return text !== undefined ? ts.createSourceFile(fileName, text, languageVersion) : undefined;
121881
+ return text !== undefined ? ts.createSourceFile(fileName, text, languageVersionOrOptions) : undefined;
121615
121882
  },
121616
121883
  getDefaultLibLocation: ts.maybeBind(host, host.getDefaultLibLocation),
121617
121884
  getDefaultLibFileName: function (options) { return host.getDefaultLibFileName(options); },
@@ -122079,7 +122346,7 @@ var ts;
122079
122346
  }
122080
122347
  return directoryStructureHost.fileExists(fileName);
122081
122348
  }
122082
- function getVersionedSourceFileByPath(fileName, path, languageVersion, onError, shouldCreateNewSourceFile) {
122349
+ function getVersionedSourceFileByPath(fileName, path, languageVersionOrOptions, onError, shouldCreateNewSourceFile) {
122083
122350
  var hostSourceFile = sourceFilesCache.get(path);
122084
122351
  // No source file on the host
122085
122352
  if (isFileMissingOnHost(hostSourceFile)) {
@@ -122087,7 +122354,7 @@ var ts;
122087
122354
  }
122088
122355
  // Create new source file if requested or the versions dont match
122089
122356
  if (hostSourceFile === undefined || shouldCreateNewSourceFile || isFilePresenceUnknownOnHost(hostSourceFile)) {
122090
- var sourceFile = getNewSourceFile(fileName, languageVersion, onError);
122357
+ var sourceFile = getNewSourceFile(fileName, languageVersionOrOptions, onError);
122091
122358
  if (hostSourceFile) {
122092
122359
  if (sourceFile) {
122093
122360
  // Set the source file and create file watcher now that file was present on the disk