closure-compiler: Undefined $jscomp during Class Inheritence (ES6 to ES5 Strict)
The following class declaration:
class Job extends JobModelMixin { ... }
Yields the following line when compiled into ES5-Strict,
$jscomp.inherits(Job, JobModelMixin);
But is missing the definition of $jscomp and so throws an error.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 51 (32 by maintainers)
@jd8
var $jscompis defined at https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/js/base.js#L26.$jscomp.inheritsis defined at https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/js/es6_runtime.js#L91. You can manually inject those files for now.whitespace-only mode is used for file-by-file transpilation, and in those cases we don’t want the runtime libraries injected in every file. There’s not currently a flag to tell it to inject libraries as needed i whitespace-only mode, but you can explicitly request the “es6_runtime” library be injected, which should take care of your case.
To clarify, in the past we rewrote calls to
new Mapasnew $jscomp.Map- we don’t do that anymore. Now all thatRewritePolyfillspass does is inject a runtime library to ensure that the globalMapsymbol is defined and correct.+1 on getting a new command line option for
--noinject_librarywhile still remapping the calls to polyfillable features.@jdb8 There’s a flag
--noinject_libraryto prevent the injection from happening, and a compiler optionforceLibraryInjectionto force the injection. Unfortunately that option is not available via the command line (yet).@shicks @MatrixFrog Should we just remove
&& !options.skipNonTranspilationPassesfrom https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/DefaultPassConfig.java#L314? I suspect it requires some internal cleanup but that should be the way to go? An alternative would be exposing theforceLibraryInjectionto the command line, which I guess is done internally already?I’ve run into the same problem with library polyfills, and I think we should consider these two cases together, as the es6_runtime is essentially a library polyfilling some language features.
Ideally, I think the output of a transpilation should include some sort of indication (possibly among its goog.requires) that it needs the runtime or certain polyfills to be injected. Ideally this would be handled correctly both by re-compilation as well as by uncompiled/debug loading.
On Tue, Sep 15, 2015 at 9:10 AM Dominator008 notifications@github.com wrote: