Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 468188f

Browse files
shickscopybara-github
authored andcommitted
Turn off all transpilation in the debug loader.
Note that the `goog.define`s and transpile.js still remain, but are always ignored. They will be cleaned up shortly afterwards. RELNOTES[INC]: The debug loader no longer downlevels sources in the browser. The alternative recommendation is to use a downleveling development server instead. PiperOrigin-RevId: 463109586 Change-Id: I1e657c18bca85a93b74d3205b7410447c2e20459
1 parent 5edb65b commit 468188f

2 files changed

Lines changed: 14 additions & 328 deletions

File tree

closure/goog/base.js

Lines changed: 8 additions & 296 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,67 +1201,6 @@ goog.loadFileSync_ = function(src) {
12011201
}
12021202
};
12031203

1204-
1205-
/**
1206-
* Lazily retrieves the transpiler and applies it to the source.
1207-
* @param {string} code JS code.
1208-
* @param {string} path Path to the code.
1209-
* @param {string} target Language level output.
1210-
* @return {string} The transpiled code.
1211-
* @private
1212-
*/
1213-
goog.transpile_ = function(code, path, target) {
1214-
var jscomp = goog.global['$jscomp'];
1215-
if (!jscomp) {
1216-
goog.global['$jscomp'] = jscomp = {};
1217-
}
1218-
var transpile = jscomp.transpile;
1219-
if (!transpile) {
1220-
var transpilerPath = goog.basePath + goog.TRANSPILER;
1221-
var transpilerCode = goog.loadFileSync_(transpilerPath);
1222-
if (transpilerCode) {
1223-
// This must be executed synchronously, since by the time we know we
1224-
// need it, we're about to load and write the ES6 code synchronously,
1225-
// so a normal script-tag load will be too slow. Wrapped in a function
1226-
// so that code is eval'd in the global scope.
1227-
(function() {
1228-
(0, eval)(transpilerCode + '\n//# sourceURL=' + transpilerPath);
1229-
}).call(goog.global);
1230-
// Even though the transpiler is optional, if $gwtExport is found, it's
1231-
// a sign the transpiler was loaded and the $jscomp.transpile *should*
1232-
// be there.
1233-
if (goog.global['$gwtExport'] && goog.global['$gwtExport']['$jscomp'] &&
1234-
!goog.global['$gwtExport']['$jscomp']['transpile']) {
1235-
throw new Error(
1236-
'The transpiler did not properly export the "transpile" ' +
1237-
'method. $gwtExport: ' + JSON.stringify(goog.global['$gwtExport']));
1238-
}
1239-
// transpile.js only exports a single $jscomp function, transpile. We
1240-
// grab just that and add it to the existing definition of $jscomp which
1241-
// contains the polyfills.
1242-
goog.global['$jscomp'].transpile =
1243-
goog.global['$gwtExport']['$jscomp']['transpile'];
1244-
jscomp = goog.global['$jscomp'];
1245-
transpile = jscomp.transpile;
1246-
}
1247-
}
1248-
if (!transpile) {
1249-
// The transpiler is an optional component. If it's not available then
1250-
// replace it with a pass-through function that simply logs.
1251-
var suffix = ' requires transpilation but no transpiler was found.';
1252-
transpile = jscomp.transpile = function(code, path) {
1253-
// TODO(sdh): figure out some way to get this error to show up
1254-
// in test results, noting that the failure may occur in many
1255-
// different ways, including in loadModule() before the test
1256-
// runner even comes up.
1257-
goog.logToConsole_(path + suffix);
1258-
return code;
1259-
};
1260-
}
1261-
// Note: any transpilation errors/warnings will be logged to the console.
1262-
return transpile(code, path, target);
1263-
};
1264-
12651204
//==============================================================================
12661205
// Language Enhancements
12671206
//==============================================================================
@@ -2296,173 +2235,6 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
22962235

22972236
goog.findBasePath_();
22982237

