From 27941916d528380140b7e73032c14c96415964bb Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 26 Sep 2018 10:01:57 -0700 Subject: [PATCH 1/2] Minor cleanup in bindNamespaceExportDeclaration --- src/compiler/binder.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 38d6f55824254..58c56be5a65a4 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2310,27 +2310,20 @@ namespace ts { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Modifiers_cannot_appear_here)); } - - if (node.parent.kind !== SyntaxKind.SourceFile) { - file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_at_top_level)); - return; + const diag = !isSourceFile(node.parent) + ? Diagnostics.Global_module_exports_may_only_appear_at_top_level + : !isExternalModule(node.parent) + ? Diagnostics.Global_module_exports_may_only_appear_in_module_files + : !node.parent.isDeclarationFile + ? Diagnostics.Global_module_exports_may_only_appear_in_declaration_files + : undefined; + if (diag) { + file.bindDiagnostics.push(createDiagnosticForNode(node, diag)); } else { - const parent = node.parent as SourceFile; - - if (!isExternalModule(parent)) { - file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_in_module_files)); - return; - } - - if (!parent.isDeclarationFile) { - file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_in_declaration_files)); - return; - } + file.symbol.globalExports = file.symbol.globalExports || createSymbolTable(); + declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } - - file.symbol.globalExports = file.symbol.globalExports || createSymbolTable(); - declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } function bindExportDeclaration(node: ExportDeclaration) { From 6c1541a18ceb1261da97eb2239dbf99321586588 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 1 Oct 2018 09:25:29 -0700 Subject: [PATCH 2/2] Change formatting --- src/compiler/binder.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 58c56be5a65a4..d4a751665f2bc 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2310,12 +2310,9 @@ namespace ts { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Modifiers_cannot_appear_here)); } - const diag = !isSourceFile(node.parent) - ? Diagnostics.Global_module_exports_may_only_appear_at_top_level - : !isExternalModule(node.parent) - ? Diagnostics.Global_module_exports_may_only_appear_in_module_files - : !node.parent.isDeclarationFile - ? Diagnostics.Global_module_exports_may_only_appear_in_declaration_files + const diag = !isSourceFile(node.parent) ? Diagnostics.Global_module_exports_may_only_appear_at_top_level + : !isExternalModule(node.parent) ? Diagnostics.Global_module_exports_may_only_appear_in_module_files + : !node.parent.isDeclarationFile ? Diagnostics.Global_module_exports_may_only_appear_in_declaration_files : undefined; if (diag) { file.bindDiagnostics.push(createDiagnosticForNode(node, diag));