mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 01:33:15 -05:00
Export * and export { names } emit in es6 format
Conflicts: src/compiler/emitter.ts tests/baselines/reference/es6ExportAll.js tests/baselines/reference/es6ExportClause.js tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js
This commit is contained in:
@@ -5108,7 +5108,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitImportSpecifier(node: ImportSpecifier) {
|
||||
function emitImportOrExportSpecifier(node: ImportSpecifier) {
|
||||
Debug.assert(languageVersion >= ScriptTarget.ES6);
|
||||
if (node.propertyName) {
|
||||
emit(node.propertyName);
|
||||
@@ -5186,42 +5186,61 @@ module ts {
|
||||
}
|
||||
|
||||
function emitExportDeclaration(node: ExportDeclaration) {
|
||||
if (node.moduleSpecifier) {
|
||||
emitStart(node);
|
||||
var generatedName = resolver.getGeneratedNameForNode(node);
|
||||
if (compilerOptions.module !== ModuleKind.AMD) {
|
||||
write("var ");
|
||||
write(generatedName);
|
||||
write(" = ");
|
||||
emitRequire(getExternalModuleName(node));
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
if (node.moduleSpecifier) {
|
||||
emitStart(node);
|
||||
var generatedName = resolver.getGeneratedNameForNode(node);
|
||||
if (compilerOptions.module !== ModuleKind.AMD) {
|
||||
write("var ");
|
||||
write(generatedName);
|
||||
write(" = ");
|
||||
emitRequire(getExternalModuleName(node));
|
||||
}
|
||||
if (node.exportClause) {
|
||||
// export { x, y, ... }
|
||||
forEach(node.exportClause.elements, specifier => {
|
||||
writeLine();
|
||||
emitStart(specifier);
|
||||
emitContainingModuleName(specifier);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
write(" = ");
|
||||
write(generatedName);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.propertyName || specifier.name);
|
||||
write(";");
|
||||
emitEnd(specifier);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// export *
|
||||
var tempName = createTempVariable(node).text;
|
||||
writeLine();
|
||||
write("for (var " + tempName + " in " + generatedName + ") if (!");
|
||||
emitContainingModuleName(node);
|
||||
write(".hasOwnProperty(" + tempName + ")) ");
|
||||
emitContainingModuleName(node);
|
||||
write("[" + tempName + "] = " + generatedName + "[" + tempName + "];");
|
||||
}
|
||||
emitEnd(node);
|
||||
}
|
||||
}
|
||||
else {
|
||||
write("export ");
|
||||
if (node.exportClause) {
|
||||
// export { x, y, ... }
|
||||
forEach(node.exportClause.elements, specifier => {
|
||||
writeLine();
|
||||
emitStart(specifier);
|
||||
emitContainingModuleName(specifier);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
write(" = ");
|
||||
write(generatedName);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.propertyName || specifier.name);
|
||||
write(";");
|
||||
emitEnd(specifier);
|
||||
});
|
||||
write("{ ");
|
||||
emitCommaList(node.exportClause.elements);
|
||||
write(" }");
|
||||
}
|
||||
else {
|
||||
// export *
|
||||
var tempName = createTempVariable(node).text;
|
||||
writeLine();
|
||||
write("for (var " + tempName + " in " + generatedName + ") if (!");
|
||||
emitContainingModuleName(node);
|
||||
write(".hasOwnProperty(" + tempName + ")) ");
|
||||
emitContainingModuleName(node);
|
||||
write("[" + tempName + "] = " + generatedName + "[" + tempName + "];");
|
||||
write("*");
|
||||
}
|
||||
emitEnd(node);
|
||||
if (node.moduleSpecifier) {
|
||||
write(" from ");
|
||||
emit(node.moduleSpecifier);
|
||||
}
|
||||
write(";");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5689,7 +5708,8 @@ module ts {
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
return emitImportDeclaration(<ImportDeclaration>node);
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
return emitImportSpecifier(<ImportSpecifier>node);
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
return emitImportOrExportSpecifier(<ImportOrExportSpecifier>node);
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
return emitImportEqualsDeclaration(<ImportEqualsDeclaration>node);
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
|
||||
Reference in New Issue
Block a user