typescript 5.6.0-dev.20240722 → 5.6.0-dev.20240723

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 +110 -13
  2. package/lib/typescript.js +126 -18
  3. package/package.json +2 -2
package/lib/tsc.js CHANGED
@@ -18,7 +18,7 @@ and limitations under the License.
18
18
 
19
19
  // src/compiler/corePublic.ts
20
20
  var versionMajorMinor = "5.6";
21
- var version = `${versionMajorMinor}.0-dev.20240722`;
21
+ var version = `${versionMajorMinor}.0-dev.20240723`;
22
22
 
23
23
  // src/compiler/core.ts
24
24
  var emptyArray = [];
@@ -4969,7 +4969,7 @@ var sys = (() => {
4969
4969
  setTimeout,
4970
4970
  clearTimeout,
4971
4971
  clearScreen: () => {
4972
- process.stdout.write("\x1Bc");
4972
+ process.stdout.write("\x1B[2J\x1B[3J\x1B[H");
4973
4973
  },
4974
4974
  setBlocking: () => {
4975
4975
  var _a;
@@ -6691,6 +6691,11 @@ var Diagnostics = {
6691
6691
  Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled: diag(2866, 1 /* Error */, "Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_w_2866", "Import '{0}' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled."),
6692
6692
  Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun: diag(2867, 1 /* Error */, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_2867", "Cannot find name '{0}'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun`."),
6693
6693
  Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig: diag(2868, 1 /* Error */, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_2868", "Cannot find name '{0}'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun` and then add 'bun' to the types field in your tsconfig."),
6694
+ Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish: diag(2869, 1 /* Error */, "Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish_2869", "Right operand of ?? is unreachable because the left operand is never nullish."),
6695
+ This_binary_expression_is_never_nullish_Are_you_missing_parentheses: diag(2870, 1 /* Error */, "This_binary_expression_is_never_nullish_Are_you_missing_parentheses_2870", "This binary expression is never nullish. Are you missing parentheses?"),
6696
+ This_expression_is_always_nullish: diag(2871, 1 /* Error */, "This_expression_is_always_nullish_2871", "This expression is always nullish."),
6697
+ 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."),
6698
+ 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."),
6694
6699
  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}'."),
6695
6700
  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}'."),
6696
6701
  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}'."),
@@ -77686,7 +77691,7 @@ function createTypeChecker(host) {
77686
77691
  setLastResult(state, checkExpression(node.right, checkMode));
77687
77692
  return state;
77688
77693
  }
77689
- checkGrammarNullishCoalesceWithLogicalExpression(node);
77694
+ checkNullishCoalesceOperands(node);
77690
77695
  const operator = node.operatorToken.kind;
77691
77696
  if (operator === 64 /* EqualsToken */ && (node.left.kind === 210 /* ObjectLiteralExpression */ || node.left.kind === 209 /* ArrayLiteralExpression */)) {
77692
77697
  state.skip = true;
@@ -77719,7 +77724,9 @@ function createTypeChecker(host) {
77719
77724
  if (operator === 56 /* AmpersandAmpersandToken */ || isIfStatement(parent)) {
77720
77725
  checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.left, leftType, isIfStatement(parent) ? parent.thenStatement : void 0);
77721
77726
  }
77722
- checkTruthinessOfType(leftType, node.left);
77727
+ if (isBinaryLogicalOperator(operator)) {
77728
+ checkTruthinessOfType(leftType, node.left);
77729
+ }
77723
77730
  }
77724
77731
  }
77725
77732
  }
@@ -77776,7 +77783,7 @@ function createTypeChecker(host) {
77776
77783
  state.typeStack[state.stackIndex + 1] = type;
77777
77784
  }
77778
77785
  }
