typescript 5.4.0-dev.20240108 → 5.4.0-dev.20240110

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
@@ -1655,7 +1655,6 @@ __export(server_exports, {
1655
1655
  isPackedArrayLiteral: () => isPackedArrayLiteral,
1656
1656
  isParameter: () => isParameter,
1657
1657
  isParameterDeclaration: () => isParameterDeclaration,
1658
- isParameterOrCatchClauseVariable: () => isParameterOrCatchClauseVariable,
1659
1658
  isParameterPropertyDeclaration: () => isParameterPropertyDeclaration,
1660
1659
  isParameterPropertyModifier: () => isParameterPropertyModifier,
1661
1660
  isParenthesizedExpression: () => isParenthesizedExpression,
@@ -2341,7 +2340,7 @@ module.exports = __toCommonJS(server_exports);
2341
2340
 
2342
2341
  // src/compiler/corePublic.ts
2343
2342
  var versionMajorMinor = "5.4";
2344
- var version = `${versionMajorMinor}.0-dev.20240108`;
2343
+ var version = `${versionMajorMinor}.0-dev.20240110`;
2345
2344
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2346
2345
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2347
2346
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -16547,7 +16546,7 @@ function isPartOfTypeNode(node) {
16547
16546
  case 116 /* VoidKeyword */:
16548
16547
  return node.parent.kind !== 222 /* VoidExpression */;
16549
16548
  case 233 /* ExpressionWithTypeArguments */:
16550
- return isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
16549
+ return isPartOfTypeExpressionWithTypeArguments(node);
16551
16550
  case 168 /* TypeParameter */:
16552
16551
  return node.parent.kind === 200 /* MappedType */ || node.parent.kind === 195 /* InferType */;
16553
16552
  case 80 /* Identifier */:
@@ -16572,7 +16571,7 @@ function isPartOfTypeNode(node) {
16572
16571
  }
16573
16572
  switch (parent2.kind) {
16574
16573
  case 233 /* ExpressionWithTypeArguments */:
16575
- return isHeritageClause(parent2.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(parent2);
16574
+ return isPartOfTypeExpressionWithTypeArguments(parent2);
16576
16575
  case 168 /* TypeParameter */:
16577
16576
  return node === parent2.constraint;
16578
16577
  case 352 /* JSDocTemplateTag */:
@@ -16606,6 +16605,9 @@ function isPartOfTypeNode(node) {
16606
16605
  }
16607
16606
  return false;
16608
16607
  }
16608
+ function isPartOfTypeExpressionWithTypeArguments(node) {
16609
+ return isJSDocImplementsTag(node.parent) || isJSDocAugmentsTag(node.parent) || isHeritageClause(node.parent) && !isExpressionWithTypeArgumentsInClassExtendsClause(node);
16610
+ }
16609
16611
  function isChildOfNodeWithKind(node, kind) {
16610
16612
  while (node) {
16611
16613
  if (node.kind === kind) {
@@ -20241,7 +20243,7 @@ function Symbol4(flags, name) {
20241
20243
  this.exportSymbol = void 0;
20242
20244
  this.constEnumOnlyModule = void 0;
20243
20245
  this.isReferenced = void 0;
20244
- this.isAssigned = void 0;
20246
+ this.lastAssignmentPos = void 0;
20245
20247
  this.links = void 0;
20246
20248
  }
20247
20249
  function Type3(checker, flags) {
@@ -21716,10 +21718,6 @@ function isInfinityOrNaNString(name) {
21716
21718
  function isCatchClauseVariableDeclaration(node) {
21717
21719
  return node.kind === 260 /* VariableDeclaration */ && node.parent.kind === 299 /* CatchClause */;
21718
21720
  }
21719
- function isParameterOrCatchClauseVariable(symbol) {
21720
- const declaration = symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration);
21721
- return !!declaration && (isParameter(declaration) || isCatchClauseVariableDeclaration(declaration));
21722
- }
21723
21721
  function isFunctionExpressionOrArrowFunction(node) {
21724
21722
  return node.kind === 218 /* FunctionExpression */ || node.kind === 219 /* ArrowFunction */;
21725
21723
  }
@@ -49024,6 +49022,14 @@ function createTypeChecker(host) {
49024
49022
  emptyArray,
49025
49023
  emptyArray
49026
49024
  );
49025
+ var resolvingApparentMappedType = createAnonymousType(
49026
+ /*symbol*/
49027
+ void 0,
49028
+ emptySymbols,
49029
+ emptyArray,
49030
+ emptyArray,
49031
+ emptyArray
49032
+ );
49027
49033
  var markerSuperType = createTypeParameter();
49028
49034
  var markerSubType = createTypeParameter();
49029
49035
  markerSubType.constraint = markerSuperType;
@@ -52073,29 +52079,7 @@ function createTypeChecker(host) {
52073
52079
  function getContainersOfSymbol(symbol, enclosingDeclaration, meaning) {
52074
52080
  const container = getParentOfSymbol(symbol);
52075
52081
  if (container && !(symbol.flags & 262144 /* TypeParameter */)) {
52076
- const additionalContainers = mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer);
52077
- const reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration);
52078
- const objectLiteralContainer = getVariableDeclarationOfObjectLiteral(container, meaning);
52079
- if (enclosingDeclaration && container.flags & getQualifiedLeftMeaning(meaning) && getAccessibleSymbolChain(
52080
- container,
52081
- enclosingDeclaration,
52082
- 1920 /* Namespace */,
52083
- /*useOnlyExternalAliasing*/
52084
- false
52085
- )) {
52086
- return append(concatenate(concatenate([container], additionalContainers), reexportContainers), objectLiteralContainer);
52087
- }
52088
- const firstVariableMatch = !(container.flags & getQualifiedLeftMeaning(meaning)) && container.flags & 788968 /* Type */ && getDeclaredTypeOfSymbol(container).flags & 524288 /* Object */ && meaning === 111551 /* Value */ ? forEachSymbolTableInScope(enclosingDeclaration, (t) => {
52089
- return forEachEntry(t, (s) => {
52090
- if (s.flags & getQualifiedLeftMeaning(meaning) && getTypeOfSymbol(s) === getDeclaredTypeOfSymbol(container)) {
52091
- return s;
52092
- }
52093
- });
52094
- }) : void 0;
52095
- let res = firstVariableMatch ? [firstVariableMatch, ...additionalContainers, container] : [...additionalContainers, container];
52096
- res = append(res, objectLiteralContainer);
52097
- res = addRange(res, reexportContainers);
52098
- return res;
52082
+ return getWithAlternativeContainers(container);
52099
52083
  }
52100
52084
  const candidates = mapDefined(symbol.declarations, (d) => {
52101
52085
  if (!isAmbientModule(d) && d.parent) {
@@ -52117,7 +52101,40 @@ function createTypeChecker(host) {
52117
52101
  if (!length(candidates)) {
52118
52102
  return void 0;
52119
52103
  }
52120
- return mapDefined(candidates, (candidate) => getAliasForSymbolInContainer(candidate, symbol) ? candidate : void 0);
52104
+ const containers = mapDefined(candidates, (candidate) => getAliasForSymbolInContainer(candidate, symbol) ? candidate : void 0);
52105
+ let bestContainers = [];
52106
+ let alternativeContainers = [];
52107
+ for (const container2 of containers) {
52108
+ const [bestMatch, ...rest] = getWithAlternativeContainers(container2);
52109
+ bestContainers = append(bestContainers, bestMatch);
52110
+ alternativeContainers = addRange(alternativeContainers, rest);
52111
+ }
52112
+ return concatenate(bestContainers, alternativeContainers);
52113
+ function getWithAlternativeContainers(container2) {
52114
+ const additionalContainers = mapDefined(container2.declarations, fileSymbolIfFileSymbolExportEqualsContainer);
52115
+ const reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration);
52116
+ const objectLiteralContainer = getVariableDeclarationOfObjectLiteral(container2, meaning);
52117
+ if (enclosingDeclaration && container2.flags & getQualifiedLeftMeaning(meaning) && getAccessibleSymbolChain(
52118
+ container2,
52119
+ enclosingDeclaration,
52120
+ 1920 /* Namespace */,
52121
+ /*useOnlyExternalAliasing*/
52122
+ false
52123
+ )) {
52124
+ return append(concatenate(concatenate([container2], additionalContainers), reexportContainers), objectLiteralContainer);
52125
+ }
52126
+ const firstVariableMatch = !(container2.flags & getQualifiedLeftMeaning(meaning)) && container2.flags & 788968 /* Type */ && getDeclaredTypeOfSymbol(container2).flags & 524288 /* Object */ && meaning === 111551 /* Value */ ? forEachSymbolTableInScope(enclosingDeclaration, (t) => {
52127
+ return forEachEntry(t, (s) => {
52128
+ if (s.flags & getQualifiedLeftMeaning(meaning) && getTypeOfSymbol(s) === getDeclaredTypeOfSymbol(container2)) {
52129
+ return s;
52130
+ }
52131
+ });
52132
+ }) : void 0;
52133
+ let res = firstVariableMatch ? [firstVariableMatch, ...additionalContainers, container2] : [...additionalContainers, container2];
52134
+ res = append(res, objectLiteralContainer);
52135
+ res = addRange(res, reexportContainers);
52136
+ return res;
52137
+ }
52121
52138
  function fileSymbolIfFileSymbolExportEqualsContainer(d) {
52122
52139
  return container && getFileSymbolIfFileSymbolExportEqualsContainer(d, container);
52123
52140
  }
@@ -52155,6 +52172,13 @@ function createTypeChecker(host) {
52155
52172
  });
52156
52173
  }
52157
52174
  function getSymbolIfSameReference(s1, s2) {
52175
+ var _a, _b;
52176
+ if (s1.flags & 524288 /* TypeAlias */ && ((_a = s2.declarations) == null ? void 0 : _a.find(isTypeAlias))) {
52177
+ s2 = getDeclaredTypeOfTypeAlias(s2).aliasSymbol || s2;
52178
+ }
52179
+ if (s2.flags & 524288 /* TypeAlias */ && ((_b = s1.declarations) == null ? void 0 : _b.find(isTypeAlias))) {
52180
+ s1 = getDeclaredTypeOfTypeAlias(s1).aliasSymbol || s1;
52181
+ }
52158
52182
  if (getMergedSymbol(resolveSymbol(getMergedSymbol(s1))) === getMergedSymbol(resolveSymbol(getMergedSymbol(s2)))) {
52159
52183
  return s1;
52160
52184
  }
@@ -59893,14 +59917,30 @@ function createTypeChecker(host) {
59893
59917
  return !!(typeParameter.symbol && forEach(typeParameter.symbol.declarations, (decl) => isTypeParameterDeclaration(decl) && decl.default));
59894
59918
  }
59895
59919
  function getApparentTypeOfMappedType(type) {
59896
- return type.resolvedApparentType || (type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type));
59920
+ if (type.resolvedApparentType) {
59921
+ if (type.resolvedApparentType === resolvingApparentMappedType) {
59922
+ return type.resolvedApparentType = type;
59923
+ }
59924
+ return type.resolvedApparentType;
59925
+ }
59926
+ type.resolvedApparentType = resolvingApparentMappedType;
59927
+ return type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type);
59897
59928
  }
59898
59929
  function getResolvedApparentTypeOfMappedType(type) {
59899
- const typeVariable = getHomomorphicTypeVariable(type);
59900
- if (typeVariable && !type.declaration.nameType) {
59901
- const constraint = getConstraintOfTypeParameter(typeVariable);
59930
+ const mappedType = type.target || type;
59931
+ const typeVariable = getHomomorphicTypeVariable(mappedType);
59932
+ if (typeVariable && !mappedType.declaration.nameType) {
59933
+ let constraint;
59934
+ if (!type.target) {
59935
+ constraint = getConstraintOfTypeParameter(typeVariable);
59936
+ } else {
59937
+ const modifiersConstraint = getConstraintOfType(getModifiersTypeFromMappedType(type));
59938
+ if (modifiersConstraint) {
59939
+ constraint = getApparentType(modifiersConstraint);
59940
+ }
59941
+ }
59902
59942
  if (constraint && everyType(constraint, isArrayOrTupleType)) {
59903
- return instantiateType(type, prependTypeMapping(typeVariable, constraint, type.mapper));
59943
+ return instantiateType(mappedType, prependTypeMapping(typeVariable, constraint, mappedType.mapper));
59904
59944
  }
59905
59945
  }
59906
59946
  return type;
@@ -59991,6 +60031,7 @@ function createTypeChecker(host) {
59991
60031
  clone2.parent = (_c = (_b = singleProp.valueDeclaration) == null ? void 0 : _b.symbol) == null ? void 0 : _c.parent;
59992
60032
  clone2.links.containingType = containingType;
59993
60033
  clone2.links.mapper = links == null ? void 0 : links.mapper;
60034
+ clone2.links.writeType = getWriteTypeOfSymbol(singleProp);
59994
60035
  return clone2;
59995
60036
  } else {
59996
60037
  return singleProp;
@@ -66616,6 +66657,18 @@ function createTypeChecker(host) {
66616
66657
  }
66617
66658
  return result2;
66618
66659
  }
66660
+ function getApparentMappedTypeKeys(nameType, targetType) {
66661
+ const modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType));
66662
+ const mappedKeys = [];
66663
+ forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(
66664
+ modifiersType,
66665
+ 8576 /* StringOrNumberLiteralOrUnique */,
66666
+ /*stringsOnly*/
66667
+ false,
66668
+ (t) => void mappedKeys.push(instantiateType(nameType, appendTypeMapping(targetType.mapper, getTypeParameterFromMappedType(targetType), t)))
66669
+ );
66670
+ return getUnionType(mappedKeys);
66671
+ }
66619
66672
  function structuredTypeRelatedToWorker(source2, target2, reportErrors2, intersectionState, saveErrorInfo) {
66620
66673
  let result2;
66621
66674
  let originalErrorInfo;
@@ -66798,16 +66851,8 @@ function createTypeChecker(host) {
66798
66851
  const constraintType = getConstraintTypeFromMappedType(targetType);
66799
66852
  let targetKeys;
66800
66853
  if (nameType && isMappedTypeWithKeyofConstraintDeclaration(targetType)) {
66801
- const modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType));
66802
- const mappedKeys = [];
66803
- forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(
66804
- modifiersType,
66805
- 8576 /* StringOrNumberLiteralOrUnique */,
66806
- /*stringsOnly*/
66807
- false,
66808
- (t) => void mappedKeys.push(instantiateType(nameType, appendTypeMapping(targetType.mapper, getTypeParameterFromMappedType(targetType), t)))
66809
- );
66810
- targetKeys = getUnionType([...mappedKeys, nameType]);
66854
+ const mappedKeys = getApparentMappedTypeKeys(nameType, targetType);
66855
+ targetKeys = getUnionType([mappedKeys, nameType]);
66811
66856
  } else {
66812
66857
  targetKeys = nameType || constraintType;
66813
66858
  }
@@ -66978,9 +67023,18 @@ function createTypeChecker(host) {
66978
67023
  }
66979
67024
  }
66980
67025
  } else if (sourceFlags & 4194304 /* Index */) {
66981
- if (result2 = isRelatedTo(keyofConstraintType, target2, 1 /* Source */, reportErrors2)) {
67026
+ const isDeferredMappedIndex = shouldDeferIndexType(source2.type, source2.indexFlags) && getObjectFlags(source2.type) & 32 /* Mapped */;
67027
+ if (result2 = isRelatedTo(keyofConstraintType, target2, 1 /* Source */, reportErrors2 && !isDeferredMappedIndex)) {
66982
67028
  return result2;
66983
67029
  }
67030
+ if (isDeferredMappedIndex) {
67031
+ const mappedType = source2.type;
67032
+ const nameType = getNameTypeFromMappedType(mappedType);
67033
+ const sourceMappedKeys = nameType && isMappedTypeWithKeyofConstraintDeclaration(mappedType) ? getApparentMappedTypeKeys(nameType, mappedType) : nameType || getConstraintTypeFromMappedType(mappedType);
67034
+ if (result2 = isRelatedTo(sourceMappedKeys, target2, 1 /* Source */, reportErrors2)) {
67035
+ return result2;
67036
+ }
67037
+ }
66984
67038
  } else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
66985
67039
  if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
66986
67040
  const constraint = getBaseConstraintOfType(source2);
@@ -70917,7 +70971,7 @@ function createTypeChecker(host) {
70917
70971
  case 80 /* Identifier */:
70918
70972
  if (!isThisInTypeQuery(node)) {
70919
70973
  const symbol = getResolvedSymbol(node);
70920
- return isConstantVariable(symbol) || isParameterOrCatchClauseVariable(symbol) && !isSymbolAssigned(symbol);
70974
+ return isConstantVariable(symbol) || isParameterOrMutableLocalVariable(symbol) && !isSymbolAssigned(symbol);
70921
70975
  }
70922
70976
  break;
70923
70977
  case 211 /* PropertyAccessExpression */:
@@ -70926,7 +70980,7 @@ function createTypeChecker(host) {
70926
70980
  case 206 /* ObjectBindingPattern */:
70927
70981
  case 207 /* ArrayBindingPattern */:
70928
70982
  const rootDeclaration = getRootDeclaration(node.parent);
70929
- return isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
70983
+ return isParameter(rootDeclaration) || isCatchClauseVariableDeclaration(rootDeclaration) ? !isSomeSymbolAssigned(rootDeclaration) : isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
70930
70984
  }
70931
70985
  return false;
70932
70986
  }
@@ -72007,10 +72061,17 @@ function createTypeChecker(host) {
72007
72061
  return findAncestor(node.parent, (node2) => isFunctionLike(node2) && !getImmediatelyInvokedFunctionExpression(node2) || node2.kind === 268 /* ModuleBlock */ || node2.kind === 312 /* SourceFile */ || node2.kind === 172 /* PropertyDeclaration */);
72008
72062
  }
72009
72063
  function isSymbolAssigned(symbol) {
72010
- if (!symbol.valueDeclaration) {
72064
+ return !isPastLastAssignment(
72065
+ symbol,
72066
+ /*location*/
72067
+ void 0
72068
+ );
72069
+ }
72070
+ function isPastLastAssignment(symbol, location) {
72071
+ const parent2 = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
72072
+ if (!parent2) {
72011
72073
  return false;
72012
72074
  }
72013
- const parent2 = getRootDeclaration(symbol.valueDeclaration).parent;
72014
72075
  const links = getNodeLinks(parent2);
72015
72076
  if (!(links.flags & 131072 /* AssignmentsMarked */)) {
72016
72077
  links.flags |= 131072 /* AssignmentsMarked */;
@@ -72018,7 +72079,7 @@ function createTypeChecker(host) {
72018
72079
  markNodeAssignments(parent2);
72019
72080
  }
72020
72081
  }
72021
- return symbol.isAssigned || false;
72082
+ return !symbol.lastAssignmentPos || location && symbol.lastAssignmentPos < location.pos;
72022
72083
  }
72023
72084
  function isSomeSymbolAssigned(rootDeclaration) {
72024
72085
  Debug.assert(isVariableDeclaration(rootDeclaration) || isParameter(rootDeclaration));
@@ -72031,23 +72092,81 @@ function createTypeChecker(host) {
72031
72092
  return some(node.elements, (e) => e.kind !== 232 /* OmittedExpression */ && isSomeSymbolAssignedWorker(e.name));
72032
72093
  }
72033
72094
  function hasParentWithAssignmentsMarked(node) {
72034
- return !!findAncestor(node.parent, (node2) => (isFunctionLike(node2) || isCatchClause(node2)) && !!(getNodeLinks(node2).flags & 131072 /* AssignmentsMarked */));
72095
+ return !!findAncestor(node.parent, (node2) => isFunctionOrSourceFile(node2) && !!(getNodeLinks(node2).flags & 131072 /* AssignmentsMarked */));
72096
+ }
72097
+ function isFunctionOrSourceFile(node) {
72098
+ return isFunctionLikeDeclaration(node) || isSourceFile(node);
72035
72099
  }
72036
72100
  function markNodeAssignments(node) {
72037
- if (node.kind === 80 /* Identifier */) {
72038
- if (isAssignmentTarget(node)) {
72039
- const symbol = getResolvedSymbol(node);
72040
- if (isParameterOrCatchClauseVariable(symbol)) {
72041
- symbol.isAssigned = true;
72101
+ switch (node.kind) {
72102
+ case 80 /* Identifier */:
72103
+ if (isAssignmentTarget(node)) {
72104
+ const symbol = getResolvedSymbol(node);
72105
+ if (isParameterOrMutableLocalVariable(symbol) && symbol.lastAssignmentPos !== Number.MAX_VALUE) {
72106
+ const referencingFunction = findAncestor(node, isFunctionOrSourceFile);
72107
+ const declaringFunction = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
72108
+ symbol.lastAssignmentPos = referencingFunction === declaringFunction ? extendAssignmentPosition(node, symbol.valueDeclaration) : Number.MAX_VALUE;
72109
+ }
72042
72110
  }
72111
+ return;
72112
+ case 281 /* ExportSpecifier */:
72113
+ const exportDeclaration = node.parent.parent;
72114
+ if (!node.isTypeOnly && !exportDeclaration.isTypeOnly && !exportDeclaration.moduleSpecifier) {
72115
+ const symbol = resolveEntityName(
72116
+ node.propertyName || node.name,
72117
+ 111551 /* Value */,
72118
+ /*ignoreErrors*/
72119
+ true,
72120
+ /*dontResolveAlias*/
72121
+ true
72122
+ );
72123
+ if (symbol && isParameterOrMutableLocalVariable(symbol)) {
72124
+ symbol.lastAssignmentPos = Number.MAX_VALUE;
72125
+ }
72126
+ }
72127
+ return;
72128
+ case 264 /* InterfaceDeclaration */:
72129
+ case 265 /* TypeAliasDeclaration */:
72130
+ case 266 /* EnumDeclaration */:
72131
+ return;
72132
+ }
72133
+ if (isTypeNode(node)) {
72134
+ return;
72135
+ }
72136
+ forEachChild(node, markNodeAssignments);
72137
+ }
72138
+ function extendAssignmentPosition(node, declaration) {
72139
+ let pos = node.pos;
72140
+ while (node && node.pos > declaration.pos) {
72141
+ switch (node.kind) {
72142
+ case 243 /* VariableStatement */:
72143
+ case 244 /* ExpressionStatement */:
72144
+ case 245 /* IfStatement */:
72145
+ case 246 /* DoStatement */:
72146
+ case 247 /* WhileStatement */:
72147
+ case 248 /* ForStatement */:
72148
+ case 249 /* ForInStatement */:
72149
+ case 250 /* ForOfStatement */:
72150
+ case 254 /* WithStatement */:
72151
+ case 255 /* SwitchStatement */:
72152
+ case 258 /* TryStatement */:
72153
+ case 263 /* ClassDeclaration */:
72154
+ pos = node.end;
72043
72155
  }
72044
- } else {
72045
- forEachChild(node, markNodeAssignments);
72156
+ node = node.parent;
72046
72157
  }
72158
+ return pos;
72047
72159
  }
72048
72160
  function isConstantVariable(symbol) {
72049
72161
  return symbol.flags & 3 /* Variable */ && (getDeclarationNodeFlagsFromSymbol(symbol) & 6 /* Constant */) !== 0;
72050
72162
  }
72163
+ function isParameterOrMutableLocalVariable(symbol) {
72164
+ const declaration = symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration);
72165
+ return !!declaration && (isParameter(declaration) || isVariableDeclaration(declaration) && (isCatchClause(declaration.parent) || isMutableLocalVariableDeclaration(declaration)));
72166
+ }
72167
+ function isMutableLocalVariableDeclaration(declaration) {
72168
+ return !!(declaration.parent.flags & 1 /* Let */) && !(getCombinedModifierFlags(declaration) & 32 /* Export */ || declaration.parent.parent.kind === 243 /* VariableStatement */ && isGlobalSourceFile(declaration.parent.parent.parent));
72169
+ }
72051
72170
  function parameterInitializerContainsUndefined(declaration) {
72052
72171
  const links = getNodeLinks(declaration);
72053
72172
  if (links.parameterInitializerContainsUndefined === void 0) {
@@ -72296,7 +72415,7 @@ function createTypeChecker(host) {
72296
72415
  const isModuleExports = symbol.flags & 134217728 /* ModuleExports */;
72297
72416
  const typeIsAutomatic = type === autoType || type === autoArrayType;
72298
72417
  const isAutomaticTypeInNonNull = typeIsAutomatic && node.parent.kind === 235 /* NonNullExpression */;
72299
- while (flowContainer !== declarationContainer && (flowContainer.kind === 218 /* FunctionExpression */ || flowContainer.kind === 219 /* ArrowFunction */ || isObjectLiteralOrClassExpressionMethodOrAccessor(flowContainer)) && (isConstantVariable(localOrExportSymbol) && type !== autoArrayType || isParameter2 && !isSymbolAssigned(localOrExportSymbol))) {
72418
+ while (flowContainer !== declarationContainer && (flowContainer.kind === 218 /* FunctionExpression */ || flowContainer.kind === 219 /* ArrowFunction */ || isObjectLiteralOrClassExpressionMethodOrAccessor(flowContainer)) && (isConstantVariable(localOrExportSymbol) && type !== autoArrayType || isParameterOrMutableLocalVariable(localOrExportSymbol) && isPastLastAssignment(localOrExportSymbol, node))) {
72300
72419
  flowContainer = getControlFlowContainer(flowContainer);
72301
72420
  }
72302
72421
  const assumeInitialized = isParameter2 || isAlias || isOuterVariable || isSpreadDestructuringAssignmentTarget || isModuleExports || isSameScopedBindingElement(node, declaration) || type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & (3 /* AnyOrUnknown */ | 16384 /* Void */)) !== 0 || isInTypeQuery(node) || isInAmbientOrTypeNode(node) || node.parent.kind === 281 /* ExportSpecifier */) || node.parent.kind === 235 /* NonNullExpression */ || declaration.kind === 260 /* VariableDeclaration */ && declaration.exclamationToken || declaration.flags & 33554432 /* Ambient */;
@@ -118337,7 +118456,14 @@ function createPrinter(printerOptions = {}, handlers = {}) {
118337
118456
  function willEmitLeadingNewLine(node) {
118338
118457
  if (!currentSourceFile)
118339
118458
  return false;
118340
- if (some(getLeadingCommentRanges(currentSourceFile.text, node.pos), commentWillEmitNewLine))
118459
+ const leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos);
118460
+ if (leadingCommentRanges) {
118461
+ const parseNode = getParseTreeNode(node);
118462
+ if (parseNode && isParenthesizedExpression(parseNode.parent)) {
118463
+ return true;
118464
+ }
118465
+ }
118466
+ if (some(leadingCommentRanges, commentWillEmitNewLine))
118341
118467
  return true;
118342
118468
  if (some(getSyntheticLeadingComments(node), commentWillEmitNewLine))
118343
118469
  return true;
@@ -152295,14 +152421,14 @@ function promoteFromTypeOnly(changes, aliasDeclaration, program, sourceFile, pre
152295
152421
  aliasDeclaration.name
152296
152422
  );
152297
152423
  const comparer = ts_OrganizeImports_exports.getOrganizeImportsComparer(preferences, sortKind === 2 /* CaseInsensitive */);
152298
- const insertionIndex = ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, comparer);
152299
- if (aliasDeclaration.parent.elements.indexOf(aliasDeclaration) !== insertionIndex) {
152424
+ const insertionIndex = ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier, comparer, preferences);
152425
+ if (insertionIndex !== aliasDeclaration.parent.elements.indexOf(aliasDeclaration)) {
152300
152426
  changes.delete(sourceFile, aliasDeclaration);
152301
152427
  changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
152302
152428
  return aliasDeclaration;
152303
152429
  }
152304
152430
  }
152305
- changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken());
152431
+ changes.deleteRange(sourceFile, { pos: getTokenPosOfNode(aliasDeclaration.getFirstToken()), end: getTokenPosOfNode(aliasDeclaration.propertyName ?? aliasDeclaration.name) });
152306
152432
  return aliasDeclaration;
152307
152433
  } else {
152308
152434
  Debug.assert(aliasDeclaration.parent.parent.isTypeOnly);
@@ -152398,7 +152524,7 @@ function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImpor
152398
152524
  const specifierSort = (existingSpecifiers == null ? void 0 : existingSpecifiers.length) && ts_OrganizeImports_exports.detectImportSpecifierSorting(existingSpecifiers, preferences);
152399
152525
  if (specifierSort && !(ignoreCaseForSorting && specifierSort === 1 /* CaseSensitive */)) {
152400
152526
  for (const spec of newSpecifiers) {
152401
- const insertionIndex = promoteFromTypeOnly2 && !spec.isTypeOnly ? 0 : ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(existingSpecifiers, spec, comparer);
152527
+ const insertionIndex = promoteFromTypeOnly2 && !spec.isTypeOnly ? 0 : ts_OrganizeImports_exports.getImportSpecifierInsertionIndex(existingSpecifiers, spec, comparer, preferences);
152402
152528
  changes.insertImportSpecifierAtIndex(sourceFile, spec, clause.namedBindings, insertionIndex);
152403
152529
  }
152404
152530
  } else if (existingSpecifiers == null ? void 0 : existingSpecifiers.length) {
@@ -167263,14 +167389,14 @@ function organizeImports(sourceFile, formatContext, host, program, preferences,
167263
167389
  if (shouldRemove)
167264
167390
  importGroup = removeUnusedImports(importGroup, sourceFile, program);
167265
167391
  if (shouldCombine)
167266
- importGroup = coalesceImportsWorker(importGroup, comparer, sourceFile);
167392
+ importGroup = coalesceImportsWorker(importGroup, comparer, sourceFile, preferences);
167267
167393
  if (shouldSort)
167268
167394
  importGroup = stableSort(importGroup, (s1, s2) => compareImportsOrRequireStatements(s1, s2, comparer));
167269
167395
  return importGroup;
167270
167396
  };
167271
167397
  topLevelImportGroupDecls.forEach((importGroupDecl) => organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier));
167272
167398
  if (mode !== "RemoveUnused" /* RemoveUnused */) {
167273
- getTopLevelExportGroups(sourceFile).forEach((exportGroupDecl) => organizeImportsWorker(exportGroupDecl, (group2) => coalesceExportsWorker(group2, comparer)));
167399
+ getTopLevelExportGroups(sourceFile).forEach((exportGroupDecl) => organizeImportsWorker(exportGroupDecl, (group2) => coalesceExportsWorker(group2, comparer, preferences)));
167274
167400
  }
167275
167401
  for (const ambientModule of sourceFile.statements.filter(isAmbientModule)) {
167276
167402
  if (!ambientModule.body)
@@ -167279,7 +167405,7 @@ function organizeImports(sourceFile, formatContext, host, program, preferences,
167279
167405
  ambientModuleImportGroupDecls.forEach((importGroupDecl) => organizeImportsWorker(importGroupDecl, processImportsOfSameModuleSpecifier));
167280
167406
  if (mode !== "RemoveUnused" /* RemoveUnused */) {
167281
167407
  const ambientModuleExportDecls = ambientModule.body.statements.filter(isExportDeclaration);
167282
- organizeImportsWorker(ambientModuleExportDecls, (group2) => coalesceExportsWorker(group2, comparer));
167408
+ organizeImportsWorker(ambientModuleExportDecls, (group2) => coalesceExportsWorker(group2, comparer, preferences));
167283
167409
  }
167284
167410
  }
167285
167411
  return changeTracker.getChanges();
@@ -167411,11 +167537,11 @@ function hasModuleDeclarationMatchingSpecifier(sourceFile, moduleSpecifier) {
167411
167537
  function getExternalModuleName2(specifier) {
167412
167538
  return specifier !== void 0 && isStringLiteralLike(specifier) ? specifier.text : void 0;
167413
167539
  }
167414
- function coalesceImports(importGroup, ignoreCase, sourceFile) {
167540
+ function coalesceImports(importGroup, ignoreCase, sourceFile, preferences) {
167415
167541
  const comparer = getOrganizeImportsOrdinalStringComparer(ignoreCase);
167416
- return coalesceImportsWorker(importGroup, comparer, sourceFile);
167542
+ return coalesceImportsWorker(importGroup, comparer, sourceFile, preferences);
167417
167543
  }
167418
- function coalesceImportsWorker(importGroup, comparer, sourceFile) {
167544
+ function coalesceImportsWorker(importGroup, comparer, sourceFile, preferences) {
167419
167545
  if (importGroup.length === 0) {
167420
167546
  return importGroup;
167421
167547
  }
@@ -167469,7 +167595,7 @@ function coalesceImportsWorker(importGroup, comparer, sourceFile) {
167469
167595
  }
167470
167596
  newImportSpecifiers.push(...getNewImportSpecifiers(namedImports));
167471
167597
  const sortedImportSpecifiers = factory.createNodeArray(
167472
- sortSpecifiers(newImportSpecifiers, comparer),
167598
+ sortSpecifiers(newImportSpecifiers, comparer, preferences),
167473
167599
  firstNamedImport == null ? void 0 : firstNamedImport.importClause.namedBindings.elements.hasTrailingComma
167474
167600
  );
167475
167601
  const newNamedImports = sortedImportSpecifiers.length === 0 ? newDefaultImport ? void 0 : factory.createNamedImports(emptyArray) : firstNamedImport ? factory.updateNamedImports(firstNamedImport.importClause.namedBindings, sortedImportSpecifiers) : factory.createNamedImports(sortedImportSpecifiers);
@@ -167529,11 +167655,11 @@ function getCategorizedImports(importGroup) {
167529
167655
  regularImports
167530
167656
  };
167531
167657
  }
167532
- function coalesceExports(exportGroup, ignoreCase) {
167658
+ function coalesceExports(exportGroup, ignoreCase, preferences) {
167533
167659
  const comparer = getOrganizeImportsOrdinalStringComparer(ignoreCase);
167534
- return coalesceExportsWorker(exportGroup, comparer);
167660
+ return coalesceExportsWorker(exportGroup, comparer, preferences);
167535
167661
  }
167536
- function coalesceExportsWorker(exportGroup, comparer) {
167662
+ function coalesceExportsWorker(exportGroup, comparer, preferences) {
167537
167663
  if (exportGroup.length === 0) {
167538
167664
  return exportGroup;
167539
167665
  }
@@ -167548,7 +167674,7 @@ function coalesceExportsWorker(exportGroup, comparer) {
167548
167674
  }
167549
167675
  const newExportSpecifiers = [];
167550
167676
  newExportSpecifiers.push(...flatMap(exportGroup2, (i) => i.exportClause && isNamedExports(i.exportClause) ? i.exportClause.elements : emptyArray));
167551
- const sortedExportSpecifiers = sortSpecifiers(newExportSpecifiers, comparer);
167677
+ const sortedExportSpecifiers = sortSpecifiers(newExportSpecifiers, comparer, preferences);
167552
167678
  const exportDecl = exportGroup2[0];
167553
167679
  coalescedExports.push(
167554
167680
  factory.updateExportDeclaration(
@@ -167592,11 +167718,18 @@ function updateImportDeclarationAndClause(importDeclaration, name, namedBindings
167592
167718
  importDeclaration.attributes
167593
167719
  );
167594
167720
  }
167595
- function sortSpecifiers(specifiers, comparer) {
167596
- return stableSort(specifiers, (s1, s2) => compareImportOrExportSpecifiers(s1, s2, comparer));
167721
+ function sortSpecifiers(specifiers, comparer, preferences) {
167722
+ return stableSort(specifiers, (s1, s2) => compareImportOrExportSpecifiers(s1, s2, comparer, preferences));
167597
167723
  }
167598
- function compareImportOrExportSpecifiers(s1, s2, comparer) {
167599
- return compareBooleans(s1.isTypeOnly, s2.isTypeOnly) || comparer(s1.name.text, s2.name.text);
167724
+ function compareImportOrExportSpecifiers(s1, s2, comparer, preferences) {
167725
+ switch (preferences == null ? void 0 : preferences.organizeImportsTypeOrder) {
167726
+ case "first":
167727
+ return compareBooleans(s2.isTypeOnly, s1.isTypeOnly) || comparer(s1.name.text, s2.name.text);
167728
+ case "inline":
167729
+ return comparer(s1.name.text, s2.name.text);
167730
+ default:
167731
+ return compareBooleans(s1.isTypeOnly, s2.isTypeOnly) || comparer(s1.name.text, s2.name.text);
167732
+ }
167600
167733
  }
167601
167734
  function compareModuleSpecifiers2(m1, m2, ignoreCase) {
167602
167735
  const comparer = getOrganizeImportsOrdinalStringComparer(!!ignoreCase);
@@ -167718,8 +167851,26 @@ var ImportSpecifierSortingCache = class {
167718
167851
  }
167719
167852
  };
167720
167853
  var detectImportSpecifierSorting = memoizeCached((specifiers, preferences) => {
167721
- if (!arrayIsSorted(specifiers, (s1, s2) => compareBooleans(s1.isTypeOnly, s2.isTypeOnly))) {
167722
- return 0 /* None */;
167854
+ switch (preferences.organizeImportsTypeOrder) {
167855
+ case "first":
167856
+ if (!arrayIsSorted(specifiers, (s1, s2) => compareBooleans(s2.isTypeOnly, s1.isTypeOnly)))
167857
+ return 0 /* None */;
167858
+ break;
167859
+ case "inline":
167860
+ if (!arrayIsSorted(specifiers, (s1, s2) => {
167861
+ const comparer = getStringComparer(
167862
+ /*ignoreCase*/
167863
+ true
167864
+ );
167865
+ return comparer(s1.name.text, s2.name.text);
167866
+ })) {
167867
+ return 0 /* None */;
167868
+ }
167869
+ break;
167870
+ default:
167871
+ if (!arrayIsSorted(specifiers, (s1, s2) => compareBooleans(s1.isTypeOnly, s2.isTypeOnly)))
167872
+ return 0 /* None */;
167873
+ break;
167723
167874
  }
167724
167875
  const collateCaseSensitive = getOrganizeImportsComparer(
167725
167876
  preferences,
@@ -167731,14 +167882,29 @@ var detectImportSpecifierSorting = memoizeCached((specifiers, preferences) => {
167731
167882
  /*ignoreCase*/
167732
167883
  true
167733
167884
  );
167885
+ if (preferences.organizeImportsTypeOrder !== "inline") {
167886
+ const { type: regularImports, regular: typeImports } = groupBy(specifiers, (s) => s.isTypeOnly ? "type" : "regular");
167887
+ const regularCaseSensitivity = (regularImports == null ? void 0 : regularImports.length) ? detectSortCaseSensitivity(regularImports, (specifier) => specifier.name.text, collateCaseSensitive, collateCaseInsensitive) : void 0;
167888
+ const typeCaseSensitivity = (typeImports == null ? void 0 : typeImports.length) ? detectSortCaseSensitivity(typeImports, (specifier) => specifier.name.text ?? "", collateCaseSensitive, collateCaseInsensitive) : void 0;
167889
+ if (regularCaseSensitivity === void 0) {
167890
+ return typeCaseSensitivity ?? 0 /* None */;
167891
+ }
167892
+ if (typeCaseSensitivity === void 0) {
167893
+ return regularCaseSensitivity;
167894
+ }
167895
+ if (regularCaseSensitivity === 0 /* None */ || typeCaseSensitivity === 0 /* None */) {
167896
+ return 0 /* None */;
167897
+ }
167898
+ return typeCaseSensitivity & regularCaseSensitivity;
167899
+ }
167734
167900
  return detectSortCaseSensitivity(specifiers, (specifier) => specifier.name.text, collateCaseSensitive, collateCaseInsensitive);
167735
167901
  }, new ImportSpecifierSortingCache());
167736
167902
  function getImportDeclarationInsertionIndex(sortedImports, newImport, comparer) {
167737
167903
  const index = binarySearch(sortedImports, newImport, identity, (a, b) => compareImportsOrRequireStatements(a, b, comparer));
167738
167904
  return index < 0 ? ~index : index;
167739
167905
  }
167740
- function getImportSpecifierInsertionIndex(sortedImports, newImport, comparer) {
167741
- const index = binarySearch(sortedImports, newImport, identity, (s1, s2) => compareImportOrExportSpecifiers(s1, s2, comparer));
167906
+ function getImportSpecifierInsertionIndex(sortedImports, newImport, comparer, preferences) {
167907
+ const index = binarySearch(sortedImports, newImport, identity, (s1, s2) => compareImportOrExportSpecifiers(s1, s2, comparer, preferences));
167742
167908
  return index < 0 ? ~index : index;
167743
167909
  }
167744
167910
  function compareImportsOrRequireStatements(s1, s2, comparer) {
@@ -175484,7 +175650,6 @@ __export(ts_exports2, {
175484
175650
  isPackedArrayLiteral: () => isPackedArrayLiteral,
175485
175651
  isParameter: () => isParameter,
175486
175652
  isParameterDeclaration: () => isParameterDeclaration,
175487
- isParameterOrCatchClauseVariable: () => isParameterOrCatchClauseVariable,
175488
175653
  isParameterPropertyDeclaration: () => isParameterPropertyDeclaration,
175489
175654
  isParameterPropertyModifier: () => isParameterPropertyModifier,
175490
175655
  isParenthesizedExpression: () => isParenthesizedExpression,
@@ -190285,7 +190450,6 @@ start(initializeNodeSystem(), require("os").platform());
190285
190450
  isPackedArrayLiteral,
190286
190451
  isParameter,
190287
190452
  isParameterDeclaration,
190288
- isParameterOrCatchClauseVariable,
190289
190453
  isParameterPropertyDeclaration,
190290
190454
  isParameterPropertyModifier,
190291
190455
  isParenthesizedExpression,
@@ -2933,6 +2933,13 @@ declare namespace ts {
2933
2933
  * Default: `false`
2934
2934
  */
2935
2935
  readonly organizeImportsCaseFirst?: "upper" | "lower" | false;
2936
+ /**
2937
+ * Indicates where named type-only imports should sort. "inline" sorts named imports without regard to if the import is
2938
+ * type-only.
2939
+ *
2940
+ * Default: `last`
2941
+ */
2942
+ readonly organizeImportsTypeOrder?: "last" | "first" | "inline";
2936
2943
  /**
2937
2944
  * Indicates whether {@link ReferencesResponseItem.lineText} is supported.
2938
2945
  */
@@ -8784,6 +8791,7 @@ declare namespace ts {
8784
8791
  readonly organizeImportsNumericCollation?: boolean;
8785
8792
  readonly organizeImportsAccentCollation?: boolean;
8786
8793
  readonly organizeImportsCaseFirst?: "upper" | "lower" | false;
8794
+ readonly organizeImportsTypeOrder?: "first" | "last" | "inline";
8787
8795
  readonly excludeLibrarySymbolsInNavTo?: boolean;
8788
8796
  }
8789
8797
  /** Represents a bigint literal value without requiring bigint support */