fix: Don’t break on circular imports#154
Conversation
b35a3d4 to
d845f08
Compare
|
As discussed in jsdom/jsdom#2770 (comment) I would prefer not to do this. |
|
Well, this is also closer to how ECMAScript modules work. |
|
Until we drop support for Node 10 (in May 2021) and start leveraging ES module, using I found myself introducing new circular dependency issues when working jsdom/jsdom#2548. There is one interesting case with
Using |
|
OK. While I still think that we should avoid circular dependencies whenever possible (e.g. we should merge attributes.js and Attr-impl.js), I can understand that the web platform we're implementing is not so cleanly layered, and so perhaps we should allow them in some cases. |
Needed for jsdom/jsdom#2770 and converting
Windowto use WebIDL (jsdom/jsdom#2771).Re‑assigning
module.exportsbreaks circularrequire(…)s, as any module that was evaluated beforemodule.exportswas re-assigned will keep the reference to the old object, which is still empty.By instead creating data properties on
exportsand treating it as a constant, then every reference will have all the properties after all modules have been evaluated.This is also closer to how ECMAScript modules work.