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.
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220403";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220406";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -4415,10 +4415,11 @@ var ts;
4415
4415
  NodeFlags[NodeFlags["YieldContext"] = 8192] = "YieldContext";
4416
4416
  NodeFlags[NodeFlags["DecoratorContext"] = 16384] = "DecoratorContext";
4417
4417
  NodeFlags[NodeFlags["AwaitContext"] = 32768] = "AwaitContext";
4418
- NodeFlags[NodeFlags["ThisNodeHasError"] = 65536] = "ThisNodeHasError";
4419
- NodeFlags[NodeFlags["JavaScriptFile"] = 131072] = "JavaScriptFile";
4420
- NodeFlags[NodeFlags["ThisNodeOrAnySubNodesHasError"] = 262144] = "ThisNodeOrAnySubNodesHasError";
4421
- NodeFlags[NodeFlags["HasAggregatedChildData"] = 524288] = "HasAggregatedChildData";
4418
+ NodeFlags[NodeFlags["DisallowConditionalTypesContext"] = 65536] = "DisallowConditionalTypesContext";
4419
+ NodeFlags[NodeFlags["ThisNodeHasError"] = 131072] = "ThisNodeHasError";
4420
+ NodeFlags[NodeFlags["JavaScriptFile"] = 262144] = "JavaScriptFile";
4421
+ NodeFlags[NodeFlags["ThisNodeOrAnySubNodesHasError"] = 524288] = "ThisNodeOrAnySubNodesHasError";
4422
+ NodeFlags[NodeFlags["HasAggregatedChildData"] = 1048576] = "HasAggregatedChildData";
4422
4423
  // These flags will be set when the parser encounters a dynamic import expression or 'import.meta' to avoid
4423
4424
  // walking the tree if the flags are not set. However, these flags are just a approximation
4424
4425
  // (hence why it's named "PossiblyContainsDynamicImport") because once set, the flags never get cleared.
@@ -4428,25 +4429,25 @@ var ts;
4428
4429
  // removal, it is likely that users will add the import anyway.
4429
4430
  // The advantage of this approach is its simplicity. For the case of batch compilation,
4430
4431
  // we guarantee that users won't have to pay the price of walking the tree if a dynamic import isn't used.
4431
- /* @internal */ NodeFlags[NodeFlags["PossiblyContainsDynamicImport"] = 1048576] = "PossiblyContainsDynamicImport";
4432
- /* @internal */ NodeFlags[NodeFlags["PossiblyContainsImportMeta"] = 2097152] = "PossiblyContainsImportMeta";
4433
- NodeFlags[NodeFlags["JSDoc"] = 4194304] = "JSDoc";
4434
- /* @internal */ NodeFlags[NodeFlags["Ambient"] = 8388608] = "Ambient";
4435
- /* @internal */ NodeFlags[NodeFlags["InWithStatement"] = 16777216] = "InWithStatement";
4436
- NodeFlags[NodeFlags["JsonFile"] = 33554432] = "JsonFile";
4437
- /* @internal */ NodeFlags[NodeFlags["TypeCached"] = 67108864] = "TypeCached";
4438
- /* @internal */ NodeFlags[NodeFlags["Deprecated"] = 134217728] = "Deprecated";
4432
+ /* @internal */ NodeFlags[NodeFlags["PossiblyContainsDynamicImport"] = 2097152] = "PossiblyContainsDynamicImport";
4433
+ /* @internal */ NodeFlags[NodeFlags["PossiblyContainsImportMeta"] = 4194304] = "PossiblyContainsImportMeta";
4434
+ NodeFlags[NodeFlags["JSDoc"] = 8388608] = "JSDoc";
4435
+ /* @internal */ NodeFlags[NodeFlags["Ambient"] = 16777216] = "Ambient";
4436
+ /* @internal */ NodeFlags[NodeFlags["InWithStatement"] = 33554432] = "InWithStatement";
4437
+ NodeFlags[NodeFlags["JsonFile"] = 67108864] = "JsonFile";
4438
+ /* @internal */ NodeFlags[NodeFlags["TypeCached"] = 134217728] = "TypeCached";
4439
+ /* @internal */ NodeFlags[NodeFlags["Deprecated"] = 268435456] = "Deprecated";
4439
4440
  NodeFlags[NodeFlags["BlockScoped"] = 3] = "BlockScoped";
4440
4441
  NodeFlags[NodeFlags["ReachabilityCheckFlags"] = 768] = "ReachabilityCheckFlags";
4441
4442
  NodeFlags[NodeFlags["ReachabilityAndEmitFlags"] = 2816] = "ReachabilityAndEmitFlags";
4442
4443
  // Parsing context flags
4443
- NodeFlags[NodeFlags["ContextFlags"] = 25358336] = "ContextFlags";
4444
+ NodeFlags[NodeFlags["ContextFlags"] = 50720768] = "ContextFlags";
4444
4445
  // Exclude these flags when parsing a Type
4445
4446
  NodeFlags[NodeFlags["TypeExcludesFlags"] = 40960] = "TypeExcludesFlags";
4446
4447
  // Represents all flags that are potentially set once and
4447
4448
  // never cleared on SourceFiles which get re-used in between incremental parses.
4448
4449
  // See the comment above on `PossiblyContainsDynamicImport` and `PossiblyContainsImportMeta`.
4449
- /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 3145728] = "PermanentlySetIncrementalFlags";
4450
+ /* @internal */ NodeFlags[NodeFlags["PermanentlySetIncrementalFlags"] = 6291456] = "PermanentlySetIncrementalFlags";
4450
4451
  })(NodeFlags = ts.NodeFlags || (ts.NodeFlags = {}));
4451
4452
  var ModifierFlags;
4452
4453
  (function (ModifierFlags) {
@@ -8888,6 +8889,7 @@ var ts;
8888
8889
  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}'?"),
8889
8890
  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."),
8890
8891
  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."),
8892
+ 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."),
8891
8893
  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}'."),
8892
8894
  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}'."),
8893
8895
  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}'."),
@@ -14302,24 +14304,24 @@ var ts;
14302
14304
  // Returns true if this node contains a parse error anywhere underneath it.
14303
14305
  function containsParseError(node) {
14304
14306
  aggregateChildData(node);
14305
- return (node.flags & 262144 /* ThisNodeOrAnySubNodesHasError */) !== 0;
14307
+ return (node.flags & 524288 /* ThisNodeOrAnySubNodesHasError */) !== 0;
14306
14308
  }
14307
14309
  ts.containsParseError = containsParseError;
14308
14310
  function aggregateChildData(node) {
14309
- if (!(node.flags & 524288 /* HasAggregatedChildData */)) {
14311
+ if (!(node.flags & 1048576 /* HasAggregatedChildData */)) {
14310
14312
  // A node is considered to contain a parse error if:
14311
14313
  // a) the parser explicitly marked that it had an error
14312
14314
  // b) any of it's children reported that it had an error.
14313
- var thisNodeOrAnySubNodesHasError = ((node.flags & 65536 /* ThisNodeHasError */) !== 0) ||
14315
+ var thisNodeOrAnySubNodesHasError = ((node.flags & 131072 /* ThisNodeHasError */) !== 0) ||
14314
14316
  ts.forEachChild(node, containsParseError);
14315
14317
  // If so, mark ourselves accordingly.
14316
14318
  if (thisNodeOrAnySubNodesHasError) {
14317
- node.flags |= 262144 /* ThisNodeOrAnySubNodesHasError */;
14319
+ node.flags |= 524288 /* ThisNodeOrAnySubNodesHasError */;
14318
14320
  }
14319
14321
  // Also mark that we've propagated the child information to this node. This way we can
14320
14322
  // always consult the bit directly on this node without needing to check its children
14321
14323
  // again.
14322
- node.flags |= 524288 /* HasAggregatedChildData */;
14324
+ node.flags |= 1048576 /* HasAggregatedChildData */;
14323
14325
  }
14324
14326
  }
14325
14327
  function getSourceFileOfNode(node) {
@@ -16126,11 +16128,11 @@ var ts;
16126
16128
  }
16127
16129
  ts.isSourceFileNotJS = isSourceFileNotJS;
16128
16130
  function isInJSFile(node) {
16129
- return !!node && !!(node.flags & 131072 /* JavaScriptFile */);
16131
+ return !!node && !!(node.flags & 262144 /* JavaScriptFile */);
16130
16132
  }
16131
16133
  ts.isInJSFile = isInJSFile;
16132
16134
  function isInJsonFile(node) {
16133
- return !!node && !!(node.flags & 33554432 /* JsonFile */);
16135
+ return !!node && !!(node.flags & 67108864 /* JsonFile */);
16134
16136
  }
16135
16137
  ts.isInJsonFile = isInJsonFile;
16136
16138
  function isSourceFileNotJson(file) {
@@ -16138,7 +16140,7 @@ var ts;
16138
16140
  }
16139
16141
  ts.isSourceFileNotJson = isSourceFileNotJson;
16140
16142
  function isInJSDoc(node) {
16141
- return !!node && !!(node.flags & 4194304 /* JSDoc */);
16143
+ return !!node && !!(node.flags & 8388608 /* JSDoc */);
16142
16144
  }
16143
16145
  ts.isInJSDoc = isInJSDoc;
16144
16146
  function isJSDocIndexSignature(node) {
@@ -16524,7 +16526,7 @@ var ts;
16524
16526
  function setValueDeclaration(symbol, node) {
16525
16527
  var valueDeclaration = symbol.valueDeclaration;
16526
16528
  if (!valueDeclaration ||
16527
- !(node.flags & 8388608 /* Ambient */ && !(valueDeclaration.flags & 8388608 /* Ambient */)) &&
16529
+ !(node.flags & 16777216 /* Ambient */ && !(valueDeclaration.flags & 16777216 /* Ambient */)) &&
16528
16530
  (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) ||
16529
16531
  (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) {
16530
16532
  // other kinds of value declarations take precedence over modules and assignment declarations
@@ -16797,7 +16799,11 @@ var ts;
16797
16799
  ts.getEffectiveContainerForJSDocTemplateTag = getEffectiveContainerForJSDocTemplateTag;
16798
16800
  function getHostSignatureFromJSDoc(node) {
16799
16801
  var host = getEffectiveJSDocHost(node);
16800
- return host && ts.isFunctionLike(host) ? host : undefined;
16802
+ if (host) {
16803
+ return ts.isPropertySignature(host) && host.type && ts.isFunctionLike(host.type) ? host.type :
16804
+ ts.isFunctionLike(host) ? host : undefined;
16805
+ }
16806
+ return undefined;
16801
16807
  }
16802
16808
  ts.getHostSignatureFromJSDoc = getHostSignatureFromJSDoc;
16803
16809
  function getEffectiveJSDocHost(node) {
@@ -20822,7 +20828,7 @@ var ts;
20822
20828
  }
20823
20829
  ts.pseudoBigIntToString = pseudoBigIntToString;
20824
20830
  function isValidTypeOnlyAliasUseSite(useSite) {
20825
- return !!(useSite.flags & 8388608 /* Ambient */)
20831
+ return !!(useSite.flags & 16777216 /* Ambient */)
20826
20832
  || isPartOfTypeQuery(useSite)
20827
20833
  || isIdentifierInNonEmittingHeritageClause(useSite)
20828
20834
  || isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(useSite)
@@ -21275,11 +21281,20 @@ var ts;
21275
21281
  parenthesizeExpressionForDisallowedComma: parenthesizeExpressionForDisallowedComma,
21276
21282
  parenthesizeExpressionOfExpressionStatement: parenthesizeExpressionOfExpressionStatement,
21277
21283
  parenthesizeConciseBodyOfArrowFunction: parenthesizeConciseBodyOfArrowFunction,
21278
- parenthesizeMemberOfConditionalType: parenthesizeMemberOfConditionalType,
21279
- parenthesizeMemberOfElementType: parenthesizeMemberOfElementType,
21280
- parenthesizeElementTypeOfArrayType: parenthesizeElementTypeOfArrayType,
21281
- parenthesizeConstituentTypesOfUnionOrIntersectionType: parenthesizeConstituentTypesOfUnionOrIntersectionType,
21284
+ parenthesizeCheckTypeOfConditionalType: parenthesizeCheckTypeOfConditionalType,
21285
+ parenthesizeExtendsTypeOfConditionalType: parenthesizeExtendsTypeOfConditionalType,
21286
+ parenthesizeConstituentTypesOfUnionType: parenthesizeConstituentTypesOfUnionType,
21287
+ parenthesizeConstituentTypeOfUnionType: parenthesizeConstituentTypeOfUnionType,
21288
+ parenthesizeConstituentTypesOfIntersectionType: parenthesizeConstituentTypesOfIntersectionType,
21289
+ parenthesizeConstituentTypeOfIntersectionType: parenthesizeConstituentTypeOfIntersectionType,
21290
+ parenthesizeOperandOfTypeOperator: parenthesizeOperandOfTypeOperator,
21291
+ parenthesizeOperandOfReadonlyTypeOperator: parenthesizeOperandOfReadonlyTypeOperator,
21292
+ parenthesizeNonArrayTypeOfPostfixType: parenthesizeNonArrayTypeOfPostfixType,
21293
+ parenthesizeElementTypesOfTupleType: parenthesizeElementTypesOfTupleType,
21294
+ parenthesizeElementTypeOfTupleType: parenthesizeElementTypeOfTupleType,
21295
+ parenthesizeTypeOfOptionalType: parenthesizeTypeOfOptionalType,
21282
21296
  parenthesizeTypeArguments: parenthesizeTypeArguments,
21297
+ parenthesizeLeadingTypeArgument: parenthesizeLeadingTypeArgument,
21283
21298
  };
21284
21299
  function getParenthesizeLeftSideOfBinaryForOperator(operatorKind) {
21285
21300
  binaryLeftOperandParenthesizerCache || (binaryLeftOperandParenthesizerCache = new ts.Map());
@@ -21591,33 +21606,191 @@ var ts;
21591
21606
  }
21592
21607
  return body;
21593
21608
  }
21594
- function parenthesizeMemberOfConditionalType(member) {
21595
- return member.kind === 189 /* ConditionalType */ ? factory.createParenthesizedType(member) : member;
21609
+ // Type[Extends] :
21610
+ // FunctionOrConstructorType
21611
+ // ConditionalType[?Extends]
21612
+ // ConditionalType[Extends] :
21613
+ // UnionType[?Extends]
21614
+ // [~Extends] UnionType[~Extends] `extends` Type[+Extends] `?` Type[~Extends] `:` Type[~Extends]
21615
+ //
21616
+ // - The check type (the `UnionType`, above) does not allow function, constructor, or conditional types (they must be parenthesized)
21617
+ // - The extends type (the first `Type`, above) does not allow conditional types (they must be parenthesized). Function and constructor types are fine.
21618
+ // - The true and false branch types (the second and third `Type` non-terminals, above) allow any type
21619
+ function parenthesizeCheckTypeOfConditionalType(checkType) {
21620
+ switch (checkType.kind) {
21621
+ case 179 /* FunctionType */:
21622
+ case 180 /* ConstructorType */:
21623
+ case 189 /* ConditionalType */:
21624
+ return factory.createParenthesizedType(checkType);
21625
+ }
21626
+ return checkType;
21596
21627
  }
21597
- function parenthesizeMemberOfElementType(member) {
21598
- switch (member.kind) {
21628
+ function parenthesizeExtendsTypeOfConditionalType(extendsType) {
21629
+ switch (extendsType.kind) {
21630
+ case 189 /* ConditionalType */:
21631
+ return factory.createParenthesizedType(extendsType);
21632
+ }
21633
+ return extendsType;
21634
+ }
21635
+ // UnionType[Extends] :
21636
+ // `|`? IntersectionType[?Extends]
21637
+ // UnionType[?Extends] `|` IntersectionType[?Extends]
21638
+ //
21639
+ // - A union type constituent has the same precedence as the check type of a conditional type
21640
+ function parenthesizeConstituentTypeOfUnionType(type) {
21641
+ switch (type.kind) {
21642
+ case 187 /* UnionType */: // Not strictly necessary, but a union containing a union should have been flattened
21643
+ case 188 /* IntersectionType */: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests
21644
+ return factory.createParenthesizedType(type);
21645
+ }
21646
+ return parenthesizeCheckTypeOfConditionalType(type);
21647
+ }
21648
+ function parenthesizeConstituentTypesOfUnionType(members) {
21649
+ return factory.createNodeArray(ts.sameMap(members, parenthesizeConstituentTypeOfUnionType));
21650
+ }
21651
+ // IntersectionType[Extends] :
21652
+ // `&`? TypeOperator[?Extends]
21653
+ // IntersectionType[?Extends] `&` TypeOperator[?Extends]
21654
+ //
21655
+ // - An intersection type constituent does not allow function, constructor, conditional, or union types (they must be parenthesized)
21656
+ function parenthesizeConstituentTypeOfIntersectionType(type) {
21657
+ switch (type.kind) {
21599
21658
  case 187 /* UnionType */:
21659
+ case 188 /* IntersectionType */: // Not strictly necessary, but an intersection containing an intersection should have been flattened
21660
+ return factory.createParenthesizedType(type);
21661
+ }
21662
+ return parenthesizeConstituentTypeOfUnionType(type);
21663
+ }
21664
+ function parenthesizeConstituentTypesOfIntersectionType(members) {
21665
+ return factory.createNodeArray(ts.sameMap(members, parenthesizeConstituentTypeOfIntersectionType));
21666
+ }
21667
+ // TypeOperator[Extends] :
21668
+ // PostfixType
21669
+ // InferType[?Extends]
21670
+ // `keyof` TypeOperator[?Extends]
21671
+ // `unique` TypeOperator[?Extends]
21672
+ // `readonly` TypeOperator[?Extends]
21673
+ //
21674
+ function parenthesizeOperandOfTypeOperator(type) {
21675
+ switch (type.kind) {
21600
21676
  case 188 /* IntersectionType */:
21601
- case 179 /* FunctionType */:
21602
- case 180 /* ConstructorType */:
21603
- return factory.createParenthesizedType(member);
21677
+ return factory.createParenthesizedType(type);
21604
21678
  }
21605
- return parenthesizeMemberOfConditionalType(member);
21679
+ return parenthesizeConstituentTypeOfIntersectionType(type);
21606
21680
  }
21607
- function parenthesizeElementTypeOfArrayType(member) {
21608
- switch (member.kind) {
21609
- case 181 /* TypeQuery */:
21681
+ function parenthesizeOperandOfReadonlyTypeOperator(type) {
21682
+ switch (type.kind) {
21610
21683
  case 193 /* TypeOperator */:
21684
+ return factory.createParenthesizedType(type);
21685
+ }
21686
+ return parenthesizeOperandOfTypeOperator(type);
21687
+ }
21688
+ // PostfixType :
21689
+ // NonArrayType
21690
+ // NonArrayType [no LineTerminator here] `!` // JSDoc
21691
+ // NonArrayType [no LineTerminator here] `?` // JSDoc
21692
+ // IndexedAccessType
21693
+ // ArrayType
21694
+ //
21695
+ // IndexedAccessType :
21696
+ // NonArrayType `[` Type[~Extends] `]`
21697
+ //
21698
+ // ArrayType :
21699
+ // NonArrayType `[` `]`
21700
+ //
21701
+ function parenthesizeNonArrayTypeOfPostfixType(type) {
21702
+ switch (type.kind) {
21611
21703
  case 190 /* InferType */:
21612
- return factory.createParenthesizedType(member);
21704
+ case 193 /* TypeOperator */:
21705
+ case 181 /* TypeQuery */: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests
21706
+ return factory.createParenthesizedType(type);
21613
21707
  }
21614
- return parenthesizeMemberOfElementType(member);
21708
+ return parenthesizeOperandOfTypeOperator(type);
21615
21709
  }
21616
- function parenthesizeConstituentTypesOfUnionOrIntersectionType(members) {
21617
- return factory.createNodeArray(ts.sameMap(members, parenthesizeMemberOfElementType));
21710
+ // TupleType :
21711
+ // `[` Elision? `]`
21712
+ // `[` NamedTupleElementTypes `]`
21713
+ // `[` NamedTupleElementTypes `,` Elision? `]`
21714
+ // `[` TupleElementTypes `]`
21715
+ // `[` TupleElementTypes `,` Elision? `]`
21716
+ //
21717
+ // NamedTupleElementTypes :
21718
+ // Elision? NamedTupleMember
21719
+ // NamedTupleElementTypes `,` Elision? NamedTupleMember
21720
+ //
21721
+ // NamedTupleMember :
21722
+ // Identifier `?`? `:` Type[~Extends]
21723
+ // `...` Identifier `:` Type[~Extends]
21724
+ //
21725
+ // TupleElementTypes :
21726
+ // Elision? TupleElementType
21727
+ // TupleElementTypes `,` Elision? TupleElementType
21728
+ //
21729
+ // TupleElementType :
21730
+ // Type[~Extends] // NOTE: Needs cover grammar to disallow JSDoc postfix-optional
21731
+ // OptionalType
21732
+ // RestType
21733
+ //
21734
+ // OptionalType :
21735
+ // Type[~Extends] `?` // NOTE: Needs cover grammar to disallow JSDoc postfix-optional
21736
+ //
21737
+ // RestType :
21738
+ // `...` Type[~Extends]
21739
+ //
21740
+ function parenthesizeElementTypesOfTupleType(types) {
21741
+ return factory.createNodeArray(ts.sameMap(types, parenthesizeElementTypeOfTupleType));
21742
+ }
21743
+ function parenthesizeElementTypeOfTupleType(type) {
21744
+ if (hasJSDocPostfixQuestion(type))
21745
+ return factory.createParenthesizedType(type);
21746
+ return type;
21747
+ }
21748
+ function hasJSDocPostfixQuestion(type) {
21749
+ if (ts.isJSDocNullableType(type))
21750
+ return type.postfix;
21751
+ if (ts.isNamedTupleMember(type))
21752
+ return hasJSDocPostfixQuestion(type.type);
21753
+ if (ts.isFunctionTypeNode(type) || ts.isConstructorTypeNode(type) || ts.isTypeOperatorNode(type))
21754
+ return hasJSDocPostfixQuestion(type.type);
21755
+ if (ts.isConditionalTypeNode(type))
21756
+ return hasJSDocPostfixQuestion(type.falseType);
21757
+ if (ts.isUnionTypeNode(type))
21758
+ return hasJSDocPostfixQuestion(ts.last(type.types));
21759
+ if (ts.isIntersectionTypeNode(type))
21760
+ return hasJSDocPostfixQuestion(ts.last(type.types));
21761
+ if (ts.isInferTypeNode(type))
21762
+ return !!type.typeParameter.constraint && hasJSDocPostfixQuestion(type.typeParameter.constraint);
21763
+ return false;
21764
+ }
21765
+ function parenthesizeTypeOfOptionalType(type) {
21766
+ if (hasJSDocPostfixQuestion(type))
21767
+ return factory.createParenthesizedType(type);
21768
+ return parenthesizeNonArrayTypeOfPostfixType(type);
21769
+ }
21770
+ // function parenthesizeMemberOfElementType(member: TypeNode): TypeNode {
21771
+ // switch (member.kind) {
21772
+ // case SyntaxKind.UnionType:
21773
+ // case SyntaxKind.IntersectionType:
21774
+ // case SyntaxKind.FunctionType:
21775
+ // case SyntaxKind.ConstructorType:
21776
+ // return factory.createParenthesizedType(member);
21777
+ // }
21778
+ // return parenthesizeMemberOfConditionalType(member);
21779
+ // }
21780
+ // function parenthesizeElementTypeOfArrayType(member: TypeNode): TypeNode {
21781
+ // switch (member.kind) {
21782
+ // case SyntaxKind.TypeQuery:
21783
+ // case SyntaxKind.TypeOperator:
21784
+ // case SyntaxKind.InferType:
21785
+ // return factory.createParenthesizedType(member);
21786
+ // }
21787
+ // return parenthesizeMemberOfElementType(member);
21788
+ // }
21789
+ function parenthesizeLeadingTypeArgument(node) {
21790
+ return ts.isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory.createParenthesizedType(node) : node;
21618
21791
  }
21619
21792
  function parenthesizeOrdinalTypeArgument(node, i) {
21620
- return i === 0 && ts.isFunctionOrConstructorTypeNode(node) && node.typeParameters ? factory.createParenthesizedType(node) : node;
21793
+ return i === 0 ? parenthesizeLeadingTypeArgument(node) : node;
21621
21794
  }
21622
21795
  function parenthesizeTypeArguments(typeArguments) {
21623
21796
  if (ts.some(typeArguments)) {
@@ -21643,11 +21816,20 @@ var ts;
21643
21816
  parenthesizeExpressionForDisallowedComma: ts.identity,
21644
21817
  parenthesizeExpressionOfExpressionStatement: ts.identity,
21645
21818
  parenthesizeConciseBodyOfArrowFunction: ts.identity,
21646
- parenthesizeMemberOfConditionalType: ts.identity,
21647
- parenthesizeMemberOfElementType: ts.identity,
21648
- parenthesizeElementTypeOfArrayType: ts.identity,
21649
- parenthesizeConstituentTypesOfUnionOrIntersectionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
21819
+ parenthesizeCheckTypeOfConditionalType: ts.identity,
21820
+ parenthesizeExtendsTypeOfConditionalType: ts.identity,
21821
+ parenthesizeConstituentTypesOfUnionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
21822
+ parenthesizeConstituentTypeOfUnionType: ts.identity,
21823
+ parenthesizeConstituentTypesOfIntersectionType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
21824
+ parenthesizeConstituentTypeOfIntersectionType: ts.identity,
21825
+ parenthesizeOperandOfTypeOperator: ts.identity,
21826
+ parenthesizeOperandOfReadonlyTypeOperator: ts.identity,
21827
+ parenthesizeNonArrayTypeOfPostfixType: ts.identity,
21828
+ parenthesizeElementTypesOfTupleType: function (nodes) { return ts.cast(nodes, ts.isNodeArray); },
21829
+ parenthesizeElementTypeOfTupleType: ts.identity,
21830
+ parenthesizeTypeOfOptionalType: ts.identity,
21650
21831
  parenthesizeTypeArguments: function (nodes) { return nodes && ts.cast(nodes, ts.isNodeArray); },
21832
+ parenthesizeLeadingTypeArgument: ts.identity,
21651
21833
  };
21652
21834
  })(ts || (ts = {}));
21653
21835
  /* @internal */
@@ -21787,6 +21969,8 @@ var ts;
21787
21969
  var getJSDocPrimaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function () { return createJSDocPrimaryTypeWorker(kind); }; });
21788
21970
  var getJSDocUnaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function (type) { return createJSDocUnaryTypeWorker(kind, type); }; });
21789
21971
  var getJSDocUnaryTypeUpdateFunction = ts.memoizeOne(function (kind) { return function (node, type) { return updateJSDocUnaryTypeWorker(kind, node, type); }; });
21972
+ var getJSDocPrePostfixUnaryTypeCreateFunction = ts.memoizeOne(function (kind) { return function (type, postfix) { return createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix); }; });
21973
+ var getJSDocPrePostfixUnaryTypeUpdateFunction = ts.memoizeOne(function (kind) { return function (node, type) { return updateJSDocPrePostfixUnaryTypeWorker(kind, node, type); }; });
21790
21974
  var getJSDocSimpleTagCreateFunction = ts.memoizeOne(function (kind) { return function (tagName, comment) { return createJSDocSimpleTagWorker(kind, tagName, comment); }; });
21791
21975
  var getJSDocSimpleTagUpdateFunction = ts.memoizeOne(function (kind) { return function (node, tagName, comment) { return updateJSDocSimpleTagWorker(kind, node, tagName, comment); }; });
21792
21976
  var getJSDocTypeLikeTagCreateFunction = ts.memoizeOne(function (kind) { return function (tagName, typeExpression, comment) { return createJSDocTypeLikeTagWorker(kind, tagName, typeExpression, comment); }; });
@@ -21794,6 +21978,8 @@ var ts;
21794
21978
  var factory = {
21795
21979
  get parenthesizer() { return parenthesizerRules(); },
21796
21980
  get converters() { return converters(); },
21981
+ baseFactory: baseFactory,
21982
+ flags: flags,
21797
21983
  createNodeArray: createNodeArray,
21798
21984
  createNumericLiteral: createNumericLiteral,
21799
21985
  createBigIntLiteral: createBigIntLiteral,
@@ -22069,10 +22255,10 @@ var ts;
22069
22255
  // lazily load factory members for JSDoc types with similar structure
22070
22256
  get createJSDocAllType() { return getJSDocPrimaryTypeCreateFunction(312 /* JSDocAllType */); },
22071
22257
  get createJSDocUnknownType() { return getJSDocPrimaryTypeCreateFunction(313 /* JSDocUnknownType */); },
22072
- get createJSDocNonNullableType() { return getJSDocUnaryTypeCreateFunction(315 /* JSDocNonNullableType */); },
22073
- get updateJSDocNonNullableType() { return getJSDocUnaryTypeUpdateFunction(315 /* JSDocNonNullableType */); },
22074
- get createJSDocNullableType() { return getJSDocUnaryTypeCreateFunction(314 /* JSDocNullableType */); },
22075
- get updateJSDocNullableType() { return getJSDocUnaryTypeUpdateFunction(314 /* JSDocNullableType */); },
22258
+ get createJSDocNonNullableType() { return getJSDocPrePostfixUnaryTypeCreateFunction(315 /* JSDocNonNullableType */); },
22259
+ get updateJSDocNonNullableType() { return getJSDocPrePostfixUnaryTypeUpdateFunction(315 /* JSDocNonNullableType */); },
22260
+ get createJSDocNullableType() { return getJSDocPrePostfixUnaryTypeCreateFunction(314 /* JSDocNullableType */); },
22261
+ get updateJSDocNullableType() { return getJSDocPrePostfixUnaryTypeUpdateFunction(314 /* JSDocNullableType */); },
22076
22262
  get createJSDocOptionalType() { return getJSDocUnaryTypeCreateFunction(316 /* JSDocOptionalType */); },
22077
22263
  get updateJSDocOptionalType() { return getJSDocUnaryTypeUpdateFunction(316 /* JSDocOptionalType */); },
22078
22264
  get createJSDocVariadicType() { return getJSDocUnaryTypeCreateFunction(318 /* JSDocVariadicType */); },
@@ -23188,7 +23374,7 @@ var ts;
23188
23374
  // @api
23189
23375
  function createArrayTypeNode(elementType) {
23190
23376
  var node = createBaseNode(183 /* ArrayType */);
23191
- node.elementType = parenthesizerRules().parenthesizeElementTypeOfArrayType(elementType);
23377
+ node.elementType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(elementType);
23192
23378
  node.transformFlags = 1 /* ContainsTypeScript */;
23193
23379
  return node;
23194
23380
  }
@@ -23201,7 +23387,7 @@ var ts;
23201
23387
  // @api
23202
23388
  function createTupleTypeNode(elements) {
23203
23389
  var node = createBaseNode(184 /* TupleType */);
23204
- node.elements = createNodeArray(elements);
23390
+ node.elements = createNodeArray(parenthesizerRules().parenthesizeElementTypesOfTupleType(elements));
23205
23391
  node.transformFlags = 1 /* ContainsTypeScript */;
23206
23392
  return node;
23207
23393
  }
@@ -23233,7 +23419,7 @@ var ts;
23233
23419
  // @api
23234
23420
  function createOptionalTypeNode(type) {
23235
23421
  var node = createBaseNode(185 /* OptionalType */);
23236
- node.type = parenthesizerRules().parenthesizeElementTypeOfArrayType(type);
23422
+ node.type = parenthesizerRules().parenthesizeTypeOfOptionalType(type);
23237
23423
  node.transformFlags = 1 /* ContainsTypeScript */;
23238
23424
  return node;
23239
23425
  }
@@ -23256,38 +23442,38 @@ var ts;
23256
23442
  ? update(createRestTypeNode(type), node)
23257
23443
  : node;
23258
23444
  }
23259
- function createUnionOrIntersectionTypeNode(kind, types) {
23445
+ function createUnionOrIntersectionTypeNode(kind, types, parenthesize) {
23260
23446
  var node = createBaseNode(kind);
23261
- node.types = parenthesizerRules().parenthesizeConstituentTypesOfUnionOrIntersectionType(types);
23447
+ node.types = factory.createNodeArray(parenthesize(types));
23262
23448
  node.transformFlags = 1 /* ContainsTypeScript */;
23263
23449
  return node;
23264
23450
  }
23265
- function updateUnionOrIntersectionTypeNode(node, types) {
23451
+ function updateUnionOrIntersectionTypeNode(node, types, parenthesize) {
23266
23452
  return node.types !== types
23267
- ? update(createUnionOrIntersectionTypeNode(node.kind, types), node)
23453
+ ? update(createUnionOrIntersectionTypeNode(node.kind, types, parenthesize), node)
23268
23454
  : node;
23269
23455
  }
23270
23456
  // @api
23271
23457
  function createUnionTypeNode(types) {
23272
- return createUnionOrIntersectionTypeNode(187 /* UnionType */, types);
23458
+ return createUnionOrIntersectionTypeNode(187 /* UnionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
23273
23459
  }
23274
23460
  // @api
23275
23461
  function updateUnionTypeNode(node, types) {
23276
- return updateUnionOrIntersectionTypeNode(node, types);
23462
+ return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfUnionType);
23277
23463
  }
23278
23464
  // @api
23279
23465
  function createIntersectionTypeNode(types) {
23280
- return createUnionOrIntersectionTypeNode(188 /* IntersectionType */, types);
23466
+ return createUnionOrIntersectionTypeNode(188 /* IntersectionType */, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
23281
23467
  }
23282
23468
  // @api
23283
23469
  function updateIntersectionTypeNode(node, types) {
23284
- return updateUnionOrIntersectionTypeNode(node, types);
23470
+ return updateUnionOrIntersectionTypeNode(node, types, parenthesizerRules().parenthesizeConstituentTypesOfIntersectionType);
23285
23471
  }
23286
23472
  // @api
23287
23473
  function createConditionalTypeNode(checkType, extendsType, trueType, falseType) {
23288
23474
  var node = createBaseNode(189 /* ConditionalType */);
23289
- node.checkType = parenthesizerRules().parenthesizeMemberOfConditionalType(checkType);
23290
- node.extendsType = parenthesizerRules().parenthesizeMemberOfConditionalType(extendsType);
23475
+ node.checkType = parenthesizerRules().parenthesizeCheckTypeOfConditionalType(checkType);
23476
+ node.extendsType = parenthesizerRules().parenthesizeExtendsTypeOfConditionalType(extendsType);
23291
23477
  node.trueType = trueType;
23292
23478
  node.falseType = falseType;
23293
23479
  node.transformFlags = 1 /* ContainsTypeScript */;
@@ -23382,7 +23568,9 @@ var ts;
23382
23568
  function createTypeOperatorNode(operator, type) {
23383
23569
  var node = createBaseNode(193 /* TypeOperator */);
23384
23570
  node.operator = operator;
23385
- node.type = parenthesizerRules().parenthesizeMemberOfElementType(type);
23571
+ node.type = operator === 145 /* ReadonlyKeyword */ ?
23572
+ parenthesizerRules().parenthesizeOperandOfReadonlyTypeOperator(type) :
23573
+ parenthesizerRules().parenthesizeOperandOfTypeOperator(type);
23386
23574
  node.transformFlags = 1 /* ContainsTypeScript */;
23387
23575
  return node;
23388
23576
  }
@@ -23395,7 +23583,7 @@ var ts;
23395
23583
  // @api
23396
23584
  function createIndexedAccessTypeNode(objectType, indexType) {
23397
23585
  var node = createBaseNode(194 /* IndexedAccessType */);
23398
- node.objectType = parenthesizerRules().parenthesizeMemberOfElementType(objectType);
23586
+ node.objectType = parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(objectType);
23399
23587
  node.indexType = indexType;
23400
23588
  node.transformFlags = 1 /* ContainsTypeScript */;
23401
23589
  return node;
@@ -25131,8 +25319,15 @@ var ts;
25131
25319
  return createBaseNode(kind);
25132
25320
  }
25133
25321
  // @api
25134
- // createJSDocNonNullableType
25135
25322
  // createJSDocNullableType
25323
+ // createJSDocNonNullableType
25324
+ function createJSDocPrePostfixUnaryTypeWorker(kind, type, postfix) {
25325
+ if (postfix === void 0) { postfix = false; }
25326
+ var node = createJSDocUnaryTypeWorker(kind, postfix ? type && parenthesizerRules().parenthesizeNonArrayTypeOfPostfixType(type) : type);
25327
+ node.postfix = postfix;
25328
+ return node;
25329
+ }
25330
+ // @api
25136
25331
  // createJSDocOptionalType
25137
25332
  // createJSDocVariadicType
25138
25333
  // createJSDocNamepathType
@@ -25144,6 +25339,12 @@ var ts;
25144
25339
  // @api
25145
25340
  // updateJSDocNonNullableType
25146
25341
  // updateJSDocNullableType
25342
+ function updateJSDocPrePostfixUnaryTypeWorker(kind, node, type) {
25343
+ return node.type !== type
25344
+ ? update(createJSDocPrePostfixUnaryTypeWorker(kind, type, node.postfix), node)
25345
+ : node;
25346
+ }
25347
+ // @api
25147
25348
  // updateJSDocOptionalType
25148
25349
  // updateJSDocVariadicType
25149
25350
  // updateJSDocNamepathType
@@ -30224,7 +30425,7 @@ var ts;
30224
30425
  || ts.isExportDeclaration(node) ? node : undefined;
30225
30426
  }
30226
30427
  function getImportMetaIfNecessary(sourceFile) {
30227
- return sourceFile.flags & 2097152 /* PossiblyContainsImportMeta */ ?
30428
+ return sourceFile.flags & 4194304 /* PossiblyContainsImportMeta */ ?
30228
30429
  walkTreeForImportMeta(sourceFile) :
30229
30430
  undefined;
30230
30431
  }
@@ -30879,7 +31080,7 @@ var ts;
30879
31080
  var newSourceFile = IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
30880
31081
  // 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.
30881
31082
  // We will manually port the flag to the new source file.
30882
- newSourceFile.flags |= (sourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */);
31083
+ newSourceFile.flags |= (sourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */);
30883
31084
  return newSourceFile;
30884
31085
  }
30885
31086
  ts.updateSourceFile = updateSourceFile;
@@ -31163,10 +31364,10 @@ var ts;
31163
31364
  switch (scriptKind) {
31164
31365
  case 1 /* JS */:
31165
31366
  case 2 /* JSX */:
31166
- contextFlags = 131072 /* JavaScriptFile */;
31367
+ contextFlags = 262144 /* JavaScriptFile */;
31167
31368
  break;
31168
31369
  case 6 /* JSON */:
31169
- contextFlags = 131072 /* JavaScriptFile */ | 33554432 /* JsonFile */;
31370
+ contextFlags = 262144 /* JavaScriptFile */ | 67108864 /* JsonFile */;
31170
31371
  break;
31171
31372
  default:
31172
31373
  contextFlags = 0 /* None */;
@@ -31201,7 +31402,7 @@ var ts;
31201
31402
  function parseSourceFileWorker(languageVersion, setParentNodes, scriptKind, setExternalModuleIndicator) {
31202
31403
  var isDeclarationFile = isDeclarationFileName(fileName);
31203
31404
  if (isDeclarationFile) {
31204
- contextFlags |= 8388608 /* Ambient */;
31405
+ contextFlags |= 16777216 /* Ambient */;
31205
31406
  }
31206
31407
  sourceFlags = contextFlags;
31207
31408
  // Prime the scanner.
@@ -31240,7 +31441,7 @@ var ts;
31240
31441
  node.jsDoc = jsDoc;
31241
31442
  if (hasDeprecatedTag) {
31242
31443
  hasDeprecatedTag = false;
31243
- node.flags |= 134217728 /* Deprecated */;
31444
+ node.flags |= 268435456 /* Deprecated */;
31244
31445
  }
31245
31446
  return node;
31246
31447
  }
@@ -31435,6 +31636,12 @@ var ts;
31435
31636
  function disallowInAnd(func) {
31436
31637
  return doInsideOfContext(4096 /* DisallowInContext */, func);
31437
31638
  }
31639
+ function allowConditionalTypesAnd(func) {
31640
+ return doOutsideOfContext(65536 /* DisallowConditionalTypesContext */, func);
31641
+ }
31642
+ function disallowConditionalTypesAnd(func) {
31643
+ return doInsideOfContext(65536 /* DisallowConditionalTypesContext */, func);
31644
+ }
31438
31645
  function doInYieldContext(func) {
31439
31646
  return doInsideOfContext(8192 /* YieldContext */, func);
31440
31647
  }
@@ -31462,6 +31669,9 @@ var ts;
31462
31669
  function inDisallowInContext() {
31463
31670
  return inContext(4096 /* DisallowInContext */);
31464
31671
  }
31672
+ function inDisallowConditionalTypesContext() {
31673
+ return inContext(65536 /* DisallowConditionalTypesContext */);
31674
+ }
31465
31675
  function inDecoratorContext() {
31466
31676
  return inContext(16384 /* DecoratorContext */);
31467
31677
  }
@@ -31846,7 +32056,7 @@ var ts;
31846
32056
  // flag so that we don't mark any subsequent nodes.
31847
32057
  if (parseErrorBeforeNextFinishedNode) {
31848
32058
  parseErrorBeforeNextFinishedNode = false;
31849
- node.flags |= 65536 /* ThisNodeHasError */;
32059
+ node.flags |= 131072 /* ThisNodeHasError */;
31850
32060
  }
31851
32061
  return node;
31852
32062
  }
@@ -32304,7 +32514,7 @@ var ts;
32304
32514
  // differently depending on what mode it is in.
32305
32515
  //
32306
32516
  // This also applies to all our other context flags as well.
32307
- var nodeContextFlags = node.flags & 25358336 /* ContextFlags */;
32517
+ var nodeContextFlags = node.flags & 50720768 /* ContextFlags */;
32308
32518
  if (nodeContextFlags !== contextFlags) {
32309
32519
  return undefined;
32310
32520
  }
@@ -32563,7 +32773,6 @@ var ts;
32563
32773
  default: return [undefined]; // TODO: GH#18217 `default: Debug.assertNever(context);`
32564
32774
  }
32565
32775
  }
32566
- // Parses a comma-delimited list of elements
32567
32776
  function parseDelimitedList(kind, parseElement, considerSemicolonAsDelimiter) {
32568
32777
  var saveParsingContext = parsingContext;
32569
32778
  parsingContext |= 1 << kind;
@@ -32573,7 +32782,11 @@ var ts;
32573
32782
  while (true) {
32574
32783
  if (isListElement(kind, /*inErrorRecovery*/ false)) {
32575
32784
  var startPos = scanner.getStartPos();
32576
- list.push(parseListElement(kind, parseElement));
32785
+ var result = parseListElement(kind, parseElement);
32786
+ if (!result) {
32787
+ return undefined;
32788
+ }
32789
+ list.push(result);
32577
32790
  commaStart = scanner.getTokenPos();
32578
32791
  if (parseOptional(27 /* CommaToken */)) {
32579
32792
  // No need to check for a zero length node since we know we parsed a comma
@@ -32826,7 +33039,7 @@ var ts;
32826
33039
  function parseJSDocNonNullableType() {
32827
33040
  var pos = getNodePos();
32828
33041
  nextToken();
32829
- return finishNode(factory.createJSDocNonNullableType(parseNonArrayType()), pos);
33042
+ return finishNode(factory.createJSDocNonNullableType(parseNonArrayType(), /*postfix*/ false), pos);
32830
33043
  }
32831
33044
  function parseJSDocUnknownOrNullableType() {
32832
33045
  var pos = getNodePos();
@@ -32850,7 +33063,7 @@ var ts;
32850
33063
  return finishNode(factory.createJSDocUnknownType(), pos);
32851
33064
  }
32852
33065
  else {
32853
- return finishNode(factory.createJSDocNullableType(parseType()), pos);
33066
+ return finishNode(factory.createJSDocNullableType(parseType(), /*postfix*/ false), pos);
32854
33067
  }
32855
33068
  }
32856
33069
  function parseJSDocFunctionType() {
@@ -32978,13 +33191,20 @@ var ts;
32978
33191
  }
32979
33192
  return name;
32980
33193
  }
32981
- function parseParameterInOuterAwaitContext() {
32982
- return parseParameterWorker(/*inOuterAwaitContext*/ true);
33194
+ function isParameterNameStart() {
33195
+ // Be permissive about await and yield by calling isBindingIdentifier instead of isIdentifier; disallowing
33196
+ // them during a speculative parse leads to many more follow-on errors than allowing the function to parse then later
33197
+ // complaining about the use of the keywords.
33198
+ return isBindingIdentifier() || token() === 22 /* OpenBracketToken */ || token() === 18 /* OpenBraceToken */;
33199
+ }
33200
+ function parseParameter(inOuterAwaitContext) {
33201
+ return parseParameterWorker(inOuterAwaitContext);
32983
33202
  }
32984
- function parseParameter() {
32985
- return parseParameterWorker(/*inOuterAwaitContext*/ false);
33203
+ function parseParameterForSpeculation(inOuterAwaitContext) {
33204
+ return parseParameterWorker(inOuterAwaitContext, /*allowAmbiguity*/ false);
32986
33205
  }
32987
- function parseParameterWorker(inOuterAwaitContext) {
33206
+ function parseParameterWorker(inOuterAwaitContext, allowAmbiguity) {
33207
+ if (allowAmbiguity === void 0) { allowAmbiguity = true; }
32988
33208
  var pos = getNodePos();
32989
33209
  var hasJSDoc = hasPrecedingJSDocComment();
32990
33210
  // FormalParameter [Yield,Await]:
@@ -33005,13 +33225,17 @@ var ts;
33005
33225
  var savedTopLevel = topLevel;
33006
33226
  topLevel = false;
33007
33227
  var modifiers = parseModifiers();
33008
- var node = withJSDoc(finishNode(factory.createParameterDeclaration(decorators, modifiers, parseOptionalToken(25 /* DotDotDotToken */), parseNameOfParameter(modifiers), parseOptionalToken(57 /* QuestionToken */), parseTypeAnnotation(), parseInitializer()), pos), hasJSDoc);
33228
+ var dotDotDotToken = parseOptionalToken(25 /* DotDotDotToken */);
33229
+ if (!allowAmbiguity && !isParameterNameStart()) {
33230
+ return undefined;
33231
+ }
33232
+ var node = withJSDoc(finishNode(factory.createParameterDeclaration(decorators, modifiers, dotDotDotToken, parseNameOfParameter(modifiers), parseOptionalToken(57 /* QuestionToken */), parseTypeAnnotation(), parseInitializer()), pos), hasJSDoc);
33009
33233
  topLevel = savedTopLevel;
33010
33234
  return node;
33011
33235
  }
33012
33236
  function parseReturnType(returnToken, isType) {
33013
33237
  if (shouldParseReturnType(returnToken, isType)) {
33014
- return parseTypeOrTypePredicate();
33238
+ return allowConditionalTypesAnd(parseTypeOrTypePredicate);
33015
33239
  }
33016
33240
  }
33017
33241
  function shouldParseReturnType(returnToken, isType) {
@@ -33030,7 +33254,7 @@ var ts;
33030
33254
  }
33031
33255
  return false;
33032
33256
  }
33033
- function parseParametersWorker(flags) {
33257
+ function parseParametersWorker(flags, allowAmbiguity) {
33034
33258
  // FormalParameters [Yield,Await]: (modified)
33035
33259
  // [empty]
33036
33260
  // FormalParameterList[?Yield,Await]
@@ -33050,7 +33274,7 @@ var ts;
33050
33274
  setAwaitContext(!!(flags & 2 /* Await */));
33051
33275
  var parameters = flags & 32 /* JSDoc */ ?
33052
33276
  parseDelimitedList(17 /* JSDocParameters */, parseJSDocParameter) :
33053
- parseDelimitedList(16 /* Parameters */, savedAwaitContext ? parseParameterInOuterAwaitContext : parseParameter);
33277
+ parseDelimitedList(16 /* Parameters */, function () { return allowAmbiguity ? parseParameter(savedAwaitContext) : parseParameterForSpeculation(savedAwaitContext); });
33054
33278
  setYieldContext(savedYieldContext);
33055
33279
  setAwaitContext(savedAwaitContext);
33056
33280
  return parameters;
@@ -33072,7 +33296,7 @@ var ts;
33072
33296
  if (!parseExpected(20 /* OpenParenToken */)) {
33073
33297
  return createMissingList();
33074
33298
  }
33075
- var parameters = parseParametersWorker(flags);
33299
+ var parameters = parseParametersWorker(flags, /*allowAmbiguity*/ true);
33076
33300
  parseExpected(21 /* CloseParenToken */);
33077
33301
  return parameters;
33078
33302
  }
@@ -33154,7 +33378,7 @@ var ts;
33154
33378
  return token() === 58 /* ColonToken */ || token() === 27 /* CommaToken */ || token() === 23 /* CloseBracketToken */;
33155
33379
  }
33156
33380
  function parseIndexSignatureDeclaration(pos, hasJSDoc, decorators, modifiers) {
33157
- var parameters = parseBracketedList(16 /* Parameters */, parseParameter, 22 /* OpenBracketToken */, 23 /* CloseBracketToken */);
33381
+ var parameters = parseBracketedList(16 /* Parameters */, function () { return parseParameter(/*inOuterAwaitContext*/ false); }, 22 /* OpenBracketToken */, 23 /* CloseBracketToken */);
33158
33382
  var type = parseTypeAnnotation();
33159
33383
  parseTypeMemberSemicolon();
33160
33384
  var node = factory.createIndexSignature(decorators, modifiers, parameters, type);
@@ -33426,7 +33650,7 @@ var ts;
33426
33650
  return finishNode(factory.createImportTypeAssertionContainer(clause, multiLine), pos);
33427
33651
  }
33428
33652
  function parseImportType() {
33429
- sourceFlags |= 1048576 /* PossiblyContainsDynamicImport */;
33653
+ sourceFlags |= 2097152 /* PossiblyContainsDynamicImport */;
33430
33654
  var pos = getNodePos();
33431
33655
  var isTypeOf = parseOptional(112 /* TypeOfKeyword */);
33432
33656
  parseExpected(100 /* ImportKeyword */);
@@ -33576,7 +33800,7 @@ var ts;
33576
33800
  switch (token()) {
33577
33801
  case 53 /* ExclamationToken */:
33578
33802
  nextToken();
33579
- type = finishNode(factory.createJSDocNonNullableType(type), pos);
33803
+ type = finishNode(factory.createJSDocNonNullableType(type, /*postfix*/ true), pos);
33580
33804
  break;
33581
33805
  case 57 /* QuestionToken */:
33582
33806
  // If next token is start of a type we have a conditional type
@@ -33584,7 +33808,7 @@ var ts;
33584
33808
  return type;
33585
33809
  }
33586
33810
  nextToken();
33587
- type = finishNode(factory.createJSDocNullableType(type), pos);
33811
+ type = finishNode(factory.createJSDocNullableType(type, /*postfix*/ true), pos);
33588
33812
  break;
33589
33813
  case 22 /* OpenBracketToken */:
33590
33814
  parseExpected(22 /* OpenBracketToken */);
@@ -33609,12 +33833,20 @@ var ts;
33609
33833
  parseExpected(operator);
33610
33834
  return finishNode(factory.createTypeOperatorNode(operator, parseTypeOperatorOrHigher()), pos);
33611
33835
  }
33836
+ function tryParseConstraintOfInferType() {
33837
+ if (parseOptional(94 /* ExtendsKeyword */)) {
33838
+ var constraint = disallowConditionalTypesAnd(parseType);
33839
+ if (inDisallowConditionalTypesContext() || token() !== 57 /* QuestionToken */) {
33840
+ return constraint;
33841
+ }
33842
+ }
33843
+ }
33612
33844
  function parseTypeParameterOfInferType() {
33613
33845
  var pos = getNodePos();
33614
- return finishNode(factory.createTypeParameterDeclaration(
33615
- /*modifiers*/ undefined, parseIdentifier(),
33616
- /*constraint*/ undefined,
33617
- /*defaultType*/ undefined), pos);
33846
+ var name = parseIdentifier();
33847
+ var constraint = tryParse(tryParseConstraintOfInferType);
33848
+ var node = factory.createTypeParameterDeclaration(/*modifiers*/ undefined, name, constraint);
33849
+ return finishNode(node, pos);
33618
33850
  }
33619
33851
  function parseInferType() {
33620
33852
  var pos = getNodePos();
@@ -33631,7 +33863,7 @@ var ts;
33631
33863
  case 137 /* InferKeyword */:
33632
33864
  return parseInferType();
33633
33865
  }
33634
- return parsePostfixTypeOrHigher();
33866
+ return allowConditionalTypesAnd(parsePostfixTypeOrHigher);
33635
33867
  }
33636
33868
  function parseFunctionOrConstructorTypeToError(isInUnionType) {
33637
33869
  // the function type and constructor type shorthand notation
@@ -33761,23 +33993,21 @@ var ts;
33761
33993
  return finishNode(factory.createTypePredicateNode(assertsModifier, parameterName, type), pos);
33762
33994
  }
33763
33995
  function parseType() {
33764
- // The rules about 'yield' only apply to actual code/expression contexts. They don't
33765
- // apply to 'type' contexts. So we disable these parameters here before moving on.
33766
- return doOutsideOfContext(40960 /* TypeExcludesFlags */, parseTypeWorker);
33767
- }
33768
- function parseTypeWorker(noConditionalTypes) {
33996
+ if (contextFlags & 40960 /* TypeExcludesFlags */) {
33997
+ return doOutsideOfContext(40960 /* TypeExcludesFlags */, parseType);
33998
+ }
33769
33999
  if (isStartOfFunctionTypeOrConstructorType()) {
33770
34000
  return parseFunctionOrConstructorType();
33771
34001
  }
33772
34002
  var pos = getNodePos();
33773
34003
  var type = parseUnionTypeOrHigher();
33774
- if (!noConditionalTypes && !scanner.hasPrecedingLineBreak() && parseOptional(94 /* ExtendsKeyword */)) {
34004
+ if (!inDisallowConditionalTypesContext() && !scanner.hasPrecedingLineBreak() && parseOptional(94 /* ExtendsKeyword */)) {
33775
34005
  // The type following 'extends' is not permitted to be another conditional type
33776
- var extendsType = parseTypeWorker(/*noConditionalTypes*/ true);
34006
+ var extendsType = disallowConditionalTypesAnd(parseType);
33777
34007
  parseExpected(57 /* QuestionToken */);
33778
- var trueType = parseTypeWorker();
34008
+ var trueType = allowConditionalTypesAnd(parseType);
33779
34009
  parseExpected(58 /* ColonToken */);
33780
- var falseType = parseTypeWorker();
34010
+ var falseType = allowConditionalTypesAnd(parseType);
33781
34011
  return finishNode(factory.createConditionalTypeNode(type, extendsType, trueType, falseType), pos);
33782
34012
  }
33783
34013
  return type;
@@ -34204,7 +34434,16 @@ var ts;
34204
34434
  parameters = createMissingList();
34205
34435
  }
34206
34436
  else {
34207
- parameters = parseParametersWorker(isAsync);
34437
+ if (!allowAmbiguity) {
34438
+ var maybeParameters = parseParametersWorker(isAsync, allowAmbiguity);
34439
+ if (!maybeParameters) {
34440
+ return undefined;
34441
+ }
34442
+ parameters = maybeParameters;
34443
+ }
34444
+ else {
34445
+ parameters = parseParametersWorker(isAsync, allowAmbiguity);
34446
+ }
34208
34447
  if (!parseExpected(21 /* CloseParenToken */) && !allowAmbiguity) {
34209
34448
  return undefined;
34210
34449
  }
@@ -34605,7 +34844,7 @@ var ts;
34605
34844
  // var foo3 = require("subfolder
34606
34845
  // import * as foo1 from "module-from-node
34607
34846
  // We want this import to be a statement rather than import call expression
34608
- sourceFlags |= 1048576 /* PossiblyContainsDynamicImport */;
34847
+ sourceFlags |= 2097152 /* PossiblyContainsDynamicImport */;
34609
34848
  expression = parseTokenNode();
34610
34849
  }
34611
34850
  else if (lookAhead(nextTokenIsDot)) {
@@ -34613,7 +34852,7 @@ var ts;
34613
34852
  nextToken(); // advance past the 'import'
34614
34853
  nextToken(); // advance past the dot
34615
34854
  expression = finishNode(factory.createMetaProperty(100 /* ImportKeyword */, parseIdentifierName()), pos);
34616
- sourceFlags |= 2097152 /* PossiblyContainsImportMeta */;
34855
+ sourceFlags |= 4194304 /* PossiblyContainsImportMeta */;
34617
34856
  }
34618
34857
  else {
34619
34858
  expression = parseMemberExpressionOrHigher();
@@ -34829,7 +35068,7 @@ var ts;
34829
35068
  return finishNode(factory.createJsxOpeningFragment(), pos);
34830
35069
  }
34831
35070
  var tagName = parseJsxElementName();
34832
- var typeArguments = (contextFlags & 131072 /* JavaScriptFile */) === 0 ? tryParseTypeArguments() : undefined;
35071
+ var typeArguments = (contextFlags & 262144 /* JavaScriptFile */) === 0 ? tryParseTypeArguments() : undefined;
34833
35072
  var attributes = parseJsxAttributes();
34834
35073
  var node;
34835
35074
  if (token() === 31 /* GreaterThanToken */) {
@@ -35107,7 +35346,7 @@ var ts;
35107
35346
  return result;
35108
35347
  }
35109
35348
  function parseTypeArgumentsInExpression() {
35110
- if ((contextFlags & 131072 /* JavaScriptFile */) !== 0) {
35349
+ if ((contextFlags & 262144 /* JavaScriptFile */) !== 0) {
35111
35350
  // TypeArguments must not be parsed in JavaScript files to avoid ambiguity with binary operators.
35112
35351
  return undefined;
35113
35352
  }
@@ -35503,7 +35742,7 @@ var ts;
35503
35742
  var openParenParsed = parseExpected(20 /* OpenParenToken */);
35504
35743
  var expression = allowInAnd(parseExpression);
35505
35744
  parseExpectedMatchingBrackets(20 /* OpenParenToken */, 21 /* CloseParenToken */, openParenParsed, openParenPosition);
35506
- var statement = doInsideOfContext(16777216 /* InWithStatement */, parseStatement);
35745
+ var statement = doInsideOfContext(33554432 /* InWithStatement */, parseStatement);
35507
35746
  return withJSDoc(finishNode(factory.createWithStatement(expression, statement), pos), hasJSDoc);
35508
35747
  }
35509
35748
  function parseCaseClause() {
@@ -35878,16 +36117,16 @@ var ts;
35878
36117
  if (isAmbient) {
35879
36118
  for (var _i = 0, _a = modifiers; _i < _a.length; _i++) {
35880
36119
  var m = _a[_i];
35881
- m.flags |= 8388608 /* Ambient */;
36120
+ m.flags |= 16777216 /* Ambient */;
35882
36121
  }
35883
- return doInsideOfContext(8388608 /* Ambient */, function () { return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers); });
36122
+ return doInsideOfContext(16777216 /* Ambient */, function () { return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers); });
35884
36123
  }
35885
36124
  else {
35886
36125
  return parseDeclarationWorker(pos, hasJSDoc, decorators, modifiers);
35887
36126
  }
35888
36127
  }
35889
36128
  function tryReuseAmbientDeclaration() {
35890
- return doInsideOfContext(8388608 /* Ambient */, function () {
36129
+ return doInsideOfContext(16777216 /* Ambient */, function () {
35891
36130
  var node = currentNode(parsingContext);
35892
36131
  if (node) {
35893
36132
  return consumeNode(node);
@@ -36354,9 +36593,9 @@ var ts;
36354
36593
  if (isAmbient) {
36355
36594
  for (var _i = 0, _a = modifiers; _i < _a.length; _i++) {
36356
36595
  var m = _a[_i];
36357
- m.flags |= 8388608 /* Ambient */;
36596
+ m.flags |= 16777216 /* Ambient */;
36358
36597
  }
36359
- return doInsideOfContext(8388608 /* Ambient */, function () { return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers); });
36598
+ return doInsideOfContext(16777216 /* Ambient */, function () { return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers); });
36360
36599
  }
36361
36600
  else {
36362
36601
  return parsePropertyOrMethodDeclaration(pos, hasJSDoc, decorators, modifiers);
@@ -36921,7 +37160,7 @@ var ts;
36921
37160
  function parseJSDocTypeExpression(mayOmitBraces) {
36922
37161
  var pos = getNodePos();
36923
37162
  var hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(18 /* OpenBraceToken */);
36924
- var type = doInsideOfContext(4194304 /* JSDoc */, parseJSDocType);
37163
+ var type = doInsideOfContext(8388608 /* JSDoc */, parseJSDocType);
36925
37164
  if (!mayOmitBraces || hasBrace) {
36926
37165
  parseExpectedJSDoc(19 /* CloseBraceToken */);
36927
37166
  }
@@ -36950,7 +37189,7 @@ var ts;
36950
37189
  JSDocParser.parseJSDocNameReference = parseJSDocNameReference;
36951
37190
  function parseIsolatedJSDocComment(content, start, length) {
36952
37191
  initializeState("", content, 99 /* Latest */, /*_syntaxCursor:*/ undefined, 1 /* JS */);
36953
- var jsDoc = doInsideOfContext(4194304 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37192
+ var jsDoc = doInsideOfContext(8388608 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
36954
37193
  var sourceFile = { languageVariant: 0 /* Standard */, text: content };
36955
37194
  var diagnostics = ts.attachFileToDiagnostics(parseDiagnostics, sourceFile);
36956
37195
  clearState();
@@ -36961,9 +37200,9 @@ var ts;
36961
37200
  var saveToken = currentToken;
36962
37201
  var saveParseDiagnosticsLength = parseDiagnostics.length;
36963
37202
  var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
36964
- var comment = doInsideOfContext(4194304 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
37203
+ var comment = doInsideOfContext(8388608 /* JSDoc */, function () { return parseJSDocCommentWorker(start, length); });
36965
37204
  ts.setParent(comment, parent);
36966
- if (contextFlags & 131072 /* JavaScriptFile */) {
37205
+ if (contextFlags & 262144 /* JavaScriptFile */) {
36967
37206
  if (!jsDocDiagnostics) {
36968
37207
  jsDocDiagnostics = [];
36969
37208
  }
@@ -37779,7 +38018,7 @@ var ts;
37779
38018
  if (isBracketed) {
37780
38019
  skipWhitespace();
37781
38020
  parseExpected(63 /* EqualsToken */);
37782
- defaultType = doInsideOfContext(4194304 /* JSDoc */, parseJSDocType);
38021
+ defaultType = doInsideOfContext(8388608 /* JSDoc */, parseJSDocType);
37783
38022
  parseExpected(23 /* CloseBracketToken */);
37784
38023
  }
37785
38024
  if (ts.nodeIsMissing(name)) {
@@ -45667,7 +45906,7 @@ var ts;
45667
45906
  function setExportContextFlag(node) {
45668
45907
  // A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
45669
45908
  // declarations with export modifiers) is an export context in which declarations are implicitly exported.
45670
- if (node.flags & 8388608 /* Ambient */ && !hasExportDeclarations(node)) {
45909
+ if (node.flags & 16777216 /* Ambient */ && !hasExportDeclarations(node)) {
45671
45910
  node.flags |= 64 /* ExportContext */;
45672
45911
  }
45673
45912
  else {
@@ -45870,8 +46109,8 @@ var ts;
45870
46109
  function checkContextualIdentifier(node) {
45871
46110
  // Report error only if there are no parse errors in file
45872
46111
  if (!file.parseDiagnostics.length &&
45873
- !(node.flags & 8388608 /* Ambient */) &&
45874
- !(node.flags & 4194304 /* JSDoc */) &&
46112
+ !(node.flags & 16777216 /* Ambient */) &&
46113
+ !(node.flags & 8388608 /* JSDoc */) &&
45875
46114
  !ts.isIdentifierName(node)) {
45876
46115
  // strict mode identifiers
45877
46116
  if (inStrictMode &&
@@ -46900,7 +47139,7 @@ var ts;
46900
47139
  if (node.kind === 340 /* JSDocParameterTag */ && container.kind !== 323 /* JSDocSignature */) {
46901
47140
  return;
46902
47141
  }
46903
- if (inStrictMode && !(node.flags & 8388608 /* Ambient */)) {
47142
+ if (inStrictMode && !(node.flags & 16777216 /* Ambient */)) {
46904
47143
  // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
46905
47144
  // strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
46906
47145
  checkStrictModeEvalOrArguments(node, node.name);
@@ -46919,7 +47158,7 @@ var ts;
46919
47158
  }
46920
47159
  }
46921
47160
  function bindFunctionDeclaration(node) {
46922
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */)) {
47161
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */)) {
46923
47162
  if (ts.isAsyncFunction(node)) {
46924
47163
  emitFlags |= 2048 /* HasAsyncFunctions */;
46925
47164
  }
@@ -46934,7 +47173,7 @@ var ts;
46934
47173
  }
46935
47174
  }
46936
47175
  function bindFunctionExpression(node) {
46937
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */)) {
47176
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */)) {
46938
47177
  if (ts.isAsyncFunction(node)) {
46939
47178
  emitFlags |= 2048 /* HasAsyncFunctions */;
46940
47179
  }
@@ -46947,7 +47186,7 @@ var ts;
46947
47186
  return bindAnonymousDeclaration(node, 16 /* Function */, bindingName);
46948
47187
  }
46949
47188
  function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
46950
- if (!file.isDeclarationFile && !(node.flags & 8388608 /* Ambient */) && ts.isAsyncFunction(node)) {
47189
+ if (!file.isDeclarationFile && !(node.flags & 16777216 /* Ambient */) && ts.isAsyncFunction(node)) {
46951
47190
  emitFlags |= 2048 /* HasAsyncFunctions */;
46952
47191
  }
46953
47192
  if (currentFlow && ts.isObjectLiteralOrClassExpressionMethodOrAccessor(node)) {
@@ -47020,7 +47259,7 @@ var ts;
47020
47259
  // Rationale: we don't want to report errors on non-initialized var's since they are hoisted
47021
47260
  // On the other side we do want to report errors on non-initialized 'lets' because of TDZ
47022
47261
  var isError_1 = ts.unreachableCodeIsError(options) &&
47023
- !(node.flags & 8388608 /* Ambient */) &&
47262
+ !(node.flags & 16777216 /* Ambient */) &&
47024
47263
  (!ts.isVariableStatement(node) ||
47025
47264
  !!(ts.getCombinedNodeFlags(node.declarationList) & 3 /* BlockScoped */) ||
47026
47265
  node.declarationList.declarations.some(function (d) { return !!d.initializer; }));
@@ -47920,7 +48159,7 @@ var ts;
47920
48159
  ts.Debug.assert(!!(getNodeLinks(file).flags & 1 /* TypeChecked */));
47921
48160
  diagnostics = ts.addRange(diagnostics, suggestionDiagnostics.getDiagnostics(file.fileName));
47922
48161
  checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) {
47923
- if (!ts.containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
48162
+ if (!ts.containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 16777216 /* Ambient */))) {
47924
48163
  (diagnostics || (diagnostics = [])).push(__assign(__assign({}, diag), { category: ts.DiagnosticCategory.Suggestion }));
47925
48164
  }
47926
48165
  });
@@ -48371,7 +48610,7 @@ var ts;
48371
48610
  return diagnostic;
48372
48611
  }
48373
48612
  function isDeprecatedSymbol(symbol) {
48374
- return !!(getDeclarationNodeFlagsFromSymbol(symbol) & 134217728 /* Deprecated */);
48613
+ return !!(getDeclarationNodeFlagsFromSymbol(symbol) & 268435456 /* Deprecated */);
48375
48614
  }
48376
48615
  function addDeprecatedSuggestion(location, declarations, deprecatedEntity) {
48377
48616
  var diagnostic = ts.createDiagnosticForNode(location, ts.Diagnostics._0_is_deprecated, deprecatedEntity);
@@ -48599,7 +48838,7 @@ var ts;
48599
48838
  else {
48600
48839
  // find a module that about to be augmented
48601
48840
  // do not validate names of augmentations that are defined in ambient context
48602
- var moduleNotFoundError = !(moduleName.parent.parent.flags & 8388608 /* Ambient */)
48841
+ var moduleNotFoundError = !(moduleName.parent.parent.flags & 16777216 /* Ambient */)
48603
48842
  ? ts.Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
48604
48843
  : undefined;
48605
48844
  var mainModule_1 = resolveExternalModuleNameWorker(moduleName, moduleName, moduleNotFoundError, /*isForAugmentation*/ true);
@@ -48713,7 +48952,7 @@ var ts;
48713
48952
  if ((moduleKind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
48714
48953
  (!ts.outFile(compilerOptions)) ||
48715
48954
  isInTypeQuery(usage) ||
48716
- declaration.flags & 8388608 /* Ambient */) {
48955
+ declaration.flags & 16777216 /* Ambient */) {
48717
48956
  // nodes are in different files and order cannot be determined
48718
48957
  return true;
48719
48958
  }
@@ -48775,7 +49014,7 @@ var ts;
48775
49014
  if (usage.kind === 271 /* ExportAssignment */ && usage.isExportEquals) {
48776
49015
  return true;
48777
49016
  }
48778
- if (!!(usage.flags & 4194304 /* JSDoc */) || isInTypeQuery(usage) || usageInTypeDeclaration()) {
49017
+ if (!!(usage.flags & 8388608 /* JSDoc */) || isInTypeQuery(usage) || usageInTypeDeclaration()) {
48779
49018
  return true;
48780
49019
  }
48781
49020
  if (isUsedInFunctionOrInstanceProperty(usage, declaration)) {
@@ -49040,7 +49279,7 @@ var ts;
49040
49279
  // falls through
49041
49280
  case 261 /* ModuleDeclaration */:
49042
49281
  var moduleExports = ((_a = getSymbolOfNode(location)) === null || _a === void 0 ? void 0 : _a.exports) || emptySymbols;
49043
- if (location.kind === 305 /* SourceFile */ || (ts.isModuleDeclaration(location) && location.flags & 8388608 /* Ambient */ && !ts.isGlobalScopeAugmentation(location))) {
49282
+ if (location.kind === 305 /* SourceFile */ || (ts.isModuleDeclaration(location) && location.flags & 16777216 /* Ambient */ && !ts.isGlobalScopeAugmentation(location))) {
49044
49283
  // It's an external module. First see if the module has an export default and if the local
49045
49284
  // name of that export default matches.
49046
49285
  if (result = moduleExports.get("default" /* Default */)) {
@@ -49363,7 +49602,7 @@ var ts;
49363
49602
  }
49364
49603
  }
49365
49604
  // If we're in an external module, we can't reference value symbols created from UMD export declarations
49366
- if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 4194304 /* JSDoc */)) {
49605
+ if (result && isInExternalModule && (meaning & 111551 /* Value */) === 111551 /* Value */ && !(originalLocation.flags & 8388608 /* JSDoc */)) {
49367
49606
  var merged = getMergedSymbol(result);
49368
49607
  if (ts.length(merged.declarations) && ts.every(merged.declarations, function (d) { return ts.isNamespaceExportDeclaration(d) || ts.isSourceFile(d) && !!d.symbol.globalExports; })) {
49369
49608
  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));
@@ -49618,7 +49857,7 @@ var ts;
49618
49857
  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 */); });
49619
49858
  if (declaration === undefined)
49620
49859
  return ts.Debug.fail("checkResolvedBlockScopedVariable could not find block-scoped declaration");
49621
- if (!(declaration.flags & 8388608 /* Ambient */) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
49860
+ if (!(declaration.flags & 16777216 /* Ambient */) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
49622
49861
  var diagnosticMessage = void 0;
49623
49862
  var declarationName = ts.declarationNameToString(ts.getNameOfDeclaration(declaration));
49624
49863
  if (result.flags & 2 /* BlockScopedVariable */) {
@@ -50391,7 +50630,7 @@ var ts;
50391
50630
  }
50392
50631
  }
50393
50632
  function getAssignmentDeclarationLocation(node) {
50394
- var typeAlias = ts.findAncestor(node, function (node) { return !(ts.isJSDocNode(node) || node.flags & 4194304 /* JSDoc */) ? "quit" : ts.isJSDocTypeAlias(node); });
50633
+ var typeAlias = ts.findAncestor(node, function (node) { return !(ts.isJSDocNode(node) || node.flags & 8388608 /* JSDoc */) ? "quit" : ts.isJSDocTypeAlias(node); });
50395
50634
  if (typeAlias) {
50396
50635
  return;
50397
50636
  }
@@ -51859,7 +52098,20 @@ var ts;
51859
52098
  if (type.flags & 262144 /* TypeParameter */ || objectFlags & 3 /* ClassOrInterface */) {
51860
52099
  if (type.flags & 262144 /* TypeParameter */ && ts.contains(context.inferTypeParameters, type)) {
51861
52100
  context.approximateLength += (ts.symbolName(type.symbol).length + 6);
51862
- return ts.factory.createInferTypeNode(typeParameterToDeclarationWithConstraint(type, context, /*constraintNode*/ undefined));
52101
+ var constraintNode = void 0;
52102
+ var constraint = getConstraintOfTypeParameter(type);
52103
+ if (constraint) {
52104
+ // If the infer type has a constraint that is not the same as the constraint
52105
+ // we would have normally inferred based on context, we emit the constraint
52106
+ // using `infer T extends ?`. We omit inferred constraints from type references
52107
+ // as they may be elided.
52108
+ var inferredConstraint = getInferredTypeParameterConstraint(type, /*omitTypeReferences*/ true);
52109
+ if (!(inferredConstraint && isTypeIdenticalTo(constraint, inferredConstraint))) {
52110
+ context.approximateLength += 9;
52111
+ constraintNode = constraint && typeToTypeNodeHelper(constraint, context);
52112
+ }
52113
+ }
52114
+ return ts.factory.createInferTypeNode(typeParameterToDeclarationWithConstraint(type, context, constraintNode));
51863
52115
  }
51864
52116
  if (context.flags & 4 /* GenerateNamesForShadowedTypeParams */ &&
51865
52117
  type.flags & 262144 /* TypeParameter */ &&
@@ -53815,7 +54067,7 @@ var ts;
53815
54067
  newModifierFlags |= 1 /* Export */;
53816
54068
  }
53817
54069
  if (addingDeclare && !(newModifierFlags & 1 /* Export */) &&
53818
- (!enclosingDeclaration_1 || !(enclosingDeclaration_1.flags & 8388608 /* Ambient */)) &&
54070
+ (!enclosingDeclaration_1 || !(enclosingDeclaration_1.flags & 16777216 /* Ambient */)) &&
53819
54071
  (ts.isEnumDeclaration(node) || ts.isVariableStatement(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isModuleDeclaration(node))) {
53820
54072
  // Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope
53821
54073
  newModifierFlags |= 2 /* Ambient */;
@@ -54785,7 +55037,7 @@ var ts;
54785
55037
  var parent = getDeclarationContainer(node);
54786
55038
  // If the node is not exported or it is not ambient module element (except import declaration)
54787
55039
  if (!(ts.getCombinedModifierFlags(node) & 1 /* Export */) &&
54788
- !(node.kind !== 265 /* ImportEqualsDeclaration */ && parent.kind !== 305 /* SourceFile */ && parent.flags & 8388608 /* Ambient */)) {
55040
+ !(node.kind !== 265 /* ImportEqualsDeclaration */ && parent.kind !== 305 /* SourceFile */ && parent.flags & 16777216 /* Ambient */)) {
54789
55041
  return isGlobalSourceFile(parent);
54790
55042
  }
54791
55043
  // Exported members/ambient module elements (exception import declaration) are visible if parent is visible
@@ -55125,7 +55377,7 @@ var ts;
55125
55377
  }
55126
55378
  var pattern = declaration.parent;
55127
55379
  // Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
55128
- if (strictNullChecks && declaration.flags & 8388608 /* Ambient */ && ts.isParameterDeclaration(declaration)) {
55380
+ if (strictNullChecks && declaration.flags & 16777216 /* Ambient */ && ts.isParameterDeclaration(declaration)) {
55129
55381
  parentType = getNonNullableType(parentType);
55130
55382
  }
55131
55383
  // Filter `undefined` from the type we check against if the parent has an initializer and that initializer is not possibly `undefined`
@@ -55241,7 +55493,7 @@ var ts;
55241
55493
  }
55242
55494
  if ((noImplicitAny || ts.isInJSFile(declaration)) &&
55243
55495
  ts.isVariableDeclaration(declaration) && !ts.isBindingPattern(declaration.name) &&
55244
- !(ts.getCombinedModifierFlags(declaration) & 1 /* Export */) && !(declaration.flags & 8388608 /* Ambient */)) {
55496
+ !(ts.getCombinedModifierFlags(declaration) & 1 /* Export */) && !(declaration.flags & 16777216 /* Ambient */)) {
55245
55497
  // If --noImplicitAny is on or the declaration is in a Javascript file,
55246
55498
  // use control flow tracked 'any' type for non-ambient, non-exported var or let variables with no
55247
55499
  // initializer or a 'null' or 'undefined' initializer.
@@ -56697,7 +56949,7 @@ var ts;
56697
56949
  function isLiteralEnumMember(member) {
56698
56950
  var expr = member.initializer;
56699
56951
  if (!expr) {
56700
- return !(member.flags & 8388608 /* Ambient */);
56952
+ return !(member.flags & 16777216 /* Ambient */);
56701
56953
  }
56702
56954
  switch (expr.kind) {
56703
56955
  case 10 /* StringLiteral */:
@@ -59330,7 +59582,7 @@ var ts;
59330
59582
  function getConstraintDeclaration(type) {
59331
59583
  return ts.mapDefined(ts.filter(type.symbol && type.symbol.declarations, ts.isTypeParameterDeclaration), ts.getEffectiveConstraintOfTypeParameter)[0];
59332
59584
  }
59333
- function getInferredTypeParameterConstraint(typeParameter) {
59585
+ function getInferredTypeParameterConstraint(typeParameter, omitTypeReferences) {
59334
59586
  var _a;
59335
59587
  var inferences;
59336
59588
  if ((_a = typeParameter.symbol) === null || _a === void 0 ? void 0 : _a.declarations) {
@@ -59342,7 +59594,7 @@ var ts;
59342
59594
  // corresponding type parameter in 'Foo'. When multiple 'infer T' declarations are
59343
59595
  // present, we form an intersection of the inferred constraint types.
59344
59596
  var _c = ts.walkUpParenthesizedTypesAndGetParentAndChild(declaration.parent.parent), _d = _c[0], childTypeParameter = _d === void 0 ? declaration.parent : _d, grandParent = _c[1];
59345
- if (grandParent.kind === 178 /* TypeReference */) {
59597
+ if (grandParent.kind === 178 /* TypeReference */ && !omitTypeReferences) {
59346
59598
  var typeReference = grandParent;
59347
59599
  var typeParameters = getTypeParametersForTypeReference(typeReference);
59348
59600
  if (typeParameters) {
@@ -59764,7 +60016,7 @@ var ts;
59764
60016
  return constraints ? getSubstitutionType(type, getIntersectionType(ts.append(constraints, type))) : type;
59765
60017
  }
59766
60018
  function isJSDocTypeReference(node) {
59767
- return !!(node.flags & 4194304 /* JSDoc */) && (node.kind === 178 /* TypeReference */ || node.kind === 200 /* ImportType */);
60019
+ return !!(node.flags & 8388608 /* JSDoc */) && (node.kind === 178 /* TypeReference */ || node.kind === 200 /* ImportType */);
59768
60020
  }
59769
60021
  function checkNoTypeArguments(node, symbol) {
59770
60022
  if (node.typeArguments) {
@@ -61323,7 +61575,7 @@ var ts;
61323
61575
  if (ts.isCallLikeExpression(parent)) {
61324
61576
  return ts.isCallOrNewExpression(parent) && ts.isIdentifier(node) && hasMatchingArgument(parent, node);
61325
61577
  }
61326
- return ts.every(symbol.declarations, function (d) { return !ts.isFunctionLike(d) || !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); });
61578
+ return ts.every(symbol.declarations, function (d) { return !ts.isFunctionLike(d) || !!(ts.getCombinedNodeFlags(d) & 268435456 /* Deprecated */); });
61327
61579
  }
61328
61580
  return true;
61329
61581
  }
@@ -61764,7 +62016,11 @@ var ts;
61764
62016
  return !root.isDistributive && isSingletonTupleType(root.node.checkType) && isSingletonTupleType(root.node.extendsType);
61765
62017
  }
61766
62018
  function isSingletonTupleType(node) {
61767
- return ts.isTupleTypeNode(node) && ts.length(node.elements) === 1 && !ts.isOptionalTypeNode(node.elements[0]) && !ts.isRestTypeNode(node.elements[0]);
62019
+ return ts.isTupleTypeNode(node) &&
62020
+ ts.length(node.elements) === 1 &&
62021
+ !ts.isOptionalTypeNode(node.elements[0]) &&
62022
+ !ts.isRestTypeNode(node.elements[0]) &&
62023
+ !(ts.isNamedTupleMember(node.elements[0]) && (node.elements[0].questionToken || node.elements[0].dotDotDotToken));
61768
62024
  }
61769
62025
  /**
61770
62026
  * We syntactually check for common nondistributive conditional shapes and unwrap them into
@@ -62012,7 +62268,7 @@ var ts;
62012
62268
  links.resolvedSymbol = unknownSymbol;
62013
62269
  return links.resolvedType = errorType;
62014
62270
  }
62015
- var targetMeaning = node.isTypeOf ? 111551 /* Value */ : node.flags & 4194304 /* JSDoc */ ? 111551 /* Value */ | 788968 /* Type */ : 788968 /* Type */;
62271
+ var targetMeaning = node.isTypeOf ? 111551 /* Value */ : node.flags & 8388608 /* JSDoc */ ? 111551 /* Value */ | 788968 /* Type */ : 788968 /* Type */;
62016
62272
  // TODO: Future work: support unions/generics/whatever via a deferred import-type
62017
62273
  var innerModuleSymbol = resolveExternalModuleName(node, node.argument.literal);
62018
62274
  if (!innerModuleSymbol) {
@@ -62348,7 +62604,7 @@ var ts;
62348
62604
  }
62349
62605
  // /** @return {this} */
62350
62606
  // x.prototype.m = function() { ... }
62351
- var host = node.flags & 4194304 /* JSDoc */ ? ts.getHostSignatureFromJSDoc(node) : undefined;
62607
+ var host = node.flags & 8388608 /* JSDoc */ ? ts.getHostSignatureFromJSDoc(node) : undefined;
62352
62608
  if (host && ts.isFunctionExpression(host) && ts.isBinaryExpression(host.parent) && ts.getAssignmentDeclarationKind(host.parent) === 3 /* PrototypeProperty */) {
62353
62609
  return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(host.parent.left).parent).thisType;
62354
62610
  }
@@ -62423,7 +62679,7 @@ var ts;
62423
62679
  case 143 /* NeverKeyword */:
62424
62680
  return neverType;
62425
62681
  case 148 /* ObjectKeyword */:
62426
- return node.flags & 131072 /* JavaScriptFile */ && !noImplicitAny ? anyType : nonPrimitiveType;
62682
+ return node.flags & 262144 /* JavaScriptFile */ && !noImplicitAny ? anyType : nonPrimitiveType;
62427
62683
  case 138 /* IntrinsicKeyword */:
62428
62684
  return intrinsicMarkerType;
62429
62685
  case 192 /* ThisType */:
@@ -66284,6 +66540,9 @@ var ts;
66284
66540
  function createMarkerType(symbol, source, target) {
66285
66541
  var mapper = makeUnaryTypeMapper(source, target);
66286
66542
  var type = getDeclaredTypeOfSymbol(symbol);
66543
+ if (isErrorType(type)) {
66544
+ return type;
66545
+ }
66287
66546
  var result = symbol.flags & 524288 /* TypeAlias */ ?
66288
66547
  getTypeAliasInstantiation(symbol, instantiateTypes(getSymbolLinks(symbol).typeParameters, mapper)) :
66289
66548
  createTypeReference(type, instantiateTypes(type.typeParameters, mapper));
@@ -67297,6 +67556,9 @@ var ts;
67297
67556
  var inference = inferences[i];
67298
67557
  if (t === inference.typeParameter) {
67299
67558
  if (fix && !inference.isFixed) {
67559
+ // Before we commit to a particular inference (and thus lock out any further inferences),
67560
+ // we infer from any intra-expression inference sites we have collected.
67561
+ inferFromIntraExpressionSites(context);
67300
67562
  clearCachedInferences(inferences);
67301
67563
  inference.isFixed = true;
67302
67564
  }
@@ -67313,6 +67575,37 @@ var ts;
67313
67575
  }
67314
67576
  }
67315
67577
  }
67578
+ function addIntraExpressionInferenceSite(context, node, type) {
67579
+ var _a;
67580
+ ((_a = context.intraExpressionInferenceSites) !== null && _a !== void 0 ? _a : (context.intraExpressionInferenceSites = [])).push({ node: node, type: type });
67581
+ }
67582
+ // We collect intra-expression inference sites within object and array literals to handle cases where
67583
+ // inferred types flow between context sensitive element expressions. For example:
67584
+ //
67585
+ // declare function foo<T>(arg: [(n: number) => T, (x: T) => void]): void;
67586
+ // foo([_a => 0, n => n.toFixed()]);
67587
+ //
67588
+ // Above, both arrow functions in the tuple argument are context sensitive, thus both are omitted from the
67589
+ // pass that collects inferences from the non-context sensitive parts of the arguments. In the subsequent
67590
+ // pass where nothing is omitted, we need to commit to an inference for T in order to contextually type the
67591
+ // parameter in the second arrow function, but we want to first infer from the return type of the first
67592
+ // arrow function. This happens automatically when the arrow functions are discrete arguments (because we
67593
+ // infer from each argument before processing the next), but when the arrow functions are elements of an
67594
+ // object or array literal, we need to perform intra-expression inferences early.
67595
+ function inferFromIntraExpressionSites(context) {
67596
+ if (context.intraExpressionInferenceSites) {
67597
+ for (var _i = 0, _a = context.intraExpressionInferenceSites; _i < _a.length; _i++) {
67598
+ var _b = _a[_i], node = _b.node, type = _b.type;
67599
+ var contextualType = node.kind === 169 /* MethodDeclaration */ ?
67600
+ getContextualTypeForObjectLiteralMethod(node, 2 /* NoConstraints */) :
67601
+ getContextualType(node, 2 /* NoConstraints */);
67602
+ if (contextualType) {
67603
+ inferTypes(context.inferences, type, contextualType);
67604
+ }
67605
+ }
67606
+ context.intraExpressionInferenceSites = undefined;
67607
+ }
67608
+ }
67316
67609
  function createInferenceInfo(typeParameter) {
67317
67610
  return {
67318
67611
  typeParameter: typeParameter,
@@ -69295,7 +69588,7 @@ var ts;
69295
69588
  // parameter symbols with declarations that have explicit type annotations. Such references are
69296
69589
  // resolvable with no possibility of triggering circularities in control flow analysis.
69297
69590
  function getTypeOfDottedName(node, diagnostic) {
69298
- if (!(node.flags & 16777216 /* InWithStatement */)) {
69591
+ if (!(node.flags & 33554432 /* InWithStatement */)) {
69299
69592
  switch (node.kind) {
69300
69593
  case 79 /* Identifier */:
69301
69594
  var symbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(node));
@@ -70699,6 +70992,7 @@ var ts;
70699
70992
  // a generic type without a nullable constraint and x is a generic type. This is because when both obj
70700
70993
  // and x are of generic types T and K, we want the resulting type to be T[K].
70701
70994
  return parent.kind === 206 /* PropertyAccessExpression */ ||
70995
+ parent.kind === 161 /* QualifiedName */ ||
70702
70996
  parent.kind === 208 /* CallExpression */ && parent.expression === node ||
70703
70997
  parent.kind === 207 /* ElementAccessExpression */ && parent.expression === node &&
70704
70998
  !(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression(parent.argumentExpression)));
@@ -70992,7 +71286,7 @@ var ts;
70992
71286
  isInTypeQuery(node) || node.parent.kind === 275 /* ExportSpecifier */) ||
70993
71287
  node.parent.kind === 230 /* NonNullExpression */ ||
70994
71288
  declaration.kind === 254 /* VariableDeclaration */ && declaration.exclamationToken ||
70995
- declaration.flags & 8388608 /* Ambient */;
71289
+ declaration.flags & 16777216 /* Ambient */;
70996
71290
  var initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration) : type) :
70997
71291
  type === autoType || type === autoArrayType ? undefinedType :
70998
71292
  getOptionalType(type);
@@ -72000,7 +72294,7 @@ var ts;
72000
72294
  // exists. Otherwise, it is the type of the string index signature in T, if one exists.
72001
72295
  function getContextualTypeForObjectLiteralMethod(node, contextFlags) {
72002
72296
  ts.Debug.assert(ts.isObjectLiteralMethod(node));
72003
- if (node.flags & 16777216 /* InWithStatement */) {
72297
+ if (node.flags & 33554432 /* InWithStatement */) {
72004
72298
  // We cannot answer semantic questions within a with block, do not proceed any further
72005
72299
  return undefined;
72006
72300
  }
@@ -72188,7 +72482,7 @@ var ts;
72188
72482
  * @returns the contextual type of an expression.
72189
72483
  */
72190
72484
  function getContextualType(node, contextFlags) {
72191
- if (node.flags & 16777216 /* InWithStatement */) {
72485
+ if (node.flags & 33554432 /* InWithStatement */) {
72192
72486
  // We cannot answer semantic questions within a with block, do not proceed any further
72193
72487
  return undefined;
72194
72488
  }
@@ -72606,6 +72900,11 @@ var ts;
72606
72900
  var type = checkExpressionForMutableLocation(e, checkMode, elementContextualType, forceTuple);
72607
72901
  elementTypes.push(addOptionality(type, /*isProperty*/ true, hasOmittedExpression));
72608
72902
  elementFlags.push(hasOmittedExpression ? 2 /* Optional */ : 1 /* Required */);
72903
+ if (contextualType && someType(contextualType, isTupleLikeType) && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) && isContextSensitive(e)) {
72904
+ var inferenceContext = getInferenceContext(node);
72905
+ ts.Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context
72906
+ addIntraExpressionInferenceSite(inferenceContext, e, type);
72907
+ }
72609
72908
  }
72610
72909
  }
72611
72910
  if (inDestructuringPattern) {
@@ -72807,6 +73106,13 @@ var ts;
72807
73106
  prop.target = member;
72808
73107
  member = prop;
72809
73108
  allPropertiesTable === null || allPropertiesTable === void 0 ? void 0 : allPropertiesTable.set(prop.escapedName, prop);
73109
+ if (contextualType && checkMode && checkMode & 2 /* Inferential */ && !(checkMode & 4 /* SkipContextSensitive */) &&
73110
+ (memberDecl.kind === 296 /* PropertyAssignment */ || memberDecl.kind === 169 /* MethodDeclaration */) && isContextSensitive(memberDecl)) {
73111
+ var inferenceContext = getInferenceContext(node);
73112
+ ts.Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context
73113
+ var inferenceNode = memberDecl.kind === 296 /* PropertyAssignment */ ? memberDecl.initializer : memberDecl;
73114
+ addIntraExpressionInferenceSite(inferenceContext, inferenceNode, type);
73115
+ }
72810
73116
  }
72811
73117
  else if (memberDecl.kind === 298 /* SpreadAssignment */) {
72812
73118
  if (languageVersion < 2 /* ES2015 */) {
@@ -73899,7 +74205,7 @@ var ts;
73899
74205
  if (compilerOptions.noPropertyAccessFromIndexSignature && ts.isPropertyAccessExpression(node)) {
73900
74206
  error(right, ts.Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, ts.unescapeLeadingUnderscores(right.escapedText));
73901
74207
  }
73902
- if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 134217728 /* Deprecated */) {
74208
+ if (indexInfo.declaration && ts.getCombinedNodeFlags(indexInfo.declaration) & 268435456 /* Deprecated */) {
73903
74209
  addDeprecatedSuggestion(right, [indexInfo.declaration], right.escapedText);
73904
74210
  }
73905
74211
  }
@@ -73967,7 +74273,7 @@ var ts;
73967
74273
  if (declaration && isPropertyWithoutInitializer(declaration)) {
73968
74274
  if (!ts.isStatic(declaration)) {
73969
74275
  var flowContainer = getControlFlowContainer(node);
73970
- if (flowContainer.kind === 171 /* Constructor */ && flowContainer.parent === declaration.parent && !(declaration.flags & 8388608 /* Ambient */)) {
74276
+ if (flowContainer.kind === 171 /* Constructor */ && flowContainer.parent === declaration.parent && !(declaration.flags & 16777216 /* Ambient */)) {
73971
74277
  assumeUninitialized = true;
73972
74278
  }
73973
74279
  }
@@ -74004,7 +74310,7 @@ var ts;
74004
74310
  }
74005
74311
  else if (valueDeclaration.kind === 257 /* ClassDeclaration */ &&
74006
74312
  node.parent.kind !== 178 /* TypeReference */ &&
74007
- !(valueDeclaration.flags & 8388608 /* Ambient */) &&
74313
+ !(valueDeclaration.flags & 16777216 /* Ambient */) &&
74008
74314
  !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)) {
74009
74315
  diagnosticMessage = error(right, ts.Diagnostics.Class_0_used_before_its_declaration, declarationName);
74010
74316
  }
@@ -74669,34 +74975,36 @@ var ts;
74669
74975
  if (node.kind !== 165 /* Decorator */) {
74670
74976
  var contextualType = getContextualType(node, ts.every(signature.typeParameters, function (p) { return !!getDefaultFromTypeParameter(p); }) ? 8 /* SkipBindingPatterns */ : 0 /* None */);
74671
74977
  if (contextualType) {
74672
- // We clone the inference context to avoid disturbing a resolution in progress for an
74673
- // outer call expression. Effectively we just want a snapshot of whatever has been
74674
- // inferred for any outer call expression so far.
74675
- var outerContext = getInferenceContext(node);
74676
- var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
74677
- var instantiatedType = instantiateType(contextualType, outerMapper);
74678
- // If the contextual type is a generic function type with a single call signature, we
74679
- // instantiate the type with its own type parameters and type arguments. This ensures that
74680
- // the type parameters are not erased to type any during type inference such that they can
74681
- // be inferred as actual types from the contextual type. For example:
74682
- // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
74683
- // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
74684
- // Above, the type of the 'value' parameter is inferred to be 'A'.
74685
- var contextualSignature = getSingleCallSignature(instantiatedType);
74686
- var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
74687
- getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
74688
- instantiatedType;
74689
74978
  var inferenceTargetType = getReturnTypeOfSignature(signature);
74690
- // Inferences made from return types have lower priority than all other inferences.
74691
- inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
74692
- // Create a type mapper for instantiating generic contextual types using the inferences made
74693
- // from the return type. We need a separate inference pass here because (a) instantiation of
74694
- // the source type uses the outer context's return mapper (which excludes inferences made from
74695
- // outer arguments), and (b) we don't want any further inferences going into this context.
74696
- var returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
74697
- var returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
74698
- inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
74699
- context.returnMapper = ts.some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : undefined;
74979
+ if (couldContainTypeVariables(inferenceTargetType)) {
74980
+ // We clone the inference context to avoid disturbing a resolution in progress for an
74981
+ // outer call expression. Effectively we just want a snapshot of whatever has been
74982
+ // inferred for any outer call expression so far.
74983
+ var outerContext = getInferenceContext(node);
74984
+ var outerMapper = getMapperFromContext(cloneInferenceContext(outerContext, 1 /* NoDefault */));
74985
+ var instantiatedType = instantiateType(contextualType, outerMapper);
74986
+ // If the contextual type is a generic function type with a single call signature, we
74987
+ // instantiate the type with its own type parameters and type arguments. This ensures that
74988
+ // the type parameters are not erased to type any during type inference such that they can
74989
+ // be inferred as actual types from the contextual type. For example:
74990
+ // declare function arrayMap<T, U>(f: (x: T) => U): (a: T[]) => U[];
74991
+ // const boxElements: <A>(a: A[]) => { value: A }[] = arrayMap(value => ({ value }));
74992
+ // Above, the type of the 'value' parameter is inferred to be 'A'.
74993
+ var contextualSignature = getSingleCallSignature(instantiatedType);
74994
+ var inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
74995
+ getOrCreateTypeFromSignature(getSignatureInstantiationWithoutFillingInTypeArguments(contextualSignature, contextualSignature.typeParameters)) :
74996
+ instantiatedType;
74997
+ // Inferences made from return types have lower priority than all other inferences.
74998
+ inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, 128 /* ReturnType */);
74999
+ // Create a type mapper for instantiating generic contextual types using the inferences made
75000
+ // from the return type. We need a separate inference pass here because (a) instantiation of
75001
+ // the source type uses the outer context's return mapper (which excludes inferences made from
75002
+ // outer arguments), and (b) we don't want any further inferences going into this context.
75003
+ var returnContext = createInferenceContext(signature.typeParameters, signature, context.flags);
75004
+ var returnSourceType = instantiateType(contextualType, outerContext && outerContext.returnMapper);
75005
+ inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);
75006
+ context.returnMapper = ts.some(returnContext.inferences, hasInferenceCandidates) ? getMapperFromContext(cloneInferredPartOfContext(returnContext)) : undefined;
75007
+ }
74700
75008
  }
74701
75009
  }
74702
75010
  var restType = getNonArrayRestType(signature);
@@ -74708,7 +75016,7 @@ var ts;
74708
75016
  }
74709
75017
  }
74710
75018
  var thisType = getThisTypeOfSignature(signature);
74711
- if (thisType) {
75019
+ if (thisType && couldContainTypeVariables(thisType)) {
74712
75020
  var thisArgumentNode = getThisArgumentOfCall(node);
74713
75021
  inferTypes(context.inferences, getThisArgumentType(thisArgumentNode), thisType);
74714
75022
  }
@@ -74716,11 +75024,13 @@ var ts;
74716
75024
  var arg = args[i];
74717
75025
  if (arg.kind !== 227 /* OmittedExpression */ && !(checkMode & 32 /* IsForStringLiteralArgumentCompletions */ && hasSkipDirectInferenceFlag(arg))) {
74718
75026
  var paramType = getTypeAtPosition(signature, i);
74719
- var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
74720
- inferTypes(context.inferences, argType, paramType);
75027
+ if (couldContainTypeVariables(paramType)) {
75028
+ var argType = checkExpressionWithContextualType(arg, paramType, context, checkMode);
75029
+ inferTypes(context.inferences, argType, paramType);
75030
+ }
74721
75031
  }
74722
75032
  }
74723
- if (restType) {
75033
+ if (restType && couldContainTypeVariables(restType)) {
74724
75034
  var spreadType = getSpreadArgumentType(args, argCount, args.length, restType, context, checkMode);
74725
75035
  inferTypes(context.inferences, spreadType, restType);
74726
75036
  }
@@ -76300,7 +76610,7 @@ var ts;
76300
76610
  return returnType;
76301
76611
  }
76302
76612
  function checkDeprecatedSignature(signature, node) {
76303
- if (signature.declaration && signature.declaration.flags & 134217728 /* Deprecated */) {
76613
+ if (signature.declaration && signature.declaration.flags & 268435456 /* Deprecated */) {
76304
76614
  var suggestionNode = getDeprecatedSuggestionNode(node);
76305
76615
  var name = ts.tryGetPropertyAccessOrIdentifierToString(ts.getInvokedExpression(node));
76306
76616
  addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name, signatureToString(signature));
@@ -76444,7 +76754,7 @@ var ts;
76444
76754
  if (targetDeclarationKind !== 0 /* Unknown */) {
76445
76755
  var decl = ts.getDeclarationOfKind(resolvedRequire, targetDeclarationKind);
76446
76756
  // function/variable declaration should be ambient
76447
- return !!decl && !!(decl.flags & 8388608 /* Ambient */);
76757
+ return !!decl && !!(decl.flags & 16777216 /* Ambient */);
76448
76758
  }
76449
76759
  return false;
76450
76760
  }
@@ -76639,7 +76949,7 @@ var ts;
76639
76949
  error(node, ts.Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext);
76640
76950
  }
76641
76951
  var file = ts.getSourceFileOfNode(node);
76642
- ts.Debug.assert(!!(file.flags & 2097152 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
76952
+ ts.Debug.assert(!!(file.flags & 4194304 /* PossiblyContainsImportMeta */), "Containing file is missing import meta node flag.");
76643
76953
  return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
76644
76954
  }
76645
76955
  function getTypeOfParameter(symbol) {
@@ -78653,6 +78963,11 @@ var ts;
78653
78963
  context.contextualType = contextualType;
78654
78964
  context.inferenceContext = inferenceContext;
78655
78965
  var type = checkExpression(node, checkMode | 1 /* Contextual */ | (inferenceContext ? 2 /* Inferential */ : 0));
78966
+ // In CheckMode.Inferential we collect intra-expression inference sites to process before fixing any type
78967
+ // parameters. This information is no longer needed after the call to checkExpression.
78968
+ if (inferenceContext && inferenceContext.intraExpressionInferenceSites) {
78969
+ inferenceContext.intraExpressionInferenceSites = undefined;
78970
+ }
78656
78971
  // We strip literal freshness when an appropriate contextual type is present such that contextually typed
78657
78972
  // literals always preserve their literal types (otherwise they might widen during type inference). An alternative
78658
78973
  // here would be to not mark contextually typed literals as fresh in the first place.
@@ -78944,7 +79259,7 @@ var ts;
78944
79259
  return quickType;
78945
79260
  }
78946
79261
  // If a type has been cached for the node, return it.
78947
- if (node.flags & 67108864 /* TypeCached */ && flowTypeCache) {
79262
+ if (node.flags & 134217728 /* TypeCached */ && flowTypeCache) {
78948
79263
  var cachedType = flowTypeCache[getNodeId(node)];
78949
79264
  if (cachedType) {
78950
79265
  return cachedType;
@@ -78956,7 +79271,7 @@ var ts;
78956
79271
  if (flowInvocationCount !== startInvocationCount) {
78957
79272
  var cache = flowTypeCache || (flowTypeCache = []);
78958
79273
  cache[getNodeId(node)] = type;
78959
- ts.setNodeFlags(node, node.flags | 67108864 /* TypeCached */);
79274
+ ts.setNodeFlags(node, node.flags | 134217728 /* TypeCached */);
78960
79275
  }
78961
79276
  return type;
78962
79277
  }
@@ -79042,7 +79357,7 @@ var ts;
79042
79357
  if (compilerOptions.isolatedModules) {
79043
79358
  ts.Debug.assert(!!(type.symbol.flags & 128 /* ConstEnum */));
79044
79359
  var constEnumDeclaration = type.symbol.valueDeclaration;
79045
- if (constEnumDeclaration.flags & 8388608 /* Ambient */) {
79360
+ if (constEnumDeclaration.flags & 16777216 /* Ambient */) {
79046
79361
  error(node, ts.Diagnostics.Cannot_access_ambient_const_enums_when_the_isolatedModules_flag_is_provided);
79047
79362
  }
79048
79363
  }
@@ -79735,7 +80050,7 @@ var ts;
79735
80050
  checkDecorators(node);
79736
80051
  checkSignatureDeclaration(node);
79737
80052
  if (node.kind === 172 /* GetAccessor */) {
79738
- if (!(node.flags & 8388608 /* Ambient */) && ts.nodeIsPresent(node.body) && (node.flags & 256 /* HasImplicitReturn */)) {
80053
+ if (!(node.flags & 16777216 /* Ambient */) && ts.nodeIsPresent(node.body) && (node.flags & 256 /* HasImplicitReturn */)) {
79739
80054
  if (!(node.flags & 512 /* HasExplicitReturn */)) {
79740
80055
  error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value);
79741
80056
  }
@@ -79830,7 +80145,7 @@ var ts;
79830
80145
  }
79831
80146
  var symbol = getNodeLinks(node).resolvedSymbol;
79832
80147
  if (symbol) {
79833
- if (ts.some(symbol.declarations, function (d) { return isTypeDeclaration(d) && !!(d.flags & 134217728 /* Deprecated */); })) {
80148
+ if (ts.some(symbol.declarations, function (d) { return isTypeDeclaration(d) && !!(d.flags & 268435456 /* Deprecated */); })) {
79834
80149
  addDeprecatedSuggestion(getDeprecatedSuggestionNode(node), symbol.declarations, symbol.escapedName);
79835
80150
  }
79836
80151
  if (type.flags & 32 /* Enum */ && symbol.flags & 8 /* EnumMember */) {
@@ -79990,6 +80305,23 @@ var ts;
79990
80305
  grammarErrorOnNode(node, ts.Diagnostics.infer_declarations_are_only_permitted_in_the_extends_clause_of_a_conditional_type);
79991
80306
  }
79992
80307
  checkSourceElement(node.typeParameter);
80308
+ var symbol = getSymbolOfNode(node.typeParameter);
80309
+ if (symbol.declarations && symbol.declarations.length > 1) {
80310
+ var links = getSymbolLinks(symbol);
80311
+ if (!links.typeParametersChecked) {
80312
+ links.typeParametersChecked = true;
80313
+ var typeParameter = getDeclaredTypeOfTypeParameter(symbol);
80314
+ var declarations = ts.getDeclarationsOfKind(symbol, 163 /* TypeParameter */);
80315
+ if (!areTypeParametersIdentical(declarations, [typeParameter], function (decl) { return [decl]; })) {
80316
+ // Report an error on every conflicting declaration.
80317
+ var name = symbolToString(symbol);
80318
+ for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
80319
+ var declaration = declarations_4[_i];
80320
+ error(declaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_constraints, name);
80321
+ }
80322
+ }
80323
+ }
80324
+ }
79993
80325
  registerForUnusedIdentifiersCheck(node);
79994
80326
  }
79995
80327
  function checkTemplateLiteralType(node) {
@@ -80027,7 +80359,7 @@ var ts;
80027
80359
  getTypeFromTypeNode(node);
80028
80360
  }
80029
80361
  function isPrivateWithinAmbient(node) {
80030
- return (ts.hasEffectiveModifier(node, 8 /* Private */) || ts.isPrivateIdentifierClassElementDeclaration(node)) && !!(node.flags & 8388608 /* Ambient */);
80362
+ return (ts.hasEffectiveModifier(node, 8 /* Private */) || ts.isPrivateIdentifierClassElementDeclaration(node)) && !!(node.flags & 16777216 /* Ambient */);
80031
80363
  }
80032
80364
  function getEffectiveDeclarationFlags(n, flagsToCheck) {
80033
80365
  var flags = ts.getCombinedModifierFlags(n);
@@ -80036,7 +80368,7 @@ var ts;
80036
80368
  if (n.parent.kind !== 258 /* InterfaceDeclaration */ &&
80037
80369
  n.parent.kind !== 257 /* ClassDeclaration */ &&
80038
80370
  n.parent.kind !== 226 /* ClassExpression */ &&
80039
- n.flags & 8388608 /* Ambient */) {
80371
+ n.flags & 16777216 /* Ambient */) {
80040
80372
  if (!(flags & 2 /* Ambient */) && !(ts.isModuleBlock(n.parent) && ts.isModuleDeclaration(n.parent.parent) && ts.isGlobalScopeAugmentation(n.parent.parent))) {
80041
80373
  // It is nested in an ambient context, which means it is automatically exported
80042
80374
  flags |= 1 /* Export */;
@@ -80169,10 +80501,10 @@ var ts;
80169
80501
  var hasNonAmbientClass = false;
80170
80502
  var functionDeclarations = [];
80171
80503
  if (declarations) {
80172
- for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
80173
- var current = declarations_4[_i];
80504
+ for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) {
80505
+ var current = declarations_5[_i];
80174
80506
  var node = current;
80175
- var inAmbientContext = node.flags & 8388608 /* Ambient */;
80507
+ var inAmbientContext = node.flags & 16777216 /* Ambient */;
80176
80508
  var inAmbientContextOrInterface = node.parent && (node.parent.kind === 258 /* InterfaceDeclaration */ || node.parent.kind === 182 /* TypeLiteral */) || inAmbientContext;
80177
80509
  if (inAmbientContextOrInterface) {
80178
80510
  // check if declarations are consecutive only if they are non-ambient
@@ -81024,7 +81356,7 @@ var ts;
81024
81356
  // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function.
81025
81357
  var firstDeclaration = (_a = localSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(
81026
81358
  // Get first non javascript function declaration
81027
- function (declaration) { return declaration.kind === node.kind && !(declaration.flags & 131072 /* JavaScriptFile */); });
81359
+ function (declaration) { return declaration.kind === node.kind && !(declaration.flags & 262144 /* JavaScriptFile */); });
81028
81360
  // Only type check the symbol once
81029
81361
  if (node === firstDeclaration) {
81030
81362
  checkFunctionOrConstructorSymbol(localSymbol);
@@ -81146,7 +81478,7 @@ var ts;
81146
81478
  var symbol = getSymbolOfNode(member);
81147
81479
  if (!symbol.isReferenced
81148
81480
  && (ts.hasEffectiveModifier(member, 8 /* Private */) || ts.isNamedDeclaration(member) && ts.isPrivateIdentifier(member.name))
81149
- && !(member.flags & 8388608 /* Ambient */)) {
81481
+ && !(member.flags & 16777216 /* Ambient */)) {
81150
81482
  addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol)));
81151
81483
  }
81152
81484
  break;
@@ -81336,8 +81668,8 @@ var ts;
81336
81668
  : ts.createDiagnosticForNode(declarationList.parent.kind === 237 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused));
81337
81669
  }
81338
81670
  else {
81339
- for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) {
81340
- var decl = declarations_5[_i];
81671
+ for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
81672
+ var decl = declarations_6[_i];
81341
81673
  addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(decl.name)));
81342
81674
  }
81343
81675
  }
@@ -81379,7 +81711,7 @@ var ts;
81379
81711
  }
81380
81712
  function checkCollisionWithArgumentsInGeneratedCode(node) {
81381
81713
  // no rest parameters \ declaration context \ overload - no codegen impact
81382
- if (languageVersion >= 2 /* ES2015 */ || !ts.hasRestParameter(node) || node.flags & 8388608 /* Ambient */ || ts.nodeIsMissing(node.body)) {
81714
+ if (languageVersion >= 2 /* ES2015 */ || !ts.hasRestParameter(node) || node.flags & 16777216 /* Ambient */ || ts.nodeIsMissing(node.body)) {
81383
81715
  return;
81384
81716
  }
81385
81717
  ts.forEach(node.parameters, function (p) {
@@ -81407,7 +81739,7 @@ var ts;
81407
81739
  // it is ok to have member named '_super', '_this', `Promise`, etc. - member access is always qualified
81408
81740
  return false;
81409
81741
  }
81410
- if (node.flags & 8388608 /* Ambient */) {
81742
+ if (node.flags & 16777216 /* Ambient */) {
81411
81743
  // ambient context - no codegen impact
81412
81744
  return false;
81413
81745
  }
@@ -81546,7 +81878,7 @@ var ts;
81546
81878
  recordPotentialCollisionWithReflectInGeneratedCode(node, name);
81547
81879
  if (ts.isClassLike(node)) {
81548
81880
  checkTypeNameIsReserved(name, ts.Diagnostics.Class_name_cannot_be_0);
81549
- if (!(node.flags & 8388608 /* Ambient */)) {
81881
+ if (!(node.flags & 16777216 /* Ambient */)) {
81550
81882
  checkClassNameCollisionWithObject(name);
81551
81883
  }
81552
81884
  }
@@ -83140,23 +83472,23 @@ var ts;
83140
83472
  return;
83141
83473
  }
83142
83474
  var type = getDeclaredTypeOfSymbol(symbol);
83143
- if (!areTypeParametersIdentical(declarations, type.localTypeParameters)) {
83475
+ if (!areTypeParametersIdentical(declarations, type.localTypeParameters, ts.getEffectiveTypeParameterDeclarations)) {
83144
83476
  // Report an error on every conflicting declaration.
83145
83477
  var name = symbolToString(symbol);
83146
- for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
83147
- var declaration = declarations_6[_i];
83478
+ for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
83479
+ var declaration = declarations_7[_i];
83148
83480
  error(declaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_type_parameters, name);
83149
83481
  }
83150
83482
  }
83151
83483
  }
83152
83484
  }
83153
- function areTypeParametersIdentical(declarations, targetParameters) {
83485
+ function areTypeParametersIdentical(declarations, targetParameters, getTypeParameterDeclarations) {
83154
83486
  var maxTypeArgumentCount = ts.length(targetParameters);
83155
83487
  var minTypeArgumentCount = getMinTypeArgumentCount(targetParameters);
83156
- for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
83157
- var declaration = declarations_7[_i];
83488
+ for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
83489
+ var declaration = declarations_8[_i];
83158
83490
  // If this declaration has too few or too many type parameters, we report an error
83159
- var sourceParameters = ts.getEffectiveTypeParameterDeclarations(declaration);
83491
+ var sourceParameters = getTypeParameterDeclarations(declaration);
83160
83492
  var numTypeParameters = sourceParameters.length;
83161
83493
  if (numTypeParameters < minTypeArgumentCount || numTypeParameters > maxTypeArgumentCount) {
83162
83494
  return false;
@@ -83224,7 +83556,7 @@ var ts;
83224
83556
  checkFunctionOrConstructorSymbol(symbol);
83225
83557
  checkClassForDuplicateDeclarations(node);
83226
83558
  // Only check for reserved static identifiers on non-ambient context.
83227
- var nodeInAmbientContext = !!(node.flags & 8388608 /* Ambient */);
83559
+ var nodeInAmbientContext = !!(node.flags & 16777216 /* Ambient */);
83228
83560
  if (!nodeInAmbientContext) {
83229
83561
  checkClassForStaticPropertyNameConflicts(node);
83230
83562
  }
@@ -83374,7 +83706,7 @@ var ts;
83374
83706
  */
83375
83707
  function checkMemberForOverrideModifier(node, staticType, baseStaticType, baseWithThis, type, typeWithThis, memberHasOverrideModifier, memberHasAbstractModifier, memberIsStatic, memberIsParameterProperty, memberName, errorNode) {
83376
83708
  var isJs = ts.isInJSFile(node);
83377
- var nodeInAmbientContext = !!(node.flags & 8388608 /* Ambient */);
83709
+ var nodeInAmbientContext = !!(node.flags & 16777216 /* Ambient */);
83378
83710
  if (baseWithThis && (memberHasOverrideModifier || compilerOptions.noImplicitOverride)) {
83379
83711
  var memberEscapedName = ts.escapeLeadingUnderscores(memberName);
83380
83712
  var thisType = memberIsStatic ? staticType : typeWithThis;
@@ -83602,7 +83934,7 @@ var ts;
83602
83934
  && !(derived.flags & 33554432 /* Transient */)
83603
83935
  && !(baseDeclarationFlags & 128 /* Abstract */)
83604
83936
  && !(derivedDeclarationFlags & 128 /* Abstract */)
83605
- && !((_b = derived.declarations) === null || _b === void 0 ? void 0 : _b.some(function (d) { return !!(d.flags & 8388608 /* Ambient */); }))) {
83937
+ && !((_b = derived.declarations) === null || _b === void 0 ? void 0 : _b.some(function (d) { return !!(d.flags & 16777216 /* Ambient */); }))) {
83606
83938
  var constructor = findConstructorDeclaration(ts.getClassLikeDeclarationOfSymbol(type.symbol));
83607
83939
  var propName = uninitialized.name;
83608
83940
  if (uninitialized.exclamationToken
@@ -83694,7 +84026,7 @@ var ts;
83694
84026
  return ok;
83695
84027
  }
83696
84028
  function checkPropertyInitialization(node) {
83697
- if (!strictNullChecks || !strictPropertyInitialization || node.flags & 8388608 /* Ambient */) {
84029
+ if (!strictNullChecks || !strictPropertyInitialization || node.flags & 16777216 /* Ambient */) {
83698
84030
  return;
83699
84031
  }
83700
84032
  var constructor = findConstructorDeclaration(node);
@@ -83831,7 +84163,7 @@ var ts;
83831
84163
  }
83832
84164
  // In ambient non-const numeric enum declarations, enum members without initializers are
83833
84165
  // considered computed members (as opposed to having auto-incremented values).
83834
- if (member.parent.flags & 8388608 /* Ambient */ && !ts.isEnumConst(member.parent) && getEnumKind(getSymbolOfNode(member.parent)) === 0 /* Numeric */) {
84166
+ if (member.parent.flags & 16777216 /* Ambient */ && !ts.isEnumConst(member.parent) && getEnumKind(getSymbolOfNode(member.parent)) === 0 /* Numeric */) {
83835
84167
  return undefined;
83836
84168
  }
83837
84169
  // If the member declaration specifies no value, the member is considered a constant enum member.
@@ -83863,7 +84195,7 @@ var ts;
83863
84195
  else if (isConstEnum) {
83864
84196
  error(initializer, ts.Diagnostics.const_enum_member_initializers_can_only_contain_literal_values_and_other_computed_enum_values);
83865
84197
  }
83866
- else if (member.parent.flags & 8388608 /* Ambient */) {
84198
+ else if (member.parent.flags & 16777216 /* Ambient */) {
83867
84199
  error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
83868
84200
  }
83869
84201
  else {
@@ -84031,11 +84363,11 @@ var ts;
84031
84363
  function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
84032
84364
  var declarations = symbol.declarations;
84033
84365
  if (declarations) {
84034
- for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
84035
- var declaration = declarations_8[_i];
84366
+ for (var _i = 0, declarations_9 = declarations; _i < declarations_9.length; _i++) {
84367
+ var declaration = declarations_9[_i];
84036
84368
  if ((declaration.kind === 257 /* ClassDeclaration */ ||
84037
84369
  (declaration.kind === 256 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) &&
84038
- !(declaration.flags & 8388608 /* Ambient */)) {
84370
+ !(declaration.flags & 16777216 /* Ambient */)) {
84039
84371
  return declaration;
84040
84372
  }
84041
84373
  }
@@ -84066,7 +84398,7 @@ var ts;
84066
84398
  function checkModuleDeclarationDiagnostics() {
84067
84399
  // Grammar checking
84068
84400
  var isGlobalAugmentation = ts.isGlobalScopeAugmentation(node);
84069
- var inAmbientContext = node.flags & 8388608 /* Ambient */;
84401
+ var inAmbientContext = node.flags & 16777216 /* Ambient */;
84070
84402
  if (isGlobalAugmentation && !inAmbientContext) {
84071
84403
  error(node.name, ts.Diagnostics.Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context);
84072
84404
  }
@@ -84284,7 +84616,7 @@ var ts;
84284
84616
  }
84285
84617
  if (compilerOptions.isolatedModules
84286
84618
  && !ts.isTypeOnlyImportOrExportDeclaration(node)
84287
- && !(node.flags & 8388608 /* Ambient */)) {
84619
+ && !(node.flags & 16777216 /* Ambient */)) {
84288
84620
  var typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
84289
84621
  var isType = !(target.flags & 111551 /* Value */);
84290
84622
  if (isType || typeOnlyAlias) {
@@ -84330,7 +84662,7 @@ var ts;
84330
84662
  }
84331
84663
  }
84332
84664
  function isDeprecatedAliasedSymbol(symbol) {
84333
- return !!symbol.declarations && ts.every(symbol.declarations, function (d) { return !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); });
84665
+ return !!symbol.declarations && ts.every(symbol.declarations, function (d) { return !!(ts.getCombinedNodeFlags(d) & 268435456 /* Deprecated */); });
84334
84666
  }
84335
84667
  function checkDeprecatedAliasedSymbol(symbol, location) {
84336
84668
  if (!(symbol.flags & 2097152 /* Alias */))
@@ -84459,7 +84791,7 @@ var ts;
84459
84791
  }
84460
84792
  }
84461
84793
  else {
84462
- if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat === undefined && !node.isTypeOnly && !(node.flags & 8388608 /* Ambient */)) {
84794
+ if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat === undefined && !node.isTypeOnly && !(node.flags & 16777216 /* Ambient */)) {
84463
84795
  // Import equals declaration is deprecated in es6 or above
84464
84796
  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);
84465
84797
  }
@@ -84485,7 +84817,7 @@ var ts;
84485
84817
  ts.forEach(node.exportClause.elements, checkExportSpecifier);
84486
84818
  var inAmbientExternalModule = node.parent.kind === 262 /* ModuleBlock */ && ts.isAmbientModule(node.parent.parent);
84487
84819
  var inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === 262 /* ModuleBlock */ &&
84488
- !node.moduleSpecifier && node.flags & 8388608 /* Ambient */;
84820
+ !node.moduleSpecifier && node.flags & 16777216 /* Ambient */;
84489
84821
  if (node.parent.kind !== 305 /* SourceFile */ && !inAmbientExternalModule && !inAmbientNamespaceDeclaration) {
84490
84822
  error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
84491
84823
  }
@@ -84650,10 +84982,10 @@ var ts;
84650
84982
  checkExpressionCached(node.expression);
84651
84983
  }
84652
84984
  checkExternalModuleExports(container);
84653
- if ((node.flags & 8388608 /* Ambient */) && !ts.isEntityNameExpression(node.expression)) {
84985
+ if ((node.flags & 16777216 /* Ambient */) && !ts.isEntityNameExpression(node.expression)) {
84654
84986
  grammarErrorOnNode(node.expression, ts.Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context);
84655
84987
  }
84656
- if (node.isExportEquals && !(node.flags & 8388608 /* Ambient */)) {
84988
+ if (node.isExportEquals && !(node.flags & 16777216 /* Ambient */)) {
84657
84989
  if (moduleKind >= ts.ModuleKind.ES2015 && ts.getSourceFileOfNode(node).impliedNodeFormat !== ts.ModuleKind.CommonJS) {
84658
84990
  // export assignment is not supported in es6 modules
84659
84991
  grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
@@ -85086,7 +85418,7 @@ var ts;
85086
85418
  // This relies on the results of other lazy diagnostics, so must be computed after them
85087
85419
  if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
85088
85420
  checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) {
85089
- if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 8388608 /* Ambient */))) {
85421
+ if (!ts.containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 16777216 /* Ambient */))) {
85090
85422
  diagnostics.add(diag);
85091
85423
  }
85092
85424
  });
@@ -85186,7 +85518,7 @@ var ts;
85186
85518
  }
85187
85519
  // Language service support
85188
85520
  function getSymbolsInScope(location, meaning) {
85189
- if (location.flags & 16777216 /* InWithStatement */) {
85521
+ if (location.flags & 33554432 /* InWithStatement */) {
85190
85522
  // We cannot answer semantic questions within a with block, do not proceed any further
85191
85523
  return [];
85192
85524
  }
@@ -85536,7 +85868,7 @@ var ts;
85536
85868
  }
85537
85869
  var parent = node.parent;
85538
85870
  var grandParent = parent.parent;
85539
- if (node.flags & 16777216 /* InWithStatement */) {
85871
+ if (node.flags & 33554432 /* InWithStatement */) {
85540
85872
  // We cannot answer semantic questions within a with block, do not proceed any further
85541
85873
  return undefined;
85542
85874
  }
@@ -85678,7 +86010,7 @@ var ts;
85678
86010
  if (ts.isSourceFile(node) && !ts.isExternalModule(node)) {
85679
86011
  return errorType;
85680
86012
  }
85681
- if (node.flags & 16777216 /* InWithStatement */) {
86013
+ if (node.flags & 33554432 /* InWithStatement */) {
85682
86014
  // We cannot answer semantic questions within a with block, do not proceed any further
85683
86015
  return errorType;
85684
86016
  }
@@ -86731,7 +87063,7 @@ var ts;
86731
87063
  function checkExternalEmitHelpers(location, helpers) {
86732
87064
  if ((requestedExternalEmitHelpers & helpers) !== helpers && compilerOptions.importHelpers) {
86733
87065
  var sourceFile = ts.getSourceFileOfNode(location);
86734
- if (ts.isEffectiveExternalModule(sourceFile, compilerOptions) && !(location.flags & 8388608 /* Ambient */)) {
87066
+ if (ts.isEffectiveExternalModule(sourceFile, compilerOptions) && !(location.flags & 16777216 /* Ambient */)) {
86735
87067
  var helpersModule = resolveHelpersModule(sourceFile, location);
86736
87068
  if (helpersModule !== unknownSymbol) {
86737
87069
  var uncheckedHelpers = helpers & ~requestedExternalEmitHelpers;
@@ -86984,7 +87316,7 @@ var ts;
86984
87316
  else if (node.kind === 164 /* Parameter */) {
86985
87317
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
86986
87318
  }
86987
- else if ((node.parent.flags & 8388608 /* Ambient */) && node.parent.kind === 262 /* ModuleBlock */) {
87319
+ else if ((node.parent.flags & 16777216 /* Ambient */) && node.parent.kind === 262 /* ModuleBlock */) {
86988
87320
  return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
86989
87321
  }
86990
87322
  else if (ts.isPrivateIdentifierClassElementDeclaration(node)) {
@@ -87030,7 +87362,7 @@ var ts;
87030
87362
  if (flags & 256 /* Async */) {
87031
87363
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async");
87032
87364
  }
87033
- else if (flags & 2 /* Ambient */ || node.parent.flags & 8388608 /* Ambient */) {
87365
+ else if (flags & 2 /* Ambient */ || node.parent.flags & 16777216 /* Ambient */) {
87034
87366
  return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
87035
87367
  }
87036
87368
  else if (node.kind === 164 /* Parameter */) {
@@ -87176,7 +87508,7 @@ var ts;
87176
87508
  if (i !== (parameterCount - 1)) {
87177
87509
  return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
87178
87510
  }
87179
- if (!(parameter.flags & 8388608 /* Ambient */)) { // Allow `...foo,` in ambient declarations; see GH#23070
87511
+ if (!(parameter.flags & 16777216 /* Ambient */)) { // Allow `...foo,` in ambient declarations; see GH#23070
87180
87512
  checkGrammarForDisallowedTrailingComma(parameters, ts.Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma);
87181
87513
  }
87182
87514
  if (parameter.questionToken) {
@@ -87387,7 +87719,7 @@ var ts;
87387
87719
  ts.Debug.assert(node.kind === 256 /* FunctionDeclaration */ ||
87388
87720
  node.kind === 213 /* FunctionExpression */ ||
87389
87721
  node.kind === 169 /* MethodDeclaration */);
87390
- if (node.flags & 8388608 /* Ambient */) {
87722
+ if (node.flags & 16777216 /* Ambient */) {
87391
87723
  return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
87392
87724
  }
87393
87725
  if (!node.body) {
@@ -87625,7 +87957,7 @@ var ts;
87625
87957
  return false;
87626
87958
  }
87627
87959
  function checkGrammarAccessor(accessor) {
87628
- if (!(accessor.flags & 8388608 /* Ambient */) && (accessor.parent.kind !== 182 /* TypeLiteral */) && (accessor.parent.kind !== 258 /* InterfaceDeclaration */)) {
87960
+ if (!(accessor.flags & 16777216 /* Ambient */) && (accessor.parent.kind !== 182 /* TypeLiteral */) && (accessor.parent.kind !== 258 /* InterfaceDeclaration */)) {
87629
87961
  if (languageVersion < 1 /* ES5 */) {
87630
87962
  return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
87631
87963
  }
@@ -87765,7 +88097,7 @@ var ts;
87765
88097
  // However, property declarations disallow computed names in general,
87766
88098
  // and accessors are not allowed in ambient contexts in general,
87767
88099
  // so this error only really matters for methods.
87768
- if (node.flags & 8388608 /* Ambient */) {
88100
+ if (node.flags & 16777216 /* Ambient */) {
87769
88101
  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);
87770
88102
  }
87771
88103
  else if (node.kind === 169 /* MethodDeclaration */ && !node.body) {
@@ -87881,7 +88213,7 @@ var ts;
87881
88213
  }
87882
88214
  function checkGrammarVariableDeclaration(node) {
87883
88215
  if (node.parent.parent.kind !== 243 /* ForInStatement */ && node.parent.parent.kind !== 244 /* ForOfStatement */) {
87884
- if (node.flags & 8388608 /* Ambient */) {
88216
+ if (node.flags & 16777216 /* Ambient */) {
87885
88217
  checkAmbientInitializer(node);
87886
88218
  }
87887
88219
  else if (!node.initializer) {
@@ -87893,7 +88225,7 @@ var ts;
87893
88225
  }
87894
88226
  }
87895
88227
  }
87896
- if (node.exclamationToken && (node.parent.parent.kind !== 237 /* VariableStatement */ || !node.type || node.initializer || node.flags & 8388608 /* Ambient */)) {
88228
+ if (node.exclamationToken && (node.parent.parent.kind !== 237 /* VariableStatement */ || !node.type || node.initializer || node.flags & 16777216 /* Ambient */)) {
87897
88229
  var message = node.initializer
87898
88230
  ? ts.Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions
87899
88231
  : !node.type
@@ -87902,7 +88234,7 @@ var ts;
87902
88234
  return grammarErrorOnNode(node.exclamationToken, message);
87903
88235
  }
87904
88236
  if ((moduleKind < ts.ModuleKind.ES2015 || ts.getSourceFileOfNode(node).impliedNodeFormat === ts.ModuleKind.CommonJS) && moduleKind !== ts.ModuleKind.System &&
87905
- !(node.parent.parent.flags & 8388608 /* Ambient */) && ts.hasSyntacticModifier(node.parent.parent, 1 /* Export */)) {
88237
+ !(node.parent.parent.flags & 16777216 /* Ambient */) && ts.hasSyntacticModifier(node.parent.parent, 1 /* Export */)) {
87906
88238
  checkESModuleMarker(node.name);
87907
88239
  }
87908
88240
  var checkLetConstNames = (ts.isLet(node) || ts.isVarConst(node));
@@ -88079,11 +88411,11 @@ var ts;
88079
88411
  return grammarErrorOnNode(node.initializer, ts.Diagnostics.A_type_literal_property_cannot_have_an_initializer);
88080
88412
  }
88081
88413
  }
88082
- if (node.flags & 8388608 /* Ambient */) {
88414
+ if (node.flags & 16777216 /* Ambient */) {
88083
88415
  checkAmbientInitializer(node);
88084
88416
  }
88085
88417
  if (ts.isPropertyDeclaration(node) && node.exclamationToken && (!ts.isClassLike(node.parent) || !node.type || node.initializer ||
88086
- node.flags & 8388608 /* Ambient */ || ts.isStatic(node) || ts.hasAbstractModifier(node))) {
88418
+ node.flags & 16777216 /* Ambient */ || ts.isStatic(node) || ts.hasAbstractModifier(node))) {
88087
88419
  var message = node.initializer
88088
88420
  ? ts.Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions
88089
88421
  : !node.type
@@ -88129,10 +88461,10 @@ var ts;
88129
88461
  return false;
88130
88462
  }
88131
88463
  function checkGrammarSourceFile(node) {
88132
- return !!(node.flags & 8388608 /* Ambient */) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
88464
+ return !!(node.flags & 16777216 /* Ambient */) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
88133
88465
  }
88134
88466
  function checkGrammarStatementInAmbientContext(node) {
88135
- if (node.flags & 8388608 /* Ambient */) {
88467
+ if (node.flags & 16777216 /* Ambient */) {
88136
88468
  // Find containing block which is either Block, ModuleBlock, SourceFile
88137
88469
  var links = getNodeLinks(node);
88138
88470
  if (!links.hasReportedStatementInAmbientContext && (ts.isFunctionLike(node.parent) || ts.isAccessor(node.parent))) {
@@ -92250,7 +92582,7 @@ var ts;
92250
92582
  return !ts.nodeIsMissing(node.body);
92251
92583
  }
92252
92584
  function visitPropertyDeclaration(node) {
92253
- if (node.flags & 8388608 /* Ambient */ || ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
92585
+ if (node.flags & 16777216 /* Ambient */ || ts.hasSyntacticModifier(node, 128 /* Abstract */)) {
92254
92586
  return undefined;
92255
92587
  }
92256
92588
  var updated = factory.updatePropertyDeclaration(node,
@@ -99140,8 +99472,8 @@ var ts;
99140
99472
  // declarations may not be sorted by position.
99141
99473
  // pos should be the minimum* position over all nodes (that's not -1), end should be the maximum end over all nodes.
99142
99474
  var pos = -1, end = -1;
99143
- for (var _i = 0, declarations_9 = declarations; _i < declarations_9.length; _i++) {
99144
- var node = declarations_9[_i];
99475
+ for (var _i = 0, declarations_10 = declarations; _i < declarations_10.length; _i++) {
99476
+ var node = declarations_10[_i];
99145
99477
  pos = pos === -1 ? node.pos : node.pos === -1 ? pos : Math.min(pos, node.pos);
99146
99478
  end = Math.max(end, node.end);
99147
99479
  }
@@ -108184,7 +108516,7 @@ var ts;
108184
108516
  needsScopeFixMarker = false;
108185
108517
  var statements = ts.visitNodes(inner.statements, visitDeclarationStatements);
108186
108518
  var lateStatements = transformAndReplaceLatePaintedStatements(statements);
108187
- if (input.flags & 8388608 /* Ambient */) {
108519
+ if (input.flags & 16777216 /* Ambient */) {
108188
108520
  needsScopeFixMarker = false; // If it was `declare`'d everything is implicitly exported already, ignore late printed "privates"
108189
108521
  }
108190
108522
  // With the final list of statements, there are 3 possibilities:
@@ -109832,6 +110164,9 @@ var ts;
109832
110164
  var currentParenthesizerRule;
109833
110165
  var _c = ts.performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment"), enterComment = _c.enter, exitComment = _c.exit;
109834
110166
  var parenthesizer = ts.factory.parenthesizer;
110167
+ var typeArgumentParenthesizerRuleSelector = {
110168
+ select: function (index) { return index === 0 ? parenthesizer.parenthesizeLeadingTypeArgument : undefined; }
110169
+ };
109835
110170
  var emitBinaryExpression = createEmitBinaryExpression();
109836
110171
  reset();
109837
110172
  return {
@@ -111044,7 +111379,7 @@ var ts;
111044
111379
  writePunctuation("}");
111045
111380
  }
111046
111381
  function emitArrayType(node) {
111047
- emit(node.elementType, parenthesizer.parenthesizeElementTypeOfArrayType);
111382
+ emit(node.elementType, parenthesizer.parenthesizeNonArrayTypeOfPostfixType);
111048
111383
  writePunctuation("[");
111049
111384
  writePunctuation("]");
111050
111385
  }
@@ -111055,7 +111390,7 @@ var ts;
111055
111390
  function emitTupleType(node) {
111056
111391
  emitTokenWithComment(22 /* OpenBracketToken */, node.pos, writePunctuation, node);
111057
111392
  var flags = ts.getEmitFlags(node) & 1 /* SingleLine */ ? 528 /* SingleLineTupleTypeElements */ : 657 /* MultiLineTupleTypeElements */;
111058
- emitList(node, node.elements, flags | 524288 /* NoSpaceIfEmpty */);
111393
+ emitList(node, node.elements, flags | 524288 /* NoSpaceIfEmpty */, parenthesizer.parenthesizeElementTypeOfTupleType);
111059
111394
  emitTokenWithComment(23 /* CloseBracketToken */, node.elements.end, writePunctuation, node);
111060
111395
  }
111061
111396
  function emitNamedTupleMember(node) {
@@ -111067,21 +111402,21 @@ var ts;
111067
111402
  emit(node.type);
111068
111403
  }
111069
111404
  function emitOptionalType(node) {
111070
- emit(node.type, parenthesizer.parenthesizeElementTypeOfArrayType);
111405
+ emit(node.type, parenthesizer.parenthesizeTypeOfOptionalType);
111071
111406
  writePunctuation("?");
111072
111407
  }
111073
111408
  function emitUnionType(node) {
111074
- emitList(node, node.types, 516 /* UnionTypeConstituents */, parenthesizer.parenthesizeMemberOfElementType);
111409
+ emitList(node, node.types, 516 /* UnionTypeConstituents */, parenthesizer.parenthesizeConstituentTypeOfUnionType);
111075
111410
  }
111076
111411
  function emitIntersectionType(node) {
111077
- emitList(node, node.types, 520 /* IntersectionTypeConstituents */, parenthesizer.parenthesizeMemberOfElementType);
111412
+ emitList(node, node.types, 520 /* IntersectionTypeConstituents */, parenthesizer.parenthesizeConstituentTypeOfIntersectionType);
111078
111413
  }
111079
111414
  function emitConditionalType(node) {
111080
- emit(node.checkType, parenthesizer.parenthesizeMemberOfConditionalType);
111415
+ emit(node.checkType, parenthesizer.parenthesizeCheckTypeOfConditionalType);
111081
111416
  writeSpace();
111082
111417
  writeKeyword("extends");
111083
111418
  writeSpace();
111084
- emit(node.extendsType, parenthesizer.parenthesizeMemberOfConditionalType);
111419
+ emit(node.extendsType, parenthesizer.parenthesizeExtendsTypeOfConditionalType);
111085
111420
  writeSpace();
111086
111421
  writePunctuation("?");
111087
111422
  writeSpace();
@@ -111107,10 +111442,13 @@ var ts;
111107
111442
  function emitTypeOperator(node) {
111108
111443
  writeTokenText(node.operator, writeKeyword);
111109
111444
  writeSpace();
111110
- emit(node.type, parenthesizer.parenthesizeMemberOfElementType);
111445
+ var parenthesizerRule = node.operator === 145 /* ReadonlyKeyword */ ?
111446
+ parenthesizer.parenthesizeOperandOfReadonlyTypeOperator :
111447
+ parenthesizer.parenthesizeOperandOfTypeOperator;
111448
+ emit(node.type, parenthesizerRule);
111111
111449
  }
111112
111450
  function emitIndexedAccessType(node) {
111113
- emit(node.objectType, parenthesizer.parenthesizeMemberOfElementType);
111451
+ emit(node.objectType, parenthesizer.parenthesizeNonArrayTypeOfPostfixType);
111114
111452
  writePunctuation("[");
111115
111453
  emit(node.indexType);
111116
111454
  writePunctuation("]");
@@ -112844,7 +113182,7 @@ var ts;
112844
113182
  emitList(parentNode, decorators, 2146305 /* Decorators */);
112845
113183
  }
112846
113184
  function emitTypeArguments(parentNode, typeArguments) {
112847
- emitList(parentNode, typeArguments, 53776 /* TypeArguments */, parenthesizer.parenthesizeMemberOfElementType);
113185
+ emitList(parentNode, typeArguments, 53776 /* TypeArguments */, typeArgumentParenthesizerRuleSelector);
112848
113186
  }
112849
113187
  function emitTypeParameters(parentNode, typeParameters) {
112850
113188
  if (ts.isFunctionLike(parentNode) && parentNode.typeArguments) { // Quick info uses type arguments in place of type parameters on instantiated signatures
@@ -112963,6 +113301,7 @@ var ts;
112963
113301
  if (format & 128 /* Indented */) {
112964
113302
  increaseIndent();
112965
113303
  }
113304
+ var emitListItem = getEmitListItem(emit, parenthesizerRule);
112966
113305
  // Emit each child.
112967
113306
  var previousSibling = void 0;
112968
113307
  var previousSourceFileTextKind = void 0;
@@ -113013,12 +113352,7 @@ var ts;
113013
113352
  shouldEmitInterveningComments = mayEmitInterveningComments;
113014
113353
  }
113015
113354
  nextListElementPos = child.pos;
113016
- if (emit.length === 1) {
113017
- emit(child);
113018
- }
113019
- else {
113020
- emit(child, parenthesizerRule);
113021
- }
113355
+ emitListItem(child, emit, parenthesizerRule, i);
113022
113356
  if (shouldDecreaseIndentAfterEmit) {
113023
113357
  decreaseIndent();
113024
113358
  shouldDecreaseIndentAfterEmit = false;
@@ -114259,6 +114593,20 @@ var ts;
114259
114593
  TempFlags[TempFlags["CountMask"] = 268435455] = "CountMask";
114260
114594
  TempFlags[TempFlags["_i"] = 268435456] = "_i";
114261
114595
  })(TempFlags || (TempFlags = {}));
114596
+ function emitListItemNoParenthesizer(node, emit, _parenthesizerRule, _index) {
114597
+ emit(node);
114598
+ }
114599
+ function emitListItemWithParenthesizerRuleSelector(node, emit, parenthesizerRuleSelector, index) {
114600
+ emit(node, parenthesizerRuleSelector.select(index));
114601
+ }
114602
+ function emitListItemWithParenthesizerRule(node, emit, parenthesizerRule, _index) {
114603
+ emit(node, parenthesizerRule);
114604
+ }
114605
+ function getEmitListItem(emit, parenthesizerRule) {
114606
+ return emit.length === 1 ? emitListItemNoParenthesizer :
114607
+ typeof parenthesizerRule === "object" ? emitListItemWithParenthesizerRuleSelector :
114608
+ emitListItemWithParenthesizerRule;
114609
+ }
114262
114610
  })(ts || (ts = {}));
114263
114611
  /* @internal */
114264
114612
  var ts;
@@ -116325,7 +116673,7 @@ var ts;
116325
116673
  // moduleAugmentations has changed
116326
116674
  structureIsReused = 1 /* SafeModules */;
116327
116675
  }
116328
- if ((oldSourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 3145728 /* PermanentlySetIncrementalFlags */)) {
116676
+ if ((oldSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */) !== (newSourceFile.flags & 6291456 /* PermanentlySetIncrementalFlags */)) {
116329
116677
  // dynamicImport has changed
116330
116678
  structureIsReused = 1 /* SafeModules */;
116331
116679
  }
@@ -116489,6 +116837,9 @@ var ts;
116489
116837
  return !!sourceFilesFoundSearchingNodeModules.get(file.path);
116490
116838
  }
116491
116839
  function isSourceFileDefaultLibrary(file) {
116840
+ if (!file.isDeclarationFile) {
116841
+ return false;
116842
+ }
116492
116843
  if (file.hasNoDefaultLib) {
116493
116844
  return true;
116494
116845
  }
@@ -117000,7 +117351,7 @@ var ts;
117000
117351
  var node = _a[_i];
117001
117352
  collectModuleReferences(node, /*inAmbientModule*/ false);
117002
117353
  }
117003
- if ((file.flags & 1048576 /* PossiblyContainsDynamicImport */) || isJavaScriptFile) {
117354
+ if ((file.flags & 2097152 /* PossiblyContainsDynamicImport */) || isJavaScriptFile) {
117004
117355
  collectDynamicImportOrRequireCalls(file);
117005
117356
  }
117006
117357
  file.imports = imports || ts.emptyArray;
@@ -117598,7 +117949,7 @@ var ts;
117598
117949
  && index < file.imports.length
117599
117950
  && !elideImport
117600
117951
  && !(isJsFile && !ts.getAllowJSCompilerOption(optionsForFile))
117601
- && (ts.isInJSFile(file.imports[index]) || !(file.imports[index].flags & 4194304 /* JSDoc */));
117952
+ && (ts.isInJSFile(file.imports[index]) || !(file.imports[index].flags & 8388608 /* JSDoc */));
117602
117953
  if (elideImport) {
117603
117954
  modulesWithElidedImports.set(file.path, true);
117604
117955
  }
@@ -117679,21 +118030,6 @@ var ts;
117679
118030
  return resolvedRef;
117680
118031
  }
117681
118032
  function verifyCompilerOptions() {
117682
- var isNightly = ts.stringContains(ts.version, "-dev") || ts.stringContains(ts.version, "-insiders");
117683
- if (!isNightly) {
117684
- if (ts.getEmitModuleKind(options) === ts.ModuleKind.Node12) {
117685
- 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");
117686
- }
117687
- else if (ts.getEmitModuleKind(options) === ts.ModuleKind.NodeNext) {
117688
- 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");
117689
- }
117690
- else if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.Node12) {
117691
- 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");
117692
- }
117693
- else if (ts.getEmitModuleResolutionKind(options) === ts.ModuleResolutionKind.NodeNext) {
117694
- 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");
117695
- }
117696
- }
117697
118033
  if (options.strictPropertyInitialization && !ts.getStrictOptionValue(options, "strictNullChecks")) {
117698
118034
  createDiagnosticForOptionName(ts.Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "strictPropertyInitialization", "strictNullChecks");
117699
118035
  }
@@ -126480,7 +126816,7 @@ var ts;
126480
126816
  result.push("export" /* exportedModifier */);
126481
126817
  if (flags & 8192 /* Deprecated */)
126482
126818
  result.push("deprecated" /* deprecatedModifier */);
126483
- if (node.flags & 8388608 /* Ambient */)
126819
+ if (node.flags & 16777216 /* Ambient */)
126484
126820
  result.push("declare" /* ambientModifier */);
126485
126821
  if (node.kind === 271 /* ExportAssignment */)
126486
126822
  result.push("export" /* exportedModifier */);
@@ -132796,7 +133132,7 @@ var ts;
132796
133132
  var instantiatedType = tryGetObjectLiteralContextualType(objectLikeContainer, typeChecker);
132797
133133
  // Check completions for Object property value shorthand
132798
133134
  if (instantiatedType === undefined) {
132799
- if (objectLikeContainer.flags & 16777216 /* InWithStatement */) {
133135
+ if (objectLikeContainer.flags & 33554432 /* InWithStatement */) {
132800
133136
  return 2 /* Fail */;
132801
133137
  }
132802
133138
  isNonContextualObjectLiteral = true;
@@ -135459,17 +135795,25 @@ var ts;
135459
135795
  var options = { use: 1 /* References */ };
135460
135796
  var referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options);
135461
135797
  var checker = program.getTypeChecker();
135462
- var symbol = checker.getSymbolAtLocation(ts.getAdjustedReferenceLocation(Core.getAdjustedNode(node, options)));
135798
+ // Unless the starting node is a declaration (vs e.g. JSDoc), don't attempt to compute isDefinition
135799
+ var adjustedNode = Core.getAdjustedNode(node, options);
135800
+ var symbol = isDefinitionForReference(adjustedNode) ? checker.getSymbolAtLocation(adjustedNode) : undefined;
135463
135801
  return !referencedSymbols || !referencedSymbols.length ? undefined : ts.mapDefined(referencedSymbols, function (_a) {
135464
135802
  var definition = _a.definition, references = _a.references;
135465
135803
  // Only include referenced symbols that have a valid definition.
135466
135804
  return definition && {
135467
135805
  definition: checker.runWithCancellationToken(cancellationToken, function (checker) { return definitionToReferencedSymbolDefinitionInfo(definition, checker, node); }),
135468
- references: references.map(function (r) { return toReferenceEntry(r, symbol); })
135806
+ references: references.map(function (r) { return toReferencedSymbolEntry(r, symbol); })
135469
135807
  };
135470
135808
  });
135471
135809
  }
135472
135810
  FindAllReferences.findReferencedSymbols = findReferencedSymbols;
135811
+ function isDefinitionForReference(node) {
135812
+ return node.kind === 88 /* DefaultKeyword */
135813
+ || !!ts.getDeclarationFromName(node)
135814
+ || ts.isLiteralComputedPropertyDeclarationName(node)
135815
+ || (node.kind === 134 /* ConstructorKeyword */ && ts.isConstructorDeclaration(node.parent));
135816
+ }
135473
135817
  function getImplementationsAtPosition(program, cancellationToken, sourceFiles, sourceFile, position) {
135474
135818
  var node = ts.getTouchingPropertyName(sourceFile, position);
135475
135819
  var referenceEntries;
@@ -135598,13 +135942,19 @@ var ts;
135598
135942
  return __assign(__assign({}, entryToDocumentSpan(entry)), (providePrefixAndSuffixText && getPrefixAndSuffixText(entry, originalNode, checker)));
135599
135943
  }
135600
135944
  FindAllReferences.toRenameLocation = toRenameLocation;
135601
- function toReferenceEntry(entry, symbol) {
135945
+ function toReferencedSymbolEntry(entry, symbol) {
135946
+ var referenceEntry = toReferenceEntry(entry);
135947
+ if (!symbol)
135948
+ return referenceEntry;
135949
+ return __assign(__assign({}, referenceEntry), { isDefinition: entry.kind !== 0 /* Span */ && isDeclarationOfSymbol(entry.node, symbol) });
135950
+ }
135951
+ function toReferenceEntry(entry) {
135602
135952
  var documentSpan = entryToDocumentSpan(entry);
135603
135953
  if (entry.kind === 0 /* Span */) {
135604
- return __assign(__assign({}, documentSpan), { isWriteAccess: false, isDefinition: false });
135954
+ return __assign(__assign({}, documentSpan), { isWriteAccess: false });
135605
135955
  }
135606
135956
  var kind = entry.kind, node = entry.node;
135607
- return __assign(__assign({}, documentSpan), { isWriteAccess: isWriteAccessForReference(node), isDefinition: isDeclarationOfSymbol(node, symbol), isInString: kind === 2 /* StringLiteral */ ? true : undefined });
135957
+ return __assign(__assign({}, documentSpan), { isWriteAccess: isWriteAccessForReference(node), isInString: kind === 2 /* StringLiteral */ ? true : undefined });
135608
135958
  }
135609
135959
  FindAllReferences.toReferenceEntry = toReferenceEntry;
135610
135960
  function entryToDocumentSpan(entry) {
@@ -135747,7 +136097,7 @@ var ts;
135747
136097
  */
135748
136098
  function declarationIsWriteAccess(decl) {
135749
136099
  // Consider anything in an ambient declaration to be a write access since it may be coming from JS.
135750
- if (!!(decl.flags & 8388608 /* Ambient */))
136100
+ if (!!(decl.flags & 16777216 /* Ambient */))
135751
136101
  return true;
135752
136102
  switch (decl.kind) {
135753
136103
  case 221 /* BinaryExpression */:
@@ -136312,15 +136662,21 @@ var ts;
136312
136662
  }
136313
136663
  function eachExportReference(sourceFiles, checker, cancellationToken, exportSymbol, exportingModuleSymbol, exportName, isDefaultExport, cb) {
136314
136664
  var importTracker = FindAllReferences.createImportTracker(sourceFiles, new ts.Set(sourceFiles.map(function (f) { return f.fileName; })), checker, cancellationToken);
136315
- var _a = importTracker(exportSymbol, { exportKind: isDefaultExport ? 1 /* Default */ : 0 /* Named */, exportingModuleSymbol: exportingModuleSymbol }, /*isForRename*/ false), importSearches = _a.importSearches, indirectUsers = _a.indirectUsers;
136665
+ var _a = importTracker(exportSymbol, { exportKind: isDefaultExport ? 1 /* Default */ : 0 /* Named */, exportingModuleSymbol: exportingModuleSymbol }, /*isForRename*/ false), importSearches = _a.importSearches, indirectUsers = _a.indirectUsers, singleReferences = _a.singleReferences;
136316
136666
  for (var _i = 0, importSearches_2 = importSearches; _i < importSearches_2.length; _i++) {
136317
136667
  var importLocation = importSearches_2[_i][0];
136318
136668
  cb(importLocation);
136319
136669
  }
136320
- for (var _b = 0, indirectUsers_2 = indirectUsers; _b < indirectUsers_2.length; _b++) {
136321
- var indirectUser = indirectUsers_2[_b];
136322
- for (var _c = 0, _d = getPossibleSymbolReferenceNodes(indirectUser, isDefaultExport ? "default" : exportName); _c < _d.length; _c++) {
136323
- var node = _d[_c];
136670
+ for (var _b = 0, singleReferences_2 = singleReferences; _b < singleReferences_2.length; _b++) {
136671
+ var singleReference = singleReferences_2[_b];
136672
+ if (ts.isIdentifier(singleReference) && ts.isImportTypeNode(singleReference.parent)) {
136673
+ cb(singleReference);
136674
+ }
136675
+ }
136676
+ for (var _c = 0, indirectUsers_2 = indirectUsers; _c < indirectUsers_2.length; _c++) {
136677
+ var indirectUser = indirectUsers_2[_c];
136678
+ for (var _d = 0, _e = getPossibleSymbolReferenceNodes(indirectUser, isDefaultExport ? "default" : exportName); _d < _e.length; _d++) {
136679
+ var node = _e[_d];
136324
136680
  // Import specifiers should be handled by importSearches
136325
136681
  var symbol = checker.getSymbolAtLocation(node);
136326
136682
  var hasExportAssignmentDeclaration = ts.some(symbol === null || symbol === void 0 ? void 0 : symbol.declarations, function (d) { return ts.tryCast(d, ts.isExportAssignment) ? true : false; });
@@ -137322,7 +137678,7 @@ var ts;
137322
137678
  }
137323
137679
  Core.getIntersectingMeaningFromDeclarations = getIntersectingMeaningFromDeclarations;
137324
137680
  function isImplementation(node) {
137325
- return !!(node.flags & 8388608 /* Ambient */) ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) :
137681
+ return !!(node.flags & 16777216 /* Ambient */) ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) :
137326
137682
  (ts.isVariableLike(node) ? ts.hasInitializer(node) :
137327
137683
  ts.isFunctionLikeDeclaration(node) ? !!node.body :
137328
137684
  ts.isClassLike(node) || ts.isModuleOrEnumDeclaration(node));
@@ -137700,7 +138056,7 @@ var ts;
137700
138056
  function collect(node) {
137701
138057
  if (!node)
137702
138058
  return;
137703
- if (node.flags & 8388608 /* Ambient */) {
138059
+ if (node.flags & 16777216 /* Ambient */) {
137704
138060
  // do not descend into ambient nodes.
137705
138061
  return;
137706
138062
  }
@@ -137859,7 +138215,7 @@ var ts;
137859
138215
  }
137860
138216
  /** Gets the call sites that call out of the provided call hierarchy declaration. */
137861
138217
  function getOutgoingCalls(program, declaration) {
137862
- if (declaration.flags & 8388608 /* Ambient */ || ts.isMethodSignature(declaration)) {
138218
+ if (declaration.flags & 16777216 /* Ambient */ || ts.isMethodSignature(declaration)) {
137863
138219
  return [];
137864
138220
  }
137865
138221
  return ts.group(collectCallSites(program, declaration), getCallSiteGroupKey, function (entries) { return convertCallSiteGroupToOutgoingCall(program, entries); });
@@ -139993,8 +140349,8 @@ var ts;
139993
140349
  var changeTracker = ts.textChanges.ChangeTracker.fromContext({ host: host, formatContext: formatContext, preferences: preferences });
139994
140350
  var coalesceAndOrganizeImports = function (importGroup) { return ts.stableSort(coalesceImports(removeUnusedImports(importGroup, sourceFile, program, skipDestructiveCodeActions)), function (s1, s2) { return compareImportsOrRequireStatements(s1, s2); }); };
139995
140351
  // All of the old ImportDeclarations in the file, in syntactic order.
139996
- var topLevelImportDecls = sourceFile.statements.filter(ts.isImportDeclaration);
139997
- organizeImportsWorker(topLevelImportDecls, coalesceAndOrganizeImports);
140352
+ var topLevelImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, sourceFile.statements.filter(ts.isImportDeclaration));
140353
+ topLevelImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
139998
140354
  // All of the old ExportDeclarations in the file, in syntactic order.
139999
140355
  var topLevelExportDecls = sourceFile.statements.filter(ts.isExportDeclaration);
140000
140356
  organizeImportsWorker(topLevelExportDecls, coalesceExports);
@@ -140002,8 +140358,8 @@ var ts;
140002
140358
  var ambientModule = _a[_i];
140003
140359
  if (!ambientModule.body)
140004
140360
  continue;
140005
- var ambientModuleImportDecls = ambientModule.body.statements.filter(ts.isImportDeclaration);
140006
- organizeImportsWorker(ambientModuleImportDecls, coalesceAndOrganizeImports);
140361
+ var ambientModuleImportGroupDecls = groupImportsByNewlineContiguous(sourceFile, ambientModule.body.statements.filter(ts.isImportDeclaration));
140362
+ ambientModuleImportGroupDecls.forEach(function (importGroupDecl) { return organizeImportsWorker(importGroupDecl, coalesceAndOrganizeImports); });
140007
140363
  var ambientModuleExportDecls = ambientModule.body.statements.filter(ts.isExportDeclaration);
140008
140364
  organizeImportsWorker(ambientModuleExportDecls, coalesceExports);
140009
140365
  }
@@ -140049,6 +140405,40 @@ var ts;
140049
140405
  }
140050
140406
  }
140051
140407
  OrganizeImports.organizeImports = organizeImports;
140408
+ function groupImportsByNewlineContiguous(sourceFile, importDecls) {
140409
+ var scanner = ts.createScanner(sourceFile.languageVersion, /*skipTrivia*/ false, sourceFile.languageVariant);
140410
+ var groupImports = [];
140411
+ var groupIndex = 0;
140412
+ for (var _i = 0, importDecls_1 = importDecls; _i < importDecls_1.length; _i++) {
140413
+ var topLevelImportDecl = importDecls_1[_i];
140414
+ if (isNewGroup(sourceFile, topLevelImportDecl, scanner)) {
140415
+ groupIndex++;
140416
+ }
140417
+ if (!groupImports[groupIndex]) {
140418
+ groupImports[groupIndex] = [];
140419
+ }
140420
+ groupImports[groupIndex].push(topLevelImportDecl);
140421
+ }
140422
+ return groupImports;
140423
+ }
140424
+ // a new group is created if an import includes at least two new line
140425
+ // new line from multi-line comment doesn't count
140426
+ function isNewGroup(sourceFile, topLevelImportDecl, scanner) {
140427
+ var startPos = topLevelImportDecl.getFullStart();
140428
+ var endPos = topLevelImportDecl.getStart();
140429
+ scanner.setText(sourceFile.text, startPos, endPos - startPos);
140430
+ var numberOfNewLines = 0;
140431
+ while (scanner.getTokenPos() < endPos) {
140432
+ var tokenKind = scanner.scan();
140433
+ if (tokenKind === 4 /* NewLineTrivia */) {
140434
+ numberOfNewLines++;
140435
+ if (numberOfNewLines >= 2) {
140436
+ return true;
140437
+ }
140438
+ }
140439
+ }
140440
+ return false;
140441
+ }
140052
140442
  function removeUnusedImports(oldImports, sourceFile, program, skipDestructiveCodeActions) {
140053
140443
  // As a precaution, consider unused import detection to be destructive (GH #43051)
140054
140444
  if (skipDestructiveCodeActions) {
@@ -142284,10 +142674,13 @@ var ts;
142284
142674
  var contextualType = info.contextualType, argumentIndex = info.argumentIndex, argumentCount = info.argumentCount, argumentsSpan = info.argumentsSpan;
142285
142675
  // for optional function condition.
142286
142676
  var nonNullableContextualType = contextualType.getNonNullableType();
142287
- var signatures = nonNullableContextualType.getCallSignatures();
142288
- if (signatures.length !== 1)
142677
+ var symbol = nonNullableContextualType.symbol;
142678
+ if (symbol === undefined)
142679
+ return undefined;
142680
+ var signature = ts.lastOrUndefined(nonNullableContextualType.getCallSignatures());
142681
+ if (signature === undefined)
142289
142682
  return undefined;
142290
- var invocation = { kind: 2 /* Contextual */, signature: ts.first(signatures), node: startingToken, symbol: chooseBetterSymbol(nonNullableContextualType.symbol) };
142683
+ var invocation = { kind: 2 /* Contextual */, signature: signature, node: startingToken, symbol: chooseBetterSymbol(symbol) };
142291
142684
  return { isTypeParameterList: false, invocation: invocation, argumentsSpan: argumentsSpan, argumentIndex: argumentIndex, argumentCount: argumentCount };
142292
142685
  }
142293
142686
  function getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker) {
@@ -146457,9 +146850,9 @@ var ts;
146457
146850
  // for block indentation, we should look for a line which contains something that's not
146458
146851
  // whitespace.
146459
146852
  var currentToken = ts.getTokenAtPosition(sourceFile, position);
146460
- // for object literal, we want to the indentation work like block
146461
- // if { starts in any position (can be in the middle of line)
146462
- // the following indentation should treat { as starting of that line (including leading whitespace)
146853
+ // For object literals, we want indentation to work just like with blocks.
146854
+ // If the `{` starts in any position (even in the middle of a line), then
146855
+ // the following indentation should treat `{` as the start of that line (including leading whitespace).
146463
146856
  // ```
146464
146857
  // const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
146465
146858
  // ->
@@ -146477,7 +146870,8 @@ var ts;
146477
146870
  // y: undefined,
146478
146871
  // }
146479
146872
  // ```
146480
- if (options.indentStyle === ts.IndentStyle.Block || currentToken.kind === 18 /* OpenBraceToken */) {
146873
+ var isObjectLiteral = currentToken.kind === 18 /* OpenBraceToken */ && currentToken.parent.kind === 205 /* ObjectLiteralExpression */;
146874
+ if (options.indentStyle === ts.IndentStyle.Block || isObjectLiteral) {
146481
146875
  return getBlockIndent(sourceFile, position, options);
146482
146876
  }
146483
146877
  if (precedingToken.kind === 27 /* CommaToken */ && precedingToken.parent.kind !== 221 /* BinaryExpression */) {
@@ -146490,7 +146884,9 @@ var ts;
146490
146884
  var containerList = getListByPosition(position, precedingToken.parent, sourceFile);
146491
146885
  // use list position if the preceding token is before any list items
146492
146886
  if (containerList && !ts.rangeContainsRange(containerList, precedingToken)) {
146493
- return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize; // TODO: GH#18217
146887
+ var useTheSameBaseIndentation = [213 /* FunctionExpression */, 214 /* ArrowFunction */].indexOf(currentToken.parent.kind) !== -1;
146888
+ var indentSize = useTheSameBaseIndentation ? 0 : options.indentSize;
146889
+ return getActualIndentationForListStartLine(containerList, sourceFile, options) + indentSize; // TODO: GH#18217
146494
146890
  }
146495
146891
  return getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options);
146496
146892
  }
@@ -148003,8 +148399,11 @@ var ts;
148003
148399
  function isTrivia(s) {
148004
148400
  return ts.skipTrivia(s, 0) === s.length;
148005
148401
  }
148402
+ // A transformation context that won't perform parenthesization, as some parenthesization rules
148403
+ // are more aggressive than is strictly necessary.
148404
+ var textChangesTransformationContext = __assign(__assign({}, ts.nullTransformationContext), { factory: ts.createNodeFactory(ts.nullTransformationContext.factory.flags | 1 /* NoParenthesizerRules */, ts.nullTransformationContext.factory.baseFactory) });
148006
148405
  function assignPositionsToNode(node) {
148007
- var visited = ts.visitEachChild(node, assignPositionsToNode, ts.nullTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
148406
+ var visited = ts.visitEachChild(node, assignPositionsToNode, textChangesTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
148008
148407
  // create proxy node for non synthesized nodes
148009
148408
  var newNode = ts.nodeIsSynthesized(visited) ? visited : Object.create(visited);
148010
148409
  ts.setTextRangePosEnd(newNode, getPos(node), getEnd(node));
@@ -153056,7 +153455,7 @@ var ts;
153056
153455
  var param = signature.parameters[argIndex].valueDeclaration;
153057
153456
  if (!(param && ts.isParameter(param) && ts.isIdentifier(param.name)))
153058
153457
  return undefined;
153059
- var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getTypeAtLocation(param), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
153458
+ var properties = ts.arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent), checker.getParameterType(signature, argIndex), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
153060
153459
  if (!ts.length(properties))
153061
153460
  return undefined;
153062
153461
  return { kind: 3 /* ObjectLiteral */, token: param.name, properties: properties, parentDeclaration: parent };
@@ -155969,7 +156368,7 @@ var ts;
155969
156368
  var modifiers = visibilityModifier ? ts.factory.createNodeArray([visibilityModifier]) : undefined;
155970
156369
  var type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration));
155971
156370
  var optional = !!(symbol.flags & 16777216 /* Optional */);
155972
- var ambient = !!(enclosingDeclaration.flags & 8388608 /* Ambient */) || isAmbient;
156371
+ var ambient = !!(enclosingDeclaration.flags & 16777216 /* Ambient */) || isAmbient;
155973
156372
  var quotePreference = ts.getQuotePreference(sourceFile, preferences);
155974
156373
  switch (declaration.kind) {
155975
156374
  case 166 /* PropertySignature */:
@@ -156064,7 +156463,11 @@ var ts;
156064
156463
  var program = context.program;
156065
156464
  var checker = program.getTypeChecker();
156066
156465
  var scriptTarget = ts.getEmitScriptTarget(program.getCompilerOptions());
156067
- var flags = 1 /* NoTruncation */ | 1073741824 /* NoUndefinedOptionalParameterType */ | 256 /* SuppressAnyReturnType */ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0);
156466
+ var flags = 1 /* NoTruncation */
156467
+ | 1073741824 /* NoUndefinedOptionalParameterType */
156468
+ | 256 /* SuppressAnyReturnType */
156469
+ | 524288 /* AllowEmptyTuple */
156470
+ | (quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */);
156068
156471
  var signatureDeclaration = checker.signatureToSignatureDeclaration(signature, kind, enclosingDeclaration, flags, getNoopSymbolTrackerWithResolver(context));
156069
156472
  if (!signatureDeclaration) {
156070
156473
  return undefined;
@@ -157542,6 +157945,10 @@ var ts;
157542
157945
  }
157543
157946
  break;
157544
157947
  }
157948
+ case 200 /* ImportType */:
157949
+ var importTypeNode = parent;
157950
+ changes.replaceNode(importingSourceFile, parent, ts.factory.createImportTypeNode(importTypeNode.argument, ts.factory.createIdentifier(exportName), importTypeNode.typeArguments, importTypeNode.isTypeOf));
157951
+ break;
157545
157952
  default:
157546
157953
  ts.Debug.failBadSyntaxKind(parent);
157547
157954
  }
@@ -158482,7 +158889,7 @@ var ts;
158482
158889
  // cannot find either start or end node
158483
158890
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
158484
158891
  }
158485
- if (start.flags & 4194304 /* JSDoc */) {
158892
+ if (start.flags & 8388608 /* JSDoc */) {
158486
158893
  return { errors: [ts.createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractJSDoc)] };
158487
158894
  }
158488
158895
  if (start.parent !== end.parent) {
@@ -158608,7 +159015,7 @@ var ts;
158608
159015
  if (!ts.isStatement(nodeToCheck) && !(ts.isExpressionNode(nodeToCheck) && isExtractableExpression(nodeToCheck)) && !isStringLiteralJsxAttribute(nodeToCheck)) {
158609
159016
  return [ts.createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
158610
159017
  }
158611
- if (nodeToCheck.flags & 8388608 /* Ambient */) {
159018
+ if (nodeToCheck.flags & 16777216 /* Ambient */) {
158612
159019
  return [ts.createDiagnosticForNode(nodeToCheck, Messages.cannotExtractAmbientBlock)];
158613
159020
  }
158614
159021
  // If we're in a class, see whether we're in a static region (static property initializer, static method, class constructor parameter default)
@@ -158798,7 +159205,8 @@ var ts;
158798
159205
  return undefined;
158799
159206
  }
158800
159207
  function isScope(node) {
158801
- return ts.isFunctionLikeDeclaration(node) || ts.isSourceFile(node) || ts.isModuleBlock(node) || ts.isClassLike(node);
159208
+ return ts.isArrowFunction(node) ? ts.isFunctionBody(node.body) :
159209
+ ts.isFunctionLikeDeclaration(node) || ts.isSourceFile(node) || ts.isModuleBlock(node) || ts.isClassLike(node);
158802
159210
  }
158803
159211
  /**
158804
159212
  * Computes possible places we could extract the function into. For example,
@@ -160139,6 +160547,7 @@ var ts;
160139
160547
  }
160140
160548
  function doTypedefChange(changes, file, name, info) {
160141
160549
  var firstStatement = info.firstStatement, selection = info.selection, typeParameters = info.typeParameters;
160550
+ ts.setEmitFlags(selection, 1536 /* NoComments */ | 2048 /* NoNestedComments */);
160142
160551
  var node = ts.factory.createJSDocTypedefTag(ts.factory.createIdentifier("typedef"), ts.factory.createJSDocTypeExpression(selection), ts.factory.createIdentifier(name));
160143
160552
  var templates = [];
160144
160553
  ts.forEach(typeParameters, function (typeParameter) {
@@ -162169,7 +162578,7 @@ var ts;
162169
162578
  kind === 80 /* PrivateIdentifier */ ? new PrivateIdentifierObject(80 /* PrivateIdentifier */, pos, end) :
162170
162579
  new TokenObject(kind, pos, end);
162171
162580
  node.parent = parent;
162172
- node.flags = parent.flags & 25358336 /* ContextFlags */;
162581
+ node.flags = parent.flags & 50720768 /* ContextFlags */;
162173
162582
  return node;
162174
162583
  }
162175
162584
  var NodeObject = /** @class */ (function () {
@@ -163625,7 +164034,7 @@ var ts;
163625
164034
  }
163626
164035
  /// References and Occurrences
163627
164036
  function getOccurrencesAtPosition(fileName, position) {
163628
- 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 })); }); });
164037
+ 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 })); }); });
163629
164038
  }
163630
164039
  function getDocumentHighlights(fileName, position, filesToSearch) {
163631
164040
  var normalizedFileName = ts.normalizePath(fileName);
@@ -163654,7 +164063,7 @@ var ts;
163654
164063
  }
163655
164064
  function getReferencesAtPosition(fileName, position) {
163656
164065
  synchronizeHostData();
163657
- return getReferencesWorker(ts.getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: 1 /* References */ }, function (entry, node, checker) { return ts.FindAllReferences.toReferenceEntry(entry, checker.getSymbolAtLocation(node)); });
164066
+ return getReferencesWorker(ts.getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: 1 /* References */ }, ts.FindAllReferences.toReferenceEntry);
163658
164067
  }
163659
164068
  function getReferencesWorker(node, position, options, cb) {
163660
164069
  synchronizeHostData();
@@ -163669,10 +164078,8 @@ var ts;
163669
164078
  return ts.FindAllReferences.findReferencedSymbols(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position);
163670
164079
  }
163671
164080
  function getFileReferences(fileName) {
163672
- var _a;
163673
164081
  synchronizeHostData();
163674
- var moduleSymbol = (_a = program.getSourceFile(fileName)) === null || _a === void 0 ? void 0 : _a.symbol;
163675
- return ts.FindAllReferences.Core.getReferencesForFileName(fileName, program, program.getSourceFiles()).map(function (r) { return ts.FindAllReferences.toReferenceEntry(r, moduleSymbol); });
164082
+ return ts.FindAllReferences.Core.getReferencesForFileName(fileName, program, program.getSourceFiles()).map(ts.FindAllReferences.toReferenceEntry);
163676
164083
  }
163677
164084
  function getNavigateToItems(searchValue, maxResultCount, fileName, excludeDtsFiles) {
163678
164085
  if (excludeDtsFiles === void 0) { excludeDtsFiles = false; }
@@ -164145,7 +164552,7 @@ var ts;
164145
164552
  }
164146
164553
  function isUnclosedFragment(_a) {
164147
164554
  var closingFragment = _a.closingFragment, parent = _a.parent;
164148
- return !!(closingFragment.flags & 65536 /* ThisNodeHasError */) || (ts.isJsxFragment(parent) && isUnclosedFragment(parent));
164555
+ return !!(closingFragment.flags & 131072 /* ThisNodeHasError */) || (ts.isJsxFragment(parent) && isUnclosedFragment(parent));
164149
164556
  }
164150
164557
  function getSpanOfEnclosingComment(fileName, position, onlyMultiLine) {
164151
164558
  var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
@@ -164593,7 +165000,7 @@ var ts;
164593
165000
  tokenAtLocation = preceding;
164594
165001
  }
164595
165002
  // Cannot set breakpoint in ambient declarations
164596
- if (tokenAtLocation.flags & 8388608 /* Ambient */) {
165003
+ if (tokenAtLocation.flags & 16777216 /* Ambient */) {
164597
165004
  return undefined;
164598
165005
  }
164599
165006
  // Get the span in the node based on its syntax
@@ -173513,6 +173920,7 @@ var ts;
173513
173920
  logger.info("Finding references to " + location.fileName + " position " + location.pos + " in project " + project.getProjectName());
173514
173921
  var projectOutputs = project.getLanguageService().findReferences(location.fileName, location.pos);
173515
173922
  if (projectOutputs) {
173923
+ var clearIsDefinition = projectOutputs[0].references[0].isDefinition === undefined;
173516
173924
  var _loop_9 = function (referencedSymbol) {
173517
173925
  var mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(referencedSymbol.definition));
173518
173926
  var definition = mappedDefinitionFile === undefined ?
@@ -173526,6 +173934,9 @@ var ts;
173526
173934
  var ref = _b[_a];
173527
173935
  // If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
173528
173936
  if (!ts.contains(symbolToAddTo.references, ref, ts.documentSpansEqual) && !getMappedLocation(project, documentSpanLocation(ref))) {
173937
+ if (clearIsDefinition) {
173938
+ delete ref.isDefinition;
173939
+ }
173529
173940
  symbolToAddTo.references.push(ref);
173530
173941
  }
173531
173942
  }