Babelify Scripts in Editor

Are there plans to Babelify the scripts for ES6/ES7 support in the editor?

1 Like

No plans at the moment. Generally speaking we keep all engine code and interfaces in vanilla JavaScript. So as to avoid adding additional layers for people to learn.

That said it would be nice to support additional workflows for all users…

1 Like

Although if you want to use ES6 features, you can, but that does not gives a guarantee it will work everywhere. So that is not recommended of course.
But if lets say you making game to be wrapped in stand-alone wrapper or mobile wrapper, and you know that this wrapper supports specific features, then its fine to use them so.

So babel actually transforms the code into valid ES5 syntax and has polyfills for APIs that don’t exist. The idea is that it will work everywhere, and you can start using future syntax today.

1 Like

There wouldn’t be anything new anyone would have to learn, because all original could would just work. This was more of a request for improvements that the writers of the scripts would benefit from, not so much the engine or app sourcecode you guys write.

Example change

pc.script.create('selector', function (app) {
  class Selector {
    constructor(entity) {
      this.entity = entity;
      this.selected = undefined;
    }
    
    // Called once after all resources are loaded and before the first update
    initialize () {
    }

    // Called every frame, dt is time in seconds since last update
    update (dt) {
    }
  }
  
  return Selector;
});
3 Likes

The same with TypeScript.

1 Like

Yeah would love this as a feature, JavaScript is moving too fast. Things like async/await, etc, are huge wins for developers.

2 Likes

i’d vote up for the feature request too. ES6/7 transpilation would be great.