Fix downstream crashes resulting from allowing module elements in a statement context
This commit is contained in:
parent
d01a9667fc
commit
4fcbbc8cce
2 changed files with 18 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -11187,6 +11187,7 @@ module ts {
|
|||
let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (<ModuleDeclaration>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 ? <SourceFile>node.parent : <ModuleDeclaration>node.parent.parent;
|
||||
if (container.kind === SyntaxKind.ModuleDeclaration && (<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(<SourceFile | ModuleDeclaration>container);
|
||||
|
||||
if (node.isExportEquals && !isInAmbientContext(node)) {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
|
|
Loading…
Reference in a new issue