Created
June 9, 2014 20:41
-
-
Save mariusGundersen/f11d439f1fb7cebe3c58 to your computer and use it in GitHub Desktop.
Peculiarities in ES6 modules
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
//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"); |
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
//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 |
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
//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