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.
package/lib/tsserver.js CHANGED
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = "".concat(ts.versionMajorMinor, ".0-dev.20220929");
112
+ ts.version = "".concat(ts.versionMajorMinor, ".0-dev.20220930");
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -49498,6 +49498,12 @@ var ts;
49498
49498
  getOptionalType: function () { return optionalType; },
49499
49499
  getPromiseType: function () { return getGlobalPromiseType(/*reportErrors*/ false); },
49500
49500
  getPromiseLikeType: function () { return getGlobalPromiseLikeType(/*reportErrors*/ false); },
49501
+ getAsyncIterableType: function () {
49502
+ var type = getGlobalAsyncIterableType(/*reportErrors*/ false);
49503
+ if (type === emptyGenericType)
49504
+ return undefined;
49505
+ return type;
49506
+ },
49501
49507
  isSymbolAccessible: isSymbolAccessible,
49502
49508
  isArrayType: isArrayType,
49503
49509
  isTupleType: isTupleType,
@@ -50335,9 +50341,9 @@ var ts;
50335
50341
  return symbol;
50336
50342
  }
50337
50343
  if (symbol.flags & 2097152 /* SymbolFlags.Alias */) {
50338
- var target = resolveAlias(symbol);
50339
- // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors
50340
- if (target === unknownSymbol || target.flags & meaning) {
50344
+ var targetFlags = getAllSymbolFlags(symbol);
50345
+ // `targetFlags` will be `SymbolFlags.All` if an error occurred in alias resolution; this avoids cascading errors
50346
+ if (targetFlags & meaning) {
50341
50347
  return symbol;
50342
50348
  }
50343
50349
  }
@@ -50970,8 +50976,8 @@ var ts;
50970
50976
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
50971
50977
  !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
50972
50978
  !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
50979
+ !checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) &&
50973
50980
  !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) &&
50974
- !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
50975
50981
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
50976
50982
  var suggestion = void 0;
50977
50983
  var suggestedLib = void 0;
@@ -51058,7 +51064,7 @@ var ts;
51058
51064
  }
51059
51065
  }
