typescript 4.7.0-dev.20220404 → 4.7.0-dev.20220408

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220404";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220408";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -4609,10 +4609,11 @@ var ts;
4609
4609
  NodeFlags[NodeFlags["YieldContext"] = 8192] = "YieldContext";
4610
4610
  NodeFlags[NodeFlags["DecoratorContext"] = 16384] = "DecoratorContext";
4611
4611
  NodeFlags[NodeFlags["AwaitContext"] = 32768] = "AwaitContext";
4612
- NodeFlags[NodeFlags["ThisNodeHasError"] = 65536] = "ThisNodeHasError";
4613
- NodeFlags[NodeFlags["JavaScriptFile"] = 131072] = "JavaScriptFile";
4614
- NodeFlags[NodeFlags["ThisNodeOrAnySubNodesHasError"] = 262144] = "ThisNodeOrAnySubNodesHasError";
4615
- NodeFlags[NodeFlags["HasAggregatedChildData"] = 524288] = "HasAggregatedChildData";
4612
+ NodeFlags[NodeFlags["DisallowConditionalTypesContext"] = 65536] = "DisallowConditionalTypesContext";
4613
+ NodeFlags[NodeFlags["ThisNodeHasError"] = 131072] = "ThisNodeHasError";
4614
+ NodeFlags[NodeFlags["JavaScriptFile"] = 262144] = "JavaScriptFile";
4615
+ NodeFlags[NodeFlags["ThisNodeOrAnySubNodesHasError"] = 524288] = "ThisNodeOrAnySubNodesHasError";
4616
+ NodeFlags[NodeFlags["HasAggregatedChildData"] = 1048576] = "HasAggregatedChildData";
4616
4617
  // These flags will be set when the parser encounters a dynamic import expression or 'import.meta' to avoid
4617
4618
  // walking the tree if the flags are not set. However, these flags are just a approximation
4618
4619
  // (hence why it's named "PossiblyContainsDynamicImport") because once set, the flags never get cleared.
@@ -4622,25 +4623,25 @@ var ts;
4622
4623
  // removal, it is likely that users will add the import anyway.
4623
4624
  // The advantage of this approach is its simplicity. For the case of batch compilation,
4624
4625
  // we guarantee that users won't have to pay the price of walking the tree if a dynamic import isn't used.
4625
- /* @internal */ NodeFlags[NodeFlags["PossiblyContainsDynamicImport"] = 1048576] = "PossiblyContainsDynamicImport";
4626
- /* @internal */ NodeFlags[NodeFlags["PossiblyContainsImportMeta"] = 2097152] = "PossiblyContainsImportMeta";
4627
- NodeFlags[NodeFlags["JSDoc"] = 4194304] = "JSDoc";
4628
- /* @internal */ NodeFlags[NodeFlags["Ambient"] = 8388608] = "Ambient";
4629
- /* @internal */ NodeFlags[NodeFlags["InWithStatement"] = 16777216] = "InWithStatement";
4630
- NodeFlags[NodeFlags["JsonFile"] = 33554432] = "JsonFile";
4631
- /* @internal */ NodeFlags[NodeFlags["TypeCached"] = 67108864] = "TypeCached";
4632
- /* @internal */ NodeFlags[NodeFlags["Deprecated"] = 134217728] = "Deprecated";
4626
+ /* @internal */ NodeFlags[NodeFlags["PossiblyContainsDynamicImport"] = 2097152] = "PossiblyContainsDynamicImport";
4627
+ /* @internal */ NodeFlags[NodeFlags["PossiblyContainsImportMeta"] = 4194304] = "PossiblyContainsImportMeta";
4628
+ NodeFlags[NodeFlags["JSDoc"] = 8388608] = "JSDoc";
4629
+ /* @internal */ NodeFlags[NodeFlags["Ambient"] = 16777216] = "Ambient";
4630
+ /* @internal */ NodeFlags[NodeFlags["InWithStatement"] = 33554432] = "InWithStatement";
4631
+ NodeFlags[NodeFlags["JsonFile"] = 67108864] = "JsonFile";
4632
+ /* @internal */ NodeFlags[NodeFlags["TypeCached"] = 134217728] = "TypeCached";
4633
+ /* @internal */ NodeFlags[NodeFlags["Deprecated"] = 268435456] = "Deprecated";
4633
4634
  NodeFlags[NodeFlags["BlockScoped"] = 3] = "BlockScoped";
4634
4635
  NodeFlags[NodeFlags["ReachabilityCheckFlags"] = 768] = "ReachabilityCheckFlags";
4635
4636
  NodeFlags[NodeFlags["ReachabilityAndEmitFlags"] = 2816] = "ReachabilityAndEmitFlags";
4636
4637
  // Parsing context flags
4637
- NodeFlags[NodeFlags["ContextFlags"] = 25358336] = "ContextFlags";
4638
+ NodeFlags[NodeFlags["ContextFlags"] = 50720768] = "ContextFlags";
4638
4639
  // Exclude these flags when parsing a Type
4639
4640
  NodeFlags[NodeFlags["TypeExcludesFlags"] = 40960] = "TypeExcludesFlags";
4640
4641
  // Represents all flags that are potentially set once and
4641
4642
  // never cleared on SourceFiles which get re-used in between incremental parses.
4642
4643
  // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`.
4643
- /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 3145728] = "PermanentlySetIncrementalFlags";
4644
+ /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 6291456] = "PermanentlySetIncrementalFlags";
4644
4645
  })(NodeFlags = ts.NodeFlags || (ts.NodeFlags = {}));
4645
4646
  var ModifierFlags;
4646
4647
  (function (ModifierFlags) {
@@ -8910,6 +8911,7 @@ var ts;
8910
8911
  _0_index_signatures_are_incompatible: diag(2634, ts.DiagnosticCategory.Error, "_0_index_signatures_are_incompatible_2634", "'{0}' index signatures are incompatible."),
8911
8912
  Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable: diag(2635, ts.DiagnosticCategory.Error, "Type_0_has_no_signatures_for_which_the_type_argument_list_is_applicable_2635", "Type '{0}' has no signatures for which the type argument list is applicable."),
8912
8913
  Type_0_is_not_assignable_to_type_1_as_implied_by_variance_annotation: diag(2636, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_as_implied_by_variance_annotation_2636", "Type '{0}' is not assignable to type '{1}' as implied by variance annotation."),
8914
+ Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types: diag(2637, ts.DiagnosticCategory.Error, "Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_t_2637", "Variance annotations are only supported in type aliases for object, function, constructor, and mapped types."),
8913
8915
  Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity: diag(2649, ts.DiagnosticCategory.Error, "Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity_2649", "Cannot augment module '{0}' with value exports because it resolves to a non-module entity."),
8914
8916
  A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums: diag(2651, ts.DiagnosticCategory.Error, "A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_memb_2651", "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums."),
8915
8917
  Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: diag(2652, ts.DiagnosticCategory.Error, "Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_d_2652", "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead."),
@@ -9082,6 +9084,7 @@ var ts;
9082
9084
  Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_node12_or_nodenext_Did_you_mean_0: diag(2835, ts.DiagnosticCategory.Error, "Relative_import_paths_need_explicit_file_extensions_in_EcmaScript_imports_when_moduleResolution_is_n_2835", "Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node12' or 'nodenext'. Did you mean '{0}'?"),
9083
9085
  Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls: diag(2836, ts.DiagnosticCategory.Error, "Import_assertions_are_not_allowed_on_statements_that_transpile_to_commonjs_require_calls_2836", "Import assertions are not allowed on statements that transpile to commonjs 'require' calls."),
9084
9086
  Import_assertion_values_must_be_string_literal_expressions: diag(2837, ts.DiagnosticCategory.Error, "Import_assertion_values_must_be_string_literal_expressions_2837", "Import assertion values must be string literal expressions."),
9087
+ All_declarations_of_0_must_have_identical_constraints: diag(2838, ts.DiagnosticCategory.Error, "All_declarations_of_0_must_have_identical_constraints_2838", "All declarations of '{0}' must have identical constraints."),
9085
9088
  Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
9086
9089
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
9087
9090
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -14496,24 +14499,24 @@ var ts;
14496
14499
  // Returns true if this node contains a parse error anywhere underneath it.
14497
14500
  function containsParseError(node) {
14498
14501
  aggregateChildData(node);
14499
- return (node.flags & 262144 /* ThisNodeOrAnySubNodesHasError */) !== 0;
14502
+ return (node.flags & 524288 /* ThisNodeOrAnySubNodesHasError */) !== 0;
14500
14503
  }
14501
14504
  ts.containsParseError = containsParseError;
14502
14505
  function aggregateChildData(node) {
14503
- if (!(node.flags & 524288 /* HasAggregatedChildData */)) {
14506
+ if (!(node.flags & 1048576 /* HasAggregatedChildData */)) {
14504
14507
  // A node is considered to contain a parse error if:
14505
14508
  // a) the parser explicitly marked that it had an error
14506
14509
  // b) any of it's children reported that it had an error.
14507
- var thisNodeOrAnySubNodesHasError = ((node.flags & 65536 /* ThisNodeHasError */) !== 0) ||
14510
+ var thisNodeOrAnySubNodesHasError = ((node.flags & 131072 /* ThisNodeHasError */) !== 0) ||
14508
14511
  ts.forEachChild(node, containsParseError);
14509
14512
  // If so, mark ourselves accordingly.
14510
14513
  if (thisNodeOrAnySubNodesHasError) {
14511
- node.flags |= 262144 /* ThisNodeOrAnySubNodesHasError */;
14514
+ node.flags |= 524288 /* ThisNodeOrAnySubNodesHasError */;
14512
14515
  }
14513
14516
  // Also mark that we've propagated the child information to this node. This way we can
14514
14517
  // always consult the bit directly on this node without needing to check its children
14515
14518
  // again.
14516
- node.flags |= 524288 /* HasAggregatedChildData */;
14519
+ node.flags |= 1048576 /* HasAggregatedChildData */;
14517
14520
  }
14518
14521
  }
14519
14522
  function getSourceFileOfNode(node) {
@@ -16320,11 +16323,11 @@ var ts;
16320
16323
  }
16321
16324
  ts.isSourceFileNotJS = isSourceFileNotJS;
16322
16325
  function isInJSFile(node) {
16323
- return !!node && !!(node.flags & 131072 /* JavaScriptFile */);
16326
+ return !!node && !!(node.flags & 262144 /* JavaScriptFile */);
16324
16327
  }
16325
16328
  ts.isInJSFile = isInJSFile;
16326
16329
  function isInJsonFile(node) {
16327
- return !!node && !!(node.flags & 33554432 /* JsonFile */);
16330
+ return !!node && !!(node.flags & 67108864 /* JsonFile */);
16328
16331
  }
16329
16332
  ts.isInJsonFile = isInJsonFile;
16330
16333
  function isSourceFileNotJson(file) {
@@ -16332,7 +16335,7 @@ var ts;
16332
16335
  }
16333
16336
  ts.isSourceFileNotJson = isSourceFileNotJson;
16334
16337
  function isInJSDoc(node) {
16335
- return !!node && !!(node.flags & 4194304 /* JSDoc */);
16338
+ return !!node && !!(node.flags & 8388608 /* JSDoc */);
16336
16339
  }
16337
16340
  ts.isInJSDoc = isInJSDoc;
16338
16341
  function isJSDocIndexSignature(node) {
@@ -16718,7 +16721,7 @@ var ts;
16718
16721
  function setValueDeclaration(symbol, node) {
16719
16722
  var valueDeclaration = symbol.valueDeclaration;
16720
16723
  if (!valueDeclaration ||
16721
- !(node.flags & 8388608 /* Ambient */ && !(valueDeclaration.flags & 8388608 /* Ambient */)) &&
16724
+ !(node.flags & 16777216 /* Ambient */ && !(valueDeclaration.flags & 16777216 /* Ambient */)) &&
16722
16725
  (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) ||
16723
16726
  (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) {
16724
16727
  // other kinds of value declarations take precedence over modules and assignment declarations
@@ -16991,7 +16994,11 @@ var ts;
16991
16994
  ts.getEffectiveContainerForJSDocTemplateTag = getEffectiveContainerForJSDocTemplateTag;
16992
16995
  function getHostSignatureFromJSDoc(node) {
16993
16996
  var host = getEffectiveJSDocHost(node);
16994
- return host && ts.isFunctionLike(host) ? host : undefined;
16997
+ if (host) {
16998
+ return ts.isPropertySignature(host) && host.type && ts.isFunctionLike(host.type) ? host.type :
16999
+ ts.isFunctionLike(host) ? host : undefined;
17000
+ }
17001
+ return undefined;
16995
17002
  }
16996
17003
  ts.getHostSignatureFromJSDoc = getHostSignatureFromJSDoc;
16997
17004
  function getEffectiveJSDocHost(node) {
@@ -21016,7 +21023,7 @@ var ts;
21016
21023
  }
21017
21024
  ts.pseudoBigIntToString = pseudoBigIntToString;
21018
21025
  function isValidTypeOnlyAliasUseSite(useSite) {
21019
- return !!(useSite.flags & 8388608 /* Ambient */)
21026
+ return !!(useSite.flags & 16777216 /* Ambient */)
21020
21027
  || isPartOfTypeQuery(useSite)
21021
21028
  || isIdentifierInNonEmittingHeritageClause(useSite)
21022
21029
  || isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(useSite)
@@ -21469,11 +21476,20 @@ var ts;
21469
21476
  parenthesizeExpressionForDisallowedComma: parenthesizeExpressionForDisallowedComma,
21470
21477
  parenthesizeExpressionOfExpressionStatement: parenthesizeExpressionOfExpressionStatement,
21471
21478
  parenthesizeConciseBodyOfArrowFunction: parenthesizeConciseBodyOfArrowFunction,
21472
- parenthesizeMemberOfConditionalType: parenthesizeMemberOfConditionalType,
21473
- parenthesizeMemberOfElementType: parenthesizeMemberOfElementType,
21474
- parenthesizeElementTypeOfArrayType: parenthesizeElementTypeOfArrayType,
21475
- parenthesizeConstituentTypesOfUnionOrIntersectionType: parenthesizeConstituentTypesOfUnionOrIntersectionType,
21479
+ parenthesizeCheckTypeOfConditionalType: parenthesizeCheckTypeOfConditionalType,
21480
+ parenthesizeExtendsTypeOfConditionalType: parenthesizeExtendsTypeOfConditionalType,
21481
+ parenthesizeConstituentTypesOfUnionType: parenthesizeConstituentTypesOfUnionType,
21482
+ parenthesizeConstituentTypeOfUnionType: parenthesizeConstituentTypeOfUnionType,
21483
+ parenthesizeConstituentTypesOfIntersectionType: parenthesizeConstituentTypesOfIntersectionType,
21484
+ parenthesizeConstituentTypeOfIntersectionType: parenthesizeConstituentTypeOfIntersectionType,
21485
+ parenthesizeOperandOfTypeOperator: parenthesizeOperandOfTypeOperator,
21486
+ parenthesizeOperandOfReadonlyTypeOperator: parenthesizeOperandOfReadonlyTypeOperator,
21487
+ parenthesizeNonArrayTypeOfPostfixType: parenthesizeNonArrayTypeOfPostfixType,
21488
+ parenthesizeElementTypesOfTupleType: parenthesizeElementTypesOfTupleType,
21489
+ parenthesizeElementTypeOfTupleType: parenthesizeElementTypeOfTupleType,
21490
+ parenthesizeTypeOfOptionalType: parenthesizeTypeOfOptionalType,
21476
21491
  parenthesizeTypeArguments: parenthesizeTypeArguments,
21492
+ parenthesizeLeadingTypeArgument: parenthesizeLeadingTypeArgument,
21477
21493
  };
21478
21494
  function getParenthesizeLeftSideOfBinaryForOperator(operatorKind) {
21479
21495
  binaryLeftOperandParenthesizerCache || (binaryLeftOperandParenthesizerCache = new ts.Map());
@@ -21785,33 +21801,191 @@ var ts;
21785
21801
  }
21786
21802
  return body;
21787
21803
  }
21788
- function parenthesizeMemberOfConditionalType(member) {
21789
- return member.kind === 189 /* ConditionalType */ ? factory.createParenthesizedType(member) : member;
21804
+ // Type[Extends] :
21805
+ // FunctionOrConstructorType
21806
+ // ConditionalType[?Extends]
21807
+ // ConditionalType[Extends] :
21808
+ // UnionType[?Extends]
21809
+ // [~Extends] UnionType[~Extends] `extends` Type[+Extends] `?` Type[~Extends] `:` Type[~Extends]
21810
+ //
21811
+ // - The check type (the `UnionType`, above) does not allow function, constructor, or conditional types (they must be parenthesized)
21812
+ // - The extends type (the first `Type`, above) does not allow conditional types (they must be parenthesized). Function and constructor types are fine.
21813
+ // - The true and false branch types (the second and third `Type` non-terminals, above) allow any type
21814
+ function parenthesizeCheckTypeOfConditionalType(checkType) {
21815
+ switch (checkType.kind) {
21816
+ case 179 /* FunctionType */:
21817
+ case 180 /* ConstructorType */:
21818
+ case 189 /* ConditionalType */:
21819
+ return factory.createParenthesizedType(checkType);
21820
+ }
21821
+ return checkType;
21790
21822
  }
21791
- function parenthesizeMemberOfElementType(member) {
21792
- switch (member.kind) {
21823
+ function parenthesizeExtendsTypeOfConditionalType(extendsType) {
21824
+ switch (extendsType.kind) {
21825
+ case 189 /* ConditionalType */:
21826
+ return factory.createParenthesizedType(extendsType);
21827
+ }
21828
+ return extendsType;
21829
+ }
21830
+ // UnionType[Extends] :
21831
+ // `|`? IntersectionType[?Extends]
21832
+ // UnionType[?Extends] `|` IntersectionType[?Extends]
21833
+ //
21834
+ // - A union type constituent has the same precedence as the check type of a conditional type
21835
+ function parenthesizeConstituentTypeOfUnionType(type) {
21836
+ switch (type.kind) {
21837
+ case 187 /* UnionType */: // Not strictly necessary, but a union containing a union should have been flattened
21838
+ case 188 /* IntersectionType */: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests
21839
+ return factory.createParenthesizedType(type);
21840
+ }
21841
+ return parenthesizeCheckTypeOfConditionalType(type);
21842
+ }
21843
+ function parenthesizeConstituentTypesOfUnionType(members) {
21844
+ return factory.createNodeArray(ts.sameMap(members, parenthesizeConstituentTypeOfUnionType));
21845
+ }
21846
+ // IntersectionType[Extends] :
21847
+ // `&`? TypeOperator[?Extends]
21848
+ // IntersectionType[?Extends] `&` TypeOperator[?Extends]
21849
+ //
21850
+ // - An intersection type constituent does not allow function, constructor, conditional, or union types (they must be parenthesized)
21851
+ function parenthesizeConstituentTypeOfIntersectionType(type) {
21852
+ switch (type.kind) {
21793
21853
  case 187 /* UnionType */:
21854
+ case 188 /* IntersectionType */: // Not strictly necessary, but an intersection containing an intersection should have been flattened
21855
+ return factory.createParenthesizedType(type);
21856
+ }
21857
+ return parenthesizeConstituentTypeOfUnionType(type);
21858
+ }
21859
+ function parenthesizeConstituentTypesOfIntersectionType(members) {
21860
+ return factory.createNodeArray(ts.sameMap(members, parenthesizeConstituentTypeOfIntersectionType));
21861
+ }
21862
+ // TypeOperator[Extends] :
21863
+ // PostfixType
21864
+ // InferType[?Extends]
21865
+ // `keyof` TypeOperator[?Extends]
21866
+ // `unique` TypeOperator[?Extends]
21867
+ // `readonly` TypeOperator[?Extends]
21868
+ //
21869
+ function parenthesizeOperandOfTypeOperator(type) {
21870
+ switch (type.kind) {
21794
21871
  case 188 /* IntersectionType */:
21795
- case 179 /* FunctionType */:
21796
- case 180 /* ConstructorType */:
21797
- return factory.createParenthesizedType(member);
21872
+ return factory.createParenthesizedType(type);
21798
21873
  }
21799
- return parenthesizeMemberOfConditionalType(member);
21874
+ return parenthesizeConstituentTypeOfIntersectionType(type);
21800
21875
  }
21801
- function parenthesizeElementTypeOfArrayType(member) {
21802
- switch (member.kind) {
21803
- case 181 /* TypeQuery */:
21876
+ function parenthesizeOperandOfReadonlyTypeOperator(type) {
21877
+ switch (type.kind) {
21804
21878
  case 193 /* TypeOperator */:
21879
+ return factory.createParenthesizedType(type);
21880
+ }
21881
+ return parenthesizeOperandOfTypeOperator(type);
21882
+ }
21883
+ // PostfixType :
21884
+ // NonArrayType
21885
+ // NonArrayType [no LineTerminator here] `!` // JSDoc
21886
+ // NonArrayType [no LineTerminator here] `?` // JSDoc
21887
+ // IndexedAccessType
21888
+ // ArrayType
21889
+ //
21890
+ // IndexedAccessType :
21891
+ // NonArrayType `[` Type[~Extends] `]`
21892
+ //
21893
+ // ArrayType :
21894
+ // NonArrayType `[` `]`
21895
+ //
21896
+ function parenthesizeNonArrayTypeOfPostfixType(type) {
21897
+ switch (type.kind) {
21805
21898
  case 190 /* InferType */:
21806
- return factory.createParenthesizedType(member);
21899
+ case 193 /* TypeOperator */:
21900
+ case 181 /* TypeQuery */: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests
21901
+ return factory.createParenthesizedType(type);
21807
21902
  }
21808
- return parenthesizeMemberOfElementType(member);
21903
+ return parenthesizeOperandOfTypeOperator(type);
21904
+ }
21905
+ // TupleType :
21906
+ // `[` Elision? `]`
21907
+ // `[` NamedTupleElementTypes `]`
21908
+ // `[` NamedTupleElementTypes `,` Elision? `]`
21909
+ // `[` TupleElementTypes `]`
21910
+ // `[` TupleElementTypes `,` Elision? `]`
21911
+ //
21912
+ // NamedTupleElementTypes :
21913
+ // Elision? NamedTupleMember
21914
+ // NamedTupleElementTypes `,` Elision? NamedTupleMember
21915
+ //
21916
+ // NamedTupleMember :
21917
+ // Identifier `?`? `:` Type[~Extends]
21918
+ // `...` Identifier `:` Type[~Extends]
21919
+ //
21920
+ // TupleElementTypes :
21921
+ // Elision? TupleElementType
21922
+ // TupleElementTypes `,` Elision? TupleElementType
21923
+ //
21924
+ // TupleElementType :
21925
+ // Type[~Extends] // NOTE: Needs cover grammar to disallow JSDoc postfix-optional
21926
+ // OptionalType
21927
+ // RestType
21928
+ //
21929
+ // OptionalType :
21930
+ // Type[~Extends] `?` // NOTE: Needs cover grammar to disallow JSDoc postfix-optional
21931
+ //
21932
+ // RestType :
21933
+ // `...` Type[~Extends]
21934
+ //
21935
+ function parenthesizeElementTypesOfTupleType(types) {
21936
+ return factory.createNodeArray(ts.sameMap(types, parenthesizeElementTypeOfTupleType));
21937
+ }
21938
+ function parenthesizeElementTypeOfTupleType(type) {
21939
+ if (hasJSDocPostfixQuestion(type))
21940
+ return factory.createParenthesizedType(type);
21941
+ return type;
21942
+ }
21943
+ function hasJSDocPostfixQuestion(type) {
21944
+ if (ts.isJSDocNullableType(type))
21945
+ return type.postfix;
21946
+ if (ts.isNamedTupleMember(type))
21947
+ return hasJSDocPostfixQuestion(type.type);
21948
+ if (ts.isFunctionTypeNode(type) || ts.isConstructorTypeNode(type) || ts.isTypeOperatorNode(type))
21949
+ return hasJSDocPostfixQuestion(type.type);
21950
+ if (ts.isConditionalTypeNode(type))
21951
+ return hasJSDocPostfixQuestion(type.falseType);
21952
+ if (ts.isUnionTypeNode(type))
21953
+ return hasJSDocPostfixQuestion(ts.last(type.types));
21954
+ if (ts.isIntersectionTypeNode(type))
21955
+ return hasJSDocPostfixQuestion(ts.last(type.types));
21956
+ if (ts.isInferTypeNode(type))
21957
+ return !!type.typeParameter.constraint && hasJSDocPostfixQuestion(type.typeParameter.constraint);
21958
+ return false;
21809
21959
  }
21810
- function parenthesizeConstituentTypesOfUnionOrIntersectionType(members) {
21811
- return factory.createNodeArray(ts.sameMap(members, parenthesizeMemberOfElementType));
21960
+ function parenthesizeTypeOfOptionalType(type) {
21961
+ if (hasJSDocPostfixQuestion(type))
21962
+ return factory.createParenthesizedType(type);
21963
+ return parenthesizeNonArrayTypeOfPostfixType(type);
21964
+ }
21965
+ // function parenthesizeMemberOfElementType(member: TypeNode): TypeNode {
21966
+ // switch (member.kind) {
21967
+ // case SyntaxKind.UnionType:
21968
+ // case SyntaxKind.IntersectionType:
21969
+ // case SyntaxKind.FunctionType:
21970
+ // case SyntaxKind.ConstructorType:
21971
+ // return factory.createParenthesizedType(member);
21972
+ // }
21973
+ // return parenthesizeMemberOfConditionalType(member);
21974
+ // }
21975
+ // function parenthesizeElementTypeOfArrayType(member: TypeNode): TypeNode {
21976
+ // switch (member.kind) {
21977
+ // case SyntaxKind.TypeQuery:
21978
+ // case SyntaxKind.TypeOperator:
21979
+ // case SyntaxKind.InferType:
21980
+ // return factory.createParenthesizedType(member);
21981
+ // }
21982
+ // return parenthesizeMemberOfElementType(member);
21983
+ // }
21984
+ function parenthesizeLeadingTypeArgument(node) {
21985
+ return ts.isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory.createParenthesizedType(node) : node;
21812
21986
  }
21813
21987
  function parenthesizeOrdinalTypeArgument(node, i) {
21814
- return i === 0 && ts.isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory.createParenthesizedType(node) : node;
21988
+ return i === 0 ? parenthesizeLeadingTypeArgument(node) : node;
21815
21989
  }
21816
21990
  function parenthesizeTypeArguments(typeArguments) {
21817
21991
  if (ts.some(typeArguments)) {
@@ -21837,11 +22011,20 @@ var ts;
21837
22011
  parenthesizeExpressionForDisallowedComma: ts.identity,
21838
22012
  parenthesizeExpressionOfExpressionStatement: ts.identity,
21839
22013
  parenthesizeConciseBodyOfArrowFunction: ts.identity,
21840
- parenthesizeMemberOfConditionalType: ts.identity,
21841
- parenthesizeMemberOfElementType: ts.identity,
21842
- parenthesizeElementTypeOfArrayType: ts.identity,
21843
- parenthesizeConstituentTypesOfUnionOrIntersectionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
22014
+ parenthesizeCheckTypeOfConditionalType: ts.identity,
22015
+ parenthesizeExtendsTypeOfConditionalType: ts.identity,
22016
+ parenthesizeConstituentTypesOfUnionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
22017
+ parenthesizeConstituentTypeOfUnionType: ts.identity,
22018
+ parenthesizeConstituentTypesOfIntersectionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
22019
+ parenthesizeConstituentTypeOfIntersectionType: ts.identity,
22020
+ parenthesizeOperandOfTypeOperator: ts.identity,
22021
+ parenthesizeOperandOfReadonlyTypeOperator: ts.identity,
22022
+ parenthesizeNonArrayTypeOfPostfixType: ts.identity,
22023
+ parenthesizeElementTypesOfTupleType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
22024
+ parenthesizeElementTypeOfTupleType: ts.identity,
22025
+ parenthesizeTypeOfOptionalType: ts.identity,
21844
22026
  parenthesizeTypeArguments: function (nodes) { return nodes && ts.cast(nodes, ts.isNodeArray); },
22027
+ parenthesizeLeadingTypeArgument: ts.identity,
21845
22028
  };
21846
22029
  })(ts || (ts = {}));
21847
22030
  /* @internal */
@@ -21981,6 +22164,8 @@ var ts;
21981
22164
  var getJSDocPrimaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function () { return createJSDocPrimaryTypeWorker(kind); }; });
21982
22165
  var getJSDocUnaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function (type) { return createJSDocUnaryTypeWorker(kind, type); }; });
21983
22166
  var getJSDocUnaryTypeUpdateFunction = ts.memoizeOne(function (kind) { return function (node, type) { return updateJSDocUnaryTypeWorker(kind, node, type); }; });
22167
+ var getJSDocPrePostfixUnaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function (type, postfix) { return createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix); }; });
22168
+ var getJSDocPrePostfixUnaryTypeUpdateFunction = ts.memoizeOne(function (kind) { return function (node, type) { return updateJSDocPrePostfixUnaryTypeWorker(kind, node, type); }; });
21984
22169
  var getJSDocSimpleTagCreateFunction = ts.memoizeOne(function (kind) { return function (tagName, comment) { return createJSDocSimpleTagWorker(kind, tagName, comment); }; });
21985
22170
  var getJSDocSimpleTagUpdateFunction = ts.memoizeOne(function (kind) { return function (node, tagName, comment) { return updateJSDocSimpleTagWorker(kind, node, tagName, comment); }; });
21986
22171
  var getJSDocTypeLikeTagCreateFunction = ts.memoizeOne(function (kind) { return function (tagName, typeExpression, comment) { return createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment); }; });
@@ -21988,6 +22173,8 @@ var ts;
21988
22173
  var factory = {
21989
22174
  get parenthesizer() { return parenthesizerRules(); },
21990
22175
  get converters() { return converters(); },
22176
+ baseFactory: baseFactory,
22177
+ flags: flags,
21991
22178
  createNodeArray: createNodeArray,
21992
22179
  createNumericLiteral: createNumericLiteral,
21993
22180
  createBigIntLiteral: createBigIntLiteral,
@@ -22263,10 +22450,10 @@ var ts;
22263
22450
  // lazily load factory members for JSDoc types with similar structure
22264
22451
  get createJSDocAllType() { return getJSDocPrimaryTypeCreateFunction(312 /* JSDocAllType */); },
22265
22452
  get createJSDocUnknownType() { return getJSDocPrimaryTypeCreateFunction(313 /* JSDocUnknownType */); },
22266
- get createJSDocNonNullableType() { return getJSDocUnaryTypeCreateFunction(315 /* JSDocNonNullableType */); },
22267
- get updateJSDocNonNullableType() { return getJSDocUnaryTypeUpdateFunction(315 /* JSDocNonNullableType */); },
22268
- get createJSDocNullableType() { return getJSDocUnaryTypeCreateFunction(314 /* JSDocNullableType */); },
22269
- get updateJSDocNullableType() { return getJSDocUnaryTypeUpdateFunction(314 /* JSDocNullableType */); },
22453
+ get createJSDocNonNullableType() { return getJSDocPrePostfixUnaryTypeCreateFunction(315 /* JSDocNonNullableType */); },
22454
+ get updateJSDocNonNullableType() { return getJSDocPrePostfixUnaryTypeUpdateFunction(315 /* JSDocNonNullableType */); },
22455
+ get createJSDocNullableType() { return getJSDocPrePostfixUnaryTypeCreateFunction(314 /* JSDocNullableType */); },
22456
+ get updateJSDocNullableType() { return getJSDocPrePostfixUnaryTypeUpdateFunction(314 /* JSDocNullableType */); },
22270
22457
  get createJSDocOptionalType() { return getJSDocUnaryTypeCreateFunction(316 /* JSDocOptionalType */); },
22271
22458
  get updateJSDocOptionalType() { return getJSDocUnaryTypeUpdateFunction(316 /* JSDocOptionalType */); },
22272
22459
  get createJSDocVariadicType() { return getJSDocUnaryTypeCreateFunction(318 /* JSDocVariadicType */); },
@@ -23382,7 +23569,7 @@ var ts;
23382
23569
  // @api
23383
23570
  function createArrayTypeNode(elementType) {
23384
23571
  var node = createBaseNode(183 /* ArrayType */);
23385
- node.elementType = parenthesizerRules().parenthesizeElementTypeOfArrayType(elementType);
23572
+ node.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType);
23386
23573
  node.transformFlags = 1 /* ContainsTypeScript */;
23387
23574
  return node;
23388
23575
  }
@@ -23395,7 +23582,7 @@ var ts;
23395
23582
  // @api
23396
23583
  function createTupleTypeNode(elements) {
23397
23584
  var node = createBaseNode(184 /* TupleType */);
23398
- node.elements = createNodeArray(elements);
23585
+ node.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements));
23399
23586
  node.transformFlags = 1 /* ContainsTypeScript */;
23400
23587
  return node;
23401
23588
  }
@@ -23427,7 +23614,7 @@ var ts;
23427
23614
  // @api
23428
23615
  function createOptionalTypeNode(type) {
23429
23616
  var node = createBaseNode(185 /* OptionalType */);
23430
- node.type = parenthesizerRules().parenthesizeElementTypeOfArrayType(type);
23617
+ node.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type);
23431
23618
  node.transformFlags = 1 /* ContainsTypeScript */;
23432
23619
  return node;
23433
23620
  }
@@ -23450,38 +23637,38 @@ var ts;
23450
23637
  ? update(createRestTypeNode(type), node)
23451
23638
  : node;
23452
23639
  }
