typescript 4.9.0-dev.20220928 → 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/typescript.js CHANGED
@@ -99,7 +99,7 @@ var ts;
99
99
  // The following is baselined as a literal template type without intervention
100
100
  /** The version of the TypeScript compiler release */
101
101
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
102
- ts.version = "".concat(ts.versionMajorMinor, ".0-dev.20220928");
102
+ ts.version = "".concat(ts.versionMajorMinor, ".0-dev.20220930");
103
103
  /* @internal */
104
104
  var Comparison;
105
105
  (function (Comparison) {
@@ -3205,11 +3205,13 @@ var ts;
3205
3205
  // > alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers
3206
3206
  // > MUST NOT include leading zeroes.
3207
3207
  var prereleaseRegExp = /^(?:0|[1-9]\d*|[a-z-][a-z0-9-]*)(?:\.(?:0|[1-9]\d*|[a-z-][a-z0-9-]*))*$/i;
3208
+ var prereleasePartRegExp = /^(?:0|[1-9]\d*|[a-z-][a-z0-9-]*)$/i;
3208
3209
  // https://semver.org/#spec-item-10
3209
3210
  // > Build metadata MAY be denoted by appending a plus sign and a series of dot separated
3210
3211
  // > identifiers immediately following the patch or pre-release version. Identifiers MUST
3211
3212
  // > comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty.
3212
3213
  var buildRegExp = /^[a-z0-9-]+(?:\.[a-z0-9-]+)*$/i;
3214
+ var buildPartRegExp = /^[a-z0-9-]+$/i;
3213
3215
  // https://semver.org/#spec-item-9
3214
3216
  // > Numeric identifiers MUST NOT include leading zeroes.
3215
3217
  var numericIdentifierRegExp = /^(0|[1-9]\d*)$/;
@@ -3229,13 +3231,15 @@ var ts;
3229
3231
  ts.Debug.assert(major >= 0, "Invalid argument: major");
3230
3232
  ts.Debug.assert(minor >= 0, "Invalid argument: minor");
3231
3233
  ts.Debug.assert(patch >= 0, "Invalid argument: patch");
3232
- ts.Debug.assert(!prerelease || prereleaseRegExp.test(prerelease), "Invalid argument: prerelease");
3233
- ts.Debug.assert(!build || buildRegExp.test(build), "Invalid argument: build");
3234
+ var prereleaseArray = prerelease ? ts.isArray(prerelease) ? prerelease : prerelease.split(".") : ts.emptyArray;
3235
+ var buildArray = build ? ts.isArray(build) ? build : build.split(".") : ts.emptyArray;
3236
+ ts.Debug.assert(ts.every(prereleaseArray, function (s) { return prereleasePartRegExp.test(s); }), "Invalid argument: prerelease");
3237
+ ts.Debug.assert(ts.every(buildArray, function (s) { return buildPartRegExp.test(s); }), "Invalid argument: build");
3234
3238
  this.major = major;
3235
3239
  this.minor = minor;
3236
3240
  this.patch = patch;
3237
- this.prerelease = prerelease ? prerelease.split(".") : ts.emptyArray;
3238
- this.build = build ? build.split(".") : ts.emptyArray;
3241
+ this.prerelease = prereleaseArray;
3242
+ this.build = buildArray;
3239
3243
  }
3240
3244
  Version.tryParse = function (text) {
3241
3245
  var result = tryParseComponents(text);
@@ -3274,6 +3278,10 @@ var ts;
3274
3278
  default: return ts.Debug.assertNever(field);
3275
3279
  }
3276
3280
  };
3281
+ Version.prototype.with = function (fields) {
3282
+ var _a = fields.major, major = _a === void 0 ? this.major : _a, _b = fields.minor, minor = _b === void 0 ? this.minor : _b, _c = fields.patch, patch = _c === void 0 ? this.patch : _c, _d = fields.prerelease, prerelease = _d === void 0 ? this.prerelease : _d, _e = fields.build, build = _e === void 0 ? this.build : _e;
3283
+ return new Version(major, minor, patch, prerelease, build);
3284
+ };
3277
3285
  Version.prototype.toString = function () {
3278
3286
  var result = "".concat(this.major, ".").concat(this.minor, ".").concat(this.patch);
3279
3287
  if (ts.some(this.prerelease))
@@ -3282,7 +3290,7 @@ var ts;
3282
3290
  result += "+".concat(this.build.join("."));
3283
3291
  return result;
3284
3292
  };
3285
- Version.zero = new Version(0, 0, 0);
3293
+ Version.zero = new Version(0, 0, 0, ["0"]);
3286
3294
  return Version;
3287
3295
  }());
3288
3296
  ts.Version = Version;
@@ -3365,6 +3373,10 @@ var ts;
3365
3373
  }
3366
3374
  return undefined;
3367
3375
  };
3376
+ /**
3377
+ * Tests whether a version matches the range. This is equivalent to `satisfies(version, range, { includePrerelease: true })`.
3378
+ * in `node-semver`.
3379
+ */
3368
3380
  VersionRange.prototype.test = function (version) {
3369
3381
  if (typeof version === "string")
3370
3382
  version = new Version(version);
@@ -3475,19 +3487,20 @@ var ts;
3475
3487
  break;
3476
3488
  case "<":
3477
3489
  case ">=":
3478
- comparators.push(createComparator(operator, version));
3490
+ comparators.push(isWildcard(minor) || isWildcard(patch) ? createComparator(operator, version.with({ prerelease: "0" })) :
3491
+ createComparator(operator, version));
3479
3492
  break;
3480
3493
  case "<=":
3481
3494
  case ">":
3482
- comparators.push(isWildcard(minor) ? createComparator(operator === "<=" ? "<" : ">=", version.increment("major")) :
3483
- isWildcard(patch) ? createComparator(operator === "<=" ? "<" : ">=", version.increment("minor")) :
3495
+ comparators.push(isWildcard(minor) ? createComparator(operator === "<=" ? "<" : ">=", version.increment("major").with({ prerelease: "0" })) :
3496
+ isWildcard(patch) ? createComparator(operator === "<=" ? "<" : ">=", version.increment("minor").with({ prerelease: "0" })) :
3484
3497
  createComparator(operator, version));
3485
3498
  break;
3486
3499
  case "=":
3487
3500
  case undefined:
3488
3501
  if (isWildcard(minor) || isWildcard(patch)) {
3489
- comparators.push(createComparator(">=", version));
3490
- comparators.push(createComparator("<", version.increment(isWildcard(minor) ? "major" : "minor")));
3502
+ comparators.push(createComparator(">=", version.with({ prerelease: "0" })));
3503
+ comparators.push(createComparator("<", version.increment(isWildcard(minor) ? "major" : "minor").with({ prerelease: "0" })));
3491
3504
  }
3492
3505
  else {
3493
3506
  comparators.push(createComparator("=", version));
@@ -49475,6 +49488,12 @@ var ts;
49475
49488
  getOptionalType: function () { return optionalType; },
49476
49489
  getPromiseType: function () { return getGlobalPromiseType(/*reportErrors*/ false); },
49477
49490
  getPromiseLikeType: function () { return getGlobalPromiseLikeType(/*reportErrors*/ false); },
49491
+ getAsyncIterableType: function () {
49492
+ var type = getGlobalAsyncIterableType(/*reportErrors*/ false);
49493
+ if (type === emptyGenericType)
49494
+ return undefined;
49495
+ return type;
49496
+ },
49478
49497
  isSymbolAccessible: isSymbolAccessible,
49479
49498
  isArrayType: isArrayType,
49480
49499
  isTupleType: isTupleType,
@@ -50312,9 +50331,9 @@ var ts;
50312
50331
  return symbol;
50313
50332
  }
50314
50333
  if (symbol.flags & 2097152 /* SymbolFlags.Alias */) {
50315
- var target = resolveAlias(symbol);
50316
- // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors
50317
- if (target === unknownSymbol || target.flags & meaning) {
50334
+ var targetFlags = getAllSymbolFlags(symbol);
50335
+ // `targetFlags` will be `SymbolFlags.All` if an error occurred in alias resolution; this avoids cascading errors
50336
+ if (targetFlags & meaning) {
50318
50337
  return symbol;
50319
50338
  }
50320
50339
  }
@@ -50947,8 +50966,8 @@ var ts;
50947
50966
  !checkAndReportErrorForExtendingInterface(errorLocation) &&
50948
50967
  !checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
50949
50968
  !checkAndReportErrorForExportingPrimitiveType(errorLocation, name) &&
50969
+ !checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) &&
50950
50970
  !checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) &&
50951
- !checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
50952
50971
  !checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
50953
50972
  var suggestion = void 0;
50954
50973
  var suggestedLib = void 0;
@@ -51035,7 +51054,7 @@ var ts;
51035
51054
  }
51036
51055
  }
