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)

Most upvoted comments

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 Map as new $jscomp.Map - we don’t do that anymore. Now all that RewritePolyfills pass does is inject a runtime library to ensure that the global Map symbol is defined and correct.

+1 on getting a new command line option for --noinject_library while still remapping the calls to polyfillable features.

@jdb8 There’s a flag --noinject_library to prevent the injection from happening, and a compiler option forceLibraryInjection to force the injection. Unfortunately that option is not available via the command line (yet).

@shicks @MatrixFrog Should we just remove && !options.skipNonTranspilationPasses from 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 the forceLibraryInjection to 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:

Maybe perFileTranspilation should be a separate option so that people can explicitly not inject the runtime library when doing so?

I do think it’s broken that a WHITESPACE_ONLY whole-program compilation on ES6 code definitely won’t work because the runtime library won’t be injected.

— Reply to this email directly or view it on GitHub https://github.com/google/closure-compiler/issues/1138#issuecomment-140446508 .