Limitations of Cyclic dependencies in ES6 modules/classes

176 views
Skip to first unread message

Björn Harrtell

unread,
Dec 26, 2015, 5:02:31 PM12/26/15
to Exploring ES6
Hi,

Thanks for Exploring ES6.

I've been investigating ES6 and CommonJS modules support for cyclic dependencies as a part of an effort to translate Java to ES6 via AST transformation (1).

A supported case in Java is cyclic dependencies in class hierarchies. An example in JTS (2), a well known Java library for Geometry, is that the base Geometry class imports subclasses of itself. If not refactored, this kind of relationship will give errors like this from Babel at runtime:

TypeError: Super expression must either be null or a function, not undefined
    at Object.babelHelpers.inherits 

I'm pretty sure that it's an intentionally unsupported case in Babel at the moment but I'm still not entirely sure it has to be (in post ES5 engines?), even if it can perhaps be considered bad design/practice.

In any case it's a bit sad for me since my effort to translate Java to ES6 otherwise seems to work pretty well. I actually made a manual port of JTS (3) to JavaScript some years ago, but it is getting old and I have no desire of manually updating it. I actually do not know why the manual port works, considering the cyclic dependencies. Perhaps it's because I've manually forced a dependency order that just happens to work out.

My point is, that it might be worthwhile to mention this limitation in Exploring ES6, in the section on cyclic dependencies (4). I've spent many fruitless hours trying to understand and get around this limitation. I have not been able to find out what magic is going on in Java compilers/runtimes to make it work there.


Regards

Björn Harrtell

Axel Rauschmayer

unread,
Dec 26, 2015, 8:36:22 PM12/26/15
to Exploring ES6
Sounds complicated! Offhand, I don’t know how I’d fix this.

Björn Harrtell

unread,
Dec 27, 2015, 11:16:14 AM12/27/15
to Exploring ES6
Yeah in my case it's complicated... and I suspect there is no fix coming, ever.

But I think it would be good to put out knowledge about this. It's easy to make an example of with a few dummy classes to demonstrate this without bringing in my issue of Java translation. People might assume it should work with the current section on cyclic dependencies in Exploring ES6 (or if comming from a Java background). Do you have any interest in expanding that section? I could provide a simple as possible example.
Reply all
Reply to author
Forward
0 new messages