Do Anonymous Exports Solve the Backwards Compatibility Problem?
dherman at mozilla.com
Wed Dec 19 14:29:42 PST 2012
On Dec 18, 2012, at 12:56 PM, Kevin Smith <khs4473 at gmail.com> wrote:
> At first glance, it seems like anonymous exports might provide a way for pre-ES6 (read: Node) modules and ES6 modules to coexist.
That's not what anonymous exports are for. They're there to support the use case of modules that want to support a popular idiom, a style.
> There are two directions that an interop strategy will have to deal with. First, we might want an ES6 module to be loaded by a pre-ES6 module:
> // "es5-module.js"
> var ES6Module = require("es6-module.js");
> We might want to use this when a dependency is upgraded to ES6 modules and we want to leave the dependent alone. Now, since ES6 modules are asynchronous, and require is synchronous, we must load "es6-module.js" *before* "es5-module.js" is executed. The only way to do that is to statically analyze "es5-module.js", searching for calls to require.
If you want to use Node modules in the browser, well, you'll have to get more clever, but I don't think we need to solve this problem in ES6.
> What about the other direction? Let's say that we want to load an ES5 module from an ES6 module:
Loader hooks are the answer here.
More information about the es-discuss