Last active
January 15, 2022 14:22
-
-
Save caridy/839d5359321604a12648 to your computer and use it in GitHub Desktop.
ES6 Module Syntax Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// default exports | |
export default 42; | |
export default {}; | |
export default []; | |
export default foo; | |
export default function () {} | |
export default class {} | |
export default function foo () {} | |
export default class foo {} | |
// variables exports | |
export var foo = 1; | |
export var foo = function () {}; | |
export var bar; // lazy initialization | |
export let foo = 2; | |
export let bar; // lazy initialization | |
export const foo = 3; | |
export function foo () {} | |
export class foo {} | |
// named exports | |
export {foo}; | |
export {foo, bar}; | |
export {foo as bar}; | |
export {foo as default}; | |
export {foo as default, bar}; | |
// exports from | |
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// default imports | |
import foo from "foo"; | |
import {default as foo} from "foo"; | |
// named imports | |
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 * as bar, {baz as xyz} from "foo"; | |
import foo, * as bar, {baz as xyz} from "foo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const bar; | |
// const variables must have an initializer | |
export foo; | |
// Unexpected token identifier, invalid named export syntax | |
export function () {} | |
// Unexpected token (, use a function declaration instead | |
export function default () {} | |
// Unexpected token default | |
import foo; | |
// Missing from after import | |
import { foo, bar }; | |
// Missing from after import | |
import foo from bar; | |
// Invalid module specifier | |
import default from "foo"; | |
// Unexpected token default | |
export default from "foo"; | |
// Unexpected token from | |
export {default}; | |
// Missing from after export | |
export *; | |
// Missing from after export | |
import {default as foo}; | |
// Missing from after import | |
import * from "foo"; | |
// Missing as after import *' | |
export default = 42; | |
// Unexpected token = | |
import {bar as default} from "foo"; | |
// Unexpected token default |
Thanks man
Yes, very clear, very useful.
I was facing issue in importing a module. This helped me in resolving it. Thanks. Keep up the good work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is exactly what I was looking for, Thank you!!