51037
51056
  if (result && errorLocation && meaning & 111551 /* SymbolFlags.Value */ && result.flags & 2097152 /* SymbolFlags.Alias */ && !(result.flags & 111551 /* SymbolFlags.Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
51038
- var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
51057
+ var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result, 111551 /* SymbolFlags.Value */);
51039
51058
  if (typeOnlyDeclaration) {
51040
51059
  var message = typeOnlyDeclaration.kind === 278 /* SyntaxKind.ExportSpecifier */
51041
51060
  ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
@@ -51198,7 +51217,7 @@ var ts;
51198
51217
  return false;
51199
51218
  }
51200
51219
  function checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) {
51201
- if (meaning & (111551 /* SymbolFlags.Value */ & ~1024 /* SymbolFlags.NamespaceModule */)) {
51220
+ if (meaning & 111551 /* SymbolFlags.Value */) {
51202
51221
  if (isPrimitiveTypeName(name)) {
51203
51222
  if (isExtendedByInterface(errorLocation)) {
51204
51223
  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));
@@ -51209,7 +51228,8 @@ var ts;
51209
51228
  return true;
51210
51229
  }
51211
51230
  var symbol = resolveSymbol(resolveName(errorLocation, name, 788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51212
- if (symbol && !(symbol.flags & 1024 /* SymbolFlags.NamespaceModule */)) {
51231
+ var allFlags = symbol && getAllSymbolFlags(symbol);
51232
+ if (symbol && allFlags !== undefined && !(allFlags & 111551 /* SymbolFlags.Value */)) {
51213
51233
  var rawName = ts.unescapeLeadingUnderscores(name);
51214
51234
  if (isES2015OrLaterConstructorName(name)) {
51215
51235
  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);
@@ -51257,16 +51277,16 @@ var ts;
51257
51277
  }
51258
51278
  return false;
51259
51279
  }
51260
- function checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) {
51261
- if (meaning & (111551 /* SymbolFlags.Value */ & ~1024 /* SymbolFlags.NamespaceModule */ & ~788968 /* SymbolFlags.Type */)) {
51262
- var symbol = resolveSymbol(resolveName(errorLocation, name, 1024 /* SymbolFlags.NamespaceModule */ & ~111551 /* SymbolFlags.Value */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51280
+ function checkAndReportErrorForUsingNamespaceAsTypeOrValue(errorLocation, name, meaning) {
51281
+ if (meaning & (111551 /* SymbolFlags.Value */ & ~788968 /* SymbolFlags.Type */)) {
51282
+ var symbol = resolveSymbol(resolveName(errorLocation, name, 1024 /* SymbolFlags.NamespaceModule */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51263
51283
  if (symbol) {
51264
51284
  error(errorLocation, ts.Diagnostics.Cannot_use_namespace_0_as_a_value, ts.unescapeLeadingUnderscores(name));
51265
51285
  return true;
51266
51286
  }
51267
51287
  }
51268
- else if (meaning & (788968 /* SymbolFlags.Type */ & ~1024 /* SymbolFlags.NamespaceModule */ & ~111551 /* SymbolFlags.Value */)) {
51269
- var symbol = resolveSymbol(resolveName(errorLocation, name, (512 /* SymbolFlags.ValueModule */ | 1024 /* SymbolFlags.NamespaceModule */) & ~788968 /* SymbolFlags.Type */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51288
+ else if (meaning & (788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */)) {
51289
+ var symbol = resolveSymbol(resolveName(errorLocation, name, 1536 /* SymbolFlags.Module */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false));
51270
51290
  if (symbol) {
51271
51291
  error(errorLocation, ts.Diagnostics.Cannot_use_namespace_0_as_a_type, ts.unescapeLeadingUnderscores(name));
51272
51292
  return true;
@@ -51856,6 +51876,52 @@ var ts;
51856
51876
  }
51857
51877
  return undefined;
51858
51878
  }
51879
+ /**
51880
+ * Gets combined flags of a `symbol` and all alias targets it resolves to. `resolveAlias`
51881
+ * is typically recursive over chains of aliases, but stops mid-chain if an alias is merged
51882
+ * with another exported symbol, e.g.
51883
+ * ```ts
51884
+ * // a.ts
51885
+ * export const a = 0;
51886
+ * // b.ts
51887
+ * export { a } from "./a";
51888
+ * export type a = number;
51889
+ * // c.ts
51890
+ * import { a } from "./b";
51891
+ * ```
51892
+ * Calling `resolveAlias` on the `a` in c.ts would stop at the merged symbol exported
51893
+ * from b.ts, even though there is still more alias to resolve. Consequently, if we were
51894
+ * trying to determine if the `a` in c.ts has a value meaning, looking at the flags on
51895
+ * the local symbol and on the symbol returned by `resolveAlias` is not enough.
51896
+ * @returns SymbolFlags.All if `symbol` is an alias that ultimately resolves to `unknown`;
51897
+ * combined flags of all alias targets otherwise.
51898
+ */
51899
+ function getAllSymbolFlags(symbol) {
51900
+ var flags = symbol.flags;
51901
+ var seenSymbols;
51902
+ while (symbol.flags & 2097152 /* SymbolFlags.Alias */) {
51903
+ var target = resolveAlias(symbol);
51904
+ if (target === unknownSymbol) {
51905
+ return 67108863 /* SymbolFlags.All */;
51906
+ }
51907
+ // Optimizations - try to avoid creating or adding to
51908
+ // `seenSymbols` if possible
51909
+ if (target === symbol || (seenSymbols === null || seenSymbols === void 0 ? void 0 : seenSymbols.has(target))) {
51910
+ break;
51911
+ }
51912
+ if (target.flags & 2097152 /* SymbolFlags.Alias */) {
51913
+ if (seenSymbols) {
51914
+ seenSymbols.add(target);
51915
+ }
51916
+ else {
51917
+ seenSymbols = new ts.Set([symbol, target]);
51918
+ }
51919
+ }
51920
+ flags |= target.flags;
51921
+ symbol = target;
51922
+ }
51923
+ return flags;
51924
+ }
51859
51925
  /**
51860
51926
  * Marks a symbol as type-only if its declaration is syntactically type-only.
51861
51927
  * If it is not itself marked type-only, but resolves to a type-only alias
@@ -51901,19 +51967,25 @@ var ts;
51901
51967
  return !!aliasDeclarationLinks.typeOnlyDeclaration;
51902
51968
  }
51903
51969
  /** Indicates that a symbol directly or indirectly resolves to a type-only import or export. */
51904
- function getTypeOnlyAliasDeclaration(symbol) {
51970
+ function getTypeOnlyAliasDeclaration(symbol, include) {
51905
51971
  if (!(symbol.flags & 2097152 /* SymbolFlags.Alias */)) {
51906
51972
  return undefined;
51907
51973
  }
51908
51974
  var links = getSymbolLinks(symbol);
51909
- return links.typeOnlyDeclaration || undefined;
51975
+ if (include === undefined) {
51976
+ return links.typeOnlyDeclaration || undefined;
51977
+ }
51978
+ if (links.typeOnlyDeclaration) {
51979
+ return getAllSymbolFlags(resolveAlias(links.typeOnlyDeclaration.symbol)) & include ? links.typeOnlyDeclaration : undefined;
51980
+ }
51981
+ return undefined;
51910
51982
  }
51911
51983
  function markExportAsReferenced(node) {
51912
51984
  var symbol = getSymbolOfNode(node);
51913
51985
  var target = resolveAlias(symbol);
51914
51986
  if (target) {
51915
51987
  var markAlias = target === unknownSymbol ||
51916
- ((target.flags & 111551 /* SymbolFlags.Value */) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol));
51988
+ ((getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) && !isConstEnumOrConstEnumOnlyModule(target) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */));
51917
51989
  if (markAlias) {
51918
51990
  markAliasSymbolAsReferenced(symbol);
51919
51991
  }
@@ -51933,8 +52005,7 @@ var ts;
51933
52005
  // This way a chain of imports can be elided if ultimately the final input is only used in a type
51934
52006
  // position.
51935
52007
  if (ts.isInternalModuleImportEqualsDeclaration(node)) {
51936
- var target = resolveSymbol(symbol);
51937
- if (target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
52008
+ if (getAllSymbolFlags(resolveSymbol(symbol)) & 111551 /* SymbolFlags.Value */) {
51938
52009
  // import foo = <symbol>
51939
52010
  checkExpressionCached(node.moduleReference);
51940
52011
  }
@@ -52756,7 +52827,7 @@ var ts;
52756
52827
  }
52757
52828
  function symbolIsValue(symbol, includeTypeOnlyMembers) {
52758
52829
  return !!(symbol.flags & 111551 /* SymbolFlags.Value */ ||
52759
- symbol.flags & 2097152 /* SymbolFlags.Alias */ && resolveAlias(symbol).flags & 111551 /* SymbolFlags.Value */ && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
52830
+ symbol.flags & 2097152 /* SymbolFlags.Alias */ && getAllSymbolFlags(symbol) & 111551 /* SymbolFlags.Value */ && (includeTypeOnlyMembers || !getTypeOnlyAliasDeclaration(symbol)));
52760
52831
  }
52761
52832
  function findConstructorDeclaration(node) {
52762
52833
  var members = node.members;
@@ -53025,8 +53096,10 @@ var ts;
53025
53096
  return true;
53026
53097
  }
53027
53098
  // Qualify if the symbol from symbol table has same meaning as expected
53028
- symbolFromSymbolTable = (symbolFromSymbolTable.flags & 2097152 /* SymbolFlags.Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 278 /* SyntaxKind.ExportSpecifier */)) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
53029
- if (symbolFromSymbolTable.flags & meaning) {
53099
+ var shouldResolveAlias = (symbolFromSymbolTable.flags & 2097152 /* SymbolFlags.Alias */ && !ts.getDeclarationOfKind(symbolFromSymbolTable, 278 /* SyntaxKind.ExportSpecifier */));
53100
+ symbolFromSymbolTable = shouldResolveAlias ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable;
53101
+ var flags = shouldResolveAlias ? getAllSymbolFlags(symbolFromSymbolTable) : symbolFromSymbolTable.flags;
53102
+ if (flags & meaning) {
53030
53103
  qualify = true;
53031
53104
  return true;
53032
53105
  }
@@ -55683,7 +55756,7 @@ var ts;
55683
55756
  return !symbol.exports ? [] : ts.filter(ts.arrayFrom(symbol.exports.values()), isNamespaceMember);
55684
55757
  }
55685
55758
  function isTypeOnlyNamespace(symbol) {
55686
- return ts.every(getNamespaceMembersForSerialization(symbol), function (m) { return !(resolveSymbol(m).flags & 111551 /* SymbolFlags.Value */); });
55759
+ return ts.every(getNamespaceMembersForSerialization(symbol), function (m) { return !(getAllSymbolFlags(resolveSymbol(m)) & 111551 /* SymbolFlags.Value */); });
55687
55760
  }
55688
55761
  function serializeModule(symbol, symbolName, modifierFlags) {
55689
55762
  var members = getNamespaceMembersForSerialization(symbol);
@@ -57903,7 +57976,7 @@ var ts;
57903
57976
  links.type = (exportSymbol === null || exportSymbol === void 0 ? void 0 : exportSymbol.declarations) && isDuplicatedCommonJSExport(exportSymbol.declarations) && symbol.declarations.length ? getFlowTypeFromCommonJSExport(exportSymbol)
57904
57977
  : isDuplicatedCommonJSExport(symbol.declarations) ? autoType
57905
57978
  : declaredType ? declaredType
57906
- : targetSymbol.flags & 111551 /* SymbolFlags.Value */ ? getTypeOfSymbol(targetSymbol)
57979
+ : getAllSymbolFlags(targetSymbol) & 111551 /* SymbolFlags.Value */ ? getTypeOfSymbol(targetSymbol)
57907
57980
  : errorType;
57908
57981
  }
57909
57982
  return links.type;
@@ -60256,7 +60329,7 @@ var ts;
60256
60329
  var indexTypes;
60257
60330
  var isUnion = containingType.flags & 1048576 /* TypeFlags.Union */;
60258
60331
  // Flags we want to propagate to the result if they exist in all source symbols
60259
- var optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */;
60332
+ var optionalFlag;
60260
60333
  var syntheticFlag = 4 /* CheckFlags.SyntheticMethod */;
60261
60334
  var checkFlags = isUnion ? 0 : 8 /* CheckFlags.Readonly */;
60262
60335
  var mergedInstantiations = false;
@@ -60267,11 +60340,14 @@ var ts;
60267
60340
  var prop = getPropertyOfType(type, name, skipObjectFunctionPropertyAugment);
60268
60341
  var modifiers = prop ? ts.getDeclarationModifierFlagsFromSymbol(prop) : 0;
60269
60342
  if (prop) {
60270
- if (isUnion) {
60271
- optionalFlag |= (prop.flags & 16777216 /* SymbolFlags.Optional */);
60272
- }
60273
- else {
60274
- optionalFlag &= prop.flags;
60343
+ if (prop.flags & 106500 /* SymbolFlags.ClassMember */) {
60344
+ optionalFlag !== null && optionalFlag !== void 0 ? optionalFlag : (optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */);
60345
+ if (isUnion) {
60346
+ optionalFlag |= (prop.flags & 16777216 /* SymbolFlags.Optional */);
60347
+ }
60348
+ else {
60349
+ optionalFlag &= prop.flags;
60350
+ }
60275
60351
  }
60276
60352
  if (!singleProp) {
60277
60353
  singleProp = prop;
@@ -60390,7 +60466,7 @@ var ts;
60390
60466
  propTypes.push(type);
60391
60467
  }
60392
60468
  ts.addRange(propTypes, indexTypes);
60393
- var result = createSymbol(4 /* SymbolFlags.Property */ | optionalFlag, name, syntheticFlag | checkFlags);
60469
+ var result = createSymbol(4 /* SymbolFlags.Property */ | (optionalFlag !== null && optionalFlag !== void 0 ? optionalFlag : 0), name, syntheticFlag | checkFlags);
60394
60470
  result.containingType = containingType;
60395
60471
  if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
60396
60472
  result.valueDeclaration = firstValueDeclaration;
@@ -67001,7 +67077,7 @@ var ts;
67001
67077
  // with another type parameter unless one extends the other. (Remember: comparability is mostly bidirectional!)
67002
67078
  var constraint = getConstraintOfTypeParameter(source);
67003
67079
  if (constraint && hasNonCircularBaseConstraint(source)) {
67004
- while (constraint && constraint.flags & 262144 /* TypeFlags.TypeParameter */) {
67080
+ while (constraint && someType(constraint, function (c) { return !!(c.flags & 262144 /* TypeFlags.TypeParameter */); })) {
67005
67081
  if (result = isRelatedTo(constraint, target, 1 /* RecursionFlags.Source */, /*reportErrors*/ false)) {
67006
67082
  return result;
67007
67083
  }
@@ -67657,7 +67733,7 @@ var ts;
67657
67733
  return 0 /* Ternary.False */;
67658
67734
  }
67659
67735
  // When checking for comparability, be more lenient with optional properties.
67660
- if (!skipOptional && sourceProp.flags & 16777216 /* SymbolFlags.Optional */ && !(targetProp.flags & 16777216 /* SymbolFlags.Optional */)) {
67736
+ if (!skipOptional && sourceProp.flags & 16777216 /* SymbolFlags.Optional */ && targetProp.flags & 106500 /* SymbolFlags.ClassMember */ && !(targetProp.flags & 16777216 /* SymbolFlags.Optional */)) {
67661
67737
  // TypeScript 1.0 spec (April 2014): 3.8.3
67662
67738
  // S is a subtype of a type T, and T is a supertype of S if ...
67663
67739
  // S' and T are object types and, for each member M in T..
@@ -72929,9 +73005,9 @@ var ts;
72929
73005
  });
72930
73006
  }
72931
73007
  function markAliasReferenced(symbol, location) {
72932
- if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol)) {
73008
+ if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !isInTypeQuery(location) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */)) {
72933
73009
  var target = resolveAlias(symbol);
72934
- if (target.flags & 111551 /* SymbolFlags.Value */) {
73010
+ if (getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
72935
73011
  // An alias resolving to a const enum cannot be elided if (1) 'isolatedModules' is enabled
72936
73012
  // (because the const enum value will not be inlined), or if (2) the alias is an export
72937
73013
  // of a const enum declaration that will be preserved.
@@ -78823,7 +78899,7 @@ var ts;
78823
78899
  if (symbol && symbol.flags & 2097152 /* SymbolFlags.Alias */) {
78824
78900
  symbol = resolveAlias(symbol);
78825
78901
  }
78826
- return !!(symbol && (symbol.flags & 384 /* SymbolFlags.Enum */) && getEnumKind(symbol) === 1 /* EnumKind.Literal */);
78902
+ return !!(symbol && (getAllSymbolFlags(symbol) & 384 /* SymbolFlags.Enum */) && getEnumKind(symbol) === 1 /* EnumKind.Literal */);
78827
78903
  }
78828
78904
  return false;
78829
78905
  }
@@ -84998,7 +85074,16 @@ var ts;
84998
85074
  var message = allowAsyncIterables
84999
85075
  ? ts.Diagnostics.Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator
85000
85076
  : ts.Diagnostics.Type_0_must_have_a_Symbol_iterator_method_that_returns_an_iterator;
85001
- return errorAndMaybeSuggestAwait(errorNode, !!getAwaitedTypeOfPromise(type), message, typeToString(type));
85077
+ var suggestAwait =
85078
+ // for (const x of Promise<...>) or [...Promise<...>]
85079
+ !!getAwaitedTypeOfPromise(type)
85080
+ // for (const x of AsyncIterable<...>)
85081
+ || (!allowAsyncIterables &&
85082
+ ts.isForOfStatement(errorNode.parent) &&
85083
+ errorNode.parent.expression === errorNode &&
85084
+ getGlobalAsyncIterableType(/** reportErrors */ false) !== emptyGenericType &&
85085
+ isTypeAssignableTo(type, getGlobalAsyncIterableType(/** reportErrors */ false)));
85086
+ return errorAndMaybeSuggestAwait(errorNode, suggestAwait, message, typeToString(type));
85002
85087
  }
85003
85088
  /**
85004
85089
  * Gets the *yield*, *return*, and *next* types from an `Iterator`-like or `AsyncIterator`-like type.
@@ -86849,10 +86934,11 @@ var ts;
86849
86934
  }
86850
86935
  return;
86851
86936
  }
86937
+ var targetFlags = getAllSymbolFlags(target);
86852
86938
  var excludedMeanings = (symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */) ? 111551 /* SymbolFlags.Value */ : 0) |
86853
86939
  (symbol.flags & 788968 /* SymbolFlags.Type */ ? 788968 /* SymbolFlags.Type */ : 0) |
86854
86940
  (symbol.flags & 1920 /* SymbolFlags.Namespace */ ? 1920 /* SymbolFlags.Namespace */ : 0);
86855
- if (target.flags & excludedMeanings) {
86941
+ if (targetFlags & excludedMeanings) {
86856
86942
  var message = node.kind === 278 /* SyntaxKind.ExportSpecifier */ ?
86857
86943
  ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
86858
86944
  ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
@@ -86862,7 +86948,7 @@ var ts;
86862
86948
  && !ts.isTypeOnlyImportOrExportDeclaration(node)
86863
86949
  && !(node.flags & 16777216 /* NodeFlags.Ambient */)) {
86864
86950
  var typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
86865
- var isType = !(target.flags & 111551 /* SymbolFlags.Value */);
86951
+ var isType = !(targetFlags & 111551 /* SymbolFlags.Value */);
86866
86952
  if (isType || typeOnlyAlias) {
86867
86953
  switch (node.kind) {
86868
86954
  case 270 /* SyntaxKind.ImportClause */:
@@ -87022,14 +87108,15 @@ var ts;
87022
87108
  if (node.moduleReference.kind !== 280 /* SyntaxKind.ExternalModuleReference */) {
87023
87109
  var target = resolveAlias(getSymbolOfNode(node));
87024
87110
  if (target !== unknownSymbol) {
87025
- if (target.flags & 111551 /* SymbolFlags.Value */) {
87111
+ var targetFlags = getAllSymbolFlags(target);
87112
+ if (targetFlags & 111551 /* SymbolFlags.Value */) {
87026
87113
  // Target is a value symbol, check that it is not hidden by a local declaration with the same name
87027
87114
  var moduleName = ts.getFirstIdentifier(node.moduleReference);
87028
87115
  if (!(resolveEntityName(moduleName, 111551 /* SymbolFlags.Value */ | 1920 /* SymbolFlags.Namespace */).flags & 1920 /* SymbolFlags.Namespace */)) {
87029
87116
  error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName));
87030
87117
  }
87031
87118
  }
87032
- if (target.flags & 788968 /* SymbolFlags.Type */) {
87119
+ if (targetFlags & 788968 /* SymbolFlags.Type */) {
87033
87120
  checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0);
87034
87121
  }
87035
87122
  }
@@ -87168,7 +87255,7 @@ var ts;
87168
87255
  markExportAsReferenced(node);
87169
87256
  }
87170
87257
  var target = symbol && (symbol.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(symbol) : symbol);
87171
- if (!target || target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
87258
+ if (!target || getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
87172
87259
  checkExpressionCached(node.propertyName || node.name);
87173
87260
  }
87174
87261
  }
@@ -87215,7 +87302,7 @@ var ts;
87215
87302
  markAliasReferenced(sym, id);
87216
87303
  // If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`)
87217
87304
  var target = sym.flags & 2097152 /* SymbolFlags.Alias */ ? resolveAlias(sym) : sym;
87218
- if (target === unknownSymbol || target.flags & 111551 /* SymbolFlags.Value */) {
87305
+ if (getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */) {
87219
87306
  // However if it is a value, we need to check it's being used correctly
87220
87307
  checkExpressionCached(node.expression);
87221
87308
  }
@@ -88537,7 +88624,7 @@ var ts;
88537
88624
  return symbolLinks.exportsSomeValue;
88538
88625
  function isValue(s) {
88539
88626
  s = resolveSymbol(s);
88540
- return s && !!(s.flags & 111551 /* SymbolFlags.Value */);
88627
+ return s && !!(getAllSymbolFlags(s) & 111551 /* SymbolFlags.Value */);
88541
88628
  }
88542
88629
  }
88543
88630
  function isNameOfModuleOrEnumDeclaration(node) {
@@ -88590,7 +88677,7 @@ var ts;
88590
88677
  var symbol = getReferencedValueOrAliasSymbol(node);
88591
88678
  // We should only get the declaration of an alias if there isn't a local value
88592
88679
  // declaration for the symbol
88593
- if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !getTypeOnlyAliasDeclaration(symbol)) {
88680
+ if (isNonLocalAlias(symbol, /*excludes*/ 111551 /* SymbolFlags.Value */) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */)) {
88594
88681
  return getDeclarationOfAliasSymbol(symbol);
88595
88682
  }
88596
88683
  }
@@ -88678,7 +88765,7 @@ var ts;
88678
88765
  case 273 /* SyntaxKind.ImportSpecifier */:
88679
88766
  case 278 /* SyntaxKind.ExportSpecifier */:
88680
88767
  var symbol = getSymbolOfNode(node);
88681
- return !!symbol && isAliasResolvedToValue(symbol) && !getTypeOnlyAliasDeclaration(symbol);
88768
+ return !!symbol && isAliasResolvedToValue(symbol) && !getTypeOnlyAliasDeclaration(symbol, 111551 /* SymbolFlags.Value */);
88682
88769
  case 275 /* SyntaxKind.ExportDeclaration */:
88683
88770
  var exportClause = node.exportClause;
88684
88771
  return !!exportClause && (ts.isNamespaceExport(exportClause) ||
@@ -88700,6 +88787,7 @@ var ts;
88700
88787
  return isValue && node.moduleReference && !ts.nodeIsMissing(node.moduleReference);
88701
88788
  }
88702
88789
  function isAliasResolvedToValue(symbol) {
88790
+ var _a;
88703
88791
  if (!symbol) {
88704
88792
  return false;
88705
88793
  }
@@ -88709,7 +88797,7 @@ var ts;
88709
88797
  }
88710
88798
  // const enums and modules that contain only const enums are not considered values from the emit perspective
88711
88799
  // unless 'preserveConstEnums' option is set to true
88712
- return !!(target.flags & 111551 /* SymbolFlags.Value */) &&
88800
+ return !!(((_a = getAllSymbolFlags(target)) !== null && _a !== void 0 ? _a : -1) & 111551 /* SymbolFlags.Value */) &&
88713
88801
  (ts.shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target));
88714
88802
  }
88715
88803
  function isConstEnumOrConstEnumOnlyModule(s) {
@@ -88724,7 +88812,7 @@ var ts;
88724
88812
  }
88725
88813
  var target = getSymbolLinks(symbol).aliasTarget; // TODO: GH#18217
88726
88814
  if (target && ts.getEffectiveModifierFlags(node) & 1 /* ModifierFlags.Export */ &&
88727
- target.flags & 111551 /* SymbolFlags.Value */ &&
88815
+ getAllSymbolFlags(target) & 111551 /* SymbolFlags.Value */ &&
88728
88816
  (ts.shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target))) {
88729
88817
  // An `export import ... =` of a value symbol is always considered referenced
88730
88818
  return true;
@@ -129180,6 +129268,12 @@ var ts;
129180
129268
  SemanticClassificationFormat["Original"] = "original";
129181
129269
  SemanticClassificationFormat["TwentyTwenty"] = "2020";
129182
129270
  })(SemanticClassificationFormat = ts.SemanticClassificationFormat || (ts.SemanticClassificationFormat = {}));
129271
+ var OrganizeImportsMode;
129272
+ (function (OrganizeImportsMode) {
129273
+ OrganizeImportsMode["All"] = "All";
129274
+ OrganizeImportsMode["SortAndCombine"] = "SortAndCombine";
129275
+ OrganizeImportsMode["RemoveUnused"] = "RemoveUnused";
129276
+ })(OrganizeImportsMode = ts.OrganizeImportsMode || (ts.OrganizeImportsMode = {}));
129183
129277
  var CompletionTriggerKind;
129184
129278
  (function (CompletionTriggerKind) {
129185
129279
  /** Completion was triggered by typing an identifier, manual invocation (e.g Ctrl+Space) or via API. */
@@ -144935,23 +145029,39 @@ var ts;
144935
145029
  * 2) Coalescing imports from the same module
144936
145030
  * 3) Sorting imports
144937
145031
  */
144938
- function organizeImports(sourceFile, formatContext, host, program, preferences, skipDestructiveCodeActions) {
145032
+ function organizeImports(sourceFile, formatContext, host, program, preferences, mode) {
144939
145033
  var changeTracker = ts.textChanges.ChangeTracker.fromContext({ host: host, formatContext: formatContext, preferences: preferences });
144940
- var coalesceAndOrganizeImports = function (importGroup) { return ts.stableSort(coalesceImports(removeUnusedImports(importGroup, sourceFile, program, skipDestructiveCodeActions)), function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); }); };
145034
+ var shouldSort = mode === "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ || mode === "All" /* OrganizeImportsMode.All */;
145035
+ var shouldCombine = shouldSort; // These are currently inseparable, but I draw a distinction for clarity and in case we add modes in the future.
145036
+ var shouldRemove = mode === "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */ || mode === "All" /* OrganizeImportsMode.All */;
145037
+ var maybeRemove = shouldRemove ? removeUnusedImports : ts.identity;
145038
+ var maybeCoalesce = shouldCombine ? coalesceImports : ts.identity;
145039
+ var processImportsOfSameModuleSpecifier = function (importGroup) {
145040
+ var processedDeclarations = maybeCoalesce(maybeRemove(importGroup, sourceFile, program));
145041
+ return shouldSort
145042
+ ? ts.stableSort(processedDeclarations, function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); })
145043
+ : processedDeclarations;
145044
+ };
144941
145045
  // All of the old ImportDeclarations in the file, in syntactic order.
144942
145046
  var topLevelImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, sourceFile.statements.filter(ts.isImportDeclaration));
144943
- topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
144944
- // All of the old ExportDeclarations in the file, in syntactic order.
144945
- var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
144946
- organizeImportsWorker(topLevelExportDecls, coalesceExports);
145047
+ topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier); });
145048
+ // Exports are always used
145049
+ if (mode !== "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */) {
145050
+ // All of the old ExportDeclarations in the file, in syntactic order.
145051
+ var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
145052
+ organizeImportsWorker(topLevelExportDecls, coalesceExports);
145053
+ }
144947
145054
  for (var _i = 0, _a = sourceFile.statements.filter(ts.isAmbientModule); _i < _a.length; _i++) {
144948
145055
  var ambientModule = _a[_i];
144949
145056
  if (!ambientModule.body)
144950
145057
  continue;
144951
145058
  var ambientModuleImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, ambientModule.body.statements.filter(ts.isImportDeclaration));
144952
- ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
144953
- var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
144954
- organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
145059
+ ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier); });
145060
+ // Exports are always used
145061
+ if (mode !== "RemoveUnused" /* OrganizeImportsMode.RemoveUnused */) {
145062
+ var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
145063
+ organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
145064
+ }
144955
145065
  }
144956
145066
  return changeTracker.getChanges();
144957
145067
  function organizeImportsWorker(oldImportDecls, coalesce) {
@@ -144964,8 +145074,12 @@ var ts;
144964
145074
  // Consider: we could do a more careful check that this trivia is actually a header,
144965
145075
  // but the consequences of being wrong are very minor.
144966
145076
  ts.suppressLeadingTrivia(oldImportDecls[0]);
144967
- var oldImportGroups = ts.group(oldImportDecls, function (importDecl) { return getExternalModuleName(importDecl.moduleSpecifier); });
144968
- var sortedImportGroups = ts.stableSort(oldImportGroups, function (group1, group2) { return compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier); });
145077
+ var oldImportGroups = shouldCombine
145078
+ ? ts.group(oldImportDecls, function (importDecl) { return getExternalModuleName(importDecl.moduleSpecifier); })
145079
+ : [oldImportDecls];
145080
+ var sortedImportGroups = shouldSort
145081
+ ? ts.stableSort(oldImportGroups, function (group1, group2) { return compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier); })
145082
+ : oldImportGroups;
144969
145083
  var newImportDecls = ts.flatMap(sortedImportGroups, function (importGroup) {
144970
145084
  return getExternalModuleName(importGroup[0].moduleSpecifier)
144971
145085
  ? coalesce(importGroup)
@@ -145029,11 +145143,7 @@ var ts;
145029
145143
  }
145030
145144
  return false;
145031
145145
  }
