typescript 4.5.0-dev.20211027 → 4.5.0-dev.20211028

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20211027";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20211028";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -9537,6 +9537,7 @@ var ts;
9537
9537
  This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead: diag(7059, ts.DiagnosticCategory.Error, "This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead_7059", "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead."),
9538
9538
  This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Add_a_trailing_comma_or_explicit_constraint: diag(7060, ts.DiagnosticCategory.Error, "This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Add_a_trailing_comma_or_explicit_cons_7060", "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma or explicit constraint."),
9539
9539
  A_mapped_type_may_not_declare_properties_or_methods: diag(7061, ts.DiagnosticCategory.Error, "A_mapped_type_may_not_declare_properties_or_methods_7061", "A mapped type may not declare properties or methods."),
9540
+ JSON_imports_are_experimental_in_ES_module_mode_imports: diag(7062, ts.DiagnosticCategory.Error, "JSON_imports_are_experimental_in_ES_module_mode_imports_7062", "JSON imports are experimental in ES module mode imports."),
9540
9541
  You_cannot_rename_this_element: diag(8000, ts.DiagnosticCategory.Error, "You_cannot_rename_this_element_8000", "You cannot rename this element."),
9541
9542
  You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: diag(8001, ts.DiagnosticCategory.Error, "You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library_8001", "You cannot rename elements that are defined in the standard TypeScript library."),
9542
9543
  import_can_only_be_used_in_TypeScript_files: diag(8002, ts.DiagnosticCategory.Error, "import_can_only_be_used_in_TypeScript_files_8002", "'import ... =' can only be used in TypeScript files."),
@@ -19833,6 +19834,8 @@ var ts;
19833
19834
  case ts.ModuleKind.ES2020:
19834
19835
  case ts.ModuleKind.ES2022:
19835
19836
  case ts.ModuleKind.ESNext:
19837
+ case ts.ModuleKind.Node12:
19838
+ case ts.ModuleKind.NodeNext:
19836
19839
  return true;
19837
19840
  default:
19838
19841
  return false;
@@ -49018,6 +49021,10 @@ var ts;
49018
49021
  function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) {
49019
49022
  return usageMode === ts.ModuleKind.ESNext && targetMode === ts.ModuleKind.CommonJS;
49020
49023
  }
49024
+ function isOnlyImportedAsDefault(usage) {
49025
+ var usageMode = getUsageModeForExpression(usage);
49026
+ return usageMode === ts.ModuleKind.ESNext && ts.endsWith(usage.text, ".json" /* Json */);
49027
+ }
49021
49028
  function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) {
49022
49029
  var usageMode = file && getUsageModeForExpression(usage);
49023
49030
  if (file && usageMode !== undefined) {
@@ -49068,8 +49075,9 @@ var ts;
49068
49075
  exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* Default */, node, dontResolveAlias);
49069
49076
  }
49070
49077
  var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
49078
+ var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier);
49071
49079
  var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier);
49072
- if (!exportDefaultSymbol && !hasSyntheticDefault) {
49080
+ if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) {
49073
49081
  if (hasExportAssignmentSymbol(moduleSymbol)) {
49074
49082
  var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";
49075
49083
  var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* ExportEquals */);
@@ -49083,7 +49091,7 @@ var ts;
49083
49091
  reportNonDefaultExport(moduleSymbol, node);
49084
49092
  }
49085
49093
  }
49086
- else if (hasSyntheticDefault) {
49094
+ else if (hasSyntheticDefault || hasDefaultOnly) {
49087
49095
  // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present
49088
49096
  var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
49089
49097
  markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false);
@@ -49208,7 +49216,7 @@ var ts;
49208
49216
  var symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias);
49209
49217
  if (symbolFromModule === undefined && name.escapedText === "default" /* Default */) {
49210
49218
  var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
49211
- if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
49219
+ if (isOnlyImportedAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
49212
49220
  symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
49213
49221
  }
49214
49222
  }