51060
51066
  if (result && errorLocation && meaning & 111551 /* SymbolFlags.Value */ && result.flags & 2097152 /* SymbolFlags.Alias */ && !(result.flags & 111551 /* SymbolFlags.Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
51061
- var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
51067
+ var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result, 111551 /* SymbolFlags.Value */);
51062
51068
  if (typeOnlyDeclaration) {
51063
51069
  var message = typeOnlyDeclaration.kind === 278 /* SyntaxKind.ExportSpecifier */
51064
51070
  ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
@@ -51221,7 +51227,7 @@ var ts;
51221
51227
  return false;
51222
51228
  }
51223
51229
  function checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) {
51224
- if (meaning & (111551 /* SymbolFlags.Value */ & ~1024 /* SymbolFlags.NamespaceModule */)) {
51230
+ if (meaning & 111551 /* SymbolFlags.Value */) {
51225
51231
  if (isPrimitiveTypeName(name)) {
51226
51232
  if (isExtendedByInterface(errorLocation)) {
51227
51233
  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));
@@ -51232,7 +51238,8 @@ var ts;
51232
51238
  return true;
51233
51239
  }
51234
51240
  var symbol = resolveSymbol(resolveName(errorLocation, name, 788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51235
- if (symbol && !(symbol.flags & 1024 /* SymbolFlags.NamespaceModule */)) {
51241
+ var allFlags = symbol && getAllSymbolFlags(symbol);
51242
+ if (symbol && allFlags !== undefined && !(allFlags & 111551 /* SymbolFlags.Value */)) {
51236
51243
  var rawName = ts.unescapeLeadingUnderscores(name);
51237
51244
  if (isES2015OrLaterConstructorName(name)) {
51238
51245
  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);
@@ -51280,16 +51287,16 @@ var ts;
51280
51287
  }
51281
51288
  return false;
51282
51289
  }
51283
- function checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) {
51284
- if (meaning & (111551 /* SymbolFlags.Value */ & ~1024 /* SymbolFlags.NamespaceModule */ & ~788968 /* SymbolFlags.Type */)) {
51285
- var symbol = resolveSymbol(resolveName(errorLocation, name, 1024 /* SymbolFlags.NamespaceModule */ & ~111551 /* SymbolFlags.Value */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51290
+ function checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) {
51291
+ if (meaning & (111551 /* SymbolFlags.Value */ & ~788968 /* SymbolFlags.Type */)) {
51292
+ var symbol = resolveSymbol(resolveName(errorLocation, name, 1024 /* SymbolFlags.NamespaceModule */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51286
51293
  if (symbol) {
51287
51294
  error(errorLocation, ts.Diagnostics.Cannot_use_namespace_0_as_a_value, ts.unescapeLeadingUnderscores(name));
51288
51295
  return true;
51289
51296
  }
51290
51297
  }
51291
- else if (meaning & (788968 /* SymbolFlags.Type */ & ~1024 /* SymbolFlags.NamespaceModule */ & ~111551 /* SymbolFlags.Value */)) {
51292
- var symbol = resolveSymbol(resolveName(errorLocation, name, (512 /* SymbolFlags.ValueModule */ | 1024 /* SymbolFlags.NamespaceModule */) & ~788968 /* SymbolFlags.Type */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51298
+ else if (meaning & (788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */)) {
51299
+ var symbol = resolveSymbol(resolveName(errorLocation, name, 1536 /* SymbolFlags.Module */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51293
51300
  if (symbol) {
51294
51301
  error(errorLocation, ts.Diagnostics.Cannot_use_namespace_0_as_a_type, ts.unescapeLeadingUnderscores(name));
51295
51302
  return true;
@@ -51879,6 +51886,52 @@ var ts;
51879
51886
  }
51880
51887
  return undefined;
51881
51888
  }
51889
+ /**
51890
+ * Gets combined flags of a `symbol` and all alias targets it resolves to. `resolveAlias`
51891
+ * is typically recursive over chains of aliases, but stops mid-chain if an alias is merged
51892
+ * with another exported symbol, e.g.
51893
+ * ```ts
51894
+ * // a.ts
51895
+ * export const a = 0;
51896
+ * // b.ts
51897
+ * export { a } from "./a";
51898
+ * export type a = number;
51899
+ * // c.ts
51900
+ * import { a } from "./b";
51901
+ * ```
51902
+ * Calling `resolveAlias` on the `a` in c.ts would stop at the merged symbol exported
51903
+ * from b.ts, even though there is still more alias to resolve. Consequently, if we were
51904
+ * trying to determine if the `a` in c.ts has a value meaning, looking at the flags on
51905
+ * the local symbol and on the symbol returned by `resolveAlias` is not enough.
51906
+ * @returns SymbolFlags.All if `symbol` is an alias that ultimately resolves to `unknown`;
51907
+ * combined flags of all alias targets otherwise.
51908
+ */
51909
+ function getAllSymbolFlags(symbol) {
51910
+ var flags = symbol.flags;
51911
+ var seenSymbols;
51912
+ while (symbol.flags & 2097152 /* SymbolFlags.Alias */) {
51913
+ var target = resolveAlias(symbol);
51914
+ if (target === unknownSymbol) {
51915
+ return 67108863 /* SymbolFlags.All */;
51916
+ }
51917
+ // Optimizations - try to avoid creating or adding to
51918
+ // `seenSymbols` if possible
51919
+ if (target === symbol || (seenSymbols === null || seenSymbols === void 0 ? void 0 : seenSymbols.has(target))) {
51920
+ break;
51921
+ }
51922
+ if (target.flags & 2097152 /* SymbolFlags.Alias */) {
51923
+ if (seenSymbols) {
51924
+ seenSymbols.add(target);
51925
+ }
51926
+ else {
51927
+ seenSymbols = new ts.Set([symbol, target]);
51928
+ }
51929
+ }
51930
+ flags |= target.flags;
51931
+ symbol = target;
51932
+ }
51933
+ return flags;
51934
+ }
51882
51935
  /**
51883
51936
  * Marks a symbol as type-only if its declaration is syntactically type-only.
51884
51937
  * If it is not itself marked type-only, but resolves to a type-only alias
@@ -51924,19 +51977,25 @@ var ts;
51924
51977
  return !!aliasDeclarationLinks.typeOnlyDeclaration;
51925
51978
  }
51926
51979
  /** Indicates that a symbol directly or indirectly resolves to a type-only import or export. */
51927
- function getTypeOnlyAliasDeclaration(symbol) {
51980
+ function getTypeOnlyAliasDeclaration(symbol, include) {
51928
51981
  if (!(symbol.flags & 2097152 /* SymbolFlags.Alias */)) {
51929
51982
  return undefined;
51930
51983
  }
51931
51984
  var links = getSymbolLinks(symbol);
51932
- return links.typeOnlyDeclaration || undefined;
51985
+ if (include === undefined) {
51986
+ return links.typeOnlyDeclaration || undefined;
51987
+ }
51988
+ if (links.typeOnlyDeclaration) {
51989
+ return getAllSymbolFlags(resolveAlias(links.typeOnlyDeclaration.symbol)) & include ? links.typeOnlyDeclaration : undefined;
51990
+ }
51991
+ return undefined;
51933
51992
  }
51934
51993
  function markExportAsReferenced(node) {
51935
51994
  var symbol = getSymbolOfNode(node);
51936
51995
  var target = resolveAlias(symbol);
51937
51996
  if (target) {
51938
51997
  var markAlias = target === unknownSymbol ||
51939
- ((target.flags & 111551 /* SymbolFlags.Value */) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol));
51998
+ ((getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */));
51940
51999
  if (markAlias) {
51941
52000
  markAliasSymbolAsReferenced(symbol);
51942
52001
  }
@@ -51956,8 +52015,7 @@ var ts;
51956
52015
  // This way a chain of imports can be elided if ultimately the final input is only used in a type
51957
52016
  // position.
51958
52017
  if (ts.isInternalModuleImportEqualsDeclaration(node)) {
51959
- var target = resolveSymbol(symbol);
51960
- if (target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
52018
+ if (getAllSymbolFlags(resolveSymbol(symbol)) & 111551 /* SymbolFlags.Value */) {
51961
52019
  // import foo = <symbol>
51962
52020
  checkExpressionCached(node.moduleReference);
51963
52021
  }
@@ -52779,7 +52837,7 @@ var ts;
52779
52837
  }
52780
52838
  function symbolIsValue(symbol, includeTypeOnlyMembers) {
52781
52839
  return !!(symbol.flags & 111551 /* SymbolFlags.Value */ ||
52782
- symbol.flags & 2097152 /* SymbolFlags.Alias */ && resolveAlias(symbol).flags & 111551 /* SymbolFlags.Value */ && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
52840
+ symbol.flags & 2097152 /* SymbolFlags.Alias */ && getAllSymbolFlags(symbol) & 111551 /* SymbolFlags.Value */ && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
52783
52841
  }
52784
52842
  function findConstructorDeclaration(node) {
52785
52843
  var members = node.members;
@@ -53048,8 +53106,10 @@ var ts;
53048
53106
  return true;
53049
53107
  }
53050
53108
  // Qualify if the symbol from symbol table has same meaning as expected
53051
- symbolFromSymbolTable = (symbolFromSymbolTable.flags & 2097152 /* SymbolFlags.Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 278 /* SyntaxKind.ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
53052
- if (symbolFromSymbolTable.flags & meaning) {
53109
+ var shouldResolveAlias = (symbolFromSymbolTable.flags & 2097152 /* SymbolFlags.Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 278 /* SyntaxKind.ExportSpecifier */));
53110
+ symbolFromSymbolTable = shouldResolveAlias ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
53111
+ var flags = shouldResolveAlias ? getAllSymbolFlags(symbolFromSymbolTable) : symbolFromSymbolTable.flags;
53112
+ if (flags & meaning) {
53053
53113
  qualify = true;
53054
53114
  return true;
53055
53115
  }
@@ -55706,7 +55766,7 @@ var ts;
55706
55766
  return !symbol.exports ? [] : ts.filter(ts.arrayFrom(symbol.exports.values()), isNamespaceMember);
55707
55767
  }
55708
55768
  function isTypeOnlyNamespace(symbol) {
55709
- return ts.every(getNamespaceMembersForSerialization(symbol), function (m) { return !(resolveSymbol(m).flags & 111551 /* SymbolFlags.Value */); });
55769
+ return ts.every(getNamespaceMembersForSerialization(symbol), function (m) { return !(getAllSymbolFlags(resolveSymbol(m)) & 111551 /* SymbolFlags.Value */); });
55710
55770
  }
55711
55771
  function serializeModule(symbol, symbolName, modifierFlags) {
55712
55772
  var members = getNamespaceMembersForSerialization(symbol);
@@ -57926,7 +57986,7 @@ var ts;
57926
57986
  links.type = (exportSymbol === null || exportSymbol === void 0 ? void 0 : exportSymbol.declarations) && isDuplicatedCommonJSExport(exportSymbol.declarations) && symbol.declarations.length ? getFlowTypeFromCommonJSExport(exportSymbol)
57927
57987
  : isDuplicatedCommonJSExport(symbol.declarations) ? autoType
57928
57988
  : declaredType ? declaredType
57929
- : targetSymbol.flags & 111551 /* SymbolFlags.Value */ ? getTypeOfSymbol(targetSymbol)
57989
+ : getAllSymbolFlags(targetSymbol) & 111551 /* SymbolFlags.Value */ ? getTypeOfSymbol(targetSymbol)
57930
57990
  : errorType;
57931
57991
  }
57932
57992
  return links.type;
@@ -60279,7 +60339,7 @@ var ts;
60279
60339
  var indexTypes;
60280
60340
  var isUnion = containingType.flags & 1048576 /* TypeFlags.Union */;
60281
60341
  // Flags we want to propagate to the result if they exist in all source symbols
60282
- var optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */;
60342
+ var optionalFlag;
60283
60343
  var syntheticFlag = 4 /* CheckFlags.SyntheticMethod */;
60284
60344
  var checkFlags = isUnion ? 0 : 8 /* CheckFlags.Readonly */;
60285
60345
  var mergedInstantiations = false;
@@ -60290,11 +60350,14 @@ var ts;
60290
60350
  var prop = getPropertyOfType(type, name, skipObjectFunctionPropertyAugment);
60291
60351
  var modifiers = prop ? ts.getDeclarationModifierFlagsFromSymbol(prop) : 0;
60292
60352
  if (prop) {
60293
- if (isUnion) {
60294
- optionalFlag |= (prop.flags & 16777216 /* SymbolFlags.Optional */);
60295
- }
60296
- else {
60297
- optionalFlag &= prop.flags;
60353
+ if (prop.flags & 106500 /* SymbolFlags.ClassMember */) {
60354
+ optionalFlag !== null && optionalFlag !== void 0 ? optionalFlag : (optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */);
60355
+ if (isUnion) {
60356
+ optionalFlag |= (prop.flags & 16777216 /* SymbolFlags.Optional */);
60357
+ }
60358
+ else {
60359
+ optionalFlag &= prop.flags;
60360
+ }
60298
60361
  }
60299
60362
  if (!singleProp) {
60300
60363
  singleProp = prop;
@@ -60413,7 +60476,7 @@ var ts;
60413
60476
  propTypes.push(type);
60414
60477
  }
60415
60478
  ts.addRange(propTypes, indexTypes);
60416
- var result = createSymbol(4 /* SymbolFlags.Property */ | optionalFlag, name, syntheticFlag | checkFlags);
60479
+ var result = createSymbol(4 /* SymbolFlags.Property */ | (optionalFlag !== null && optionalFlag !== void 0 ? optionalFlag : 0), name, syntheticFlag | checkFlags);
60417
60480
  result.containingType = containingType;
60418
60481
  if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
60419
60482
  result.valueDeclaration = firstValueDeclaration;
@@ -67680,7 +67743,7 @@ var ts;
67680
67743
  return 0 /* Ternary.False */;
67681
67744
  }
67682
67745
  // When checking for comparability, be more lenient with optional properties.
67683
- if (!skipOptional && sourceProp.flags & 16777216 /* SymbolFlags.Optional */ && !(targetProp.flags & 16777216 /* SymbolFlags.Optional */)) {
67746
+ if (!skipOptional && sourceProp.flags & 16777216 /* SymbolFlags.Optional */ && targetProp.flags & 106500 /* SymbolFlags.ClassMember */ && !(targetProp.flags & 16777216 /* SymbolFlags.Optional */)) {
67684
67747
  // TypeScript 1.0 spec (April 2014): 3.8.3
67685
67748
  // S is a subtype of a type T, and T is a supertype of S if ...
67686
67749
  // S' and T are object types and, for each member M in T..
@@ -72952,9 +73015,9 @@ var ts;
72952
73015
  });
72953
73016
  }
72954
73017
  function markAliasReferenced(symbol, location) {
72955
- if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol)) {
73018
+ if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */)) {
72956
73019
  var target = resolveAlias(symbol);
72957
- if (target.flags & 111551 /* SymbolFlags.Value */) {
73020
+ if (getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
72958
73021
  // An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
72959
73022
  // (because the const enum value will not be inlined), or if (2) the alias is an export
72960
73023
  // of a const enum declaration that will be preserved.
@@ -78846,7 +78909,7 @@ var ts;
78846
78909
  if (symbol && symbol.flags & 2097152 /* SymbolFlags.Alias */) {
78847
78910
  symbol = resolveAlias(symbol);
78848
78911
  }
78849
- return !!(symbol && (symbol.flags & 384 /* SymbolFlags.Enum */) && getEnumKind(symbol) === 1 /* EnumKind.Literal */);
78912
+ return !!(symbol && (getAllSymbolFlags(symbol) & 384 /* SymbolFlags.Enum */) && getEnumKind(symbol) === 1 /* EnumKind.Literal */);
78850
78913
  }
78851
78914
  return false;
78852
78915
  }
@@ -85021,7 +85084,16 @@ var ts;
85021
85084
  var message = allowAsyncIterables
85022
85085
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
85023
85086
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
85024
- return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
85087
+ var suggestAwait =
85088
+ // for (const x of Promise<...>) or [...Promise<...>]
85089
+ !!getAwaitedTypeOfPromise(type)
85090
+ // for (const x of AsyncIterable<...>)
85091
+ || (!allowAsyncIterables &&
85092
+ ts.isForOfStatement(errorNode.parent) &&
85093
+ errorNode.parent.expression === errorNode &&
85094
+ getGlobalAsyncIterableType(/** reportErrors */ false) !== emptyGenericType &&
85095
+ isTypeAssignableTo(type, getGlobalAsyncIterableType(/** reportErrors */ false)));
85096
+ return errorAndMaybeSuggestAwait(errorNode, suggestAwait, message, typeToString(type));
85025
85097
  }
85026
85098
  /**
85027
85099
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
@@ -86872,10 +86944,11 @@ var ts;
86872
86944
  }
86873
86945
  return;
86874
86946
  }
86947
+ var targetFlags = getAllSymbolFlags(target);
86875
86948
  var excludedMeanings = (symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */) ? 111551 /* SymbolFlags.Value */ : 0) |
86876
86949
  (symbol.flags & 788968 /* SymbolFlags.Type */ ? 788968 /* SymbolFlags.Type */ : 0) |
86877
86950
  (symbol.flags & 1920 /* SymbolFlags.Namespace */ ? 1920 /* SymbolFlags.Namespace */ : 0);
86878
- if (target.flags & excludedMeanings) {
86951
+ if (targetFlags & excludedMeanings) {
86879
86952
  var message = node.kind === 278 /* SyntaxKind.ExportSpecifier */ ?
86880
86953
  ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
86881
86954
  ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
@@ -86885,7 +86958,7 @@ var ts;
86885
86958
  && !ts.isTypeOnlyImportOrExportDeclaration(node)
86886
86959
  && !(node.flags & 16777216 /* NodeFlags.Ambient */)) {
86887
86960
  var typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
86888
- var isType = !(target.flags & 111551 /* SymbolFlags.Value */);
86961
+ var isType = !(targetFlags & 111551 /* SymbolFlags.Value */);
86889
86962
  if (isType || typeOnlyAlias) {
86890
86963
  switch (node.kind) {
86891
86964
  case 270 /* SyntaxKind.ImportClause */:
@@ -87045,14 +87118,15 @@ var ts;
87045
87118
  if (node.moduleReference.kind !== 280 /* SyntaxKind.ExternalModuleReference */) {
87046
87119
  var target = resolveAlias(getSymbolOfNode(node));
87047
87120
  if (target !== unknownSymbol) {
87048
- if (target.flags & 111551 /* SymbolFlags.Value */) {
87121
+ var targetFlags = getAllSymbolFlags(target);
87122
+ if (targetFlags & 111551 /* SymbolFlags.Value */) {
87049
87123
  // Target is a value symbol, check that it is not hidden by a local declaration with the same name
87050
87124
  var moduleName = ts.getFirstIdentifier(node.moduleReference);
87051
87125
  if (!(resolveEntityName(moduleName, 111551 /* SymbolFlags.Value */ | 1920 /* SymbolFlags.Namespace */).flags & 1920 /* SymbolFlags.Namespace */)) {
87052
87126
  error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName));
87053
87127
  }
87054
87128
  }
87055
- if (target.flags & 788968 /* SymbolFlags.Type */) {
87129
+ if (targetFlags & 788968 /* SymbolFlags.Type */) {
87056
87130
  checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0);
87057
87131
  }
87058
87132
  }
@@ -87191,7 +87265,7 @@ var ts;
87191
87265
  markExportAsReferenced(node);
87192
87266
  }
87193
87267
  var target = symbol && (symbol.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(symbol) : symbol);
87194
- if (!target || target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
87268
+ if (!target || getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
87195
87269
  checkExpressionCached(node.propertyName || node.name);
87196
87270
  }
87197
87271
  }
@@ -87238,7 +87312,7 @@ var ts;
87238
87312
  markAliasReferenced(sym, id);
87239
87313
  // If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
87240
87314
  var target = sym.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(sym) : sym;
87241
- if (target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
87315
+ if (getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
87242
87316
  // However if it is a value, we need to check it's being used correctly
87243
87317
  checkExpressionCached(node.expression);
87244
87318
  }
@@ -88560,7 +88634,7 @@ var ts;
88560
88634
  return symbolLinks.exportsSomeValue;
88561
88635
  function isValue(s) {
88562
88636
  s = resolveSymbol(s);
88563
- return s && !!(s.flags & 111551 /* SymbolFlags.Value */);
88637
+ return s && !!(getAllSymbolFlags(s) & 111551 /* SymbolFlags.Value */);
88564
88638
  }
88565
88639
  }
88566
88640
  function isNameOfModuleOrEnumDeclaration(node) {
@@ -88613,7 +88687,7 @@ var ts;
88613
88687
  var symbol = getReferencedValueOrAliasSymbol(node);
88614
88688
  // We should only get the declaration of an alias if there isn't a local value
88615
88689
  // declaration for the symbol
88616
- if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !getTypeOnlyAliasDeclaration(symbol)) {
88690
+ if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */)) {
88617
88691
  return getDeclarationOfAliasSymbol(symbol);
88618
88692
  }
88619
88693
  }
@@ -88701,7 +88775,7 @@ var ts;
88701
88775
  case 273 /* SyntaxKind.ImportSpecifier */:
88702
88776
  case 278 /* SyntaxKind.ExportSpecifier */:
88703
88777
  var symbol = getSymbolOfNode(node);
88704
- return !!symbol && isAliasResolvedToValue(symbol) && !getTypeOnlyAliasDeclaration(symbol);
88778
+ return !!symbol && isAliasResolvedToValue(symbol) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */);
88705
88779
  case 275 /* SyntaxKind.ExportDeclaration */:
88706
88780
  var exportClause = node.exportClause;
88707
88781
  return !!exportClause && (ts.isNamespaceExport(exportClause) ||
@@ -88723,6 +88797,7 @@ var ts;
88723
88797
  return isValue && node.moduleReference && !ts.nodeIsMissing(node.moduleReference);
88724
88798
  }
88725
88799
  function isAliasResolvedToValue(symbol) {
88800
+ var _a;
88726
88801
  if (!symbol) {
88727
88802
  return false;
88728
88803
  }
@@ -88732,7 +88807,7 @@ var ts;
88732
88807
  }
88733
88808
  // const enums and modules that contain only const enums are not considered values from the emit perspective
88734
88809
  // unless 'preserveConstEnums' option is set to true
88735
- return !!(target.flags & 111551 /* SymbolFlags.Value */) &&
88810
+ return !!(((_a = getAllSymbolFlags(target)) !== null && _a !== void 0 ? _a : -1) & 111551 /* SymbolFlags.Value */) &&
88736
88811
  (ts.shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target));
88737
88812
  }
88738
88813
  function isConstEnumOrConstEnumOnlyModule(s) {
@@ -88747,7 +88822,7 @@ var ts;
88747
88822
  }
88748
88823
  var target = getSymbolLinks(symbol).aliasTarget; // TODO: GH#18217
88749
88824
  if (target && ts.getEffectiveModifierFlags(node) & 1 /* ModifierFlags.Export */ &&
88750
- target.flags & 111551 /* SymbolFlags.Value */ &&
88825
+ getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */ &&
88751
88826
  (ts.shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target))) {
88752
88827
  // An `export import ... =` of a value symbol is always considered referenced
88753
88828
  return true;
@@ -128784,6 +128859,12 @@ var ts;
128784
128859
  SemanticClassificationFormat["Original"] = "original";
128785
128860
  SemanticClassificationFormat["TwentyTwenty"] = "2020";
128786
128861
  })(SemanticClassificationFormat = ts.SemanticClassificationFormat || (ts.SemanticClassificationFormat = {}));
128862
+ var OrganizeImportsMode;
128863
+ (function (OrganizeImportsMode) {
128864
+ OrganizeImportsMode["All"] = "All";
128865
+ OrganizeImportsMode["SortAndCombine"] = "SortAndCombine";
128866
+ OrganizeImportsMode["RemoveUnused"] = "RemoveUnused";
128867
+ })(OrganizeImportsMode = ts.OrganizeImportsMode || (ts.OrganizeImportsMode = {}));
128787
128868
  var CompletionTriggerKind;
128788
128869
  (function (CompletionTriggerKind) {
128789
128870
  /** Completion was triggered by typing an identifier, manual invocation (e.g Ctrl+Space) or via API. */
@@ -144539,23 +144620,39 @@ var ts;
144539
144620
  * 2) Coalescing imports from the same module
144540
144621
  * 3) Sorting imports
144541
144622
  */
144542
- function organizeImports(sourceFile, formatContext, host, program, preferences, skipDestructiveCodeActions) {
144623
+ function organizeImports(sourceFile, formatContext, host, program, preferences, mode) {
144543
144624
  var changeTracker = ts.textChanges.ChangeTracker.fromContext({ host: host, formatContext: formatContext, preferences: preferences });
144544
- var coalesceAndOrganizeImports = function (importGroup) { return ts.stableSort(coalesceImports(removeUnusedImports(importGroup, sourceFile, program, skipDestructiveCodeActions)), function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); }); };
144625
+ var shouldSort = mode === "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ || mode === "All" /* OrganizeImportsMode.All */;
144626
+ var shouldCombine = shouldSort; // These are currently inseparable, but I draw a distinction for clarity and in case we add modes in the future.
144627
+ var shouldRemove = mode === "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */ || mode === "All" /* OrganizeImportsMode.All */;
144628
+ var maybeRemove = shouldRemove ? removeUnusedImports : ts.identity;
144629
+ var maybeCoalesce = shouldCombine ? coalesceImports : ts.identity;
144630
+ var processImportsOfSameModuleSpecifier = function (importGroup) {
144631
+ var processedDeclarations = maybeCoalesce(maybeRemove(importGroup, sourceFile, program));
144632
+ return shouldSort
144633
+ ? ts.stableSort(processedDeclarations, function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); })
144634
+ : processedDeclarations;
144635
+ };
144545
144636
  // All of the old ImportDeclarations in the file, in syntactic order.
144546
144637
  var topLevelImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, sourceFile.statements.filter(ts.isImportDeclaration));
144547
- topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
144548
- // All of the old ExportDeclarations in the file, in syntactic order.
144549
- var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
144550
- organizeImportsWorker(topLevelExportDecls, coalesceExports);
144638
+ topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier); });
144639
+ // Exports are always used
144640
+ if (mode !== "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */) {
144641
+ // All of the old ExportDeclarations in the file, in syntactic order.
144642
+ var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
144643
+ organizeImportsWorker(topLevelExportDecls, coalesceExports);
144644
+ }
144551
144645
  for (var _i = 0, _a = sourceFile.statements.filter(ts.isAmbientModule); _i < _a.length; _i++) {
144552
144646
  var ambientModule = _a[_i];
144553
144647
  if (!ambientModule.body)
144554
144648
  continue;
144555
144649
  var ambientModuleImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, ambientModule.body.statements.filter(ts.isImportDeclaration));
144556
- ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
144557
- var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
144558
- organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
144650
+ ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier); });
144651
+ // Exports are always used
144652
+ if (mode !== "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */) {
144653
+ var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
144654
+ organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
144655
+ }
144559
144656
  }