145032
- function removeUnusedImports(oldImports, sourceFile, program, skipDestructiveCodeActions) {
145033
- // As a precaution, consider unused import detection to be destructive (GH #43051)
145034
- if (skipDestructiveCodeActions) {
145035
- return oldImports;
145036
- }
145146
+ function removeUnusedImports(oldImports, sourceFile, program) {
145037
145147
  var typeChecker = program.getTypeChecker();
145038
145148
  var compilerOptions = program.getCompilerOptions();
145039
145149
  var jsxNamespace = typeChecker.getJsxNamespace(sourceFile);
@@ -154066,6 +154176,15 @@ var ts;
154066
154176
  });
154067
154177
  }
154068
154178
  function makeChange(changeTracker, errorCode, sourceFile, checker, insertionSite, fixedDeclarations) {
154179
+ if (ts.isForOfStatement(insertionSite.parent) && !insertionSite.parent.awaitModifier) {
154180
+ var exprType = checker.getTypeAtLocation(insertionSite);
154181
+ var asyncIter = checker.getAsyncIterableType();
154182
+ if (asyncIter && checker.isTypeAssignableTo(exprType, asyncIter)) {
154183
+ var forOf = insertionSite.parent;
154184
+ changeTracker.replaceNode(sourceFile, forOf, ts.factory.updateForOfStatement(forOf, ts.factory.createToken(133 /* SyntaxKind.AwaitKeyword */), forOf.initializer, forOf.expression, forOf.statement));
154185
+ return;
154186
+ }
154187
+ }
154069
154188
  if (ts.isBinaryExpression(insertionSite)) {
154070
154189
  for (var _i = 0, _a = [insertionSite.left, insertionSite.right]; _i < _a.length; _i++) {
154071
154190
  var side = _a[_i];
@@ -169421,12 +169540,14 @@ var ts;
169421
169540
  return ts.codefix.getAllFixes({ fixId: fixId, sourceFile: sourceFile, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences });
169422
169541
  }
169423
169542
  function organizeImports(args, formatOptions, preferences) {
169543
+ var _a;
169424
169544
  if (preferences === void 0) { preferences = ts.emptyOptions; }
169425
169545
  synchronizeHostData();
169426
169546
  ts.Debug.assert(args.type === "file");
169427
169547
  var sourceFile = getValidSourceFile(args.fileName);
169428
169548
  var formatContext = ts.formatting.getFormatContext(formatOptions, host);
169429
- return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences, args.skipDestructiveCodeActions);
169549
+ var mode = (_a = args.mode) !== null && _a !== void 0 ? _a : (args.skipDestructiveCodeActions ? "SortAndCombine" /* OrganizeImportsMode.SortAndCombine */ : "All" /* OrganizeImportsMode.All */);
169550
+ return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences, mode);
169430
169551
  }
169431
169552
  function getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) {
169432
169553
  if (preferences === void 0) { preferences = ts.emptyOptions; }