Disallow export declarations in internal modules

This commit is contained in:
Mohamed Hegazy
2015-03-24 21:17:11 -07:00
parent 27c5d6fa50
commit 6c40c95313
13 changed files with 201 additions and 284 deletions

View File

@@ -10236,6 +10236,11 @@ module ts {
// export { x, y }
// export { x, y } from "foo"
forEach(node.exportClause.elements, checkExportSpecifier);
let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (<ModuleDeclaration>node.parent.parent).name.kind === SyntaxKind.StringLiteral;
if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) {
error(node, Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module);
}
}
else {
// export * from "foo"

View File

@@ -3838,35 +3838,7 @@ module ts {
}
function emitExportDeclaration(node: ExportDeclaration) {
if (node.parent.kind !== SyntaxKind.SourceFile) {
// internal module
if (node.exportClause) {
// export { x, y, ... }
for (let specifier of node.exportClause.elements) {
if (resolver.isValueAliasDeclaration(specifier)) {
writeLine();
emitStart(specifier);
emitContainingModuleName(specifier);
write(".");
emitNodeWithoutSourceMap(specifier.name);
write(" = ");
var name = specifier.propertyName || specifier.name;
var generatedName = getGeneratedNameForIdentifier(name);
if (generatedName) {
write(generatedName);
}
else {
emitExpressionIdentifier(name);
}
write(";");
emitEnd(specifier);
}
}
}
}
else if (languageVersion < ScriptTarget.ES6) {
if (languageVersion < ScriptTarget.ES6) {
if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) {
emitStart(node);
let generatedName = resolver.getGeneratedNameForNode(node);