typescript 4.7.0-dev.20220403 → 4.7.0-dev.20220406

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.20220403";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220406";
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) {
@@ -9082,6 +9083,7 @@ var ts;
9082
9083
  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
9084
  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
9085
  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."),
9086
+ 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
9087
  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
9088
  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
9089
  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 +14498,24 @@ var ts;
14496
14498
  // Returns true if this node contains a parse error anywhere underneath it.
14497
14499
  function containsParseError(node) {
14498
14500
  aggregateChildData(node);
14499
- return (node.flags & 262144 /* ThisNodeOrAnySubNodesHasError */) !== 0;
14501
+ return (node.flags & 524288 /* ThisNodeOrAnySubNodesHasError */) !== 0;
14500
14502
  }
14501
14503
  ts.containsParseError = containsParseError;
14502
14504
  function aggregateChildData(node) {
14503
- if (!(node.flags & 524288 /* HasAggregatedChildData */)) {
14505
+ if (!(node.flags & 1048576 /* HasAggregatedChildData */)) {
14504
14506
  // A node is considered to contain a parse error if:
14505
14507
  // a) the parser explicitly marked that it had an error
14506
14508
  // b) any of it's children reported that it had an error.
14507
- var thisNodeOrAnySubNodesHasError = ((node.flags & 65536 /* ThisNodeHasError */) !== 0) ||
14509
+ var thisNodeOrAnySubNodesHasError = ((node.flags & 131072 /* ThisNodeHasError */) !== 0) ||
14508
14510
  ts.forEachChild(node, containsParseError);
14509
14511
  // If so, mark ourselves accordingly.
14510
14512
  if (thisNodeOrAnySubNodesHasError) {
14511
- node.flags |= 262144 /* ThisNodeOrAnySubNodesHasError */;
14513
+ node.flags |= 524288 /* ThisNodeOrAnySubNodesHasError */;
14512
14514
  }
14513
14515
  // Also mark that we've propagated the child information to this node. This way we can
14514
14516
  // always consult the bit directly on this node without needing to check its children
14515
14517
  // again.
14516
- node.flags |= 524288 /* HasAggregatedChildData */;
14518
+ node.flags |= 1048576 /* HasAggregatedChildData */;
14517
14519
  }
14518
14520
  }
14519
14521
  function getSourceFileOfNode(node) {
@@ -16320,11 +16322,11 @@ var ts;
16320
16322
  }
16321
16323
  ts.isSourceFileNotJS = isSourceFileNotJS;
16322
16324
  function isInJSFile(node) {
16323
- return !!node && !!(node.flags & 131072 /* JavaScriptFile */);
16325
+ return !!node && !!(node.flags & 262144 /* JavaScriptFile */);
16324
16326
  }
16325
16327
  ts.isInJSFile = isInJSFile;
16326
16328
  function isInJsonFile(node) {
16327
- return !!node && !!(node.flags & 33554432 /* JsonFile */);
16329
+ return !!node && !!(node.flags & 67108864 /* JsonFile */);
16328
16330
  }
16329
16331
  ts.isInJsonFile = isInJsonFile;
16330
16332
  function isSourceFileNotJson(file) {
@@ -16332,7 +16334,7 @@ var ts;
16332
16334
  }
16333
16335
  ts.isSourceFileNotJson = isSourceFileNotJson;
16334
16336
  function isInJSDoc(node) {
16335
- return !!node && !!(node.flags & 4194304 /* JSDoc */);
16337
+ return !!node && !!(node.flags & 8388608 /* JSDoc */);
16336
16338
  }
16337
16339
  ts.isInJSDoc = isInJSDoc;
16338
16340
  function isJSDocIndexSignature(node) {
@@ -16718,7 +16720,7 @@ var ts;
16718
16720
  function setValueDeclaration(symbol, node) {
16719
16721
  var valueDeclaration = symbol.valueDeclaration;
16720
16722
  if (!valueDeclaration ||
16721
- !(node.flags & 8388608 /* Ambient */ && !(valueDeclaration.flags & 8388608 /* Ambient */)) &&
16723
+ !(node.flags & 16777216 /* Ambient */ && !(valueDeclaration.flags & 16777216 /* Ambient */)) &&
16722
16724
  (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) ||
16723
16725
  (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) {
16724
16726
  // other kinds of value declarations take precedence over modules and assignment declarations
@@ -16991,7 +16993,11 @@ var ts;
16991
16993
  ts.getEffectiveContainerForJSDocTemplateTag = getEffectiveContainerForJSDocTemplateTag;
16992
16994
  function getHostSignatureFromJSDoc(node) {
16993
16995
  var host = getEffectiveJSDocHost(node);
16994
- return host && ts.isFunctionLike(host) ? host : undefined;
16996
+ if (host) {
16997
+ return ts.isPropertySignature(host) && host.type && ts.isFunctionLike(host.type) ? host.type :
16998
+ ts.isFunctionLike(host) ? host : undefined;
16999
+ }
17000
+ return undefined;
16995
17001
  }
16996
17002
  ts.getHostSignatureFromJSDoc = getHostSignatureFromJSDoc;
16997
17003
  function getEffectiveJSDocHost(node) {
@@ -21016,7 +21022,7 @@ var ts;
21016
21022
  }
21017
21023
  ts.pseudoBigIntToString = pseudoBigIntToString;
21018
21024
  function isValidTypeOnlyAliasUseSite(useSite) {
21019
- return !!(useSite.flags & 8388608 /* Ambient */)
21025
+ return !!(useSite.flags & 16777216 /* Ambient */)
21020
21026
  || isPartOfTypeQuery(useSite)
21021
21027
  || isIdentifierInNonEmittingHeritageClause(useSite)
21022
21028
  || isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(useSite)
@@ -21469,11 +21475,20 @@ var ts;
21469
21475
  parenthesizeExpressionForDisallowedComma: parenthesizeExpressionForDisallowedComma,
21470
21476
  parenthesizeExpressionOfExpressionStatement: parenthesizeExpressionOfExpressionStatement,
21471
21477
  parenthesizeConciseBodyOfArrowFunction: parenthesizeConciseBodyOfArrowFunction,
21472
- parenthesizeMemberOfConditionalType: parenthesizeMemberOfConditionalType,
21473
- parenthesizeMemberOfElementType: parenthesizeMemberOfElementType,
21474
- parenthesizeElementTypeOfArrayType: parenthesizeElementTypeOfArrayType,
21475
- parenthesizeConstituentTypesOfUnionOrIntersectionType: parenthesizeConstituentTypesOfUnionOrIntersectionType,
21478
+ parenthesizeCheckTypeOfConditionalType: parenthesizeCheckTypeOfConditionalType,
21479
+ parenthesizeExtendsTypeOfConditionalType: parenthesizeExtendsTypeOfConditionalType,
21480
+ parenthesizeConstituentTypesOfUnionType: parenthesizeConstituentTypesOfUnionType,
21481
+ parenthesizeConstituentTypeOfUnionType: parenthesizeConstituentTypeOfUnionType,
21482
+ parenthesizeConstituentTypesOfIntersectionType: parenthesizeConstituentTypesOfIntersectionType,
21483
+ parenthesizeConstituentTypeOfIntersectionType: parenthesizeConstituentTypeOfIntersectionType,
21484
+ parenthesizeOperandOfTypeOperator: parenthesizeOperandOfTypeOperator,
21485
+ parenthesizeOperandOfReadonlyTypeOperator: parenthesizeOperandOfReadonlyTypeOperator,
21486
+ parenthesizeNonArrayTypeOfPostfixType: parenthesizeNonArrayTypeOfPostfixType,
21487
+ parenthesizeElementTypesOfTupleType: parenthesizeElementTypesOfTupleType,
21488
+ parenthesizeElementTypeOfTupleType: parenthesizeElementTypeOfTupleType,
21489
+ parenthesizeTypeOfOptionalType: parenthesizeTypeOfOptionalType,
21476
21490
  parenthesizeTypeArguments: parenthesizeTypeArguments,
21491
+ parenthesizeLeadingTypeArgument: parenthesizeLeadingTypeArgument,
21477
21492
  };
21478
21493
  function getParenthesizeLeftSideOfBinaryForOperator(operatorKind) {
21479
21494
  binaryLeftOperandParenthesizerCache || (binaryLeftOperandParenthesizerCache = new ts.Map());
@@ -21785,33 +21800,191 @@ var ts;
21785
21800
  }
21786
21801
  return body;
21787
21802
  }
21788
- function parenthesizeMemberOfConditionalType(member) {
21789
- return member.kind === 189 /* ConditionalType */ ? factory.createParenthesizedType(member) : member;
21803
+ // Type[Extends] :
21804
+ // FunctionOrConstructorType
21805
+ // ConditionalType[?Extends]
21806
+ // ConditionalType[Extends] :
21807
+ // UnionType[?Extends]
21808
+ // [~Extends] UnionType[~Extends] `extends` Type[+Extends] `?` Type[~Extends] `:` Type[~Extends]
21809
+ //
21810
+ // - The check type (the `UnionType`, above) does not allow function, constructor, or conditional types (they must be parenthesized)
21811
+ // - The extends type (the first `Type`, above) does not allow conditional types (they must be parenthesized). Function and constructor types are fine.
21812
+ // - The true and false branch types (the second and third `Type` non-terminals, above) allow any type
21813
+ function parenthesizeCheckTypeOfConditionalType(checkType) {
21814
+ switch (checkType.kind) {
21815
+ case 179 /* FunctionType */:
21816
+ case 180 /* ConstructorType */:
21817
+ case 189 /* ConditionalType */:
21818
+ return factory.createParenthesizedType(checkType);
21819
+ }
21820
+ return checkType;
21790
21821
  }
21791
- function parenthesizeMemberOfElementType(member) {
21792
- switch (member.kind) {
21822
+ function parenthesizeExtendsTypeOfConditionalType(extendsType) {
21823
+ switch (extendsType.kind) {
21824
+ case 189 /* ConditionalType */:
21825
+ return factory.createParenthesizedType(extendsType);
21826
+ }
21827
+ return extendsType;
21828
+ }
21829
+ // UnionType[Extends] :
21830
+ // `|`? IntersectionType[?Extends]
21831
+ // UnionType[?Extends] `|` IntersectionType[?Extends]
21832
+ //
21833
+ // - A union type constituent has the same precedence as the check type of a conditional type
21834
+ function parenthesizeConstituentTypeOfUnionType(type) {
21835
+ switch (type.kind) {
21836
+ case 187 /* UnionType */: // Not strictly necessary, but a union containing a union should have been flattened
21837
+ case 188 /* IntersectionType */: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests
21838
+ return factory.createParenthesizedType(type);
21839
+ }
21840
+ return parenthesizeCheckTypeOfConditionalType(type);
21841
+ }
21842
+ function parenthesizeConstituentTypesOfUnionType(members) {
21843
+ return factory.createNodeArray(ts.sameMap(members, parenthesizeConstituentTypeOfUnionType));
21844
+ }
21845
+ // IntersectionType[Extends] :
21846
+ // `&`? TypeOperator[?Extends]
21847
+ // IntersectionType[?Extends] `&` TypeOperator[?Extends]
21848
+ //
21849
+ // - An intersection type constituent does not allow function, constructor, conditional, or union types (they must be parenthesized)
21850
+ function parenthesizeConstituentTypeOfIntersectionType(type) {
21851
+ switch (type.kind) {
21793
21852
  case 187 /* UnionType */:
21853
+ case 188 /* IntersectionType */: // Not strictly necessary, but an intersection containing an intersection should have been flattened
21854
+ return factory.createParenthesizedType(type);
21855
+ }
21856
+ return parenthesizeConstituentTypeOfUnionType(type);
21857
+ }
21858
+ function parenthesizeConstituentTypesOfIntersectionType(members) {
21859
+ return factory.createNodeArray(ts.sameMap(members, parenthesizeConstituentTypeOfIntersectionType));
21860
+ }
21861
+ // TypeOperator[Extends] :
21862
+ // PostfixType
21863
+ // InferType[?Extends]
21864
+ // `keyof` TypeOperator[?Extends]
21865
+ // `unique` TypeOperator[?Extends]
21866
+ // `readonly` TypeOperator[?Extends]
21867
+ //
21868
+ function parenthesizeOperandOfTypeOperator(type) {
21869
+ switch (type.kind) {
21794
21870
  case 188 /* IntersectionType */:
21795
- case 179 /* FunctionType */:
21796
- case 180 /* ConstructorType */:
21797
- return factory.createParenthesizedType(member);
21871
+ return factory.createParenthesizedType(type);
21798
21872
  }
21799
- return parenthesizeMemberOfConditionalType(member);
21873
+ return parenthesizeConstituentTypeOfIntersectionType(type);
21800
21874
  }
21801
- function parenthesizeElementTypeOfArrayType(member) {
21802
- switch (member.kind) {
21803
- case 181 /* TypeQuery */:
21875
+ function parenthesizeOperandOfReadonlyTypeOperator(type) {
21876
+ switch (type.kind) {
21804
21877
  case 193 /* TypeOperator */:
21878
+ return factory.createParenthesizedType(type);
21879
+ }
21880
+ return parenthesizeOperandOfTypeOperator(type);
21881
+ }
21882
+ // PostfixType :
21883
+ // NonArrayType
21884
+ // NonArrayType [no LineTerminator here] `!` // JSDoc
21885
+ // NonArrayType [no LineTerminator here] `?` // JSDoc
21886
+ // IndexedAccessType
21887
+ // ArrayType
21888
+ //
21889
+ // IndexedAccessType :
21890
+ // NonArrayType `[` Type[~Extends] `]`
21891
+ //
21892
+ // ArrayType :
21893
+ // NonArrayType `[` `]`
21894
+ //
21895
+ function parenthesizeNonArrayTypeOfPostfixType(type) {
21896
+ switch (type.kind) {
21805
21897
  case 190 /* InferType */:
21806
- return factory.createParenthesizedType(member);
21898
+ case 193 /* TypeOperator */:
21899
+ case 181 /* TypeQuery */: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests
21900
+ return factory.createParenthesizedType(type);
21807
21901
  }
21808
- return parenthesizeMemberOfElementType(member);
21902
+ return parenthesizeOperandOfTypeOperator(type);
21809
21903
  }
21810
- function parenthesizeConstituentTypesOfUnionOrIntersectionType(members) {
21811
- return factory.createNodeArray(ts.sameMap(members, parenthesizeMemberOfElementType));
21904
+ // TupleType :
21905
+ // `[` Elision? `]`
21906
+ // `[` NamedTupleElementTypes `]`
21907
+ // `[` NamedTupleElementTypes `,` Elision? `]`
21908
+ // `[` TupleElementTypes `]`
21909
+ // `[` TupleElementTypes `,` Elision? `]`
21910
+ //
21911
+ // NamedTupleElementTypes :
21912
+ // Elision? NamedTupleMember
21913
+ // NamedTupleElementTypes `,` Elision? NamedTupleMember
21914
+ //
21915
+ // NamedTupleMember :
21916
+ // Identifier `?`? `:` Type[~Extends]
21917
+ // `...` Identifier `:` Type[~Extends]
21918
+ //
21919
+ // TupleElementTypes :
21920
+ // Elision? TupleElementType
21921
+ // TupleElementTypes `,` Elision? TupleElementType
21922
+ //
21923
+ // TupleElementType :
21924
+ // Type[~Extends] // NOTE: Needs cover grammar to disallow JSDoc postfix-optional
21925
+ // OptionalType
21926
+ // RestType
21927
+ //
21928
+ // OptionalType :
21929
+ // Type[~Extends] `?` // NOTE: Needs cover grammar to disallow JSDoc postfix-optional
21930
+ //
21931
+ // RestType :
21932
+ // `...` Type[~Extends]
21933
+ //
21934
+ function parenthesizeElementTypesOfTupleType(types) {
21935
+ return factory.createNodeArray(ts.sameMap(types, parenthesizeElementTypeOfTupleType));
21936
+ }
21937
+ function parenthesizeElementTypeOfTupleType(type) {
21938
+ if (hasJSDocPostfixQuestion(type))
21939
+ return factory.createParenthesizedType(type);
21940
+ return type;
21941
+ }
21942
+ function hasJSDocPostfixQuestion(type) {
21943
+ if (ts.isJSDocNullableType(type))
21944
+ return type.postfix;
21945
+ if (ts.isNamedTupleMember(type))
21946
+ return hasJSDocPostfixQuestion(type.type);
21947
+ if (ts.isFunctionTypeNode(type) || ts.isConstructorTypeNode(type) || ts.isTypeOperatorNode(type))
21948
+ return hasJSDocPostfixQuestion(type.type);
21949
+ if (ts.isConditionalTypeNode(type))
21950
+ return hasJSDocPostfixQuestion(type.falseType);
21951
+ if (ts.isUnionTypeNode(type))
21952
+ return hasJSDocPostfixQuestion(ts.last(type.types));
21953
+ if (ts.isIntersectionTypeNode(type))
21954
+ return hasJSDocPostfixQuestion(ts.last(type.types));
21955
+ if (ts.isInferTypeNode(type))
21956
+ return !!type.typeParameter.constraint && hasJSDocPostfixQuestion(type.typeParameter.constraint);
21957
+ return false;
21958
+ }
21959
+ function parenthesizeTypeOfOptionalType(type) {
21960
+ if (hasJSDocPostfixQuestion(type))
21961
+ return factory.createParenthesizedType(type);
21962
+ return parenthesizeNonArrayTypeOfPostfixType(type);
21963
+ }
21964
+ // function parenthesizeMemberOfElementType(member: TypeNode): TypeNode {
21965
+ // switch (member.kind) {
21966
+ // case SyntaxKind.UnionType:
21967
+ // case SyntaxKind.IntersectionType:
21968
+ // case SyntaxKind.FunctionType:
21969
+ // case SyntaxKind.ConstructorType:
21970
+ // return factory.createParenthesizedType(member);
21971
+ // }
21972
+ // return parenthesizeMemberOfConditionalType(member);
21973
+ // }
21974
+ // function parenthesizeElementTypeOfArrayType(member: TypeNode): TypeNode {
21975
+ // switch (member.kind) {
21976
+ // case SyntaxKind.TypeQuery:
21977
+ // case SyntaxKind.TypeOperator:
21978
+ // case SyntaxKind.InferType:
21979
+ // return factory.createParenthesizedType(member);
21980
+ // }
21981
+ // return parenthesizeMemberOfElementType(member);
21982
+ // }
21983
+ function parenthesizeLeadingTypeArgument(node) {
21984
+ return ts.isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory.createParenthesizedType(node) : node;
21812
21985
  }
21813
21986
  function parenthesizeOrdinalTypeArgument(node, i) {
21814
- return i === 0 && ts.isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory.createParenthesizedType(node) : node;
21987
+ return i === 0 ? parenthesizeLeadingTypeArgument(node) : node;
21815
21988
  }
21816
21989
  function parenthesizeTypeArguments(typeArguments) {
21817
21990
  if (ts.some(typeArguments)) {
@@ -21837,11 +22010,20 @@ var ts;
21837
22010
  parenthesizeExpressionForDisallowedComma: ts.identity,
21838
22011
  parenthesizeExpressionOfExpressionStatement: ts.identity,
21839
22012
  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); },
22013
+ parenthesizeCheckTypeOfConditionalType: ts.identity,
22014
+ parenthesizeExtendsTypeOfConditionalType: ts.identity,
22015
+ parenthesizeConstituentTypesOfUnionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
22016
+ parenthesizeConstituentTypeOfUnionType: ts.identity,
22017
+ parenthesizeConstituentTypesOfIntersectionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
22018
+ parenthesizeConstituentTypeOfIntersectionType: ts.identity,
22019
+ parenthesizeOperandOfTypeOperator: ts.identity,
22020
+ parenthesizeOperandOfReadonlyTypeOperator: ts.identity,
22021
+ parenthesizeNonArrayTypeOfPostfixType: ts.identity,
22022
+ parenthesizeElementTypesOfTupleType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
22023
+ parenthesizeElementTypeOfTupleType: ts.identity,
22024
+ parenthesizeTypeOfOptionalType: ts.identity,
21844
22025
  parenthesizeTypeArguments: function (nodes) { return nodes && ts.cast(nodes, ts.isNodeArray); },
22026
+ parenthesizeLeadingTypeArgument: ts.identity,
21845
22027
  };
21846
22028
  })(ts || (ts = {}));
21847
22029
  /* @internal */
@@ -21981,6 +22163,8 @@ var ts;
21981
22163
  var getJSDocPrimaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function () { return createJSDocPrimaryTypeWorker(kind); }; });
21982
22164
  var getJSDocUnaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function (type) { return createJSDocUnaryTypeWorker(kind, type); }; });
21983
22165
  var getJSDocUnaryTypeUpdateFunction = ts.memoizeOne(function (kind) { return function (node, type) { return updateJSDocUnaryTypeWorker(kind, node, type); }; });
22166
+ var getJSDocPrePostfixUnaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function (type, postfix) { return createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix); }; });
22167
+ var getJSDocPrePostfixUnaryTypeUpdateFunction = ts.memoizeOne(function (kind) { return function (node, type) { return updateJSDocPrePostfixUnaryTypeWorker(kind, node, type); }; });
21984
22168
  var getJSDocSimpleTagCreateFunction = ts.memoizeOne(function (kind) { return function (tagName, comment) { return createJSDocSimpleTagWorker(kind, tagName, comment); }; });
21985
22169
  var getJSDocSimpleTagUpdateFunction = ts.memoizeOne(function (kind) { return function (node, tagName, comment) { return updateJSDocSimpleTagWorker(kind, node, tagName, comment); }; });
21986
22170
  var getJSDocTypeLikeTagCreateFunction = ts.memoizeOne(function (kind) { return function (tagName, typeExpression, comment) { return createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment); }; });
