mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Remove undefined from the IIFE to allow easier customizations with the iife build option.
Former-commit-id: a496b1fba74fdab3b2819d27b769371f73364684
This commit is contained in:
20
build.js
20
build.js
@@ -588,7 +588,7 @@
|
|||||||
' lodash exports=... Comma separated names of ways to export the `lodash` function',
|
' lodash exports=... Comma separated names of ways to export the `lodash` function',
|
||||||
' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)',
|
' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)',
|
||||||
' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash',
|
' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash',
|
||||||
' (e.g. `lodash iife="!function(window,undefined){%output%}(this)"`)',
|
' (e.g. `lodash iife="!function(window){%output%}(this)"`)',
|
||||||
'',
|
'',
|
||||||
' lodash template=... File path pattern used to match template files to precompile',
|
' lodash template=... File path pattern used to match template files to precompile',
|
||||||
' (e.g. `lodash template=./*.jst`)',
|
' (e.g. `lodash template=./*.jst`)',
|
||||||
@@ -964,8 +964,8 @@
|
|||||||
|
|
||||||
source = source
|
source = source
|
||||||
.replace(/context/g, 'window')
|
.replace(/context/g, 'window')
|
||||||
.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var Array *=[\s\S]+?;\n/m, '')
|
.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var Array *=[\s\S]+?;\n/, '')
|
||||||
.replace(/(?: *\/\/.*\n)* *var lodash *= *runInContext.+\n/, '');
|
.replace(/^ *var lodash *= *runInContext.+\n+/m, '');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
source = source.replace(snippet, '');
|
source = source.replace(snippet, '');
|
||||||
@@ -1136,7 +1136,7 @@
|
|||||||
|
|
||||||
// remove `noCharByIndex` from `_.at`
|
// remove `noCharByIndex` from `_.at`
|
||||||
source = source.replace(matchFunction(source, 'at'), function(match) {
|
source = source.replace(matchFunction(source, 'at'), function(match) {
|
||||||
return match.replace(/^ *if *\(noCharByIndex[^}]+}\n/m, '');
|
return match.replace(/^ *if *\(noCharByIndex[^}]+}\n+/m, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove `noCharByIndex` from `_.reduceRight`
|
// remove `noCharByIndex` from `_.reduceRight`
|
||||||
@@ -2359,19 +2359,19 @@
|
|||||||
source = source.replace(/(?: *\/\/.*\n)*( *)if *\(typeof +define[\s\S]+?else /, '$1');
|
source = source.replace(/(?: *\/\/.*\n)*( *)if *\(typeof +define[\s\S]+?else /, '$1');
|
||||||
}
|
}
|
||||||
if (!isNode) {
|
if (!isNode) {
|
||||||
source = source.replace(/(?: *\/\/.*\n)*( *)if *\(freeModule[\s\S]+?else *{([\s\S]+?\n)\1}\n/, '$1$2');
|
source = source.replace(/(?: *\/\/.*\n)*( *)if *\(freeModule[\s\S]+?else *{([\s\S]+?\n)\1}\n+/, '$1$2');
|
||||||
}
|
}
|
||||||
if (!isCommonJS) {
|
if (!isCommonJS) {
|
||||||
source = source.replace(/(?: *\/\/.*\n)*(?:( *)else *{)?\s*freeExports\.\w+ *=[\s\S]+?(?:\n\1})?\n/, '');
|
source = source.replace(/(?: *\/\/.*\n)*(?:( *)else *{)?\s*freeExports\.\w+ *=[\s\S]+?(?:\n\1})?\n+/, '');
|
||||||
}
|
}
|
||||||
if (!isGlobal) {
|
if (!isGlobal) {
|
||||||
source = source.replace(/(?:( *)(})? *else(?: *if *\(_\))? *{)?(?:\s*\/\/.*)*\s*(?:window\._|_\.templates) *=[\s\S]+?(?:\n\1})?\n/g, '$1$2\n');
|
source = source.replace(/(?:( *)(})? *else(?: *if *\(_\))? *{)?(?:\s*\/\/.*)*\s*(?:window\._|_\.templates) *=[\s\S]+?(?:\n\1})?\n+/g, '$1$2\n');
|
||||||
}
|
}
|
||||||
// remove `if (freeExports) {...}` if it's empty
|
// remove `if (freeExports) {...}` if it's empty
|
||||||
if (isAMD && isGlobal) {
|
if (isAMD && isGlobal) {
|
||||||
source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}\n/, '');
|
source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}\n+/, '');
|
||||||
} else {
|
} else {
|
||||||
source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{([\s\S]+?) *})?\n/, '$1\n');
|
source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{([\s\S]+?) *})?\n+/, '$1\n');
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -2454,7 +2454,7 @@
|
|||||||
}
|
}
|
||||||
if (!source.match(/var (?:hasDontEnumBug|hasEnumPrototype|iteratesOwnLast|nonEnumArgs)\b/g)) {
|
if (!source.match(/var (?:hasDontEnumBug|hasEnumPrototype|iteratesOwnLast|nonEnumArgs)\b/g)) {
|
||||||
// remove IIFE used to assign `hasDontEnumBug`, `hasEnumPrototype`, `iteratesOwnLast`, and `nonEnumArgs`
|
// remove IIFE used to assign `hasDontEnumBug`, `hasEnumPrototype`, `iteratesOwnLast`, and `nonEnumArgs`
|
||||||
source = source.replace(/^ *\(function\(\) *{[\s\S]+?}\(1\)\);\n/m, '');
|
source = source.replace(/^ *\(function\(\) *{[\s\S]+?}\(1\)\);\n+/m, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((source.match(/\bfreeModule\b/g) || []).length < 2) {
|
if ((source.match(/\bfreeModule\b/g) || []).length < 2) {
|
||||||
|
|||||||
@@ -353,7 +353,7 @@
|
|||||||
source = source.replace(license, '');
|
source = source.replace(license, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasIIFE = /^;?\(function[^{]+{\s*/.test(source),
|
var hasIIFE = /^;?\(function[^{]+{/.test(source),
|
||||||
isStrict = hasIIFE && /^;?\(function[^{]+{\s*["']use strict["']/.test(source);
|
isStrict = hasIIFE && /^;?\(function[^{]+{\s*["']use strict["']/.test(source);
|
||||||
|
|
||||||
// to avoid stripping the IIFE, convert it to a function call
|
// to avoid stripping the IIFE, convert it to a function call
|
||||||
|
|||||||
@@ -6,7 +6,10 @@
|
|||||||
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
|
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
|
||||||
* Available under MIT license <http://lodash.com/license>
|
* Available under MIT license <http://lodash.com/license>
|
||||||
*/
|
*/
|
||||||
;(function(window, undefined) {
|
;(function(window) {
|
||||||
|
|
||||||
|
/** Used as a safe reference for `undefined` in pre ES5 environments */
|
||||||
|
var undefined;
|
||||||
|
|
||||||
/** Detect free variable `exports` */
|
/** Detect free variable `exports` */
|
||||||
var freeExports = typeof exports == 'object' && exports;
|
var freeExports = typeof exports == 'object' && exports;
|
||||||
@@ -115,7 +118,7 @@
|
|||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Utilities
|
* @category Utilities
|
||||||
* @param {Object} context The context object.
|
* @param {Object} [context=window] The context object.
|
||||||
* @returns {Function} Returns the `lodash` function.
|
* @returns {Function} Returns the `lodash` function.
|
||||||
*/
|
*/
|
||||||
function runInContext(context) {
|
function runInContext(context) {
|
||||||
@@ -5161,9 +5164,9 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// expose Lo-Dash
|
||||||
var lodash = runInContext();
|
var lodash = runInContext();
|
||||||
|
|
||||||
// expose Lo-Dash
|
|
||||||
// some AMD build optimizers, like r.js, check for specific condition patterns like the following:
|
// some AMD build optimizers, like r.js, check for specific condition patterns like the following:
|
||||||
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
||||||
// Expose Lo-Dash to the global object even when an AMD loader is present in
|
// Expose Lo-Dash to the global object even when an AMD loader is present in
|
||||||
|
|||||||
Reference in New Issue
Block a user