diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a0e177e7659..969e6dc8a4b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -661,7 +661,11 @@ module ts { } function bindExportAssignment(node: ExportAssignment) { - if (node.expression.kind === SyntaxKind.Identifier) { + if (!container.symbol || !container.symbol.exports) { + // Export assignment in some sort of block construct + bindAnonymousDeclaration(node, SymbolFlags.Alias, ""); + } + else if (node.expression.kind === SyntaxKind.Identifier) { // An export default clause with an identifier exports all meanings of that identifier declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); } @@ -672,7 +676,11 @@ module ts { } function bindExportDeclaration(node: ExportDeclaration) { - if (!node.exportClause) { + if (!container.symbol || !container.symbol.exports) { + // Export * in some sort of block construct + bindAnonymousDeclaration(node, SymbolFlags.ExportStar, ""); + } + else if (!node.exportClause) { // All export * declarations are collected in an __export symbol declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c8150d644a2..1ad31795beb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11187,6 +11187,7 @@ module ts { let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { error(moduleName, node.kind === SyntaxKind.ExportDeclaration ? + // TODO: StatementFlags (clarify message) Diagnostics.Export_declarations_are_not_permitted_in_a_namespace : Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module); return false; @@ -11311,6 +11312,11 @@ module ts { } function checkExportAssignment(node: ExportAssignment) { + if (node.parent.kind !== SyntaxKind.SourceFile && node.parent.kind !== SyntaxKind.ModuleBlock) { + // TODO: StatementFlags + return; + } + let container = node.parent.kind === SyntaxKind.SourceFile ? node.parent : node.parent.parent; if (container.kind === SyntaxKind.ModuleDeclaration && (container).name.kind === SyntaxKind.Identifier) { error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace); @@ -11326,7 +11332,8 @@ module ts { else { checkExpressionCached(node.expression); } - checkExternalModuleExports(container); + + checkExternalModuleExports(container); if (node.isExportEquals && !isInAmbientContext(node)) { if (languageVersion >= ScriptTarget.ES6) {