144560
144657
  return changeTracker.getChanges();
144561
144658
  function organizeImportsWorker(oldImportDecls, coalesce) {
@@ -144568,8 +144665,12 @@ var ts;
144568
144665
  // Consider: we could do a more careful check that this trivia is actually a header,
144569
144666
  // but the consequences of being wrong are very minor.
144570
144667
  ts.suppressLeadingTrivia(oldImportDecls[0]);
144571
- var oldImportGroups = ts.group(oldImportDecls, function (importDecl) { return getExternalModuleName(importDecl.moduleSpecifier); });
144572
- var sortedImportGroups = ts.stableSort(oldImportGroups, function (group1, group2) { return compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier); });
144668
+ var oldImportGroups = shouldCombine
144669
+ ? ts.group(oldImportDecls, function (importDecl) { return getExternalModuleName(importDecl.moduleSpecifier); })
144670
+ : [oldImportDecls];
144671
+ var sortedImportGroups = shouldSort
144672
+ ? ts.stableSort(oldImportGroups, function (group1, group2) { return compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier); })
144673
+ : oldImportGroups;
144573
144674
  var newImportDecls = ts.flatMap(sortedImportGroups, function (importGroup) {
144574
144675
  return getExternalModuleName(importGroup[0].moduleSpecifier)
144575
144676
  ? coalesce(importGroup)
@@ -144633,11 +144734,7 @@ var ts;
144633
144734
  }
144634
144735
  return false;
144635
144736
  }
144636
- function removeUnusedImports(oldImports, sourceFile, program, skipDestructiveCodeActions) {
144637
- // As a precaution, consider unused import detection to be destructive (GH #43051)
144638
- if (skipDestructiveCodeActions) {
144639
- return oldImports;
144640
- }
144737
+ function removeUnusedImports(oldImports, sourceFile, program) {
144641
144738
  var typeChecker = program.getTypeChecker();
144642
144739
  var compilerOptions = program.getCompilerOptions();
144643
144740
  var jsxNamespace = typeChecker.getJsxNamespace(sourceFile);
@@ -153670,6 +153767,15 @@ var ts;
153670
153767
  });
153671
153768
  }
153672
153769
  function makeChange(changeTracker, errorCode, sourceFile, checker, insertionSite, fixedDeclarations) {
153770
+ if (ts.isForOfStatement(insertionSite.parent) && !insertionSite.parent.awaitModifier) {
153771
+ var exprType = checker.getTypeAtLocation(insertionSite);
153772
+ var asyncIter = checker.getAsyncIterableType();
153773
+ if (asyncIter && checker.isTypeAssignableTo(exprType, asyncIter)) {
153774
+ var forOf = insertionSite.parent;
153775
+ changeTracker.replaceNode(sourceFile, forOf, ts.factory.updateForOfStatement(forOf, ts.factory.createToken(133 /* SyntaxKind.AwaitKeyword */), forOf.initializer, forOf.expression, forOf.statement));
153776
+ return;
153777
+ }
153778
+ }
153673
153779
  if (ts.isBinaryExpression(insertionSite)) {
153674
153780
  for (var _i = 0, _a = [insertionSite.left, insertionSite.right]; _i < _a.length; _i++) {
153675
153781
  var side = _a[_i];
@@ -169025,12 +169131,14 @@ var ts;
169025
169131
  return ts.codefix.getAllFixes({ fixId: fixId, sourceFile: sourceFile, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences });
169026
169132
  }
169027
169133
  function organizeImports(args, formatOptions, preferences) {
169134
+ var _a;
169028
169135
  if (preferences === void 0) { preferences = ts.emptyOptions; }
169029
169136
  synchronizeHostData();
169030
169137
  ts.Debug.assert(args.type === "file");
169031
169138
  var sourceFile = getValidSourceFile(args.fileName);
169032
169139
  var formatContext = ts.formatting.getFormatContext(formatOptions, host);
169033
- return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences, args.skipDestructiveCodeActions);
169140
+ var mode = (_a = args.mode) !== null && _a !== void 0 ? _a : (args.skipDestructiveCodeActions ? "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ : "All" /* OrganizeImportsMode.All */);
169141
+ return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences, mode);
169034
169142
  }
169035
169143
  function getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) {
169036
169144
  if (preferences === void 0) { preferences = ts.emptyOptions; }
@@ -172029,6 +172137,12 @@ var ts;
172029
172137
  CommandTypes["ProvideInlayHints"] = "provideInlayHints";
172030
172138
  // NOTE: If updating this, be sure to also update `allCommandNames` in `testRunner/unittests/tsserver/session.ts`.
172031
172139
  })(CommandTypes = protocol.CommandTypes || (protocol.CommandTypes = {}));
172140
+ var OrganizeImportsMode;
172141
+ (function (OrganizeImportsMode) {
172142
+ OrganizeImportsMode["All"] = "All";
172143
+ OrganizeImportsMode["SortAndCombine"] = "SortAndCombine";
172144
+ OrganizeImportsMode["RemoveUnused"] = "RemoveUnused";
172145
+ })(OrganizeImportsMode = protocol.OrganizeImportsMode || (protocol.OrganizeImportsMode = {}));
172032
172146
  var WatchFileKind;
172033
172147
  (function (WatchFileKind) {
172034
172148
  WatchFileKind["FixedPollingInterval"] = "FixedPollingInterval";
@@ -181192,11 +181306,12 @@ var ts;
181192
181306
  }
181193
181307
  };
181194
181308
  Session.prototype.organizeImports = function (args, simplifiedResult) {
181309
+ var _a;
181195
181310
  ts.Debug.assert(args.scope.type === "file");
181196
- var _a = this.getFileAndProject(args.scope.args), file = _a.file, project = _a.project;
181311
+ var _b = this.getFileAndProject(args.scope.args), file = _b.file, project = _b.project;
181197
181312
  var changes = project.getLanguageService().organizeImports({
181198
181313
  fileName: file,
181199
- skipDestructiveCodeActions: args.skipDestructiveCodeActions,
181314
+ mode: (_a = args.mode) !== null && _a !== void 0 ? _a : (args.skipDestructiveCodeActions ? "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ : undefined),
181200
181315
  type: "file",
181201
181316
  }, this.getFormatOptions(file), this.getPreferences(file));
181202
181317
  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 {
@@ -7616,9 +7623,16 @@ declare namespace ts.server.protocol {
7616
7623
  arguments: OrganizeImportsRequestArgs;
7617
7624
  }
7618
7625
  type OrganizeImportsScope = GetCombinedCodeFixScope;
7626
+ enum OrganizeImportsMode {
7627
+ All = "All",
7628
+ SortAndCombine = "SortAndCombine",
7629
+ RemoveUnused = "RemoveUnused"
7630
+ }
7619
7631
  interface OrganizeImportsRequestArgs {
7620
7632
  scope: OrganizeImportsScope;
7633
+ /** @deprecated Use `mode` instead */
7621
7634
  skipDestructiveCodeActions?: boolean;
7635
+ mode?: OrganizeImportsMode;
7622
7636
  }
7623
7637
  interface OrganizeImportsResponse extends Response {
7624
7638
  body: readonly FileCodeEdits[];