23453
- function createUnionOrIntersectionTypeNode(kind, types) {
23640
+ function createUnionOrIntersectionTypeNode(kind, types, parenthesize) {
23454
23641
  var node = createBaseNode(kind);
23455
- node.types = parenthesizerRules().parenthesizeConstituentTypesOfUnionOrIntersectionType(types);
23642
+ node.types = factory.createNodeArray(parenthesize(types));
23456
23643
  node.transformFlags = 1 /* ContainsTypeScript */;
23457
23644
  return node;
23458
23645
  }
23459
- function updateUnionOrIntersectionTypeNode(node, types) {
23646
+ function updateUnionOrIntersectionTypeNode(node, types, parenthesize) {
23460
23647
  return node.types !== types
23461
- ? update(createUnionOrIntersectionTypeNode(node.kind, types), node)
23648
+ ? update(createUnionOrIntersectionTypeNode(node.kind, types, parenthesize), node)
23462
23649
  : node;
23463
23650
  }
23464
23651
  // @api
23465
23652
  function createUnionTypeNode(types) {
23466
- return createUnionOrIntersectionTypeNode(187 /* UnionType */, types);
23653
+ return createUnionOrIntersectionTypeNode(187 /* UnionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
23467
23654
  }
23468
23655
  // @api
23469
23656
  function updateUnionTypeNode(node, types) {
23470
- return updateUnionOrIntersectionTypeNode(node, types);
23657
+ return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
23471
23658
  }
23472
23659
  // @api
23473
23660
  function createIntersectionTypeNode(types) {
23474
- return createUnionOrIntersectionTypeNode(188 /* IntersectionType */, types);
23661
+ return createUnionOrIntersectionTypeNode(188 /* IntersectionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
23475
23662
  }
23476
23663
  // @api
23477
23664
  function updateIntersectionTypeNode(node, types) {
23478
- return updateUnionOrIntersectionTypeNode(node, types);
23665
+ return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
23479
23666
  }
23480
23667
  // @api
23481
23668
  function createConditionalTypeNode(checkType, extendsType, trueType, falseType) {
23482
23669
  var node = createBaseNode(189 /* ConditionalType */);
23483
- node.checkType = parenthesizerRules().parenthesizeMemberOfConditionalType(checkType);
23484
- node.extendsType = parenthesizerRules().parenthesizeMemberOfConditionalType(extendsType);
23670
+ node.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType);
23671
+ node.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType);
23485
23672
  node.trueType = trueType;
23486
23673
  node.falseType = falseType;
23487
23674
  node.transformFlags = 1 /* ContainsTypeScript */;
@@ -23576,7 +23763,9 @@ var ts;
23576
23763
  function createTypeOperatorNode(operator, type) {
23577
23764
  var node = createBaseNode(193 /* TypeOperator */);
23578
23765
  node.operator = operator;
23579
- node.type = parenthesizerRules().parenthesizeMemberOfElementType(type);
23766
+ node.type = operator === 145 /* ReadonlyKeyword */ ?
23767
+ parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) :
23768
+ parenthesizerRules().parenthesizeOperandOfTypeOperator(type);
23580
23769
  node.transformFlags = 1 /* ContainsTypeScript */;
23581
23770
  return node;
23582
23771
  }
@@ -23589,7 +23778,7 @@ var ts;
23589
23778
  // @api
23590
23779
  function createIndexedAccessTypeNode(objectType, indexType) {
23591
23780
  var node = createBaseNode(194 /* IndexedAccessType */);
23592
- node.objectType = parenthesizerRules().parenthesizeMemberOfElementType(objectType);
23781
+ node.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType);
23593
23782
  node.indexType = indexType;
23594
23783
  node.transformFlags = 1 /* ContainsTypeScript */;
23595
23784
  return node;
@@ -25325,8 +25514,15 @@ var ts;
25325
25514
  return createBaseNode(kind);
25326
25515
  }
25327
25516
  // @api
25328
- // createJSDocNonNullableType
25329
25517
  // createJSDocNullableType
25518
+ // createJSDocNonNullableType
25519
+ function createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix) {
25520
+ if (postfix === void 0) { postfix = false; }
25521
+ var node = createJSDocUnaryTypeWorker(kind, postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type);
25522
+ node.postfix = postfix;
25523
+ return node;
25524
+ }
25525
+ // @api
25330
25526
  // createJSDocOptionalType
25331
25527
  // createJSDocVariadicType
25332
25528
  // createJSDocNamepathType
@@ -25338,6 +25534,12 @@ var ts;
25338
25534
  // @api
25339
25535
  // updateJSDocNonNullableType
25340
25536
  // updateJSDocNullableType
25537
+ function updateJSDocPrePostfixUnaryTypeWorker(kind, node, type) {
25538
+ return node.type !== type
25539
+ ? update(createJSDocPrePostfixUnaryTypeWorker(kind, type, node.postfix), node)
25540
+ : node;
25541
+ }
25542
+ // @api
25341
25543
  // updateJSDocOptionalType
25342
25544
  // updateJSDocVariadicType
25343
25545
  // updateJSDocNamepathType
@@ -30418,7 +30620,7 @@ var ts;
30418
30620
  || ts.isExportDeclaration(node) ? node : undefined;
30419
30621
  }
30420
30622
  function getImportMetaIfNecessary(sourceFile) {
30421
- return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
30623
+ return sourceFile.flags & 4194304 /* PossiblyContainsImportMeta */ ?
30422
30624
  walkTreeForImportMeta(sourceFile) :
30423
30625
  undefined;
30424
30626
  }
@@ -31073,7 +31275,7 @@ var ts;
31073
31275
  var newSourceFile = IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
31074
31276
  // Because new source file node is created, it may not have the flag PossiblyContainDynamicImport. This is the case if there is no new edit to add dynamic import.
31075
31277
  // We will manually port the flag to the new source file.
31076
- newSourceFile.flags |= (sourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */);
31278
+ newSourceFile.flags |= (sourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */);
31077
31279
  return newSourceFile;
31078
31280
  }
31079
31281
  ts.updateSourceFile = updateSourceFile;
@@ -31357,10 +31559,10 @@ var ts;
31357
31559
  switch (scriptKind) {
31358
31560
  case 1 /* JS */:
31359
31561
  case 2 /* JSX */:
31360
- contextFlags = 131072 /* JavaScriptFile */;
31562
+ contextFlags = 262144 /* JavaScriptFile */;
31361
31563
  break;
31362
31564
  case 6 /* JSON */:
31363
- contextFlags = 131072 /* JavaScriptFile */ | 33554432 /* JsonFile */;
31565
+ contextFlags = 262144 /* JavaScriptFile */ | 67108864 /* JsonFile */;
31364
31566
  break;
31365
31567
  default:
31366
31568
  contextFlags = 0 /* None */;
@@ -31395,7 +31597,7 @@ var ts;
31395
31597
  function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicator) {
31396
31598
  var isDeclarationFile = isDeclarationFileName(fileName);
31397
31599
  if (isDeclarationFile) {
31398
- contextFlags |= 8388608 /* Ambient */;
31600
+ contextFlags |= 16777216 /* Ambient */;
31399
31601
  }
31400
31602
  sourceFlags = contextFlags;
31401
31603
  // Prime the scanner.
@@ -31434,7 +31636,7 @@ var ts;
31434
31636
  node.jsDoc = jsDoc;
31435
31637
  if (hasDeprecatedTag) {
31436
31638
  hasDeprecatedTag = false;
31437
- node.flags |= 134217728 /* Deprecated */;
31639
+ node.flags |= 268435456 /* Deprecated */;
31438
31640
  }
31439
31641
  return node;
31440
31642
  }
@@ -31629,6 +31831,12 @@ var ts;
31629
31831
  function disallowInAnd(func) {
31630
31832
  return doInsideOfContext(4096 /* DisallowInContext */, func);
31631
31833
  }
31834
+ function allowConditionalTypesAnd(func) {
31835
+ return doOutsideOfContext(65536 /* DisallowConditionalTypesContext */, func);
31836
+ }
31837
+ function disallowConditionalTypesAnd(func) {
31838
+ return doInsideOfContext(65536 /* DisallowConditionalTypesContext */, func);
31839
+ }
31632
31840
  function doInYieldContext(func) {
31633
31841
  return doInsideOfContext(8192 /* YieldContext */, func);
31634
31842
  }
@@ -31656,6 +31864,9 @@ var ts;
31656
31864
  function inDisallowInContext() {
31657
31865
  return inContext(4096 /* DisallowInContext */);
31658
31866
  }
31867
+ function inDisallowConditionalTypesContext() {
31868
+ return inContext(65536 /* DisallowConditionalTypesContext */);
31869
+ }
31659
31870
  function inDecoratorContext() {
31660
31871
  return inContext(16384 /* DecoratorContext */);
31661
31872
  }
@@ -32040,7 +32251,7 @@ var ts;
32040
32251
  // flag so that we don't mark any subsequent nodes.
32041
32252
  if (parseErrorBeforeNextFinishedNode) {
32042
32253
  parseErrorBeforeNextFinishedNode = false;
32043
- node.flags |= 65536 /* ThisNodeHasError */;
32254
+ node.flags |= 131072 /* ThisNodeHasError */;
32044
32255
  }
32045
32256
  return node;
32046
32257
  }
@@ -32498,7 +32709,7 @@ var ts;
32498
32709
  // differently depending on what mode it is in.
32499
32710
  //
32500
32711
  // This also applies to all our other context flags as well.
32501
- var nodeContextFlags = node.flags & 25358336 /* ContextFlags */;
32712
+ var nodeContextFlags = node.flags & 50720768 /* ContextFlags */;
32502
32713
  if (nodeContextFlags !== contextFlags) {
32503
32714
  return undefined;
32504
32715
  }
@@ -32757,7 +32968,6 @@ var ts;
32757
32968
  default: return [undefined]; // TODO: GH#18217 `default: Debug.assertNever(context);`
32758
32969
  }
32759
32970
  }
32760
- // Parses a comma-delimited list of elements
32761
32971
  function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
32762
32972
  var saveParsingContext = parsingContext;
32763
32973
  parsingContext |= 1 << kind;
