Merge branch 'master' of github.com:bestiejs/lodash

Former-commit-id: a4de2b320b871d2bfd689890fc526605215091bf
This commit is contained in:
John-David Dalton
2012-06-29 03:58:54 -04:00
2 changed files with 12 additions and 27 deletions

View File

@@ -14,7 +14,6 @@
'className', 'className',
'collection', 'collection',
'ctor', 'ctor',
'false',
'funcClass', 'funcClass',
'hasOwnProperty', 'hasOwnProperty',
'identity', 'identity',
@@ -36,8 +35,6 @@
'target', 'target',
'thisArg', 'thisArg',
'toString', 'toString',
'true',
'undefined',
'value' 'value'
]; ];
@@ -270,16 +267,10 @@
isIteratorTemplate = /var iteratorTemplate\b/.test(snippet), isIteratorTemplate = /var iteratorTemplate\b/.test(snippet),
result = snippet; result = snippet;
// add brackets to whitelisted properties so Closure Compiler won't mung them // add brackets to whitelisted properties so Closure Compiler won't mung them
result = result.replace(RegExp('\\.(' + iteratorOptions.join('|') + ')\\b', 'g'), "['$1']"); result = result.replace(RegExp('\\.(' + iteratorOptions.join('|') + ')\\b', 'g'), "['$1']");
if (isCreateIterator) { if (isCreateIterator) {
// add `true` and `false` arguments to be minified
result = result
.replace(/(Function\(\s*'[\s\S]+?)undefined/, '$1true,false,undefined')
.replace(/factory\([^)]+/, '$&,true,false');
// replace with modified snippet early and clip snippet so other arguments // replace with modified snippet early and clip snippet so other arguments
// aren't minified // aren't minified
source = source.replace(snippet, result); source = source.replace(snippet, result);
@@ -295,12 +286,6 @@
if (variable == 'object') { if (variable == 'object') {
result = result.replace(RegExp("(typeof [^']+')" + minNames[index] + "'", 'g'), "$1object'"); result = result.replace(RegExp("(typeof [^']+')" + minNames[index] + "'", 'g'), "$1object'");
} }
// correct external boolean literals
else if (variable == 'true' || variable == 'false') {
result = result
.replace(RegExp(': *' + minNames[index] + '([,\\n])', 'g'), ':' + variable + '$1')
.replace(RegExp('\\b' + minNames[index] + ';', 'g'), variable + ';');
}
}); });
// minify `createIterator` option property names // minify `createIterator` option property names

View File

@@ -451,7 +451,7 @@
// create the function factory // create the function factory
var factory = Function( var factory = Function(
'arrayClass, funcClass, hasOwnProperty, identity, iteratorBind, objectTypes, ' + 'arrayClass, funcClass, hasOwnProperty, identity, iteratorBind, objectTypes, ' +
'slice, stringClass, toString, undefined', 'slice, stringClass, toString',
'"use strict"; return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}' '"use strict"; return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
); );
// return the compiled function // return the compiled function
@@ -1163,7 +1163,7 @@
*/ */
function first(array, n, guard) { function first(array, n, guard) {
if (array) { if (array) {
return (n == undefined || guard) ? array[0] : slice.call(array, 0, n); return (n == null || guard) ? array[0] : slice.call(array, 0, n);
} }
} }
@@ -1273,7 +1273,7 @@
if (!array) { if (!array) {
return []; return [];
} }
return slice.call(array, 0, -((n == undefined || guard) ? 1 : n)); return slice.call(array, 0, -((n == null || guard) ? 1 : n));
} }
/** /**
@@ -1331,7 +1331,7 @@
function last(array, n, guard) { function last(array, n, guard) {
if (array) { if (array) {
var length = array.length; var length = array.length;
return (n == undefined || guard) ? array[length - 1] : slice.call(array, -n || length); return (n == null || guard) ? array[length - 1] : slice.call(array, -n || length);
} }
} }
@@ -1514,7 +1514,7 @@
// use `Array(length)` so V8 will avoid the slower "dictionary" mode // use `Array(length)` so V8 will avoid the slower "dictionary" mode
// http://www.youtube.com/watch?v=XAqIpGU8ZZk#t=16m27s // http://www.youtube.com/watch?v=XAqIpGU8ZZk#t=16m27s
var index = -1, var index = -1,
length = Math.max(Math.ceil((end - start) / step), 0), length = Math.max(0, Math.ceil((end - start) / step)),
result = Array(length); result = Array(length);
while (++index < length) { while (++index < length) {
@@ -1546,7 +1546,7 @@
if (!array) { if (!array) {
return []; return [];
} }
return slice.call(array, (n == undefined || guard) ? 1 : n); return slice.call(array, (n == null || guard) ? 1 : n);
} }
/** /**
@@ -2012,7 +2012,7 @@
timeoutId; timeoutId;
function delayed() { function delayed() {
timeoutId = undefined; timeoutId = null;
if (!immediate) { if (!immediate) {
func.apply(thisArg, args); func.apply(thisArg, args);
} }
@@ -2197,7 +2197,7 @@
function trailingCall() { function trailingCall() {
lastCalled = new Date; lastCalled = new Date;
timeoutId = undefined; timeoutId = null;
func.apply(thisArg, args); func.apply(thisArg, args);
} }
@@ -2290,7 +2290,7 @@
* // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } * // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' }
*/ */
var defaults = createIterator(extendIteratorOptions, { var defaults = createIterator(extendIteratorOptions, {
'inLoop': 'if (object[index] == undefined)' + extendIteratorOptions.inLoop 'inLoop': 'if (object[index] == null)' + extendIteratorOptions.inLoop
}); });
/** /**
@@ -2560,8 +2560,8 @@
// treat `+0` vs. `-0` as not equal // treat `+0` vs. `-0` as not equal
return a !== 0 || (1 / a == 1 / b); return a !== 0 || (1 / a == 1 / b);
} }
// a strict comparison is necessary because `null == undefined` // a strict comparison is necessary because `undefined == null`
if (a == undefined || b == undefined) { if (a == null || b == null) {
return a === b; return a === b;
} }
// unwrap any wrapped objects // unwrap any wrapped objects