Skip to content
This repository was archived by the owner on Mar 29, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add tests and basic support for batch exports.
  • Loading branch information
eventualbuddha committed Oct 24, 2014
commit fba1bf83e30175be2075d60ba436ca7e3f8410d3
24 changes: 20 additions & 4 deletions lib/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ ExportDeclarationList.prototype.declarationForNode = function(node) {
} else if (n.FunctionDeclaration.check(node.declaration)) {
return new FunctionExportDeclaration(this.module, node);
} else if (n.ExportBatchSpecifier.check(node.specifiers[0])) {
throw new Error(
'`export *` found at ' + sourcePosition(this.module, node) +
' is not supported, please use `export { … }` instead'
);
return new BatchExportDeclaration(this.module, node);
} else {
return new NamedExportDeclaration(this.module, node);
}
Expand Down Expand Up @@ -225,6 +222,25 @@ memo(FunctionExportDeclaration.prototype, 'specifiers', /** @this FunctionExport
return [new ExportSpecifier(this, this.node.declaration)];
});

/**
* Represents an batch export declaration.
*
* @constructor
* @extends ExportDeclaration
* @param {Module} mod
* @param {AST.ExportDeclaration} node
*/
function BatchExportDeclaration(mod, node) {
ExportDeclaration.call(this, mod, node);
}
extend(BatchExportDeclaration, ExportDeclaration);

memo(BatchExportDeclaration.prototype, 'specifiers', /** @this BatchExportDeclaration */function() {
return this.source.exports.declarations.reduce(function(specifiers, declaration) {
return specifiers.concat(declaration.specifiers);
}, []);
});

/**
* Represents an export specifier in an export declaration.
*
Expand Down
5 changes: 5 additions & 0 deletions test/examples/batch-export/first.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* jshint esnext:true */

export var a = 1;
export var b = 2;
export var c = 3;
4 changes: 4 additions & 0 deletions test/examples/batch-export/second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* jshint esnext:true */

export var c = 99;
export * from './first';
7 changes: 7 additions & 0 deletions test/examples/batch-export/third.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* jshint esnext:true */

import { a, b, c } from './second';

assert.strictEqual(a, 1);
assert.strictEqual(b, 2);
assert.strictEqual(c, 99);