srph
srph

Reputation: 1332

Shorthand for exporting an import

I've been meaning to do this with BabelJS, however I'm not sure whether Babel or the specifications support it at the moment.

Given Outer.js:

export default function() { }

The example below does not work.

export Outer from './Outer'

With CommonJS modules, this could be easily written as

exports.x = require('./x');

Upvotes: 5

Views: 3337

Answers (2)

JonnyReeves
JonnyReeves

Reputation: 6209

TypeScript 1.5 also supports the ES 2015 additional export-from statements syntax:

export { default as Injector } from './lib/Injector';

Which generates the following ES5:

var Injector_1 = require('./lib/Injector');
exports.Injector = Injector_1.default;

Upvotes: 3

alexpods
alexpods

Reputation: 48535

As of April 3, 2015, the BabelJS team has released v5.0 3 days ago which includes support for the said shorthand as stated in their blog post.

Lee Byron's stage 1 additional export-from statements proposal completes the symmetry between import and export statement, allowing you to easily export namespaces and defaults from external modules without modifying the local scope.

Exporting a default

export foo from "bar";

equivalent to:

import _foo from "bar";
export { _foo as foo };

Old Answer:

This export notation

export v from "mod";

does not supported in ES6 (look at supported examples in the specification), but it can be supported in ES7 (look at this proposal).

To achieve exactly the same result you must use import for now:

import Outer from './Outer';
export {Outer};

Upvotes: 4

Related Questions