-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about a generated closures. #219
Comments
Ideally we would like it to produce this: function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
Geometry.call( this );
this.type = 'BoxGeometry';
}
BoxGeometry.prototype = Object.create( Geometry.prototype );
BoxGeometry.prototype.constructor = BoxGeometry; |
@mrdoob @Mugen87 as far as I know, the closure is necessary in case of subclassing because superclass reference can otherwise change, leading to broken class Foo {}
class Bar extends Foo {}
Foo = null;
new Bar(); This code will throw if transpiled without a closure. TypeScript behaves the same way (adding a closure), and Babel probably is too. if ( Geometry ) BoxGeometry.__proto__ = Geometry; This line is necessary to inherit static methods. Checks for whether superclass is falsy are necessary for compatibility, because ES allows code like |
@mourner The ideal output I shared is the current pattern the whole library uses. We were hoping to adopt ES6 classes, and be able to produce the same ES5 build (or as close as possible). |
@mrdoob yeah, I see, although it's unlikely to be achievable with Buble without some custom transforms — we can't sacrifice compatibility for a few more bytes that are likely mitigated by gzip. BTW I'm wondering what you think about dropping IE11 support — any rough timelines? That would produce a lean build and make transpilation unnecessary. |
Yeah I understand. FWIW, is not about bytes, but about avoiding side effects. If the ES5 code remains the same I can go to sleep wihtout worrying that in a random config somewhere the extra closure is not changing something or affecting performance somehow.
The |
@mourner now that you're here... are you planning on adding a "module" export to |
@mrdoob oh yes :) Let's discuss there: mapbox/earcut#126 |
Ended up doing a rollup transform to cleans this up: mrdoob/three.js#19934 |
This can be closed. |
We at the
three.js
team try move our code base to ES6 classes and want to use Bublé to generate ES2015 code. When inspecting the output, we noticed that Bublé produces a closure around class definitions iff the class is inherited from another one. Consider this (stripped-down) code:Bublé produces:
Is there a way to avoid the closure around
BoxGeometry
(see mrdoob/three.js#17276 (comment))?The text was updated successfully, but these errors were encountered: