diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index ad02d84a35bdd..96db98d337a73 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1625,15 +1625,8 @@ namespace ts { } function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean { - const body = node.kind === SyntaxKind.SourceFile ? node : node.body; - if (body && (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock)) { - for (const stat of (body).statements) { - if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) { - return true; - } - } - } - return false; + const body = isSourceFile(node) ? node : tryCast(node.body, isModuleBlock); + return !!body && body.statements.some(s => isExportDeclaration(s) || isExportAssignment(s)); } function setExportContextFlag(node: ModuleDeclaration | SourceFile) {