2299-
/** @struct @constructor @final */
2300-
goog.Transpiler = function() {
2301-
/** @private {?Object<string, boolean>} */
2302-
this.requiresTranspilation_ = null;
2303-
/** @private {string} */
2304-
this.transpilationTarget_ = goog.TRANSPILE_TO_LANGUAGE;
2305-
};
2306-
/**
2307-
* Returns a newly created map from language mode string to a boolean
2308-
* indicating whether transpilation should be done for that mode as well as
2309-
* the highest level language that this environment supports.
2310-
*
2311-
* Guaranteed invariant:
2312-
* For any two modes, l1 and l2 where l2 is a newer mode than l1,
2313-
* `map[l1] == true` implies that `map[l2] == true`.
2314-
*
2315-
* Note this method is extracted and used elsewhere, so it cannot rely on
2316-
* anything external (it should easily be able to be transformed into a
2317-
* standalone, top level function).
2318-
*
2319-
* @private
2320-
* @return {{
2321-
* target: string,
2322-
* map: !Object<string, boolean>
2323-
* }}
2324-
*/
2325-
goog.Transpiler.prototype.createRequiresTranspilation_ = function() {
2326-
var transpilationTarget = 'es3';
2327-
var /** !Object<string, boolean> */ requiresTranspilation = {'es3': false};
2328-
var transpilationRequiredForAllLaterModes = false;
2329-
2330-
/**
2331-
* Adds an entry to requiresTranspliation for the given language mode.
2332-
*
2333-
* IMPORTANT: Calls must be made in order from oldest to newest language
2334-
* mode.
2335-
* @param {string} modeName
2336-
* @param {function(): boolean} isSupported Returns true if the JS engine
2337-
* supports the given mode.
2338-
*/
2339-
function addNewerLanguageTranspilationCheck(modeName, isSupported) {
2340-
if (transpilationRequiredForAllLaterModes) {
2341-
requiresTranspilation[modeName] = true;
2342-
} else if (isSupported()) {
2343-
transpilationTarget = modeName;
2344-
requiresTranspilation[modeName] = false;
2345-
} else {
2346-
requiresTranspilation[modeName] = true;
2347-
transpilationRequiredForAllLaterModes = true;
2348-
}
2349-
}
2350-
2351-
/**
2352-
* Does the given code evaluate without syntax errors and return a truthy
2353-
* result?
2354-
*/
2355-
function /** boolean */ evalCheck(/** string */ code) {
2356-
try {
2357-
return !!eval(goog.CLOSURE_EVAL_PREFILTER_.createScript(code));
2358-
} catch (ignored) {
2359-
return false;
2360-
}
2361-
}
2362-
2363-
// Identify ES3-only browsers by their incorrect treatment of commas.
2364-
addNewerLanguageTranspilationCheck('es5', function() {
2365-
return evalCheck('[1,].length==1');
2366-
});
2367-
addNewerLanguageTranspilationCheck('es6', function() {
2368-
// Edge has a non-deterministic (i.e., not reproducible) bug with ES6:
2369-
// https://github.com/Microsoft/ChakraCore/issues/1496.
2370-
if (goog.isEdge_()) {
2371-
// The Reflect.construct test below is flaky on Edge. It can sometimes
2372-
// pass or fail on 40 15.15063, so just exit early for Edge and treat
2373-
// it as ES5. Until we're on a more up to date version just always use
2374-
// ES5. See https://github.com/Microsoft/ChakraCore/issues/3217.
2375-
return false;
2376-
}
2377-
// Test es6: [FF50 (?), Edge 14 (?), Chrome 50]
2378-
// (a) default params (specifically shadowing locals),
2379-
// (b) destructuring, (c) block-scoped functions,
2380-
// (d) for-of (const), (e) new.target/Reflect.construct
2381-
var es6fullTest =
2382-
'class X{constructor(){if(new.target!=String)throw 1;this.x=42}}' +
2383-
'let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof ' +
2384-
'String))throw 1;for(const a of[2,3]){if(a==2)continue;function ' +
2385-
'f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()' +
2386-
'==3}';
2387-
2388-
return evalCheck('(()=>{"use strict";' + es6fullTest + '})()');
2389-
});
2390-
// ** and **= are the only new features in 'es7'
2391-
addNewerLanguageTranspilationCheck('es7', function() {
2392-
return evalCheck('2**3==8');
2393-
});
2394-
// async functions are the only new features in 'es8'
2395-
addNewerLanguageTranspilationCheck('es8', function() {
2396-
return evalCheck('async()=>1,1');
2397-
});
2398-
addNewerLanguageTranspilationCheck('es9', function() {
2399-
return evalCheck('({...rest}={}),1');
2400-
});
2401-
// optional catch binding, unescaped unicode paragraph separator in strings
2402-
addNewerLanguageTranspilationCheck('es_2019', function() {
2403-
return evalCheck('let r;try{r="\u2029"}catch{};r');
2404-
});
2405-
// optional chaining, nullish coalescing
2406-
// untested/unsupported: bigint, import meta
2407-
addNewerLanguageTranspilationCheck('es_2020', function() {
2408-
return evalCheck('null?.x??1');
2409-
});
2410-
addNewerLanguageTranspilationCheck('es_next', function() {
2411-
return false; // assume it always need to transpile
2412-
});
2413-
return {target: transpilationTarget, map: requiresTranspilation};
2414-
};
2415-
2416-
2417-
/**
2418-
* Determines whether the given language needs to be transpiled.
2419-
* @param {string} lang
2420-
* @param {string|undefined} module
2421-
* @return {boolean}
2422-
*/
2423-
goog.Transpiler.prototype.needsTranspile = function(lang, module) {
2424-
if (goog.TRANSPILE == 'always') {
2425-
return true;
2426-
} else if (goog.TRANSPILE == 'never') {
2427-
return false;
2428-
} else if (!this.requiresTranspilation_) {
2429-
var obj = this.createRequiresTranspilation_();
2430-
this.requiresTranspilation_ = obj.map;
2431-
this.transpilationTarget_ = this.transpilationTarget_ || obj.target;
2432-
}
2433-
if (lang in this.requiresTranspilation_) {
2434-
if (this.requiresTranspilation_[lang]) {
2435-
return true;
2436-
} else if (
2437-
goog.inHtmlDocument_() && module == 'es6' &&
2438-
!('noModule' in goog.global.document.createElement('script'))) {
2439-
return true;
2440-
} else {
2441-
return false;
2442-
}
2443-
} else {
2444-
throw new Error('Unknown language mode: ' + lang);
2445-
}
2446-
};
2447-
2448-
2449-
/**
2450-
* Lazily retrieves the transpiler and applies it to the source.
2451-
* @param {string} code JS code.
2452-
* @param {string} path Path to the code.
2453-
* @return {string} The transpiled code.
2454-
*/
2455-
goog.Transpiler.prototype.transpile = function(code, path) {
2456-
// TODO(johnplaisted): We should delete goog.transpile_ and just have this
2457-
// function. But there's some compile error atm where goog.global is being
2458-
// stripped incorrectly without this.
2459-
return goog.transpile_(code, path, this.transpilationTarget_);
2460-
};
2461-
2462-
2463-
/** @private @final {!goog.Transpiler} */
2464-
goog.transpiler_ = new goog.Transpiler();
2465-
24662238
/**
24672239
* Rewrites closing script tags in input to avoid ending an enclosing script
24682240
* tag.
@@ -2499,7 +2271,7 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
24992271
/** @private {boolean} */
25002272
this.paused_ = false;
25012273
/** @private {!goog.DependencyFactory} */
2502-
this.factory_ = new goog.DependencyFactory(goog.transpiler_);
2274+
this.factory_ = new goog.DependencyFactory();
25032275
/** @private @const {!Object<string, !Function>} */
25042276
this.deferredCallbacks_ = {};
25052277
/** @private @const {!Array<string>} */
@@ -2559,8 +2331,7 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
25592331
// transpile is set to always.
25602332
var relPath = 'deps.js';
25612333
this.depsToLoad_.push(this.factory_.createDependency(
2562-
goog.normalizePath_(goog.basePath + relPath), relPath, [], [], {},
2563-
false));
2334+
goog.normalizePath_(goog.basePath + relPath), relPath, [], [], {}));
25642335
this.loadDeps_();
25652336
};
25662337

@@ -2956,7 +2727,6 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
29562727
* This default implementation is designed to load untranspiled, non-module
29572728
* scripts in a web broswer.
29582729
*
2959-
* For transpiled non-goog.module files {@see goog.TranspiledDependency}.
29602730
* For goog.modules see {@see goog.GoogModuleDependency}.
29612731
* For untranspiled ES6 modules {@see goog.Es6ModuleDependency}.
29622732
*
@@ -3586,41 +3356,6 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
35863356
goog.TransformedDependency.prototype.transform = function(contents) {};
35873357

35883358

3589-
/**
3590-
* Any non-goog.module dependency which needs to be transpiled before eval.
3591-
*
3592-
* @param {string} path Absolute path of this script.
3593-
* @param {string} relativePath Path of this script relative to goog.basePath.
3594-
* @param {!Array<string>} provides goog.provided or goog.module symbols
3595-
* in this file.
3596-
* @param {!Array<string>} requires goog symbols or relative paths to Closure
3597-
* this depends on.
3598-
* @param {!Object<string, string>} loadFlags
3599-
* @param {!goog.Transpiler} transpiler
3600-
* @struct @constructor
3601-
* @extends {goog.TransformedDependency}
3602-
*/
3603-
goog.TranspiledDependency = function(
3604-
path, relativePath, provides, requires, loadFlags, transpiler) {
3605-
goog.TranspiledDependency.base(
3606-
this, 'constructor', path, relativePath, provides, requires, loadFlags);
3607-
/** @protected @const*/
3608-
this.transpiler = transpiler;
3609-
};
3610-
goog.inherits(goog.TranspiledDependency, goog.TransformedDependency);
3611-
3612-
3613-
/**
3614-
* @override
3615-
* @param {string} contents
3616-
* @return {string}
3617-
*/
3618-
goog.TranspiledDependency.prototype.transform = function(contents) {
3619-
// Transpile with the pathname so that ES6 modules are domain agnostic.
3620-
return this.transpiler.transpile(contents, this.getPathName());
3621-
};
3622-
3623-
36243359
/**
36253360
* An ES6 module dependency that was transpiled to a jscomp module outside
36263361
* of the debug loader, e.g. server side.
@@ -3667,20 +3402,13 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
36673402
* @param {!Array<string>} requires goog symbols or relative paths to Closure
36683403
* this depends on.
36693404
* @param {!Object<string, string>} loadFlags
3670-
* @param {boolean} needsTranspile
3671-
* @param {!goog.Transpiler} transpiler
36723405
* @struct @constructor
36733406
* @extends {goog.TransformedDependency}
36743407
*/
36753408
goog.GoogModuleDependency = function(
3676-
path, relativePath, provides, requires, loadFlags, needsTranspile,
3677-
transpiler) {
3409+
path, relativePath, provides, requires, loadFlags) {
36783410
goog.GoogModuleDependency.base(
36793411
this, 'constructor', path, relativePath, provides, requires, loadFlags);
3680-
/** @private @const */
3681-
this.needsTranspile_ = needsTranspile;
3682-
/** @private @const */
3683-
this.transpiler_ = transpiler;
36843412
};
36853413
goog.inherits(goog.GoogModuleDependency, goog.TransformedDependency);
36863414

