|
472 | 472 |
|
473 | 473 | var source = [
|
474 | 474 | ';(function(window) {',
|
475 |
| - " var freeExports = typeof exports == 'object' && exports &&", |
476 |
| - " (typeof global == 'object' && global && global == global.global && (window = global), exports);", |
| 475 | + " var freeExports = typeof exports == 'object' && exports;", |
| 476 | + '', |
| 477 | + " var freeModule = typeof module == 'object' && module && module.exports == freeExports && module;", |
| 478 | + '', |
| 479 | + " var freeGlobal = typeof global ==
8000
'object' && global;", |
| 480 | + ' if (freeGlobal.global === freeGlobal) {', |
| 481 | + ' window = freeGlobal;', |
| 482 | + ' }', |
477 | 483 | '',
|
478 | 484 | ' var templates = {},',
|
479 | 485 | ' _ = window._;',
|
|
505 | 511 | ' lodash.templates = lodash.extend(lodash.templates || {}, templates);',
|
506 | 512 | ' });',
|
507 | 513 | " } else if (freeExports) {",
|
508 |
| - " if (typeof module == 'object' && module && module.exports == freeExports) {", |
509 |
| - ' (module.exports = templates).templates = templates;', |
| 514 | + " if (freeModule) {", |
| 515 | + ' (freeModule.exports = templates).templates = templates;', |
510 | 516 | ' } else {',
|
511 | 517 | ' freeExports.templates = templates;',
|
512 | 518 | ' }',
|
|
1184 | 1190 | .replace(/(?:\s*\/\/.*)*\n( *)if *\(hasObjectSpliceBug[\s\S]+?(?:{\s*}|\n\1})/, '');
|
1185 | 1191 | }
|
1186 | 1192 |
|
| 1193 | + /** |
| 1194 | + * Removes the `setImmediate` fork of `_.defer`. |
| 1195 | + * |
| 1196 | + * @private |
| 1197 | + * @param {String} source The source to process. |
| 1198 | + * @returns {String} Returns the modified source. |
| 1199 | + */ |
| 1200 | + function removeSetImmediate(source) { |
| 1201 | + return source.replace(/(?:\s*\/\/.*)*\n( *)if *\(isV8 *&& *freeModule[\s\S]+?\n\1}/, ''); |
| 1202 | + } |
| 1203 | + |
1187 | 1204 | /**
|
1188 | 1205 | * Removes a given variable from `source`.
|
1189 | 1206 | *
|
|
2110 | 2127 | /*----------------------------------------------------------------------*/
|
2111 | 2128 |
|
2112 | 2129 | if (isLegacy) {
|
| 2130 | + source = removeSetImmediate(source); |
| 2131 | + |
2113 | 2132 | _.each(['isBindFast', 'isV8', 'nativeBind', 'nativeIsArray', 'nativeKeys', 'reNative'], function(varName) {
|
2114 | 2133 | source = removeVar(source, varName);
|
2115 | 2134 | });
|
|
2119 | 2138 | return match.replace(/(?:\s*\/\/.*)*\s*return isBindFast[^:]+:\s*/, 'return ');
|
2120 | 2139 | });
|
2121 | 2140 |
|
2122 |
| - // remove native `setImmediate` branch in `_.defer` |
2123 |
| - source = source.replace(matchFunction(source, 'defer'), function(match) { |
2124 |
| - return match.replace(/reNative.*?\|\|\s*/, ''); |
2125 |
| - }); |
2126 |
| - |
2127 | 2141 | // remove native `Array.isArray` branch in `_.isArray`
|
2128 | 2142 | source = source.replace(matchFunction(source, 'isArray'), function(match) {
|
2129 | 2143 | return match.replace(/nativeIsArray * \|\|\s*/, '');
|
|
2296 | 2310 | source = source.replace(/(?: *\/\/.*\n)*( *)if *\(typeof +define[\s\S]+?else /, '$1');
|
2297 | 2311 | }
|
2298 | 2312 | if (!isNode) {
|
2299 |
| - source = source.replace(/(?: *\/\/.*\n)*( *)if *\(typeof +module[\s\S]+?else *{([\s\S]+?\n)\1}\n/, '$1$2'); |
| 2313 | + source = source.replace(/(?: *\/\/.*\n)*( *)if *\(freeModule[\s\S]+?else *{([\s\S]+?\n)\1}\n/, '$1$2'); |
2300 | 2314 | }
|
2301 | 2315 | if (!isCommonJS) {
|
2302 | 2316 | source = source.replace(/(?: *\/\/.*\n)*(?:( *)else *{)?\s*freeExports\.\w+ *=[\s\S]+?(?:\n\1})?\n/, '');
|
|
2380 | 2394 | source = removeHasEnumPrototype(source);
|
2381 | 2395 | }
|
2382 | 2396 | if (isRemoved(source, 'createIterator', 'bind', 'keys')) {
|
| 2397 | + source = removeSetImmediate(source); |
2383 | 2398 | source = removeVar(source, 'isBindFast');
|
2384 | 2399 | source = removeVar(source, 'isV8');
|
2385 | 2400 | source = removeVar(source, 'nativeBind');
|
|
0 commit comments