来自 stackoverflow 一个问题(ES6+ javascript module export options)的答案:#34842087,很全面的 ES6 Module 导入/导出语法,出自 eslint/espree/pull/43,为方便之后查阅特记录于此:
This is the bulk of the module grammar from TC39, the exact same supported by esprima today in the harmony branch. This PR includes:
import
grammarexport
grammar- option
sourceType=module
to enable strict mode
, import
, export
and any other module’s feature.
Export Syntax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| export default 42; export default {}; export default []; export default (1 + 2); export default foo; export default function () {} export default class {} export default function foo () {} export default class foo {}
export var foo = 1; export var foo = function () {}; export var bar; export let foo = 2; export let bar; export const foo = 3; export function foo () {} export class foo {}
export {}; export {foo}; export {foo, bar}; export {foo as bar}; export {foo as default}; export {foo as default, bar};
export * from "foo"; export {} from "foo"; export {foo} from "foo"; export {foo, bar} from "foo"; export {foo as bar} from "foo"; export {foo as default} from "foo"; export {foo as default, bar} from "foo"; export {default} from "foo"; export {default as foo} from "foo";
|
Import Syntax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import foo from "foo"; import {default as foo} from "foo";
import {} from "foo"; import {bar} from "foo"; import {bar, baz} from "foo"; import {bar as baz} from "foo"; import {bar as baz, xyz} from "foo";
import * as foo from "foo";
import foo, {baz as xyz} from "foo"; import foo, * as bar from "foo";
import "foo";
|