@typescript-deploys/pr-build 5.6.0-pr-59421-2 → 5.6.0-pr-55887-49

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.
Files changed (3) hide show
  1. package/lib/tsc.js +106 -49
  2. package/lib/typescript.js +114 -59
  3. package/package.json +1 -1
package/lib/tsc.js CHANGED
@@ -6703,6 +6703,7 @@ var Diagnostics = {
6703
6703
  This_expression_is_always_nullish: diag(2871, 1 /* Error */, "This_expression_is_always_nullish_2871", "This expression is always nullish."),
6704
6704
  This_kind_of_expression_is_always_truthy: diag(2872, 1 /* Error */, "This_kind_of_expression_is_always_truthy_2872", "This kind of expression is always truthy."),
6705
6705
  This_kind_of_expression_is_always_falsy: diag(2873, 1 /* Error */, "This_kind_of_expression_is_always_falsy_2873", "This kind of expression is always falsy."),
6706
+ Variable_0_is_used_but_never_initialized: diag(2874, 1 /* Error */, "Variable_0_is_used_but_never_initialized_2874", "Variable '{0}' is used but never initialized."),
6706
6707
  Import_declaration_0_is_using_private_name_1: diag(4e3, 1 /* Error */, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
6707
6708
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, 1 /* 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}'."),
6708
6709
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, 1 /* 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}'."),
@@ -17121,6 +17122,9 @@ function accessKind(node) {
17121
17122
  return node === parent.objectAssignmentInitializer ? 0 /* Read */ : accessKind(parent.parent);
17122
17123
  case 209 /* ArrayLiteralExpression */:
17123
17124
  return accessKind(parent);
17125
+ case 249 /* ForInStatement */:
17126
+ case 250 /* ForOfStatement */:
17127
+ return node === parent.initializer ? 1 /* Write */ : 0 /* Read */;
17124
17128
  default:
17125
17129
  return 0 /* Read */;
17126
17130
  }
@@ -17260,6 +17264,7 @@ function Symbol4(flags, name) {
17260
17264
  this.constEnumOnlyModule = void 0;
17261
17265
  this.isReferenced = void 0;
17262
17266
  this.lastAssignmentPos = void 0;
17267
+ this.isDefinitelyAssigned = void 0;
17263
17268
  this.links = void 0;
17264
17269
  }
17265
17270
  function Type3(checker, flags) {
@@ -45741,11 +45746,16 @@ function createTypeChecker(host) {
45741
45746
  checkSourceFileWithEagerDiagnostics(file);
45742
45747
  Debug.assert(!!(getNodeLinks(file).flags & 1 /* TypeChecked */));
45743
45748
  diagnostics2 = addRange(diagnostics2, suggestionDiagnostics.getDiagnostics(file.fileName));
45744
- checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), (containingNode, kind, diag2) => {
45745
- if (!containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
45746
- (diagnostics2 || (diagnostics2 = [])).push({ ...diag2, category: 2 /* Suggestion */ });
45747
- }
45748
- });
45749
+ checkUnusedOrUninitializedIdentifiers(
45750
+ getPotentiallyUnusedOrUninitializedIdentifiers(file),
45751
+ (containingNode, kind, diag2) => {
45752
+ if (!containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
45753
+ (diagnostics2 || (diagnostics2 = [])).push({ ...diag2, category: 2 /* Suggestion */ });
45754
+ }
45755
+ },
45756
+ /*checkUnused*/
45757
+ true
45758
+ );
45749
45759
  return diagnostics2 || emptyArray;
45750
45760
  } finally {
45751
45761
  cancellationToken = void 0;
@@ -46238,7 +46248,7 @@ function createTypeChecker(host) {
46238
46248
  var deferredGlobalClassAccessorDecoratorTargetType;
46239
46249
  var deferredGlobalClassAccessorDecoratorResultType;
46240
46250
  var deferredGlobalClassFieldDecoratorContextType;
46241
- var allPotentiallyUnusedIdentifiers = /* @__PURE__ */ new Map();
46251
+ var allPotentiallyUnusedOrUninitializedIdentifiers = /* @__PURE__ */ new Map();
46242
46252
  var flowLoopStart = 0;
46243
46253
  var flowLoopCount = 0;
46244
46254
  var sharedFlowCount = 0;
@@ -69572,6 +69582,9 @@ function createTypeChecker(host) {
69572
69582
  void 0
69573
69583
  );
69574
69584
  }
69585
+ function isSymbolAssignedDefinitely(symbol) {
69586
+ return symbol.isDefinitelyAssigned ?? (isSymbolAssigned(symbol) && symbol.isDefinitelyAssigned);
69587
+ }
69575
69588
  function isPastLastAssignment(symbol, location) {
69576
69589
  const parent = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
69577
69590
  if (!parent) {
@@ -69582,6 +69595,7 @@ function createTypeChecker(host) {
69582
69595
  links.flags |= 131072 /* AssignmentsMarked */;
69583
69596
  if (!hasParentWithAssignmentsMarked(parent)) {
69584
69597
  markNodeAssignments(parent);
69598
+ symbol.isDefinitelyAssigned ?? (symbol.isDefinitelyAssigned = false);
69585
69599
  }
69586
69600
  }
69587
69601
  return !symbol.lastAssignmentPos || location && symbol.lastAssignmentPos < location.pos;
@@ -69605,12 +69619,18 @@ function createTypeChecker(host) {
69605
69619
  function markNodeAssignments(node) {
69606
69620
  switch (node.kind) {
69607
69621
  case 80 /* Identifier */:
69608
- if (isAssignmentTarget(node)) {
69622
+ const assignmentKind = getAssignmentTargetKind(node);
69623
+ if (assignmentKind !== 0 /* None */) {
69609
69624
  const symbol = getResolvedSymbol(node);
69610
- if (isParameterOrMutableLocalVariable(symbol) && symbol.lastAssignmentPos !== Number.MAX_VALUE) {
69611
- const referencingFunction = findAncestor(node, isFunctionOrSourceFile);
69612
- const declaringFunction = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
69613
- symbol.lastAssignmentPos = referencingFunction === declaringFunction ? extendAssignmentPosition(node, symbol.valueDeclaration) : Number.MAX_VALUE;
69625
+ if (isParameterOrMutableLocalVariable(symbol)) {
69626
+ if (assignmentKind === 1 /* Definite */) {
69627
+ symbol.isDefinitelyAssigned = true;
69628
+ }
69629
+ if (symbol.lastAssignmentPos !== Number.MAX_VALUE) {
69630
+ const referencingFunction = findAncestor(node, isFunctionOrSourceFile);
69631
+ const declaringFunction = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
69632
+ symbol.lastAssignmentPos = referencingFunction === declaringFunction ? extendAssignmentPosition(node, symbol.valueDeclaration) : Number.MAX_VALUE;
69633
+ }
69614
69634
  }
69615
69635
  }
69616
69636
  return;
@@ -79160,7 +79180,7 @@ function createTypeChecker(host) {
79160
79180
  }
79161
79181
  }
79162
79182
  if (node.kind !== 181 /* IndexSignature */ && node.kind !== 317 /* JSDocFunctionType */) {
79163
- registerForUnusedIdentifiersCheck(node);
79183
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
79164
79184
  }
79165
79185
  }
79166
79186
  }
@@ -79706,7 +79726,7 @@ function createTypeChecker(host) {
79706
79726
  }
79707
79727
  }
79708
79728
  }
79709
- registerForUnusedIdentifiersCheck(node);
79729
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
79710
79730
  }
79711
79731
  function checkTemplateLiteralType(node) {
79712
79732
  for (const span of node.templateSpans) {
@@ -80658,25 +80678,27 @@ function createTypeChecker(host) {
80658
80678
  }
80659
80679
  }
80660
80680
  }
80661
- function registerForUnusedIdentifiersCheck(node) {
80662
- addLazyDiagnostic(registerForUnusedIdentifiersCheckDiagnostics);
80663
- function registerForUnusedIdentifiersCheckDiagnostics() {
80681
+ function registerForUnusedOrUninitializedIdentifiersCheck(node) {
80682
+ addLazyDiagnostic(registerForUnusedOrUninitializedIdentifiersCheckDiagnostics);
80683
+ function registerForUnusedOrUninitializedIdentifiersCheckDiagnostics() {
80664
80684
  const sourceFile = getSourceFileOfNode(node);
80665
- let potentiallyUnusedIdentifiers = allPotentiallyUnusedIdentifiers.get(sourceFile.path);
80666
- if (!potentiallyUnusedIdentifiers) {
80667
- potentiallyUnusedIdentifiers = [];
80668
- allPotentiallyUnusedIdentifiers.set(sourceFile.path, potentiallyUnusedIdentifiers);
80685
+ let potentiallyUnusedOrUninitializedIdentifiers = allPotentiallyUnusedOrUninitializedIdentifiers.get(sourceFile.path);
80686
+ if (!potentiallyUnusedOrUninitializedIdentifiers) {
80687
+ potentiallyUnusedOrUninitializedIdentifiers = [];
80688
+ allPotentiallyUnusedOrUninitializedIdentifiers.set(sourceFile.path, potentiallyUnusedOrUninitializedIdentifiers);
80669
80689
  }
80670
- potentiallyUnusedIdentifiers.push(node);
80690
+ potentiallyUnusedOrUninitializedIdentifiers.push(node);
80671
80691
  }
80672
80692
  }
80673
- function checkUnusedIdentifiers(potentiallyUnusedIdentifiers, addDiagnostic) {
80693
+ function checkUnusedOrUninitializedIdentifiers(potentiallyUnusedIdentifiers, addDiagnostic, checkUnused, checkUninitialized) {
80674
80694
  for (const node of potentiallyUnusedIdentifiers) {
80675
80695
  switch (node.kind) {
80676
80696
  case 263 /* ClassDeclaration */:
80677
80697
  case 231 /* ClassExpression */:
80678
- checkUnusedClassMembers(node, addDiagnostic);
80679
- checkUnusedTypeParameters(node, addDiagnostic);
80698
+ if (checkUnused) {
80699
+ checkUnusedClassMembers(node, addDiagnostic);
80700
+ checkUnusedTypeParameters(node, addDiagnostic);
80701
+ }
80680
80702
  break;
80681
80703
  case 307 /* SourceFile */:
80682
80704
  case 267 /* ModuleDeclaration */:
@@ -80685,7 +80707,12 @@ function createTypeChecker(host) {
80685
80707
  case 248 /* ForStatement */:
80686
80708
  case 249 /* ForInStatement */:
80687
80709
  case 250 /* ForOfStatement */:
80688
- checkUnusedLocalsAndParameters(node, addDiagnostic);
80710
+ if (checkUnused) {
80711
+ checkUnusedLocalsAndParameters(node, addDiagnostic);
80712
+ }
80713
+ if (checkUninitialized) {
80714
+ checkUninitializedLocals(node);
80715
+ }
80689
80716
  break;
80690
80717
  case 176 /* Constructor */:
80691
80718
  case 218 /* FunctionExpression */:
@@ -80694,10 +80721,15 @@ function createTypeChecker(host) {
80694
80721
  case 174 /* MethodDeclaration */:
80695
80722
  case 177 /* GetAccessor */:
80696
80723
  case 178 /* SetAccessor */:
80697
- if (node.body) {
80698
- checkUnusedLocalsAndParameters(node, addDiagnostic);
80724
+ if (checkUnused) {
80725
+ if (node.body) {
80726
+ checkUnusedLocalsAndParameters(node, addDiagnostic);
80727
+ }
80728
+ checkUnusedTypeParameters(node, addDiagnostic);
80729
+ }
80730
+ if (checkUninitialized) {
80731
+ checkUninitializedLocals(node);
80699
80732
  }
80700
- checkUnusedTypeParameters(node, addDiagnostic);
80701
80733
  break;
80702
80734
  case 173 /* MethodSignature */:
80703
80735
  case 179 /* CallSignature */:
@@ -80706,10 +80738,14 @@ function createTypeChecker(host) {
80706
80738
  case 185 /* ConstructorType */:
80707
80739
  case 265 /* TypeAliasDeclaration */:
80708
80740
  case 264 /* InterfaceDeclaration */:
80709
- checkUnusedTypeParameters(node, addDiagnostic);
80741
+ if (checkUnused) {
80742
+ checkUnusedTypeParameters(node, addDiagnostic);
80743
+ }
80710
80744
  break;
80711
80745
  case 195 /* InferType */:
80712
- checkUnusedInferTypeParameter(node, addDiagnostic);
80746
+ if (checkUnused) {
80747
+ checkUnusedInferTypeParameter(node, addDiagnostic);
80748
+ }
80713
80749
  break;
80714
80750
  default:
80715
80751
  Debug.assertNever(node, "Node should not have been registered for unused identifiers check");
@@ -80896,6 +80932,21 @@ function createTypeChecker(host) {
80896
80932
  }
80897
80933
  });
80898
80934
  }
80935
+ function checkUninitializedLocals(nodeWithLocals) {
80936
+ nodeWithLocals.locals.forEach((local) => {
80937
+ if (!(local.flags & 3 /* Variable */) || !local.isReferenced || isSymbolAssignedDefinitely(local)) {
80938
+ return;
80939
+ }
80940
+ const declaration = local.valueDeclaration;
80941
+ if (!declaration || !isVariableDeclaration(declaration) || !(getCombinedNodeFlagsCached(declaration) & 7 /* BlockScoped */) || getCombinedNodeFlagsCached(declaration) & 33554432 /* Ambient */ || declaration.exclamationToken || declaration.initializer || !declaration.type) {
80942
+ return;
80943
+ }
80944
+ const type = getTypeFromTypeNode(declaration.type);
80945
+ if (!(type.flags & 3 /* AnyOrUnknown */) && !containsUndefinedType(type)) {
80946
+ error(declaration, Diagnostics.Variable_0_is_used_but_never_initialized, idText(declaration.name));
80947
+ }
80948
+ });
80949
+ }
80899
80950
  function checkPotentialUncheckedRenamedBindingElementsInTypes() {
80900
80951
  var _a;
80901
80952
  for (const node of potentialUnusedRenamedBindingElementsInTypes) {
@@ -80942,7 +80993,7 @@ function createTypeChecker(host) {
80942
80993
  forEach(node.statements, checkSourceElement);
80943
80994
  }
80944
80995
  if (node.locals) {
80945
- registerForUnusedIdentifiersCheck(node);
80996
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
80946
80997
  }
80947
80998
  }
80948
80999
  function checkCollisionWithArgumentsInGeneratedCode(node) {
@@ -81532,7 +81583,7 @@ function createTypeChecker(host) {
81532
81583
  if (node.incrementor) checkExpression(node.incrementor);
81533
81584
  checkSourceElement(node.statement);
81534
81585
  if (node.locals) {
81535
- registerForUnusedIdentifiersCheck(node);
81586
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
81536
81587
  }
81537
81588
  }
81538
81589
  function checkForOfStatement(node) {
@@ -81571,7 +81622,7 @@ function createTypeChecker(host) {
81571
81622
  }
81572
81623
  checkSourceElement(node.statement);
81573
81624
  if (node.locals) {
81574
- registerForUnusedIdentifiersCheck(node);
81625
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
81575
81626
  }
81576
81627
  }
81577
81628
  function checkForInStatement(node) {
@@ -81603,7 +81654,7 @@ function createTypeChecker(host) {
81603
81654
  }
81604
81655
  checkSourceElement(node.statement);
81605
81656
  if (node.locals) {
81606
- registerForUnusedIdentifiersCheck(node);
81657
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
81607
81658
  }
81608
81659
  }
81609
81660
  function checkRightHandSideOfForOf(statement) {
@@ -82289,7 +82340,7 @@ function createTypeChecker(host) {
82289
82340
  }
82290
82341
  });
82291
82342
  if (node.caseBlock.locals) {
82292
- registerForUnusedIdentifiersCheck(node.caseBlock);
82343
+ registerForUnusedOrUninitializedIdentifiersCheck(node.caseBlock);
82293
82344
  }
82294
82345
  }
82295
82346
  function checkLabeledStatement(node) {
@@ -82626,7 +82677,7 @@ function createTypeChecker(host) {
82626
82677
  }
82627
82678
  function checkClassExpressionDeferred(node) {
82628
82679
  forEach(node.members, checkSourceElement);
82629
- registerForUnusedIdentifiersCheck(node);
82680
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
82630
82681
  }
82631
82682
  function checkClassDeclaration(node) {
82632
82683
  const firstDecorator = find(node.modifiers, isDecorator);
@@ -82638,7 +82689,7 @@ function createTypeChecker(host) {
82638
82689
  }
82639
82690
  checkClassLikeDeclaration(node);
82640
82691
  forEach(node.members, checkSourceElement);
82641
- registerForUnusedIdentifiersCheck(node);
82692
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
82642
82693
  }
82643
82694
  function checkClassLikeDeclaration(node) {
82644
82695
  checkGrammarClassLikeDeclaration(node);
@@ -83194,7 +83245,7 @@ function createTypeChecker(host) {
83194
83245
  forEach(node.members, checkSourceElement);
83195
83246
  addLazyDiagnostic(() => {
83196
83247
  checkTypeForDuplicateIndexSignatures(node);
83197
- registerForUnusedIdentifiersCheck(node);
83248
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
83198
83249
  });
83199
83250
  }
83200
83251
  function checkTypeAliasDeclaration(node) {
@@ -83210,7 +83261,7 @@ function createTypeChecker(host) {
83210
83261
  }
83211
83262
  } else {
83212
83263
  checkSourceElement(node.type);
83213
- registerForUnusedIdentifiersCheck(node);
83264
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
83214
83265
  }
83215
83266
  }
83216
83267
  function computeEnumMemberValues(node) {
@@ -83472,7 +83523,7 @@ function createTypeChecker(host) {
83472
83523
  if (node.body) {
83473
83524
  checkSourceElement(node.body);
83474
83525
  if (!isGlobalScopeAugmentation(node)) {
83475
- registerForUnusedIdentifiersCheck(node);
83526
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
83476
83527
  }
83477
83528
  }
83478
83529
  addLazyDiagnostic(checkModuleDeclarationDiagnostics);
@@ -84517,8 +84568,8 @@ function createTypeChecker(host) {
84517
84568
  return Debug.assertNever(kind);
84518
84569
  }
84519
84570
  }
84520
- function getPotentiallyUnusedIdentifiers(sourceFile) {
84521
- return allPotentiallyUnusedIdentifiers.get(sourceFile.path) || emptyArray;
84571
+ function getPotentiallyUnusedOrUninitializedIdentifiers(sourceFile) {
84572
+ return allPotentiallyUnusedOrUninitializedIdentifiers.get(sourceFile.path) || emptyArray;
84522
84573
  }
84523
84574
  function checkSourceFileWorker(node) {
84524
84575
  const links = getNodeLinks(node);
@@ -84543,15 +84594,21 @@ function createTypeChecker(host) {
84543
84594
  checkSourceElement(node.endOfFileToken);
84544
84595
  checkDeferredNodes(node);
84545
84596
  if (isExternalOrCommonJsModule(node)) {
84546
- registerForUnusedIdentifiersCheck(node);
84597
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
84547
84598
  }
84548
84599
  addLazyDiagnostic(() => {
84549
- if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
84550
- checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), (containingNode, kind, diag2) => {
84551
- if (!containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
84552
- diagnostics.add(diag2);
84553
- }
84554
- });
84600
+ const checkUnused = !node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters);
84601
+ if (checkUnused || strictNullChecks) {
84602
+ checkUnusedOrUninitializedIdentifiers(
84603
+ getPotentiallyUnusedOrUninitializedIdentifiers(node),
84604
+ (containingNode, kind, diag2) => {
84605
+ if (!containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
84606
+ diagnostics.add(diag2);
84607
+ }
84608
+ },
84609
+ checkUnused,
84610
+ strictNullChecks
84611
+ );
84555
84612
  }
84556
84613
  if (!node.isDeclarationFile) {
84557
84614
  checkPotentialUncheckedRenamedBindingElementsInTypes();
package/lib/typescript.js CHANGED
@@ -10099,6 +10099,7 @@ var Diagnostics = {
10099
10099
  This_expression_is_always_nullish: diag(2871, 1 /* Error */, "This_expression_is_always_nullish_2871", "This expression is always nullish."),
10100
10100
  This_kind_of_expression_is_always_truthy: diag(2872, 1 /* Error */, "This_kind_of_expression_is_always_truthy_2872", "This kind of expression is always truthy."),
10101
10101
  This_kind_of_expression_is_always_falsy: diag(2873, 1 /* Error */, "This_kind_of_expression_is_always_falsy_2873", "This kind of expression is always falsy."),
10102
+ Variable_0_is_used_but_never_initialized: diag(2874, 1 /* Error */, "Variable_0_is_used_but_never_initialized_2874", "Variable '{0}' is used but never initialized."),
10102
10103
  Import_declaration_0_is_using_private_name_1: diag(4e3, 1 /* Error */, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
10103
10104
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, 1 /* 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}'."),
10104
10105
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, 1 /* 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}'."),
@@ -21011,6 +21012,9 @@ function accessKind(node) {
21011
21012
  return node === parent2.objectAssignmentInitializer ? 0 /* Read */ : accessKind(parent2.parent);
21012
21013
  case 209 /* ArrayLiteralExpression */:
21013
21014
  return accessKind(parent2);
21015
+ case 249 /* ForInStatement */:
21016
+ case 250 /* ForOfStatement */:
21017
+ return node === parent2.initializer ? 1 /* Write */ : 0 /* Read */;
21014
21018
  default:
21015
21019
  return 0 /* Read */;
21016
21020
  }
@@ -21209,6 +21213,7 @@ function Symbol4(flags, name) {
21209
21213
  this.constEnumOnlyModule = void 0;
21210
21214
  this.isReferenced = void 0;
21211
21215
  this.lastAssignmentPos = void 0;
21216
+ this.isDefinitelyAssigned = void 0;
21212
21217
  this.links = void 0;
21213
21218
  }
21214
21219
  function Type3(checker, flags) {
@@ -50359,11 +50364,16 @@ function createTypeChecker(host) {
50359
50364
  checkSourceFileWithEagerDiagnostics(file);
50360
50365
  Debug.assert(!!(getNodeLinks(file).flags & 1 /* TypeChecked */));
50361
50366
  diagnostics2 = addRange(diagnostics2, suggestionDiagnostics.getDiagnostics(file.fileName));
50362
- checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), (containingNode, kind, diag2) => {
50363
- if (!containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
50364
- (diagnostics2 || (diagnostics2 = [])).push({ ...diag2, category: 2 /* Suggestion */ });
50365
- }
50366
- });
50367
+ checkUnusedOrUninitializedIdentifiers(
50368
+ getPotentiallyUnusedOrUninitializedIdentifiers(file),
50369
+ (containingNode, kind, diag2) => {
50370
+ if (!containsParseError(containingNode) && !unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
50371
+ (diagnostics2 || (diagnostics2 = [])).push({ ...diag2, category: 2 /* Suggestion */ });
50372
+ }
50373
+ },
50374
+ /*checkUnused*/
50375
+ true
50376
+ );
50367
50377
  return diagnostics2 || emptyArray;
50368
50378
  } finally {
50369
50379
  cancellationToken = void 0;
@@ -50856,7 +50866,7 @@ function createTypeChecker(host) {
50856
50866
  var deferredGlobalClassAccessorDecoratorTargetType;
50857
50867
  var deferredGlobalClassAccessorDecoratorResultType;
50858
50868
  var deferredGlobalClassFieldDecoratorContextType;
50859
- var allPotentiallyUnusedIdentifiers = /* @__PURE__ */ new Map();
50869
+ var allPotentiallyUnusedOrUninitializedIdentifiers = /* @__PURE__ */ new Map();
50860
50870
  var flowLoopStart = 0;
50861
50871
  var flowLoopCount = 0;
50862
50872
  var sharedFlowCount = 0;
@@ -74190,6 +74200,9 @@ function createTypeChecker(host) {
74190
74200
  void 0
74191
74201
  );
74192
74202
  }
74203
+ function isSymbolAssignedDefinitely(symbol) {
74204
+ return symbol.isDefinitelyAssigned ?? (isSymbolAssigned(symbol) && symbol.isDefinitelyAssigned);
74205
+ }
74193
74206
  function isPastLastAssignment(symbol, location) {
74194
74207
  const parent2 = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
74195
74208
  if (!parent2) {
@@ -74200,6 +74213,7 @@ function createTypeChecker(host) {
74200
74213
  links.flags |= 131072 /* AssignmentsMarked */;
74201
74214
  if (!hasParentWithAssignmentsMarked(parent2)) {
74202
74215
  markNodeAssignments(parent2);
74216
+ symbol.isDefinitelyAssigned ?? (symbol.isDefinitelyAssigned = false);
74203
74217
  }
74204
74218
  }
74205
74219
  return !symbol.lastAssignmentPos || location && symbol.lastAssignmentPos < location.pos;
@@ -74223,12 +74237,18 @@ function createTypeChecker(host) {
74223
74237
  function markNodeAssignments(node) {
74224
74238
  switch (node.kind) {
74225
74239
  case 80 /* Identifier */:
74226
- if (isAssignmentTarget(node)) {
74240
+ const assignmentKind = getAssignmentTargetKind(node);
74241
+ if (assignmentKind !== 0 /* None */) {
74227
74242
  const symbol = getResolvedSymbol(node);
74228
- if (isParameterOrMutableLocalVariable(symbol) && symbol.lastAssignmentPos !== Number.MAX_VALUE) {
74229
- const referencingFunction = findAncestor(node, isFunctionOrSourceFile);
74230
- const declaringFunction = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
74231
- symbol.lastAssignmentPos = referencingFunction === declaringFunction ? extendAssignmentPosition(node, symbol.valueDeclaration) : Number.MAX_VALUE;
74243
+ if (isParameterOrMutableLocalVariable(symbol)) {
74244
+ if (assignmentKind === 1 /* Definite */) {
74245
+ symbol.isDefinitelyAssigned = true;
74246
+ }
74247
+ if (symbol.lastAssignmentPos !== Number.MAX_VALUE) {
74248
+ const referencingFunction = findAncestor(node, isFunctionOrSourceFile);
74249
+ const declaringFunction = findAncestor(symbol.valueDeclaration, isFunctionOrSourceFile);
74250
+ symbol.lastAssignmentPos = referencingFunction === declaringFunction ? extendAssignmentPosition(node, symbol.valueDeclaration) : Number.MAX_VALUE;
74251
+ }
74232
74252
  }
74233
74253
  }
74234
74254
  return;
@@ -83778,7 +83798,7 @@ function createTypeChecker(host) {
83778
83798
  }
83779
83799
  }
83780
83800
  if (node.kind !== 181 /* IndexSignature */ && node.kind !== 317 /* JSDocFunctionType */) {
83781
- registerForUnusedIdentifiersCheck(node);
83801
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
83782
83802
  }
83783
83803
  }
83784
83804
  }
@@ -84324,7 +84344,7 @@ function createTypeChecker(host) {
84324
84344
  }
84325
84345
  }
84326
84346
  }
84327
- registerForUnusedIdentifiersCheck(node);
84347
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
84328
84348
  }
84329
84349
  function checkTemplateLiteralType(node) {
84330
84350
  for (const span of node.templateSpans) {
@@ -85276,25 +85296,27 @@ function createTypeChecker(host) {
85276
85296
  }
85277
85297
  }
85278
85298
  }
85279
- function registerForUnusedIdentifiersCheck(node) {
85280
- addLazyDiagnostic(registerForUnusedIdentifiersCheckDiagnostics);
85281
- function registerForUnusedIdentifiersCheckDiagnostics() {
85299
+ function registerForUnusedOrUninitializedIdentifiersCheck(node) {
85300
+ addLazyDiagnostic(registerForUnusedOrUninitializedIdentifiersCheckDiagnostics);
85301
+ function registerForUnusedOrUninitializedIdentifiersCheckDiagnostics() {
85282
85302
  const sourceFile = getSourceFileOfNode(node);
85283
- let potentiallyUnusedIdentifiers = allPotentiallyUnusedIdentifiers.get(sourceFile.path);
85284
- if (!potentiallyUnusedIdentifiers) {
85285
- potentiallyUnusedIdentifiers = [];
85286
- allPotentiallyUnusedIdentifiers.set(sourceFile.path, potentiallyUnusedIdentifiers);
85303
+ let potentiallyUnusedOrUninitializedIdentifiers = allPotentiallyUnusedOrUninitializedIdentifiers.get(sourceFile.path);
85304
+ if (!potentiallyUnusedOrUninitializedIdentifiers) {
85305
+ potentiallyUnusedOrUninitializedIdentifiers = [];
85306
+ allPotentiallyUnusedOrUninitializedIdentifiers.set(sourceFile.path, potentiallyUnusedOrUninitializedIdentifiers);
85287
85307
  }
85288
- potentiallyUnusedIdentifiers.push(node);
85308
+ potentiallyUnusedOrUninitializedIdentifiers.push(node);
85289
85309
  }
85290
85310
  }
85291
- function checkUnusedIdentifiers(potentiallyUnusedIdentifiers, addDiagnostic) {
85311
+ function checkUnusedOrUninitializedIdentifiers(potentiallyUnusedIdentifiers, addDiagnostic, checkUnused, checkUninitialized) {
85292
85312
  for (const node of potentiallyUnusedIdentifiers) {
85293
85313
  switch (node.kind) {
85294
85314
  case 263 /* ClassDeclaration */:
85295
85315
  case 231 /* ClassExpression */:
85296
- checkUnusedClassMembers(node, addDiagnostic);
85297
- checkUnusedTypeParameters(node, addDiagnostic);
85316
+ if (checkUnused) {
85317
+ checkUnusedClassMembers(node, addDiagnostic);
85318
+ checkUnusedTypeParameters(node, addDiagnostic);
85319
+ }
85298
85320
  break;
85299
85321
  case 307 /* SourceFile */:
85300
85322
  case 267 /* ModuleDeclaration */:
@@ -85303,7 +85325,12 @@ function createTypeChecker(host) {
85303
85325
  case 248 /* ForStatement */:
85304
85326
  case 249 /* ForInStatement */:
85305
85327
  case 250 /* ForOfStatement */:
85306
- checkUnusedLocalsAndParameters(node, addDiagnostic);
85328
+ if (checkUnused) {
85329
+ checkUnusedLocalsAndParameters(node, addDiagnostic);
85330
+ }
85331
+ if (checkUninitialized) {
85332
+ checkUninitializedLocals(node);
85333
+ }
85307
85334
  break;
85308
85335
  case 176 /* Constructor */:
85309
85336
  case 218 /* FunctionExpression */:
@@ -85312,10 +85339,15 @@ function createTypeChecker(host) {
85312
85339
  case 174 /* MethodDeclaration */:
85313
85340
  case 177 /* GetAccessor */:
85314
85341
  case 178 /* SetAccessor */:
85315
- if (node.body) {
85316
- checkUnusedLocalsAndParameters(node, addDiagnostic);
85342
+ if (checkUnused) {
85343
+ if (node.body) {
85344
+ checkUnusedLocalsAndParameters(node, addDiagnostic);
85345
+ }
85346
+ checkUnusedTypeParameters(node, addDiagnostic);
85347
+ }
85348
+ if (checkUninitialized) {
85349
+ checkUninitializedLocals(node);
85317
85350
  }
85318
- checkUnusedTypeParameters(node, addDiagnostic);
85319
85351
  break;
85320
85352
  case 173 /* MethodSignature */:
85321
85353
  case 179 /* CallSignature */:
@@ -85324,10 +85356,14 @@ function createTypeChecker(host) {
85324
85356
  case 185 /* ConstructorType */:
85325
85357
  case 265 /* TypeAliasDeclaration */:
85326
85358
  case 264 /* InterfaceDeclaration */:
85327
- checkUnusedTypeParameters(node, addDiagnostic);
85359
+ if (checkUnused) {
85360
+ checkUnusedTypeParameters(node, addDiagnostic);
85361
+ }
85328
85362
  break;
85329
85363
  case 195 /* InferType */:
85330
- checkUnusedInferTypeParameter(node, addDiagnostic);
85364
+ if (checkUnused) {
85365
+ checkUnusedInferTypeParameter(node, addDiagnostic);
85366
+ }
85331
85367
  break;
85332
85368
  default:
85333
85369
  Debug.assertNever(node, "Node should not have been registered for unused identifiers check");
@@ -85514,6 +85550,21 @@ function createTypeChecker(host) {
85514
85550
  }
85515
85551
  });
85516
85552
  }
85553
+ function checkUninitializedLocals(nodeWithLocals) {
85554
+ nodeWithLocals.locals.forEach((local) => {
85555
+ if (!(local.flags & 3 /* Variable */) || !local.isReferenced || isSymbolAssignedDefinitely(local)) {
85556
+ return;
85557
+ }
85558
+ const declaration = local.valueDeclaration;
85559
+ if (!declaration || !isVariableDeclaration(declaration) || !(getCombinedNodeFlagsCached(declaration) & 7 /* BlockScoped */) || getCombinedNodeFlagsCached(declaration) & 33554432 /* Ambient */ || declaration.exclamationToken || declaration.initializer || !declaration.type) {
85560
+ return;
85561
+ }
85562
+ const type = getTypeFromTypeNode(declaration.type);
85563
+ if (!(type.flags & 3 /* AnyOrUnknown */) && !containsUndefinedType(type)) {
85564
+ error2(declaration, Diagnostics.Variable_0_is_used_but_never_initialized, idText(declaration.name));
85565
+ }
85566
+ });
85567
+ }
85517
85568
  function checkPotentialUncheckedRenamedBindingElementsInTypes() {
85518
85569
  var _a;
85519
85570
  for (const node of potentialUnusedRenamedBindingElementsInTypes) {
@@ -85560,7 +85611,7 @@ function createTypeChecker(host) {
85560
85611
  forEach(node.statements, checkSourceElement);
85561
85612
  }
85562
85613
  if (node.locals) {
85563
- registerForUnusedIdentifiersCheck(node);
85614
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
85564
85615
  }
85565
85616
  }
85566
85617
  function checkCollisionWithArgumentsInGeneratedCode(node) {
@@ -86150,7 +86201,7 @@ function createTypeChecker(host) {
86150
86201
  if (node.incrementor) checkExpression(node.incrementor);
86151
86202
  checkSourceElement(node.statement);
86152
86203
  if (node.locals) {
86153
- registerForUnusedIdentifiersCheck(node);
86204
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
86154
86205
  }
86155
86206
  }
86156
86207
  function checkForOfStatement(node) {
@@ -86189,7 +86240,7 @@ function createTypeChecker(host) {
86189
86240
  }
86190
86241
  checkSourceElement(node.statement);
86191
86242
  if (node.locals) {
86192
- registerForUnusedIdentifiersCheck(node);
86243
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
86193
86244
  }
86194
86245
  }
86195
86246
  function checkForInStatement(node) {
@@ -86221,7 +86272,7 @@ function createTypeChecker(host) {
86221
86272
  }
86222
86273
  checkSourceElement(node.statement);
86223
86274
  if (node.locals) {
86224
- registerForUnusedIdentifiersCheck(node);
86275
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
86225
86276
  }
86226
86277
  }
86227
86278
  function checkRightHandSideOfForOf(statement) {
@@ -86907,7 +86958,7 @@ function createTypeChecker(host) {
86907
86958
  }
86908
86959
  });
86909
86960
  if (node.caseBlock.locals) {
86910
- registerForUnusedIdentifiersCheck(node.caseBlock);
86961
+ registerForUnusedOrUninitializedIdentifiersCheck(node.caseBlock);
86911
86962
  }
86912
86963
  }
86913
86964
  function checkLabeledStatement(node) {
@@ -87244,7 +87295,7 @@ function createTypeChecker(host) {
87244
87295
  }
87245
87296
  function checkClassExpressionDeferred(node) {
87246
87297
  forEach(node.members, checkSourceElement);
87247
- registerForUnusedIdentifiersCheck(node);
87298
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
87248
87299
  }
87249
87300
  function checkClassDeclaration(node) {
87250
87301
  const firstDecorator = find(node.modifiers, isDecorator);
@@ -87256,7 +87307,7 @@ function createTypeChecker(host) {
87256
87307
  }
87257
87308
  checkClassLikeDeclaration(node);
87258
87309
  forEach(node.members, checkSourceElement);
87259
- registerForUnusedIdentifiersCheck(node);
87310
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
87260
87311
  }
87261
87312
  function checkClassLikeDeclaration(node) {
87262
87313
  checkGrammarClassLikeDeclaration(node);
@@ -87812,7 +87863,7 @@ function createTypeChecker(host) {
87812
87863
  forEach(node.members, checkSourceElement);
87813
87864
  addLazyDiagnostic(() => {
87814
87865
  checkTypeForDuplicateIndexSignatures(node);
87815
- registerForUnusedIdentifiersCheck(node);
87866
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
87816
87867
  });
87817
87868
  }
87818
87869
  function checkTypeAliasDeclaration(node) {
@@ -87828,7 +87879,7 @@ function createTypeChecker(host) {
87828
87879
  }
87829
87880
  } else {
87830
87881
  checkSourceElement(node.type);
87831
- registerForUnusedIdentifiersCheck(node);
87882
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
87832
87883
  }
87833
87884
  }
87834
87885
  function computeEnumMemberValues(node) {
@@ -88090,7 +88141,7 @@ function createTypeChecker(host) {
88090
88141
  if (node.body) {
88091
88142
  checkSourceElement(node.body);
88092
88143
  if (!isGlobalScopeAugmentation(node)) {
88093
- registerForUnusedIdentifiersCheck(node);
88144
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
88094
88145
  }
88095
88146
  }
88096
88147
  addLazyDiagnostic(checkModuleDeclarationDiagnostics);
@@ -89135,8 +89186,8 @@ function createTypeChecker(host) {
89135
89186
  return Debug.assertNever(kind);
89136
89187
  }
89137
89188
  }
89138
- function getPotentiallyUnusedIdentifiers(sourceFile) {
89139
- return allPotentiallyUnusedIdentifiers.get(sourceFile.path) || emptyArray;
89189
+ function getPotentiallyUnusedOrUninitializedIdentifiers(sourceFile) {
89190
+ return allPotentiallyUnusedOrUninitializedIdentifiers.get(sourceFile.path) || emptyArray;
89140
89191
  }
89141
89192
  function checkSourceFileWorker(node) {
89142
89193
  const links = getNodeLinks(node);
@@ -89161,15 +89212,21 @@ function createTypeChecker(host) {
89161
89212
  checkSourceElement(node.endOfFileToken);
89162
89213
  checkDeferredNodes(node);
89163
89214
  if (isExternalOrCommonJsModule(node)) {
89164
- registerForUnusedIdentifiersCheck(node);
89215
+ registerForUnusedOrUninitializedIdentifiersCheck(node);
89165
89216
  }
89166
89217
  addLazyDiagnostic(() => {
89167
- if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) {
89168
- checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), (containingNode, kind, diag2) => {
89169
- if (!containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
89170
- diagnostics.add(diag2);
89171
- }
89172
- });
89218
+ const checkUnused = !node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters);
89219
+ if (checkUnused || strictNullChecks) {
89220
+ checkUnusedOrUninitializedIdentifiers(
89221
+ getPotentiallyUnusedOrUninitializedIdentifiers(node),
89222
+ (containingNode, kind, diag2) => {
89223
+ if (!containsParseError(containingNode) && unusedIsError(kind, !!(containingNode.flags & 33554432 /* Ambient */))) {
89224
+ diagnostics.add(diag2);
89225
+ }
89226
+ },
89227
+ checkUnused,
89228
+ strictNullChecks
89229
+ );
89173
89230
  }
89174
89231
  if (!node.isDeclarationFile) {
89175
89232
  checkPotentialUncheckedRenamedBindingElementsInTypes();
@@ -157350,7 +157407,7 @@ function getInfo10(sourceFile, tokenPos, errorCode, checker, program) {
157350
157407
  const moduleDeclaration = find(symbol.declarations, isModuleDeclaration);
157351
157408
  const moduleDeclarationSourceFile = moduleDeclaration == null ? void 0 : moduleDeclaration.getSourceFile();
157352
157409
  if (moduleDeclaration && moduleDeclarationSourceFile && !isSourceFileFromLibrary(program, moduleDeclarationSourceFile)) {
157353
- return { kind: 2 /* Function */, token, call: parent2.parent, sourceFile, modifierFlags: 32 /* Export */, parentDeclaration: moduleDeclaration };
157410
+ return { kind: 2 /* Function */, token, call: parent2.parent, sourceFile: moduleDeclarationSourceFile, modifierFlags: 32 /* Export */, parentDeclaration: moduleDeclaration };
157354
157411
  }
157355
157412
  const moduleSourceFile = find(symbol.declarations, isSourceFile);
157356
157413
  if (sourceFile.commonJsModuleIndicator) return void 0;
@@ -170469,13 +170526,12 @@ function getDefinitionAtPosition(program, sourceFile, position, searchOtherFiles
170469
170526
  const calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
170470
170527
  if (calledDeclaration && !(isJsxOpeningLikeElement(node.parent) && isJsxConstructorLike(calledDeclaration))) {
170471
170528
  const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration, failedAliasResolution);
170472
- let includeDeclarations;
170473
170529
  if (typeChecker.getRootSymbols(symbol).some((s) => symbolMatchesSignature(s, calledDeclaration))) {
170474
- if (!isConstructorDeclaration(calledDeclaration)) return [sigInfo];
170475
- includeDeclarations = (d) => d !== calledDeclaration && (isClassDeclaration(d) || isClassExpression(d));
170530
+ return [sigInfo];
170531
+ } else {
170532
+ const defs = getDefinitionFromSymbol(typeChecker, symbol, node, failedAliasResolution, calledDeclaration) || emptyArray;
170533
+ return node.kind === 108 /* SuperKeyword */ ? [sigInfo, ...defs] : [...defs, sigInfo];
170476
170534
  }
170477
- const defs = getDefinitionFromSymbol(typeChecker, symbol, node, failedAliasResolution, calledDeclaration, includeDeclarations) || emptyArray;
170478
- return node.kind === 108 /* SuperKeyword */ ? [sigInfo, ...defs] : [...defs, sigInfo];
170479
170535
  }
170480
170536
  if (node.parent.kind === 304 /* ShorthandPropertyAssignment */) {
170481
170537
  const shorthandSymbol = typeChecker.getShorthandAssignmentValueSymbol(symbol.valueDeclaration);
@@ -170732,10 +170788,9 @@ function isExpandoDeclaration(node) {
170732
170788
  });
170733
170789
  return !!containingAssignment && getAssignmentDeclarationKind(containingAssignment) === 5 /* Property */;
170734
170790
  }
170735
- function getDefinitionFromSymbol(typeChecker, symbol, node, failedAliasResolution, excludeDeclaration, includeDeclarations) {
170736
- const excludeConstructorDeclaration = excludeDeclaration !== void 0 && isConstructorDeclaration(excludeDeclaration);
170737
- const filteredDeclarations = filter(symbol.declarations, includeDeclarations ?? ((d) => d !== excludeDeclaration));
170738
- const signatureDefinition = !excludeConstructorDeclaration && (getConstructSignatureDefinition() || getCallSignatureDefinition());
170791
+ function getDefinitionFromSymbol(typeChecker, symbol, node, failedAliasResolution, excludeDeclaration) {
170792
+ const filteredDeclarations = filter(symbol.declarations, (d) => d !== excludeDeclaration);
170793
+ const signatureDefinition = getConstructSignatureDefinition() || getCallSignatureDefinition();
170739
170794
  if (signatureDefinition) {
170740
170795
  return signatureDefinition;
170741
170796
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@typescript-deploys/pr-build",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "5.6.0-pr-59421-2",
5
+ "version": "5.6.0-pr-55887-49",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [