EcmaScript module syntax

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
// default exports
export default
export default
export default
export default
export default
export default
export default
export default
export default
// inline exports
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 {}
// named exports
export {};
export {foo};
export {foo, bar};
export {foo as bar};
export {foo as default};
export {foo as default, bar};
// exports from (re-exports)
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
// default imports
import foo from “foo”;
import {default as foo} from “foo”;
// named imports
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”;
// glob imports
import * as foo from “foo”;
// mixing imports
import foo, {baz as xyz} from “foo”;
import foo, * as bar from “foo”;
// just import
import “foo”;