@@ -49759,6 +49767,9 @@ var ts;
49759
49767
  if (isSyncImport && sourceFile.impliedNodeFormat === ts.ModuleKind.ESNext) {
49760
49768
  error(errorNode, ts.Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead, moduleReference);
49761
49769
  }
49770
+ if (mode === ts.ModuleKind.ESNext && compilerOptions.resolveJsonModule && resolvedModule.extension === ".json" /* Json */) {
49771
+ error(errorNode, ts.Diagnostics.JSON_imports_are_experimental_in_ES_module_mode_imports);
49772
+ }
49762
49773
  }
49763
49774
  // merged symbol is module declaration symbol combined with all augmentations
49764
49775
  return getMergedSymbol(sourceFile.symbol);
@@ -49897,40 +49908,50 @@ var ts;
49897
49908
  error(referencingLocation, ts.Diagnostics.This_module_can_only_be_referenced_with_ECMAScript_imports_Slashexports_by_turning_on_the_0_flag_and_referencing_its_default_export, compilerOptionName);
49898
49909
  return symbol;
49899
49910
  }
49900
- if (ts.getESModuleInterop(compilerOptions)) {
49901
- var referenceParent = referencingLocation.parent;
49902
- if ((ts.isImportDeclaration(referenceParent) && ts.getNamespaceDeclarationNode(referenceParent)) ||
49903
- ts.isImportCall(referenceParent)) {
49904
- var type = getTypeOfSymbol(symbol);
49911
+ var referenceParent = referencingLocation.parent;
49912
+ if ((ts.isImportDeclaration(referenceParent) && ts.getNamespaceDeclarationNode(referenceParent)) ||
49913
+ ts.isImportCall(referenceParent)) {
49914
+ var reference = ts.isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier;
49915
+ var type = getTypeOfSymbol(symbol);
49916
+ var defaultOnlyType = getTypeWithSyntheticDefaultOnly(type, symbol, moduleSymbol, reference);
49917
+ if (defaultOnlyType) {
49918
+ return cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent);
49919
+ }
49920
+ if (ts.getESModuleInterop(compilerOptions)) {
49905
49921
  var sigs = getSignaturesOfStructuredType(type, 0 /* Call */);
49906
49922
  if (!sigs || !sigs.length) {
49907
49923
  sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
49908
49924
  }
49909
- if (sigs && sigs.length) {
49910
- var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, ts.isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier);
49911
- // Create a new symbol which has the module's type less the call and construct signatures
49912
- var result = createSymbol(symbol.flags, symbol.escapedName);
49913
- result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
49914
- result.parent = symbol.parent;
49915
- result.target = symbol;
49916
- result.originatingImport = referenceParent;
49917
- if (symbol.valueDeclaration)
49918
- result.valueDeclaration = symbol.valueDeclaration;
49919
- if (symbol.constEnumOnlyModule)
49920
- result.constEnumOnlyModule = true;
49921
- if (symbol.members)
49922
- result.members = new ts.Map(symbol.members);
49923
- if (symbol.exports)
49924
- result.exports = new ts.Map(symbol.exports);
49925
- var resolvedModuleType = resolveStructuredTypeMembers(moduleType); // Should already be resolved from the signature checks above
49926
- result.type = createAnonymousType(result, resolvedModuleType.members, ts.emptyArray, ts.emptyArray, resolvedModuleType.indexInfos);
49927
- return result;
49925
+ if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
49926
+ var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
49927
+ return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
49928
49928
  }
49929
49929
  }
49930
49930
  }
49931
49931
  }
49932
49932
  return symbol;
49933
49933
  }