@@ -21988,6 +22172,8 @@ var ts;
21988
22172
  var factory = {
21989
22173
  get parenthesizer() { return parenthesizerRules(); },
21990
22174
  get converters() { return converters(); },
22175
+ baseFactory: baseFactory,
22176
+ flags: flags,
21991
22177
  createNodeArray: createNodeArray,
21992
22178
  createNumericLiteral: createNumericLiteral,
21993
22179
  createBigIntLiteral: createBigIntLiteral,
@@ -22263,10 +22449,10 @@ var ts;
22263
22449
  // lazily load factory members for JSDoc types with similar structure
22264
22450
  get createJSDocAllType() { return getJSDocPrimaryTypeCreateFunction(312 /* JSDocAllType */); },
22265
22451
  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 */); },
22452
+ get createJSDocNonNullableType() { return getJSDocPrePostfixUnaryTypeCreateFunction(315 /* JSDocNonNullableType */); },
22453
+ get updateJSDocNonNullableType() { return getJSDocPrePostfixUnaryTypeUpdateFunction(315 /* JSDocNonNullableType */); },
22454
+ get createJSDocNullableType() { return getJSDocPrePostfixUnaryTypeCreateFunction(314 /* JSDocNullableType */); },
22455
+ get updateJSDocNullableType() { return getJSDocPrePostfixUnaryTypeUpdateFunction(314 /* JSDocNullableType */); },
22270
22456
  get createJSDocOptionalType() { return getJSDocUnaryTypeCreateFunction(316 /* JSDocOptionalType */); },
22271
22457
  get updateJSDocOptionalType() { return getJSDocUnaryTypeUpdateFunction(316 /* JSDocOptionalType */); },
22272
22458
  get createJSDocVariadicType() { return getJSDocUnaryTypeCreateFunction(318 /* JSDocVariadicType */); },
@@ -23382,7 +23568,7 @@ var ts;
23382
23568
  // @api
23383
23569
  function createArrayTypeNode(elementType) {
23384
23570
  var node = createBaseNode(183 /* ArrayType */);
23385
- node.elementType = parenthesizerRules().parenthesizeElementTypeOfArrayType(elementType);
23571
+ node.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType);
23386
23572
  node.transformFlags = 1 /* ContainsTypeScript */;
23387
23573
  return node;
23388
23574
  }
@@ -23395,7 +23581,7 @@ var ts;
23395
23581
  // @api
23396
23582
  function createTupleTypeNode(elements) {
23397
23583
  var node = createBaseNode(184 /* TupleType */);
23398
- node.elements = createNodeArray(elements);
23584
+ node.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements));
23399
23585
  node.transformFlags = 1 /* ContainsTypeScript */;
23400
23586
  return node;
23401
23587
  }
@@ -23427,7 +23613,7 @@ var ts;
23427
23613
  // @api
23428
23614
  function createOptionalTypeNode(type) {
23429
23615
  var node = createBaseNode(185 /* OptionalType */);
23430
- node.type = parenthesizerRules().parenthesizeElementTypeOfArrayType(type);
23616
+ node.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type);
23431
23617
  node.transformFlags = 1 /* ContainsTypeScript */;
23432
23618
  return node;
23433
23619
  }
@@ -23450,38 +23636,38 @@ var ts;
23450
23636
  ? update(createRestTypeNode(type), node)
23451
23637
  : node;
23452
23638
  }
23453
- function createUnionOrIntersectionTypeNode(kind, types) {
23639
+ function createUnionOrIntersectionTypeNode(kind, types, parenthesize) {
23454
23640
  var node = createBaseNode(kind);
23455
- node.types = parenthesizerRules().parenthesizeConstituentTypesOfUnionOrIntersectionType(types);
23641
+ node.types = factory.createNodeArray(parenthesize(types));
23456
23642
  node.transformFlags = 1 /* ContainsTypeScript */;
23457
23643
  return node;
23458
23644
  }
23459
- function updateUnionOrIntersectionTypeNode(node, types) {
23645
+ function updateUnionOrIntersectionTypeNode(node, types, parenthesize) {
23460
23646
  return node.types !== types
23461
- ? update(createUnionOrIntersectionTypeNode(node.kind, types), node)
23647
+ ? update(createUnionOrIntersectionTypeNode(node.kind, types, parenthesize), node)
23462
23648
  : node;
23463
23649
  }
23464
23650
  // @api
23465
23651
  function createUnionTypeNode(types) {
23466
- return createUnionOrIntersectionTypeNode(187 /* UnionType */, types);
23652
+ return createUnionOrIntersectionTypeNode(187 /* UnionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
23467
23653
  }
23468
23654
  // @api
23469
23655
  function updateUnionTypeNode(node, types) {
23470
- return updateUnionOrIntersectionTypeNode(node, types);
23656
+ return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
23471
23657
  }
23472
23658
  // @api
23473
23659
  function createIntersectionTypeNode(types) {
23474
- return createUnionOrIntersectionTypeNode(188 /* IntersectionType */, types);
23660
+ return createUnionOrIntersectionTypeNode(188 /* IntersectionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
23475
23661
  }
23476
23662
  // @api
23477
23663
  function updateIntersectionTypeNode(node, types) {
23478
- return updateUnionOrIntersectionTypeNode(node, types);
23664
+ return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
23479
23665
  }
23480
23666
  // @api
23481
23667
  function createConditionalTypeNode(checkType, extendsType, trueType, falseType) {
23482
23668
  var node = createBaseNode(189 /* ConditionalType */);
23483
- node.checkType = parenthesizerRules().parenthesizeMemberOfConditionalType(checkType);
23484
- node.extendsType = parenthesizerRules().parenthesizeMemberOfConditionalType(extendsType);
23669
+ node.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType);
23670
+ node.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType);
23485
23671
  node.trueType = trueType;
23486
23672
  node.falseType = falseType;
23487
23673
  node.transformFlags = 1 /* ContainsTypeScript */;
@@ -23576,7 +23762,9 @@ var ts;
23576
23762
  function createTypeOperatorNode(operator, type) {
23577
23763
  var node = createBaseNode(193 /* TypeOperator */);
23578
23764
  node.operator = operator;
23579
- node.type = parenthesizerRules().parenthesizeMemberOfElementType(type);
23765
+ node.type = operator === 145 /* ReadonlyKeyword */ ?
23766
+ parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) :
23767
+ parenthesizerRules().parenthesizeOperandOfTypeOperator(type);
23580
23768
  node.transformFlags = 1 /* ContainsTypeScript */;
23581
23769
  return node;
23582
23770
  }
@@ -23589,7 +23777,7 @@ var ts;
23589
23777
  // @api
23590
23778
  function createIndexedAccessTypeNode(objectType, indexType) {
23591
23779
  var node = createBaseNode(194 /* IndexedAccessType */);
23592
- node.objectType = parenthesizerRules().parenthesizeMemberOfElementType(objectType);
23780
+ node.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType);
23593
23781
  node.indexType = indexType;
23594
23782
  node.transformFlags = 1 /* ContainsTypeScript */;
23595
23783
  return node;
@@ -25325,8 +25513,15 @@ var ts;
25325
25513
  return createBaseNode(kind);
25326
25514
  }
25327
25515
  // @api
25328
- // createJSDocNonNullableType
25329
25516
  // createJSDocNullableType
25517
+ // createJSDocNonNullableType
25518
+ function createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix) {
25519
+ if (postfix === void 0) { postfix = false; }
25520
+ var node = createJSDocUnaryTypeWorker(kind, postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type);
25521
+ node.postfix = postfix;
25522
+ return node;
25523
+ }
25524
+ // @api
25330
25525
  // createJSDocOptionalType
25331
25526
  // createJSDocVariadicType
25332
25527
  // createJSDocNamepathType
@@ -25338,6 +25533,12 @@ var ts;
25338
25533
  // @api
25339
25534
  // updateJSDocNonNullableType
25340
25535
  // updateJSDocNullableType
25536
+ function updateJSDocPrePostfixUnaryTypeWorker(kind, node, type) {
25537
+ return node.type !== type
25538
+ ? update(createJSDocPrePostfixUnaryTypeWorker(kind, type, node.postfix), node)
25539
+ : node;
25540
+ }
25541
+ // @api
25341
25542
  // updateJSDocOptionalType
25342
25543
  // updateJSDocVariadicType
25343
25544
  // updateJSDocNamepathType
@@ -30418,7 +30619,7 @@ var ts;
30418
30619
  || ts.isExportDeclaration(node) ? node : undefined;
30419
30620
  }
30420
30621
  function getImportMetaIfNecessary(sourceFile) {
30421
- return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
30622
+ return sourceFile.flags & 4194304 /* PossiblyContainsImportMeta */ ?
30422
30623
  walkTreeForImportMeta(sourceFile) :
30423
30624
  undefined;
30424
30625
  }
@@ -31073,7 +31274,7 @@ var ts;
31073
31274
  var newSourceFile = IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
31074
31275
  // 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
31276
  // We will manually port the flag to the new source file.
31076
- newSourceFile.flags |= (sourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */);
31277
+ newSourceFile.flags |= (sourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */);
31077
31278
  return newSourceFile;
31078
31279
  }
31079
31280
  ts.updateSourceFile = updateSourceFile;
@@ -31357,10 +31558,10 @@ var ts;
31357
31558
  switch (scriptKind) {
31358
31559
  case 1 /* JS */:
31359
31560
  case 2 /* JSX */:
31360
- contextFlags = 131072 /* JavaScriptFile */;
31561
+ contextFlags = 262144 /* JavaScriptFile */;
31361
31562
  break;
31362
31563
  case 6 /* JSON */:
31363
- contextFlags = 131072 /* JavaScriptFile */ | 33554432 /* JsonFile */;
31564
+ contextFlags = 262144 /* JavaScriptFile */ | 67108864 /* JsonFile */;
31364
31565
  break;
31365
31566
  default:
31366
31567
  contextFlags = 0 /* None */;
@@ -31395,7 +31596,7 @@ var ts;
31395
31596
  function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicator) {
31396
31597
  var isDeclarationFile = isDeclarationFileName(fileName);
31397
31598
  if (isDeclarationFile) {
31398
- contextFlags |= 8388608 /* Ambient */;
31599
+ contextFlags |= 16777216 /* Ambient */;
31399
31600
  }
31400
31601
  sourceFlags = contextFlags;
31401
31602
  // Prime the scanner.
@@ -31434,7 +31635,7 @@ var ts;
31434
31635
  node.jsDoc = jsDoc;
31435
31636
  if (hasDeprecatedTag) {
31436
31637
  hasDeprecatedTag = false;
31437
- node.flags |= 134217728 /* Deprecated */;
31638
+ node.flags |= 268435456 /* Deprecated */;
31438
31639
  }
31439
31640
  return node;
31440
31641
  }
@@ -31629,6 +31830,12 @@ var ts;
31629
31830
  function disallowInAnd(func) {
31630
31831
  return doInsideOfContext(4096 /* DisallowInContext */, func);
31631
31832
  }
31833
+ function allowConditionalTypesAnd(func) {
31834
+ return doOutsideOfContext(65536 /* DisallowConditionalTypesContext */, func);
31835
+ }
31836
+ function disallowConditionalTypesAnd(func) {
31837
+ return doInsideOfContext(65536 /* DisallowConditionalTypesContext */, func);
31838
+ }
31632
31839
  function doInYieldContext(func) {
31633
31840
  return doInsideOfContext(8192 /* YieldContext */, func);
31634
31841
  }
@@ -31656,6 +31863,9 @@ var ts;
31656
31863
  function inDisallowInContext() {
31657
31864
  return inContext(4096 /* DisallowInContext */);
31658
31865
  }
31866
+ function inDisallowConditionalTypesContext() {
31867
+ return inContext(65536 /* DisallowConditionalTypesContext */);
31868
+ }
31659
31869
  function inDecoratorContext() {
31660
31870
  return inContext(16384 /* DecoratorContext */);
31661
31871
  }
@@ -32040,7 +32250,7 @@ var ts;
32040
32250
  // flag so that we don't mark any subsequent nodes.
32041
32251
  if (parseErrorBeforeNextFinishedNode) {
32042
32252
  parseErrorBeforeNextFinishedNode = false;
32043
- node.flags |= 65536 /* ThisNodeHasError */;
32253
+ node.flags |= 131072 /* ThisNodeHasError */;
32044
32254
  }
32045
32255
  return node;
32046
32256
  }
@@ -32498,7 +32708,7 @@ var ts;
32498
32708
  // differently depending on what mode it is in.
32499
32709
  //
32500
32710
  // This also applies to all our other context flags as well.
32501
- var nodeContextFlags = node.flags & 25358336 /* ContextFlags */;
32711
+ var nodeContextFlags = node.flags & 50720768 /* ContextFlags */;
32502
32712
  if (nodeContextFlags !== contextFlags) {
32503
32713
  return undefined;
32504
32714
  }
@@ -32757,7 +32967,6 @@ var ts;
32757
32967
  default: return [undefined]; // TODO: GH#18217 `default: Debug.assertNever(context);`
32758
32968
  }
32759
32969
  }
32760
- // Parses a comma-delimited list of elements
32761
32970
  function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
32762
32971
  var saveParsingContext = parsingContext;
32763
32972
  parsingContext |= 1 << kind;
