Skip to content

Instantly share code, notes, and snippets.

@leecade
Forked from caridy/export-syntax.js
Created May 9, 2020 05:44
Show Gist options
  • Save leecade/a5220977f0beb3b9852b7f85c69f5cf5 to your computer and use it in GitHub Desktop.
Save leecade/a5220977f0beb3b9852b7f85c69f5cf5 to your computer and use it in GitHub Desktop.
ES6 Module Syntax Table
// 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";
// 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";
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment