typescript 4.9.0-dev.20220929 → 4.9.0-dev.20220930

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.
@@ -108,7 +108,7 @@ var ts;
108
108
  // The following is baselined as a literal template type without intervention
109
109
  /** The version of the TypeScript compiler release */
110
110
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
111
- ts.version = "".concat(ts.versionMajorMinor, ".0-dev.20220929");
111
+ ts.version = "".concat(ts.versionMajorMinor, ".0-dev.20220930");
112
112
  /* @internal */
113
113
  var Comparison;
114
114
  (function (Comparison) {
@@ -49497,6 +49497,12 @@ var ts;
49497
49497
  getOptionalType: function () { return optionalType; },
49498
49498
  getPromiseType: function () { return getGlobalPromiseType(/*reportErrors*/ false); },
49499
49499
  getPromiseLikeType: function () { return getGlobalPromiseLikeType(/*reportErrors*/ false); },
49500
+ getAsyncIterableType: function () {
49501
+ var type = getGlobalAsyncIterableType(/*reportErrors*/ false);
49502
+ if (type === emptyGenericType)
49503
+ return undefined;
49504
+ return type;
49505
+ },
49500
49506
  isSymbolAccessible: isSymbolAccessible,
49501
49507
  isArrayType: isArrayType,
49502
49508
  isTupleType: isTupleType,
@@ -50334,9 +50340,9 @@ var ts;
50334
50340
  return symbol;
50335
50341
  }
50336
50342
  if (symbol.flags & 2097152 /* SymbolFlags.Alias */) {
50337
- var target = resolveAlias(symbol);
50338
- // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors
50339
- if (target === unknownSymbol || target.flags & meaning) {
50343
+ var targetFlags = getAllSymbolFlags(symbol);
50344
+ // `targetFlags` will be `SymbolFlags.All` if an error occurred in alias resolution; this avoids cascading errors
50345
+ if (targetFlags & meaning) {
50340
50346
  return symbol;
50341
50347
  }
50342
50348
  }
@@ -50969,8 +50975,8 @@ var ts;
50969
50975
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
50970
50976
  !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
50971
50977
  !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
50978
+ !checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) &&
50972
50979
  !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) &&
50973
- !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
50974
50980
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
50975
50981
  var suggestion = void 0;
50976
50982
  var suggestedLib = void 0;
@@ -51057,7 +51063,7 @@ var ts;
51057
51063
  }
51058
51064
  }
51059
51065
  if (result && errorLocation && meaning & 111551 /* SymbolFlags.Value */ && result.flags & 2097152 /* SymbolFlags.Alias */ && !(result.flags & 111551 /* SymbolFlags.Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
51060
- var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
51066
+ var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result, 111551 /* SymbolFlags.Value */);
51061
51067
  if (typeOnlyDeclaration) {
51062
51068
  var message = typeOnlyDeclaration.kind === 278 /* SyntaxKind.ExportSpecifier */
51063
51069
  ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
@@ -51220,7 +51226,7 @@ var ts;
51220
51226
  return false;
51221
51227
  }
51222
51228
  function checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) {
51223
- if (meaning & (111551 /* SymbolFlags.Value */ & ~1024 /* SymbolFlags.NamespaceModule */)) {
51229
+ if (meaning & 111551 /* SymbolFlags.Value */) {
51224
51230
  if (isPrimitiveTypeName(name)) {
51225
51231
  if (isExtendedByInterface(errorLocation)) {
51226
51232
  error(errorLocation, ts.Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_classes, ts.unescapeLeadingUnderscores(name));
@@ -51231,7 +51237,8 @@ var ts;
51231
51237
  return true;
51232
51238
  }
51233
51239
  var symbol = resolveSymbol(resolveName(errorLocation, name, 788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51234
- if (symbol && !(symbol.flags & 1024 /* SymbolFlags.NamespaceModule */)) {
51240
+ var allFlags = symbol && getAllSymbolFlags(symbol);
51241
+ if (symbol && allFlags !== undefined && !(allFlags & 111551 /* SymbolFlags.Value */)) {
51235
51242
  var rawName = ts.unescapeLeadingUnderscores(name);
51236
51243
  if (isES2015OrLaterConstructorName(name)) {
51237
51244
  error(errorLocation, ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later, rawName);
@@ -51279,16 +51286,16 @@ var ts;
51279
51286
  }
51280
51287
  return false;
51281
51288
  }
51282
- function checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) {
51283
- if (meaning & (111551 /* SymbolFlags.Value */ & ~1024 /* SymbolFlags.NamespaceModule */ & ~788968 /* SymbolFlags.Type */)) {
51284
- var symbol = resolveSymbol(resolveName(errorLocation, name, 1024 /* SymbolFlags.NamespaceModule */ & ~111551 /* SymbolFlags.Value */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51289
+ function checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) {
51290
+ if (meaning & (111551 /* SymbolFlags.Value */ & ~788968 /* SymbolFlags.Type */)) {
51291
+ var symbol = resolveSymbol(resolveName(errorLocation, name, 1024 /* SymbolFlags.NamespaceModule */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51285
51292
  if (symbol) {
51286
51293
  error(errorLocation, ts.Diagnostics.Cannot_use_namespace_0_as_a_value, ts.unescapeLeadingUnderscores(name));
51287
51294
  return true;
51288
51295
  }
51289
51296
  }
51290
- else if (meaning & (788968 /* SymbolFlags.Type */ & ~1024 /* SymbolFlags.NamespaceModule */ & ~111551 /* SymbolFlags.Value */)) {
51291
- var symbol = resolveSymbol(resolveName(errorLocation, name, (512 /* SymbolFlags.ValueModule */ | 1024 /* SymbolFlags.NamespaceModule */) & ~788968 /* SymbolFlags.Type */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51297
+ else if (meaning & (788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */)) {
51298
+ var symbol = resolveSymbol(resolveName(errorLocation, name, 1536 /* SymbolFlags.Module */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51292
51299
  if (symbol) {
51293
51300
  error(errorLocation, ts.Diagnostics.Cannot_use_namespace_0_as_a_type, ts.unescapeLeadingUnderscores(name));
51294
51301
  return true;
@@ -51878,6 +51885,52 @@ var ts;
51878
51885
  }
51879
51886
  return undefined;
51880
51887
  }
51888
+ /**
51889
+ * Gets combined flags of a `symbol` and all alias targets it resolves to. `resolveAlias`
51890
+ * is typically recursive over chains of aliases, but stops mid-chain if an alias is merged
51891
+ * with another exported symbol, e.g.
51892
+ * ```ts
51893
+ * // a.ts
51894
+ * export const a = 0;
51895
+ * // b.ts
51896
+ * export { a } from "./a";
51897
+ * export type a = number;
51898
+ * // c.ts
51899
+ * import { a } from "./b";
51900
+ * ```
51901
+ * Calling `resolveAlias` on the `a` in c.ts would stop at the merged symbol exported
51902
+ * from b.ts, even though there is still more alias to resolve. Consequently, if we were
51903
+ * trying to determine if the `a` in c.ts has a value meaning, looking at the flags on
51904
+ * the local symbol and on the symbol returned by `resolveAlias` is not enough.
51905
+ * @returns SymbolFlags.All if `symbol` is an alias that ultimately resolves to `unknown`;
51906
+ * combined flags of all alias targets otherwise.
51907
+ */
51908
+ function getAllSymbolFlags(symbol) {
51909
+ var flags = symbol.flags;
51910
+ var seenSymbols;
51911
+ while (symbol.flags & 2097152 /* SymbolFlags.Alias */) {
51912
+ var target = resolveAlias(symbol);
51913
+ if (target === unknownSymbol) {
51914
+ return 67108863 /* SymbolFlags.All */;
51915
+ }
51916
+ // Optimizations - try to avoid creating or adding to
51917
+ // `seenSymbols` if possible
51918
+ if (target === symbol || (seenSymbols === null || seenSymbols === void 0 ? void 0 : seenSymbols.has(target))) {
51919
+ break;
51920
+ }
51921
+ if (target.flags & 2097152 /* SymbolFlags.Alias */) {
51922
+ if (seenSymbols) {
51923
+ seenSymbols.add(target);
51924
+ }
51925
+ else {
51926
+ seenSymbols = new ts.Set([symbol, target]);
51927
+ }
51928
+ }
51929
+ flags |= target.flags;
51930
+ symbol = target;
51931
+ }
51932
+ return flags;
51933
+ }
51881
51934
  /**
51882
51935
  * Marks a symbol as type-only if its declaration is syntactically type-only.
51883
51936
  * If it is not itself marked type-only, but resolves to a type-only alias
@@ -51923,19 +51976,25 @@ var ts;
51923
51976
  return !!aliasDeclarationLinks.typeOnlyDeclaration;
51924
51977
  }
51925
51978
  /** Indicates that a symbol directly or indirectly resolves to a type-only import or export. */
51926
- function getTypeOnlyAliasDeclaration(symbol) {
51979
+ function getTypeOnlyAliasDeclaration(symbol, include) {
51927
51980
  if (!(symbol.flags & 2097152 /* SymbolFlags.Alias */)) {
51928
51981
  return undefined;
51929
51982
  }
51930
51983
  var links = getSymbolLinks(symbol);
51931
- return links.typeOnlyDeclaration || undefined;
51984
+ if (include === undefined) {
51985
+ return links.typeOnlyDeclaration || undefined;
51986
+ }
51987
+ if (links.typeOnlyDeclaration) {
51988
+ return getAllSymbolFlags(resolveAlias(links.typeOnlyDeclaration.symbol)) & include ? links.typeOnlyDeclaration : undefined;
51989
+ }
51990
+ return undefined;
51932
51991
  }
51933
51992
  function markExportAsReferenced(node) {
51934
51993
  var symbol = getSymbolOfNode(node);
51935
51994
  var target = resolveAlias(symbol);
51936
51995
  if (target) {
51937
51996
  var markAlias = target === unknownSymbol ||
51938
- ((target.flags & 111551 /* SymbolFlags.Value */) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol));
51997
+ ((getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */));
51939
51998
  if (markAlias) {
51940
51999
  markAliasSymbolAsReferenced(symbol);
51941
52000
  }
@@ -51955,8 +52014,7 @@ var ts;
51955
52014
  // This way a chain of imports can be elided if ultimately the final input is only used in a type
51956
52015
  // position.
51957
52016
  if (ts.isInternalModuleImportEqualsDeclaration(node)) {
51958
- var target = resolveSymbol(symbol);
51959
- if (target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
52017
+ if (getAllSymbolFlags(resolveSymbol(symbol)) & 111551 /* SymbolFlags.Value */) {
51960
52018
  // import foo = <symbol>
51961
52019
  checkExpressionCached(node.moduleReference);
51962
52020
  }
@@ -52778,7 +52836,7 @@ var ts;
52778
52836
  }
52779
52837
  function symbolIsValue(symbol, includeTypeOnlyMembers) {
52780
52838
  return !!(symbol.flags & 111551 /* SymbolFlags.Value */ ||
52781
- symbol.flags & 2097152 /* SymbolFlags.Alias */ && resolveAlias(symbol).flags & 111551 /* SymbolFlags.Value */ && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
52839
+ symbol.flags & 2097152 /* SymbolFlags.Alias */ && getAllSymbolFlags(symbol) & 111551 /* SymbolFlags.Value */ && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
52782
52840
  }
52783
52841
  function findConstructorDeclaration(node) {
52784
52842
  var members = node.members;
@@ -53047,8 +53105,10 @@ var ts;
53047
53105
  return true;
53048
53106
  }
53049
53107
  // Qualify if the symbol from symbol table has same meaning as expected
53050
- symbolFromSymbolTable = (symbolFromSymbolTable.flags & 2097152 /* SymbolFlags.Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 278 /* SyntaxKind.ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
53051
- if (symbolFromSymbolTable.flags & meaning) {
53108
+ var shouldResolveAlias = (symbolFromSymbolTable.flags & 2097152 /* SymbolFlags.Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 278 /* SyntaxKind.ExportSpecifier */));
53109
+ symbolFromSymbolTable = shouldResolveAlias ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
53110
+ var flags = shouldResolveAlias ? getAllSymbolFlags(symbolFromSymbolTable) : symbolFromSymbolTable.flags;
53111
+ if (flags & meaning) {
53052
53112
  qualify = true;
53053
53113
  return true;
53054
53114
  }
@@ -55705,7 +55765,7 @@ var ts;
55705
55765
  return !symbol.exports ? [] : ts.filter(ts.arrayFrom(symbol.exports.values()), isNamespaceMember);
55706
55766
  }
55707
55767
  function isTypeOnlyNamespace(symbol) {
55708
- return ts.every(getNamespaceMembersForSerialization(symbol), function (m) { return !(resolveSymbol(m).flags & 111551 /* SymbolFlags.Value */); });
55768
+ return ts.every(getNamespaceMembersForSerialization(symbol), function (m) { return !(getAllSymbolFlags(resolveSymbol(m)) & 111551 /* SymbolFlags.Value */); });
55709
55769
  }
55710
55770
  function serializeModule(symbol, symbolName, modifierFlags) {
55711
55771
  var members = getNamespaceMembersForSerialization(symbol);
@@ -57925,7 +57985,7 @@ var ts;
57925
57985
  links.type = (exportSymbol === null || exportSymbol === void 0 ? void 0 : exportSymbol.declarations) && isDuplicatedCommonJSExport(exportSymbol.declarations) && symbol.declarations.length ? getFlowTypeFromCommonJSExport(exportSymbol)
57926
57986
  : isDuplicatedCommonJSExport(symbol.declarations) ? autoType
57927
57987
  : declaredType ? declaredType
57928
- : targetSymbol.flags & 111551 /* SymbolFlags.Value */ ? getTypeOfSymbol(targetSymbol)
57988
+ : getAllSymbolFlags(targetSymbol) & 111551 /* SymbolFlags.Value */ ? getTypeOfSymbol(targetSymbol)
57929
57989
  : errorType;
57930
57990
  }
57931
57991
  return links.type;
@@ -60278,7 +60338,7 @@ var ts;
60278
60338
  var indexTypes;
60279
60339
  var isUnion = containingType.flags & 1048576 /* TypeFlags.Union */;
60280
60340
  // Flags we want to propagate to the result if they exist in all source symbols
60281
- var optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */;
60341
+ var optionalFlag;
60282
60342
  var syntheticFlag = 4 /* CheckFlags.SyntheticMethod */;
60283
60343
  var checkFlags = isUnion ? 0 : 8 /* CheckFlags.Readonly */;
60284
60344
  var mergedInstantiations = false;
@@ -60289,11 +60349,14 @@ var ts;
60289
60349
  var prop = getPropertyOfType(type, name, skipObjectFunctionPropertyAugment);
60290
60350
  var modifiers = prop ? ts.getDeclarationModifierFlagsFromSymbol(prop) : 0;
60291
60351
  if (prop) {
60292
- if (isUnion) {
60293
- optionalFlag |= (prop.flags & 16777216 /* SymbolFlags.Optional */);
60294
- }
60295
- else {
60296
- optionalFlag &= prop.flags;
60352
+ if (prop.flags & 106500 /* SymbolFlags.ClassMember */) {
60353
+ optionalFlag !== null && optionalFlag !== void 0 ? optionalFlag : (optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */);
60354
+ if (isUnion) {
60355
+ optionalFlag |= (prop.flags & 16777216 /* SymbolFlags.Optional */);
60356
+ }
60357
+ else {
60358
+ optionalFlag &= prop.flags;
60359
+ }
60297
60360
  }
60298
60361
  if (!singleProp) {
60299
60362
  singleProp = prop;
@@ -60412,7 +60475,7 @@ var ts;
60412
60475
  propTypes.push(type);
60413
60476
  }
60414
60477
  ts.addRange(propTypes, indexTypes);
60415
- var result = createSymbol(4 /* SymbolFlags.Property */ | optionalFlag, name, syntheticFlag | checkFlags);
60478
+ var result = createSymbol(4 /* SymbolFlags.Property */ | (optionalFlag !== null && optionalFlag !== void 0 ? optionalFlag : 0), name, syntheticFlag | checkFlags);
60416
60479
  result.containingType = containingType;
60417
60480
  if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
60418
60481
  result.valueDeclaration = firstValueDeclaration;
@@ -67679,7 +67742,7 @@ var ts;
67679
67742
  return 0 /* Ternary.False */;
67680
67743
  }
67681
67744
  // When checking for comparability, be more lenient with optional properties.
67682
- if (!skipOptional && sourceProp.flags & 16777216 /* SymbolFlags.Optional */ && !(targetProp.flags & 16777216 /* SymbolFlags.Optional */)) {
67745
+ if (!skipOptional && sourceProp.flags & 16777216 /* SymbolFlags.Optional */ && targetProp.flags & 106500 /* SymbolFlags.ClassMember */ && !(targetProp.flags & 16777216 /* SymbolFlags.Optional */)) {
67683
67746
  // TypeScript 1.0 spec (April 2014): 3.8.3
67684
67747
  // S is a subtype of a type T, and T is a supertype of S if ...
67685
67748
  // S' and T are object types and, for each member M in T..
@@ -72951,9 +73014,9 @@ var ts;
72951
73014
  });
72952
73015
  }
72953
73016
  function markAliasReferenced(symbol, location) {
72954
- if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol)) {
73017
+ if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */)) {
72955
73018
  var target = resolveAlias(symbol);
72956
- if (target.flags & 111551 /* SymbolFlags.Value */) {
73019
+ if (getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
72957
73020
  // An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
72958
73021
  // (because the const enum value will not be inlined), or if (2) the alias is an export
72959
73022
  // of a const enum declaration that will be preserved.
@@ -78845,7 +78908,7 @@ var ts;
78845
78908
  if (symbol && symbol.flags & 2097152 /* SymbolFlags.Alias */) {
78846
78909
  symbol = resolveAlias(symbol);
78847
78910
  }
78848
- return !!(symbol && (symbol.flags & 384 /* SymbolFlags.Enum */) && getEnumKind(symbol) === 1 /* EnumKind.Literal */);
78911
+ return !!(symbol && (getAllSymbolFlags(symbol) & 384 /* SymbolFlags.Enum */) && getEnumKind(symbol) === 1 /* EnumKind.Literal */);
78849
78912
  }
78850
78913
  return false;
78851
78914
  }
@@ -85020,7 +85083,16 @@ var ts;
85020
85083
  var message = allowAsyncIterables
85021
85084
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
85022
85085
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
85023
- return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
85086
+ var suggestAwait =
85087
+ // for (const x of Promise<...>) or [...Promise<...>]
85088
+ !!getAwaitedTypeOfPromise(type)
85089
+ // for (const x of AsyncIterable<...>)
85090
+ || (!allowAsyncIterables &&
85091
+ ts.isForOfStatement(errorNode.parent) &&
85092
+ errorNode.parent.expression === errorNode &&
85093
+ getGlobalAsyncIterableType(/** reportErrors */ false) !== emptyGenericType &&
85094
+ isTypeAssignableTo(type, getGlobalAsyncIterableType(/** reportErrors */ false)));
85095
+ return errorAndMaybeSuggestAwait(errorNode, suggestAwait, message, typeToString(type));
85024
85096
  }
85025
85097
  /**
85026
85098
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
@@ -86871,10 +86943,11 @@ var ts;
86871
86943
  }
86872
86944
  return;
86873
86945
  }
86946
+ var targetFlags = getAllSymbolFlags(target);
86874
86947
  var excludedMeanings = (symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */) ? 111551 /* SymbolFlags.Value */ : 0) |
86875
86948
  (symbol.flags & 788968 /* SymbolFlags.Type */ ? 788968 /* SymbolFlags.Type */ : 0) |
86876
86949
  (symbol.flags & 1920 /* SymbolFlags.Namespace */ ? 1920 /* SymbolFlags.Namespace */ : 0);
86877
- if (target.flags & excludedMeanings) {
86950
+ if (targetFlags & excludedMeanings) {
86878
86951
  var message = node.kind === 278 /* SyntaxKind.ExportSpecifier */ ?
86879
86952
  ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
86880
86953
  ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
@@ -86884,7 +86957,7 @@ var ts;
86884
86957
  && !ts.isTypeOnlyImportOrExportDeclaration(node)
86885
86958
  && !(node.flags & 16777216 /* NodeFlags.Ambient */)) {
86886
86959
  var typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
86887
- var isType = !(target.flags & 111551 /* SymbolFlags.Value */);
86960
+ var isType = !(targetFlags & 111551 /* SymbolFlags.Value */);
86888
86961
  if (isType || typeOnlyAlias) {
86889
86962
  switch (node.kind) {
86890
86963
  case 270 /* SyntaxKind.ImportClause */:
@@ -87044,14 +87117,15 @@ var ts;
87044
87117
  if (node.moduleReference.kind !== 280 /* SyntaxKind.ExternalModuleReference */) {
87045
87118
  var target = resolveAlias(getSymbolOfNode(node));
87046
87119
  if (target !== unknownSymbol) {
87047
- if (target.flags & 111551 /* SymbolFlags.Value */) {
87120
+ var targetFlags = getAllSymbolFlags(target);
87121
+ if (targetFlags & 111551 /* SymbolFlags.Value */) {
87048
87122
  // Target is a value symbol, check that it is not hidden by a local declaration with the same name
87049
87123
  var moduleName = ts.getFirstIdentifier(node.moduleReference);
87050
87124
  if (!(resolveEntityName(moduleName, 111551 /* SymbolFlags.Value */ | 1920 /* SymbolFlags.Namespace */).flags & 1920 /* SymbolFlags.Namespace */)) {
87051
87125
  error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName));
87052
87126
  }
87053
87127
  }
87054
- if (target.flags & 788968 /* SymbolFlags.Type */) {
87128
+ if (targetFlags & 788968 /* SymbolFlags.Type */) {
87055
87129
  checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0);
87056
87130
  }
87057
87131
  }
@@ -87190,7 +87264,7 @@ var ts;
87190
87264
  markExportAsReferenced(node);
87191
87265
  }
87192
87266
  var target = symbol && (symbol.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(symbol) : symbol);
87193
- if (!target || target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
87267
+ if (!target || getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
87194
87268
  checkExpressionCached(node.propertyName || node.name);
87195
87269
  }
87196
87270
  }
@@ -87237,7 +87311,7 @@ var ts;
87237
87311
  markAliasReferenced(sym, id);
87238
87312
  // If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
87239
87313
  var target = sym.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(sym) : sym;
87240
- if (target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
87314
+ if (getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
87241
87315
  // However if it is a value, we need to check it's being used correctly
87242
87316
  checkExpressionCached(node.expression);
87243
87317
  }
@@ -88559,7 +88633,7 @@ var ts;
88559
88633
  return symbolLinks.exportsSomeValue;
88560
88634
  function isValue(s) {
88561
88635
  s = resolveSymbol(s);
88562
- return s && !!(s.flags & 111551 /* SymbolFlags.Value */);
88636
+ return s && !!(getAllSymbolFlags(s) & 111551 /* SymbolFlags.Value */);
88563
88637
  }
88564
88638
  }
88565
88639
  function isNameOfModuleOrEnumDeclaration(node) {
@@ -88612,7 +88686,7 @@ var ts;
88612
88686
  var symbol = getReferencedValueOrAliasSymbol(node);
88613
88687
  // We should only get the declaration of an alias if there isn't a local value
88614
88688
  // declaration for the symbol
88615
- if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !getTypeOnlyAliasDeclaration(symbol)) {
88689
+ if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */)) {
88616
88690
  return getDeclarationOfAliasSymbol(symbol);
88617
88691
  }
88618
88692
  }
@@ -88700,7 +88774,7 @@ var ts;
88700
88774
  case 273 /* SyntaxKind.ImportSpecifier */:
88701
88775
  case 278 /* SyntaxKind.ExportSpecifier */:
88702
88776
  var symbol = getSymbolOfNode(node);
88703
- return !!symbol && isAliasResolvedToValue(symbol) && !getTypeOnlyAliasDeclaration(symbol);
88777
+ return !!symbol && isAliasResolvedToValue(symbol) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */);
88704
88778
  case 275 /* SyntaxKind.ExportDeclaration */:
88705
88779
  var exportClause = node.exportClause;
88706
88780
  return !!exportClause && (ts.isNamespaceExport(exportClause) ||
@@ -88722,6 +88796,7 @@ var ts;
88722
88796
  return isValue && node.moduleReference && !ts.nodeIsMissing(node.moduleReference);
88723
88797
  }
88724
88798
  function isAliasResolvedToValue(symbol) {
88799
+ var _a;
88725
88800
  if (!symbol) {
88726
88801
  return false;
88727
88802
  }
@@ -88731,7 +88806,7 @@ var ts;
88731
88806
  }
88732
88807
  // const enums and modules that contain only const enums are not considered values from the emit perspective
88733
88808
  // unless 'preserveConstEnums' option is set to true
88734
- return !!(target.flags & 111551 /* SymbolFlags.Value */) &&
88809
+ return !!(((_a = getAllSymbolFlags(target)) !== null && _a !== void 0 ? _a : -1) & 111551 /* SymbolFlags.Value */) &&
88735
88810
  (ts.shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target));
88736
88811
  }
88737
88812
  function isConstEnumOrConstEnumOnlyModule(s) {
@@ -88746,7 +88821,7 @@ var ts;
88746
88821
  }
88747
88822
  var target = getSymbolLinks(symbol).aliasTarget; // TODO: GH#18217
88748
88823
  if (target && ts.getEffectiveModifierFlags(node) & 1 /* ModifierFlags.Export */ &&
88749
- target.flags & 111551 /* SymbolFlags.Value */ &&
88824
+ getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */ &&
88750
88825
  (ts.shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target))) {
88751
88826
  // An `export import ... =` of a value symbol is always considered referenced
88752
88827
  return true;
@@ -129202,6 +129277,12 @@ var ts;
129202
129277
  SemanticClassificationFormat["Original"] = "original";
129203
129278
  SemanticClassificationFormat["TwentyTwenty"] = "2020";
129204
129279
  })(SemanticClassificationFormat = ts.SemanticClassificationFormat || (ts.SemanticClassificationFormat = {}));
129280
+ var OrganizeImportsMode;
129281
+ (function (OrganizeImportsMode) {
129282
+ OrganizeImportsMode["All"] = "All";
129283
+ OrganizeImportsMode["SortAndCombine"] = "SortAndCombine";
129284
+ OrganizeImportsMode["RemoveUnused"] = "RemoveUnused";
129285
+ })(OrganizeImportsMode = ts.OrganizeImportsMode || (ts.OrganizeImportsMode = {}));
129205
129286
  var CompletionTriggerKind;
129206
129287
  (function (CompletionTriggerKind) {
129207
129288
  /** Completion was triggered by typing an identifier, manual invocation (e.g Ctrl+Space) or via API. */
@@ -144957,23 +145038,39 @@ var ts;
144957
145038
  * 2) Coalescing imports from the same module
144958
145039
  * 3) Sorting imports
144959
145040
  */
144960
- function organizeImports(sourceFile, formatContext, host, program, preferences, skipDestructiveCodeActions) {
145041
+ function organizeImports(sourceFile, formatContext, host, program, preferences, mode) {
144961
145042
  var changeTracker = ts.textChanges.ChangeTracker.fromContext({ host: host, formatContext: formatContext, preferences: preferences });
144962
- var coalesceAndOrganizeImports = function (importGroup) { return ts.stableSort(coalesceImports(removeUnusedImports(importGroup, sourceFile, program, skipDestructiveCodeActions)), function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); }); };
145043
+ var shouldSort = mode === "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ || mode === "All" /* OrganizeImportsMode.All */;
145044
+ var shouldCombine = shouldSort; // These are currently inseparable, but I draw a distinction for clarity and in case we add modes in the future.
145045
+ var shouldRemove = mode === "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */ || mode === "All" /* OrganizeImportsMode.All */;
145046
+ var maybeRemove = shouldRemove ? removeUnusedImports : ts.identity;
145047
+ var maybeCoalesce = shouldCombine ? coalesceImports : ts.identity;
145048
+ var processImportsOfSameModuleSpecifier = function (importGroup) {
145049
+ var processedDeclarations = maybeCoalesce(maybeRemove(importGroup, sourceFile, program));
145050
+ return shouldSort
145051
+ ? ts.stableSort(processedDeclarations, function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); })
145052
+ : processedDeclarations;
145053
+ };
144963
145054
  // All of the old ImportDeclarations in the file, in syntactic order.
144964
145055
  var topLevelImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, sourceFile.statements.filter(ts.isImportDeclaration));
144965
- topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
144966
- // All of the old ExportDeclarations in the file, in syntactic order.
144967
- var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
144968
- organizeImportsWorker(topLevelExportDecls, coalesceExports);
145056
+ topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier); });
145057
+ // Exports are always used
145058
+ if (mode !== "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */) {
145059
+ // All of the old ExportDeclarations in the file, in syntactic order.
145060
+ var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
145061
+ organizeImportsWorker(topLevelExportDecls, coalesceExports);
145062
+ }
144969
145063
  for (var _i = 0, _a = sourceFile.statements.filter(ts.isAmbientModule); _i < _a.length; _i++) {
144970
145064
  var ambientModule = _a[_i];
144971
145065
  if (!ambientModule.body)
144972
145066
  continue;
144973
145067
  var ambientModuleImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, ambientModule.body.statements.filter(ts.isImportDeclaration));
144974
- ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
144975
- var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
144976
- organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
145068
+ ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier); });
145069
+ // Exports are always used
145070
+ if (mode !== "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */) {
145071
+ var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
145072
+ organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
145073
+ }
144977
145074
  }
144978
145075
  return changeTracker.getChanges();
144979
145076
  function organizeImportsWorker(oldImportDecls, coalesce) {
@@ -144986,8 +145083,12 @@ var ts;
144986
145083
  // Consider: we could do a more careful check that this trivia is actually a header,
144987
145084
  // but the consequences of being wrong are very minor.
144988
145085
  ts.suppressLeadingTrivia(oldImportDecls[0]);
144989
- var oldImportGroups = ts.group(oldImportDecls, function (importDecl) { return getExternalModuleName(importDecl.moduleSpecifier); });
144990
- var sortedImportGroups = ts.stableSort(oldImportGroups, function (group1, group2) { return compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier); });
145086
+ var oldImportGroups = shouldCombine
145087
+ ? ts.group(oldImportDecls, function (importDecl) { return getExternalModuleName(importDecl.moduleSpecifier); })
145088
+ : [oldImportDecls];
145089
+ var sortedImportGroups = shouldSort
145090
+ ? ts.stableSort(oldImportGroups, function (group1, group2) { return compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier); })
145091
+ : oldImportGroups;
144991
145092
  var newImportDecls = ts.flatMap(sortedImportGroups, function (importGroup) {
144992
145093
  return getExternalModuleName(importGroup[0].moduleSpecifier)
144993
145094
  ? coalesce(importGroup)
@@ -145051,11 +145152,7 @@ var ts;
145051
145152
  }
145052
145153
  return false;
145053
145154
  }