@@ -32767,7 +32976,11 @@ var ts;
32767
32976
  while (true) {
32768
32977
  if (isListElement(kind, /*inErrorRecovery*/ false)) {
32769
32978
  var startPos = scanner.getStartPos();
32770
- list.push(parseListElement(kind, parseElement));
32979
+ var result = parseListElement(kind, parseElement);
32980
+ if (!result) {
32981
+ return undefined;
32982
+ }
32983
+ list.push(result);
32771
32984
  commaStart = scanner.getTokenPos();
32772
32985
  if (parseOptional(27 /* CommaToken */)) {
32773
32986
  // No need to check for a zero length node since we know we parsed a comma
@@ -33020,7 +33233,7 @@ var ts;
33020
33233
  function parseJSDocNonNullableType() {
33021
33234
  var pos = getNodePos();
33022
33235
  nextToken();
33023
- return finishNode(factory.createJSDocNonNullableType(parseNonArrayType()), pos);
33236
+ return finishNode(factory.createJSDocNonNullableType(parseNonArrayType(), /*postfix*/ false), pos);
33024
33237
  }
33025
33238
  function parseJSDocUnknownOrNullableType() {
33026
33239
  var pos = getNodePos();
@@ -33044,7 +33257,7 @@ var ts;
33044
33257
  return finishNode(factory.createJSDocUnknownType(), pos);
33045
33258
  }
33046
33259
  else {
33047
- return finishNode(factory.createJSDocNullableType(parseType()), pos);
33260
+ return finishNode(factory.createJSDocNullableType(parseType(), /*postfix*/ false), pos);
33048
33261
  }
33049
33262
  }
33050
33263
  function parseJSDocFunctionType() {
@@ -33172,13 +33385,20 @@ var ts;
33172
33385
  }
33173
33386
  return name;
33174
33387
  }
33175
- function parseParameterInOuterAwaitContext() {
33176
- return parseParameterWorker(/*inOuterAwaitContext*/ true);
33388
+ function isParameterNameStart() {
33389
+ // Be permissive about await and yield by calling isBindingIdentifier instead of isIdentifier; disallowing
33390
+ // them during a speculative parse leads to many more follow-on errors than allowing the function to parse then later
33391
+ // complaining about the use of the keywords.
33392
+ return isBindingIdentifier() || token() === 22 /* OpenBracketToken */ || token() === 18 /* OpenBraceToken */;
33393
+ }
33394
+ function parseParameter(inOuterAwaitContext) {
33395
+ return parseParameterWorker(inOuterAwaitContext);
33177
33396
  }
33178
- function parseParameter() {
33179
- return parseParameterWorker(/*inOuterAwaitContext*/ false);
33397
+ function parseParameterForSpeculation(inOuterAwaitContext) {
33398
+ return parseParameterWorker(inOuterAwaitContext, /*allowAmbiguity*/ false);
33180
33399
  }
33181
- function parseParameterWorker(inOuterAwaitContext) {
33400
+ function parseParameterWorker(inOuterAwaitContext, allowAmbiguity) {
33401
+ if (allowAmbiguity === void 0) { allowAmbiguity = true; }
33182
33402
  var pos = getNodePos();
33183
33403
  var hasJSDoc = hasPrecedingJSDocComment();
33184
33404
  // FormalParameter [Yield,Await]:
@@ -33199,13 +33419,17 @@ var ts;
33199
33419
  var savedTopLevel = topLevel;
33200
33420
  topLevel = false;
33201
33421
  var modifiers = parseModifiers();
33202
- var node = withJSDoc(finishNode(factory.createParameterDeclaration(decorators, modifiers, parseOptionalToken(25 /* DotDotDotToken */), parseNameOfParameter(modifiers), parseOptionalToken(57 /* QuestionToken */), parseTypeAnnotation(), parseInitializer()), pos), hasJSDoc);
33422
+ var dotDotDotToken = parseOptionalToken(25 /* DotDotDotToken */);
33423
+ if (!allowAmbiguity && !isParameterNameStart()) {
33424
+ return undefined;
33425
+ }
33426
+ var node = withJSDoc(finishNode(factory.createParameterDeclaration(decorators, modifiers, dotDotDotToken, parseNameOfParameter(modifiers), parseOptionalToken(57 /* QuestionToken */), parseTypeAnnotation(), parseInitializer()), pos), hasJSDoc);
33203
33427
  topLevel = savedTopLevel;
33204
33428
  return node;
33205
33429
  }
33206
33430
  function parseReturnType(returnToken, isType) {
33207
33431
  if (shouldParseReturnType(returnToken, isType)) {
33208
- return parseTypeOrTypePredicate();
33432
+ return allowConditionalTypesAnd(parseTypeOrTypePredicate);
33209
33433
  }
33210
33434
  }
33211
33435
  function shouldParseReturnType(returnToken, isType) {
@@ -33224,7 +33448,7 @@ var ts;
33224
33448
  }
33225
33449
  return false;
33226
33450
  }
33227
- function parseParametersWorker(flags) {
33451
+ function parseParametersWorker(flags, allowAmbiguity) {
33228
33452
  // FormalParameters [Yield,Await]: (modified)
33229
33453
  // [empty]
33230
33454
  // FormalParameterList[?Yield,Await]
@@ -33244,7 +33468,7 @@ var ts;
33244
33468
  setAwaitContext(!!(flags & 2 /* Await */));
33245
33469
  var parameters = flags & 32 /* JSDoc */ ?
33246
33470
  parseDelimitedList(17 /* JSDocParameters */, parseJSDocParameter) :
33247
- parseDelimitedList(16 /* Parameters */, savedAwaitContext ? parseParameterInOuterAwaitContext : parseParameter);
33471
+ parseDelimitedList(16 /* Parameters */, function () { return allowAmbiguity ? parseParameter(savedAwaitContext) : parseParameterForSpeculation(savedAwaitContext); });
33248
33472
  setYieldContext(savedYieldContext);
33249
33473
  setAwaitContext(savedAwaitContext);
33250
33474
  return parameters;
@@ -33266,7 +33490,7 @@ var ts;
33266
33490
  if (!parseExpected(20 /* OpenParenToken */)) {
33267
33491
  return createMissingList();
33268
33492
  }
33269
- var parameters = parseParametersWorker(flags);
33493
+ var parameters = parseParametersWorker(flags, /*allowAmbiguity*/ true);
33270
33494
  parseExpected(21 /* CloseParenToken */);
33271
33495
  return parameters;
33272
33496
  }
@@ -33348,7 +33572,7 @@ var ts;
33348
33572
  return token() === 58 /* ColonToken */ || token() === 27 /* CommaToken */ || token() === 23 /* CloseBracketToken */;
33349
33573
  }
33350
33574
  function parseIndexSignatureDeclaration(pos, hasJSDoc, decorators, modifiers) {
33351
- var parameters = parseBracketedList(16 /* Parameters */, parseParameter, 22 /* OpenBracketToken */, 23 /* CloseBracketToken */);
33575
+ var parameters = parseBracketedList(16 /* Parameters */, function () { return parseParameter(/*inOuterAwaitContext*/ false); }, 22 /* OpenBracketToken */, 23 /* CloseBracketToken */);
33352
33576
  var type = parseTypeAnnotation();
33353
33577
  parseTypeMemberSemicolon();
33354
33578
  var node = factory.createIndexSignature(decorators, modifiers, parameters, type);
@@ -33620,7 +33844,7 @@ var ts;
33620
33844
  return finishNode(factory.createImportTypeAssertionContainer(clause, multiLine), pos);
33621
33845
  }
33622
33846
  function parseImportType() {
33623
- sourceFlags |= 1048576 /* PossiblyContainsDynamicImport */;
33847
+ sourceFlags |= 2097152 /* PossiblyContainsDynamicImport */;
33624
33848
  var pos = getNodePos();
33625
33849
  var isTypeOf = parseOptional(112 /* TypeOfKeyword */);
33626
33850
  parseExpected(100 /* ImportKeyword */);
@@ -33770,7 +33994,7 @@ var ts;
33770
33994
  switch (token()) {
33771
33995
  case 53 /* ExclamationToken */:
33772
33996
  nextToken();
33773
- type = finishNode(factory.createJSDocNonNullableType(type), pos);
33997
+ type = finishNode(factory.createJSDocNonNullableType(type, /*postfix*/ true), pos);
33774
33998
  break;
33775
33999
  case 57 /* QuestionToken */:
33776
34000
  // If next token is start of a type we have a conditional type
@@ -33778,7 +34002,7 @@ var ts;
33778
34002
  return type;
33779
34003
  }
33780
34004
  nextToken();
33781
- type = finishNode(factory.createJSDocNullableType(type), pos);
34005
+ type = finishNode(factory.createJSDocNullableType(type, /*postfix*/ true), pos);
33782
34006
  break;
33783
34007
  case 22 /* OpenBracketToken */:
33784
34008
  parseExpected(22 /* OpenBracketToken */);
@@ -33803,12 +34027,20 @@ var ts;
33803
34027
  parseExpected(operator);
33804
34028
  return finishNode(factory.createTypeOperatorNode(operator, parseTypeOperatorOrHigher()), pos);
33805
34029
  }
34030
+ function tryParseConstraintOfInferType() {
34031
+ if (parseOptional(94 /* ExtendsKeyword */)) {
34032
+ var constraint = disallowConditionalTypesAnd(parseType);
34033
+ if (inDisallowConditionalTypesContext() || token() !== 57 /* QuestionToken */) {
34034
+ return constraint;
34035
+ }
34036
+ }
34037
+ }
33806
34038
  function parseTypeParameterOfInferType() {
33807
34039
  var pos = getNodePos();
33808
- return finishNode(factory.createTypeParameterDeclaration(
33809
- /*modifiers*/ undefined, parseIdentifier(),
33810
- /*constraint*/ undefined,
33811
- /*defaultType*/ undefined), pos);
34040
+ var name = parseIdentifier();
34041
+ var constraint = tryParse(tryParseConstraintOfInferType);
34042
+ var node = factory.createTypeParameterDeclaration(/*modifiers*/ undefined, name, constraint);
34043
+ return finishNode(node, pos);
33812
34044
  }
33813
34045
  function parseInferType() {
33814
34046
  var pos = getNodePos();
@@ -33825,7 +34057,7 @@ var ts;
33825
34057
  case 137 /* InferKeyword */:
33826
34058
  return parseInferType();
33827
34059
  }
33828
- return parsePostfixTypeOrHigher();
34060
+ return allowConditionalTypesAnd(parsePostfixTypeOrHigher);
33829
34061
  }
33830
34062
  function parseFunctionOrConstructorTypeToError(isInUnionType) {
33831
34063
  // the function type and constructor type shorthand notation
@@ -33955,23 +34187,21 @@ var ts;
33955
34187
  return finishNode(factory.createTypePredicateNode(assertsModifier, parameterName, type), pos);
33956
34188
  }
33957
34189
  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) {
34190
+ if (contextFlags & 40960 /* TypeExcludesFlags */) {
34191
+ return doOutsideOfContext(40960 /* TypeExcludesFlags */, parseType);
34192
+ }
33963
34193
  if (isStartOfFunctionTypeOrConstructorType()) {
33964
34194
  return parseFunctionOrConstructorType();
33965
34195
  }
33966
34196
  var pos = getNodePos();
33967
34197
  var type = parseUnionTypeOrHigher();
33968
- if (!noConditionalTypes && !scanner.hasPrecedingLineBreak() && parseOptional(94 /* ExtendsKeyword */)) {
34198
+ if (!inDisallowConditionalTypesContext() && !scanner.hasPrecedingLineBreak() && parseOptional(94 /* ExtendsKeyword */)) {
33969
34199
  // The type following 'extends' is not permitted to be another conditional type
33970
- var extendsType = parseTypeWorker(/*noConditionalTypes*/ true);
34200
+ var extendsType = disallowConditionalTypesAnd(parseType);
33971
34201
  parseExpected(57 /* QuestionToken */);
33972
- var trueType = parseTypeWorker();
34202
+ var trueType = allowConditionalTypesAnd(parseType);
33973
34203
  parseExpected(58 /* ColonToken */);
33974
- var falseType = parseTypeWorker();
34204
+ var falseType = allowConditionalTypesAnd(parseType);
33975
34205
  return finishNode(factory.createConditionalTypeNode(type, extendsType, trueType, falseType), pos);
33976
34206
  }
33977
34207
  return type;
@@ -34398,7 +34628,16 @@ var ts;
34398
34628
  parameters = createMissingList();
34399
34629
  }
34400
34630
  else {
34401
- parameters = parseParametersWorker(isAsync);
34631
+ if (!allowAmbiguity) {
34632
+ var maybeParameters = parseParametersWorker(isAsync, allowAmbiguity);
34633
+ if (!maybeParameters) {
34634
+ return undefined;
34635
+ }
34636
+ parameters = maybeParameters;
34637
+ }
34638
+ else {
34639
+ parameters = parseParametersWorker(isAsync, allowAmbiguity);
34640
+ }
34402
34641
  if (!parseExpected(21 /* CloseParenToken */) && !allowAmbiguity) {
34403
34642
  return undefined;
34404
34643
  }
@@ -34799,7 +35038,7 @@ var ts;
34799
35038
  // var foo3 = require("subfolder
34800
35039
  // import * as foo1 from "module-from-node
34801
35040
  // We want this import to be a statement rather than import call expression
34802
- sourceFlags |= 1048576 /* PossiblyContainsDynamicImport */;
35041
+ sourceFlags |= 2097152 /* PossiblyContainsDynamicImport */;
34803
35042
  expression = parseTokenNode();
34804
35043
  }
34805
35044
  else if (lookAhead(nextTokenIsDot)) {
@@ -34807,7 +35046,7 @@ var ts;
34807
35046
  nextToken(); // advance past the 'import'
34808
35047
  nextToken(); // advance past the dot
34809
35048
  expression = finishNode(factory.createMetaProperty(100 /* ImportKeyword */, parseIdentifierName()), pos);
34810
- sourceFlags |= 2097152 /* PossiblyContainsImportMeta */;
35049
+ sourceFlags |= 4194304 /* PossiblyContainsImportMeta */;
34811
35050
  }
34812
35051
  else {
34813
35052
  expression = parseMemberExpressionOrHigher();
@@ -35023,7 +35262,7 @@ var ts;
35023
35262
  return finishNode(factory.createJsxOpeningFragment(), pos);
35024
35263
  }
35025
35264
  var tagName = parseJsxElementName();
35026
- var typeArguments = (contextFlags & 131072 /* JavaScriptFile */) === 0 ? tryParseTypeArguments() : undefined;
35265
+ var typeArguments = (contextFlags & 262144 /* JavaScriptFile */) === 0 ? tryParseTypeArguments() : undefined;
35027
35266
  var attributes = parseJsxAttributes();
35028
35267
  var node;
35029
35268
  if (token() === 31 /* GreaterThanToken */) {
@@ -35301,7 +35540,7 @@ var ts;
35301
35540
  return result;
35302
35541
  }
35303
35542
  function parseTypeArgumentsInExpression() {
35304
- if ((contextFlags & 131072 /* JavaScriptFile */) !== 0) {
35543
+ if ((contextFlags & 262144 /* JavaScriptFile */) !== 0) {
35305
35544
  // TypeArguments must not be parsed in JavaScript files to avoid ambiguity with binary operators.
35306
35545
  return undefined;
35307
35546
  }
@@ -35697,7 +35936,7 @@ var ts;
35697
35936
  var openParenParsed = parseExpected(20 /* OpenParenToken */);
35698
35937
  var expression = allowInAnd(parseExpression);
35699
35938
  parseExpectedMatchingBrackets(20 /* OpenParenToken */, 21 /* CloseParenToken */, openParenParsed, openParenPosition);
35700
- var statement = doInsideOfContext(16777216 /* InWithStatement */, parseStatement);
35939
+ var statement = doInsideOfContext(33554432 /* InWithStatement */, parseStatement);
35701
35940
  return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc);
35702
35941
  }
35703
35942
  function parseCaseClause() {
@@ -36072,16 +36311,16 @@ var ts;
36072
36311
  if (isAmbient) {
36073
36312
  for (var _i = 0, _a = modifiers; _i < _a.length; _i++) {
36074
36313
  var m = _a[_i];
36075
- m.flags |= 8388608 /* Ambient */;
36314
+ m.flags |= 16777216 /* Ambient */;
36076
36315
  }
36077
- return doInsideOfContext(8388608 /* Ambient */, function () { return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers); });
36316
+ return doInsideOfContext(16777216 /* Ambient */, function () { return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers); });
36078
36317
  }
36079
36318
  else {
36080
36319
  return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers);
36081
36320
  }
36082
36321
  }
36083
36322
  function tryReuseAmbientDeclaration() {
36084
- return doInsideOfContext(8388608 /* Ambient */, function () {
36323
+ return doInsideOfContext(16777216 /* Ambient */, function () {
36085
36324
  var node = currentNode(parsingContext);
36086
36325
  if (node) {
36087
36326
  return consumeNode(node);
@@ -36548,9 +36787,9 @@ var ts;
36548
36787
  if (isAmbient) {
36549
36788
  for (var _i = 0, _a = modifiers; _i < _a.length; _i++) {
36550
36789
  var m = _a[_i];
36551
- m.flags |= 8388608 /* Ambient */;
36790
+ m.flags |= 16777216 /* Ambient */;
36552
36791
  }
36553
- return doInsideOfContext(8388608 /* Ambient */, function () { return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers); });
36792
+ return doInsideOfContext(16777216 /* Ambient */, function () { return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers); });
36554
36793
  }
36555
36794
  else {
36556
36795
  return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers);
@@ -37115,7 +37354,7 @@ var ts;
37115
37354
  function parseJSDocTypeExpression(mayOmitBraces) {
37116
37355
  var pos = getNodePos();
37117
37356
  var hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(18 /* OpenBraceToken */);
37118
- var type = doInsideOfContext(4194304 /* JSDoc */, parseJSDocType);
37357
+ var type = doInsideOfContext(8388608 /* JSDoc */, parseJSDocType);
37119
37358
  if (!mayOmitBraces || hasBrace) {
37120
37359
  parseExpectedJSDoc(19 /* CloseBraceToken */);
37121
37360
  }
@@ -37144,7 +37383,7 @@ var ts;
37144
37383
  JSDocParser.parseJSDocNameReference = parseJSDocNameReference;
37145
37384
  function parseIsolatedJSDocComment(content, start, length) {
37146
37385
  initializeState("", content, 99 /* Latest */, /*_syntaxCursor:*/ undefined, 1 /* JS */);
37147
- var jsDoc = doInsideOfContext(4194304 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37386
+ var jsDoc = doInsideOfContext(8388608 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37148
37387
  var sourceFile = { languageVariant: 0 /* Standard */, text: content };
37149
37388
  var diagnostics = ts.attachFileToDiagnostics(parseDiagnostics, sourceFile);
37150
37389
  clearState();
@@ -37155,9 +37394,9 @@ var ts;
37155
37394
  var saveToken = currentToken;
37156
37395
  var saveParseDiagnosticsLength = parseDiagnostics.length;
37157
37396
  var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
37158
- var comment = doInsideOfContext(4194304 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37397
+ var comment = doInsideOfContext(8388608 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37159
37398
  ts.setParent(comment, parent);
37160
- if (contextFlags & 131072 /* JavaScriptFile */) {
37399
+ if (contextFlags & 262144 /* JavaScriptFile */) {
37161
37400
  if (!jsDocDiagnostics) {
37162
37401
  jsDocDiagnostics = [];
37163
37402
  }
@@ -37973,7 +38212,7 @@ var ts;
37973
38212
  if (isBracketed) {
37974
38213
  skipWhitespace();
37975
38214
  parseExpected(63 /* EqualsToken */);
37976
- defaultType = doInsideOfContext(4194304 /* JSDoc */, parseJSDocType);
38215
+ defaultType = doInsideOfContext(8388608 /* JSDoc */, parseJSDocType);
37977
38216
  parseExpected(23 /* CloseBracketToken */);
37978
38217
  }
37979
38218
  if (ts.nodeIsMissing(name)) {
@@ -45861,7 +46100,7 @@ var ts;
45861
46100
  function setExportContextFlag(node) {
45862
46101
  // A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
45863
46102
  // declarations with export modifiers) is an export context in which declarations are implicitly exported.
45864
- if (node.flags & 8388608 /* Ambient */ && !hasExportDeclarations(node)) {
46103
+ if (node.flags & 16777216 /* Ambient */ && !hasExportDeclarations(node)) {
45865
46104
  node.flags |= 64 /* ExportContext */;
45866
46105
  }
45867
46106
  else {
@@ -46064,8 +46303,8 @@ var ts;
46064
46303
  function checkContextualIdentifier(node) {
46065
46304
  // Report error only if there are no parse errors in file
46066
46305
  if (!file.parseDiagnostics.length &&
46067
- !(node.flags & 8388608 /* Ambient */) &&
46068
- !(node.flags & 4194304 /* JSDoc */) &&
46306
+ !(node.flags & 16777216 /* Ambient */) &&
46307
+ !(node.flags & 8388608 /* JSDoc */) &&
46069
46308
  !ts.isIdentifierName(node)) {
46070
46309
  // strict mode identifiers
46071
46310
  if (inStrictMode &&
@@ -47094,7 +47333,7 @@ var ts;
47094
47333
  if (node.kind === 340 /* JSDocParameterTag */ && container.kind !== 323 /* JSDocSignature */) {
47095
47334
  return;
47096
47335
  }
47097
- if (inStrictMode && !(node.flags & 8388608 /* Ambient */)) {
47336
+ if (inStrictMode && !(node.flags & 16777216 /* Ambient */)) {
47098
47337
  // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
47099
47338
  // strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
47100
47339
  checkStrictModeEvalOrArguments(node, node.name);
@@ -47113,7 +47352,7 @@ var ts;
47113
47352
  }
47114
47353
  }
47115
47354
  function bindFunctionDeclaration(node) {
47116
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */)) {
47355
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */)) {
47117
47356
  if (ts.isAsyncFunction(node)) {
47118
47357
  emitFlags |= 2048 /* HasAsyncFunctions */;
47119
47358
  }
@@ -47128,7 +47367,7 @@ var ts;
47128
47367
  }
47129
47368
  }
47130
47369
  function bindFunctionExpression(node) {
47131
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */)) {
47370
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */)) {
47132
47371
  if (ts.isAsyncFunction(node)) {
47133
47372
  emitFlags |= 2048 /* HasAsyncFunctions */;
47134
47373
  }
@@ -47141,7 +47380,7 @@ var ts;
47141
47380
  return bindAnonymousDeclaration(node, 16 /* Function */, bindingName);
47142
47381
  }
47143
47382
  function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
47144
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */) && ts.isAsyncFunction(node)) {
47383
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */) && ts.isAsyncFunction(node)) {
47145
47384
  emitFlags |= 2048 /* HasAsyncFunctions */;
47146
47385
  }
47147
47386
  if (currentFlow && ts.isObjectLiteralOrClassExpressionMethodOrAccessor(node)) {
@@ -47214,7 +47453,7 @@ var ts;
47214
47453
  // Rationale: we don't want to report errors on non-initialized var's since they are hoisted
47215
47454
  // On the other side we do want to report errors on non-initialized 'lets' because of TDZ
47216
47455
  var isError_1 = ts.unreachableCodeIsError(options) &&
47217
- !(node.flags & 8388608 /* Ambient */) &&
47456
+ !(node.flags & 16777216 /* Ambient */) &&
47218
47457
  (!ts.isVariableStatement(node) ||
47219
47458
  !!(ts.getCombinedNodeFlags(node.declarationList) & 3 /* BlockScoped */) ||
47220
47459
  node.declarationList.declarations.some(function (d) { return !!d.initializer; }));
@@ -48114,7 +48353,7 @@ var ts;
48114
48353
  ts.Debug.assert(!!(getNodeLinks(file).flags & 1 /* TypeChecked */));
48115
48354
  diagnostics = ts.addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName));
48116
48355
  checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) {
48117
- if (!ts.containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
48356
+ if (!ts.containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 16777216 /* Ambient */))) {
48118
48357
  (diagnostics || (diagnostics = [])).push(__assign(__assign({}, diag), { category: ts.DiagnosticCategory.Suggestion }));
48119
48358
  }
48120
48359
  });
@@ -48565,7 +48804,7 @@ var ts;
48565
48804
  return diagnostic;
48566
48805
  }
48567
48806
  function isDeprecatedSymbol(symbol) {
48568
- return !!(getDeclarationNodeFlagsFromSymbol(symbol) & 134217728 /* Deprecated */);
48807
+ return !!(getDeclarationNodeFlagsFromSymbol(symbol) & 268435456 /* Deprecated */);
48569
48808
  }
48570
48809
  function addDeprecatedSuggestion(location, declarations, deprecatedEntity) {
48571
48810
  var diagnostic = ts.createDiagnosticForNode(location, ts.Diagnostics._0_is_deprecated, deprecatedEntity);
@@ -48793,7 +49032,7 @@ var ts;
48793
49032
  else {
48794
49033
  // find a module that about to be augmented
48795
49034
  // do not validate names of augmentations that are defined in ambient context
48796
- var moduleNotFoundError = !(moduleName.parent.parent.flags & 8388608 /* Ambient */)
49035
+ var moduleNotFoundError = !(moduleName.parent.parent.flags & 16777216 /* Ambient */)
48797
49036
  ? ts.Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
48798
49037
  : undefined;
48799
49038
  var mainModule_1 = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*isForAugmentation*/ true);
@@ -48907,7 +49146,7 @@ var ts;
48907
49146
  if ((moduleKind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
48908
49147
  (!ts.outFile(compilerOptions)) ||
48909
49148
  isInTypeQuery(usage) ||
48910
- declaration.flags & 8388608 /* Ambient */) {
49149
+ declaration.flags & 16777216 /* Ambient */) {
48911
49150
  // nodes are in different files and order cannot be determined
48912
49151
  return true;
48913
49152
  }
@@ -48969,7 +49208,7 @@ var ts;
48969
49208
  if (usage.kind === 271 /* ExportAssignment */ && usage.isExportEquals) {
48970
49209
  return true;
48971
49210
  }
48972
- if (!!(usage.flags & 4194304 /* JSDoc */) || isInTypeQuery(usage) || usageInTypeDeclaration()) {
49211
+ if (!!(usage.flags & 8388608 /* JSDoc */) || isInTypeQuery(usage) || usageInTypeDeclaration()) {
48973
49212
  return true;
48974
49213
  }
48975
49214
  if (isUsedInFunctionOrInstanceProperty(usage, declaration)) {
@@ -49234,7 +49473,7 @@ var ts;
49234
49473
  // falls through
49235
49474
  case 261 /* ModuleDeclaration */:
49236
49475
  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))) {
49476
+ if (location.kind === 305 /* SourceFile */ || (ts.isModuleDeclaration(location) && location.flags & 16777216 /* Ambient */ && !ts.isGlobalScopeAugmentation(location))) {
49238
49477
  // It's an external module. First see if the module has an export default and if the local
49239
49478
  // name of that export default matches.
49240
49479
  if (result = moduleExports.get("default" /* Default */)) {
@@ -49557,7 +49796,7 @@ var ts;
49557
49796
  }
49558
49797
  }
49559
49798
  // 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 */)) {
49799
+ if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 8388608 /* JSDoc */)) {
49561
49800
  var merged = getMergedSymbol(result);
49562
49801
  if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
49563
49802
  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 +50051,7 @@ var ts;
49812
50051
  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
50052
  if (declaration === undefined)
49814
50053
  return ts.Debug.fail("checkResolvedBlockScopedVariable could not find block-scoped declaration");
49815
- if (!(declaration.flags & 8388608 /* Ambient */) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
50054
+ if (!(declaration.flags & 16777216 /* Ambient */) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
49816
50055
  var diagnosticMessage = void 0;
49817
50056
  var declarationName = ts.declarationNameToString(ts.getNameOfDeclaration(declaration));
49818
50057
  if (result.flags & 2 /* BlockScopedVariable */) {
@@ -50585,7 +50824,7 @@ var ts;
50585
50824
  }
50586
50825
  }
50587
50826
  function getAssignmentDeclarationLocation(node) {
50588
- var typeAlias = ts.findAncestor(node, function (node) { return !(ts.isJSDocNode(node) || node.flags & 4194304 /* JSDoc */) ? "quit" : ts.isJSDocTypeAlias(node); });
50827
+ var typeAlias = ts.findAncestor(node, function (node) { return !(ts.isJSDocNode(node) || node.flags & 8388608 /* JSDoc */) ? "quit" : ts.isJSDocTypeAlias(node); });
50589
50828
  if (typeAlias) {
50590
50829
  return;
50591
50830
  }
@@ -52053,7 +52292,20 @@ var ts;
52053
52292
  if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
52054
52293
  if (type.flags & 262144 /* TypeParameter */ && ts.contains(context.inferTypeParameters, type)) {
52055
52294
  context.approximateLength += (ts.symbolName(type.symbol).length + 6);
52056
- return ts.factory.createInferTypeNode(typeParameterToDeclarationWithConstraint(type, context, /*constraintNode*/ undefined));
52295
+ var constraintNode = void 0;
52296
+ var constraint = getConstraintOfTypeParameter(type);
52297
+ if (constraint) {
52298
+ // If the infer type has a constraint that is not the same as the constraint
52299
+ // we would have normally inferred based on context, we emit the constraint
52300
+ // using `infer T extends ?`. We omit inferred constraints from type references
52301
+ // as they may be elided.
52302
+ var inferredConstraint = getInferredTypeParameterConstraint(type, /*omitTypeReferences*/ true);
52303
+ if (!(inferredConstraint && isTypeIdenticalTo(constraint, inferredConstraint))) {
52304
+ context.approximateLength += 9;
52305
+ constraintNode = constraint && typeToTypeNodeHelper(constraint, context);
52306
+ }
52307
+ }
52308
+ return ts.factory.createInferTypeNode(typeParameterToDeclarationWithConstraint(type, context, constraintNode));
52057
52309
  }
52058
52310
  if (context.flags & 4 /* GenerateNamesForShadowedTypeParams */ &&
52059
52311
  type.flags & 262144 /* TypeParameter */ &&
@@ -54009,7 +54261,7 @@ var ts;
54009
54261
  newModifierFlags |= 1 /* Export */;
54010
54262
  }
54011
54263
  if (addingDeclare && !(newModifierFlags & 1 /* Export */) &&
54012
- (!enclosingDeclaration_1 || !(enclosingDeclaration_1.flags & 8388608 /* Ambient */)) &&
54264
+ (!enclosingDeclaration_1 || !(enclosingDeclaration_1.flags & 16777216 /* Ambient */)) &&
54013
54265
  (ts.isEnumDeclaration(node) || ts.isVariableStatement(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isModuleDeclaration(node))) {
54014
54266
  // Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope
54015
54267
  newModifierFlags |= 2 /* Ambient */;
@@ -54979,7 +55231,7 @@ var ts;
54979
55231
  var parent = getDeclarationContainer(node);
54980
55232
  // If the node is not exported or it is not ambient module element (except import declaration)
54981
55233
  if (!(ts.getCombinedModifierFlags(node) & 1 /* Export */) &&
54982
- !(node.kind !== 265 /* ImportEqualsDeclaration */ && parent.kind !== 305 /* SourceFile */ && parent.flags & 8388608 /* Ambient */)) {
55234
+ !(node.kind !== 265 /* ImportEqualsDeclaration */ && parent.kind !== 305 /* SourceFile */ && parent.flags & 16777216 /* Ambient */)) {
54983
55235
  return isGlobalSourceFile(parent);
54984
55236
  }
54985
55237
  // Exported members/ambient module elements (exception import declaration) are visible if parent is visible
@@ -55319,7 +55571,7 @@ var ts;
55319
55571
  }
55320
55572
  var pattern = declaration.parent;
55321
55573
  // 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)) {
55574
+ if (strictNullChecks && declaration.flags & 16777216 /* Ambient */ && ts.isParameterDeclaration(declaration)) {
55323
55575
  parentType = getNonNullableType(parentType);
55324
55576
  }
55325
55577
  // Filter `undefined` from the type we check against if the parent has an initializer and that initializer is not possibly `undefined`
@@ -55435,7 +55687,7 @@ var ts;
55435
55687
  }
55436
55688
  if ((noImplicitAny || ts.isInJSFile(declaration)) &&
55437
55689
  ts.isVariableDeclaration(declaration) && !ts.isBindingPattern(declaration.name) &&
55438
- !(ts.getCombinedModifierFlags(declaration) & 1 /* Export */) && !(declaration.flags & 8388608 /* Ambient */)) {
55690
+ !(ts.getCombinedModifierFlags(declaration) & 1 /* Export */) && !(declaration.flags & 16777216 /* Ambient */)) {
55439
55691
  // If --noImplicitAny is on or the declaration is in a Javascript file,
55440
55692
  // use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
55441
55693
  // initializer or a 'null' or 'undefined' initializer.
@@ -56891,7 +57143,7 @@ var ts;
56891
57143
  function isLiteralEnumMember(member) {
56892
57144
  var expr = member.initializer;
56893
57145
  if (!expr) {
56894
- return !(member.flags & 8388608 /* Ambient */);
57146
+ return !(member.flags & 16777216 /* Ambient */);
56895
57147
  }
56896
57148
  switch (expr.kind) {
56897
57149
  case 10 /* StringLiteral */:
@@ -59524,7 +59776,7 @@ var ts;
59524
59776
  function getConstraintDeclaration(type) {
59525
59777
  return ts.mapDefined(ts.filter(type.symbol && type.symbol.declarations, ts.isTypeParameterDeclaration), ts.getEffectiveConstraintOfTypeParameter)[0];
59526
59778
  }
59527
- function getInferredTypeParameterConstraint(typeParameter) {
59779
+ function getInferredTypeParameterConstraint(typeParameter, omitTypeReferences) {
59528
59780
  var _a;
59529
59781
  var inferences;
59530
59782
  if ((_a = typeParameter.symbol) === null || _a === void 0 ? void 0 : _a.declarations) {
@@ -59536,7 +59788,7 @@ var ts;
59536
59788
  // corresponding type parameter in 'Foo'. When multiple 'infer T' declarations are
59537
59789
  // present, we form an intersection of the inferred constraint types.
59538
59790
  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 */) {
59791
+ if (grandParent.kind === 178 /* TypeReference */ && !omitTypeReferences) {
59540
59792
  var typeReference = grandParent;
59541
59793
  var typeParameters = getTypeParametersForTypeReference(typeReference);
59542
59794
  if (typeParameters) {
@@ -59958,7 +60210,7 @@ var ts;
59958
60210
  return constraints ? getSubstitutionType(type, getIntersectionType(ts.append(constraints, type))) : type;
59959
60211
  }
59960
60212
  function isJSDocTypeReference(node) {
59961
- return !!(node.flags & 4194304 /* JSDoc */) && (node.kind === 178 /* TypeReference */ || node.kind === 200 /* ImportType */);
60213
+ return !!(node.flags & 8388608 /* JSDoc */) && (node.kind === 178 /* TypeReference */ || node.kind === 200 /* ImportType */);
59962
60214
  }
59963
60215
  function checkNoTypeArguments(node, symbol) {
59964
60216
  if (node.typeArguments) {
@@ -61517,7 +61769,7 @@ var ts;
61517
61769
  if (ts.isCallLikeExpression(parent)) {
61518
61770
  return ts.isCallOrNewExpression(parent) && ts.isIdentifier(node) && hasMatchingArgument(parent, node);
61519
61771
  }
61520
- return ts.every(symbol.declarations, function (d) { return !ts.isFunctionLike(d) || !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); });
61772
+ return ts.every(symbol.declarations, function (d) { return !ts.isFunctionLike(d) || !!(ts.getCombinedNodeFlags(d) & 268435456 /* Deprecated */); });
61521
61773
  }
61522
61774
  return true;
61523
61775
  }
@@ -61958,7 +62210,11 @@ var ts;
61958
62210
  return !root.isDistributive && isSingletonTupleType(root.node.checkType) && isSingletonTupleType(root.node.extendsType);
61959
62211
  }
61960
62212
  function isSingletonTupleType(node) {
61961
- return ts.isTupleTypeNode(node) && ts.length(node.elements) === 1 && !ts.isOptionalTypeNode(node.elements[0]) && !ts.isRestTypeNode(node.elements[0]);
62213
+ return ts.isTupleTypeNode(node) &&
62214
+ ts.length(node.elements) === 1 &&
62215
+ !ts.isOptionalTypeNode(node.elements[0]) &&
62216
+ !ts.isRestTypeNode(node.elements[0]) &&
62217
+ !(ts.isNamedTupleMember(node.elements[0]) && (node.elements[0].questionToken || node.elements[0].dotDotDotToken));
61962
62218
  }
61963
62219
  /**
61964
62220
  * We syntactually check for common nondistributive conditional shapes and unwrap them into
@@ -62206,7 +62462,7 @@ var ts;
62206
62462
  links.resolvedSymbol = unknownSymbol;
62207
62463
  return links.resolvedType = errorType;
62208
62464
  }
62209
- var targetMeaning = node.isTypeOf ? 111551 /* Value */ : node.flags & 4194304 /* JSDoc */ ? 111551 /* Value */ | 788968 /* Type */ : 788968 /* Type */;
62465
+ var targetMeaning = node.isTypeOf ? 111551 /* Value */ : node.flags & 8388608 /* JSDoc */ ? 111551 /* Value */ | 788968 /* Type */ : 788968 /* Type */;
62210
62466
  // TODO: Future work: support unions/generics/whatever via a deferred import-type
62211
62467
  var innerModuleSymbol = resolveExternalModuleName(node, node.argument.literal);
62212
62468
  if (!innerModuleSymbol) {
@@ -62542,7 +62798,7 @@ var ts;
62542
62798
  }
62543
62799
  // /** @return {this} */
62544
62800
  // x.prototype.m = function() { ... }
62545
- var host = node.flags & 4194304 /* JSDoc */ ? ts.getHostSignatureFromJSDoc(node) : undefined;
62801
+ var host = node.flags & 8388608 /* JSDoc */ ? ts.getHostSignatureFromJSDoc(node) : undefined;
62546
62802
  if (host && ts.isFunctionExpression(host) && ts.isBinaryExpression(host.parent) && ts.getAssignmentDeclarationKind(host.parent) === 3 /* PrototypeProperty */) {
62547
62803
  return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(host.parent.left).parent).thisType;
62548
62804
  }
@@ -62617,7 +62873,7 @@ var ts;
62617
62873
  case 143 /* NeverKeyword */:
62618
62874
  return neverType;
62619
62875
  case 148 /* ObjectKeyword */:
62620
- return node.flags & 131072 /* JavaScriptFile */ && !noImplicitAny ? anyType : nonPrimitiveType;
62876
+ return node.flags & 262144 /* JavaScriptFile */ && !noImplicitAny ? anyType : nonPrimitiveType;
62621
62877
  case 138 /* IntrinsicKeyword */:
62622
62878
  return intrinsicMarkerType;
62623
62879
  case 192 /* ThisType */:
@@ -66478,6 +66734,9 @@ var ts;
66478
66734
  function createMarkerType(symbol, source, target) {
66479
66735
  var mapper = makeUnaryTypeMapper(source, target);
66480
66736
  var type = getDeclaredTypeOfSymbol(symbol);
66737
+ if (isErrorType(type)) {
66738
+ return type;
66739
+ }
66481
66740
  var result = symbol.flags & 524288 /* TypeAlias */ ?
66482
66741
  getTypeAliasInstantiation(symbol, instantiateTypes(getSymbolLinks(symbol).typeParameters, mapper)) :
66483
66742
  createTypeReference(type, instantiateTypes(type.typeParameters, mapper));
@@ -67491,6 +67750,9 @@ var ts;
67491
67750
  var inference = inferences[i];
67492
67751
  if (t === inference.typeParameter) {
67493
67752
  if (fix && !inference.isFixed) {
67753
+ // Before we commit to a particular inference (and thus lock out any further inferences),
67754
+ // we infer from any intra-expression inference sites we have collected.
67755
+ inferFromIntraExpressionSites(context);
67494
67756
  clearCachedInferences(inferences);
67495
67757
  inference.isFixed = true;
67496
67758
  }
@@ -67507,6 +67769,37 @@ var ts;
67507
67769
  }
67508
67770
  }
67509
67771
  }
67772
+ function addIntraExpressionInferenceSite(context, node, type) {
67773
+ var _a;
67774
+ ((_a = context.intraExpressionInferenceSites) !== null && _a !== void 0 ? _a : (context.intraExpressionInferenceSites = [])).push({ node: node, type: type });
67775
+ }
67776
+ // We collect intra-expression inference sites within object and array literals to handle cases where
67777
+ // inferred types flow between context sensitive element expressions. For example:
67778
+ //
67779
+ // declare function foo<T>(arg: [(n: number) => T, (x: T) => void]): void;
67780
+ // foo([_a => 0, n => n.toFixed()]);
67781
+ //
67782
+ // Above, both arrow functions in the tuple argument are context sensitive, thus both are omitted from the
67783
+ // pass that collects inferences from the non-context sensitive parts of the arguments. In the subsequent
67784
+ // pass where nothing is omitted, we need to commit to an inference for T in order to contextually type the
67785
+ // parameter in the second arrow function, but we want to first infer from the return type of the first
67786
+ // arrow function. This happens automatically when the arrow functions are discrete arguments (because we
67787
+ // infer from each argument before processing the next), but when the arrow functions are elements of an
67788
+ // object or array literal, we need to perform intra-expression inferences early.
67789
+ function inferFromIntraExpressionSites(context) {
67790
+ if (context.intraExpressionInferenceSites) {
67791
+ for (var _i = 0, _a = context.intraExpressionInferenceSites; _i < _a.length; _i++) {
67792
+ var _b = _a[_i], node = _b.node, type = _b.type;
67793
+ var contextualType = node.kind === 169 /* MethodDeclaration */ ?
67794
+ getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) :
67795
+ getContextualType(node, 2 /* NoConstraints */);
67796
+ if (contextualType) {
67797
+ inferTypes(context.inferences, type, contextualType);
67798
+ }
67799
+ }
67800
+ context.intraExpressionInferenceSites = undefined;
67801
+ }
67802
+ }
67510
67803
  function createInferenceInfo(typeParameter) {
67511
67804
  return {
67512
67805
  typeParameter: typeParameter,
@@ -69489,7 +69782,7 @@ var ts;
69489
69782
  // parameter symbols with declarations that have explicit type annotations. Such references are
69490
69783
  // resolvable with no possibility of triggering circularities in control flow analysis.
69491
69784
  function getTypeOfDottedName(node, diagnostic) {
69492
- if (!(node.flags & 16777216 /* InWithStatement */)) {
69785
+ if (!(node.flags & 33554432 /* InWithStatement */)) {
69493
69786
  switch (node.kind) {
69494
69787
  case 79 /* Identifier */:
69495
69788
  var symbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(node));
@@ -70893,6 +71186,7 @@ var ts;
70893
71186
  // a generic type without a nullable constraint and x is a generic type. This is because when both obj
70894
71187
  // and x are of generic types T and K, we want the resulting type to be T[K].
70895
71188
  return parent.kind === 206 /* PropertyAccessExpression */ ||
71189
+ parent.kind === 161 /* QualifiedName */ ||
70896
71190
  parent.kind === 208 /* CallExpression */ && parent.expression === node ||
70897
71191
  parent.kind === 207 /* ElementAccessExpression */ && parent.expression === node &&
70898
71192
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
@@ -71186,7 +71480,7 @@ var ts;
71186
71480
  isInTypeQuery(node) || node.parent.kind === 275 /* ExportSpecifier */) ||
71187
71481
  node.parent.kind === 230 /* NonNullExpression */ ||
71188
71482
  declaration.kind === 254 /* VariableDeclaration */ && declaration.exclamationToken ||
71189
- declaration.flags & 8388608 /* Ambient */;
71483
+ declaration.flags & 16777216 /* Ambient */;
71190
71484
  var initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration) : type) :
71191
71485
  type === autoType || type === autoArrayType ? undefinedType :
71192
71486
  getOptionalType(type);
@@ -72194,7 +72488,7 @@ var ts;
72194
72488
  // exists. Otherwise, it is the type of the string index signature in T, if one exists.
72195
72489
  function getContextualTypeForObjectLiteralMethod(node, contextFlags) {
72196
72490
  ts.Debug.assert(ts.isObjectLiteralMethod(node));
72197
- if (node.flags & 16777216 /* InWithStatement */) {
72491
+ if (node.flags & 33554432 /* InWithStatement */) {
72198
72492
  // We cannot answer semantic questions within a with block, do not proceed any further
72199
72493
  return undefined;
72200
72494
  }
@@ -72382,7 +72676,7 @@ var ts;
72382
72676
  * @returns the contextual type of an expression.
72383
72677
  */
72384
72678
  function getContextualType(node, contextFlags) {
72385
- if (node.flags & 16777216 /* InWithStatement */) {
72679
+ if (node.flags & 33554432 /* InWithStatement */) {
72386
72680
  // We cannot answer semantic questions within a with block, do not proceed any further
72387
72681
  return undefined;
72388
72682
  }
@@ -72800,6 +73094,11 @@ var ts;
72800
73094
  var type = checkExpressionForMutableLocation(e, checkMode, elementContextualType, forceTuple);
72801
73095
  elementTypes.push(addOptionality(type, /*isProperty*/ true, hasOmittedExpression));
72802
73096
  elementFlags.push(hasOmittedExpression ? 2 /* Optional */ : 1 /* Required */);
73097
+ if (contextualType && someType(contextualType, isTupleLikeType) && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
73098
+ var inferenceContext = getInferenceContext(node);
73099
+ ts.Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context
73100
+ addIntraExpressionInferenceSite(inferenceContext, e, type);
73101
+ }
72803
73102
  }
72804
73103
  }
72805
73104
  if (inDestructuringPattern) {
@@ -73001,6 +73300,13 @@ var ts;
73001
73300
  prop.target = member;
73002
73301
  member = prop;
73003
73302
  allPropertiesTable === null || allPropertiesTable === void 0 ? void 0 : allPropertiesTable.set(prop.escapedName, prop);
73303
+ if (contextualType && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) &&
73304
+ (memberDecl.kind === 296 /* PropertyAssignment */ || memberDecl.kind === 169 /* MethodDeclaration */) && isContextSensitive(memberDecl)) {
73305
+ var inferenceContext = getInferenceContext(node);
73306
+ ts.Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context
73307
+ var inferenceNode = memberDecl.kind === 296 /* PropertyAssignment */ ? memberDecl.initializer : memberDecl;
73308
+ addIntraExpressionInferenceSite(inferenceContext, inferenceNode, type);
73309
+ }
73004
73310
  }
73005
73311
  else if (memberDecl.kind === 298 /* SpreadAssignment */) {
73006
73312
  if (languageVersion < 2 /* ES2015 */) {
@@ -74093,7 +74399,7 @@ var ts;
74093
74399
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
74094
74400
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
74095
74401
  }
74096
- if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
74402
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 268435456 /* Deprecated */) {
74097
74403
  addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
74098
74404
  }
74099
74405
  }
@@ -74161,7 +74467,7 @@ var ts;
74161
74467
  if (declaration && isPropertyWithoutInitializer(declaration)) {
74162
74468
  if (!ts.isStatic(declaration)) {
74163
74469
  var flowContainer = getControlFlowContainer(node);
74164
- if (flowContainer.kind === 171 /* Constructor */ && flowContainer.parent === declaration.parent && !(declaration.flags & 8388608 /* Ambient */)) {
74470
+ if (flowContainer.kind === 171 /* Constructor */ && flowContainer.parent === declaration.parent && !(declaration.flags & 16777216 /* Ambient */)) {
74165
74471
  assumeUninitialized = true;
74166
74472
  }
74167
74473
  }
@@ -74198,7 +74504,7 @@ var ts;
74198
74504
  }
74199
74505
  else if (valueDeclaration.kind === 257 /* ClassDeclaration */ &&
74200
74506
  node.parent.kind !== 178 /* TypeReference */ &&
74201
- !(valueDeclaration.flags & 8388608 /* Ambient */) &&
74507
+ !(valueDeclaration.flags & 16777216 /* Ambient */) &&
74202
74508
  !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)) {
74203
74509
  diagnosticMessage = error(right, ts.Diagnostics.Class_0_used_before_its_declaration, declarationName);
74204
74510
  }
@@ -74863,34 +75169,36 @@ var ts;
74863
75169
  if (node.kind !== 165 /* Decorator */) {
74864
75170
  var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
74865
75171
  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
75172
  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;
75173
+ if (couldContainTypeVariables(inferenceTargetType)) {
75174
+ // We clone the inference context to avoid disturbing a resolution in progress for an
75175
+ // outer call expression. Effectively we just want a snapshot of whatever has been
75176
+ // inferred for any outer call expression so far.
75177
+ var outerContext = getInferenceContext(node);
75178
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
75179
+ var instantiatedType = instantiateType(contextualType, outerMapper);
75180
+ // If the contextual type is a generic function type with a single call signature, we
75181
+ // instantiate the type with its own type parameters and type arguments. This ensures that
75182
+ // the type parameters are not erased to type any during type inference such that they can
75183
+ // be inferred as actual types from the contextual type. For example:
75184
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
75185
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
75186
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
75187
+ var contextualSignature = getSingleCallSignature(instantiatedType);
75188
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
75189
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
75190
+ instantiatedType;
75191
+ // Inferences made from return types have lower priority than all other inferences.
75192
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
75193
+ // Create a type mapper for instantiating generic contextual types using the inferences made
75194
+ // from the return type. We need a separate inference pass here because (a) instantiation of
75195
+ // the source type uses the outer context's return mapper (which excludes inferences made from
75196
+ // outer arguments), and (b) we don't want any further inferences going into this context.
75197
+ var returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
75198
+ var returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
75199
+ inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
75200
+ context.returnMapper = ts.some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : undefined;
75201
+ }
74894
75202
  }
74895
75203
  }
74896
75204
  var restType = getNonArrayRestType(signature);
@@ -74902,7 +75210,7 @@ var ts;
74902
75210
  }
74903
75211
  }
74904
75212
  var thisType = getThisTypeOfSignature(signature);
74905
- if (thisType) {
75213
+ if (thisType && couldContainTypeVariables(thisType)) {
74906
75214
  var thisArgumentNode = getThisArgumentOfCall(node);
74907
75215
  inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
74908
75216
  }
@@ -74910,11 +75218,13 @@ var ts;
74910
75218
  var arg = args[i];
74911
75219
  if (arg.kind !== 227 /* OmittedExpression */ && !(checkMode & 32 /* IsForStringLiteralArgumentCompletions */ && hasSkipDirectInferenceFlag(arg))) {
74912
75220
  var paramType = getTypeAtPosition(signature, i);
74913
- var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
74914
- inferTypes(context.inferences, argType, paramType);
75221
+ if (couldContainTypeVariables(paramType)) {
75222
+ var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
75223
+ inferTypes(context.inferences, argType, paramType);
75224
+ }
74915
75225
  }
74916
75226
  }
74917
- if (restType) {
75227
+ if (restType && couldContainTypeVariables(restType)) {
74918
75228
  var spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
74919
75229
  inferTypes(context.inferences, spreadType, restType);
74920
75230
  }
@@ -76494,7 +76804,7 @@ var ts;
76494
76804
  return returnType;
76495
76805
  }
76496
76806
  function checkDeprecatedSignature(signature, node) {
76497
- if (signature.declaration && signature.declaration.flags & 134217728 /* Deprecated */) {
76807
+ if (signature.declaration && signature.declaration.flags & 268435456 /* Deprecated */) {
76498
76808
  var suggestionNode = getDeprecatedSuggestionNode(node);
76499
76809
  var name = ts.tryGetPropertyAccessOrIdentifierToString(ts.getInvokedExpression(node));
76500
76810
  addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name, signatureToString(signature));
@@ -76638,7 +76948,7 @@ var ts;
76638
76948
  if (targetDeclarationKind !== 0 /* Unknown */) {
76639
76949
  var decl = ts.getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
76640
76950
  // function/variable declaration should be ambient
76641
- return !!decl && !!(decl.flags & 8388608 /* Ambient */);
76951
+ return !!decl && !!(decl.flags & 16777216 /* Ambient */);
76642
76952
  }
76643
76953
  return false;
76644
76954
  }
@@ -76833,7 +77143,7 @@ var ts;
76833
77143
  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
77144
  }
76835
77145
  var file = ts.getSourceFileOfNode(node);
76836
- ts.Debug.assert(!!(file.flags & 2097152 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
77146
+ ts.Debug.assert(!!(file.flags & 4194304 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
76837
77147
  return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
76838
77148
  }
76839
77149
  function getTypeOfParameter(symbol) {
@@ -78847,6 +79157,11 @@ var ts;
78847
79157
  context.contextualType = contextualType;
78848
79158
  context.inferenceContext = inferenceContext;
78849
79159
  var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
79160
+ // In CheckMode.Inferential we collect intra-expression inference sites to process before fixing any type
79161
+ // parameters. This information is no longer needed after the call to checkExpression.
79162
+ if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
79163
+ inferenceContext.intraExpressionInferenceSites = undefined;
79164
+ }
78850
79165
  // We strip literal freshness when an appropriate contextual type is present such that contextually typed
78851
79166
  // literals always preserve their literal types (otherwise they might widen during type inference). An alternative
78852
79167
  // here would be to not mark contextually typed literals as fresh in the first place.
@@ -79138,7 +79453,7 @@ var ts;
79138
79453
  return quickType;
79139
79454
  }
79140
79455
  // If a type has been cached for the node, return it.
79141
- if (node.flags & 67108864 /* TypeCached */ && flowTypeCache) {
79456
+ if (node.flags & 134217728 /* TypeCached */ && flowTypeCache) {
79142
79457
  var cachedType = flowTypeCache[getNodeId(node)];
79143
79458
  if (cachedType) {
79144
79459
  return cachedType;
@@ -79150,7 +79465,7 @@ var ts;
79150
79465
  if (flowInvocationCount !== startInvocationCount) {
79151
79466
  var cache = flowTypeCache || (flowTypeCache = []);
79152
79467
  cache[getNodeId(node)] = type;
79153
- ts.setNodeFlags(node, node.flags | 67108864 /* TypeCached */);
79468
+ ts.setNodeFlags(node, node.flags | 134217728 /* TypeCached */);
79154
79469
  }
79155
79470
  return type;
79156
79471
  }
@@ -79236,7 +79551,7 @@ var ts;
79236
79551
  if (compilerOptions.isolatedModules) {
79237
79552
  ts.Debug.assert(!!(type.symbol.flags & 128 /* ConstEnum */));
79238
79553
  var constEnumDeclaration = type.symbol.valueDeclaration;
79239
- if (constEnumDeclaration.flags & 8388608 /* Ambient */) {
79554
+ if (constEnumDeclaration.flags & 16777216 /* Ambient */) {
79240
79555
  error(node, ts.Diagnostics.Cannot_access_ambient_const_enums_when_the_isolatedModules_flag_is_provided);
79241
79556
  }
79242
79557
  }
@@ -79929,7 +80244,7 @@ var ts;
79929
80244
  checkDecorators(node);
79930
80245
  checkSignatureDeclaration(node);
79931
80246
  if (node.kind === 172 /* GetAccessor */) {
79932
- if (!(node.flags & 8388608 /* Ambient */) && ts.nodeIsPresent(node.body) && (node.flags & 256 /* HasImplicitReturn */)) {
80247
+ if (!(node.flags & 16777216 /* Ambient */) && ts.nodeIsPresent(node.body) && (node.flags & 256 /* HasImplicitReturn */)) {
79933
80248
  if (!(node.flags & 512 /* HasExplicitReturn */)) {
79934
80249
  error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value);
79935
80250
  }
@@ -80024,7 +80339,7 @@ var ts;
80024
80339
  }
80025
80340
  var symbol = getNodeLinks(node).resolvedSymbol;
80026
80341
  if (symbol) {
80027
- if (ts.some(symbol.declarations, function (d) { return isTypeDeclaration(d) && !!(d.flags & 134217728 /* Deprecated */); })) {
80342
+ if (ts.some(symbol.declarations, function (d) { return isTypeDeclaration(d) && !!(d.flags & 268435456 /* Deprecated */); })) {
80028
80343
  addDeprecatedSuggestion(getDeprecatedSuggestionNode(node), symbol.declarations, symbol.escapedName);
80029
80344
  }
80030
80345
  if (type.flags & 32 /* Enum */ && symbol.flags & 8 /* EnumMember */) {
@@ -80184,6 +80499,23 @@ var ts;
80184
80499
  grammarErrorOnNode(node, ts.Diagnostics.infer_declarations_are_only_permitted_in_the_extends_clause_of_a_conditional_type);
80185
80500
  }
80186
80501
  checkSourceElement(node.typeParameter);
80502
+ var symbol = getSymbolOfNode(node.typeParameter);
80503
+ if (symbol.declarations && symbol.declarations.length > 1) {
80504
+ var links = getSymbolLinks(symbol);
80505
+ if (!links.typeParametersChecked) {
80506
+ links.typeParametersChecked = true;
80507
+ var typeParameter = getDeclaredTypeOfTypeParameter(symbol);
80508
+ var declarations = ts.getDeclarationsOfKind(symbol, 163 /* TypeParameter */);
80509
+ if (!areTypeParametersIdentical(declarations, [typeParameter], function (decl) { return [decl]; })) {
80510
+ // Report an error on every conflicting declaration.
80511
+ var name = symbolToString(symbol);
80512
+ for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
80513
+ var declaration = declarations_4[_i];
80514
+ error(declaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_constraints, name);
80515
+ }
80516
+ }
80517
+ }
80518
+ }
80187
80519
  registerForUnusedIdentifiersCheck(node);
80188
80520
  }
80189
80521
  function checkTemplateLiteralType(node) {
@@ -80221,7 +80553,7 @@ var ts;
80221
80553
  getTypeFromTypeNode(node);
80222
80554
  }
80223
80555
  function isPrivateWithinAmbient(node) {
80224
- return (ts.hasEffectiveModifier(node, 8 /* Private */) || ts.isPrivateIdentifierClassElementDeclaration(node)) && !!(node.flags & 8388608 /* Ambient */);
80556
+ return (ts.hasEffectiveModifier(node, 8 /* Private */) || ts.isPrivateIdentifierClassElementDeclaration(node)) && !!(node.flags & 16777216 /* Ambient */);
80225
80557
  }
80226
80558
  function getEffectiveDeclarationFlags(n, flagsToCheck) {
80227
80559
  var flags = ts.getCombinedModifierFlags(n);
@@ -80230,7 +80562,7 @@ var ts;
80230
80562
  if (n.parent.kind !== 258 /* InterfaceDeclaration */ &&
80231
80563
  n.parent.kind !== 257 /* ClassDeclaration */ &&
80232
80564
  n.parent.kind !== 226 /* ClassExpression */ &&
80233
- n.flags & 8388608 /* Ambient */) {
80565
+ n.flags & 16777216 /* Ambient */) {
80234
80566
  if (!(flags & 2 /* Ambient */) && !(ts.isModuleBlock(n.parent) && ts.isModuleDeclaration(n.parent.parent) && ts.isGlobalScopeAugmentation(n.parent.parent))) {
80235
80567
  // It is nested in an ambient context, which means it is automatically exported
80236
80568
  flags |= 1 /* Export */;
@@ -80363,10 +80695,10 @@ var ts;
80363
80695
  var hasNonAmbientClass = false;
80364
80696
  var functionDeclarations = [];
80365
80697
  if (declarations) {
80366
- for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
80367
- var current = declarations_4[_i];
80698
+ for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) {
80699
+ var current = declarations_5[_i];
80368
80700
  var node = current;
80369
- var inAmbientContext = node.flags & 8388608 /* Ambient */;
80701
+ var inAmbientContext = node.flags & 16777216 /* Ambient */;
80370
80702
  var inAmbientContextOrInterface = node.parent && (node.parent.kind === 258 /* InterfaceDeclaration */ || node.parent.kind === 182 /* TypeLiteral */) || inAmbientContext;
80371
80703
  if (inAmbientContextOrInterface) {
80372
80704
  // check if declarations are consecutive only if they are non-ambient
@@ -81218,7 +81550,7 @@ var ts;
81218
81550
  // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function.
81219
81551
  var firstDeclaration = (_a = localSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(
81220
81552
  // Get first non javascript function declaration
81221
- function (declaration) { return declaration.kind === node.kind && !(declaration.flags & 131072 /* JavaScriptFile */); });
81553
+ function (declaration) { return declaration.kind === node.kind && !(declaration.flags & 262144 /* JavaScriptFile */); });
81222
81554
  // Only type check the symbol once
81223
81555
  if (node === firstDeclaration) {
81224
81556
  checkFunctionOrConstructorSymbol(localSymbol);
@@ -81340,7 +81672,7 @@ var ts;
81340
81672
  var symbol = getSymbolOfNode(member);
81341
81673
  if (!symbol.isReferenced
81342
81674
  && (ts.hasEffectiveModifier(member, 8 /* Private */) || ts.isNamedDeclaration(member) && ts.isPrivateIdentifier(member.name))
81343
- && !(member.flags & 8388608 /* Ambient */)) {
81675
+ && !(member.flags & 16777216 /* Ambient */)) {
81344
81676
  addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol)));
81345
81677
  }
81346
81678
  break;
@@ -81530,8 +81862,8 @@ var ts;
81530
81862
  : ts.createDiagnosticForNode(declarationList.parent.kind === 237 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused));
81531
81863
  }
81532
81864
  else {
81533
- for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) {
81534
- var decl = declarations_5[_i];
81865
+ for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
81866
+ var decl = declarations_6[_i];
81535
81867
  addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(decl.name)));
81536
81868
  }
81537
81869
  }
@@ -81573,7 +81905,7 @@ var ts;
81573
81905
  }
81574
81906
  function checkCollisionWithArgumentsInGeneratedCode(node) {
81575
81907
  // 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)) {
81908
+ if (languageVersion >= 2 /* ES2015 */ || !ts.hasRestParameter(node) || node.flags & 16777216 /* Ambient */ || ts.nodeIsMissing(node.body)) {
81577
81909
  return;
81578
81910
  }
81579
81911
  ts.forEach(node.parameters, function (p) {
@@ -81601,7 +81933,7 @@ var ts;
81601
81933
  // it is ok to have member named '_super', '_this', `Promise`, etc. - member access is always qualified
81602
81934
  return false;
81603
81935
  }
81604
- if (node.flags & 8388608 /* Ambient */) {
81936
+ if (node.flags & 16777216 /* Ambient */) {
81605
81937
  // ambient context - no codegen impact
81606
81938
  return false;
81607
81939
  }
@@ -81740,7 +82072,7 @@ var ts;
81740
82072
  recordPotentialCollisionWithReflectInGeneratedCode(node, name);
81741
82073
  if (ts.isClassLike(node)) {
81742
82074
  checkTypeNameIsReserved(name, ts.Diagnostics.Class_name_cannot_be_0);
81743
- if (!(node.flags & 8388608 /* Ambient */)) {
82075
+ if (!(node.flags & 16777216 /* Ambient */)) {
81744
82076
  checkClassNameCollisionWithObject(name);
81745
82077
  }
81746
82078
  }
@@ -83334,23 +83666,23 @@ var ts;
83334
83666
  return;
83335
83667
  }
83336
83668
  var type = getDeclaredTypeOfSymbol(symbol);
83337
- if (!areTypeParametersIdentical(declarations, type.localTypeParameters)) {
83669
+ if (!areTypeParametersIdentical(declarations, type.localTypeParameters, ts.getEffectiveTypeParameterDeclarations)) {
83338
83670
  // Report an error on every conflicting declaration.
83339
83671
  var name = symbolToString(symbol);
83340
- for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
83341
- var declaration = declarations_6[_i];
83672
+ for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
83673
+ var declaration = declarations_7[_i];
83342
83674
  error(declaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_type_parameters, name);
83343
83675
  }
83344
83676
  }
83345
83677
  }
83346
83678
  }
83347
- function areTypeParametersIdentical(declarations, targetParameters) {
83679
+ function areTypeParametersIdentical(declarations, targetParameters, getTypeParameterDeclarations) {
83348
83680
  var maxTypeArgumentCount = ts.length(targetParameters);
83349
83681
  var minTypeArgumentCount = getMinTypeArgumentCount(targetParameters);
83350
- for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
83351
- var declaration = declarations_7[_i];
83682
+ for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
83683
+ var declaration = declarations_8[_i];
83352
83684
  // If this declaration has too few or too many type parameters, we report an error
83353
- var sourceParameters = ts.getEffectiveTypeParameterDeclarations(declaration);
83685
+ var sourceParameters = getTypeParameterDeclarations(declaration);
83354
83686
  var numTypeParameters = sourceParameters.length;
83355
83687
  if (numTypeParameters < minTypeArgumentCount || numTypeParameters > maxTypeArgumentCount) {
83356
83688
  return false;
@@ -83418,7 +83750,7 @@ var ts;
83418
83750
  checkFunctionOrConstructorSymbol(symbol);
83419
83751
  checkClassForDuplicateDeclarations(node);
83420
83752
  // Only check for reserved static identifiers on non-ambient context.
83421
- var nodeInAmbientContext = !!(node.flags & 8388608 /* Ambient */);
83753
+ var nodeInAmbientContext = !!(node.flags & 16777216 /* Ambient */);
83422
83754
  if (!nodeInAmbientContext) {
83423
83755
  checkClassForStaticPropertyNameConflicts(node);
83424
83756
  }
@@ -83568,7 +83900,7 @@ var ts;
83568
83900
  */
83569
83901
  function checkMemberForOverrideModifier(node, staticType, baseStaticType, baseWithThis, type, typeWithThis, memberHasOverrideModifier, memberHasAbstractModifier, memberIsStatic, memberIsParameterProperty, memberName, errorNode) {
83570
83902
  var isJs = ts.isInJSFile(node);
83571
- var nodeInAmbientContext = !!(node.flags & 8388608 /* Ambient */);
83903
+ var nodeInAmbientContext = !!(node.flags & 16777216 /* Ambient */);
83572
83904
  if (baseWithThis && (memberHasOverrideModifier || compilerOptions.noImplicitOverride)) {
83573
83905
  var memberEscapedName = ts.escapeLeadingUnderscores(memberName);
83574
83906
  var thisType = memberIsStatic ? staticType : typeWithThis;
@@ -83796,7 +84128,7 @@ var ts;
83796
84128
  && !(derived.flags & 33554432 /* Transient */)
83797
84129
  && !(baseDeclarationFlags & 128 /* Abstract */)
83798
84130
  && !(derivedDeclarationFlags & 128 /* Abstract */)
83799
- && !((_b = derived.declarations) === null || _b === void 0 ? void 0 : _b.some(function (d) { return !!(d.flags & 8388608 /* Ambient */); }))) {
84131
+ && !((_b = derived.declarations) === null || _b === void 0 ? void 0 : _b.some(function (d) { return !!(d.flags & 16777216 /* Ambient */); }))) {
83800
84132
  var constructor = findConstructorDeclaration(ts.getClassLikeDeclarationOfSymbol(type.symbol));
83801
84133
  var propName = uninitialized.name;
83802
84134
  if (uninitialized.exclamationToken
@@ -83888,7 +84220,7 @@ var ts;
83888
84220
  return ok;
83889
84221
  }
83890
84222
  function checkPropertyInitialization(node) {
83891
- if (!strictNullChecks || !strictPropertyInitialization || node.flags & 8388608 /* Ambient */) {
84223
+ if (!strictNullChecks || !strictPropertyInitialization || node.flags & 16777216 /* Ambient */) {
83892
84224
  return;
83893
84225
  }
83894
84226
  var constructor = findConstructorDeclaration(node);
@@ -84025,7 +84357,7 @@ var ts;
84025
84357
  }
84026
84358
  // In ambient non-const numeric enum declarations, enum members without initializers are
84027
84359
  // 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 */) {
84360
+ if (member.parent.flags & 16777216 /* Ambient */ && !ts.isEnumConst(member.parent) && getEnumKind(getSymbolOfNode(member.parent)) === 0 /* Numeric */) {
84029
84361
  return undefined;
84030
84362
  }
84031
84363
  // If the member declaration specifies no value, the member is considered a constant enum member.
@@ -84057,7 +84389,7 @@ var ts;
84057
84389
  else if (isConstEnum) {
84058
84390
  error(initializer, ts.Diagnostics.const_enum_member_initializers_can_only_contain_literal_values_and_other_computed_enum_values);
84059
84391
  }
84060
- else if (member.parent.flags & 8388608 /* Ambient */) {
84392
+ else if (member.parent.flags & 16777216 /* Ambient */) {
84061
84393
  error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
84062
84394
  }
84063
84395
  else {
@@ -84225,11 +84557,11 @@ var ts;
84225
84557
  function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
84226
84558
  var declarations = symbol.declarations;
84227
84559
  if (declarations) {
84228
- for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
84229
- var declaration = declarations_8[_i];
84560
+ for (var _i = 0, declarations_9 = declarations; _i < declarations_9.length; _i++) {
84561
+ var declaration = declarations_9[_i];
84230
84562
  if ((declaration.kind === 257 /* ClassDeclaration */ ||
84231
84563
  (declaration.kind === 256 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) &&
84232
- !(declaration.flags & 8388608 /* Ambient */)) {
84564
+ !(declaration.flags & 16777216 /* Ambient */)) {
84233
84565
  return declaration;
84234
84566
  }
84235
84567
  }
@@ -84260,7 +84592,7 @@ var ts;
84260
84592
  function checkModuleDeclarationDiagnostics() {
84261
84593
  // Grammar checking
84262
84594
  var isGlobalAugmentation = ts.isGlobalScopeAugmentation(node);
84263
- var inAmbientContext = node.flags & 8388608 /* Ambient */;
84595
+ var inAmbientContext = node.flags & 16777216 /* Ambient */;
84264
84596
  if (isGlobalAugmentation && !inAmbientContext) {
84265
84597
  error(node.name, ts.Diagnostics.Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context);
84266
84598
  }
@@ -84478,7 +84810,7 @@ var ts;
84478
84810
  }
84479
84811
  if (compilerOptions.isolatedModules
84480
84812
  && !ts.isTypeOnlyImportOrExportDeclaration(node)
84481
- && !(node.flags & 8388608 /* Ambient */)) {
84813
+ && !(node.flags & 16777216 /* Ambient */)) {
84482
84814
  var typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
84483
84815
  var isType = !(target.flags & 111551 /* Value */);
84484
84816
  if (isType || typeOnlyAlias) {
@@ -84524,7 +84856,7 @@ var ts;
84524
84856
  }
84525
84857
  }
84526
84858
  function isDeprecatedAliasedSymbol(symbol) {
84527
- return !!symbol.declarations && ts.every(symbol.declarations, function (d) { return !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); });
84859
+ return !!symbol.declarations && ts.every(symbol.declarations, function (d) { return !!(ts.getCombinedNodeFlags(d) & 268435456 /* Deprecated */); });
84528
84860
  }
84529
84861
  function checkDeprecatedAliasedSymbol(symbol, location) {
84530
84862
  if (!(symbol.flags & 2097152 /* Alias */))
@@ -84653,7 +84985,7 @@ var ts;
84653
84985
  }
84654
84986
  }
84655
84987
  else {
84656
- if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat === undefined && !node.isTypeOnly && !(node.flags & 8388608 /* Ambient */)) {
84988
+ if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat === undefined && !node.isTypeOnly && !(node.flags & 16777216 /* Ambient */)) {
84657
84989
  // Import equals declaration is deprecated in es6 or above
84658
84990
  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
84991
  }
@@ -84679,7 +85011,7 @@ var ts;
84679
85011
  ts.forEach(node.exportClause.elements, checkExportSpecifier);
84680
85012
  var inAmbientExternalModule = node.parent.kind === 262 /* ModuleBlock */ && ts.isAmbientModule(node.parent.parent);
84681
85013
  var inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === 262 /* ModuleBlock */ &&
84682
- !node.moduleSpecifier && node.flags & 8388608 /* Ambient */;
85014
+ !node.moduleSpecifier && node.flags & 16777216 /* Ambient */;
84683
85015
  if (node.parent.kind !== 305 /* SourceFile */ && !inAmbientExternalModule && !inAmbientNamespaceDeclaration) {
84684
85016
  error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
84685
85017
  }
@@ -84844,10 +85176,10 @@ var ts;
84844
85176
  checkExpressionCached(node.expression);
84845
85177
  }
84846
85178
  checkExternalModuleExports(container);
84847
- if ((node.flags & 8388608 /* Ambient */) && !ts.isEntityNameExpression(node.expression)) {
85179
+ if ((node.flags & 16777216 /* Ambient */) && !ts.isEntityNameExpression(node.expression)) {
84848
85180
  grammarErrorOnNode(node.expression, ts.Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context);
84849
85181
  }
84850
- if (node.isExportEquals && !(node.flags & 8388608 /* Ambient */)) {
85182
+ if (node.isExportEquals && !(node.flags & 16777216 /* Ambient */)) {
84851
85183
  if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat !== ts.ModuleKind.CommonJS) {
84852
85184
  // export assignment is not supported in es6 modules
84853
85185
  grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
@@ -85280,7 +85612,7 @@ var ts;
85280
85612
  // This relies on the results of other lazy diagnostics, so must be computed after them
85281
85613
  if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
85282
85614
  checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) {
85283
- if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
85615
+ if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 16777216 /* Ambient */))) {
85284
85616
  diagnostics.add(diag);
85285
85617
  }
85286
85618
  });
@@ -85380,7 +85712,7 @@ var ts;
85380
85712
  }
85381
85713
  // Language service support
85382
85714
  function getSymbolsInScope(location, meaning) {
85383
- if (location.flags & 16777216 /* InWithStatement */) {
85715
+ if (location.flags & 33554432 /* InWithStatement */) {
85384
85716
  // We cannot answer semantic questions within a with block, do not proceed any further
85385
85717
  return [];
85386
85718
  }
@@ -85730,7 +86062,7 @@ var ts;
85730
86062
  }
85731
86063
  var parent = node.parent;
85732
86064
  var grandParent = parent.parent;
85733
- if (node.flags & 16777216 /* InWithStatement */) {
86065
+ if (node.flags & 33554432 /* InWithStatement */) {
85734
86066
  // We cannot answer semantic questions within a with block, do not proceed any further
85735
86067
  return undefined;
85736
86068
  }
@@ -85872,7 +86204,7 @@ var ts;
85872
86204
  if (ts.isSourceFile(node) && !ts.isExternalModule(node)) {
85873
86205
  return errorType;
85874
86206
  }
85875
- if (node.flags & 16777216 /* InWithStatement */) {
86207
+ if (node.flags & 33554432 /* InWithStatement */) {
85876
86208
  // We cannot answer semantic questions within a with block, do not proceed any further
85877
86209
  return errorType;
85878
86210
  }
@@ -86925,7 +87257,7 @@ var ts;
86925
87257
  function checkExternalEmitHelpers(location, helpers) {
86926
87258
  if ((requestedExternalEmitHelpers & helpers) !== helpers && compilerOptions.importHelpers) {
86927
87259
  var sourceFile = ts.getSourceFileOfNode(location);
86928
- if (ts.isEffectiveExternalModule(sourceFile, compilerOptions) && !(location.flags & 8388608 /* Ambient */)) {
87260
+ if (ts.isEffectiveExternalModule(sourceFile, compilerOptions) && !(location.flags & 16777216 /* Ambient */)) {
86929
87261
  var helpersModule = resolveHelpersModule(sourceFile, location);
86930
87262
  if (helpersModule !== unknownSymbol) {
86931
87263
  var uncheckedHelpers = helpers & ~requestedExternalEmitHelpers;
@@ -87178,7 +87510,7 @@ var ts;
87178
87510
  else if (node.kind === 164 /* Parameter */) {
87179
87511
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
87180
87512
  }
87181
- else if ((node.parent.flags & 8388608 /* Ambient */) && node.parent.kind === 262 /* ModuleBlock */) {
87513
+ else if ((node.parent.flags & 16777216 /* Ambient */) && node.parent.kind === 262 /* ModuleBlock */) {
87182
87514
  return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
87183
87515
  }
87184
87516
  else if (ts.isPrivateIdentifierClassElementDeclaration(node)) {
@@ -87224,7 +87556,7 @@ var ts;
87224
87556
  if (flags & 256 /* Async */) {
87225
87557
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async");
87226
87558
  }
87227
- else if (flags & 2 /* Ambient */ || node.parent.flags & 8388608 /* Ambient */) {
87559
+ else if (flags & 2 /* Ambient */ || node.parent.flags & 16777216 /* Ambient */) {
87228
87560
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
87229
87561
  }
87230
87562
  else if (node.kind === 164 /* Parameter */) {
@@ -87370,7 +87702,7 @@ var ts;
87370
87702
  if (i !== (parameterCount - 1)) {
87371
87703
  return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
87372
87704
  }
87373
- if (!(parameter.flags & 8388608 /* Ambient */)) { // Allow `...foo,` in ambient declarations; see GH#23070
87705
+ if (!(parameter.flags & 16777216 /* Ambient */)) { // Allow `...foo,` in ambient declarations; see GH#23070
87374
87706
  checkGrammarForDisallowedTrailingComma(parameters, ts.Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma);
87375
87707
  }
87376
87708
  if (parameter.questionToken) {
@@ -87581,7 +87913,7 @@ var ts;
87581
87913
  ts.Debug.assert(node.kind === 256 /* FunctionDeclaration */ ||
87582
87914
  node.kind === 213 /* FunctionExpression */ ||
87583
87915
  node.kind === 169 /* MethodDeclaration */);
87584
- if (node.flags & 8388608 /* Ambient */) {
87916
+ if (node.flags & 16777216 /* Ambient */) {
87585
87917
  return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
87586
87918
  }
87587
87919
  if (!node.body) {
@@ -87819,7 +88151,7 @@ var ts;
87819
88151
  return false;
87820
88152
  }
87821
88153
  function checkGrammarAccessor(accessor) {
87822
- if (!(accessor.flags & 8388608 /* Ambient */) && (accessor.parent.kind !== 182 /* TypeLiteral */) && (accessor.parent.kind !== 258 /* InterfaceDeclaration */)) {
88154
+ if (!(accessor.flags & 16777216 /* Ambient */) && (accessor.parent.kind !== 182 /* TypeLiteral */) && (accessor.parent.kind !== 258 /* InterfaceDeclaration */)) {
87823
88155
  if (languageVersion < 1 /* ES5 */) {
87824
88156
  return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
87825
88157
  }
@@ -87959,7 +88291,7 @@ var ts;
87959
88291
  // However, property declarations disallow computed names in general,
87960
88292
  // and accessors are not allowed in ambient contexts in general,
87961
88293
  // so this error only really matters for methods.
87962
- if (node.flags & 8388608 /* Ambient */) {
88294
+ if (node.flags & 16777216 /* Ambient */) {
87963
88295
  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
88296
  }
87965
88297
  else if (node.kind === 169 /* MethodDeclaration */ && !node.body) {
@@ -88075,7 +88407,7 @@ var ts;
88075
88407
  }
88076
88408
  function checkGrammarVariableDeclaration(node) {
88077
88409
  if (node.parent.parent.kind !== 243 /* ForInStatement */ && node.parent.parent.kind !== 244 /* ForOfStatement */) {
88078
- if (node.flags & 8388608 /* Ambient */) {
88410
+ if (node.flags & 16777216 /* Ambient */) {
88079
88411
  checkAmbientInitializer(node);
88080
88412
  }
88081
88413
  else if (!node.initializer) {
@@ -88087,7 +88419,7 @@ var ts;
88087
88419
  }
88088
88420
  }
88089
88421
  }
88090
- if (node.exclamationToken && (node.parent.parent.kind !== 237 /* VariableStatement */ || !node.type || node.initializer || node.flags & 8388608 /* Ambient */)) {
88422
+ if (node.exclamationToken && (node.parent.parent.kind !== 237 /* VariableStatement */ || !node.type || node.initializer || node.flags & 16777216 /* Ambient */)) {
88091
88423
  var message = node.initializer
88092
88424
  ? ts.Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions
88093
88425
  : !node.type
@@ -88096,7 +88428,7 @@ var ts;
88096
88428
  return grammarErrorOnNode(node.exclamationToken, message);
88097
88429
  }
88098
88430
  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 */)) {
88431
+ !(node.parent.parent.flags & 16777216 /* Ambient */) && ts.hasSyntacticModifier(node.parent.parent, 1 /* Export */)) {
88100
88432
  checkESModuleMarker(node.name);
88101
88433
  }
88102
88434
  var checkLetConstNames = (ts.isLet(node) || ts.isVarConst(node));
@@ -88273,11 +88605,11 @@ var ts;
88273
88605
  return grammarErrorOnNode(node.initializer, ts.Diagnostics.A_type_literal_property_cannot_have_an_initializer);
88274
88606
  }
88275
88607
  }
88276
- if (node.flags & 8388608 /* Ambient */) {
88608
+ if (node.flags & 16777216 /* Ambient */) {
88277
88609
  checkAmbientInitializer(node);
88278
88610
  }
88279
88611
  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))) {
88612
+ node.flags & 16777216 /* Ambient */ || ts.isStatic(node) || ts.hasAbstractModifier(node))) {
88281
88613
  var message = node.initializer
88282
88614
  ? ts.Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions
88283
88615
  : !node.type
@@ -88323,10 +88655,10 @@ var ts;
88323
88655
  return false;
88324
88656
  }
88325
88657
  function checkGrammarSourceFile(node) {
88326
- return !!(node.flags & 8388608 /* Ambient */) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
88658
+ return !!(node.flags & 16777216 /* Ambient */) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
88327
88659
  }
88328
88660
  function checkGrammarStatementInAmbientContext(node) {
88329
- if (node.flags & 8388608 /* Ambient */) {
88661
+ if (node.flags & 16777216 /* Ambient */) {
88330
88662
  // Find containing block which is either Block, ModuleBlock, SourceFile
88331
88663
  var links = getNodeLinks(node);
88332
88664
  if (!links.hasReportedStatementInAmbientContext && (ts.isFunctionLike(node.parent) || ts.isAccessor(node.parent))) {
@@ -92444,7 +92776,7 @@ var ts;
92444
92776
  return !ts.nodeIsMissing(node.body);
92445
92777
  }
92446
92778
  function visitPropertyDeclaration(node) {
92447
- if (node.flags & 8388608 /* Ambient */ || ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
92779
+ if (node.flags & 16777216 /* Ambient */ || ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
92448
92780
  return undefined;
92449
92781
  }
92450
92782
  var updated = factory.updatePropertyDeclaration(node,
@@ -99334,8 +99666,8 @@ var ts;
99334
99666
  // declarations may not be sorted by position.
99335
99667
  // pos should be the minimum* position over all nodes (that's not -1), end should be the maximum end over all nodes.
99336
99668
  var pos = -1, end = -1;
99337
- for (var _i = 0, declarations_9 = declarations; _i < declarations_9.length; _i++) {
99338
- var node = declarations_9[_i];
99669
+ for (var _i = 0, declarations_10 = declarations; _i < declarations_10.length; _i++) {
99670
+ var node = declarations_10[_i];
99339
99671
  pos = pos === -1 ? node.pos : node.pos === -1 ? pos : Math.min(pos, node.pos);
99340
99672
  end = Math.max(end, node.end);
99341
99673
  }
@@ -108378,7 +108710,7 @@ var ts;
108378
108710
  needsScopeFixMarker = false;
108379
108711
  var statements = ts.visitNodes(inner.statements, visitDeclarationStatements);
108380
108712
  var lateStatements = transformAndReplaceLatePaintedStatements(statements);
108381
- if (input.flags & 8388608 /* Ambient */) {
108713
+ if (input.flags & 16777216 /* Ambient */) {
108382
108714
  needsScopeFixMarker = false; // If it was `declare`'d everything is implicitly exported already, ignore late printed "privates"
108383
108715
  }
108384
108716
  // With the final list of statements, there are 3 possibilities:
@@ -110026,6 +110358,9 @@ var ts;
110026
110358
  var currentParenthesizerRule;
110027
110359
  var _c = ts.performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment"), enterComment = _c.enter, exitComment = _c.exit;
110028
110360
  var parenthesizer = ts.factory.parenthesizer;
110361
+ var typeArgumentParenthesizerRuleSelector = {
110362
+ select: function (index) { return index === 0 ? parenthesizer.parenthesizeLeadingTypeArgument : undefined; }
110363
+ };
110029
110364
  var emitBinaryExpression = createEmitBinaryExpression();
110030
110365
  reset();
110031
110366
  return {
@@ -111238,7 +111573,7 @@ var ts;
111238
111573
  writePunctuation("}");
111239
111574
  }
111240
111575
  function emitArrayType(node) {
111241
- emit(node.elementType, parenthesizer.parenthesizeElementTypeOfArrayType);
111576
+ emit(node.elementType, parenthesizer.parenthesizeNonArrayTypeOfPostfixType);
111242
111577
  writePunctuation("[");
111243
111578
  writePunctuation("]");
111244
111579
  }
@@ -111249,7 +111584,7 @@ var ts;
111249
111584
  function emitTupleType(node) {
111250
111585
  emitTokenWithComment(22 /* OpenBracketToken */, node.pos, writePunctuation, node);
111251
111586
  var flags = ts.getEmitFlags(node) & 1 /* SingleLine */ ? 528 /* SingleLineTupleTypeElements */ : 657 /* MultiLineTupleTypeElements */;
111252
- emitList(node, node.elements, flags | 524288 /* NoSpaceIfEmpty */);
111587
+ emitList(node, node.elements, flags | 524288 /* NoSpaceIfEmpty */, parenthesizer.parenthesizeElementTypeOfTupleType);
111253
111588
  emitTokenWithComment(23 /* CloseBracketToken */, node.elements.end, writePunctuation, node);
111254
111589
  }
111255
111590
  function emitNamedTupleMember(node) {
@@ -111261,21 +111596,21 @@ var ts;
111261
111596
  emit(node.type);
111262
111597
  }
111263
111598
  function emitOptionalType(node) {
111264
- emit(node.type, parenthesizer.parenthesizeElementTypeOfArrayType);
111599
+ emit(node.type, parenthesizer.parenthesizeTypeOfOptionalType);
111265
111600
  writePunctuation("?");
111266
111601
  }
111267
111602
  function emitUnionType(node) {
111268
- emitList(node, node.types, 516 /* UnionTypeConstituents */, parenthesizer.parenthesizeMemberOfElementType);
111603
+ emitList(node, node.types, 516 /* UnionTypeConstituents */, parenthesizer.parenthesizeConstituentTypeOfUnionType);
111269
111604
  }
111270
111605
  function emitIntersectionType(node) {
111271
- emitList(node, node.types, 520 /* IntersectionTypeConstituents */, parenthesizer.parenthesizeMemberOfElementType);
111606
+ emitList(node, node.types, 520 /* IntersectionTypeConstituents */, parenthesizer.parenthesizeConstituentTypeOfIntersectionType);
111272
111607
  }
111273
111608
  function emitConditionalType(node) {
111274
- emit(node.checkType, parenthesizer.parenthesizeMemberOfConditionalType);
111609
+ emit(node.checkType, parenthesizer.parenthesizeCheckTypeOfConditionalType);
111275
111610
  writeSpace();
111276
111611
  writeKeyword("extends");
111277
111612
  writeSpace();
111278
- emit(node.extendsType, parenthesizer.parenthesizeMemberOfConditionalType);
111613
+ emit(node.extendsType, parenthesizer.parenthesizeExtendsTypeOfConditionalType);
111279
111614
  writeSpace();
111280
111615
  writePunctuation("?");
111281
111616
  writeSpace();
@@ -111301,10 +111636,13 @@ var ts;
111301
111636
  function emitTypeOperator(node) {
111302
111637
  writeTokenText(node.operator, writeKeyword);
111303
111638
  writeSpace();
111304
- emit(node.type, parenthesizer.parenthesizeMemberOfElementType);
111639
+ var parenthesizerRule = node.operator === 145 /* ReadonlyKeyword */ ?
111640
+ parenthesizer.parenthesizeOperandOfReadonlyTypeOperator :
111641
+ parenthesizer.parenthesizeOperandOfTypeOperator;
111642
+ emit(node.type, parenthesizerRule);
111305
111643
  }
111306
111644
  function emitIndexedAccessType(node) {
111307
- emit(node.objectType, parenthesizer.parenthesizeMemberOfElementType);
111645
+ emit(node.objectType, parenthesizer.parenthesizeNonArrayTypeOfPostfixType);
111308
111646
  writePunctuation("[");
111309
111647
  emit(node.indexType);
111310
111648
  writePunctuation("]");
@@ -113038,7 +113376,7 @@ var ts;
113038
113376
  emitList(parentNode, decorators, 2146305 /* Decorators */);
113039
113377
  }
113040
113378
  function emitTypeArguments(parentNode, typeArguments) {
113041
- emitList(parentNode, typeArguments, 53776 /* TypeArguments */, parenthesizer.parenthesizeMemberOfElementType);
113379
+ emitList(parentNode, typeArguments, 53776 /* TypeArguments */, typeArgumentParenthesizerRuleSelector);
113042
113380
  }
113043
113381
  function emitTypeParameters(parentNode, typeParameters) {
113044
113382
  if (ts.isFunctionLike(parentNode) && parentNode.typeArguments) { // Quick info uses type arguments in place of type parameters on instantiated signatures
@@ -113157,6 +113495,7 @@ var ts;
113157
113495
  if (format & 128 /* Indented */) {
113158
113496
  increaseIndent();
113159
113497
  }
113498
+ var emitListItem = getEmitListItem(emit, parenthesizerRule);
113160
113499
  // Emit each child.
113161
113500
  var previousSibling = void 0;
113162
113501
  var previousSourceFileTextKind = void 0;
@@ -113207,12 +113546,7 @@ var ts;
113207
113546
  shouldEmitInterveningComments = mayEmitInterveningComments;
113208
113547
  }
113209
113548
  nextListElementPos = child.pos;
113210
- if (emit.length === 1) {
113211
- emit(child);
113212
- }
113213
- else {
113214
- emit(child, parenthesizerRule);
113215
- }
113549
+ emitListItem(child, emit, parenthesizerRule, i);
113216
113550
  if (shouldDecreaseIndentAfterEmit) {
113217
113551
  decreaseIndent();
113218
113552
  shouldDecreaseIndentAfterEmit = false;
@@ -114453,6 +114787,20 @@ var ts;
114453
114787
  TempFlags[TempFlags["CountMask"] = 268435455] = "CountMask";
114454
114788
  TempFlags[TempFlags["_i"] = 268435456] = "_i";
114455
114789
  })(TempFlags || (TempFlags = {}));
114790
+ function emitListItemNoParenthesizer(node, emit, _parenthesizerRule, _index) {
114791
+ emit(node);
114792
+ }
114793
+ function emitListItemWithParenthesizerRuleSelector(node, emit, parenthesizerRuleSelector, index) {
114794
+ emit(node, parenthesizerRuleSelector.select(index));
114795
+ }
114796
+ function emitListItemWithParenthesizerRule(node, emit, parenthesizerRule, _index) {
114797
+ emit(node, parenthesizerRule);
114798
+ }
114799
+ function getEmitListItem(emit, parenthesizerRule) {
114800
+ return emit.length === 1 ? emitListItemNoParenthesizer :
114801
+ typeof parenthesizerRule === "object" ? emitListItemWithParenthesizerRuleSelector :
114802
+ emitListItemWithParenthesizerRule;
114803
+ }
114456
114804
  })(ts || (ts = {}));
114457
114805
  /* @internal */
114458
114806
  var ts;
@@ -116519,7 +116867,7 @@ var ts;
116519
116867
  // moduleAugmentations has changed
116520
116868
  structureIsReused = 1 /* SafeModules */;
116521
116869
  }
116522
- if ((oldSourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */)) {
116870
+ if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
116523
116871
  // dynamicImport has changed
116524
116872
  structureIsReused = 1 /* SafeModules */;
116525
116873
  }
@@ -116683,6 +117031,9 @@ var ts;
116683
117031
  return !!sourceFilesFoundSearchingNodeModules.get(file.path);
116684
117032
  }
116685
117033
  function isSourceFileDefaultLibrary(file) {
117034
+ if (!file.isDeclarationFile) {
117035
+ return false;
117036
+ }
116686
117037
  if (file.hasNoDefaultLib) {
116687
117038
  return true;
116688
117039
  }
@@ -117194,7 +117545,7 @@ var ts;
117194
117545
  var node = _a[_i];
117195
117546
  collectModuleReferences(node, /*inAmbientModule*/ false);
117196
117547
  }
117197
- if ((file.flags & 1048576 /* PossiblyContainsDynamicImport */) || isJavaScriptFile) {
117548
+ if ((file.flags & 2097152 /* PossiblyContainsDynamicImport */) || isJavaScriptFile) {
117198
117549
  collectDynamicImportOrRequireCalls(file);
117199
117550
  }
117200
117551
  file.imports = imports || ts.emptyArray;
@@ -117792,7 +118143,7 @@ var ts;
117792
118143
  && index < file.imports.length
117793
118144
  && !elideImport
117794
118145
  && !(isJsFile && !ts.getAllowJSCompilerOption(optionsForFile))
117795
- && (ts.isInJSFile(file.imports[index]) || !(file.imports[index].flags & 4194304 /* JSDoc */));
118146
+ && (ts.isInJSFile(file.imports[index]) || !(file.imports[index].flags & 8388608 /* JSDoc */));
117796
118147
  if (elideImport) {
117797
118148
  modulesWithElidedImports.set(file.path, true);
117798
118149
  }
@@ -117873,21 +118224,6 @@ var ts;
117873
118224
  return resolvedRef;
117874
118225
  }
117875
118226
  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
118227
  if (options.strictPropertyInitialization && !ts.getStrictOptionValue(options, "strictNullChecks")) {
117892
118228
  createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks");
117893
118229
  }
@@ -127091,7 +127427,7 @@ var ts;
127091
127427
  result.push("export" /* exportedModifier */);
127092
127428
  if (flags & 8192 /* Deprecated */)
127093
127429
  result.push("deprecated" /* deprecatedModifier */);
127094
- if (node.flags & 8388608 /* Ambient */)
127430
+ if (node.flags & 16777216 /* Ambient */)
127095
127431
  result.push("declare" /* ambientModifier */);
127096
127432
  if (node.kind === 271 /* ExportAssignment */)
127097
127433
  result.push("export" /* exportedModifier */);
@@ -133407,7 +133743,7 @@ var ts;
133407
133743
  var instantiatedType = tryGetObjectLiteralContextualType(objectLikeContainer, typeChecker);
133408
133744
  // Check completions for Object property value shorthand
133409
133745
  if (instantiatedType === undefined) {
133410
- if (objectLikeContainer.flags & 16777216 /* InWithStatement */) {
133746
+ if (objectLikeContainer.flags & 33554432 /* InWithStatement */) {
133411
133747
  return 2 /* Fail */;
133412
133748
  }
133413
133749
  isNonContextualObjectLiteral = true;
@@ -136070,17 +136406,25 @@ var ts;
136070
136406
  var options = { use: 1 /* References */ };
136071
136407
  var referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options);
136072
136408
  var checker = program.getTypeChecker();
136073
- var symbol = checker.getSymbolAtLocation(ts.getAdjustedReferenceLocation(Core.getAdjustedNode(node, options)));
136409
+ // Unless the starting node is a declaration (vs e.g. JSDoc), don't attempt to compute isDefinition
136410
+ var adjustedNode = Core.getAdjustedNode(node, options);
136411
+ var symbol = isDefinitionForReference(adjustedNode) ? checker.getSymbolAtLocation(adjustedNode) : undefined;
136074
136412
  return !referencedSymbols || !referencedSymbols.length ? undefined : ts.mapDefined(referencedSymbols, function (_a) {
136075
136413
  var definition = _a.definition, references = _a.references;
136076
136414
  // Only include referenced symbols that have a valid definition.
136077
136415
  return definition && {
136078
136416
  definition: checker.runWithCancellationToken(cancellationToken, function (checker) { return definitionToReferencedSymbolDefinitionInfo(definition, checker, node); }),
136079
- references: references.map(function (r) { return toReferenceEntry(r, symbol); })
136417
+ references: references.map(function (r) { return toReferencedSymbolEntry(r, symbol); })
136080
136418
  };
136081
136419
  });
136082
136420
  }
136083
136421
  FindAllReferences.findReferencedSymbols = findReferencedSymbols;
136422
+ function isDefinitionForReference(node) {
136423
+ return node.kind === 88 /* DefaultKeyword */
136424
+ || !!ts.getDeclarationFromName(node)
136425
+ || ts.isLiteralComputedPropertyDeclarationName(node)
136426
+ || (node.kind === 134 /* ConstructorKeyword */ && ts.isConstructorDeclaration(node.parent));
136427
+ }
136084
136428
  function getImplementationsAtPosition(program, cancellationToken, sourceFiles, sourceFile, position) {
136085
136429
  var node = ts.getTouchingPropertyName(sourceFile, position);
136086
136430
  var referenceEntries;
@@ -136209,13 +136553,19 @@ var ts;
136209
136553
  return __assign(__assign({}, entryToDocumentSpan(entry)), (providePrefixAndSuffixText && getPrefixAndSuffixText(entry, originalNode, checker)));
136210
136554
  }
136211
136555
  FindAllReferences.toRenameLocation = toRenameLocation;
136212
- function toReferenceEntry(entry, symbol) {
136556
+ function toReferencedSymbolEntry(entry, symbol) {
136557
+ var referenceEntry = toReferenceEntry(entry);
136558
+ if (!symbol)
136559
+ return referenceEntry;
136560
+ return __assign(__assign({}, referenceEntry), { isDefinition: entry.kind !== 0 /* Span */ && isDeclarationOfSymbol(entry.node, symbol) });
136561
+ }
136562
+ function toReferenceEntry(entry) {
136213
136563
  var documentSpan = entryToDocumentSpan(entry);
136214
136564
  if (entry.kind === 0 /* Span */) {
136215
- return __assign(__assign({}, documentSpan), { isWriteAccess: false, isDefinition: false });
136565
+ return __assign(__assign({}, documentSpan), { isWriteAccess: false });
136216
136566
  }
136217
136567
  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 });
136568
+ return __assign(__assign({}, documentSpan), { isWriteAccess: isWriteAccessForReference(node), isInString: kind === 2 /* StringLiteral */ ? true : undefined });
136219
136569
  }
136220
136570
  FindAllReferences.toReferenceEntry = toReferenceEntry;
136221
136571
  function entryToDocumentSpan(entry) {
@@ -136358,7 +136708,7 @@ var ts;
136358
136708
  */
136359
136709
  function declarationIsWriteAccess(decl) {
136360
136710
  // Consider anything in an ambient declaration to be a write access since it may be coming from JS.
136361
- if (!!(decl.flags & 8388608 /* Ambient */))
136711
+ if (!!(decl.flags & 16777216 /* Ambient */))
136362
136712
  return true;
136363
136713
  switch (decl.kind) {
136364
136714
  case 221 /* BinaryExpression */:
@@ -136923,15 +137273,21 @@ var ts;
136923
137273
  }
136924
137274
  function eachExportReference(sourceFiles, checker, cancellationToken, exportSymbol, exportingModuleSymbol, exportName, isDefaultExport, cb) {
136925
137275
  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;
137276
+ var _a = importTracker(exportSymbol, { exportKind: isDefaultExport ? 1 /* Default */ : 0 /* Named */, exportingModuleSymbol: exportingModuleSymbol }, /*isForRename*/ false), importSearches = _a.importSearches, indirectUsers = _a.indirectUsers, singleReferences = _a.singleReferences;
136927
137277
  for (var _i = 0, importSearches_2 = importSearches; _i < importSearches_2.length; _i++) {
136928
137278
  var importLocation = importSearches_2[_i][0];
136929
137279
  cb(importLocation);
136930
137280
  }
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];
137281
+ for (var _b = 0, singleReferences_2 = singleReferences; _b < singleReferences_2.length; _b++) {
137282
+ var singleReference = singleReferences_2[_b];
137283
+ if (ts.isIdentifier(singleReference) && ts.isImportTypeNode(singleReference.parent)) {
137284
+ cb(singleReference);
137285
+ }
137286
+ }
137287
+ for (var _c = 0, indirectUsers_2 = indirectUsers; _c < indirectUsers_2.length; _c++) {
137288
+ var indirectUser = indirectUsers_2[_c];
137289
+ for (var _d = 0, _e = getPossibleSymbolReferenceNodes(indirectUser, isDefaultExport ? "default" : exportName); _d < _e.length; _d++) {
137290
+ var node = _e[_d];
136935
137291
  // Import specifiers should be handled by importSearches
136936
137292
  var symbol = checker.getSymbolAtLocation(node);
136937
137293
  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 +138289,7 @@ var ts;
137933
138289
  }
137934
138290
  Core.getIntersectingMeaningFromDeclarations = getIntersectingMeaningFromDeclarations;
137935
138291
  function isImplementation(node) {
137936
- return !!(node.flags & 8388608 /* Ambient */) ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) :
138292
+ return !!(node.flags & 16777216 /* Ambient */) ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) :
137937
138293
  (ts.isVariableLike(node) ? ts.hasInitializer(node) :
137938
138294
  ts.isFunctionLikeDeclaration(node) ? !!node.body :
137939
138295
  ts.isClassLike(node) || ts.isModuleOrEnumDeclaration(node));
@@ -138311,7 +138667,7 @@ var ts;
138311
138667
  function collect(node) {
138312
138668
  if (!node)
138313
138669
  return;
138314
- if (node.flags & 8388608 /* Ambient */) {
138670
+ if (node.flags & 16777216 /* Ambient */) {
138315
138671
  // do not descend into ambient nodes.
138316
138672
  return;
138317
138673
  }
@@ -138470,7 +138826,7 @@ var ts;
138470
138826
  }
138471
138827
  /** Gets the call sites that call out of the provided call hierarchy declaration. */
138472
138828
  function getOutgoingCalls(program, declaration) {
138473
- if (declaration.flags & 8388608 /* Ambient */ || ts.isMethodSignature(declaration)) {
138829
+ if (declaration.flags & 16777216 /* Ambient */ || ts.isMethodSignature(declaration)) {
138474
138830
  return [];
138475
138831
  }
138476
138832
  return ts.group(collectCallSites(program, declaration), getCallSiteGroupKey, function (entries) { return convertCallSiteGroupToOutgoingCall(program, entries); });
@@ -140604,8 +140960,8 @@ var ts;
140604
140960
  var changeTracker = ts.textChanges.ChangeTracker.fromContext({ host: host, formatContext: formatContext, preferences: preferences });
140605
140961
  var coalesceAndOrganizeImports = function (importGroup) { return ts.stableSort(coalesceImports(removeUnusedImports(importGroup, sourceFile, program, skipDestructiveCodeActions)), function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); }); };
140606
140962
  // All of the old ImportDeclarations in the file, in syntactic order.
140607
- var topLevelImportDecls = sourceFile.statements.filter(ts.isImportDeclaration);
140608
- organizeImportsWorker(topLevelImportDecls, coalesceAndOrganizeImports);
140963
+ var topLevelImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, sourceFile.statements.filter(ts.isImportDeclaration));
140964
+ topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
140609
140965
  // All of the old ExportDeclarations in the file, in syntactic order.
140610
140966
  var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
140611
140967
  organizeImportsWorker(topLevelExportDecls, coalesceExports);
@@ -140613,8 +140969,8 @@ var ts;
140613
140969
  var ambientModule = _a[_i];
140614
140970
  if (!ambientModule.body)
140615
140971
  continue;
140616
- var ambientModuleImportDecls = ambientModule.body.statements.filter(ts.isImportDeclaration);
140617
- organizeImportsWorker(ambientModuleImportDecls, coalesceAndOrganizeImports);
140972
+ var ambientModuleImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, ambientModule.body.statements.filter(ts.isImportDeclaration));
140973
+ ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
140618
140974
  var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
140619
140975
  organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
140620
140976
  }
@@ -140660,6 +141016,40 @@ var ts;
140660
141016
  }
140661
141017
  }
140662
141018
  OrganizeImports.organizeImports = organizeImports;
141019
+ function groupImportsByNewlineContiguous(sourceFile, importDecls) {
141020
+ var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, sourceFile.languageVariant);
141021
+ var groupImports = [];
141022
+ var groupIndex = 0;
141023
+ for (var _i = 0, importDecls_1 = importDecls; _i < importDecls_1.length; _i++) {
141024
+ var topLevelImportDecl = importDecls_1[_i];
141025
+ if (isNewGroup(sourceFile, topLevelImportDecl, scanner)) {
141026
+ groupIndex++;
141027
+ }
141028
+ if (!groupImports[groupIndex]) {
141029
+ groupImports[groupIndex] = [];
141030
+ }
141031
+ groupImports[groupIndex].push(topLevelImportDecl);
141032
+ }
141033
+ return groupImports;
141034
+ }
141035
+ // a new group is created if an import includes at least two new line
141036
+ // new line from multi-line comment doesn't count
141037
+ function isNewGroup(sourceFile, topLevelImportDecl, scanner) {
141038
+ var startPos = topLevelImportDecl.getFullStart();
141039
+ var endPos = topLevelImportDecl.getStart();
141040
+ scanner.setText(sourceFile.text, startPos, endPos - startPos);
141041
+ var numberOfNewLines = 0;
141042
+ while (scanner.getTokenPos() < endPos) {
141043
+ var tokenKind = scanner.scan();
141044
+ if (tokenKind === 4 /* NewLineTrivia */) {
141045
+ numberOfNewLines++;
141046
+ if (numberOfNewLines >= 2) {
141047
+ return true;
141048
+ }
141049
+ }
141050
+ }
141051
+ return false;
141052
+ }
140663
141053
  function removeUnusedImports(oldImports, sourceFile, program, skipDestructiveCodeActions) {
140664
141054
  // As a precaution, consider unused import detection to be destructive (GH #43051)
140665
141055
  if (skipDestructiveCodeActions) {
@@ -142895,10 +143285,13 @@ var ts;
142895
143285
  var contextualType = info.contextualType, argumentIndex = info.argumentIndex, argumentCount = info.argumentCount, argumentsSpan = info.argumentsSpan;
142896
143286
  // for optional function condition.
142897
143287
  var nonNullableContextualType = contextualType.getNonNullableType();
142898
- var signatures = nonNullableContextualType.getCallSignatures();
142899
- if (signatures.length !== 1)
143288
+ var symbol = nonNullableContextualType.symbol;
143289
+ if (symbol === undefined)
143290
+ return undefined;
143291
+ var signature = ts.lastOrUndefined(nonNullableContextualType.getCallSignatures());
143292
+ if (signature === undefined)
142900
143293
  return undefined;
142901
- var invocation = { kind: 2 /* Contextual */, signature: ts.first(signatures), node: startingToken, symbol: chooseBetterSymbol(nonNullableContextualType.symbol) };
143294
+ var invocation = { kind: 2 /* Contextual */, signature: signature, node: startingToken, symbol: chooseBetterSymbol(symbol) };
142902
143295
  return { isTypeParameterList: false, invocation: invocation, argumentsSpan: argumentsSpan, argumentIndex: argumentIndex, argumentCount: argumentCount };
142903
143296
  }
142904
143297
  function getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker) {
@@ -147068,9 +147461,9 @@ var ts;
147068
147461
  // for block indentation, we should look for a line which contains something that's not
147069
147462
  // whitespace.
147070
147463
  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)
147464
+ // For object literals, we want indentation to work just like with blocks.
147465
+ // If the `{` starts in any position (even in the middle of a line), then
147466
+ // the following indentation should treat `{` as the start of that line (including leading whitespace).
147074
147467
  // ```
147075
147468
  // const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
147076
147469
  // ->
@@ -147088,7 +147481,8 @@ var ts;
147088
147481
  // y: undefined,
147089
147482
  // }
147090
147483
  // ```
147091
- if (options.indentStyle === ts.IndentStyle.Block || currentToken.kind === 18 /* OpenBraceToken */) {
147484
+ var isObjectLiteral = currentToken.kind === 18 /* OpenBraceToken */ && currentToken.parent.kind === 205 /* ObjectLiteralExpression */;
147485
+ if (options.indentStyle === ts.IndentStyle.Block || isObjectLiteral) {
147092
147486
  return getBlockIndent(sourceFile, position, options);
147093
147487
  }
147094
147488
  if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 221 /* BinaryExpression */) {
@@ -147101,7 +147495,9 @@ var ts;
147101
147495
  var containerList = getListByPosition(position, precedingToken.parent, sourceFile);
147102
147496
  // use list position if the preceding token is before any list items
147103
147497
  if (containerList && !ts.rangeContainsRange(containerList, precedingToken)) {
147104
- return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize; // TODO: GH#18217
147498
+ var useTheSameBaseIndentation = [213 /* FunctionExpression */, 214 /* ArrowFunction */].indexOf(currentToken.parent.kind) !== -1;
147499
+ var indentSize = useTheSameBaseIndentation ? 0 : options.indentSize;
147500
+ return getActualIndentationForListStartLine(containerList, sourceFile, options) + indentSize; // TODO: GH#18217
147105
147501
  }
147106
147502
  return getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options);
147107
147503
  }
@@ -148614,8 +149010,11 @@ var ts;
148614
149010
  function isTrivia(s) {
148615
149011
  return ts.skipTrivia(s, 0) === s.length;
148616
149012
  }
149013
+ // A transformation context that won't perform parenthesization, as some parenthesization rules
149014
+ // are more aggressive than is strictly necessary.
149015
+ var textChangesTransformationContext = __assign(__assign({}, ts.nullTransformationContext), { factory: ts.createNodeFactory(ts.nullTransformationContext.factory.flags | 1 /* NoParenthesizerRules */, ts.nullTransformationContext.factory.baseFactory) });
148617
149016
  function assignPositionsToNode(node) {
148618
- var visited = ts.visitEachChild(node, assignPositionsToNode, ts.nullTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
149017
+ var visited = ts.visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
148619
149018
  // create proxy node for non synthesized nodes
148620
149019
  var newNode = ts.nodeIsSynthesized(visited) ? visited : Object.create(visited);
148621
149020
  ts.setTextRangePosEnd(newNode, getPos(node), getEnd(node));
@@ -153667,7 +154066,7 @@ var ts;
153667
154066
  var param = signature.parameters[argIndex].valueDeclaration;
153668
154067
  if (!(param && ts.isParameter(param) && ts.isIdentifier(param.name)))
153669
154068
  return undefined;
153670
- var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getTypeAtLocation(param), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
154069
+ var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getParameterType(signature, argIndex), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
153671
154070
  if (!ts.length(properties))
153672
154071
  return undefined;
153673
154072
  return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, parentDeclaration: parent };
@@ -156580,7 +156979,7 @@ var ts;
156580
156979
  var modifiers = visibilityModifier ? ts.factory.createNodeArray([visibilityModifier]) : undefined;
156581
156980
  var type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
156582
156981
  var optional = !!(symbol.flags & 16777216 /* Optional */);
156583
- var ambient = !!(enclosingDeclaration.flags & 8388608 /* Ambient */) || isAmbient;
156982
+ var ambient = !!(enclosingDeclaration.flags & 16777216 /* Ambient */) || isAmbient;
156584
156983
  var quotePreference = ts.getQuotePreference(sourceFile, preferences);
156585
156984
  switch (declaration.kind) {
156586
156985
  case 166 /* PropertySignature */:
@@ -156675,7 +157074,11 @@ var ts;
156675
157074
  var program = context.program;
156676
157075
  var checker = program.getTypeChecker();
156677
157076
  var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156678
- var flags = 1 /* NoTruncation */ | 1073741824 /* NoUndefinedOptionalParameterType */ | 256 /* SuppressAnyReturnType */ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0);
157077
+ var flags = 1 /* NoTruncation */
157078
+ | 1073741824 /* NoUndefinedOptionalParameterType */
157079
+ | 256 /* SuppressAnyReturnType */
157080
+ | 524288 /* AllowEmptyTuple */
157081
+ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */);
156679
157082
  var signatureDeclaration = checker.signatureToSignatureDeclaration(signature, kind, enclosingDeclaration, flags, getNoopSymbolTrackerWithResolver(context));
156680
157083
  if (!signatureDeclaration) {
156681
157084
  return undefined;
@@ -158153,6 +158556,10 @@ var ts;
158153
158556
  }
158154
158557
  break;
158155
158558
  }
158559
+ case 200 /* ImportType */:
158560
+ var importTypeNode = parent;
158561
+ changes.replaceNode(importingSourceFile, parent, ts.factory.createImportTypeNode(importTypeNode.argument, ts.factory.createIdentifier(exportName), importTypeNode.typeArguments, importTypeNode.isTypeOf));
158562
+ break;
158156
158563
  default:
158157
158564
  ts.Debug.failBadSyntaxKind(parent);
158158
158565
  }
@@ -159093,7 +159500,7 @@ var ts;
159093
159500
  // cannot find either start or end node
159094
159501
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
159095
159502
  }
159096
- if (start.flags & 4194304 /* JSDoc */) {
159503
+ if (start.flags & 8388608 /* JSDoc */) {
159097
159504
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractJSDoc)] };
159098
159505
  }
159099
159506
  if (start.parent !== end.parent) {
@@ -159219,7 +159626,7 @@ var ts;
159219
159626
  if (!ts.isStatement(nodeToCheck) && !(ts.isExpressionNode(nodeToCheck) && isExtractableExpression(nodeToCheck)) && !isStringLiteralJsxAttribute(nodeToCheck)) {
159220
159627
  return [ts.createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
159221
159628
  }
159222
- if (nodeToCheck.flags & 8388608 /* Ambient */) {
159629
+ if (nodeToCheck.flags & 16777216 /* Ambient */) {
159223
159630
  return [ts.createDiagnosticForNode(nodeToCheck, Messages.cannotExtractAmbientBlock)];
159224
159631
  }
159225
159632
  // If we're in a class, see whether we're in a static region (static property initializer, static method, class constructor parameter default)
@@ -159409,7 +159816,8 @@ var ts;
159409
159816
  return undefined;
159410
159817
  }
159411
159818
  function isScope(node) {
159412
- return ts.isFunctionLikeDeclaration(node) || ts.isSourceFile(node) || ts.isModuleBlock(node) || ts.isClassLike(node);
159819
+ return ts.isArrowFunction(node) ? ts.isFunctionBody(node.body) :
159820
+ ts.isFunctionLikeDeclaration(node) || ts.isSourceFile(node) || ts.isModuleBlock(node) || ts.isClassLike(node);
159413
159821
  }
159414
159822
  /**
159415
159823
  * Computes possible places we could extract the function into. For example,
@@ -160750,6 +161158,7 @@ var ts;
160750
161158
  }
160751
161159
  function doTypedefChange(changes, file, name, info) {
160752
161160
  var firstStatement = info.firstStatement, selection = info.selection, typeParameters = info.typeParameters;
161161
+ ts.setEmitFlags(selection, 1536 /* NoComments */ | 2048 /* NoNestedComments */);
160753
161162
  var node = ts.factory.createJSDocTypedefTag(ts.factory.createIdentifier("typedef"), ts.factory.createJSDocTypeExpression(selection), ts.factory.createIdentifier(name));
160754
161163
  var templates = [];
160755
161164
  ts.forEach(typeParameters, function (typeParameter) {
@@ -162780,7 +163189,7 @@ var ts;
162780
163189
  kind === 80 /* PrivateIdentifier */ ? new PrivateIdentifierObject(80 /* PrivateIdentifier */, pos, end) :
162781
163190
  new TokenObject(kind, pos, end);
162782
163191
  node.parent = parent;
162783
- node.flags = parent.flags & 25358336 /* ContextFlags */;
163192
+ node.flags = parent.flags & 50720768 /* ContextFlags */;
162784
163193
  return node;
162785
163194
  }
162786
163195
  var NodeObject = /** @class */ (function () {
@@ -164236,7 +164645,7 @@ var ts;
164236
164645
  }
164237
164646
  /// References and Occurrences
164238
164647
  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 })); }); });
164648
+ 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
164649
  }
164241
164650
  function getDocumentHighlights(fileName, position, filesToSearch) {
164242
164651
  var normalizedFileName = ts.normalizePath(fileName);
@@ -164265,7 +164674,7 @@ var ts;
164265
164674
  }
164266
164675
  function getReferencesAtPosition(fileName, position) {
164267
164676
  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)); });
164677
+ return getReferencesWorker(ts.getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: 1 /* References */ }, ts.FindAllReferences.toReferenceEntry);
164269
164678
  }
164270
164679
  function getReferencesWorker(node, position, options, cb) {
164271
164680
  synchronizeHostData();
@@ -164280,10 +164689,8 @@ var ts;
164280
164689
  return ts.FindAllReferences.findReferencedSymbols(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position);
164281
164690
  }
164282
164691
  function getFileReferences(fileName) {
164283
- var _a;
164284
164692
  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); });
164693
+ return ts.FindAllReferences.Core.getReferencesForFileName(fileName, program, program.getSourceFiles()).map(ts.FindAllReferences.toReferenceEntry);
164287
164694
  }
164288
164695
  function getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles) {
164289
164696
  if (excludeDtsFiles === void 0) { excludeDtsFiles = false; }
@@ -164756,7 +165163,7 @@ var ts;
164756
165163
  }
164757
165164
  function isUnclosedFragment(_a) {
164758
165165
  var closingFragment = _a.closingFragment, parent = _a.parent;
164759
- return !!(closingFragment.flags & 65536 /* ThisNodeHasError */) || (ts.isJsxFragment(parent) && isUnclosedFragment(parent));
165166
+ return !!(closingFragment.flags & 131072 /* ThisNodeHasError */) || (ts.isJsxFragment(parent) && isUnclosedFragment(parent));
164760
165167
  }
164761
165168
  function getSpanOfEnclosingComment(fileName, position, onlyMultiLine) {
164762
165169
  var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
@@ -165204,7 +165611,7 @@ var ts;
165204
165611
  tokenAtLocation = preceding;
165205
165612
  }
165206
165613
  // Cannot set breakpoint in ambient declarations
165207
- if (tokenAtLocation.flags & 8388608 /* Ambient */) {
165614
+ if (tokenAtLocation.flags & 16777216 /* Ambient */) {
165208
165615
  return undefined;
165209
165616
  }
165210
165617
  // Get the span in the node based on its syntax
@@ -173707,6 +174114,7 @@ var ts;
173707
174114
  logger.info("Finding references to " + location.fileName + " position " + location.pos + " in project " + project.getProjectName());
173708
174115
  var projectOutputs = project.getLanguageService().findReferences(location.fileName, location.pos);
173709
174116
  if (projectOutputs) {
174117
+ var clearIsDefinition = projectOutputs[0].references[0].isDefinition === undefined;
173710
174118
  var _loop_9 = function (referencedSymbol) {
173711
174119
  var mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(referencedSymbol.definition));
173712
174120
  var definition = mappedDefinitionFile === undefined ?
@@ -173720,6 +174128,9 @@ var ts;
173720
174128
  var ref = _b[_a];
173721
174129
  // If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
173722
174130
  if (!ts.contains(symbolToAddTo.references, ref, ts.documentSpansEqual) && !getMappedLocation(project, documentSpanLocation(ref))) {
174131
+ if (clearIsDefinition) {
174132
+ delete ref.isDefinition;
174133
+ }
173723
174134
  symbolToAddTo.references.push(ref);
173724
174135
  }
173725
174136
  }