Skip to content

Commit 4fcbbc8

Browse files
committed
Fix downstream crashes resulting from allowing module elements in a statement context
1 parent d01a966 commit 4fcbbc8

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/compiler/binder.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,11 @@ module ts {
661661
}
662662

663663
function bindExportAssignment(node: ExportAssignment) {
664-
if (node.expression.kind === SyntaxKind.Identifier) {
664+
if (!container.symbol || !container.symbol.exports) {
665+
// Export assignment in some sort of block construct
666+
bindAnonymousDeclaration(node, SymbolFlags.Alias, "");
667+
}
668+
else if (node.expression.kind === SyntaxKind.Identifier) {
665669
// An export default clause with an identifier exports all meanings of that identifier
666670
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
667671
}
@@ -672,7 +676,11 @@ module ts {
672676
}
673677

674678
function bindExportDeclaration(node: ExportDeclaration) {
675-
if (!node.exportClause) {
679+
if (!container.symbol || !container.symbol.exports) {
680+
// Export * in some sort of block construct
681+
bindAnonymousDeclaration(node, SymbolFlags.ExportStar, "");
682+
}
683+
else if (!node.exportClause) {
676684
// All export * declarations are collected in an __export symbol
677685
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None);
678686
}

src/compiler/checker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11187,6 +11187,7 @@ module ts {
1118711187
let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (<ModuleDeclaration>node.parent.parent).name.kind === SyntaxKind.StringLiteral;
1118811188
if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) {
1118911189
error(moduleName, node.kind === SyntaxKind.ExportDeclaration ?
11190+
// TODO: StatementFlags (clarify message)
1119011191
Diagnostics.Export_declarations_are_not_permitted_in_a_namespace :
1119111192
Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module);
1119211193
return false;
@@ -11311,6 +11312,11 @@ module ts {
1131111312
}
1131211313

1131311314
function checkExportAssignment(node: ExportAssignment) {
11315+
if (node.parent.kind !== SyntaxKind.SourceFile && node.parent.kind !== SyntaxKind.ModuleBlock) {
11316+
// TODO: StatementFlags
11317+
return;
11318+
}
11319+
1131411320
let container = node.parent.kind === SyntaxKind.SourceFile ? <SourceFile>node.parent : <ModuleDeclaration>node.parent.parent;
1131511321
if (container.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>container).name.kind === SyntaxKind.Identifier) {
1131611322
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
@@ -11326,7 +11332,8 @@ module ts {
1132611332
else {
1132711333
checkExpressionCached(node.expression);
1132811334
}
11329-
checkExternalModuleExports(container);
11335+
11336+
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
1133011337

1133111338
if (node.isExportEquals && !isInAmbientContext(node)) {
1133211339
if (languageVersion >= ScriptTarget.ES6) {

0 commit comments

Comments
 (0)