145054
- function removeUnusedImports(oldImports, sourceFile, program, skipDestructiveCodeActions) {
145055
- // As a precaution, consider unused import detection to be destructive (GH #43051)
145056
- if (skipDestructiveCodeActions) {
145057
- return oldImports;
145058
- }
145155
+ function removeUnusedImports(oldImports, sourceFile, program) {
145059
145156
  var typeChecker = program.getTypeChecker();
145060
145157
  var compilerOptions = program.getCompilerOptions();
145061
145158
  var jsxNamespace = typeChecker.getJsxNamespace(sourceFile);
@@ -154088,6 +154185,15 @@ var ts;
154088
154185
  });
154089
154186
  }
154090
154187
  function makeChange(changeTracker, errorCode, sourceFile, checker, insertionSite, fixedDeclarations) {
154188
+ if (ts.isForOfStatement(insertionSite.parent) && !insertionSite.parent.awaitModifier) {
154189
+ var exprType = checker.getTypeAtLocation(insertionSite);
154190
+ var asyncIter = checker.getAsyncIterableType();
154191
+ if (asyncIter && checker.isTypeAssignableTo(exprType, asyncIter)) {
154192
+ var forOf = insertionSite.parent;
154193
+ changeTracker.replaceNode(sourceFile, forOf, ts.factory.updateForOfStatement(forOf, ts.factory.createToken(133 /* SyntaxKind.AwaitKeyword */), forOf.initializer, forOf.expression, forOf.statement));
154194
+ return;
154195
+ }
154196
+ }
154091
154197
  if (ts.isBinaryExpression(insertionSite)) {
154092
154198
  for (var _i = 0, _a = [insertionSite.left, insertionSite.right]; _i < _a.length; _i++) {
154093
154199
  var side = _a[_i];
@@ -169443,12 +169549,14 @@ var ts;
169443
169549
  return ts.codefix.getAllFixes({ fixId: fixId, sourceFile: sourceFile, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences });
169444
169550
  }
169445
169551
  function organizeImports(args, formatOptions, preferences) {
169552
+ var _a;
169446
169553
  if (preferences === void 0) { preferences = ts.emptyOptions; }
169447
169554
  synchronizeHostData();
169448
169555
  ts.Debug.assert(args.type === "file");
169449
169556
  var sourceFile = getValidSourceFile(args.fileName);
169450
169557
  var formatContext = ts.formatting.getFormatContext(formatOptions, host);
169451
- return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences, args.skipDestructiveCodeActions);
169558
+ var mode = (_a = args.mode) !== null && _a !== void 0 ? _a : (args.skipDestructiveCodeActions ? "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ : "All" /* OrganizeImportsMode.All */);
169559
+ return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences, mode);
169452
169560
  }
169453
169561
  function getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) {
169454
169562
  if (preferences === void 0) { preferences = ts.emptyOptions; }
@@ -172028,6 +172136,12 @@ var ts;
172028
172136
  CommandTypes["ProvideInlayHints"] = "provideInlayHints";
172029
172137
  // NOTE: If updating this, be sure to also update `allCommandNames` in `testRunner/unittests/tsserver/session.ts`.
172030
172138
  })(CommandTypes = protocol.CommandTypes || (protocol.CommandTypes = {}));
