diff --git a/tools/transpiler/spec/bar.js b/tools/transpiler/spec/bar.js new file mode 100644 index 0000000000..ee9c96d3ba --- /dev/null +++ b/tools/transpiler/spec/bar.js @@ -0,0 +1,3 @@ +export var Bar1 = 'BAR1'; +export var Bar2 = 'BAR2'; +export function Bar3() {} diff --git a/tools/transpiler/spec/export.js b/tools/transpiler/spec/export.js index d6c3be1839..27d3ded4d9 100644 --- a/tools/transpiler/spec/export.js +++ b/tools/transpiler/spec/export.js @@ -1 +1,2 @@ export * from './foo'; +export {Bar1, Bar2} from './bar'; diff --git a/tools/transpiler/spec/imports_spec.js b/tools/transpiler/spec/imports_spec.js index f71941de70..62563f7a28 100644 --- a/tools/transpiler/spec/imports_spec.js +++ b/tools/transpiler/spec/imports_spec.js @@ -1,4 +1,4 @@ -import {describe, it, expect} from 'test_lib/test_lib'; +import {describe, it, expect, IS_DARTIUM} from 'test_lib/test_lib'; import {Foo, Bar} from './foo'; // TODO: Does not work, as dart does not support renaming imports @@ -21,6 +21,18 @@ export function main() { expect(exportModule.Foo).toBe('FOO'); expect(exportModule.Bar).toBe('BAR'); + expect(exportModule.Bar1).toBe('BAR1'); + expect(exportModule.Bar2).toBe('BAR2'); + + // Make sure Bar3 is not re-exported. + expect(function() { + exportModule.Bar3(); + }).toThrowError(IS_DARTIUM ? + // Dart + "No top-level method 'exportModule.Bar3' declared.": + // JavaScript + 'undefined is not a function' + ); expect(Type).toBeTruthy(); }); diff --git a/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js b/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js index 902091fbce..503ca3f59b 100644 --- a/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js +++ b/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js @@ -25,6 +25,7 @@ import { import {ParseTreeWriter as JavaScriptParseTreeWriter, ObjectLiteralExpression} from 'traceur/src/outputgeneration/ParseTreeWriter'; import {ImportedBinding, BindingIdentifier} from 'traceur/src/syntax/trees/ParseTrees'; import {IdentifierToken} from 'traceur/src/syntax/IdentifierToken'; +import {EXPORT_STAR} from 'traceur/src/syntax/trees/ParseTreeType'; export class DartParseTreeWriter extends JavaScriptParseTreeWriter { constructor(moduleName, outputPath) { @@ -275,12 +276,34 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter { // EXPORTS visitExportDeclaration(tree) { if (tree.declaration.moduleSpecifier) { - this.write_('export'); - this.writeSpace_(); - this.visitModuleSpecifier(tree.declaration.moduleSpecifier); - this.write_(SEMI_COLON); + if (tree.declaration.specifierSet.type === EXPORT_STAR) { + // export * from './foo' + // ===> + // export './foo'; + this.write_('export'); + this.writeSpace_(); + this.visitModuleSpecifier(tree.declaration.moduleSpecifier); + this.write_(SEMI_COLON); + } else { + // export {Foo, Bar} from './foo' + // ===> + // export './foo' show Foo, Bar; + this.write_('export'); + this.writeSpace_(); + this.visitModuleSpecifier(tree.declaration.moduleSpecifier); + this.writeSpace_(); + this.write_('show'); + this.writeSpace_(); + this.writeList_(tree.declaration.specifierSet.specifiers, COMMA, false); + this.write_(SEMI_COLON); + } } else { - // remove "export" + // Just remove the "export" keyword. + // export var x = true; + // export class Foo {} + // ===> + // var x = true; + // class Foo {} this.writeAnnotations_(tree.annotations); this.visitAny(tree.declaration); }