@@ -32767,7 +32977,11 @@ var ts;
32767
32977
  while (true) {
32768
32978
  if (isListElement(kind, /*inErrorRecovery*/ false)) {
32769
32979
  var startPos = scanner.getStartPos();
32770
- list.push(parseListElement(kind, parseElement));
32980
+ var result = parseListElement(kind, parseElement);
32981
+ if (!result) {
32982
+ return undefined;
32983
+ }
32984
+ list.push(result);
32771
32985
  commaStart = scanner.getTokenPos();
32772
32986
  if (parseOptional(27 /* CommaToken */)) {
32773
32987
  // No need to check for a zero length node since we know we parsed a comma
@@ -33020,7 +33234,7 @@ var ts;
33020
33234
  function parseJSDocNonNullableType() {
33021
33235
  var pos = getNodePos();
33022
33236
  nextToken();
33023
- return finishNode(factory.createJSDocNonNullableType(parseNonArrayType()), pos);
33237
+ return finishNode(factory.createJSDocNonNullableType(parseNonArrayType(), /*postfix*/ false), pos);
33024
33238
  }
33025
33239
  function parseJSDocUnknownOrNullableType() {
33026
33240
  var pos = getNodePos();
@@ -33044,7 +33258,7 @@ var ts;
33044
33258
  return finishNode(factory.createJSDocUnknownType(), pos);
33045
33259
  }
33046
33260
  else {
33047
- return finishNode(factory.createJSDocNullableType(parseType()), pos);
33261
+ return finishNode(factory.createJSDocNullableType(parseType(), /*postfix*/ false), pos);
33048
33262
  }
33049
33263
  }
33050
33264
  function parseJSDocFunctionType() {
@@ -33172,13 +33386,20 @@ var ts;
33172
33386
  }
33173
33387
  return name;
33174
33388
  }
33175
- function parseParameterInOuterAwaitContext() {
33176
- return parseParameterWorker(/*inOuterAwaitContext*/ true);
33389
+ function isParameterNameStart() {
33390
+ // Be permissive about await and yield by calling isBindingIdentifier instead of isIdentifier; disallowing
33391
+ // them during a speculative parse leads to many more follow-on errors than allowing the function to parse then later
33392
+ // complaining about the use of the keywords.
33393
+ return isBindingIdentifier() || token() === 22 /* OpenBracketToken */ || token() === 18 /* OpenBraceToken */;
33394
+ }
33395
+ function parseParameter(inOuterAwaitContext) {
33396
+ return parseParameterWorker(inOuterAwaitContext);
33177
33397
  }
33178
- function parseParameter() {
33179
- return parseParameterWorker(/*inOuterAwaitContext*/ false);
33398
+ function parseParameterForSpeculation(inOuterAwaitContext) {
33399
+ return parseParameterWorker(inOuterAwaitContext, /*allowAmbiguity*/ false);
33180
33400
  }
33181
- function parseParameterWorker(inOuterAwaitContext) {
33401
+ function parseParameterWorker(inOuterAwaitContext, allowAmbiguity) {
33402
+ if (allowAmbiguity === void 0) { allowAmbiguity = true; }
33182
33403
  var pos = getNodePos();
33183
33404
  var hasJSDoc = hasPrecedingJSDocComment();
33184
33405
  // FormalParameter [Yield,Await]:
@@ -33199,13 +33420,17 @@ var ts;
33199
33420
  var savedTopLevel = topLevel;
33200
33421
  topLevel = false;
33201
33422
  var modifiers = parseModifiers();
33202
- var node = withJSDoc(finishNode(factory.createParameterDeclaration(decorators, modifiers, parseOptionalToken(25 /* DotDotDotToken */), parseNameOfParameter(modifiers), parseOptionalToken(57 /* QuestionToken */), parseTypeAnnotation(), parseInitializer()), pos), hasJSDoc);
33423
+ var dotDotDotToken = parseOptionalToken(25 /* DotDotDotToken */);
33424
+ if (!allowAmbiguity && !isParameterNameStart()) {
33425
+ return undefined;
33426
+ }
33427
+ var node = withJSDoc(finishNode(factory.createParameterDeclaration(decorators, modifiers, dotDotDotToken, parseNameOfParameter(modifiers), parseOptionalToken(57 /* QuestionToken */), parseTypeAnnotation(), parseInitializer()), pos), hasJSDoc);
33203
33428
  topLevel = savedTopLevel;
33204
33429
  return node;
33205
33430
  }
33206
33431
  function parseReturnType(returnToken, isType) {
33207
33432
  if (shouldParseReturnType(returnToken, isType)) {
33208
- return parseTypeOrTypePredicate();
33433
+ return allowConditionalTypesAnd(parseTypeOrTypePredicate);
33209
33434
  }
33210
33435
  }
33211
33436
  function shouldParseReturnType(returnToken, isType) {
@@ -33224,7 +33449,7 @@ var ts;
33224
33449
  }
33225
33450
  return false;
33226
33451
  }
33227
- function parseParametersWorker(flags) {
33452
+ function parseParametersWorker(flags, allowAmbiguity) {
33228
33453
  // FormalParameters [Yield,Await]: (modified)
33229
33454
  // [empty]
33230
33455
  // FormalParameterList[?Yield,Await]
@@ -33244,7 +33469,7 @@ var ts;
33244
33469
  setAwaitContext(!!(flags & 2 /* Await */));
33245
33470
  var parameters = flags & 32 /* JSDoc */ ?
33246
33471
  parseDelimitedList(17 /* JSDocParameters */, parseJSDocParameter) :
33247
- parseDelimitedList(16 /* Parameters */, savedAwaitContext ? parseParameterInOuterAwaitContext : parseParameter);
33472
+ parseDelimitedList(16 /* Parameters */, function () { return allowAmbiguity ? parseParameter(savedAwaitContext) : parseParameterForSpeculation(savedAwaitContext); });
33248
33473
  setYieldContext(savedYieldContext);
33249
33474
  setAwaitContext(savedAwaitContext);
33250
33475
  return parameters;
@@ -33266,7 +33491,7 @@ var ts;
33266
33491
  if (!parseExpected(20 /* OpenParenToken */)) {
33267
33492
  return createMissingList();
33268
33493
  }
33269
- var parameters = parseParametersWorker(flags);
33494
+ var parameters = parseParametersWorker(flags, /*allowAmbiguity*/ true);
33270
33495
  parseExpected(21 /* CloseParenToken */);
33271
33496
  return parameters;
33272
33497
  }
@@ -33348,7 +33573,7 @@ var ts;
33348
33573
  return token() === 58 /* ColonToken */ || token() === 27 /* CommaToken */ || token() === 23 /* CloseBracketToken */;
33349
33574
  }
33350
33575
  function parseIndexSignatureDeclaration(pos, hasJSDoc, decorators, modifiers) {
33351
- var parameters = parseBracketedList(16 /* Parameters */, parseParameter, 22 /* OpenBracketToken */, 23 /* CloseBracketToken */);
33576
+ var parameters = parseBracketedList(16 /* Parameters */, function () { return parseParameter(/*inOuterAwaitContext*/ false); }, 22 /* OpenBracketToken */, 23 /* CloseBracketToken */);
33352
33577
  var type = parseTypeAnnotation();
33353
33578
  parseTypeMemberSemicolon();
33354
33579
  var node = factory.createIndexSignature(decorators, modifiers, parameters, type);
@@ -33620,7 +33845,7 @@ var ts;
33620
33845
  return finishNode(factory.createImportTypeAssertionContainer(clause, multiLine), pos);
33621
33846
  }
33622
33847
  function parseImportType() {
33623
- sourceFlags |= 1048576 /* PossiblyContainsDynamicImport */;
33848
+ sourceFlags |= 2097152 /* PossiblyContainsDynamicImport */;
33624
33849
  var pos = getNodePos();
33625
33850
  var isTypeOf = parseOptional(112 /* TypeOfKeyword */);
33626
33851
  parseExpected(100 /* ImportKeyword */);
@@ -33770,7 +33995,7 @@ var ts;
33770
33995
  switch (token()) {
33771
33996
  case 53 /* ExclamationToken */:
33772
33997
  nextToken();
33773
- type = finishNode(factory.createJSDocNonNullableType(type), pos);
33998
+ type = finishNode(factory.createJSDocNonNullableType(type, /*postfix*/ true), pos);
33774
33999
  break;
33775
34000
  case 57 /* QuestionToken */:
33776
34001
  // If next token is start of a type we have a conditional type
@@ -33778,7 +34003,7 @@ var ts;
33778
34003
  return type;
33779
34004
  }
33780
34005
  nextToken();
33781
- type = finishNode(factory.createJSDocNullableType(type), pos);
34006
+ type = finishNode(factory.createJSDocNullableType(type, /*postfix*/ true), pos);
33782
34007
  break;
33783
34008
  case 22 /* OpenBracketToken */:
33784
34009
  parseExpected(22 /* OpenBracketToken */);
@@ -33803,12 +34028,20 @@ var ts;
33803
34028
  parseExpected(operator);
33804
34029
  return finishNode(factory.createTypeOperatorNode(operator, parseTypeOperatorOrHigher()), pos);
33805
34030
  }
34031
+ function tryParseConstraintOfInferType() {
34032
+ if (parseOptional(94 /* ExtendsKeyword */)) {
34033
+ var constraint = disallowConditionalTypesAnd(parseType);
34034
+ if (inDisallowConditionalTypesContext() || token() !== 57 /* QuestionToken */) {
34035
+ return constraint;
34036
+ }
34037
+ }
34038
+ }
33806
34039
  function parseTypeParameterOfInferType() {
33807
34040
  var pos = getNodePos();
33808
- return finishNode(factory.createTypeParameterDeclaration(
33809
- /*modifiers*/ undefined, parseIdentifier(),
33810
- /*constraint*/ undefined,
33811
- /*defaultType*/ undefined), pos);
34041
+ var name = parseIdentifier();
34042
+ var constraint = tryParse(tryParseConstraintOfInferType);
34043
+ var node = factory.createTypeParameterDeclaration(/*modifiers*/ undefined, name, constraint);
34044
+ return finishNode(node, pos);
33812
34045
  }
33813
34046
  function parseInferType() {
33814
34047
  var pos = getNodePos();
@@ -33825,7 +34058,7 @@ var ts;
33825
34058
  case 137 /* InferKeyword */:
33826
34059
  return parseInferType();
33827
34060
  }
33828
- return parsePostfixTypeOrHigher();
34061
+ return allowConditionalTypesAnd(parsePostfixTypeOrHigher);
33829
34062
  }
33830
34063
  function parseFunctionOrConstructorTypeToError(isInUnionType) {
33831
34064
  // the function type and constructor type shorthand notation
@@ -33955,23 +34188,21 @@ var ts;
33955
34188
  return finishNode(factory.createTypePredicateNode(assertsModifier, parameterName, type), pos);
33956
34189
  }
33957
34190
  function parseType() {
33958
- // The rules about 'yield' only apply to actual code/expression contexts. They don't
33959
- // apply to 'type' contexts. So we disable these parameters here before moving on.
33960
- return doOutsideOfContext(40960 /* TypeExcludesFlags */, parseTypeWorker);
33961
- }
33962
- function parseTypeWorker(noConditionalTypes) {
34191
+ if (contextFlags & 40960 /* TypeExcludesFlags */) {
34192
+ return doOutsideOfContext(40960 /* TypeExcludesFlags */, parseType);
34193
+ }
33963
34194
  if (isStartOfFunctionTypeOrConstructorType()) {
33964
34195
  return parseFunctionOrConstructorType();
33965
34196
  }
33966
34197
  var pos = getNodePos();
33967
34198
  var type = parseUnionTypeOrHigher();
33968
- if (!noConditionalTypes && !scanner.hasPrecedingLineBreak() && parseOptional(94 /* ExtendsKeyword */)) {
34199
+ if (!inDisallowConditionalTypesContext() && !scanner.hasPrecedingLineBreak() && parseOptional(94 /* ExtendsKeyword */)) {
33969
34200
  // The type following 'extends' is not permitted to be another conditional type
33970
- var extendsType = parseTypeWorker(/*noConditionalTypes*/ true);
34201
+ var extendsType = disallowConditionalTypesAnd(parseType);
33971
34202
  parseExpected(57 /* QuestionToken */);
33972
- var trueType = parseTypeWorker();
34203
+ var trueType = allowConditionalTypesAnd(parseType);
33973
34204
  parseExpected(58 /* ColonToken */);
33974
- var falseType = parseTypeWorker();
34205
+ var falseType = allowConditionalTypesAnd(parseType);
33975
34206
  return finishNode(factory.createConditionalTypeNode(type, extendsType, trueType, falseType), pos);
33976
34207
  }
33977
34208
  return type;
@@ -34398,7 +34629,16 @@ var ts;
34398
34629
  parameters = createMissingList();
34399
34630
  }
34400
34631
  else {
34401
- parameters = parseParametersWorker(isAsync);
34632
+ if (!allowAmbiguity) {
34633
+ var maybeParameters = parseParametersWorker(isAsync, allowAmbiguity);
34634
+ if (!maybeParameters) {
34635
+ return undefined;
34636
+ }
34637
+ parameters = maybeParameters;
34638
+ }
34639
+ else {
34640
+ parameters = parseParametersWorker(isAsync, allowAmbiguity);
34641
+ }
34402
34642
  if (!parseExpected(21 /* CloseParenToken */) && !allowAmbiguity) {
34403
34643
  return undefined;
34404
34644
  }
@@ -34799,7 +35039,7 @@ var ts;
34799
35039
  // var foo3 = require("subfolder
34800
35040
  // import * as foo1 from "module-from-node
34801
35041
  // We want this import to be a statement rather than import call expression
34802
- sourceFlags |= 1048576 /* PossiblyContainsDynamicImport */;
35042
+ sourceFlags |= 2097152 /* PossiblyContainsDynamicImport */;
34803
35043
  expression = parseTokenNode();
34804
35044
  }
34805
35045
  else if (lookAhead(nextTokenIsDot)) {
@@ -34807,7 +35047,7 @@ var ts;
34807
35047
  nextToken(); // advance past the 'import'
34808
35048
  nextToken(); // advance past the dot
34809
35049
  expression = finishNode(factory.createMetaProperty(100 /* ImportKeyword */, parseIdentifierName()), pos);
34810
- sourceFlags |= 2097152 /* PossiblyContainsImportMeta */;
35050
+ sourceFlags |= 4194304 /* PossiblyContainsImportMeta */;
34811
35051
  }
34812
35052
  else {
34813
35053
  expression = parseMemberExpressionOrHigher();
@@ -35023,7 +35263,7 @@ var ts;
35023
35263
  return finishNode(factory.createJsxOpeningFragment(), pos);
35024
35264
  }
35025
35265
  var tagName = parseJsxElementName();
35026
- var typeArguments = (contextFlags & 131072 /* JavaScriptFile */) === 0 ? tryParseTypeArguments() : undefined;
35266
+ var typeArguments = (contextFlags & 262144 /* JavaScriptFile */) === 0 ? tryParseTypeArguments() : undefined;
35027
35267
  var attributes = parseJsxAttributes();
35028
35268
  var node;
35029
35269
  if (token() === 31 /* GreaterThanToken */) {
@@ -35301,7 +35541,7 @@ var ts;
35301
35541
  return result;
35302
35542
  }
35303
35543
  function parseTypeArgumentsInExpression() {
35304
- if ((contextFlags & 131072 /* JavaScriptFile */) !== 0) {
35544
+ if ((contextFlags & 262144 /* JavaScriptFile */) !== 0) {
35305
35545
  // TypeArguments must not be parsed in JavaScript files to avoid ambiguity with binary operators.
35306
35546
  return undefined;
35307
35547
  }
@@ -35697,7 +35937,7 @@ var ts;
35697
35937
  var openParenParsed = parseExpected(20 /* OpenParenToken */);
35698
35938
  var expression = allowInAnd(parseExpression);
35699
35939
  parseExpectedMatchingBrackets(20 /* OpenParenToken */, 21 /* CloseParenToken */, openParenParsed, openParenPosition);
35700
- var statement = doInsideOfContext(16777216 /* InWithStatement */, parseStatement);
35940
+ var statement = doInsideOfContext(33554432 /* InWithStatement */, parseStatement);
35701
35941
  return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc);
35702
35942
  }
35703
35943
  function parseCaseClause() {
@@ -36072,16 +36312,16 @@ var ts;
36072
36312
  if (isAmbient) {
36073
36313
  for (var _i = 0, _a = modifiers; _i < _a.length; _i++) {
36074
36314
  var m = _a[_i];
36075
- m.flags |= 8388608 /* Ambient */;
36315
+ m.flags |= 16777216 /* Ambient */;
36076
36316
  }
36077
- return doInsideOfContext(8388608 /* Ambient */, function () { return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers); });
36317
+ return doInsideOfContext(16777216 /* Ambient */, function () { return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers); });
36078
36318
  }
36079
36319
  else {
36080
36320
  return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers);
36081
36321
  }
36082
36322
  }
36083
36323
  function tryReuseAmbientDeclaration() {
36084
- return doInsideOfContext(8388608 /* Ambient */, function () {
36324
+ return doInsideOfContext(16777216 /* Ambient */, function () {
36085
36325
  var node = currentNode(parsingContext);
36086
36326
  if (node) {
36087
36327
  return consumeNode(node);
@@ -36548,9 +36788,9 @@ var ts;
36548
36788
  if (isAmbient) {
36549
36789
  for (var _i = 0, _a = modifiers; _i < _a.length; _i++) {
36550
36790
  var m = _a[_i];
36551
- m.flags |= 8388608 /* Ambient */;
36791
+ m.flags |= 16777216 /* Ambient */;
36552
36792
  }
36553
- return doInsideOfContext(8388608 /* Ambient */, function () { return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers); });
36793
+ return doInsideOfContext(16777216 /* Ambient */, function () { return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers); });
36554
36794
  }
36555
36795
  else {
36556
36796
  return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers);
@@ -37115,7 +37355,7 @@ var ts;
37115
37355
  function parseJSDocTypeExpression(mayOmitBraces) {
37116
37356
  var pos = getNodePos();
37117
37357
  var hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(18 /* OpenBraceToken */);
37118
- var type = doInsideOfContext(4194304 /* JSDoc */, parseJSDocType);
37358
+ var type = doInsideOfContext(8388608 /* JSDoc */, parseJSDocType);
37119
37359
  if (!mayOmitBraces || hasBrace) {
37120
37360
  parseExpectedJSDoc(19 /* CloseBraceToken */);
37121
37361
  }
@@ -37144,7 +37384,7 @@ var ts;
37144
37384
  JSDocParser.parseJSDocNameReference = parseJSDocNameReference;
37145
37385
  function parseIsolatedJSDocComment(content, start, length) {
37146
37386
  initializeState("", content, 99 /* Latest */, /*_syntaxCursor:*/ undefined, 1 /* JS */);
37147
- var jsDoc = doInsideOfContext(4194304 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37387
+ var jsDoc = doInsideOfContext(8388608 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37148
37388
  var sourceFile = { languageVariant: 0 /* Standard */, text: content };
37149
37389
  var diagnostics = ts.attachFileToDiagnostics(parseDiagnostics, sourceFile);
37150
37390
  clearState();
@@ -37155,9 +37395,9 @@ var ts;
37155
37395
  var saveToken = currentToken;
37156
37396
  var saveParseDiagnosticsLength = parseDiagnostics.length;
37157
37397
  var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
37158
- var comment = doInsideOfContext(4194304 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37398
+ var comment = doInsideOfContext(8388608 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37159
37399
  ts.setParent(comment, parent);
37160
- if (contextFlags & 131072 /* JavaScriptFile */) {
37400
+ if (contextFlags & 262144 /* JavaScriptFile */) {
37161
37401
  if (!jsDocDiagnostics) {
37162
37402
  jsDocDiagnostics = [];
37163
37403
  }
@@ -37973,7 +38213,7 @@ var ts;
37973
38213
  if (isBracketed) {
37974
38214
  skipWhitespace();
37975
38215
  parseExpected(63 /* EqualsToken */);
37976
- defaultType = doInsideOfContext(4194304 /* JSDoc */, parseJSDocType);
38216
+ defaultType = doInsideOfContext(8388608 /* JSDoc */, parseJSDocType);
37977
38217
  parseExpected(23 /* CloseBracketToken */);
37978
38218
  }
37979
38219
  if (ts.nodeIsMissing(name)) {
@@ -45727,6 +45967,7 @@ var ts;
45727
45967
  case 261 /* ModuleDeclaration */:
45728
45968
  case 259 /* TypeAliasDeclaration */:
45729
45969
  case 195 /* MappedType */:
45970
+ case 176 /* IndexSignature */:
45730
45971
  return 1 /* IsContainer */ | 32 /* HasLocals */;
45731
45972
  case 305 /* SourceFile */:
45732
45973
  return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */;
@@ -45745,7 +45986,6 @@ var ts;
45745
45986
  case 317 /* JSDocFunctionType */:
45746
45987
  case 179 /* FunctionType */:
45747
45988
  case 175 /* ConstructSignature */:
45748
- case 176 /* IndexSignature */:
45749
45989
  case 180 /* ConstructorType */:
45750
45990
  case 170 /* ClassStaticBlockDeclaration */:
45751
45991
  return 1 /* IsContainer */ | 4 /* IsControlFlowContainer */ | 32 /* HasLocals */ | 8 /* IsFunctionLike */;
@@ -45861,7 +46101,7 @@ var ts;
45861
46101
  function setExportContextFlag(node) {
45862
46102
  // A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
45863
46103
  // declarations with export modifiers) is an export context in which declarations are implicitly exported.
45864
- if (node.flags & 8388608 /* Ambient */ && !hasExportDeclarations(node)) {
46104
+ if (node.flags & 16777216 /* Ambient */ && !hasExportDeclarations(node)) {
45865
46105
  node.flags |= 64 /* ExportContext */;
45866
46106
  }
45867
46107
  else {
@@ -46064,8 +46304,8 @@ var ts;
46064
46304
  function checkContextualIdentifier(node) {
46065
46305
  // Report error only if there are no parse errors in file
46066
46306
  if (!file.parseDiagnostics.length &&
46067
- !(node.flags & 8388608 /* Ambient */) &&
46068
- !(node.flags & 4194304 /* JSDoc */) &&
46307
+ !(node.flags & 16777216 /* Ambient */) &&
46308
+ !(node.flags & 8388608 /* JSDoc */) &&
46069
46309
  !ts.isIdentifierName(node)) {
46070
46310
  // strict mode identifiers
46071
46311
  if (inStrictMode &&
@@ -47094,7 +47334,7 @@ var ts;
47094
47334
  if (node.kind === 340 /* JSDocParameterTag */ && container.kind !== 323 /* JSDocSignature */) {
47095
47335
  return;
47096
47336
  }
47097
- if (inStrictMode && !(node.flags & 8388608 /* Ambient */)) {
47337
+ if (inStrictMode && !(node.flags & 16777216 /* Ambient */)) {
47098
47338
  // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
47099
47339
  // strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
47100
47340
  checkStrictModeEvalOrArguments(node, node.name);
@@ -47113,7 +47353,7 @@ var ts;
47113
47353
  }
47114
47354
  }
47115
47355
  function bindFunctionDeclaration(node) {
47116
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */)) {
47356
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */)) {
47117
47357
  if (ts.isAsyncFunction(node)) {
47118
47358
  emitFlags |= 2048 /* HasAsyncFunctions */;
47119
47359
  }
@@ -47128,7 +47368,7 @@ var ts;
47128
47368
  }
47129
47369
  }
47130
47370
  function bindFunctionExpression(node) {
47131
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */)) {
47371
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */)) {
47132
47372
  if (ts.isAsyncFunction(node)) {
47133
47373
  emitFlags |= 2048 /* HasAsyncFunctions */;
47134
47374
  }
@@ -47141,7 +47381,7 @@ var ts;
47141
47381
  return bindAnonymousDeclaration(node, 16 /* Function */, bindingName);
47142
47382
  }
47143
47383
  function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
47144
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */) && ts.isAsyncFunction(node)) {
47384
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */) && ts.isAsyncFunction(node)) {
47145
47385
  emitFlags |= 2048 /* HasAsyncFunctions */;
47146
47386
  }
47147
47387
  if (currentFlow && ts.isObjectLiteralOrClassExpressionMethodOrAccessor(node)) {
@@ -47214,7 +47454,7 @@ var ts;
47214
47454
  // Rationale: we don't want to report errors on non-initialized var's since they are hoisted
47215
47455
  // On the other side we do want to report errors on non-initialized 'lets' because of TDZ
47216
47456
  var isError_1 = ts.unreachableCodeIsError(options) &&
47217
- !(node.flags & 8388608 /* Ambient */) &&
47457
+ !(node.flags & 16777216 /* Ambient */) &&
47218
47458
  (!ts.isVariableStatement(node) ||
47219
47459
  !!(ts.getCombinedNodeFlags(node.declarationList) & 3 /* BlockScoped */) ||
47220
47460
  node.declarationList.declarations.some(function (d) { return !!d.initializer; }));
@@ -48114,7 +48354,7 @@ var ts;
48114
48354
  ts.Debug.assert(!!(getNodeLinks(file).flags & 1 /* TypeChecked */));
48115
48355
  diagnostics = ts.addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName));
48116
48356
  checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) {
48117
- if (!ts.containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
48357
+ if (!ts.containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 16777216 /* Ambient */))) {
48118
48358
  (diagnostics || (diagnostics = [])).push(__assign(__assign({}, diag), { category: ts.DiagnosticCategory.Suggestion }));
48119
48359
  }
48120
48360
  });
@@ -48565,7 +48805,7 @@ var ts;
48565
48805
  return diagnostic;
48566
48806
  }
48567
48807
  function isDeprecatedSymbol(symbol) {
48568
- return !!(getDeclarationNodeFlagsFromSymbol(symbol) & 134217728 /* Deprecated */);
48808
+ return !!(getDeclarationNodeFlagsFromSymbol(symbol) & 268435456 /* Deprecated */);
48569
48809
  }
48570
48810
  function addDeprecatedSuggestion(location, declarations, deprecatedEntity) {
48571
48811
  var diagnostic = ts.createDiagnosticForNode(location, ts.Diagnostics._0_is_deprecated, deprecatedEntity);
@@ -48793,7 +49033,7 @@ var ts;
48793
49033
  else {
48794
49034
  // find a module that about to be augmented
48795
49035
  // do not validate names of augmentations that are defined in ambient context
48796
- var moduleNotFoundError = !(moduleName.parent.parent.flags & 8388608 /* Ambient */)
49036
+ var moduleNotFoundError = !(moduleName.parent.parent.flags & 16777216 /* Ambient */)
48797
49037
  ? ts.Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
48798
49038
  : undefined;
48799
49039
  var mainModule_1 = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*isForAugmentation*/ true);
@@ -48907,7 +49147,7 @@ var ts;
48907
49147
  if ((moduleKind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
48908
49148
  (!ts.outFile(compilerOptions)) ||
48909
49149
  isInTypeQuery(usage) ||
48910
- declaration.flags & 8388608 /* Ambient */) {
49150
+ declaration.flags & 16777216 /* Ambient */) {
48911
49151
  // nodes are in different files and order cannot be determined
48912
49152
  return true;
48913
49153
  }
@@ -48969,7 +49209,7 @@ var ts;
48969
49209
  if (usage.kind === 271 /* ExportAssignment */ && usage.isExportEquals) {
48970
49210
  return true;
48971
49211
  }
48972
- if (!!(usage.flags & 4194304 /* JSDoc */) || isInTypeQuery(usage) || usageInTypeDeclaration()) {
49212
+ if (!!(usage.flags & 8388608 /* JSDoc */) || isInTypeQuery(usage) || usageInTypeDeclaration()) {
48973
49213
  return true;
48974
49214
  }
48975
49215
  if (isUsedInFunctionOrInstanceProperty(usage, declaration)) {
@@ -49234,7 +49474,7 @@ var ts;
49234
49474
  // falls through
49235
49475
  case 261 /* ModuleDeclaration */:
49236
49476
  var moduleExports = ((_a = getSymbolOfNode(location)) === null || _a === void 0 ? void 0 : _a.exports) || emptySymbols;
49237
- if (location.kind === 305 /* SourceFile */ || (ts.isModuleDeclaration(location) && location.flags & 8388608 /* Ambient */ && !ts.isGlobalScopeAugmentation(location))) {
49477
+ if (location.kind === 305 /* SourceFile */ || (ts.isModuleDeclaration(location) && location.flags & 16777216 /* Ambient */ && !ts.isGlobalScopeAugmentation(location))) {
49238
49478
  // It's an external module. First see if the module has an export default and if the local
49239
49479
  // name of that export default matches.
49240
49480
  if (result = moduleExports.get("default" /* Default */)) {
@@ -49557,7 +49797,7 @@ var ts;
49557
49797
  }
49558
49798
  }
49559
49799
  // If we're in an external module, we can't reference value symbols created from UMD export declarations
49560
- if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 4194304 /* JSDoc */)) {
49800
+ if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 8388608 /* JSDoc */)) {
49561
49801
  var merged = getMergedSymbol(result);
49562
49802
  if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
49563
49803
  errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, ts.unescapeLeadingUnderscores(name));
@@ -49812,7 +50052,7 @@ var ts;
49812
50052
  var declaration = (_a = result.declarations) === null || _a === void 0 ? void 0 : _a.find(function (d) { return ts.isBlockOrCatchScoped(d) || ts.isClassLike(d) || (d.kind === 260 /* EnumDeclaration */); });
49813
50053
  if (declaration === undefined)
49814
50054
  return ts.Debug.fail("checkResolvedBlockScopedVariable could not find block-scoped declaration");
49815
- if (!(declaration.flags & 8388608 /* Ambient */) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
50055
+ if (!(declaration.flags & 16777216 /* Ambient */) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
49816
50056
  var diagnosticMessage = void 0;
49817
50057
  var declarationName = ts.declarationNameToString(ts.getNameOfDeclaration(declaration));
49818
50058
  if (result.flags & 2 /* BlockScopedVariable */) {
@@ -50323,27 +50563,27 @@ var ts;
50323
50563
  function resolveAlias(symbol) {
50324
50564
  ts.Debug.assert((symbol.flags & 2097152 /* Alias */) !== 0, "Should only get Alias here.");
50325
50565
  var links = getSymbolLinks(symbol);
50326
- if (!links.target) {
50327
- links.target = resolvingSymbol;
50566
+ if (!links.aliasTarget) {
50567
+ links.aliasTarget = resolvingSymbol;
50328
50568
  var node = getDeclarationOfAliasSymbol(symbol);
50329
50569
  if (!node)
50330
50570
  return ts.Debug.fail();
50331
50571
  var target = getTargetOfAliasDeclaration(node);
50332
- if (links.target === resolvingSymbol) {
50333
- links.target = target || unknownSymbol;
50572
+ if (links.aliasTarget === resolvingSymbol) {
50573
+ links.aliasTarget = target || unknownSymbol;
50334
50574
  }
50335
50575
  else {
50336
50576
  error(node, ts.Diagnostics.Circular_definition_of_import_alias_0, symbolToString(symbol));
50337
50577
  }
50338
50578
  }
50339
- else if (links.target === resolvingSymbol) {
50340
- links.target = unknownSymbol;
50579
+ else if (links.aliasTarget === resolvingSymbol) {
50580
+ links.aliasTarget = unknownSymbol;
50341
50581
  }
50342
- return links.target;
50582
+ return links.aliasTarget;
50343
50583
  }
50344
50584
  function tryResolveAlias(symbol) {
50345
50585
  var links = getSymbolLinks(symbol);
50346
- if (links.target !== resolvingSymbol) {
50586
+ if (links.aliasTarget !== resolvingSymbol) {
50347
50587
  return resolveAlias(symbol);
50348
50588
  }
50349
50589
  return undefined;
@@ -50585,7 +50825,7 @@ var ts;
50585
50825
  }
50586
50826
  }
50587
50827
  function getAssignmentDeclarationLocation(node) {
50588
- var typeAlias = ts.findAncestor(node, function (node) { return !(ts.isJSDocNode(node) || node.flags & 4194304 /* JSDoc */) ? "quit" : ts.isJSDocTypeAlias(node); });
50828
+ var typeAlias = ts.findAncestor(node, function (node) { return !(ts.isJSDocNode(node) || node.flags & 8388608 /* JSDoc */) ? "quit" : ts.isJSDocTypeAlias(node); });
50589
50829
  if (typeAlias) {
50590
50830
  return;
50591
50831
  }
@@ -52053,7 +52293,20 @@ var ts;
52053
52293
  if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
52054
52294
  if (type.flags & 262144 /* TypeParameter */ && ts.contains(context.inferTypeParameters, type)) {
52055
52295
  context.approximateLength += (ts.symbolName(type.symbol).length + 6);
52056
- return ts.factory.createInferTypeNode(typeParameterToDeclarationWithConstraint(type, context, /*constraintNode*/ undefined));
52296
+ var constraintNode = void 0;
52297
+ var constraint = getConstraintOfTypeParameter(type);
52298
+ if (constraint) {
52299
+ // If the infer type has a constraint that is not the same as the constraint
52300
+ // we would have normally inferred based on context, we emit the constraint
52301
+ // using `infer T extends ?`. We omit inferred constraints from type references
52302
+ // as they may be elided.
52303
+ var inferredConstraint = getInferredTypeParameterConstraint(type, /*omitTypeReferences*/ true);
52304
+ if (!(inferredConstraint && isTypeIdenticalTo(constraint, inferredConstraint))) {
52305
+ context.approximateLength += 9;
52306
+ constraintNode = constraint && typeToTypeNodeHelper(constraint, context);
52307
+ }
52308
+ }
52309
+ return ts.factory.createInferTypeNode(typeParameterToDeclarationWithConstraint(type, context, constraintNode));
52057
52310
  }
52058
52311
  if (context.flags & 4 /* GenerateNamesForShadowedTypeParams */ &&
52059
52312
  type.flags & 262144 /* TypeParameter */ &&
@@ -52127,13 +52380,37 @@ var ts;
52127
52380
  return ts.Debug.fail("Should be unreachable.");
52128
52381
  function conditionalTypeToTypeNode(type) {
52129
52382
  var checkTypeNode = typeToTypeNodeHelper(type.checkType, context);
52383
+ context.approximateLength += 15;
52384
+ if (context.flags & 4 /* GenerateNamesForShadowedTypeParams */ && type.root.isDistributive && !(type.checkType.flags & 262144 /* TypeParameter */)) {
52385
+ var newParam = createTypeParameter(createSymbol(262144 /* TypeParameter */, "T"));
52386
+ var name = typeParameterToName(newParam, context);
52387
+ var newTypeVariable = ts.factory.createTypeReferenceNode(name);
52388
+ context.approximateLength += 37; // 15 each for two added conditionals, 7 for an added infer type
52389
+ var newMapper = prependTypeMapping(type.root.checkType, newParam, type.combinedMapper || type.mapper);
52390
+ var saveInferTypeParameters_1 = context.inferTypeParameters;
52391
+ context.inferTypeParameters = type.root.inferTypeParameters;
52392
+ var extendsTypeNode_1 = typeToTypeNodeHelper(instantiateType(type.root.extendsType, newMapper), context);
52393
+ context.inferTypeParameters = saveInferTypeParameters_1;
52394
+ var trueTypeNode_1 = typeToTypeNodeOrCircularityElision(instantiateType(getTypeFromTypeNode(type.root.node.trueType), newMapper));
52395
+ var falseTypeNode_1 = typeToTypeNodeOrCircularityElision(instantiateType(getTypeFromTypeNode(type.root.node.falseType), newMapper));
52396
+ // outermost conditional makes `T` a type parameter, allowing the inner conditionals to be distributive
52397
+ // second conditional makes `T` have `T & checkType` substitution, so it is correctly usable as the checkType
52398
+ // inner conditional runs the check the user provided on the check type (distributively) and returns the result
52399
+ // checkType extends infer T ? T extends checkType ? T extends extendsType<T> ? trueType<T> : falseType<T> : never : never;
52400
+ // this is potentially simplifiable to
52401
+ // checkType extends infer T ? T extends checkType & extendsType<T> ? trueType<T> : falseType<T> : never;
52402
+ // but that may confuse users who read the output more.
52403
+ // On the other hand,
52404
+ // checkType extends infer T extends checkType ? T extends extendsType<T> ? trueType<T> : falseType<T> : never;
52405
+ // may also work with `infer ... extends ...` in, but would produce declarations only compatible with the latest TS.
52406
+ return ts.factory.createConditionalTypeNode(checkTypeNode, ts.factory.createInferTypeNode(ts.factory.createTypeParameterDeclaration(/*modifiers*/ undefined, ts.factory.cloneNode(newTypeVariable.typeName))), ts.factory.createConditionalTypeNode(ts.factory.createTypeReferenceNode(ts.factory.cloneNode(name)), typeToTypeNodeHelper(type.checkType, context), ts.factory.createConditionalTypeNode(newTypeVariable, extendsTypeNode_1, trueTypeNode_1, falseTypeNode_1), ts.factory.createKeywordTypeNode(143 /* NeverKeyword */)), ts.factory.createKeywordTypeNode(143 /* NeverKeyword */));
52407
+ }
52130
52408
  var saveInferTypeParameters = context.inferTypeParameters;
52131
52409
  context.inferTypeParameters = type.root.inferTypeParameters;
52132
52410
  var extendsTypeNode = typeToTypeNodeHelper(type.extendsType, context);
52133
52411
  context.inferTypeParameters = saveInferTypeParameters;
52134
52412
  var trueTypeNode = typeToTypeNodeOrCircularityElision(getTrueTypeFromConditionalType(type));
52135
52413
  var falseTypeNode = typeToTypeNodeOrCircularityElision(getFalseTypeFromConditionalType(type));
52136
- context.approximateLength += 15;
52137
52414
  return ts.factory.createConditionalTypeNode(checkTypeNode, extendsTypeNode, trueTypeNode, falseTypeNode);
52138
52415
  }
52139
52416
  function typeToTypeNodeOrCircularityElision(type) {
@@ -54009,7 +54286,7 @@ var ts;
54009
54286
  newModifierFlags |= 1 /* Export */;
54010
54287
  }
54011
54288
  if (addingDeclare && !(newModifierFlags & 1 /* Export */) &&
54012
- (!enclosingDeclaration_1 || !(enclosingDeclaration_1.flags & 8388608 /* Ambient */)) &&
54289
+ (!enclosingDeclaration_1 || !(enclosingDeclaration_1.flags & 16777216 /* Ambient */)) &&
54013
54290
  (ts.isEnumDeclaration(node) || ts.isVariableStatement(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isModuleDeclaration(node))) {
54014
54291
  // Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope
54015
54292
  newModifierFlags |= 2 /* Ambient */;
@@ -54979,7 +55256,7 @@ var ts;
54979
55256
  var parent = getDeclarationContainer(node);
54980
55257
  // If the node is not exported or it is not ambient module element (except import declaration)
54981
55258
  if (!(ts.getCombinedModifierFlags(node) & 1 /* Export */) &&
54982
- !(node.kind !== 265 /* ImportEqualsDeclaration */ && parent.kind !== 305 /* SourceFile */ && parent.flags & 8388608 /* Ambient */)) {
55259
+ !(node.kind !== 265 /* ImportEqualsDeclaration */ && parent.kind !== 305 /* SourceFile */ && parent.flags & 16777216 /* Ambient */)) {
54983
55260
  return isGlobalSourceFile(parent);
54984
55261
  }
54985
55262
  // Exported members/ambient module elements (exception import declaration) are visible if parent is visible
@@ -55319,7 +55596,7 @@ var ts;
55319
55596
  }
55320
55597
  var pattern = declaration.parent;
55321
55598
  // Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
55322
- if (strictNullChecks && declaration.flags & 8388608 /* Ambient */ && ts.isParameterDeclaration(declaration)) {
55599
+ if (strictNullChecks && declaration.flags & 16777216 /* Ambient */ && ts.isParameterDeclaration(declaration)) {
55323
55600
  parentType = getNonNullableType(parentType);
55324
55601
  }
55325
55602
  // Filter `undefined` from the type we check against if the parent has an initializer and that initializer is not possibly `undefined`
@@ -55435,7 +55712,7 @@ var ts;
55435
55712
  }
55436
55713
  if ((noImplicitAny || ts.isInJSFile(declaration)) &&
55437
55714
  ts.isVariableDeclaration(declaration) && !ts.isBindingPattern(declaration.name) &&
55438
- !(ts.getCombinedModifierFlags(declaration) & 1 /* Export */) && !(declaration.flags & 8388608 /* Ambient */)) {
55715
+ !(ts.getCombinedModifierFlags(declaration) & 1 /* Export */) && !(declaration.flags & 16777216 /* Ambient */)) {
55439
55716
  // If --noImplicitAny is on or the declaration is in a Javascript file,
55440
55717
  // use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
55441
55718
  // initializer or a 'null' or 'undefined' initializer.
@@ -56891,7 +57168,7 @@ var ts;
56891
57168
  function isLiteralEnumMember(member) {
56892
57169
  var expr = member.initializer;
56893
57170
  if (!expr) {
56894
- return !(member.flags & 8388608 /* Ambient */);
57171
+ return !(member.flags & 16777216 /* Ambient */);
56895
57172
  }
56896
57173
  switch (expr.kind) {
56897
57174
  case 10 /* StringLiteral */:
@@ -59524,7 +59801,7 @@ var ts;
59524
59801
  function getConstraintDeclaration(type) {
59525
59802
  return ts.mapDefined(ts.filter(type.symbol && type.symbol.declarations, ts.isTypeParameterDeclaration), ts.getEffectiveConstraintOfTypeParameter)[0];
59526
59803
  }
59527
- function getInferredTypeParameterConstraint(typeParameter) {
59804
+ function getInferredTypeParameterConstraint(typeParameter, omitTypeReferences) {
59528
59805
  var _a;
59529
59806
  var inferences;
59530
59807
  if ((_a = typeParameter.symbol) === null || _a === void 0 ? void 0 : _a.declarations) {
@@ -59536,7 +59813,7 @@ var ts;
59536
59813
  // corresponding type parameter in 'Foo'. When multiple 'infer T' declarations are
59537
59814
  // present, we form an intersection of the inferred constraint types.
59538
59815
  var _c = ts.walkUpParenthesizedTypesAndGetParentAndChild(declaration.parent.parent), _d = _c[0], childTypeParameter = _d === void 0 ? declaration.parent : _d, grandParent = _c[1];
59539
- if (grandParent.kind === 178 /* TypeReference */) {
59816
+ if (grandParent.kind === 178 /* TypeReference */ && !omitTypeReferences) {
59540
59817
  var typeReference = grandParent;
59541
59818
  var typeParameters = getTypeParametersForTypeReference(typeReference);
59542
59819
  if (typeParameters) {
@@ -59958,7 +60235,7 @@ var ts;
59958
60235
  return constraints ? getSubstitutionType(type, getIntersectionType(ts.append(constraints, type))) : type;
59959
60236
  }
59960
60237
  function isJSDocTypeReference(node) {
59961
- return !!(node.flags & 4194304 /* JSDoc */) && (node.kind === 178 /* TypeReference */ || node.kind === 200 /* ImportType */);
60238
+ return !!(node.flags & 8388608 /* JSDoc */) && (node.kind === 178 /* TypeReference */ || node.kind === 200 /* ImportType */);
59962
60239
  }
59963
60240
  function checkNoTypeArguments(node, symbol) {
59964
60241
  if (node.typeArguments) {
@@ -61517,7 +61794,7 @@ var ts;
61517
61794
  if (ts.isCallLikeExpression(parent)) {
61518
61795
  return ts.isCallOrNewExpression(parent) && ts.isIdentifier(node) && hasMatchingArgument(parent, node);
61519
61796
  }
61520
- return ts.every(symbol.declarations, function (d) { return !ts.isFunctionLike(d) || !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); });
61797
+ return ts.every(symbol.declarations, function (d) { return !ts.isFunctionLike(d) || !!(ts.getCombinedNodeFlags(d) & 268435456 /* Deprecated */); });
61521
61798
  }
61522
61799
  return true;
61523
61800
  }
@@ -61958,7 +62235,11 @@ var ts;
61958
62235
  return !root.isDistributive && isSingletonTupleType(root.node.checkType) && isSingletonTupleType(root.node.extendsType);
61959
62236
  }
61960
62237
  function isSingletonTupleType(node) {
61961
- return ts.isTupleTypeNode(node) && ts.length(node.elements) === 1 && !ts.isOptionalTypeNode(node.elements[0]) && !ts.isRestTypeNode(node.elements[0]);
62238
+ return ts.isTupleTypeNode(node) &&
62239
+ ts.length(node.elements) === 1 &&
62240
+ !ts.isOptionalTypeNode(node.elements[0]) &&
62241
+ !ts.isRestTypeNode(node.elements[0]) &&
62242
+ !(ts.isNamedTupleMember(node.elements[0]) && (node.elements[0].questionToken || node.elements[0].dotDotDotToken));
61962
62243
  }
61963
62244
  /**
61964
62245
  * We syntactually check for common nondistributive conditional shapes and unwrap them into
@@ -62206,7 +62487,7 @@ var ts;
62206
62487
  links.resolvedSymbol = unknownSymbol;
62207
62488
  return links.resolvedType = errorType;
62208
62489
  }
62209
- var targetMeaning = node.isTypeOf ? 111551 /* Value */ : node.flags & 4194304 /* JSDoc */ ? 111551 /* Value */ | 788968 /* Type */ : 788968 /* Type */;
62490
+ var targetMeaning = node.isTypeOf ? 111551 /* Value */ : node.flags & 8388608 /* JSDoc */ ? 111551 /* Value */ | 788968 /* Type */ : 788968 /* Type */;
62210
62491
  // TODO: Future work: support unions/generics/whatever via a deferred import-type
62211
62492
  var innerModuleSymbol = resolveExternalModuleName(node, node.argument.literal);
62212
62493
  if (!innerModuleSymbol) {
@@ -62542,7 +62823,7 @@ var ts;
62542
62823
  }
62543
62824
  // /** @return {this} */
62544
62825
  // x.prototype.m = function() { ... }
62545
- var host = node.flags & 4194304 /* JSDoc */ ? ts.getHostSignatureFromJSDoc(node) : undefined;
62826
+ var host = node.flags & 8388608 /* JSDoc */ ? ts.getHostSignatureFromJSDoc(node) : undefined;
62546
62827
  if (host && ts.isFunctionExpression(host) && ts.isBinaryExpression(host.parent) && ts.getAssignmentDeclarationKind(host.parent) === 3 /* PrototypeProperty */) {
62547
62828
  return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(host.parent.left).parent).thisType;
62548
62829
  }
@@ -62617,7 +62898,7 @@ var ts;
62617
62898
  case 143 /* NeverKeyword */:
62618
62899
  return neverType;
62619
62900
  case 148 /* ObjectKeyword */:
62620
- return node.flags & 131072 /* JavaScriptFile */ && !noImplicitAny ? anyType : nonPrimitiveType;
62901
+ return node.flags & 262144 /* JavaScriptFile */ && !noImplicitAny ? anyType : nonPrimitiveType;
62621
62902
  case 138 /* IntrinsicKeyword */:
62622
62903
  return intrinsicMarkerType;
62623
62904
  case 192 /* ThisType */:
@@ -66478,6 +66759,9 @@ var ts;
66478
66759
  function createMarkerType(symbol, source, target) {
66479
66760
  var mapper = makeUnaryTypeMapper(source, target);
66480
66761
  var type = getDeclaredTypeOfSymbol(symbol);
66762
+ if (isErrorType(type)) {
66763
+ return type;
66764
+ }
66481
66765
  var result = symbol.flags & 524288 /* TypeAlias */ ?
66482
66766
  getTypeAliasInstantiation(symbol, instantiateTypes(getSymbolLinks(symbol).typeParameters, mapper)) :
66483
66767
  createTypeReference(type, instantiateTypes(type.typeParameters, mapper));
@@ -67491,6 +67775,9 @@ var ts;
67491
67775
  var inference = inferences[i];
67492
67776
  if (t === inference.typeParameter) {
67493
67777
  if (fix && !inference.isFixed) {
67778
+ // Before we commit to a particular inference (and thus lock out any further inferences),
67779
+ // we infer from any intra-expression inference sites we have collected.
67780
+ inferFromIntraExpressionSites(context);
67494
67781
  clearCachedInferences(inferences);
67495
67782
  inference.isFixed = true;
67496
67783
  }
@@ -67507,6 +67794,37 @@ var ts;
67507
67794
  }
67508
67795
  }
67509
67796
  }
67797
+ function addIntraExpressionInferenceSite(context, node, type) {
67798
+ var _a;
67799
+ ((_a = context.intraExpressionInferenceSites) !== null && _a !== void 0 ? _a : (context.intraExpressionInferenceSites = [])).push({ node: node, type: type });
67800
+ }
67801
+ // We collect intra-expression inference sites within object and array literals to handle cases where
67802
+ // inferred types flow between context sensitive element expressions. For example:
67803
+ //
67804
+ // declare function foo<T>(arg: [(n: number) => T, (x: T) => void]): void;
67805
+ // foo([_a => 0, n => n.toFixed()]);
67806
+ //
67807
+ // Above, both arrow functions in the tuple argument are context sensitive, thus both are omitted from the
67808
+ // pass that collects inferences from the non-context sensitive parts of the arguments. In the subsequent
67809
+ // pass where nothing is omitted, we need to commit to an inference for T in order to contextually type the
67810
+ // parameter in the second arrow function, but we want to first infer from the return type of the first
67811
+ // arrow function. This happens automatically when the arrow functions are discrete arguments (because we
67812
+ // infer from each argument before processing the next), but when the arrow functions are elements of an
67813
+ // object or array literal, we need to perform intra-expression inferences early.
67814
+ function inferFromIntraExpressionSites(context) {
67815
+ if (context.intraExpressionInferenceSites) {
67816
+ for (var _i = 0, _a = context.intraExpressionInferenceSites; _i < _a.length; _i++) {
67817
+ var _b = _a[_i], node = _b.node, type = _b.type;
67818
+ var contextualType = node.kind === 169 /* MethodDeclaration */ ?
67819
+ getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) :
67820
+ getContextualType(node, 2 /* NoConstraints */);
67821
+ if (contextualType) {
67822
+ inferTypes(context.inferences, type, contextualType);
67823
+ }
67824
+ }
67825
+ context.intraExpressionInferenceSites = undefined;
67826
+ }
67827
+ }
67510
67828
  function createInferenceInfo(typeParameter) {
67511
67829
  return {
67512
67830
  typeParameter: typeParameter,
@@ -69489,7 +69807,7 @@ var ts;
69489
69807
  // parameter symbols with declarations that have explicit type annotations. Such references are
69490
69808
  // resolvable with no possibility of triggering circularities in control flow analysis.
69491
69809
  function getTypeOfDottedName(node, diagnostic) {
69492
- if (!(node.flags & 16777216 /* InWithStatement */)) {
69810
+ if (!(node.flags & 33554432 /* InWithStatement */)) {
69493
69811
  switch (node.kind) {
69494
69812
  case 79 /* Identifier */:
69495
69813
  var symbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(node));
@@ -70893,6 +71211,7 @@ var ts;
70893
71211
  // a generic type without a nullable constraint and x is a generic type. This is because when both obj
70894
71212
  // and x are of generic types T and K, we want the resulting type to be T[K].
70895
71213
  return parent.kind === 206 /* PropertyAccessExpression */ ||
71214
+ parent.kind === 161 /* QualifiedName */ ||
70896
71215
  parent.kind === 208 /* CallExpression */ && parent.expression === node ||
70897
71216
  parent.kind === 207 /* ElementAccessExpression */ && parent.expression === node &&
70898
71217
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
@@ -71186,7 +71505,7 @@ var ts;
71186
71505
  isInTypeQuery(node) || node.parent.kind === 275 /* ExportSpecifier */) ||
71187
71506
  node.parent.kind === 230 /* NonNullExpression */ ||
71188
71507
  declaration.kind === 254 /* VariableDeclaration */ && declaration.exclamationToken ||
71189
- declaration.flags & 8388608 /* Ambient */;
71508
+ declaration.flags & 16777216 /* Ambient */;
71190
71509
  var initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration) : type) :
71191
71510
  type === autoType || type === autoArrayType ? undefinedType :
71192
71511
  getOptionalType(type);
@@ -72194,7 +72513,7 @@ var ts;
72194
72513
  // exists. Otherwise, it is the type of the string index signature in T, if one exists.
72195
72514
  function getContextualTypeForObjectLiteralMethod(node, contextFlags) {
72196
72515
  ts.Debug.assert(ts.isObjectLiteralMethod(node));
72197
- if (node.flags & 16777216 /* InWithStatement */) {
72516
+ if (node.flags & 33554432 /* InWithStatement */) {
72198
72517
  // We cannot answer semantic questions within a with block, do not proceed any further
72199
72518
  return undefined;
72200
72519
  }
@@ -72382,7 +72701,7 @@ var ts;
72382
72701
  * @returns the contextual type of an expression.
72383
72702
  */
72384
72703
  function getContextualType(node, contextFlags) {
72385
- if (node.flags & 16777216 /* InWithStatement */) {
72704
+ if (node.flags & 33554432 /* InWithStatement */) {
72386
72705
  // We cannot answer semantic questions within a with block, do not proceed any further
72387
72706
  return undefined;
72388
72707
  }
@@ -72800,6 +73119,11 @@ var ts;
72800
73119
  var type = checkExpressionForMutableLocation(e, checkMode, elementContextualType, forceTuple);
72801
73120
  elementTypes.push(addOptionality(type, /*isProperty*/ true, hasOmittedExpression));
72802
73121
  elementFlags.push(hasOmittedExpression ? 2 /* Optional */ : 1 /* Required */);
73122
+ if (contextualType && someType(contextualType, isTupleLikeType) && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
73123
+ var inferenceContext = getInferenceContext(node);
73124
+ ts.Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context
73125
+ addIntraExpressionInferenceSite(inferenceContext, e, type);
73126
+ }
72803
73127
  }
72804
73128
  }
72805
73129
  if (inDestructuringPattern) {
@@ -73001,6 +73325,13 @@ var ts;
73001
73325
  prop.target = member;
73002
73326
  member = prop;
73003
73327
  allPropertiesTable === null || allPropertiesTable === void 0 ? void 0 : allPropertiesTable.set(prop.escapedName, prop);
73328
+ if (contextualType && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) &&
73329
+ (memberDecl.kind === 296 /* PropertyAssignment */ || memberDecl.kind === 169 /* MethodDeclaration */) && isContextSensitive(memberDecl)) {
73330
+ var inferenceContext = getInferenceContext(node);
73331
+ ts.Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context
73332
+ var inferenceNode = memberDecl.kind === 296 /* PropertyAssignment */ ? memberDecl.initializer : memberDecl;
73333
+ addIntraExpressionInferenceSite(inferenceContext, inferenceNode, type);
73334
+ }
73004
73335
  }
73005
73336
  else if (memberDecl.kind === 298 /* SpreadAssignment */) {
73006
73337
  if (languageVersion < 2 /* ES2015 */) {
@@ -74093,7 +74424,7 @@ var ts;
74093
74424
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
74094
74425
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
74095
74426
  }
74096
- if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
74427
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 268435456 /* Deprecated */) {
74097
74428
  addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
74098
74429
  }
74099
74430
  }
@@ -74161,7 +74492,7 @@ var ts;
74161
74492
  if (declaration && isPropertyWithoutInitializer(declaration)) {
74162
74493
  if (!ts.isStatic(declaration)) {
74163
74494
  var flowContainer = getControlFlowContainer(node);
74164
- if (flowContainer.kind === 171 /* Constructor */ && flowContainer.parent === declaration.parent && !(declaration.flags & 8388608 /* Ambient */)) {
74495
+ if (flowContainer.kind === 171 /* Constructor */ && flowContainer.parent === declaration.parent && !(declaration.flags & 16777216 /* Ambient */)) {
74165
74496
  assumeUninitialized = true;
74166
74497
  }
74167
74498
  }
@@ -74198,7 +74529,7 @@ var ts;
74198
74529
  }
74199
74530
  else if (valueDeclaration.kind === 257 /* ClassDeclaration */ &&
74200
74531
  node.parent.kind !== 178 /* TypeReference */ &&
74201
- !(valueDeclaration.flags & 8388608 /* Ambient */) &&
74532
+ !(valueDeclaration.flags & 16777216 /* Ambient */) &&
74202
74533
  !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)) {
74203
74534
  diagnosticMessage = error(right, ts.Diagnostics.Class_0_used_before_its_declaration, declarationName);
74204
74535
  }
@@ -74863,34 +75194,36 @@ var ts;
74863
75194
  if (node.kind !== 165 /* Decorator */) {
74864
75195
  var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
74865
75196
  if (contextualType) {
74866
- // We clone the inference context to avoid disturbing a resolution in progress for an
74867
- // outer call expression. Effectively we just want a snapshot of whatever has been
74868
- // inferred for any outer call expression so far.
74869
- var outerContext = getInferenceContext(node);
74870
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
74871
- var instantiatedType = instantiateType(contextualType, outerMapper);
74872
- // If the contextual type is a generic function type with a single call signature, we
74873
- // instantiate the type with its own type parameters and type arguments. This ensures that
74874
- // the type parameters are not erased to type any during type inference such that they can
74875
- // be inferred as actual types from the contextual type. For example:
74876
- // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
74877
- // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
74878
- // Above, the type of the 'value' parameter is inferred to be 'A'.
74879
- var contextualSignature = getSingleCallSignature(instantiatedType);
74880
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
74881
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
74882
- instantiatedType;
74883
75197
  var inferenceTargetType = getReturnTypeOfSignature(signature);
74884
- // Inferences made from return types have lower priority than all other inferences.
74885
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
74886
- // Create a type mapper for instantiating generic contextual types using the inferences made
74887
- // from the return type. We need a separate inference pass here because (a) instantiation of
74888
- // the source type uses the outer context's return mapper (which excludes inferences made from
74889
- // outer arguments), and (b) we don't want any further inferences going into this context.
74890
- var returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
74891
- var returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
74892
- inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
74893
- context.returnMapper = ts.some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : undefined;
75198
+ if (couldContainTypeVariables(inferenceTargetType)) {
75199
+ // We clone the inference context to avoid disturbing a resolution in progress for an
75200
+ // outer call expression. Effectively we just want a snapshot of whatever has been
75201
+ // inferred for any outer call expression so far.
75202
+ var outerContext = getInferenceContext(node);
75203
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75204
+ var instantiatedType = instantiateType(contextualType, outerMapper);
75205
+ // If the contextual type is a generic function type with a single call signature, we
75206
+ // instantiate the type with its own type parameters and type arguments. This ensures that
75207
+ // the type parameters are not erased to type any during type inference such that they can
75208
+ // be inferred as actual types from the contextual type. For example:
75209
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75210
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75211
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
75212
+ var contextualSignature = getSingleCallSignature(instantiatedType);
75213
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75214
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75215
+ instantiatedType;
75216
+ // Inferences made from return types have lower priority than all other inferences.
75217
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75218
+ // Create a type mapper for instantiating generic contextual types using the inferences made
75219
+ // from the return type. We need a separate inference pass here because (a) instantiation of
75220
+ // the source type uses the outer context's return mapper (which excludes inferences made from
75221
+ // outer arguments), and (b) we don't want any further inferences going into this context.
75222
+ var returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
75223
+ var returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
75224
+ inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
75225
+ context.returnMapper = ts.some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : undefined;
75226
+ }
74894
75227
  }
74895
75228
  }
74896
75229
  var restType = getNonArrayRestType(signature);
@@ -74902,7 +75235,7 @@ var ts;
74902
75235
  }
74903
75236
  }
74904
75237
  var thisType = getThisTypeOfSignature(signature);
74905
- if (thisType) {
75238
+ if (thisType && couldContainTypeVariables(thisType)) {
74906
75239
  var thisArgumentNode = getThisArgumentOfCall(node);
74907
75240
  inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
74908
75241
  }
@@ -74910,11 +75243,13 @@ var ts;
74910
75243
  var arg = args[i];
74911
75244
  if (arg.kind !== 227 /* OmittedExpression */ && !(checkMode & 32 /* IsForStringLiteralArgumentCompletions */ && hasSkipDirectInferenceFlag(arg))) {
74912
75245
  var paramType = getTypeAtPosition(signature, i);
74913
- var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
74914
- inferTypes(context.inferences, argType, paramType);
75246
+ if (couldContainTypeVariables(paramType)) {
75247
+ var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
75248
+ inferTypes(context.inferences, argType, paramType);
75249
+ }
74915
75250
  }
74916
75251
  }
74917
- if (restType) {
75252
+ if (restType && couldContainTypeVariables(restType)) {
74918
75253
  var spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
74919
75254
  inferTypes(context.inferences, spreadType, restType);
74920
75255
  }
@@ -76494,7 +76829,7 @@ var ts;
76494
76829
  return returnType;
76495
76830
  }
76496
76831
  function checkDeprecatedSignature(signature, node) {
76497
- if (signature.declaration && signature.declaration.flags & 134217728 /* Deprecated */) {
76832
+ if (signature.declaration && signature.declaration.flags & 268435456 /* Deprecated */) {
76498
76833
  var suggestionNode = getDeprecatedSuggestionNode(node);
76499
76834
  var name = ts.tryGetPropertyAccessOrIdentifierToString(ts.getInvokedExpression(node));
76500
76835
  addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name, signatureToString(signature));
@@ -76578,7 +76913,7 @@ var ts;
76578
76913
  var newSymbol = createSymbol(2097152 /* Alias */, "default" /* Default */);
76579
76914
  newSymbol.parent = originalSymbol;
76580
76915
  newSymbol.nameType = getStringLiteralType("default");
76581
- newSymbol.target = resolveSymbol(symbol);
76916
+ newSymbol.aliasTarget = resolveSymbol(symbol);
76582
76917
  memberTable.set("default" /* Default */, newSymbol);
76583
76918
  return createAnonymousType(anonymousSymbol, memberTable, ts.emptyArray, ts.emptyArray, ts.emptyArray);
76584
76919
  }
@@ -76638,7 +76973,7 @@ var ts;
76638
76973
  if (targetDeclarationKind !== 0 /* Unknown */) {
76639
76974
  var decl = ts.getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
76640
76975
  // function/variable declaration should be ambient
76641
- return !!decl && !!(decl.flags & 8388608 /* Ambient */);
76976
+ return !!decl && !!(decl.flags & 16777216 /* Ambient */);
76642
76977
  }
76643
76978
  return false;
76644
76979
  }
@@ -76833,7 +77168,7 @@ var ts;
76833
77168
  error(node, ts.Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext);
76834
77169
  }
76835
77170
  var file = ts.getSourceFileOfNode(node);
76836
- ts.Debug.assert(!!(file.flags & 2097152 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
77171
+ ts.Debug.assert(!!(file.flags & 4194304 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
76837
77172
  return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
76838
77173
  }
76839
77174
  function getTypeOfParameter(symbol) {
@@ -78847,6 +79182,11 @@ var ts;
78847
79182
  context.contextualType = contextualType;
78848
79183
  context.inferenceContext = inferenceContext;
78849
79184
  var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
79185
+ // In CheckMode.Inferential we collect intra-expression inference sites to process before fixing any type
79186
+ // parameters. This information is no longer needed after the call to checkExpression.
79187
+ if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
79188
+ inferenceContext.intraExpressionInferenceSites = undefined;
79189
+ }
78850
79190
  // We strip literal freshness when an appropriate contextual type is present such that contextually typed
78851
79191
  // literals always preserve their literal types (otherwise they might widen during type inference). An alternative
78852
79192
  // here would be to not mark contextually typed literals as fresh in the first place.
@@ -79138,7 +79478,7 @@ var ts;
79138
79478
  return quickType;
79139
79479
  }
79140
79480
  // If a type has been cached for the node, return it.
79141
- if (node.flags & 67108864 /* TypeCached */ && flowTypeCache) {
79481
+ if (node.flags & 134217728 /* TypeCached */ && flowTypeCache) {
79142
79482
  var cachedType = flowTypeCache[getNodeId(node)];
79143
79483
  if (cachedType) {
79144
79484
  return cachedType;
@@ -79150,7 +79490,7 @@ var ts;
79150
79490
  if (flowInvocationCount !== startInvocationCount) {
79151
79491
  var cache = flowTypeCache || (flowTypeCache = []);
79152
79492
  cache[getNodeId(node)] = type;
79153
- ts.setNodeFlags(node, node.flags | 67108864 /* TypeCached */);
79493
+ ts.setNodeFlags(node, node.flags | 134217728 /* TypeCached */);
79154
79494
  }
79155
79495
  return type;
79156
79496
  }
@@ -79236,7 +79576,7 @@ var ts;
79236
79576
  if (compilerOptions.isolatedModules) {
79237
79577
  ts.Debug.assert(!!(type.symbol.flags & 128 /* ConstEnum */));
79238
79578
  var constEnumDeclaration = type.symbol.valueDeclaration;
79239
- if (constEnumDeclaration.flags & 8388608 /* Ambient */) {
79579
+ if (constEnumDeclaration.flags & 16777216 /* Ambient */) {
79240
79580
  error(node, ts.Diagnostics.Cannot_access_ambient_const_enums_when_the_isolatedModules_flag_is_provided);
79241
79581
  }
79242
79582
  }
@@ -79387,14 +79727,19 @@ var ts;
79387
79727
  }
79388
79728
  if (node.parent.kind === 258 /* InterfaceDeclaration */ || node.parent.kind === 257 /* ClassDeclaration */ || node.parent.kind === 259 /* TypeAliasDeclaration */) {
79389
79729
  var modifiers = getVarianceModifiers(typeParameter);
79390
- if (modifiers === 32768 /* In */ || modifiers === 65536 /* Out */) {
79730
+ if (modifiers) {
79391
79731
  var symbol = getSymbolOfNode(node.parent);
79392
- var source = createMarkerType(symbol, typeParameter, modifiers === 65536 /* Out */ ? markerSubType : markerSuperType);
79393
- var target = createMarkerType(symbol, typeParameter, modifiers === 65536 /* Out */ ? markerSuperType : markerSubType);
79394
- var saveVarianceTypeParameter = typeParameter;
79395
- varianceTypeParameter = typeParameter;
79396
- checkTypeAssignableTo(source, target, node, ts.Diagnostics.Type_0_is_not_assignable_to_type_1_as_implied_by_variance_annotation);
79397
- varianceTypeParameter = saveVarianceTypeParameter;
79732
+ if (node.parent.kind === 259 /* TypeAliasDeclaration */ && !(ts.getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (16 /* Anonymous */ | 32 /* Mapped */))) {
79733
+ error(node, ts.Diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types);
79734
+ }
79735
+ else if (modifiers === 32768 /* In */ || modifiers === 65536 /* Out */) {
79736
+ var source = createMarkerType(symbol, typeParameter, modifiers === 65536 /* Out */ ? markerSubType : markerSuperType);
79737
+ var target = createMarkerType(symbol, typeParameter, modifiers === 65536 /* Out */ ? markerSuperType : markerSubType);
79738
+ var saveVarianceTypeParameter = typeParameter;
79739
+ varianceTypeParameter = typeParameter;
79740
+ checkTypeAssignableTo(source, target, node, ts.Diagnostics.Type_0_is_not_assignable_to_type_1_as_implied_by_variance_annotation);
79741
+ varianceTypeParameter = saveVarianceTypeParameter;
79742
+ }
79398
79743
  }
79399
79744
  }
79400
79745
  addLazyDiagnostic(function () { return checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_parameter_name_cannot_be_0); });
@@ -79929,7 +80274,7 @@ var ts;
79929
80274
  checkDecorators(node);
79930
80275
  checkSignatureDeclaration(node);
79931
80276
  if (node.kind === 172 /* GetAccessor */) {
79932
- if (!(node.flags & 8388608 /* Ambient */) && ts.nodeIsPresent(node.body) && (node.flags & 256 /* HasImplicitReturn */)) {
80277
+ if (!(node.flags & 16777216 /* Ambient */) && ts.nodeIsPresent(node.body) && (node.flags & 256 /* HasImplicitReturn */)) {
79933
80278
  if (!(node.flags & 512 /* HasExplicitReturn */)) {
79934
80279
  error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value);
79935
80280
  }
@@ -80024,7 +80369,7 @@ var ts;
80024
80369
  }
80025
80370
  var symbol = getNodeLinks(node).resolvedSymbol;
80026
80371
  if (symbol) {
80027
- if (ts.some(symbol.declarations, function (d) { return isTypeDeclaration(d) && !!(d.flags & 134217728 /* Deprecated */); })) {
80372
+ if (ts.some(symbol.declarations, function (d) { return isTypeDeclaration(d) && !!(d.flags & 268435456 /* Deprecated */); })) {
80028
80373
  addDeprecatedSuggestion(getDeprecatedSuggestionNode(node), symbol.declarations, symbol.escapedName);
80029
80374
  }
80030
80375
  if (type.flags & 32 /* Enum */ && symbol.flags & 8 /* EnumMember */) {
@@ -80184,6 +80529,23 @@ var ts;
80184
80529
  grammarErrorOnNode(node, ts.Diagnostics.infer_declarations_are_only_permitted_in_the_extends_clause_of_a_conditional_type);
80185
80530
  }
80186
80531
  checkSourceElement(node.typeParameter);
80532
+ var symbol = getSymbolOfNode(node.typeParameter);
80533
+ if (symbol.declarations && symbol.declarations.length > 1) {
80534
+ var links = getSymbolLinks(symbol);
80535
+ if (!links.typeParametersChecked) {
80536
+ links.typeParametersChecked = true;
80537
+ var typeParameter = getDeclaredTypeOfTypeParameter(symbol);
80538
+ var declarations = ts.getDeclarationsOfKind(symbol, 163 /* TypeParameter */);
80539
+ if (!areTypeParametersIdentical(declarations, [typeParameter], function (decl) { return [decl]; })) {
80540
+ // Report an error on every conflicting declaration.
80541
+ var name = symbolToString(symbol);
80542
+ for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
80543
+ var declaration = declarations_4[_i];
80544
+ error(declaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_constraints, name);
80545
+ }
80546
+ }
80547
+ }
80548
+ }
80187
80549
  registerForUnusedIdentifiersCheck(node);
80188
80550
  }
80189
80551
  function checkTemplateLiteralType(node) {
@@ -80221,7 +80583,7 @@ var ts;
80221
80583
  getTypeFromTypeNode(node);
80222
80584
  }
80223
80585
  function isPrivateWithinAmbient(node) {
80224
- return (ts.hasEffectiveModifier(node, 8 /* Private */) || ts.isPrivateIdentifierClassElementDeclaration(node)) && !!(node.flags & 8388608 /* Ambient */);
80586
+ return (ts.hasEffectiveModifier(node, 8 /* Private */) || ts.isPrivateIdentifierClassElementDeclaration(node)) && !!(node.flags & 16777216 /* Ambient */);
80225
80587
  }
80226
80588
  function getEffectiveDeclarationFlags(n, flagsToCheck) {
80227
80589
  var flags = ts.getCombinedModifierFlags(n);
@@ -80230,7 +80592,7 @@ var ts;
80230
80592
  if (n.parent.kind !== 258 /* InterfaceDeclaration */ &&
80231
80593
  n.parent.kind !== 257 /* ClassDeclaration */ &&
80232
80594
  n.parent.kind !== 226 /* ClassExpression */ &&
80233
- n.flags & 8388608 /* Ambient */) {
80595
+ n.flags & 16777216 /* Ambient */) {
80234
80596
  if (!(flags & 2 /* Ambient */) && !(ts.isModuleBlock(n.parent) && ts.isModuleDeclaration(n.parent.parent) && ts.isGlobalScopeAugmentation(n.parent.parent))) {
80235
80597
  // It is nested in an ambient context, which means it is automatically exported
80236
80598
  flags |= 1 /* Export */;
@@ -80363,10 +80725,10 @@ var ts;
80363
80725
  var hasNonAmbientClass = false;
80364
80726
  var functionDeclarations = [];
80365
80727
  if (declarations) {
80366
- for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
80367
- var current = declarations_4[_i];
80728
+ for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) {
80729
+ var current = declarations_5[_i];
80368
80730
  var node = current;
80369
- var inAmbientContext = node.flags & 8388608 /* Ambient */;
80731
+ var inAmbientContext = node.flags & 16777216 /* Ambient */;
80370
80732
  var inAmbientContextOrInterface = node.parent && (node.parent.kind === 258 /* InterfaceDeclaration */ || node.parent.kind === 182 /* TypeLiteral */) || inAmbientContext;
80371
80733
  if (inAmbientContextOrInterface) {
80372
80734
  // check if declarations are consecutive only if they are non-ambient
@@ -81218,7 +81580,7 @@ var ts;
81218
81580
  // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function.
81219
81581
  var firstDeclaration = (_a = localSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(
81220
81582
  // Get first non javascript function declaration
81221
- function (declaration) { return declaration.kind === node.kind && !(declaration.flags & 131072 /* JavaScriptFile */); });
81583
+ function (declaration) { return declaration.kind === node.kind && !(declaration.flags & 262144 /* JavaScriptFile */); });
81222
81584
  // Only type check the symbol once
81223
81585
  if (node === firstDeclaration) {
81224
81586
  checkFunctionOrConstructorSymbol(localSymbol);
@@ -81340,7 +81702,7 @@ var ts;
81340
81702
  var symbol = getSymbolOfNode(member);
81341
81703
  if (!symbol.isReferenced
81342
81704
  && (ts.hasEffectiveModifier(member, 8 /* Private */) || ts.isNamedDeclaration(member) && ts.isPrivateIdentifier(member.name))
81343
- && !(member.flags & 8388608 /* Ambient */)) {
81705
+ && !(member.flags & 16777216 /* Ambient */)) {
81344
81706
  addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol)));
81345
81707
  }
81346
81708
  break;
@@ -81530,8 +81892,8 @@ var ts;
81530
81892
  : ts.createDiagnosticForNode(declarationList.parent.kind === 237 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused));
81531
81893
  }
81532
81894
  else {
81533
- for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) {
81534
- var decl = declarations_5[_i];
81895
+ for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
81896
+ var decl = declarations_6[_i];
81535
81897
  addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(decl.name)));
81536
81898
  }
81537
81899
  }
@@ -81573,7 +81935,7 @@ var ts;
81573
81935
  }
81574
81936
  function checkCollisionWithArgumentsInGeneratedCode(node) {
81575
81937
  // no rest parameters \ declaration context \ overload - no codegen impact
81576
- if (languageVersion >= 2 /* ES2015 */ || !ts.hasRestParameter(node) || node.flags & 8388608 /* Ambient */ || ts.nodeIsMissing(node.body)) {
81938
+ if (languageVersion >= 2 /* ES2015 */ || !ts.hasRestParameter(node) || node.flags & 16777216 /* Ambient */ || ts.nodeIsMissing(node.body)) {
81577
81939
  return;
81578
81940
  }
81579
81941
  ts.forEach(node.parameters, function (p) {
@@ -81601,7 +81963,7 @@ var ts;
81601
81963
  // it is ok to have member named '_super', '_this', `Promise`, etc. - member access is always qualified
81602
81964
  return false;
81603
81965
  }
81604
- if (node.flags & 8388608 /* Ambient */) {
81966
+ if (node.flags & 16777216 /* Ambient */) {
81605
81967
  // ambient context - no codegen impact
81606
81968
  return false;
81607
81969
  }
@@ -81740,7 +82102,7 @@ var ts;
81740
82102
  recordPotentialCollisionWithReflectInGeneratedCode(node, name);
81741
82103
  if (ts.isClassLike(node)) {
81742
82104
  checkTypeNameIsReserved(name, ts.Diagnostics.Class_name_cannot_be_0);
81743
- if (!(node.flags & 8388608 /* Ambient */)) {
82105
+ if (!(node.flags & 16777216 /* Ambient */)) {
81744
82106
  checkClassNameCollisionWithObject(name);
81745
82107
  }
81746
82108
  }
@@ -83334,23 +83696,23 @@ var ts;
83334
83696
  return;
83335
83697
  }
83336
83698
  var type = getDeclaredTypeOfSymbol(symbol);
83337
- if (!areTypeParametersIdentical(declarations, type.localTypeParameters)) {
83699
+ if (!areTypeParametersIdentical(declarations, type.localTypeParameters, ts.getEffectiveTypeParameterDeclarations)) {
83338
83700
  // Report an error on every conflicting declaration.
83339
83701
  var name = symbolToString(symbol);
83340
- for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
83341
- var declaration = declarations_6[_i];
83702
+ for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
83703
+ var declaration = declarations_7[_i];
83342
83704
  error(declaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_type_parameters, name);
83343
83705
  }
83344
83706
  }
83345
83707
  }
83346
83708
  }
83347
- function areTypeParametersIdentical(declarations, targetParameters) {
83709
+ function areTypeParametersIdentical(declarations, targetParameters, getTypeParameterDeclarations) {
83348
83710
  var maxTypeArgumentCount = ts.length(targetParameters);
83349
83711
  var minTypeArgumentCount = getMinTypeArgumentCount(targetParameters);
83350
- for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
83351
- var declaration = declarations_7[_i];
83712
+ for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
83713
+ var declaration = declarations_8[_i];
83352
83714
  // If this declaration has too few or too many type parameters, we report an error
83353
- var sourceParameters = ts.getEffectiveTypeParameterDeclarations(declaration);
83715
+ var sourceParameters = getTypeParameterDeclarations(declaration);
83354
83716
  var numTypeParameters = sourceParameters.length;
83355
83717
  if (numTypeParameters < minTypeArgumentCount || numTypeParameters > maxTypeArgumentCount) {
83356
83718
  return false;
@@ -83418,7 +83780,7 @@ var ts;
83418
83780
  checkFunctionOrConstructorSymbol(symbol);
83419
83781
  checkClassForDuplicateDeclarations(node);
83420
83782
  // Only check for reserved static identifiers on non-ambient context.
83421
- var nodeInAmbientContext = !!(node.flags & 8388608 /* Ambient */);
83783
+ var nodeInAmbientContext = !!(node.flags & 16777216 /* Ambient */);
83422
83784
  if (!nodeInAmbientContext) {
83423
83785
  checkClassForStaticPropertyNameConflicts(node);
83424
83786
  }
@@ -83568,7 +83930,7 @@ var ts;
83568
83930
  */
83569
83931
  function checkMemberForOverrideModifier(node, staticType, baseStaticType, baseWithThis, type, typeWithThis, memberHasOverrideModifier, memberHasAbstractModifier, memberIsStatic, memberIsParameterProperty, memberName, errorNode) {
83570
83932
  var isJs = ts.isInJSFile(node);
83571
- var nodeInAmbientContext = !!(node.flags & 8388608 /* Ambient */);
83933
+ var nodeInAmbientContext = !!(node.flags & 16777216 /* Ambient */);
83572
83934
  if (baseWithThis && (memberHasOverrideModifier || compilerOptions.noImplicitOverride)) {
83573
83935
  var memberEscapedName = ts.escapeLeadingUnderscores(memberName);
83574
83936
  var thisType = memberIsStatic ? staticType : typeWithThis;
@@ -83796,7 +84158,7 @@ var ts;
83796
84158
  && !(derived.flags & 33554432 /* Transient */)
83797
84159
  && !(baseDeclarationFlags & 128 /* Abstract */)
83798
84160
  && !(derivedDeclarationFlags & 128 /* Abstract */)
83799
- && !((_b = derived.declarations) === null || _b === void 0 ? void 0 : _b.some(function (d) { return !!(d.flags & 8388608 /* Ambient */); }))) {
84161
+ && !((_b = derived.declarations) === null || _b === void 0 ? void 0 : _b.some(function (d) { return !!(d.flags & 16777216 /* Ambient */); }))) {
83800
84162
  var constructor = findConstructorDeclaration(ts.getClassLikeDeclarationOfSymbol(type.symbol));
83801
84163
  var propName = uninitialized.name;
83802
84164
  if (uninitialized.exclamationToken
@@ -83888,7 +84250,7 @@ var ts;
83888
84250
  return ok;
83889
84251
  }
83890
84252
  function checkPropertyInitialization(node) {
83891
- if (!strictNullChecks || !strictPropertyInitialization || node.flags & 8388608 /* Ambient */) {
84253
+ if (!strictNullChecks || !strictPropertyInitialization || node.flags & 16777216 /* Ambient */) {
83892
84254
  return;
83893
84255
  }
83894
84256
  var constructor = findConstructorDeclaration(node);
@@ -84025,7 +84387,7 @@ var ts;
84025
84387
  }
84026
84388
  // In ambient non-const numeric enum declarations, enum members without initializers are
84027
84389
  // considered computed members (as opposed to having auto-incremented values).
84028
- if (member.parent.flags & 8388608 /* Ambient */ && !ts.isEnumConst(member.parent) && getEnumKind(getSymbolOfNode(member.parent)) === 0 /* Numeric */) {
84390
+ if (member.parent.flags & 16777216 /* Ambient */ && !ts.isEnumConst(member.parent) && getEnumKind(getSymbolOfNode(member.parent)) === 0 /* Numeric */) {
84029
84391
  return undefined;
84030
84392
  }
84031
84393
  // If the member declaration specifies no value, the member is considered a constant enum member.
@@ -84057,7 +84419,7 @@ var ts;
84057
84419
  else if (isConstEnum) {
84058
84420
  error(initializer, ts.Diagnostics.const_enum_member_initializers_can_only_contain_literal_values_and_other_computed_enum_values);
84059
84421
  }
84060
- else if (member.parent.flags & 8388608 /* Ambient */) {
84422
+ else if (member.parent.flags & 16777216 /* Ambient */) {
84061
84423
  error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
84062
84424
  }
84063
84425
  else {
@@ -84225,11 +84587,11 @@ var ts;
84225
84587
  function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
84226
84588
  var declarations = symbol.declarations;
84227
84589
  if (declarations) {
84228
- for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
84229
- var declaration = declarations_8[_i];
84590
+ for (var _i = 0, declarations_9 = declarations; _i < declarations_9.length; _i++) {
84591
+ var declaration = declarations_9[_i];
84230
84592
  if ((declaration.kind === 257 /* ClassDeclaration */ ||
84231
84593
  (declaration.kind === 256 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) &&
84232
- !(declaration.flags & 8388608 /* Ambient */)) {
84594
+ !(declaration.flags & 16777216 /* Ambient */)) {
84233
84595
  return declaration;
84234
84596
  }
84235
84597
  }
@@ -84260,7 +84622,7 @@ var ts;
84260
84622
  function checkModuleDeclarationDiagnostics() {
84261
84623
  // Grammar checking
84262
84624
  var isGlobalAugmentation = ts.isGlobalScopeAugmentation(node);
84263
- var inAmbientContext = node.flags & 8388608 /* Ambient */;
84625
+ var inAmbientContext = node.flags & 16777216 /* Ambient */;
84264
84626
  if (isGlobalAugmentation && !inAmbientContext) {
84265
84627
  error(node.name, ts.Diagnostics.Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context);
84266
84628
  }
@@ -84478,7 +84840,7 @@ var ts;
84478
84840
  }
84479
84841
  if (compilerOptions.isolatedModules
84480
84842
  && !ts.isTypeOnlyImportOrExportDeclaration(node)
84481
- && !(node.flags & 8388608 /* Ambient */)) {
84843
+ && !(node.flags & 16777216 /* Ambient */)) {
84482
84844
  var typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
84483
84845
  var isType = !(target.flags & 111551 /* Value */);
84484
84846
  if (isType || typeOnlyAlias) {
@@ -84524,7 +84886,7 @@ var ts;
84524
84886
  }
84525
84887
  }
84526
84888
  function isDeprecatedAliasedSymbol(symbol) {
84527
- return !!symbol.declarations && ts.every(symbol.declarations, function (d) { return !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); });
84889
+ return !!symbol.declarations && ts.every(symbol.declarations, function (d) { return !!(ts.getCombinedNodeFlags(d) & 268435456 /* Deprecated */); });
84528
84890
  }
84529
84891
  function checkDeprecatedAliasedSymbol(symbol, location) {
84530
84892
  if (!(symbol.flags & 2097152 /* Alias */))
@@ -84653,7 +85015,7 @@ var ts;
84653
85015
  }
84654
85016
  }
84655
85017
  else {
84656
- if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat === undefined && !node.isTypeOnly && !(node.flags & 8388608 /* Ambient */)) {
85018
+ if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat === undefined && !node.isTypeOnly && !(node.flags & 16777216 /* Ambient */)) {
84657
85019
  // Import equals declaration is deprecated in es6 or above
84658
85020
  grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
84659
85021
  }
@@ -84679,7 +85041,7 @@ var ts;
84679
85041
  ts.forEach(node.exportClause.elements, checkExportSpecifier);
84680
85042
  var inAmbientExternalModule = node.parent.kind === 262 /* ModuleBlock */ && ts.isAmbientModule(node.parent.parent);
84681
85043
  var inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === 262 /* ModuleBlock */ &&
84682
- !node.moduleSpecifier && node.flags & 8388608 /* Ambient */;
85044
+ !node.moduleSpecifier && node.flags & 16777216 /* Ambient */;
84683
85045
  if (node.parent.kind !== 305 /* SourceFile */ && !inAmbientExternalModule && !inAmbientNamespaceDeclaration) {
84684
85046
  error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
84685
85047
  }
@@ -84844,10 +85206,10 @@ var ts;
84844
85206
  checkExpressionCached(node.expression);
84845
85207
  }
84846
85208
  checkExternalModuleExports(container);
84847
- if ((node.flags & 8388608 /* Ambient */) && !ts.isEntityNameExpression(node.expression)) {
85209
+ if ((node.flags & 16777216 /* Ambient */) && !ts.isEntityNameExpression(node.expression)) {
84848
85210
  grammarErrorOnNode(node.expression, ts.Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context);
84849
85211
  }
84850
- if (node.isExportEquals && !(node.flags & 8388608 /* Ambient */)) {
85212
+ if (node.isExportEquals && !(node.flags & 16777216 /* Ambient */)) {
84851
85213
  if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat !== ts.ModuleKind.CommonJS) {
84852
85214
  // export assignment is not supported in es6 modules
84853
85215
  grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
@@ -85280,7 +85642,7 @@ var ts;
85280
85642
  // This relies on the results of other lazy diagnostics, so must be computed after them
85281
85643
  if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
85282
85644
  checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) {
85283
- if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
85645
+ if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 16777216 /* Ambient */))) {
85284
85646
  diagnostics.add(diag);
85285
85647
  }
85286
85648
  });
@@ -85380,7 +85742,7 @@ var ts;
85380
85742
  }
85381
85743
  // Language service support
85382
85744
  function getSymbolsInScope(location, meaning) {
85383
- if (location.flags & 16777216 /* InWithStatement */) {
85745
+ if (location.flags & 33554432 /* InWithStatement */) {
85384
85746
  // We cannot answer semantic questions within a with block, do not proceed any further
85385
85747
  return [];
85386
85748
  }
@@ -85730,7 +86092,7 @@ var ts;
85730
86092
  }
85731
86093
  var parent = node.parent;
85732
86094
  var grandParent = parent.parent;
85733
- if (node.flags & 16777216 /* InWithStatement */) {
86095
+ if (node.flags & 33554432 /* InWithStatement */) {
85734
86096
  // We cannot answer semantic questions within a with block, do not proceed any further
85735
86097
  return undefined;
85736
86098
  }
@@ -85872,7 +86234,7 @@ var ts;
85872
86234
  if (ts.isSourceFile(node) && !ts.isExternalModule(node)) {
85873
86235
  return errorType;
85874
86236
  }
85875
- if (node.flags & 16777216 /* InWithStatement */) {
86237
+ if (node.flags & 33554432 /* InWithStatement */) {
85876
86238
  // We cannot answer semantic questions within a with block, do not proceed any further
85877
86239
  return errorType;
85878
86240
  }
@@ -86037,11 +86399,11 @@ var ts;
86037
86399
  var _a = symbol, leftSpread = _a.leftSpread, rightSpread = _a.rightSpread, syntheticOrigin = _a.syntheticOrigin;
86038
86400
  return leftSpread ? [leftSpread, rightSpread]
86039
86401
  : syntheticOrigin ? [syntheticOrigin]
86040
- : ts.singleElementArray(tryGetAliasTarget(symbol));
86402
+ : ts.singleElementArray(tryGetTarget(symbol));
86041
86403
  }
86042
86404
  return undefined;
86043
86405
  }
86044
- function tryGetAliasTarget(symbol) {
86406
+ function tryGetTarget(symbol) {
86045
86407
  var target;
86046
86408
  var next = symbol;
86047
86409
  while (next = getSymbolLinks(next).target) {
@@ -86271,7 +86633,7 @@ var ts;
86271
86633
  if (links === null || links === void 0 ? void 0 : links.referenced) {
86272
86634
  return true;
86273
86635
  }
86274
- var target = getSymbolLinks(symbol).target; // TODO: GH#18217
86636
+ var target = getSymbolLinks(symbol).aliasTarget; // TODO: GH#18217
86275
86637
  if (target && ts.getEffectiveModifierFlags(node) & 1 /* Export */ &&
86276
86638
  target.flags & 111551 /* Value */ &&
86277
86639
  (ts.shouldPreserveConstEnums(compilerOptions) || !isConstEnumOrConstEnumOnlyModule(target))) {
@@ -86925,7 +87287,7 @@ var ts;
86925
87287
  function checkExternalEmitHelpers(location, helpers) {
86926
87288
  if ((requestedExternalEmitHelpers & helpers) !== helpers && compilerOptions.importHelpers) {
86927
87289
  var sourceFile = ts.getSourceFileOfNode(location);
86928
- if (ts.isEffectiveExternalModule(sourceFile, compilerOptions) && !(location.flags & 8388608 /* Ambient */)) {
87290
+ if (ts.isEffectiveExternalModule(sourceFile, compilerOptions) && !(location.flags & 16777216 /* Ambient */)) {
86929
87291
  var helpersModule = resolveHelpersModule(sourceFile, location);
86930
87292
  if (helpersModule !== unknownSymbol) {
86931
87293
  var uncheckedHelpers = helpers & ~requestedExternalEmitHelpers;
@@ -87178,7 +87540,7 @@ var ts;
87178
87540
  else if (node.kind === 164 /* Parameter */) {
87179
87541
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
87180
87542
  }
87181
- else if ((node.parent.flags & 8388608 /* Ambient */) && node.parent.kind === 262 /* ModuleBlock */) {
87543
+ else if ((node.parent.flags & 16777216 /* Ambient */) && node.parent.kind === 262 /* ModuleBlock */) {
87182
87544
  return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
87183
87545
  }
87184
87546
  else if (ts.isPrivateIdentifierClassElementDeclaration(node)) {
@@ -87224,7 +87586,7 @@ var ts;
87224
87586
  if (flags & 256 /* Async */) {
87225
87587
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async");
87226
87588
  }
87227
- else if (flags & 2 /* Ambient */ || node.parent.flags & 8388608 /* Ambient */) {
87589
+ else if (flags & 2 /* Ambient */ || node.parent.flags & 16777216 /* Ambient */) {
87228
87590
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
87229
87591
  }
87230
87592
  else if (node.kind === 164 /* Parameter */) {
@@ -87370,7 +87732,7 @@ var ts;
87370
87732
  if (i !== (parameterCount - 1)) {
87371
87733
  return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
87372
87734
  }
87373
- if (!(parameter.flags & 8388608 /* Ambient */)) { // Allow `...foo,` in ambient declarations; see GH#23070
87735
+ if (!(parameter.flags & 16777216 /* Ambient */)) { // Allow `...foo,` in ambient declarations; see GH#23070
87374
87736
  checkGrammarForDisallowedTrailingComma(parameters, ts.Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma);
87375
87737
  }
87376
87738
  if (parameter.questionToken) {
@@ -87581,7 +87943,7 @@ var ts;
87581
87943
  ts.Debug.assert(node.kind === 256 /* FunctionDeclaration */ ||
87582
87944
  node.kind === 213 /* FunctionExpression */ ||
87583
87945
  node.kind === 169 /* MethodDeclaration */);
87584
- if (node.flags & 8388608 /* Ambient */) {
87946
+ if (node.flags & 16777216 /* Ambient */) {
87585
87947
  return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
87586
87948
  }
87587
87949
  if (!node.body) {
@@ -87819,7 +88181,7 @@ var ts;
87819
88181
  return false;
87820
88182
  }
87821
88183
  function checkGrammarAccessor(accessor) {
87822
- if (!(accessor.flags & 8388608 /* Ambient */) && (accessor.parent.kind !== 182 /* TypeLiteral */) && (accessor.parent.kind !== 258 /* InterfaceDeclaration */)) {
88184
+ if (!(accessor.flags & 16777216 /* Ambient */) && (accessor.parent.kind !== 182 /* TypeLiteral */) && (accessor.parent.kind !== 258 /* InterfaceDeclaration */)) {
87823
88185
  if (languageVersion < 1 /* ES5 */) {
87824
88186
  return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
87825
88187
  }
@@ -87959,7 +88321,7 @@ var ts;
87959
88321
  // However, property declarations disallow computed names in general,
87960
88322
  // and accessors are not allowed in ambient contexts in general,
87961
88323
  // so this error only really matters for methods.
87962
- if (node.flags & 8388608 /* Ambient */) {
88324
+ if (node.flags & 16777216 /* Ambient */) {
87963
88325
  return checkGrammarForInvalidDynamicName(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type);
87964
88326
  }
87965
88327
  else if (node.kind === 169 /* MethodDeclaration */ && !node.body) {
@@ -88075,7 +88437,7 @@ var ts;
88075
88437
  }
88076
88438
  function checkGrammarVariableDeclaration(node) {
88077
88439
  if (node.parent.parent.kind !== 243 /* ForInStatement */ && node.parent.parent.kind !== 244 /* ForOfStatement */) {
88078
- if (node.flags & 8388608 /* Ambient */) {
88440
+ if (node.flags & 16777216 /* Ambient */) {
88079
88441
  checkAmbientInitializer(node);
88080
88442
  }
88081
88443
  else if (!node.initializer) {
@@ -88087,7 +88449,7 @@ var ts;
88087
88449
  }
88088
88450
  }
88089
88451
  }
88090
- if (node.exclamationToken && (node.parent.parent.kind !== 237 /* VariableStatement */ || !node.type || node.initializer || node.flags & 8388608 /* Ambient */)) {
88452
+ if (node.exclamationToken && (node.parent.parent.kind !== 237 /* VariableStatement */ || !node.type || node.initializer || node.flags & 16777216 /* Ambient */)) {
88091
88453
  var message = node.initializer
88092
88454
  ? ts.Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions
88093
88455
  : !node.type
@@ -88096,7 +88458,7 @@ var ts;
88096
88458
  return grammarErrorOnNode(node.exclamationToken, message);
88097
88459
  }
88098
88460
  if ((moduleKind < ts.ModuleKind.ES2015 || ts.getSourceFileOfNode(node).impliedNodeFormat === ts.ModuleKind.CommonJS) && moduleKind !== ts.ModuleKind.System &&
88099
- !(node.parent.parent.flags & 8388608 /* Ambient */) && ts.hasSyntacticModifier(node.parent.parent, 1 /* Export */)) {
88461
+ !(node.parent.parent.flags & 16777216 /* Ambient */) && ts.hasSyntacticModifier(node.parent.parent, 1 /* Export */)) {
88100
88462
  checkESModuleMarker(node.name);
88101
88463
  }
88102
88464
  var checkLetConstNames = (ts.isLet(node) || ts.isVarConst(node));
@@ -88273,11 +88635,11 @@ var ts;
88273
88635
  return grammarErrorOnNode(node.initializer, ts.Diagnostics.A_type_literal_property_cannot_have_an_initializer);
88274
88636
  }
88275
88637
  }
88276
- if (node.flags & 8388608 /* Ambient */) {
88638
+ if (node.flags & 16777216 /* Ambient */) {
88277
88639
  checkAmbientInitializer(node);
88278
88640
  }
88279
88641
  if (ts.isPropertyDeclaration(node) && node.exclamationToken && (!ts.isClassLike(node.parent) || !node.type || node.initializer ||
88280
- node.flags & 8388608 /* Ambient */ || ts.isStatic(node) || ts.hasAbstractModifier(node))) {
88642
+ node.flags & 16777216 /* Ambient */ || ts.isStatic(node) || ts.hasAbstractModifier(node))) {
88281
88643
  var message = node.initializer
88282
88644
  ? ts.Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions
88283
88645
  : !node.type
@@ -88323,10 +88685,10 @@ var ts;
88323
88685
  return false;
88324
88686
  }
88325
88687
  function checkGrammarSourceFile(node) {
88326
- return !!(node.flags & 8388608 /* Ambient */) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
88688
+ return !!(node.flags & 16777216 /* Ambient */) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
88327
88689
  }
88328
88690
  function checkGrammarStatementInAmbientContext(node) {
88329
- if (node.flags & 8388608 /* Ambient */) {
88691
+ if (node.flags & 16777216 /* Ambient */) {
88330
88692
  // Find containing block which is either Block, ModuleBlock, SourceFile
88331
88693
  var links = getNodeLinks(node);
88332
88694
  if (!links.hasReportedStatementInAmbientContext && (ts.isFunctionLike(node.parent) || ts.isAccessor(node.parent))) {
@@ -92444,7 +92806,7 @@ var ts;
92444
92806
  return !ts.nodeIsMissing(node.body);
92445
92807
  }
92446
92808
  function visitPropertyDeclaration(node) {
92447
- if (node.flags & 8388608 /* Ambient */ || ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
92809
+ if (node.flags & 16777216 /* Ambient */ || ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
92448
92810
  return undefined;
92449
92811
  }
92450
92812
  var updated = factory.updatePropertyDeclaration(node,
@@ -99334,8 +99696,8 @@ var ts;
99334
99696
  // declarations may not be sorted by position.
99335
99697
  // pos should be the minimum* position over all nodes (that's not -1), end should be the maximum end over all nodes.
99336
99698
  var pos = -1, end = -1;
99337
- for (var _i = 0, declarations_9 = declarations; _i < declarations_9.length; _i++) {
99338
- var node = declarations_9[_i];
99699
+ for (var _i = 0, declarations_10 = declarations; _i < declarations_10.length; _i++) {
99700
+ var node = declarations_10[_i];
99339
99701
  pos = pos === -1 ? node.pos : node.pos === -1 ? pos : Math.min(pos, node.pos);
99340
99702
  end = Math.max(end, node.end);
99341
99703
  }
@@ -108267,6 +108629,10 @@ var ts;
108267
108629
  return factory.updateModifiers(statement, modifiers);
108268
108630
  }
108269
108631
  function transformTopLevelDeclaration(input) {
108632
+ if (lateMarkedStatements) {
108633
+ while (ts.orderedRemoveItem(lateMarkedStatements, input))
108634
+ ;
108635
+ }
108270
108636
  if (shouldStripInternal(input))
108271
108637
  return;
108272
108638
  switch (input.kind) {
@@ -108378,7 +108744,7 @@ var ts;
108378
108744
  needsScopeFixMarker = false;
108379
108745
  var statements = ts.visitNodes(inner.statements, visitDeclarationStatements);
108380
108746
  var lateStatements = transformAndReplaceLatePaintedStatements(statements);
108381
- if (input.flags & 8388608 /* Ambient */) {
108747
+ if (input.flags & 16777216 /* Ambient */) {
108382
108748
  needsScopeFixMarker = false; // If it was `declare`'d everything is implicitly exported already, ignore late printed "privates"
108383
108749
  }
108384
108750
  // With the final list of statements, there are 3 possibilities:
@@ -110026,6 +110392,9 @@ var ts;
110026
110392
  var currentParenthesizerRule;
110027
110393
  var _c = ts.performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment"), enterComment = _c.enter, exitComment = _c.exit;
110028
110394
  var parenthesizer = ts.factory.parenthesizer;
110395
+ var typeArgumentParenthesizerRuleSelector = {
110396
+ select: function (index) { return index === 0 ? parenthesizer.parenthesizeLeadingTypeArgument : undefined; }
110397
+ };
110029
110398
  var emitBinaryExpression = createEmitBinaryExpression();
110030
110399
  reset();
110031
110400
  return {
@@ -111238,7 +111607,7 @@ var ts;
111238
111607
  writePunctuation("}");
111239
111608
  }
111240
111609
  function emitArrayType(node) {
111241
- emit(node.elementType, parenthesizer.parenthesizeElementTypeOfArrayType);
111610
+ emit(node.elementType, parenthesizer.parenthesizeNonArrayTypeOfPostfixType);
111242
111611
  writePunctuation("[");
111243
111612
  writePunctuation("]");
111244
111613
  }
@@ -111249,7 +111618,7 @@ var ts;
111249
111618
  function emitTupleType(node) {
111250
111619
  emitTokenWithComment(22 /* OpenBracketToken */, node.pos, writePunctuation, node);
111251
111620
  var flags = ts.getEmitFlags(node) & 1 /* SingleLine */ ? 528 /* SingleLineTupleTypeElements */ : 657 /* MultiLineTupleTypeElements */;
111252
- emitList(node, node.elements, flags | 524288 /* NoSpaceIfEmpty */);
111621
+ emitList(node, node.elements, flags | 524288 /* NoSpaceIfEmpty */, parenthesizer.parenthesizeElementTypeOfTupleType);
111253
111622
  emitTokenWithComment(23 /* CloseBracketToken */, node.elements.end, writePunctuation, node);
111254
111623
  }
111255
111624
  function emitNamedTupleMember(node) {
@@ -111261,21 +111630,21 @@ var ts;
111261
111630
  emit(node.type);
111262
111631
  }
111263
111632
  function emitOptionalType(node) {
111264
- emit(node.type, parenthesizer.parenthesizeElementTypeOfArrayType);
111633
+ emit(node.type, parenthesizer.parenthesizeTypeOfOptionalType);
111265
111634
  writePunctuation("?");
111266
111635
  }
111267
111636
  function emitUnionType(node) {
111268
- emitList(node, node.types, 516 /* UnionTypeConstituents */, parenthesizer.parenthesizeMemberOfElementType);
111637
+ emitList(node, node.types, 516 /* UnionTypeConstituents */, parenthesizer.parenthesizeConstituentTypeOfUnionType);
111269
111638
  }
111270
111639
  function emitIntersectionType(node) {
111271
- emitList(node, node.types, 520 /* IntersectionTypeConstituents */, parenthesizer.parenthesizeMemberOfElementType);
111640
+ emitList(node, node.types, 520 /* IntersectionTypeConstituents */, parenthesizer.parenthesizeConstituentTypeOfIntersectionType);
111272
111641
  }
111273
111642
  function emitConditionalType(node) {
111274
- emit(node.checkType, parenthesizer.parenthesizeMemberOfConditionalType);
111643
+ emit(node.checkType, parenthesizer.parenthesizeCheckTypeOfConditionalType);
111275
111644
  writeSpace();
111276
111645
  writeKeyword("extends");
111277
111646
  writeSpace();
111278
- emit(node.extendsType, parenthesizer.parenthesizeMemberOfConditionalType);
111647
+ emit(node.extendsType, parenthesizer.parenthesizeExtendsTypeOfConditionalType);
111279
111648
  writeSpace();
111280
111649
  writePunctuation("?");
111281
111650
  writeSpace();
@@ -111301,10 +111670,13 @@ var ts;
111301
111670
  function emitTypeOperator(node) {
111302
111671
  writeTokenText(node.operator, writeKeyword);
111303
111672
  writeSpace();
111304
- emit(node.type, parenthesizer.parenthesizeMemberOfElementType);
111673
+ var parenthesizerRule = node.operator === 145 /* ReadonlyKeyword */ ?
111674
+ parenthesizer.parenthesizeOperandOfReadonlyTypeOperator :
111675
+ parenthesizer.parenthesizeOperandOfTypeOperator;
111676
+ emit(node.type, parenthesizerRule);
111305
111677
  }
111306
111678
  function emitIndexedAccessType(node) {
111307
- emit(node.objectType, parenthesizer.parenthesizeMemberOfElementType);
111679
+ emit(node.objectType, parenthesizer.parenthesizeNonArrayTypeOfPostfixType);
111308
111680
  writePunctuation("[");
111309
111681
  emit(node.indexType);
111310
111682
  writePunctuation("]");
@@ -113038,7 +113410,7 @@ var ts;
113038
113410
  emitList(parentNode, decorators, 2146305 /* Decorators */);
113039
113411
  }
113040
113412
  function emitTypeArguments(parentNode, typeArguments) {
113041
- emitList(parentNode, typeArguments, 53776 /* TypeArguments */, parenthesizer.parenthesizeMemberOfElementType);
113413
+ emitList(parentNode, typeArguments, 53776 /* TypeArguments */, typeArgumentParenthesizerRuleSelector);
113042
113414
  }
113043
113415
  function emitTypeParameters(parentNode, typeParameters) {
113044
113416
  if (ts.isFunctionLike(parentNode) && parentNode.typeArguments) { // Quick info uses type arguments in place of type parameters on instantiated signatures
@@ -113157,6 +113529,7 @@ var ts;
113157
113529
  if (format & 128 /* Indented */) {
113158
113530
  increaseIndent();
113159
113531
  }
113532
+ var emitListItem = getEmitListItem(emit, parenthesizerRule);
113160
113533
  // Emit each child.
113161
113534
  var previousSibling = void 0;
113162
113535
  var previousSourceFileTextKind = void 0;
@@ -113207,12 +113580,7 @@ var ts;
113207
113580
  shouldEmitInterveningComments = mayEmitInterveningComments;
113208
113581
  }
113209
113582
  nextListElementPos = child.pos;
113210
- if (emit.length === 1) {
113211
- emit(child);
113212
- }
113213
- else {
113214
- emit(child, parenthesizerRule);
113215
- }
113583
+ emitListItem(child, emit, parenthesizerRule, i);
113216
113584
  if (shouldDecreaseIndentAfterEmit) {
113217
113585
  decreaseIndent();
113218
113586
  shouldDecreaseIndentAfterEmit = false;
@@ -114453,6 +114821,20 @@ var ts;
114453
114821
  TempFlags[TempFlags["CountMask"] = 268435455] = "CountMask";
114454
114822
  TempFlags[TempFlags["_i"] = 268435456] = "_i";
114455
114823
  })(TempFlags || (TempFlags = {}));
114824
+ function emitListItemNoParenthesizer(node, emit, _parenthesizerRule, _index) {
114825
+ emit(node);
114826
+ }
114827
+ function emitListItemWithParenthesizerRuleSelector(node, emit, parenthesizerRuleSelector, index) {
114828
+ emit(node, parenthesizerRuleSelector.select(index));
114829
+ }
114830
+ function emitListItemWithParenthesizerRule(node, emit, parenthesizerRule, _index) {
114831
+ emit(node, parenthesizerRule);
114832
+ }
114833
+ function getEmitListItem(emit, parenthesizerRule) {
114834
+ return emit.length === 1 ? emitListItemNoParenthesizer :
114835
+ typeof parenthesizerRule === "object" ? emitListItemWithParenthesizerRuleSelector :
114836
+ emitListItemWithParenthesizerRule;
114837
+ }
114456
114838
  })(ts || (ts = {}));
114457
114839
  /* @internal */
114458
114840
  var ts;
@@ -116519,7 +116901,7 @@ var ts;
116519
116901
  // moduleAugmentations has changed
116520
116902
  structureIsReused = 1 /* SafeModules */;
116521
116903
  }
116522
- if ((oldSourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */)) {
116904
+ if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
116523
116905
  // dynamicImport has changed
116524
116906
  structureIsReused = 1 /* SafeModules */;
116525
116907
  }
@@ -116683,6 +117065,9 @@ var ts;
116683
117065
  return !!sourceFilesFoundSearchingNodeModules.get(file.path);
116684
117066
  }
116685
117067
  function isSourceFileDefaultLibrary(file) {
117068
+ if (!file.isDeclarationFile) {
117069
+ return false;
117070
+ }
116686
117071
  if (file.hasNoDefaultLib) {
116687
117072
  return true;
116688
117073
  }
@@ -117194,7 +117579,7 @@ var ts;
117194
117579
  var node = _a[_i];
117195
117580
  collectModuleReferences(node, /*inAmbientModule*/ false);
117196
117581
  }
117197
- if ((file.flags & 1048576 /* PossiblyContainsDynamicImport */) || isJavaScriptFile) {
117582
+ if ((file.flags & 2097152 /* PossiblyContainsDynamicImport */) || isJavaScriptFile) {
117198
117583
  collectDynamicImportOrRequireCalls(file);
117199
117584
  }
117200
117585
  file.imports = imports || ts.emptyArray;
@@ -117792,7 +118177,7 @@ var ts;
117792
118177
  && index < file.imports.length
117793
118178
  && !elideImport
117794
118179
  && !(isJsFile && !ts.getAllowJSCompilerOption(optionsForFile))
117795
- && (ts.isInJSFile(file.imports[index]) || !(file.imports[index].flags & 4194304 /* JSDoc */));
118180
+ && (ts.isInJSFile(file.imports[index]) || !(file.imports[index].flags & 8388608 /* JSDoc */));
117796
118181
  if (elideImport) {
117797
118182
  modulesWithElidedImports.set(file.path, true);
117798
118183
  }
@@ -117873,21 +118258,6 @@ var ts;
117873
118258
  return resolvedRef;
117874
118259
  }
117875
118260
  function verifyCompilerOptions() {
117876
- var isNightly = ts.stringContains(ts.version, "-dev") || ts.stringContains(ts.version, "-insiders");
117877
- if (!isNightly) {
117878
- if (ts.getEmitModuleKind(options) === ts.ModuleKind.Node12) {
117879
- createOptionValueDiagnostic("module", ts.Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "module", "node12");
117880
- }
117881
- else if (ts.getEmitModuleKind(options) === ts.ModuleKind.NodeNext) {
117882
- createOptionValueDiagnostic("module", ts.Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "module", "nodenext");
117883
- }
117884
- else if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12) {
117885
- createOptionValueDiagnostic("moduleResolution", ts.Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "moduleResolution", "node12");
117886
- }
117887
- else if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
117888
- createOptionValueDiagnostic("moduleResolution", ts.Diagnostics.Compiler_option_0_of_value_1_is_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next, "moduleResolution", "nodenext");
117889
- }
117890
- }
117891
118261
  if (options.strictPropertyInitialization && !ts.getStrictOptionValue(options, "strictNullChecks")) {
117892
118262
  createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks");
117893
118263
  }
@@ -127091,7 +127461,7 @@ var ts;
127091
127461
  result.push("export" /* exportedModifier */);
127092
127462
  if (flags & 8192 /* Deprecated */)
127093
127463
  result.push("deprecated" /* deprecatedModifier */);
127094
- if (node.flags & 8388608 /* Ambient */)
127464
+ if (node.flags & 16777216 /* Ambient */)
127095
127465
  result.push("declare" /* ambientModifier */);
127096
127466
  if (node.kind === 271 /* ExportAssignment */)
127097
127467
  result.push("export" /* exportedModifier */);
@@ -133407,7 +133777,7 @@ var ts;
133407
133777
  var instantiatedType = tryGetObjectLiteralContextualType(objectLikeContainer, typeChecker);
133408
133778
  // Check completions for Object property value shorthand
133409
133779
  if (instantiatedType === undefined) {
133410
- if (objectLikeContainer.flags & 16777216 /* InWithStatement */) {
133780
+ if (objectLikeContainer.flags & 33554432 /* InWithStatement */) {
133411
133781
  return 2 /* Fail */;
133412
133782
  }
133413
133783
  isNonContextualObjectLiteral = true;
@@ -136070,17 +136440,25 @@ var ts;
136070
136440
  var options = { use: 1 /* References */ };
136071
136441
  var referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options);
136072
136442
  var checker = program.getTypeChecker();
136073
- var symbol = checker.getSymbolAtLocation(ts.getAdjustedReferenceLocation(Core.getAdjustedNode(node, options)));
136443
+ // Unless the starting node is a declaration (vs e.g. JSDoc), don't attempt to compute isDefinition
136444
+ var adjustedNode = Core.getAdjustedNode(node, options);
136445
+ var symbol = isDefinitionForReference(adjustedNode) ? checker.getSymbolAtLocation(adjustedNode) : undefined;
136074
136446
  return !referencedSymbols || !referencedSymbols.length ? undefined : ts.mapDefined(referencedSymbols, function (_a) {
136075
136447
  var definition = _a.definition, references = _a.references;
136076
136448
  // Only include referenced symbols that have a valid definition.
136077
136449
  return definition && {
136078
136450
  definition: checker.runWithCancellationToken(cancellationToken, function (checker) { return definitionToReferencedSymbolDefinitionInfo(definition, checker, node); }),
136079
- references: references.map(function (r) { return toReferenceEntry(r, symbol); })
136451
+ references: references.map(function (r) { return toReferencedSymbolEntry(r, symbol); })
136080
136452
  };
136081
136453
  });
136082
136454
  }
136083
136455
  FindAllReferences.findReferencedSymbols = findReferencedSymbols;
136456
+ function isDefinitionForReference(node) {
136457
+ return node.kind === 88 /* DefaultKeyword */
136458
+ || !!ts.getDeclarationFromName(node)
136459
+ || ts.isLiteralComputedPropertyDeclarationName(node)
136460
+ || (node.kind === 134 /* ConstructorKeyword */ && ts.isConstructorDeclaration(node.parent));
136461
+ }
136084
136462
  function getImplementationsAtPosition(program, cancellationToken, sourceFiles, sourceFile, position) {
136085
136463
  var node = ts.getTouchingPropertyName(sourceFile, position);
136086
136464
  var referenceEntries;
@@ -136209,13 +136587,19 @@ var ts;
136209
136587
  return __assign(__assign({}, entryToDocumentSpan(entry)), (providePrefixAndSuffixText && getPrefixAndSuffixText(entry, originalNode, checker)));
136210
136588
  }
136211
136589
  FindAllReferences.toRenameLocation = toRenameLocation;
136212
- function toReferenceEntry(entry, symbol) {
136590
+ function toReferencedSymbolEntry(entry, symbol) {
136591
+ var referenceEntry = toReferenceEntry(entry);
136592
+ if (!symbol)
136593
+ return referenceEntry;
136594
+ return __assign(__assign({}, referenceEntry), { isDefinition: entry.kind !== 0 /* Span */ && isDeclarationOfSymbol(entry.node, symbol) });
136595
+ }
136596
+ function toReferenceEntry(entry) {
136213
136597
  var documentSpan = entryToDocumentSpan(entry);
136214
136598
  if (entry.kind === 0 /* Span */) {
136215
- return __assign(__assign({}, documentSpan), { isWriteAccess: false, isDefinition: false });
136599
+ return __assign(__assign({}, documentSpan), { isWriteAccess: false });
136216
136600
  }
136217
136601
  var kind = entry.kind, node = entry.node;
136218
- return __assign(__assign({}, documentSpan), { isWriteAccess: isWriteAccessForReference(node), isDefinition: isDeclarationOfSymbol(node, symbol), isInString: kind === 2 /* StringLiteral */ ? true : undefined });
136602
+ return __assign(__assign({}, documentSpan), { isWriteAccess: isWriteAccessForReference(node), isInString: kind === 2 /* StringLiteral */ ? true : undefined });
136219
136603
  }
136220
136604
  FindAllReferences.toReferenceEntry = toReferenceEntry;
136221
136605
  function entryToDocumentSpan(entry) {
@@ -136358,7 +136742,7 @@ var ts;
136358
136742
  */
136359
136743
  function declarationIsWriteAccess(decl) {
136360
136744
  // Consider anything in an ambient declaration to be a write access since it may be coming from JS.
136361
- if (!!(decl.flags & 8388608 /* Ambient */))
136745
+ if (!!(decl.flags & 16777216 /* Ambient */))
136362
136746
  return true;
136363
136747
  switch (decl.kind) {
136364
136748
  case 221 /* BinaryExpression */:
@@ -136923,15 +137307,21 @@ var ts;
136923
137307
  }
136924
137308
  function eachExportReference(sourceFiles, checker, cancellationToken, exportSymbol, exportingModuleSymbol, exportName, isDefaultExport, cb) {
136925
137309
  var importTracker = FindAllReferences.createImportTracker(sourceFiles, new ts.Set(sourceFiles.map(function (f) { return f.fileName; })), checker, cancellationToken);
136926
- var _a = importTracker(exportSymbol, { exportKind: isDefaultExport ? 1 /* Default */ : 0 /* Named */, exportingModuleSymbol: exportingModuleSymbol }, /*isForRename*/ false), importSearches = _a.importSearches, indirectUsers = _a.indirectUsers;
137310
+ var _a = importTracker(exportSymbol, { exportKind: isDefaultExport ? 1 /* Default */ : 0 /* Named */, exportingModuleSymbol: exportingModuleSymbol }, /*isForRename*/ false), importSearches = _a.importSearches, indirectUsers = _a.indirectUsers, singleReferences = _a.singleReferences;
136927
137311
  for (var _i = 0, importSearches_2 = importSearches; _i < importSearches_2.length; _i++) {
136928
137312
  var importLocation = importSearches_2[_i][0];
136929
137313
  cb(importLocation);
136930
137314
  }
136931
- for (var _b = 0, indirectUsers_2 = indirectUsers; _b < indirectUsers_2.length; _b++) {
136932
- var indirectUser = indirectUsers_2[_b];
136933
- for (var _c = 0, _d = getPossibleSymbolReferenceNodes(indirectUser, isDefaultExport ? "default" : exportName); _c < _d.length; _c++) {
136934
- var node = _d[_c];
137315
+ for (var _b = 0, singleReferences_2 = singleReferences; _b < singleReferences_2.length; _b++) {
137316
+ var singleReference = singleReferences_2[_b];
137317
+ if (ts.isIdentifier(singleReference) && ts.isImportTypeNode(singleReference.parent)) {
137318
+ cb(singleReference);
137319
+ }
137320
+ }
137321
+ for (var _c = 0, indirectUsers_2 = indirectUsers; _c < indirectUsers_2.length; _c++) {
137322
+ var indirectUser = indirectUsers_2[_c];
137323
+ for (var _d = 0, _e = getPossibleSymbolReferenceNodes(indirectUser, isDefaultExport ? "default" : exportName); _d < _e.length; _d++) {
137324
+ var node = _e[_d];
136935
137325
  // Import specifiers should be handled by importSearches
136936
137326
  var symbol = checker.getSymbolAtLocation(node);
136937
137327
  var hasExportAssignmentDeclaration = ts.some(symbol === null || symbol === void 0 ? void 0 : symbol.declarations, function (d) { return ts.tryCast(d, ts.isExportAssignment) ? true : false; });
@@ -137933,7 +138323,7 @@ var ts;
137933
138323
  }
137934
138324
  Core.getIntersectingMeaningFromDeclarations = getIntersectingMeaningFromDeclarations;
137935
138325
  function isImplementation(node) {
137936
- return !!(node.flags & 8388608 /* Ambient */) ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) :
138326
+ return !!(node.flags & 16777216 /* Ambient */) ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) :
137937
138327
  (ts.isVariableLike(node) ? ts.hasInitializer(node) :
137938
138328
  ts.isFunctionLikeDeclaration(node) ? !!node.body :
137939
138329
  ts.isClassLike(node) || ts.isModuleOrEnumDeclaration(node));
@@ -138311,7 +138701,7 @@ var ts;
138311
138701
  function collect(node) {
138312
138702
  if (!node)
138313
138703
  return;
138314
- if (node.flags & 8388608 /* Ambient */) {
138704
+ if (node.flags & 16777216 /* Ambient */) {
138315
138705
  // do not descend into ambient nodes.
138316
138706
  return;
138317
138707
  }
@@ -138470,7 +138860,7 @@ var ts;
138470
138860
  }
138471
138861
  /** Gets the call sites that call out of the provided call hierarchy declaration. */
138472
138862
  function getOutgoingCalls(program, declaration) {
138473
- if (declaration.flags & 8388608 /* Ambient */ || ts.isMethodSignature(declaration)) {
138863
+ if (declaration.flags & 16777216 /* Ambient */ || ts.isMethodSignature(declaration)) {
138474
138864
  return [];
138475
138865
  }
138476
138866
  return ts.group(collectCallSites(program, declaration), getCallSiteGroupKey, function (entries) { return convertCallSiteGroupToOutgoingCall(program, entries); });
@@ -140604,8 +140994,8 @@ var ts;
140604
140994
  var changeTracker = ts.textChanges.ChangeTracker.fromContext({ host: host, formatContext: formatContext, preferences: preferences });
140605
140995
  var coalesceAndOrganizeImports = function (importGroup) { return ts.stableSort(coalesceImports(removeUnusedImports(importGroup, sourceFile, program, skipDestructiveCodeActions)), function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); }); };
140606
140996
  // All of the old ImportDeclarations in the file, in syntactic order.
140607
- var topLevelImportDecls = sourceFile.statements.filter(ts.isImportDeclaration);
140608
- organizeImportsWorker(topLevelImportDecls, coalesceAndOrganizeImports);
140997
+ var topLevelImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, sourceFile.statements.filter(ts.isImportDeclaration));
140998
+ topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
140609
140999
  // All of the old ExportDeclarations in the file, in syntactic order.
140610
141000
  var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
140611
141001
  organizeImportsWorker(topLevelExportDecls, coalesceExports);
@@ -140613,8 +141003,8 @@ var ts;
140613
141003
  var ambientModule = _a[_i];
140614
141004
  if (!ambientModule.body)
140615
141005
  continue;
140616
- var ambientModuleImportDecls = ambientModule.body.statements.filter(ts.isImportDeclaration);
140617
- organizeImportsWorker(ambientModuleImportDecls, coalesceAndOrganizeImports);
141006
+ var ambientModuleImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, ambientModule.body.statements.filter(ts.isImportDeclaration));
141007
+ ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
140618
141008
  var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
140619
141009
  organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
140620
141010
  }
@@ -140660,6 +141050,40 @@ var ts;
140660
141050
  }
140661
141051
  }
140662
141052
  OrganizeImports.organizeImports = organizeImports;
141053
+ function groupImportsByNewlineContiguous(sourceFile, importDecls) {
141054
+ var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, sourceFile.languageVariant);
141055
+ var groupImports = [];
141056
+ var groupIndex = 0;
141057
+ for (var _i = 0, importDecls_1 = importDecls; _i < importDecls_1.length; _i++) {
141058
+ var topLevelImportDecl = importDecls_1[_i];
141059
+ if (isNewGroup(sourceFile, topLevelImportDecl, scanner)) {
141060
+ groupIndex++;
141061
+ }
141062
+ if (!groupImports[groupIndex]) {
141063
+ groupImports[groupIndex] = [];
141064
+ }
141065
+ groupImports[groupIndex].push(topLevelImportDecl);
141066
+ }
141067
+ return groupImports;
141068
+ }
141069
+ // a new group is created if an import includes at least two new line
141070
+ // new line from multi-line comment doesn't count
141071
+ function isNewGroup(sourceFile, topLevelImportDecl, scanner) {
141072
+ var startPos = topLevelImportDecl.getFullStart();
141073
+ var endPos = topLevelImportDecl.getStart();
141074
+ scanner.setText(sourceFile.text, startPos, endPos - startPos);
141075
+ var numberOfNewLines = 0;
141076
+ while (scanner.getTokenPos() < endPos) {
141077
+ var tokenKind = scanner.scan();
141078
+ if (tokenKind === 4 /* NewLineTrivia */) {
141079
+ numberOfNewLines++;
141080
+ if (numberOfNewLines >= 2) {
141081
+ return true;
141082
+ }
141083
+ }
141084
+ }
141085
+ return false;
141086
+ }
140663
141087
  function removeUnusedImports(oldImports, sourceFile, program, skipDestructiveCodeActions) {
140664
141088
  // As a precaution, consider unused import detection to be destructive (GH #43051)
140665
141089
  if (skipDestructiveCodeActions) {
@@ -142895,10 +143319,13 @@ var ts;
142895
143319
  var contextualType = info.contextualType, argumentIndex = info.argumentIndex, argumentCount = info.argumentCount, argumentsSpan = info.argumentsSpan;
142896
143320
  // for optional function condition.
142897
143321
  var nonNullableContextualType = contextualType.getNonNullableType();
142898
- var signatures = nonNullableContextualType.getCallSignatures();
142899
- if (signatures.length !== 1)
143322
+ var symbol = nonNullableContextualType.symbol;
143323
+ if (symbol === undefined)
143324
+ return undefined;
143325
+ var signature = ts.lastOrUndefined(nonNullableContextualType.getCallSignatures());
143326
+ if (signature === undefined)
142900
143327
  return undefined;
142901
- var invocation = { kind: 2 /* Contextual */, signature: ts.first(signatures), node: startingToken, symbol: chooseBetterSymbol(nonNullableContextualType.symbol) };
143328
+ var invocation = { kind: 2 /* Contextual */, signature: signature, node: startingToken, symbol: chooseBetterSymbol(symbol) };
142902
143329
  return { isTypeParameterList: false, invocation: invocation, argumentsSpan: argumentsSpan, argumentIndex: argumentIndex, argumentCount: argumentCount };
142903
143330
  }
142904
143331
  function getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker) {
@@ -147068,9 +147495,9 @@ var ts;
147068
147495
  // for block indentation, we should look for a line which contains something that's not
147069
147496
  // whitespace.
147070
147497
  var currentToken = ts.getTokenAtPosition(sourceFile, position);
147071
- // for object literal, we want to the indentation work like block
147072
- // if { starts in any position (can be in the middle of line)
147073
- // the following indentation should treat { as starting of that line (including leading whitespace)
147498
+ // For object literals, we want indentation to work just like with blocks.
147499
+ // If the `{` starts in any position (even in the middle of a line), then
147500
+ // the following indentation should treat `{` as the start of that line (including leading whitespace).
147074
147501
  // ```
147075
147502
  // const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
147076
147503
  // ->
@@ -147088,7 +147515,8 @@ var ts;
147088
147515
  // y: undefined,
147089
147516
  // }
147090
147517
  // ```
147091
- if (options.indentStyle === ts.IndentStyle.Block || currentToken.kind === 18 /* OpenBraceToken */) {
147518
+ var isObjectLiteral = currentToken.kind === 18 /* OpenBraceToken */ && currentToken.parent.kind === 205 /* ObjectLiteralExpression */;
147519
+ if (options.indentStyle === ts.IndentStyle.Block || isObjectLiteral) {
147092
147520
  return getBlockIndent(sourceFile, position, options);
147093
147521
  }
147094
147522
  if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 221 /* BinaryExpression */) {
@@ -147101,7 +147529,9 @@ var ts;
147101
147529
  var containerList = getListByPosition(position, precedingToken.parent, sourceFile);
147102
147530
  // use list position if the preceding token is before any list items
147103
147531
  if (containerList && !ts.rangeContainsRange(containerList, precedingToken)) {
147104
- return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize; // TODO: GH#18217
147532
+ var useTheSameBaseIndentation = [213 /* FunctionExpression */, 214 /* ArrowFunction */].indexOf(currentToken.parent.kind) !== -1;
147533
+ var indentSize = useTheSameBaseIndentation ? 0 : options.indentSize;
147534
+ return getActualIndentationForListStartLine(containerList, sourceFile, options) + indentSize; // TODO: GH#18217
147105
147535
  }
147106
147536
  return getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options);
147107
147537
  }
@@ -148614,8 +149044,11 @@ var ts;
148614
149044
  function isTrivia(s) {
148615
149045
  return ts.skipTrivia(s, 0) === s.length;
148616
149046
  }
149047
+ // A transformation context that won't perform parenthesization, as some parenthesization rules
149048
+ // are more aggressive than is strictly necessary.
149049
+ var textChangesTransformationContext = __assign(__assign({}, ts.nullTransformationContext), { factory: ts.createNodeFactory(ts.nullTransformationContext.factory.flags | 1 /* NoParenthesizerRules */, ts.nullTransformationContext.factory.baseFactory) });
148617
149050
  function assignPositionsToNode(node) {
148618
- var visited = ts.visitEachChild(node, assignPositionsToNode, ts.nullTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
149051
+ var visited = ts.visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
148619
149052
  // create proxy node for non synthesized nodes
148620
149053
  var newNode = ts.nodeIsSynthesized(visited) ? visited : Object.create(visited);
148621
149054
  ts.setTextRangePosEnd(newNode, getPos(node), getEnd(node));
@@ -156580,7 +157013,7 @@ var ts;
156580
157013
  var modifiers = visibilityModifier ? ts.factory.createNodeArray([visibilityModifier]) : undefined;
156581
157014
  var type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
156582
157015
  var optional = !!(symbol.flags & 16777216 /* Optional */);
156583
- var ambient = !!(enclosingDeclaration.flags & 8388608 /* Ambient */) || isAmbient;
157016
+ var ambient = !!(enclosingDeclaration.flags & 16777216 /* Ambient */) || isAmbient;
156584
157017
  var quotePreference = ts.getQuotePreference(sourceFile, preferences);
156585
157018
  switch (declaration.kind) {
156586
157019
  case 166 /* PropertySignature */:
@@ -156675,7 +157108,11 @@ var ts;
156675
157108
  var program = context.program;
156676
157109
  var checker = program.getTypeChecker();
156677
157110
  var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156678
- var flags = 1 /* NoTruncation */ | 1073741824 /* NoUndefinedOptionalParameterType */ | 256 /* SuppressAnyReturnType */ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0);
157111
+ var flags = 1 /* NoTruncation */
157112
+ | 1073741824 /* NoUndefinedOptionalParameterType */
157113
+ | 256 /* SuppressAnyReturnType */
157114
+ | 524288 /* AllowEmptyTuple */
157115
+ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */);
156679
157116
  var signatureDeclaration = checker.signatureToSignatureDeclaration(signature, kind, enclosingDeclaration, flags, getNoopSymbolTrackerWithResolver(context));
156680
157117
  if (!signatureDeclaration) {
156681
157118
  return undefined;
@@ -158153,6 +158590,10 @@ var ts;
158153
158590
  }
158154
158591
  break;
158155
158592
  }
158593
+ case 200 /* ImportType */:
158594
+ var importTypeNode = parent;
158595
+ changes.replaceNode(importingSourceFile, parent, ts.factory.createImportTypeNode(importTypeNode.argument, ts.factory.createIdentifier(exportName), importTypeNode.typeArguments, importTypeNode.isTypeOf));
158596
+ break;
158156
158597
  default:
158157
158598
  ts.Debug.failBadSyntaxKind(parent);
158158
158599
  }
@@ -159047,6 +159488,7 @@ var ts;
159047
159488
  Messages.cannotAccessVariablesFromNestedScopes = createMessage("Cannot access variables from nested scopes");
159048
159489
  Messages.cannotExtractToJSClass = createMessage("Cannot extract constant to a class scope in JS");
159049
159490
  Messages.cannotExtractToExpressionArrowFunction = createMessage("Cannot extract constant to an arrow function without a block");
159491
+ Messages.cannotExtractFunctionsContainingThisToMethod = createMessage("Cannot extract functions containing this to method");
159050
159492
  })(Messages = extractSymbol.Messages || (extractSymbol.Messages = {}));
159051
159493
  var RangeFacts;
159052
159494
  (function (RangeFacts) {
@@ -159055,10 +159497,11 @@ var ts;
159055
159497
  RangeFacts[RangeFacts["IsGenerator"] = 2] = "IsGenerator";
159056
159498
  RangeFacts[RangeFacts["IsAsyncFunction"] = 4] = "IsAsyncFunction";
159057
159499
  RangeFacts[RangeFacts["UsesThis"] = 8] = "UsesThis";
159500
+ RangeFacts[RangeFacts["UsesThisInFunction"] = 16] = "UsesThisInFunction";
159058
159501
  /**
159059
159502
  * The range is in a function which needs the 'static' modifier in a class
159060
159503
  */
159061
- RangeFacts[RangeFacts["InStaticRegion"] = 16] = "InStaticRegion";
159504
+ RangeFacts[RangeFacts["InStaticRegion"] = 32] = "InStaticRegion";
159062
159505
  })(RangeFacts || (RangeFacts = {}));
159063
159506
  /**
159064
159507
  * getRangeToExtract takes a span inside a text file and returns either an expression or an array
@@ -159089,11 +159532,12 @@ var ts;
159089
159532
  // We'll modify these flags as we walk the tree to collect data
159090
159533
  // about what things need to be done as part of the extraction.
159091
159534
  var rangeFacts = RangeFacts.None;
159535
+ var thisNode;
159092
159536
  if (!start || !end) {
159093
159537
  // cannot find either start or end node
159094
159538
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
159095
159539
  }
159096
- if (start.flags & 4194304 /* JSDoc */) {
159540
+ if (start.flags & 8388608 /* JSDoc */) {
159097
159541
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractJSDoc)] };
159098
159542
  }
159099
159543
  if (start.parent !== end.parent) {
@@ -159127,7 +159571,7 @@ var ts;
159127
159571
  // the expression.
159128
159572
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
159129
159573
  }
159130
- return { targetRange: { range: statements, facts: rangeFacts, declarations: declarations } };
159574
+ return { targetRange: { range: statements, facts: rangeFacts, declarations: declarations, thisNode: thisNode } };
159131
159575
  }
159132
159576
  if (ts.isReturnStatement(start) && !start.expression) {
159133
159577
  // Makes no sense to extract an expression-less return statement.
@@ -159139,7 +159583,7 @@ var ts;
159139
159583
  if (errors) {
159140
159584
  return { errors: errors };
159141
159585
  }
159142
- return { targetRange: { range: getStatementOrExpressionRange(node), facts: rangeFacts, declarations: declarations } }; // TODO: GH#18217
159586
+ return { targetRange: { range: getStatementOrExpressionRange(node), facts: rangeFacts, declarations: declarations, thisNode: thisNode } }; // TODO: GH#18217
159143
159587
  /**
159144
159588
  * Attempt to refine the extraction node (generally, by shrinking it) to produce better results.
159145
159589
  * @param node The unrefined extraction node.
@@ -159219,7 +159663,7 @@ var ts;
159219
159663
  if (!ts.isStatement(nodeToCheck) && !(ts.isExpressionNode(nodeToCheck) && isExtractableExpression(nodeToCheck)) && !isStringLiteralJsxAttribute(nodeToCheck)) {
159220
159664
  return [ts.createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
159221
159665
  }
159222
- if (nodeToCheck.flags & 8388608 /* Ambient */) {
159666
+ if (nodeToCheck.flags & 16777216 /* Ambient */) {
159223
159667
  return [ts.createDiagnosticForNode(nodeToCheck, Messages.cannotExtractAmbientBlock)];
159224
159668
  }
159225
159669
  // If we're in a class, see whether we're in a static region (static property initializer, static method, class constructor parameter default)
@@ -159231,6 +159675,14 @@ var ts;
159231
159675
  var permittedJumps = 4 /* Return */;
159232
159676
  var seenLabels;
159233
159677
  visit(nodeToCheck);
159678
+ if (rangeFacts & RangeFacts.UsesThis) {
159679
+ var container = ts.getThisContainer(nodeToCheck, /** includeArrowFunctions */ false);
159680
+ if (container.kind === 256 /* FunctionDeclaration */ ||
159681
+ (container.kind === 169 /* MethodDeclaration */ && container.parent.kind === 205 /* ObjectLiteralExpression */) ||
159682
+ container.kind === 213 /* FunctionExpression */) {
159683
+ rangeFacts |= RangeFacts.UsesThisInFunction;
159684
+ }
159685
+ }
159234
159686
  return errors;
159235
159687
  function visit(node) {
159236
159688
  if (errors) {
@@ -159269,6 +159721,7 @@ var ts;
159269
159721
  }
159270
159722
  else {
159271
159723
  rangeFacts |= RangeFacts.UsesThis;
159724
+ thisNode = node;
159272
159725
  }
159273
159726
  break;
159274
159727
  case 214 /* ArrowFunction */:
@@ -159276,6 +159729,7 @@ var ts;
159276
159729
  ts.forEachChild(node, function check(n) {
159277
159730
  if (ts.isThis(n)) {
159278
159731
  rangeFacts |= RangeFacts.UsesThis;
159732
+ thisNode = node;
159279
159733
  }
159280
159734
  else if (ts.isClassLike(n) || (ts.isFunctionLike(n) && !ts.isArrowFunction(n))) {
159281
159735
  return false;
@@ -159332,6 +159786,7 @@ var ts;
159332
159786
  case 192 /* ThisType */:
159333
159787
  case 108 /* ThisKeyword */:
159334
159788
  rangeFacts |= RangeFacts.UsesThis;
159789
+ thisNode = node;
159335
159790
  break;
159336
159791
  case 250 /* LabeledStatement */: {
159337
159792
  var label = node.label;
@@ -159409,7 +159864,8 @@ var ts;
159409
159864
  return undefined;
159410
159865
  }
159411
159866
  function isScope(node) {
159412
- return ts.isFunctionLikeDeclaration(node) || ts.isSourceFile(node) || ts.isModuleBlock(node) || ts.isClassLike(node);
159867
+ return ts.isArrowFunction(node) ? ts.isFunctionBody(node.body) :
159868
+ ts.isFunctionLikeDeclaration(node) || ts.isSourceFile(node) || ts.isModuleBlock(node) || ts.isClassLike(node);
159413
159869
  }
159414
159870
  /**
159415
159871
  * Computes possible places we could extract the function into. For example,
@@ -159418,7 +159874,7 @@ var ts;
159418
159874
  */
159419
159875
  function collectEnclosingScopes(range) {
159420
159876
  var current = isReadonlyArray(range.range) ? ts.first(range.range) : range.range;
159421
- if (range.facts & RangeFacts.UsesThis) {
159877
+ if (range.facts & RangeFacts.UsesThis && !(range.facts & RangeFacts.UsesThisInFunction)) {
159422
159878
  // if range uses this as keyword or as type inside the class then it can only be extracted to a method of the containing class
159423
159879
  var containingClass = ts.getContainingClass(current);
159424
159880
  if (containingClass) {
@@ -159624,6 +160080,7 @@ var ts;
159624
160080
  var _b = transformFunctionBody(node, exposedVariableDeclarations, writes, substitutions, !!(range.facts & RangeFacts.HasReturn)), body = _b.body, returnValueProperty = _b.returnValueProperty;
159625
160081
  ts.suppressLeadingAndTrailingTrivia(body);
159626
160082
  var newFunction;
160083
+ var callThis = !!(range.facts & RangeFacts.UsesThisInFunction);
159627
160084
  if (ts.isClassLike(scope)) {
159628
160085
  // always create private method in TypeScript files
159629
160086
  var modifiers = isJS ? [] : [ts.factory.createModifier(121 /* PrivateKeyword */)];
@@ -159638,6 +160095,15 @@ var ts;
159638
160095
  /*questionToken*/ undefined, typeParameters, parameters, returnType, body);
159639
160096
  }
159640
160097
  else {
160098
+ if (callThis) {
160099
+ parameters.unshift(ts.factory.createParameterDeclaration(
160100
+ /*decorators*/ undefined,
160101
+ /*modifiers*/ undefined,
160102
+ /*dotDotDotToken*/ undefined,
160103
+ /*name*/ "this",
160104
+ /*questionToken*/ undefined, checker.typeToTypeNode(checker.getTypeAtLocation(range.thisNode), scope, 1 /* NoTruncation */),
160105
+ /*initializer*/ undefined));
160106
+ }
159641
160107
  newFunction = ts.factory.createFunctionDeclaration(
159642
160108
  /*decorators*/ undefined, range.facts & RangeFacts.IsAsyncFunction ? [ts.factory.createToken(131 /* AsyncKeyword */)] : undefined, range.facts & RangeFacts.IsGenerator ? ts.factory.createToken(41 /* AsteriskToken */) : undefined, functionName, typeParameters, parameters, returnType, body);
159643
160109
  }
@@ -159654,7 +160120,10 @@ var ts;
159654
160120
  var newNodes = [];
159655
160121
  // replace range with function call
159656
160122
  var called = getCalledExpression(scope, range, functionNameText);
159657
- var call = ts.factory.createCallExpression(called, callTypeArguments, // Note that no attempt is made to take advantage of type argument inference
160123
+ if (callThis) {
160124
+ callArguments.unshift(ts.factory.createIdentifier("this"));
160125
+ }
160126
+ var call = ts.factory.createCallExpression(callThis ? ts.factory.createPropertyAccessExpression(called, "call") : called, callTypeArguments, // Note that no attempt is made to take advantage of type argument inference
159658
160127
  callArguments);
159659
160128
  if (range.facts & RangeFacts.IsGenerator) {
159660
160129
  call = ts.factory.createYieldExpression(ts.factory.createToken(41 /* AsteriskToken */), call);
@@ -160265,6 +160734,9 @@ var ts;
160265
160734
  var errorNode = isReadonlyArray(targetRange.range) ? targetRange.range[0] : targetRange.range;
160266
160735
  constantErrorsPerScope[i].push(ts.createDiagnosticForNode(errorNode, Messages.cannotAccessVariablesFromNestedScopes));
160267
160736
  }
160737
+ if (targetRange.facts & RangeFacts.UsesThisInFunction && ts.isClassLike(scopes[i])) {
160738
+ functionErrorsPerScope[i].push(ts.createDiagnosticForNode(targetRange.thisNode, Messages.cannotExtractFunctionsContainingThisToMethod));
160739
+ }
160268
160740
  var hasWrite = false;
160269
160741
  var readonlyClassPropertyWrite;
160270
160742
  usagesPerScope[i].usages.forEach(function (value) {
@@ -160750,6 +161222,7 @@ var ts;
160750
161222
  }
160751
161223
  function doTypedefChange(changes, file, name, info) {
160752
161224
  var firstStatement = info.firstStatement, selection = info.selection, typeParameters = info.typeParameters;
161225
+ ts.setEmitFlags(selection, 1536 /* NoComments */ | 2048 /* NoNestedComments */);
160753
161226
  var node = ts.factory.createJSDocTypedefTag(ts.factory.createIdentifier("typedef"), ts.factory.createJSDocTypeExpression(selection), ts.factory.createIdentifier(name));
160754
161227
  var templates = [];
160755
161228
  ts.forEach(typeParameters, function (typeParameter) {
@@ -162780,7 +163253,7 @@ var ts;
162780
163253
  kind === 80 /* PrivateIdentifier */ ? new PrivateIdentifierObject(80 /* PrivateIdentifier */, pos, end) :
162781
163254
  new TokenObject(kind, pos, end);
162782
163255
  node.parent = parent;
162783
- node.flags = parent.flags & 25358336 /* ContextFlags */;
163256
+ node.flags = parent.flags & 50720768 /* ContextFlags */;
162784
163257
  return node;
162785
163258
  }
162786
163259
  var NodeObject = /** @class */ (function () {
@@ -164236,7 +164709,7 @@ var ts;
164236
164709
  }
164237
164710
  /// References and Occurrences
164238
164711
  function getOccurrencesAtPosition(fileName, position) {
164239
- return ts.flatMap(getDocumentHighlights(fileName, position, [fileName]), function (entry) { return entry.highlightSpans.map(function (highlightSpan) { return (__assign(__assign({ fileName: entry.fileName, textSpan: highlightSpan.textSpan, isWriteAccess: highlightSpan.kind === "writtenReference" /* writtenReference */, isDefinition: false }, highlightSpan.isInString && { isInString: true }), highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan })); }); });
164712
+ return ts.flatMap(getDocumentHighlights(fileName, position, [fileName]), function (entry) { return entry.highlightSpans.map(function (highlightSpan) { return (__assign(__assign({ fileName: entry.fileName, textSpan: highlightSpan.textSpan, isWriteAccess: highlightSpan.kind === "writtenReference" /* writtenReference */ }, highlightSpan.isInString && { isInString: true }), highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan })); }); });
164240
164713
  }
164241
164714
  function getDocumentHighlights(fileName, position, filesToSearch) {
164242
164715
  var normalizedFileName = ts.normalizePath(fileName);
@@ -164265,7 +164738,7 @@ var ts;
164265
164738
  }
164266
164739
  function getReferencesAtPosition(fileName, position) {
164267
164740
  synchronizeHostData();
164268
- return getReferencesWorker(ts.getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: 1 /* References */ }, function (entry, node, checker) { return ts.FindAllReferences.toReferenceEntry(entry, checker.getSymbolAtLocation(node)); });
164741
+ return getReferencesWorker(ts.getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: 1 /* References */ }, ts.FindAllReferences.toReferenceEntry);
164269
164742
  }
164270
164743
  function getReferencesWorker(node, position, options, cb) {
164271
164744
  synchronizeHostData();
@@ -164280,10 +164753,8 @@ var ts;
164280
164753
  return ts.FindAllReferences.findReferencedSymbols(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position);
164281
164754
  }
164282
164755
  function getFileReferences(fileName) {
164283
- var _a;
164284
164756
  synchronizeHostData();
164285
- var moduleSymbol = (_a = program.getSourceFile(fileName)) === null || _a === void 0 ? void 0 : _a.symbol;
164286
- return ts.FindAllReferences.Core.getReferencesForFileName(fileName, program, program.getSourceFiles()).map(function (r) { return ts.FindAllReferences.toReferenceEntry(r, moduleSymbol); });
164757
+ return ts.FindAllReferences.Core.getReferencesForFileName(fileName, program, program.getSourceFiles()).map(ts.FindAllReferences.toReferenceEntry);
164287
164758
  }
164288
164759
  function getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles) {
164289
164760
  if (excludeDtsFiles === void 0) { excludeDtsFiles = false; }
@@ -164756,7 +165227,7 @@ var ts;
164756
165227
  }
164757
165228
  function isUnclosedFragment(_a) {
164758
165229
  var closingFragment = _a.closingFragment, parent = _a.parent;
164759
- return !!(closingFragment.flags & 65536 /* ThisNodeHasError */) || (ts.isJsxFragment(parent) && isUnclosedFragment(parent));
165230
+ return !!(closingFragment.flags & 131072 /* ThisNodeHasError */) || (ts.isJsxFragment(parent) && isUnclosedFragment(parent));
164760
165231
  }
164761
165232
  function getSpanOfEnclosingComment(fileName, position, onlyMultiLine) {
164762
165233
  var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
@@ -165204,7 +165675,7 @@ var ts;
165204
165675
  tokenAtLocation = preceding;
165205
165676
  }
165206
165677
  // Cannot set breakpoint in ambient declarations
165207
- if (tokenAtLocation.flags & 8388608 /* Ambient */) {
165678
+ if (tokenAtLocation.flags & 16777216 /* Ambient */) {
165208
165679
  return undefined;
165209
165680
  }
165210
165681
  // Get the span in the node based on its syntax
@@ -173707,6 +174178,7 @@ var ts;
173707
174178
  logger.info("Finding references to " + location.fileName + " position " + location.pos + " in project " + project.getProjectName());
173708
174179
  var projectOutputs = project.getLanguageService().findReferences(location.fileName, location.pos);
173709
174180
  if (projectOutputs) {
174181
+ var clearIsDefinition = projectOutputs[0].references[0].isDefinition === undefined;
173710
174182
  var _loop_9 = function (referencedSymbol) {
173711
174183
  var mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(referencedSymbol.definition));
173712
174184
  var definition = mappedDefinitionFile === undefined ?
@@ -173720,6 +174192,9 @@ var ts;
173720
174192
  var ref = _b[_a];
173721
174193
  // If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
173722
174194
  if (!ts.contains(symbolToAddTo.references, ref, ts.documentSpansEqual) && !getMappedLocation(project, documentSpanLocation(ref))) {
174195
+ if (clearIsDefinition) {
174196
+ delete ref.isDefinition;
174197
+ }
173723
174198
  symbolToAddTo.references.push(ref);
173724
174199
  }
173725
174200
  }