Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37599,6 +37599,7 @@ namespace ts {
(condExpr.operatorToken.kind === SyntaxKind.BarBarToken || condExpr.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken)
? condExpr.right
: condExpr;
if (isModuleExportsAccessExpression(location)) return;
const type = checkTruthinessExpression(location);
const isPropertyExpressionCast = isPropertyAccessExpression(location) && isTypeAssertion(location.expression);
if (getFalsyFlags(type) || isPropertyExpressionCast) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/compiler/a.js ===
function fn() {}
>fn : Symbol(fn, Decl(a.js, 0, 0))

if (typeof module === 'object' && module.exports) {
>module : Symbol(module, Decl(a.js, 2, 51))
>module.exports : Symbol(module.exports, Decl(a.js, 0, 0))
>module : Symbol(module, Decl(a.js, 2, 51))
>exports : Symbol(module.exports, Decl(a.js, 0, 0))

module.exports = fn;
>module.exports : Symbol(module.exports, Decl(a.js, 0, 0))
>module : Symbol(export=, Decl(a.js, 2, 51))
>exports : Symbol(export=, Decl(a.js, 2, 51))
>fn : Symbol(fn, Decl(a.js, 0, 0))
}

22 changes: 22 additions & 0 deletions 22 tests/baselines/reference/truthinessCallExpressionCoercion4.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== tests/cases/compiler/a.js ===
function fn() {}
>fn : () => void

if (typeof module === 'object' && module.exports) {
>typeof module === 'object' && module.exports : false | (() => void)
>typeof module === 'object' : boolean
>typeof module : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>module : { exports: () => void; }
>'object' : "object"
>module.exports : () => void
>module : { exports: () => void; }
>exports : () => void

module.exports = fn;
>module.exports = fn : () => void
>module.exports : () => void
>module : { exports: () => void; }
>exports : () => void
>fn : () => void
}

11 changes: 11 additions & 0 deletions 11 tests/cases/compiler/truthinessCallExpressionCoercion4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @checkJs: true
// @allowJs: true
// @strict: true
// @noEmit: true
// @filename: a.js

function fn() {}

if (typeof module === 'object' && module.exports) {
module.exports = fn;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.