49934
+ /**
49935
+ * Create a new symbol which has the module's type less the call and construct signatures
49936
+ */
49937
+ function cloneTypeAsModuleType(symbol, moduleType, referenceParent) {
49938
+ var result = createSymbol(symbol.flags, symbol.escapedName);
49939
+ result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
49940
+ result.parent = symbol.parent;
49941
+ result.target = symbol;
49942
+ result.originatingImport = referenceParent;
49943
+ if (symbol.valueDeclaration)
49944
+ result.valueDeclaration = symbol.valueDeclaration;
49945
+ if (symbol.constEnumOnlyModule)
49946
+ result.constEnumOnlyModule = true;
49947
+ if (symbol.members)
49948
+ result.members = new ts.Map(symbol.members);
49949
+ if (symbol.exports)
49950
+ result.exports = new ts.Map(symbol.exports);
49951
+ var resolvedModuleType = resolveStructuredTypeMembers(moduleType); // Should already be resolved from the signature checks above
49952
+ result.type = createAnonymousType(result, resolvedModuleType.members, ts.emptyArray, ts.emptyArray, resolvedModuleType.indexInfos);
49953
+ return result;
49954
+ }
49934
49955
  function hasExportAssignmentSymbol(moduleSymbol) {
49935
49956
  return moduleSymbol.exports.get("export=" /* ExportEquals */) !== undefined;
49936
49957
  }
@@ -61729,7 +61750,8 @@ var ts;
61729
61750
  return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