77779
- function checkGrammarNullishCoalesceWithLogicalExpression(node) {
77786
+ function checkNullishCoalesceOperands(node) {
77780
77787
  const { left, operatorToken, right } = node;
77781
77788
  if (operatorToken.kind === 61 /* QuestionQuestionToken */) {
77782
77789
  if (isBinaryExpression(left) && (left.operatorToken.kind === 57 /* BarBarToken */ || left.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
@@ -77785,15 +77792,62 @@ function createTypeChecker(host) {
77785
77792
  if (isBinaryExpression(right) && (right.operatorToken.kind === 57 /* BarBarToken */ || right.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
77786
77793
  grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
77787
77794
  }
77795
+ const leftTarget = skipOuterExpressions(left, 15 /* All */);
77796
+ const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
77797
+ if (nullishSemantics !== 3 /* Sometimes */) {
77798
+ if (node.parent.kind === 226 /* BinaryExpression */) {
77799
+ error(leftTarget, Diagnostics.This_binary_expression_is_never_nullish_Are_you_missing_parentheses);
77800
+ } else {
77801
+ if (nullishSemantics === 1 /* Always */) {
77802
+ error(leftTarget, Diagnostics.This_expression_is_always_nullish);
77803
+ } else {
77804
+ error(leftTarget, Diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish);
77805
+ }
77806
+ }
77807
+ }
77788
77808
  }
77789
77809
  }
77810
+ function getSyntacticNullishnessSemantics(node) {
77811
+ node = skipOuterExpressions(node);
77812
+ switch (node.kind) {
77813
+ case 223 /* AwaitExpression */:
77814
+ case 213 /* CallExpression */:
77815
+ case 212 /* ElementAccessExpression */:
77816
+ case 214 /* NewExpression */:
77817
+ case 211 /* PropertyAccessExpression */:
77818
+ case 229 /* YieldExpression */:
77819
+ return 3 /* Sometimes */;
77820
+ case 226 /* BinaryExpression */:
77821
+ switch (node.operatorToken.kind) {
77822
+ case 64 /* EqualsToken */:
77823
+ case 61 /* QuestionQuestionToken */:
77824
+ case 78 /* QuestionQuestionEqualsToken */:
77825
+ case 57 /* BarBarToken */:
77826
+ case 76 /* BarBarEqualsToken */:
77827
+ case 56 /* AmpersandAmpersandToken */:
77828
+ case 77 /* AmpersandAmpersandEqualsToken */:
77829
+ return 3 /* Sometimes */;
77830
+ }
77831
+ return 2 /* Never */;
77832
+ case 227 /* ConditionalExpression */:
77833
+ return getSyntacticNullishnessSemantics(node.whenTrue) | getSyntacticNullishnessSemantics(node.whenFalse);
77834
+ case 106 /* NullKeyword */:
77835
+ return 1 /* Always */;
77836
+ case 80 /* Identifier */:
77837
+ if (getResolvedSymbol(node) === undefinedSymbol) {
77838
+ return 1 /* Always */;
77839
+ }
77840
+ return 3 /* Sometimes */;
77841
+ }
77842
+ return 2 /* Never */;
77843
+ }
77790
77844
  function checkBinaryLikeExpression(left, operatorToken, right, checkMode, errorNode) {
77791
77845
  const operator = operatorToken.kind;
77792
77846
  if (operator === 64 /* EqualsToken */ && (left.kind === 210 /* ObjectLiteralExpression */ || left.kind === 209 /* ArrayLiteralExpression */)) {
77793
77847
  return checkDestructuringAssignment(left, checkExpression(right, checkMode), checkMode, right.kind === 110 /* ThisKeyword */);
77794
77848
  }
77795
77849
  let leftType;
77796
- if (isLogicalOrCoalescingBinaryOperator(operator)) {
77850
+ if (isBinaryLogicalOperator(operator)) {
77797
77851
  leftType = checkTruthinessExpression(left, checkMode);
77798
77852
  } else {
77799
77853
  leftType = checkExpression(left, checkMode);
@@ -81399,9 +81453,51 @@ function createTypeChecker(host) {
81399
81453
  function checkTruthinessOfType(type, node) {
81400
81454
  if (type.flags & 16384 /* Void */) {
81401
81455
  error(node, Diagnostics.An_expression_of_type_void_cannot_be_tested_for_truthiness);
81456
+ } else {
81457
+ const semantics = getSyntacticTruthySemantics(node);
81458
+ if (semantics !== 3 /* Sometimes */) {
81459
+ error(
81460
+ node,
81461
+ semantics === 1 /* Always */ ? Diagnostics.This_kind_of_expression_is_always_truthy : Diagnostics.This_kind_of_expression_is_always_falsy
81462
+ );
81463
+ }
81402
81464
  }
81403
81465
  return type;
81404
81466
  }
81467
+ function getSyntacticTruthySemantics(node) {
81468
+ node = skipOuterExpressions(node);
81469
+ switch (node.kind) {
81470
+ case 9 /* NumericLiteral */:
81471
+ if (node.text === "0" || node.text === "1") {
81472
+ return 3 /* Sometimes */;
81473
+ }
81474
+ return 1 /* Always */;
81475
+ case 209 /* ArrayLiteralExpression */:
81476
+ case 219 /* ArrowFunction */:
81477
+ case 10 /* BigIntLiteral */:
81478
+ case 231 /* ClassExpression */:
81479
+ case 218 /* FunctionExpression */:
81480
+ case 284 /* JsxElement */:
81481
+ case 285 /* JsxSelfClosingElement */:
81482
+ case 210 /* ObjectLiteralExpression */:
81483
+ case 14 /* RegularExpressionLiteral */:
81484
+ return 1 /* Always */;
81485
+ case 222 /* VoidExpression */:
81486
+ case 106 /* NullKeyword */:
81487
+ return 2 /* Never */;
81488
+ case 15 /* NoSubstitutionTemplateLiteral */:
81489
+ case 11 /* StringLiteral */:
81490
+ return !!node.text ? 1 /* Always */ : 2 /* Never */;
81491
+ case 227 /* ConditionalExpression */:
81492
+ return getSyntacticTruthySemantics(node.whenTrue) | getSyntacticTruthySemantics(node.whenFalse);
81493
+ case 80 /* Identifier */:
81494
+ if (getResolvedSymbol(node) === undefinedSymbol) {
81495
+ return 2 /* Never */;
81496
+ }
81497
+ return 3 /* Sometimes */;
81498
+ }
81499
+ return 3 /* Sometimes */;
81500
+ }
81405
81501
  function checkTruthinessExpression(node, checkMode) {
81406
81502
  return checkTruthinessOfType(checkExpression(node, checkMode), node);
81407
81503
  }
@@ -89856,7 +89952,7 @@ function collectExternalModuleInfo(context, sourceFile) {
89856
89952
  }
89857
89953
  }
89858
89954
  function addExportedFunctionDeclaration(node, name, isDefault) {
89859
- exportedFunctions.add(node);
89955
+ exportedFunctions.add(getOriginalNode(node, isFunctionDeclaration));
89860
89956
  if (isDefault) {
89861
89957
  if (!hasExportDefault) {
89862
89958
  multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name ?? context.factory.getDeclarationName(node));
@@ -94259,6 +94355,7 @@ function transformClassFields(context) {
94259
94355
  addRange(statementsOut, visitNodes2(statementsIn, visitor, isStatement, statementOffset));
94260
94356
  }
94261
94357
  function transformConstructorBody(node, constructor, isDerivedClass) {
94358
+ var _a;
94262
94359
  const instanceProperties = getProperties(
94263
94360
  node,
94264
94361
  /*requireInitializer*/
@@ -94352,12 +94449,12 @@ function transformClassFields(context) {
94352
94449
  setTextRange(
94353
94450
  factory2.createNodeArray(statements),
94354
94451
  /*location*/
94355
- constructor ? constructor.body.statements : node.members
94452
+ ((_a = constructor == null ? void 0 : constructor.body) == null ? void 0 : _a.statements) ?? node.members
94356
94453
  ),
94357
94454
  multiLine
94358
94455
  ),
94359
94456
  /*location*/
94360
- constructor ? constructor.body : void 0
94457
+ constructor == null ? void 0 : constructor.body
94361
94458
  );
94362
94459
  }
94363
94460
  function addPropertyOrClassStaticBlockStatements(statements, properties, receiver) {
@@ -107791,7 +107888,7 @@ function transformModule(context) {
107791
107888
  return factory2.updateLabeledStatement(
107792
107889
  node,
107793
107890
  node.label,
107794
- Debug.checkDefined(visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock))
107891
+ visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createExpressionStatement(factory2.createIdentifier(""))
107795
107892
  );
107796
107893
  }
107797
107894
  function visitWithStatement(node) {
@@ -107805,7 +107902,7 @@ function transformModule(context) {
107805
107902
  return factory2.updateIfStatement(
107806
107903
  node,
107807
107904
  visitNode(node.expression, visitor, isExpression),
107808
- Debug.checkDefined(visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)),
107905
+ visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createBlock([]),
107809
107906
  visitNode(node.elseStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)
107810
107907
  );
107811
107908
  }
@@ -109908,7 +110005,7 @@ function transformSystemModule(context) {
109908
110005
  return factory2.updateLabeledStatement(
109909
110006
  node,
109910
110007
  node.label,
109911
- Debug.checkDefined(visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock))
110008
+ visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createExpressionStatement(factory2.createIdentifier(""))
109912
110009
  );
109913
110010
  }
109914
110011
  function visitWithStatement(node) {
@@ -109922,7 +110019,7 @@ function transformSystemModule(context) {
109922
110019
  return factory2.updateIfStatement(
109923
110020
  node,
109924
110021
  visitNode(node.expression, visitor, isExpression),
109925
- Debug.checkDefined(visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)),
110022
+ visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createBlock([]),
109926
110023
  visitNode(node.elseStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)
109927
110024
  );
109928
110025
  }
package/lib/typescript.js CHANGED
@@ -142,6 +142,7 @@ __export(typescript_exports, {
142
142
  PollingInterval: () => PollingInterval,
143
143
  PollingWatchKind: () => PollingWatchKind,
144
144
  PragmaKindFlags: () => PragmaKindFlags,
145
+ PredicateSemantics: () => PredicateSemantics,
145
146
  PrivateIdentifierKind: () => PrivateIdentifierKind,
146
147
  ProcessLevel: () => ProcessLevel,
147
148
  ProgramUpdateLevel: () => ProgramUpdateLevel,
@@ -1178,6 +1179,7 @@ __export(typescript_exports, {
1178
1179
  isAwaitKeyword: () => isAwaitKeyword,
1179
1180
  isBigIntLiteral: () => isBigIntLiteral,
1180
1181
  isBinaryExpression: () => isBinaryExpression,
1182
+ isBinaryLogicalOperator: () => isBinaryLogicalOperator,
1181
1183
  isBinaryOperatorToken: () => isBinaryOperatorToken,
1182
1184
  isBindableObjectDefinePropertyCall: () => isBindableObjectDefinePropertyCall,
1183
1185
  isBindableStaticAccessExpression: () => isBindableStaticAccessExpression,
@@ -2257,7 +2259,7 @@ module.exports = __toCommonJS(typescript_exports);
2257
2259
 
2258
2260
  // src/compiler/corePublic.ts
2259
2261
  var versionMajorMinor = "5.6";
2260
- var version = `${versionMajorMinor}.0-dev.20240722`;
2262
+ var version = `${versionMajorMinor}.0-dev.20240723`;
2261
2263
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2262
2264
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2263
2265
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -5994,6 +5996,13 @@ var RelationComparisonResult = /* @__PURE__ */ ((RelationComparisonResult3) => {
5994
5996
  RelationComparisonResult3[RelationComparisonResult3["Overflow"] = 96] = "Overflow";
5995
5997
  return RelationComparisonResult3;
5996
5998
  })(RelationComparisonResult || {});
5999
+ var PredicateSemantics = /* @__PURE__ */ ((PredicateSemantics2) => {
6000
+ PredicateSemantics2[PredicateSemantics2["None"] = 0] = "None";
6001
+ PredicateSemantics2[PredicateSemantics2["Always"] = 1] = "Always";
6002
+ PredicateSemantics2[PredicateSemantics2["Never"] = 2] = "Never";
6003
+ PredicateSemantics2[PredicateSemantics2["Sometimes"] = 3] = "Sometimes";
6004
+ return PredicateSemantics2;
6005
+ })(PredicateSemantics || {});
5997
6006
  var GeneratedIdentifierFlags = /* @__PURE__ */ ((GeneratedIdentifierFlags2) => {
5998
6007
  GeneratedIdentifierFlags2[GeneratedIdentifierFlags2["None"] = 0] = "None";
5999
6008
  GeneratedIdentifierFlags2[GeneratedIdentifierFlags2["Auto"] = 1] = "Auto";
@@ -8337,7 +8346,7 @@ var sys = (() => {
8337
8346
  setTimeout,
8338
8347
  clearTimeout,
8339
8348
  clearScreen: () => {
8340
- process.stdout.write("\x1Bc");
8349
+ process.stdout.write("\x1B[2J\x1B[3J\x1B[H");
8341
8350
  },
8342
8351
  setBlocking: () => {
8343
8352
  var _a;
@@ -10078,6 +10087,11 @@ var Diagnostics = {
10078
10087
  Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled: diag(2866, 1 /* Error */, "Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_w_2866", "Import '{0}' conflicts with global value used in this file, so must be declared with a type-only import when 'isolatedModules' is enabled."),
10079
10088
  Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun: diag(2867, 1 /* Error */, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_2867", "Cannot find name '{0}'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun`."),
10080
10089
  Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig: diag(2868, 1 /* Error */, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_2868", "Cannot find name '{0}'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun` and then add 'bun' to the types field in your tsconfig."),
10090
+ Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish: diag(2869, 1 /* Error */, "Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish_2869", "Right operand of ?? is unreachable because the left operand is never nullish."),
10091
+ This_binary_expression_is_never_nullish_Are_you_missing_parentheses: diag(2870, 1 /* Error */, "This_binary_expression_is_never_nullish_Are_you_missing_parentheses_2870", "This binary expression is never nullish. Are you missing parentheses?"),
10092
+ This_expression_is_always_nullish: diag(2871, 1 /* Error */, "This_expression_is_always_nullish_2871", "This expression is always nullish."),
10093
+ 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."),
10094
+ 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."),
10081
10095
  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}'."),
10082
10096
  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}'."),
10083
10097
  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}'."),
@@ -82295,7 +82309,7 @@ function createTypeChecker(host) {
82295
82309
  setLastResult(state, checkExpression(node.right, checkMode));
82296
82310
  return state;
82297
82311
  }
82298
- checkGrammarNullishCoalesceWithLogicalExpression(node);
82312
+ checkNullishCoalesceOperands(node);
82299
82313
  const operator = node.operatorToken.kind;
82300
82314
  if (operator === 64 /* EqualsToken */ && (node.left.kind === 210 /* ObjectLiteralExpression */ || node.left.kind === 209 /* ArrayLiteralExpression */)) {
82301
82315
  state.skip = true;
@@ -82328,7 +82342,9 @@ function createTypeChecker(host) {
82328
82342
  if (operator === 56 /* AmpersandAmpersandToken */ || isIfStatement(parent2)) {
82329
82343
  checkTestingKnownTruthyCallableOrAwaitableOrEnumMemberType(node.left, leftType, isIfStatement(parent2) ? parent2.thenStatement : void 0);
82330
82344
  }
82331
- checkTruthinessOfType(leftType, node.left);
82345
+ if (isBinaryLogicalOperator(operator)) {
82346
+ checkTruthinessOfType(leftType, node.left);
82347
+ }
82332
82348
  }
82333
82349
  }
82334
82350
  }
@@ -82385,7 +82401,7 @@ function createTypeChecker(host) {
82385
82401
  state.typeStack[state.stackIndex + 1] = type;
82386
82402
  }
82387
82403
  }
82388
- function checkGrammarNullishCoalesceWithLogicalExpression(node) {
82404
+ function checkNullishCoalesceOperands(node) {
82389
82405
  const { left, operatorToken, right } = node;
82390
82406
  if (operatorToken.kind === 61 /* QuestionQuestionToken */) {
82391
82407
  if (isBinaryExpression(left) && (left.operatorToken.kind === 57 /* BarBarToken */ || left.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
@@ -82394,7 +82410,54 @@ function createTypeChecker(host) {
82394
82410
  if (isBinaryExpression(right) && (right.operatorToken.kind === 57 /* BarBarToken */ || right.operatorToken.kind === 56 /* AmpersandAmpersandToken */)) {
82395
82411
  grammarErrorOnNode(right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(right.operatorToken.kind), tokenToString(operatorToken.kind));
82396
82412
  }
82413
+ const leftTarget = skipOuterExpressions(left, 15 /* All */);
82414
+ const nullishSemantics = getSyntacticNullishnessSemantics(leftTarget);
82415
+ if (nullishSemantics !== 3 /* Sometimes */) {
82416
+ if (node.parent.kind === 226 /* BinaryExpression */) {
82417
+ error2(leftTarget, Diagnostics.This_binary_expression_is_never_nullish_Are_you_missing_parentheses);
82418
+ } else {
82419
+ if (nullishSemantics === 1 /* Always */) {
82420
+ error2(leftTarget, Diagnostics.This_expression_is_always_nullish);
82421
+ } else {
82422
+ error2(leftTarget, Diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish);
82423
+ }
82424
+ }
82425
+ }
82426
+ }
82427
+ }
82428
+ function getSyntacticNullishnessSemantics(node) {
82429
+ node = skipOuterExpressions(node);
82430
+ switch (node.kind) {
82431
+ case 223 /* AwaitExpression */:
82432
+ case 213 /* CallExpression */:
82433
+ case 212 /* ElementAccessExpression */:
82434
+ case 214 /* NewExpression */:
82435
+ case 211 /* PropertyAccessExpression */:
82436
+ case 229 /* YieldExpression */:
82437
+ return 3 /* Sometimes */;
82438
+ case 226 /* BinaryExpression */:
82439
+ switch (node.operatorToken.kind) {
82440
+ case 64 /* EqualsToken */:
82441
+ case 61 /* QuestionQuestionToken */:
82442
+ case 78 /* QuestionQuestionEqualsToken */:
82443
+ case 57 /* BarBarToken */:
82444
+ case 76 /* BarBarEqualsToken */:
82445
+ case 56 /* AmpersandAmpersandToken */:
82446
+ case 77 /* AmpersandAmpersandEqualsToken */:
82447
+ return 3 /* Sometimes */;
82448
+ }
82449
+ return 2 /* Never */;
82450
+ case 227 /* ConditionalExpression */:
82451
+ return getSyntacticNullishnessSemantics(node.whenTrue) | getSyntacticNullishnessSemantics(node.whenFalse);
82452
+ case 106 /* NullKeyword */:
82453
+ return 1 /* Always */;
82454
+ case 80 /* Identifier */:
82455
+ if (getResolvedSymbol(node) === undefinedSymbol) {
82456
+ return 1 /* Always */;
82457
+ }
82458
+ return 3 /* Sometimes */;
82397
82459
  }
82460
+ return 2 /* Never */;
82398
82461
  }
82399
82462
  function checkBinaryLikeExpression(left, operatorToken, right, checkMode, errorNode) {
82400
82463
  const operator = operatorToken.kind;
@@ -82402,7 +82465,7 @@ function createTypeChecker(host) {
82402
82465
  return checkDestructuringAssignment(left, checkExpression(right, checkMode), checkMode, right.kind === 110 /* ThisKeyword */);
82403
82466
  }
82404
82467
  let leftType;
82405
- if (isLogicalOrCoalescingBinaryOperator(operator)) {
82468
+ if (isBinaryLogicalOperator(operator)) {
82406
82469
  leftType = checkTruthinessExpression(left, checkMode);
82407
82470
  } else {
82408
82471
  leftType = checkExpression(left, checkMode);
@@ -86008,9 +86071,51 @@ function createTypeChecker(host) {
86008
86071
  function checkTruthinessOfType(type, node) {
86009
86072
  if (type.flags & 16384 /* Void */) {
86010
86073
  error2(node, Diagnostics.An_expression_of_type_void_cannot_be_tested_for_truthiness);
86074
+ } else {
86075
+ const semantics = getSyntacticTruthySemantics(node);
86076
+ if (semantics !== 3 /* Sometimes */) {
86077
+ error2(
86078
+ node,
86079
+ semantics === 1 /* Always */ ? Diagnostics.This_kind_of_expression_is_always_truthy : Diagnostics.This_kind_of_expression_is_always_falsy
86080
+ );
86081
+ }
86011
86082
  }
86012
86083
  return type;
86013
86084
  }
86085
+ function getSyntacticTruthySemantics(node) {
86086
+ node = skipOuterExpressions(node);
86087
+ switch (node.kind) {
86088
+ case 9 /* NumericLiteral */:
86089
+ if (node.text === "0" || node.text === "1") {
86090
+ return 3 /* Sometimes */;
86091
+ }
86092
+ return 1 /* Always */;
86093
+ case 209 /* ArrayLiteralExpression */:
86094
+ case 219 /* ArrowFunction */:
86095
+ case 10 /* BigIntLiteral */:
86096
+ case 231 /* ClassExpression */:
86097
+ case 218 /* FunctionExpression */:
86098
+ case 284 /* JsxElement */:
86099
+ case 285 /* JsxSelfClosingElement */:
86100
+ case 210 /* ObjectLiteralExpression */:
86101
+ case 14 /* RegularExpressionLiteral */:
86102
+ return 1 /* Always */;
86103
+ case 222 /* VoidExpression */:
86104
+ case 106 /* NullKeyword */:
86105
+ return 2 /* Never */;
86106
+ case 15 /* NoSubstitutionTemplateLiteral */:
86107
+ case 11 /* StringLiteral */:
86108
+ return !!node.text ? 1 /* Always */ : 2 /* Never */;
86109
+ case 227 /* ConditionalExpression */:
86110
+ return getSyntacticTruthySemantics(node.whenTrue) | getSyntacticTruthySemantics(node.whenFalse);
86111
+ case 80 /* Identifier */:
86112
+ if (getResolvedSymbol(node) === undefinedSymbol) {
86113
+ return 2 /* Never */;
86114
+ }
86115
+ return 3 /* Sometimes */;
86116
+ }
86117
+ return 3 /* Sometimes */;
86118
+ }
86014
86119
  function checkTruthinessExpression(node, checkMode) {
86015
86120
  return checkTruthinessOfType(checkExpression(node, checkMode), node);
86016
86121
  }
@@ -94637,7 +94742,7 @@ function collectExternalModuleInfo(context, sourceFile) {
94637
94742
  }
94638
94743
  }
94639
94744
  function addExportedFunctionDeclaration(node, name, isDefault) {
94640
- exportedFunctions.add(node);
94745
+ exportedFunctions.add(getOriginalNode(node, isFunctionDeclaration));
94641
94746
  if (isDefault) {
94642
94747
  if (!hasExportDefault) {
94643
94748
  multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name ?? context.factory.getDeclarationName(node));
@@ -99050,6 +99155,7 @@ function transformClassFields(context) {
99050
99155
  addRange(statementsOut, visitNodes2(statementsIn, visitor, isStatement, statementOffset));
99051
99156
  }
99052
99157
  function transformConstructorBody(node, constructor, isDerivedClass) {
99158
+ var _a;
99053
99159
  const instanceProperties = getProperties(
99054
99160
  node,
99055
99161
  /*requireInitializer*/
@@ -99143,12 +99249,12 @@ function transformClassFields(context) {
99143
99249
  setTextRange(
99144
99250
  factory2.createNodeArray(statements),
99145
99251
  /*location*/
99146
- constructor ? constructor.body.statements : node.members
99252
+ ((_a = constructor == null ? void 0 : constructor.body) == null ? void 0 : _a.statements) ?? node.members
99147
99253
  ),
99148
99254
  multiLine
99149
99255
  ),
99150
99256
  /*location*/
99151
- constructor ? constructor.body : void 0
99257
+ constructor == null ? void 0 : constructor.body
99152
99258
  );
99153
99259
  }
99154
99260
  function addPropertyOrClassStaticBlockStatements(statements, properties, receiver) {
@@ -112582,7 +112688,7 @@ function transformModule(context) {
112582
112688
  return factory2.updateLabeledStatement(
112583
112689
  node,
112584
112690
  node.label,
112585
- Debug.checkDefined(visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock))
112691
+ visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createExpressionStatement(factory2.createIdentifier(""))
112586
112692
  );
112587
112693
  }
112588
112694
  function visitWithStatement(node) {
@@ -112596,7 +112702,7 @@ function transformModule(context) {
112596
112702
  return factory2.updateIfStatement(
112597
112703
  node,
112598
112704
  visitNode(node.expression, visitor, isExpression),
112599
- Debug.checkDefined(visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)),
112705
+ visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createBlock([]),
112600
112706
  visitNode(node.elseStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)
112601
112707
  );
112602
112708
  }
@@ -114699,7 +114805,7 @@ function transformSystemModule(context) {
114699
114805
  return factory2.updateLabeledStatement(
114700
114806
  node,
114701
114807
  node.label,
114702
- Debug.checkDefined(visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock))
114808
+ visitNode(node.statement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createExpressionStatement(factory2.createIdentifier(""))
114703
114809
  );
114704
114810
  }
114705
114811
  function visitWithStatement(node) {
@@ -114713,7 +114819,7 @@ function transformSystemModule(context) {
114713
114819
  return factory2.updateIfStatement(
114714
114820
  node,
114715
114821
  visitNode(node.expression, visitor, isExpression),
114716
- Debug.checkDefined(visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)),
114822
+ visitNode(node.thenStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock) ?? factory2.createBlock([]),
114717
114823
  visitNode(node.elseStatement, topLevelNestedVisitor, isStatement, factory2.liftToBlock)
114718
114824
  );
114719
114825
  }
@@ -140232,10 +140338,8 @@ var DocumentHighlights;
140232
140338
  return [...nodes, container];
140233
140339
  }
140234
140340
  return nodes;
140235
- case 210 /* ObjectLiteralExpression */:
140236
- return void 0;
140237
140341
  default:
140238
- Debug.assertNever(container, "Invalid container kind.");
140342
+ return void 0;
140239
140343
  }
140240
140344
  }
140241
140345
  function pushKeywordIf(keywordList, token, ...expected) {
@@ -178879,6 +178983,7 @@ __export(ts_exports2, {
178879
178983
  PollingInterval: () => PollingInterval,
178880
178984
  PollingWatchKind: () => PollingWatchKind,
178881
178985
  PragmaKindFlags: () => PragmaKindFlags,
178986
+ PredicateSemantics: () => PredicateSemantics,
178882
178987
  PrivateIdentifierKind: () => PrivateIdentifierKind,
178883
178988
  ProcessLevel: () => ProcessLevel,
178884
178989
  ProgramUpdateLevel: () => ProgramUpdateLevel,
@@ -179915,6 +180020,7 @@ __export(ts_exports2, {
179915
180020
  isAwaitKeyword: () => isAwaitKeyword,
179916
180021
  isBigIntLiteral: () => isBigIntLiteral,
179917
180022
  isBinaryExpression: () => isBinaryExpression,
180023
+ isBinaryLogicalOperator: () => isBinaryLogicalOperator,
179918
180024
  isBinaryOperatorToken: () => isBinaryOperatorToken,
179919
180025
  isBindableObjectDefinePropertyCall: () => isBindableObjectDefinePropertyCall,
179920
180026
  isBindableStaticAccessExpression: () => isBindableStaticAccessExpression,
@@ -184183,13 +184289,13 @@ var Project2 = class _Project {
184183
184289
  var _a, _b, _c, _d;
184184
184290
  const originalProgram = this.program;
184185
184291
  const rootSourceFile = Debug.checkDefined((_a = this.program) == null ? void 0 : _a.getSourceFile(rootFile), "Expected file to be part of program");
184186
- const originalText = Debug.checkDefined(rootSourceFile.getText());
184292
+ const originalText = Debug.checkDefined(rootSourceFile.getFullText());
184187
184293
  (_b = this.getScriptInfo(rootFile)) == null ? void 0 : _b.editContent(0, originalText.length, updatedText);
184188
184294
  this.updateGraph();
184189
184295
  try {
184190
184296
  cb(this.program, originalProgram, (_c = this.program) == null ? void 0 : _c.getSourceFile(rootFile));
184191
184297
  } finally {
184192
- (_d = this.getScriptInfo(rootFile)) == null ? void 0 : _d.editContent(0, this.program.getSourceFile(rootFile).getText().length, originalText);
184298
+ (_d = this.getScriptInfo(rootFile)) == null ? void 0 : _d.editContent(0, updatedText.length, originalText);
184193
184299
  }
184194
184300
  }
184195
184301
  getCompilerOptionsForNoDtsResolutionProject() {
@@ -193244,6 +193350,7 @@ if (typeof console !== "undefined") {
193244
193350
  PollingInterval,
193245
193351
  PollingWatchKind,
193246
193352
  PragmaKindFlags,
193353
+ PredicateSemantics,
193247
193354
  PrivateIdentifierKind,
193248
193355
  ProcessLevel,
193249
193356
  ProgramUpdateLevel,
@@ -194280,6 +194387,7 @@ if (typeof console !== "undefined") {
194280
194387
  isAwaitKeyword,
194281
194388
  isBigIntLiteral,
194282
194389
  isBinaryExpression,
194390
+ isBinaryLogicalOperator,
194283
194391
  isBinaryOperatorToken,
194284
194392
  isBindableObjectDefinePropertyCall,
194285
194393
  isBindableStaticAccessExpression,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "typescript",
3
3
  "author": "Microsoft Corp.",
4
4
  "homepage": "https://www.typescriptlang.org/",
5
- "version": "5.6.0-dev.20240722",
5
+ "version": "5.6.0-dev.20240723",
6
6
  "license": "Apache-2.0",
7
7
  "description": "TypeScript is a language for application scale JavaScript development",
8
8
  "keywords": [
@@ -114,5 +114,5 @@
114
114
  "node": "20.1.0",
115
115
  "npm": "8.19.4"
116
116
  },
117
- "gitHead": "5929c963781a3f026a499746c7109a71b2400437"
117
+ "gitHead": "b04c8a0edd3a750cf5ae701d82fd164daa594381"
118
118
  }