Shorthand 用于导出导入

Shorthand for exporting an import

我一直想用 BabelJS 来做这件事,但是我不确定目前 Babel 或规范是否支持它。

给定 Outer.js:

export default function() { }

下面的例子不成立。

export Outer from './Outer'

使用 CommonJS 模块,这可以很容易地写成

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

截至 2015 年 4 月 3 日BabelJS 团队在 3 天前发布了 v5.0,其中包括对说 shorthand 正如他们在 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 };

旧答案:

这个导出符号

export v from "mod";

在 ES6 中不支持(查看支持的示例 in the specification), but it can be supported in ES7 (look at this proposal)。

要获得完全相同的结果,您现在必须使用import

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

TypeScript 1.5 还支持 ES 2015 附加导出语句语法:

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

生成以下 ES5:

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