fix(transpiler/dart): re-exporting only some bindings
``` export {Foo, Bar} from ‘./foo’; ==> export ‘./foo’ show Foo, Bar; ```
This commit is contained in:
parent
7a70f8f92d
commit
c5153175b6
|
@ -0,0 +1,3 @@
|
|||
export var Bar1 = 'BAR1';
|
||||
export var Bar2 = 'BAR2';
|
||||
export function Bar3() {}
|
|
@ -1 +1,2 @@
|
|||
export * from './foo';
|
||||
export {Bar1, Bar2} from './bar';
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue