Three.js: Respect ES5 bundle format

Created on 13 Nov 2019  Â·  2Comments  Â·  Source: mrdoob/three.js

Description of the problem

Threejs dist are conain non-transpiled es6 syntax in es5 bundle (which pointed by packajge.json module property)

ES5 module package format mean that es5 bundle should not contain es6 features excepts import/export (due to support named imports and threeshaking feature).

Could you please improve your rollup config to supports specification:
https://github.com/rollup/rollup/wiki/pkg.module#wait-it-just-means-import-and-export--not-other-future-javascript-features

Example:
class BoxGeometry extends Geometry in https://raw.githubusercontent.com/mrdoob/three.js/dev/build/three.module.js

Three.js version
  • [x] Dev
  • [x] r110
  • [ ] ...
Browser
  • [x] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)
Suggestion

Most helpful comment

From your link (my bold added):

Wait, it just means import and export – not other future JavaScript features?
Yes. If you're using things like arrow functions and classes (or more exotic features like decorators and object spread), you should transpile them if you want your library to work in environments that don't support those features.

This is not a specification, just a note in a help document.

By not transpiling class in _three.module.js_, we are choosing not to support environments that don't support class. Users are responsible for transpiling their own code to work in such environments, or they can use the _three.js_ file instead.

I haven't followed the discussion around that decision closely, but this seems to be the idea:

  • _three.module.js_: support a limited set of ESNext features, evaluated and added on a case by case basis. Currently, just import/export and class I think?
  • _three.js_: Transpiled, ES5 code

BoxBufferGeometry was converted to a class in #17276 and the rest of the geometries are converted in #17425 (not merged yet).

All 2 comments

Note that ES2015 === ES6. The module entry in package.json is for ES6 Modules – there's no such thing as an ES5 Module, and there is no requirement that ES6 Modules published to npm restrict themselves to ES5 syntax other than import/export.

The decision to start using ES6 features is discussed in https://github.com/mrdoob/three.js/issues/6419 and https://github.com/mrdoob/three.js/issues/11552. I don't know whether there was a particular reason we aren't transpiling the module entry. We could, and there are pros/cons to that, but it is not required by any specification — could you explain why you need ES5 to be provided directly by three.js itself?

From your link (my bold added):

Wait, it just means import and export – not other future JavaScript features?
Yes. If you're using things like arrow functions and classes (or more exotic features like decorators and object spread), you should transpile them if you want your library to work in environments that don't support those features.

This is not a specification, just a note in a help document.

By not transpiling class in _three.module.js_, we are choosing not to support environments that don't support class. Users are responsible for transpiling their own code to work in such environments, or they can use the _three.js_ file instead.

I haven't followed the discussion around that decision closely, but this seems to be the idea:

  • _three.module.js_: support a limited set of ESNext features, evaluated and added on a case by case basis. Currently, just import/export and class I think?
  • _three.js_: Transpiled, ES5 code

BoxBufferGeometry was converted to a class in #17276 and the rest of the geometries are converted in #17425 (not merged yet).

Was this page helpful?
0 / 5 - 0 ratings