@@ -3691,10 +3419,6 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
36913419
* @return {string}
36923420
*/
36933421
goog.GoogModuleDependency.prototype.transform = function(contents) {
3694-
if (this.needsTranspile_) {
3695-
contents = this.transpiler_.transpile(contents, this.getPathName());
3696-
}
3697-
36983422
if (!goog.LOAD_MODULE_USING_EVAL || goog.global.JSON === undefined) {
36993423
return '' +
37003424
'goog.loadModule(function(exports) {' +
@@ -3729,9 +3453,7 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
37293453
opt_loadFlags = opt_loadFlags ? {'module': goog.ModuleType.GOOG} : {};
37303454
}
37313455
var dep = this.factory_.createDependency(
3732-
path, relPath, provides, requires, opt_loadFlags,
3733-
goog.transpiler_.needsTranspile(
3734-
opt_loadFlags['lang'] || 'es3', opt_loadFlags['module']));
3456+
path, relPath, provides, requires, opt_loadFlags);
37353457
this.dependencies_[path] = dep;
37363458
for (var i = 0; i < provides.length; i++) {
37373459
this.idToPath_[provides[i]] = path;
@@ -3746,13 +3468,9 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
37463468
* Should be overridden to have the debug loader use custom subclasses of
37473469
* goog.Dependency.
37483470
*
3749-
* @param {!goog.Transpiler} transpiler
37503471
* @struct @constructor
37513472
*/
3752-
goog.DependencyFactory = function(transpiler) {
3753-
/** @protected @const */
3754-
this.transpiler = transpiler;
3755-
};
3473+
goog.DependencyFactory = function() {};
37563474

37573475

37583476
/**
@@ -3762,23 +3480,17 @@ if (!COMPILED && goog.DEPENDENCIES_ENABLED) {
37623480
* @param {!Array<string>} requires Array of required goog.provide/module /
37633481
* relative ES6 module paths.
37643482
* @param {!Object<string, string>} loadFlags
3765-
* @param {boolean} needsTranspile True if the file needs to be transpiled
3766-
* per the goog.Transpiler.
37673483
* @return {!goog.Dependency}
37683484
*/
37693485
goog.DependencyFactory.prototype.createDependency = function(
3770-
path, relativePath, provides, requires, loadFlags, needsTranspile) {
3486+
path, relativePath, provides, requires, loadFlags) {
37713487

37723488
if (loadFlags['module'] == goog.ModuleType.GOOG) {
37733489
return new goog.GoogModuleDependency(
3774-
path, relativePath, provides, requires, loadFlags, needsTranspile,
3775-
this.transpiler);
3776-
} else if (needsTranspile) {
3777-
return new goog.TranspiledDependency(
3778-
path, relativePath, provides, requires, loadFlags, this.transpiler);
3490+
path, relativePath, provides, requires, loadFlags);
37793491
} else {
37803492
if (loadFlags['module'] == goog.ModuleType.ES6) {
3781-
if (goog.TRANSPILE == 'never' && goog.ASSUME_ES_MODULES_TRANSPILED) {
3493+
if (goog.ASSUME_ES_MODULES_TRANSPILED) {
37823494
return new goog.PreTranspiledEs6ModuleDependency(
37833495
path, relativePath, provides, requires, loadFlags);
37843496
} else {

0 commit comments

Comments
 (0)