Skip to content

Instantly share code, notes, and snippets.

@mariusGundersen
Created June 9, 2014 20:41
Show Gist options
  • Save mariusGundersen/f11d439f1fb7cebe3c58 to your computer and use it in GitHub Desktop.
Save mariusGundersen/f11d439f1fb7cebe3c58 to your computer and use it in GitHub Desktop.
Peculiarities in ES6 modules
//The file foobar.js contains these two lines of code
var foo = "foo", bar = "bar";
export default = {foo, bar};
//It can now be imported into another module using either of these two lines:
import foobar from "foobar";
module foobar from "foobar";
//But not this line:
import {foo, bar} from "foobar";
//but it can be imported and destructured using the System/Loader API:
var foobar = System.import("foobar");
var {foo, bar} = System.import("foobar");
//import looks like destructuring
import {map, filter, reduce} from "underscore";
let {map, filter, redcue} = System.import("underscore");
//but the ImportSpecifier[1] is not the AssignmentProperty[2]
import {map as select, filter as where, reduce as aggregate} from "underscore";
let {map: select, filter: where, reduce: aggregate} = System.import("underscore");
//[1]: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports
//[2]: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-destructuring-assignment
//The file foobar.js contains these two lines of code
var foo = "foo", bar = "bar";
export {foo, bar};
//It can now be imported into another module using either of these two lines:
import {foo, bar} from "foobar";
module foobar from "foobar";
//But not this line:
import foobar from "foobar";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment