Skip to content

Commit

Permalink
Add a new flag to the debug loader to help avoid double server/client…
Browse files Browse the repository at this point in the history
… side transpilation. Right now our test server will transpile server side, but we still require transpiling client side as well for ES6 modules only to preserve the loading logic, not the transpilation itself.

This new flag tells the debug loader that ES6 modules have been pre-transformed to jscomp modules, and thus transpilation should be skipped but the loading logic of transpiled modules preserved.

RELNOTES: none

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=228200959
  • Loading branch information
johnplaisted authored and nreid260 committed Jan 9, 2019
1 parent 490c981 commit 7e246e8
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions closure/goog/base.js
Expand Up @@ -1037,6 +1037,15 @@ goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER;
// would leave ES3 and ES5 files alone.
goog.define('goog.TRANSPILE', 'detect');

/**
* @define {boolean} If true assume that ES modules have already been
* transpiled by the jscompiler (in the same way that transpile.js would
* transpile them - to jscomp modules). Useful only for servers that wish to use
* the debug loader and transpile server side. Thus this is only respected if
* goog.TRANSPILE is "never".
*/
goog.define('goog.ASSUME_ES_MODULES_TRANSPILED', false);


/**
* @define {string} If a file needs to be transpiled what the output language
Expand Down Expand Up @@ -3812,6 +3821,36 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
};


/**
* An ES6 module dependency that was transpiled to a jscomp module outside
* of the debug loader, e.g. server side.
*
* @param {string} path Absolute path of this script.
* @param {string} relativePath Path of this script relative to goog.basePath.
* @param {!Array<string>} provides goog.provided or goog.module symbols
* in this file.
* @param {!Array<string>} requires goog symbols or relative paths to Closure
* this depends on.
* @param {!Object<string, string>} loadFlags
* @struct @constructor
* @extends {goog.TransformedDependency}
*/
goog.PreTranspiledEs6ModuleDependency = function(
path, relativePath, provides, requires, loadFlags) {
goog.PreTranspiledEs6ModuleDependency.base(
this, 'constructor', path, relativePath, provides, requires, loadFlags);
};
goog.inherits(
goog.PreTranspiledEs6ModuleDependency, goog.TransformedDependency);


/** @override */
goog.PreTranspiledEs6ModuleDependency.prototype.transform = function(
contents) {
return contents;
};


/**
* A goog.module, transpiled or not. Will always perform some minimal
* transformation even when not transpiled to wrap in a goog.loadModule
Expand Down Expand Up @@ -3940,8 +3979,13 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
path, relativePath, provides, requires, loadFlags, this.transpiler);
} else {
if (loadFlags['module'] == goog.ModuleType.ES6) {
return new goog.Es6ModuleDependency(
path, relativePath, provides, requires, loadFlags);
if (goog.TRANSPILE == 'never' && goog.ASSUME_ES_MODULES_TRANSPILED) {
return new goog.PreTranspiledEs6ModuleDependency(
path, relativePath, provides, requires, loadFlags);
} else {
return new goog.Es6ModuleDependency(
path, relativePath, provides, requires, loadFlags);
}
} else {
return new goog.Dependency(
path, relativePath, provides, requires, loadFlags);
Expand Down

0 comments on commit 7e246e8

Please sign in to comment.