Cleanup iteratorTemplate and remove more code from the "underscore" build.

Former-commit-id: 3f4c283f0aa205dbcce1940f7222b594284263c4
This commit is contained in:
John-David Dalton
2012-08-28 00:30:52 -07:00
parent b63f25a1ae
commit cf462542e9
2 changed files with 24 additions and 24 deletions

View File

@@ -23,8 +23,11 @@
/** Flag used to specify a legacy build */
var isLegacy = process.argv.indexOf('legacy') > -1;
/** Flag used to specify an Underscore build */
var isUnderscore = process.argv.indexOf('underscore') > -1;
/** Flag used to specify a mobile build */
var isMobile = !isLegacy && (isCSP || process.argv.indexOf('mobile') > -1);
var isMobile = !isLegacy && (isCSP || isUnderscore || process.argv.indexOf('mobile') > -1);
/**
* Flag used to specify `_.bindAll`, `_.extend`, and `_.defaults` are
@@ -32,9 +35,6 @@
*/
var isStrict = process.argv.indexOf('strict') > -1;
/** Flag used to specify an Underscore build */
var isUnderscore = process.argv.indexOf('underscore') > -1;
/** Flag used to specify if the build should include the "use strict" directive */
var useStrict = isStrict || !(isLegacy || isMobile);
@@ -56,14 +56,19 @@
source = setUseStrictOption(source, false);
}
}
if (isLegacy) {
source = replaceVar(source, 'noArgsClass', 'true');
['isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) {
source = replaceVar(source, varName, 'false');
});
}
else if (isMobile) {
else if (isUnderscore) {
// remove `prototype` [[Enumerable]] fix from `iteratorTemplate`
source = source
.replace(/(?: *\/\/.*\n)*\s*' *(?:<% *)?if *\(!hasDontEnumBug *(?:&&|\))[\s\S]+?<% *} *(?:%>|').+/g, '')
.replace(/!hasDontEnumBug *\|\|/g, '');
}
if (isMobile) {
source = replaceVar(source, 'isKeysFast', 'false');
}
vm.runInNewContext(source, sandbox);

View File

@@ -162,7 +162,6 @@
function ctor() { this.x = 1; }
ctor.prototype = { 'valueOf': 1, 'y': 1 };
for (var prop in new ctor) { props.push(prop); }
for (prop in arguments) { noArgsEnum = !prop; }
@@ -417,6 +416,12 @@
' } else {' +
' <% } %>' +
// Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
// (if the prototype or a property on the prototype has been set)
// incorrectly sets a function's `prototype` property [[Enumerable]]
// value to `true`. Because of this Lo-Dash standardizes on skipping
// the the `prototype` property of functions regardless of its
// [[Enumerable]] value.
' <% if (!hasDontEnumBug) { %>\n' +
' var skipProto = typeof iteratee == \'function\' && \n' +
' propertyIsEnumerable.call(iteratee, \'prototype\');\n' +
@@ -440,25 +445,15 @@
' <% } else { %>\n' +
' <%= objectBranch.beforeLoop %>;\n' +
' for (index in iteratee) {' +
' <% if (hasDontEnumBug) { %>\n' +
' <% if (useHas) { %>if (hasOwnProperty.call(iteratee, index)) {\n <% } %>' +
' <% if (!hasDontEnumBug || useHas) { %>\n if (<%' +
' if (!hasDontEnumBug) { %>!(skipProto && index == \'prototype\')<% }' +
' if (!hasDontEnumBug && useHas) { %> && <% }' +
' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' +
' %>) {' +
' <% } %>\n' +
' value = iteratee[index];\n' +
' <%= objectBranch.inLoop %>;\n' +
' <% if (useHas) { %>}<% } %>' +
// Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
// (if the prototype or a property on the prototype has been set)
// incorrectly sets a function's `prototype` property [[Enumerable]]
// value to `true`. Because of this Lo-Dash standardizes on skipping
// the the `prototype` property of functions regardless of its
// [[Enumerable]] value.
' <% } else { %>\n' +
' if (!(skipProto && index == \'prototype\')<% if (useHas) { %> &&\n' +
' hasOwnProperty.call(iteratee, index)<% } %>) {\n' +
' value = iteratee[index];\n' +
' <%= objectBranch.inLoop %>\n' +
' }' +
' <% } %>\n' +
' <% if (!hasDontEnumBug || useHas) { %>}\n<% } %>' +
' }' +
' <% } %>' +