61730
61751
  if (t.flags & (3 /* AnyOrUnknown */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && t !== wildcardType && !isErrorType(t)) {
61731
61752
  if (!type.declaration.nameType) {
61732
- if (isArrayType(t)) {
61753
+ var constraint = void 0;
61754
+ if (isArrayType(t) || (t.flags & 1 /* Any */) && (constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, ts.or(isArrayType, isTupleType))) {
61733
61755
  return instantiateMappedArrayType(t, type, prependTypeMapping(typeVariable, t, mapper));
61734
61756
  }
61735
61757
  if (isGenericTupleType(t)) {
@@ -67376,8 +67398,11 @@ var ts;
67376
67398
  function getFlowCacheKey(node, declaredType, initialType, flowContainer) {
67377
67399
  switch (node.kind) {
67378
67400
  case 79 /* Identifier */:
67379
- var symbol = getResolvedSymbol(node);
67380
- return symbol !== unknownSymbol ? (flowContainer ? getNodeId(flowContainer) : "-1") + "|" + getTypeId(declaredType) + "|" + getTypeId(initialType) + "|" + getSymbolId(symbol) : undefined;
67401
+ if (!ts.isThisInTypeQuery(node)) {
67402
+ var symbol = getResolvedSymbol(node);
67403
+ return symbol !== unknownSymbol ? (flowContainer ? getNodeId(flowContainer) : "-1") + "|" + getTypeId(declaredType) + "|" + getTypeId(initialType) + "|" + getSymbolId(symbol) : undefined;
67404
+ }
67405
+ // falls through
67381
67406
  case 108 /* ThisKeyword */:
67382
67407
  return "0|" + (flowContainer ? getNodeId(flowContainer) : "-1") + "|" + getTypeId(declaredType) + "|" + getTypeId(initialType);
67383
67408
  case 229 /* NonNullExpression */:
@@ -75106,11 +75131,33 @@ var ts;
75106
75131
  if (moduleSymbol) {
75107
75132
  var esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true, /*suppressUsageError*/ false);
75108
75133
  if (esModuleSymbol) {
75109
- return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
75134
+ return createPromiseReturnType(node, getTypeWithSyntheticDefaultOnly(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier) ||
75135
+ getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
75110
75136
  }
75111
75137
  }
75112
75138
  return createPromiseReturnType(node, anyType);
75113
75139
  }
75140
+ function createDefaultPropertyWrapperForModule(symbol, originalSymbol, anonymousSymbol) {
75141
+ var memberTable = ts.createSymbolTable();
75142
+ var newSymbol = createSymbol(2097152 /* Alias */, "default" /* Default */);
75143
+ newSymbol.parent = originalSymbol;
75144
+ newSymbol.nameType = getStringLiteralType("default");
75145
+ newSymbol.target = resolveSymbol(symbol);
75146
+ memberTable.set("default" /* Default */, newSymbol);
75147
+ return createAnonymousType(anonymousSymbol, memberTable, ts.emptyArray, ts.emptyArray, ts.emptyArray);
75148
+ }
75149
+ function getTypeWithSyntheticDefaultOnly(type, symbol, originalSymbol, moduleSpecifier) {
75150
+ var hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier);
75151
+ if (hasDefaultOnly && type && !isErrorType(type)) {
75152
+ var synthType = type;
75153
+ if (!synthType.defaultOnlyType) {
75154
+ var type_4 = createDefaultPropertyWrapperForModule(symbol, originalSymbol);
75155
+ synthType.defaultOnlyType = type_4;
75156
+ }
75157
+ return synthType.defaultOnlyType;
75158
+ }
75159
+ return undefined;
75160
+ }
75114
75161
  function getTypeWithSyntheticDefaultImportType(type, symbol, originalSymbol, moduleSpecifier) {
75115
75162
  var _a;
75116
75163
  if (allowSyntheticDefaultImports && type && !isErrorType(type)) {
@@ -75119,14 +75166,8 @@ var ts;
75119
75166
  var file = (_a = originalSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
75120
75167
  var hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false, moduleSpecifier);
75121
75168
  if (hasSyntheticDefault) {
75122
- var memberTable = ts.createSymbolTable();
75123
- var newSymbol = createSymbol(2097152 /* Alias */, "default" /* Default */);
75124
- newSymbol.parent = originalSymbol;
75125
- newSymbol.nameType = getStringLiteralType("default");
75126
- newSymbol.target = resolveSymbol(symbol);
75127
- memberTable.set("default" /* Default */, newSymbol);
75128
75169
  var anonymousSymbol = createSymbol(2048 /* TypeLiteral */, "__type" /* Type */);
75129
- var defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, ts.emptyArray, ts.emptyArray, ts.emptyArray);
75170
+ var defaultContainingObject = createDefaultPropertyWrapperForModule(symbol, originalSymbol, anonymousSymbol);
75130
75171
  anonymousSymbol.type = defaultContainingObject;
75131
75172
  synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*objectFlags*/ 0, /*readonly*/ false) : defaultContainingObject;
75132
75173
  }
@@ -75834,12 +75875,12 @@ var ts;
75834
75875
  var witnesses = getSwitchClauseTypeOfWitnesses(node, /*retainDefault*/ false);
75835
75876
  // notEqualFacts states that the type of the switched value is not equal to every type in the switch.
75836
75877
  var notEqualFacts_1 = getFactsFromTypeofSwitch(0, 0, witnesses, /*hasDefault*/ true);
75837
- var type_4 = getBaseConstraintOfType(operandType) || operandType;
75878
+ var type_5 = getBaseConstraintOfType(operandType) || operandType;
75838
75879
  // Take any/unknown as a special condition. Or maybe we could change `type` to a union containing all primitive types.
75839
- if (type_4.flags & 3 /* AnyOrUnknown */) {
75880
+ if (type_5.flags & 3 /* AnyOrUnknown */) {
75840
75881
  return (556800 /* AllTypeofNE */ & notEqualFacts_1) === 556800 /* AllTypeofNE */;
75841
75882
  }
75842
- return !!(filterType(type_4, function (t) { return (getTypeFacts(t) & notEqualFacts_1) === notEqualFacts_1; }).flags & 131072 /* Never */);
75883
+ return !!(filterType(type_5, function (t) { return (getTypeFacts(t) & notEqualFacts_1) === notEqualFacts_1; }).flags & 131072 /* Never */);
75843
75884
  }
75844
75885
  var type = getTypeOfExpression(node.expression);
75845
75886
  if (!isLiteralType(type)) {
@@ -115651,7 +115692,9 @@ var ts;
115651
115692
  }
115652
115693
  }
115653
115694
  if (options.resolveJsonModule) {
115654
- if (ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeJs) {
115695
+ if (ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeJs &&
115696
+ ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 &&
115697
+ ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
115655
115698
  createDiagnosticForOptionName(ts.Diagnostics.Option_resolveJsonModule_cannot_be_specified_without_node_module_resolution_strategy, "resolveJsonModule");
115656
115699
  }
115657
115700
  // Any emit other than common js, amd, es2015 or esnext is error
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.20211027";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20211028";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -9537,6 +9537,7 @@ var ts;
9537
9537
  This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead: diag(7059, ts.DiagnosticCategory.Error, "This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead_7059", "This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead."),
9538
9538
  This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Add_a_trailing_comma_or_explicit_constraint: diag(7060, ts.DiagnosticCategory.Error, "This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Add_a_trailing_comma_or_explicit_cons_7060", "This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma or explicit constraint."),
9539
9539
  A_mapped_type_may_not_declare_properties_or_methods: diag(7061, ts.DiagnosticCategory.Error, "A_mapped_type_may_not_declare_properties_or_methods_7061", "A mapped type may not declare properties or methods."),
9540
+ JSON_imports_are_experimental_in_ES_module_mode_imports: diag(7062, ts.DiagnosticCategory.Error, "JSON_imports_are_experimental_in_ES_module_mode_imports_7062", "JSON imports are experimental in ES module mode imports."),
9540
9541
  You_cannot_rename_this_element: diag(8000, ts.DiagnosticCategory.Error, "You_cannot_rename_this_element_8000", "You cannot rename this element."),
9541
9542
  You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: diag(8001, ts.DiagnosticCategory.Error, "You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library_8001", "You cannot rename elements that are defined in the standard TypeScript library."),
9542
9543
  import_can_only_be_used_in_TypeScript_files: diag(8002, ts.DiagnosticCategory.Error, "import_can_only_be_used_in_TypeScript_files_8002", "'import ... =' can only be used in TypeScript files."),
@@ -19833,6 +19834,8 @@ var ts;
19833
19834
  case ts.ModuleKind.ES2020:
19834
19835
  case ts.ModuleKind.ES2022:
19835
19836
  case ts.ModuleKind.ESNext:
19837
+ case ts.ModuleKind.Node12:
19838
+ case ts.ModuleKind.NodeNext:
19836
19839
  return true;
19837
19840
  default:
19838
19841
  return false;
@@ -49018,6 +49021,10 @@ var ts;
49018
49021
  function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) {
49019
49022
  return usageMode === ts.ModuleKind.ESNext && targetMode === ts.ModuleKind.CommonJS;
49020
49023
  }
49024
+ function isOnlyImportedAsDefault(usage) {
49025
+ var usageMode = getUsageModeForExpression(usage);
49026
+ return usageMode === ts.ModuleKind.ESNext && ts.endsWith(usage.text, ".json" /* Json */);
49027
+ }
49021
49028
  function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) {
49022
49029
  var usageMode = file && getUsageModeForExpression(usage);
49023
49030
  if (file && usageMode !== undefined) {
@@ -49068,8 +49075,9 @@ var ts;
49068
49075
  exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* Default */, node, dontResolveAlias);
49069
49076
  }
49070
49077
  var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
49078
+ var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier);
49071
49079
  var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier);
49072
- if (!exportDefaultSymbol && !hasSyntheticDefault) {
49080
+ if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) {
49073
49081
  if (hasExportAssignmentSymbol(moduleSymbol)) {
49074
49082
  var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";
49075
49083
  var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* ExportEquals */);
@@ -49083,7 +49091,7 @@ var ts;
49083
49091
  reportNonDefaultExport(moduleSymbol, node);
49084
49092
  }
49085
49093
  }
49086
- else if (hasSyntheticDefault) {
49094
+ else if (hasSyntheticDefault || hasDefaultOnly) {
49087
49095
  // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present
49088
49096
  var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
49089
49097
  markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false);
@@ -49208,7 +49216,7 @@ var ts;
49208
49216
  var symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias);
49209
49217
  if (symbolFromModule === undefined && name.escapedText === "default" /* Default */) {
49210
49218
  var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
49211
- if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
49219
+ if (isOnlyImportedAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
49212
49220
  symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
49213
49221
  }
49214
49222
  }
@@ -49759,6 +49767,9 @@ var ts;
49759
49767
  if (isSyncImport && sourceFile.impliedNodeFormat === ts.ModuleKind.ESNext) {
49760
49768
  error(errorNode, ts.Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_synchronously_Use_dynamic_import_instead, moduleReference);
49761
49769
  }
49770
+ if (mode === ts.ModuleKind.ESNext && compilerOptions.resolveJsonModule && resolvedModule.extension === ".json" /* Json */) {
49771
+ error(errorNode, ts.Diagnostics.JSON_imports_are_experimental_in_ES_module_mode_imports);
49772
+ }
49762
49773
  }
49763
49774
  // merged symbol is module declaration symbol combined with all augmentations
49764
49775
  return getMergedSymbol(sourceFile.symbol);
@@ -49897,40 +49908,50 @@ var ts;
49897
49908
  error(referencingLocation, ts.Diagnostics.This_module_can_only_be_referenced_with_ECMAScript_imports_Slashexports_by_turning_on_the_0_flag_and_referencing_its_default_export, compilerOptionName);
49898
49909
  return symbol;
49899
49910
  }
49900
- if (ts.getESModuleInterop(compilerOptions)) {
49901
- var referenceParent = referencingLocation.parent;
49902
- if ((ts.isImportDeclaration(referenceParent) && ts.getNamespaceDeclarationNode(referenceParent)) ||
49903
- ts.isImportCall(referenceParent)) {
49904
- var type = getTypeOfSymbol(symbol);
49911
+ var referenceParent = referencingLocation.parent;
49912
+ if ((ts.isImportDeclaration(referenceParent) && ts.getNamespaceDeclarationNode(referenceParent)) ||
49913
+ ts.isImportCall(referenceParent)) {
49914
+ var reference = ts.isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier;
49915
+ var type = getTypeOfSymbol(symbol);
49916
+ var defaultOnlyType = getTypeWithSyntheticDefaultOnly(type, symbol, moduleSymbol, reference);
49917
+ if (defaultOnlyType) {
49918
+ return cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent);
49919
+ }
49920
+ if (ts.getESModuleInterop(compilerOptions)) {
49905
49921
  var sigs = getSignaturesOfStructuredType(type, 0 /* Call */);
49906
49922
  if (!sigs || !sigs.length) {
49907
49923
  sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
49908
49924
  }
49909
- if (sigs && sigs.length) {
49910
- var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, ts.isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier);
49911
- // Create a new symbol which has the module's type less the call and construct signatures
49912
- var result = createSymbol(symbol.flags, symbol.escapedName);
49913
- result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
49914
- result.parent = symbol.parent;
49915
- result.target = symbol;
49916
- result.originatingImport = referenceParent;
49917
- if (symbol.valueDeclaration)
49918
- result.valueDeclaration = symbol.valueDeclaration;
49919
- if (symbol.constEnumOnlyModule)
49920
- result.constEnumOnlyModule = true;
49921
- if (symbol.members)
49922
- result.members = new ts.Map(symbol.members);
49923
- if (symbol.exports)
49924
- result.exports = new ts.Map(symbol.exports);
49925
- var resolvedModuleType = resolveStructuredTypeMembers(moduleType); // Should already be resolved from the signature checks above
49926
- result.type = createAnonymousType(result, resolvedModuleType.members, ts.emptyArray, ts.emptyArray, resolvedModuleType.indexInfos);
49927
- return result;
49925
+ if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
49926
+ var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
49927
+ return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
49928
49928
  }
49929
49929
  }
49930
49930
  }
