plovr icon indicating copy to clipboard operation
plovr copied to clipboard

Possible ES6 Module Support

Open adityavohra7 opened this issue 9 years ago • 3 comments

Hello!

v20151216 of Closure Compiler (released after the version which officially started supporting ES6) understands ES6 modules. It also permits the intermingling of ES6 modules and "traditional" Closure JS files. This isn't, however, the case when the compiler is used through Plovr.

Plovr 5.0.0 comes bundled with Closure Compiler v20151216, but it doesn't seem to provide this ES6 module support. Plovr seems to have its own dependency resolution system which it uses to determine what files to feed to the built in closure compiler. And because this dependency resolution is seemingly based solely on goog.require/provide's, ES6 modules aren't "passed to the compiler". Is my understanding accurate? If yes, will Plovr eventually include ES6 module support?

Thanks!

adityavohra7 avatar Jan 29 '16 06:01 adityavohra7

bump. any update on this?

struys avatar Feb 03 '16 01:02 struys

someone would need to volunteer to contribute it. I have no idea how much work this would take.

nicks avatar Feb 10 '16 19:02 nicks

I just gave it a try and stopped at the following:

Need to include the file directly in your "inputs" field in config file of plovr. In my case:

"id": "formBuilder",
	"inputs": [
		"../js-formCommon/src/main/javascript/contexts/editions/objects/LabelEs6EditionContext.js",
		"../js-formBuilder/src/main/plovrRequires/soyDeps.js",
		"../js-formBuilder/src/main/javascript/Attach.js"
	]

Otherwise it will not be visible in RAW mode, since like adityavohra7 said "Plovr seems to have its own dependency resolution system which it uses to determine what files to feed to the built in closure compiler."

Then create an es6 module encapsulated in goog.loadModule() (I followed my instinct to make it work in RAW mode and this snippet).

goog.loadModule(function (exports) {
    "use strict";
    goog.module("fusionmd.contexts.editions.objects.LabelEs6EditionContext");
    exports = class LabelEs6EditionContext {
        constructor() {

        }
    };
    return exports;
});

To use the export you could invoke it like follow: const LabelEs6EditionContext = goog.module.get("fusionmd.contexts.editions.objects.LabelEs6EditionContext");

It all worked fine in RAW mode but I gave up when I tried to compile.

     [java] ../js-formBuilder/src/main/javascript/models/ToolboxDictionnary.js:20: ERROR - goog.module.get can not be called in global scope.
     [java] const LabelEs6EditionContext = goog.module.get("fusionmd.contexts.editions.objects.LabelEs6EditionContext");

gmalartre avatar Apr 25 '17 18:04 gmalartre