172139
+ var OrganizeImportsMode;
172140
+ (function (OrganizeImportsMode) {
172141
+ OrganizeImportsMode["All"] = "All";
172142
+ OrganizeImportsMode["SortAndCombine"] = "SortAndCombine";
172143
+ OrganizeImportsMode["RemoveUnused"] = "RemoveUnused";
172144
+ })(OrganizeImportsMode = protocol.OrganizeImportsMode || (protocol.OrganizeImportsMode = {}));
172031
172145
  var WatchFileKind;
172032
172146
  (function (WatchFileKind) {
172033
172147
  WatchFileKind["FixedPollingInterval"] = "FixedPollingInterval";
@@ -181191,11 +181305,12 @@ var ts;
181191
181305
  }
181192
181306
  };
181193
181307
  Session.prototype.organizeImports = function (args, simplifiedResult) {
181308
+ var _a;
181194
181309
  ts.Debug.assert(args.scope.type === "file");
181195
- var _a = this.getFileAndProject(args.scope.args), file = _a.file, project = _a.project;
181310
+ var _b = this.getFileAndProject(args.scope.args), file = _b.file, project = _b.project;
181196
181311
  var changes = project.getLanguageService().organizeImports({
181197
181312
  fileName: file,
181198
- skipDestructiveCodeActions: args.skipDestructiveCodeActions,
181313
+ mode: (_a = args.mode) !== null && _a !== void 0 ? _a : (args.skipDestructiveCodeActions ? "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ : undefined),
181199
181314
  type: "file",
181200
181315
  }, this.getFormatOptions(file), this.getPreferences(file));
181201
181316
  if (simplifiedResult) {
@@ -6032,8 +6032,15 @@ declare namespace ts {
6032
6032
  type: "file";
6033
6033
  fileName: string;
6034
6034
  }
6035
+ enum OrganizeImportsMode {
6036
+ All = "All",
6037
+ SortAndCombine = "SortAndCombine",
6038
+ RemoveUnused = "RemoveUnused"
6039
+ }
6035
6040
  interface OrganizeImportsArgs extends CombinedCodeFixScope {
6041
+ /** @deprecated Use `mode` instead */
6036
6042
  skipDestructiveCodeActions?: boolean;
6043
+ mode?: OrganizeImportsMode;
6037
6044
  }
6038
6045
  type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#" | " ";
6039
6046
  enum CompletionTriggerKind {