49931
49931
  }
49932
49932
  return symbol;
49933
49933
  }
49934
+ /**
49935
+ * Create a new symbol which has the module's type less the call and construct signatures
49936
+ */
49937
+ function cloneTypeAsModuleType(symbol, moduleType, referenceParent) {
49938
+ var result = createSymbol(symbol.flags, symbol.escapedName);
49939
+ result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
49940
+ result.parent = symbol.parent;
49941
+ result.target = symbol;
49942
+ result.originatingImport = referenceParent;
49943
+ if (symbol.valueDeclaration)
49944
+ result.valueDeclaration = symbol.valueDeclaration;
49945
+ if (symbol.constEnumOnlyModule)
49946
+ result.constEnumOnlyModule = true;
49947
+ if (symbol.members)
49948
+ result.members = new ts.Map(symbol.members);
49949
+ if (symbol.exports)
49950
+ result.exports = new ts.Map(symbol.exports);
49951
+ var resolvedModuleType = resolveStructuredTypeMembers(moduleType); // Should already be resolved from the signature checks above
49952
+ result.type = createAnonymousType(result, resolvedModuleType.members, ts.emptyArray, ts.emptyArray, resolvedModuleType.indexInfos);
49953
+ return result;
49954
+ }
49934
49955
  function hasExportAssignmentSymbol(moduleSymbol) {
49935
49956
  return moduleSymbol.exports.get("export=" /* ExportEquals */) !== undefined;
49936
49957
  }
@@ -61729,7 +61750,8 @@ var ts;
61729
61750
  return mapTypeWithAlias(getReducedType(mappedTypeVariable), function (t) {
61730
61751
  if (t.flags & (3 /* AnyOrUnknown */ | 58982400 /* InstantiableNonPrimitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && t !== wildcardType && !isErrorType(t)) {
61731
61752
  if (!type.declaration.nameType) {
61732
- if (isArrayType(t)) {
61753
+ var constraint = void 0;
61754
+ if (isArrayType(t) || (t.flags & 1 /* Any */) && (constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, ts.or(isArrayType, isTupleType))) {
61733
61755
  return instantiateMappedArrayType(t, type, prependTypeMapping(typeVariable, t, mapper));
61734
61756
  }
61735
61757
  if (isGenericTupleType(t)) {
@@ -67376,8 +67398,11 @@ var ts;
67376
67398
  function getFlowCacheKey(node, declaredType, initialType, flowContainer) {
67377
67399
  switch (node.kind) {
67378
67400
  case 79 /* Identifier */:
67379
- var symbol = getResolvedSymbol(node);
67380
- return symbol !== unknownSymbol ? (flowContainer ? getNodeId(flowContainer) : "-1") + "|" + getTypeId(declaredType) + "|" + getTypeId(initialType) + "|" + getSymbolId(symbol) : undefined;
67401
+ if (!ts.isThisInTypeQuery(node)) {
67402
+ var symbol = getResolvedSymbol(node);
67403
+ return symbol !== unknownSymbol ? (flowContainer ? getNodeId(flowContainer) : "-1") + "|" + getTypeId(declaredType) + "|" + getTypeId(initialType) + "|" + getSymbolId(symbol) : undefined;
67404
+ }
67405
+ // falls through
67381
67406
  case 108 /* ThisKeyword */:
67382
67407
  return "0|" + (flowContainer ? getNodeId(flowContainer) : "-1") + "|" + getTypeId(declaredType) + "|" + getTypeId(initialType);
67383
67408
  case 229 /* NonNullExpression */:
@@ -75106,11 +75131,33 @@ var ts;
75106
75131
  if (moduleSymbol) {
75107
75132
  var esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true, /*suppressUsageError*/ false);
75108
75133
  if (esModuleSymbol) {
75109
- return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
75134
+ return createPromiseReturnType(node, getTypeWithSyntheticDefaultOnly(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier) ||
75135
+ getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
75110
75136
  }
75111
75137
  }
75112
75138
  return createPromiseReturnType(node, anyType);
75113
75139
  }
75140
+ function createDefaultPropertyWrapperForModule(symbol, originalSymbol, anonymousSymbol) {
75141
+ var memberTable = ts.createSymbolTable();
75142
+ var newSymbol = createSymbol(2097152 /* Alias */, "default" /* Default */);
75143
+ newSymbol.parent = originalSymbol;
75144
+ newSymbol.nameType = getStringLiteralType("default");
75145
+ newSymbol.target = resolveSymbol(symbol);
75146
+ memberTable.set("default" /* Default */, newSymbol);
75147
+ return createAnonymousType(anonymousSymbol, memberTable, ts.emptyArray, ts.emptyArray, ts.emptyArray);
75148
+ }
75149
+ function getTypeWithSyntheticDefaultOnly(type, symbol, originalSymbol, moduleSpecifier) {
75150
+ var hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier);
75151
+ if (hasDefaultOnly && type && !isErrorType(type)) {
75152
+ var synthType = type;
75153
+ if (!synthType.defaultOnlyType) {
75154
+ var type_4 = createDefaultPropertyWrapperForModule(symbol, originalSymbol);
75155
+ synthType.defaultOnlyType = type_4;
75156
+ }
75157
+ return synthType.defaultOnlyType;
75158
+ }
75159
+ return undefined;
75160
+ }
75114
75161
  function getTypeWithSyntheticDefaultImportType(type, symbol, originalSymbol, moduleSpecifier) {
75115
75162
  var _a;
75116
75163
  if (allowSyntheticDefaultImports && type && !isErrorType(type)) {
@@ -75119,14 +75166,8 @@ var ts;
75119
75166
  var file = (_a = originalSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile);
75120
75167
  var hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false, moduleSpecifier);
75121
75168
  if (hasSyntheticDefault) {
75122
- var memberTable = ts.createSymbolTable();
75123
- var newSymbol = createSymbol(2097152 /* Alias */, "default" /* Default */);
75124
- newSymbol.parent = originalSymbol;
75125
- newSymbol.nameType = getStringLiteralType("default");
75126
- newSymbol.target = resolveSymbol(symbol);
75127
- memberTable.set("default" /* Default */, newSymbol);
75128
75169
  var anonymousSymbol = createSymbol(2048 /* TypeLiteral */, "__type" /* Type */);
75129
- var defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, ts.emptyArray, ts.emptyArray, ts.emptyArray);
75170
+ var defaultContainingObject = createDefaultPropertyWrapperForModule(symbol, originalSymbol, anonymousSymbol);
75130
75171
  anonymousSymbol.type = defaultContainingObject;
75131
75172
  synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*objectFlags*/ 0, /*readonly*/ false) : defaultContainingObject;
75132
75173
  }
@@ -75834,12 +75875,12 @@ var ts;
75834
75875
  var witnesses = getSwitchClauseTypeOfWitnesses(node, /*retainDefault*/ false);
75835
75876
  // notEqualFacts states that the type of the switched value is not equal to every type in the switch.
75836
75877
  var notEqualFacts_1 = getFactsFromTypeofSwitch(0, 0, witnesses, /*hasDefault*/ true);
75837
- var type_4 = getBaseConstraintOfType(operandType) || operandType;
75878
+ var type_5 = getBaseConstraintOfType(operandType) || operandType;
75838
75879
  // Take any/unknown as a special condition. Or maybe we could change `type` to a union containing all primitive types.
75839
- if (type_4.flags & 3 /* AnyOrUnknown */) {
75880
+ if (type_5.flags & 3 /* AnyOrUnknown */) {
75840
75881
  return (556800 /* AllTypeofNE */ & notEqualFacts_1) === 556800 /* AllTypeofNE */;
75841
75882
  }
75842
- return !!(filterType(type_4, function (t) { return (getTypeFacts(t) & notEqualFacts_1) === notEqualFacts_1; }).flags & 131072 /* Never */);
75883
+ return !!(filterType(type_5, function (t) { return (getTypeFacts(t) & notEqualFacts_1) === notEqualFacts_1; }).flags & 131072 /* Never */);
75843
75884
  }
75844
75885
  var type = getTypeOfExpression(node.expression);
75845
75886
  if (!isLiteralType(type)) {
@@ -115651,7 +115692,9 @@ var ts;
115651
115692
  }
115652
115693
  }
115653
115694
  if (options.resolveJsonModule) {
115654
- if (ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeJs) {
115695
+ if (ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeJs &&
115696
+ ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.Node12 &&
115697
+ ts.getEmitModuleResolutionKind(options) !== ts.ModuleResolutionKind.NodeNext) {
115655
115698
  createDiagnosticForOptionName(ts.Diagnostics.Option_resolveJsonModule_cannot_be_specified_without_node_module_resolution_strategy, "resolveJsonModule");
115656
115699
  }
115657
115700
  // Any emit other than common js, amd, es2015 or esnext is error