Skip to content

Commit

Permalink
Investigatory patch for microsoft#59001
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCavanaugh committed Jun 24, 2024
1 parent c219989 commit 30d5cf1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43948,6 +43948,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function helper(condExpr: Expression, body: Expression | Statement | undefined) {
const location = isLogicalOrCoalescingBinaryExpression(condExpr) ? skipParentheses(condExpr.right) : condExpr;

switch (condExpr.kind) {
case SyntaxKind.RegularExpressionLiteral:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.ClassExpression:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.JsxElement:
case SyntaxKind.JsxSelfClosingElement:
error(location, Diagnostics.Truthiness_test_of_this_kind_of_expression_appears_unintentional);
return;
}

if (isModuleExportsAccessExpression(location)) {
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3907,7 +3907,10 @@
"category": "Error",
"code": 2868
},

"Truthiness test of this kind of expression appears unintentional": {
"category": "Error",
"code": 2869
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
Expand Down

0 comments on commit 30d5cf1

Please sign in to comment.