How to solve this basic ES6-module circular dependency problem?
/#!/JoePea
joe at trusktr.io
Tue Aug 9 20:05:27 UTC 2016
Oops, I forgot the export in module C:
```js
// --- Module C
import A from './A'
import B from './B'
console.log('Module C', A, B)
class C {
constructor() {
// this may run later, after all three modules are evaluated, or
// possibly never.
console.log(A)
console.log(B)
}
}
export {C as default} // export!
```
*/#!/*JoePea
On Tue, Aug 9, 2016 at 1:03 PM, /#!/JoePea <joe at trusktr.io> wrote:
> I have the very basic problem detailed at http://stackoverflow.com/
> questions/38841469, but thought I'd bring it up here because it makes me
> wonder about the ES6 Module system.
>
> Why is it that the body of module C is not evaluated before the bodies of
> modules A and B? I'm just wondering, because if that were the case, then it
> would work and the entrypoint would eventually be evaluated without errors.
>
> A possibility could be that maybe it *should* work, and that my ES6 module
> environment simply doesn't handle it as it should? (But I'm not familiar
> enough with the spec, so that's why I'm not sure about that.)
>
> These are the modules, posted here for convenience:
>
> ```js
> // --- Entrypoint
>
> import A from './app/A'
> console.log('Entrypoint', A)
> ```
>
> ```js
> // --- Module A
>
> import C from './C'
>
> console.log('Module A', C)
>
> class A extends C {
> // ...
> }
>
> export {A as default}
> ```
>
> ```js
> // --- Module B
>
> import C from './C'
>
> console.log('Module B', C)
>
> class B extends C {
> // ...
> }
>
> export {B as default}
> ```
>
> ```js
> // --- Module C
>
> import A from './A'
> import B from './B'
>
> console.log('Module C', A, B)
>
> class C {
> constructor() {
> // this may run later, after all three modules are evaluated, or
> // possibly never.
> console.log(A)
> console.log(B)
> }
> }
> ```
>
> */#!/*JoePea
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160809/3639935a/attachment-0001.html>
More information about the es-discuss
mailing list