Skip to content

Commit 1fbb1da

Browse files
authored
Add: ES6 exports / imports cheat sheet
eslint/js#43
1 parent 5302b33 commit 1fbb1da

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,77 @@
4848
+ [parserOptions.moduleResolver](#parseroptionsmoduleresolver)
4949
* [License](#license)
5050

51+
52+
53+
### ES6 exports / imports cheat sheet
54+
55+
> https://github.com/eslint/espree/pull/43
56+
>
57+
58+
```javascript
59+
// default exports
60+
export default 42;
61+
export default {};
62+
export default [];
63+
export default (1 + 2);
64+
export default foo;
65+
export default function () {}
66+
export default class {}
67+
export default function foo () {}
68+
export default class foo {}
69+
70+
// variables exports
71+
export var foo = 1;
72+
export var foo = function () {};
73+
export var bar;
74+
export let foo = 2;
75+
export let bar;
76+
export const foo = 3;
77+
export function foo () {}
78+
export class foo {}
79+
80+
// named exports
81+
export {};
82+
export {foo};
83+
export {foo, bar};
84+
export {foo as bar};
85+
export {foo as default};
86+
export {foo as default, bar};
87+
88+
// exports from
89+
export * from "foo";
90+
export {} from "foo";
91+
export {foo} from "foo";
92+
export {foo, bar} from "foo";
93+
export {foo as bar} from "foo";
94+
export {foo as default} from "foo";
95+
export {foo as default, bar} from "foo";
96+
export {default} from "foo";
97+
export {default as foo} from "foo";
98+
Import Syntax
99+
100+
// default imports
101+
import foo from "foo";
102+
import {default as foo} from "foo";
103+
104+
// named imports
105+
import {} from "foo";
106+
import {bar} from "foo";
107+
import {bar, baz} from "foo";
108+
import {bar as baz} from "foo";
109+
import {bar as baz, xyz} from "foo";
110+
111+
// glob imports
112+
import * as foo from "foo";
113+
114+
// mixing imports
115+
import foo, {baz as xyz} from "foo";
116+
import foo, * as bar from "foo";
117+
118+
// just import
119+
import "foo";
120+
```
121+
51122
## `package.json` TLDR
52123

53124
```jsonc

0 commit comments

Comments
 (0)