8000 Cleanup `iteratorTemplate` and remove more code from the "underscore"… · lodash/lodash@cf46254 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf46254

Browse files
committed
Cleanup iteratorTemplate and remove more code from the "underscore" build.
Former-commit-id: 3f4c283f0aa205dbcce1940f7222b594284263c4
1 parent b63f25a commit cf46254

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

build.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
/** Flag used to specify a legacy build */
2424
var isLegacy = process.argv.indexOf('legacy') > -1;
2525

26+
/** Flag used to specify an Underscore build */
27+
var isUnderscore = process.argv.indexOf('underscore') > -1;
28+
2629
/** Flag used to specify a mobile build */
27-
var isMobile = !isLegacy && (isCSP || process.argv.indexOf('mobile') > -1);
30+
var isMobile = !isLegacy && (isCSP || isUnderscore || process.argv.indexOf('mobile') > -1);
2831

2932
/**
3033
* Flag used to specify `_.bindAll`, `_.extend`, and `_.defaults` are
3134
* constructed using the "use strict" directive.
3235
*/
3336
var isStrict = process.argv.indexOf('strict') > -1;
3437

35-
/** Flag used to specify an Underscore build */
36-
var isUnderscore = process.argv.indexOf('underscore') > -1;
37-
3838
/** Flag used to specify if the build should include the "use strict" directive */
3939
var useStrict = isStrict || !(isLegacy || isMobile);
4040

@@ -56,14 +56,19 @@
5656
source = setUseStrictOption(source, false);
5757
}
5858
}
59-
6059
if (isLegacy) {
6160
source = replaceVar(source, 'noArgsClass', 'true');
6261
['isBindFast', 'isKeysFast', 'isStrictFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) {
6362
source = replaceVar(source, varName, 'false');
6463
});
6564
}
66-
else if (isMobile) {
65+
else if (isUnderscore) {
66+
// remove `prototype` [[Enumerable]] fix from `iteratorTemplate`
67+
source = source
68+
.replace(/(?: *\/\/.*\n)*\s*' *(?:<% *)?if *\(!hasDontEnumBug *(?:&&|\))[\s\S]+?<% *} *(?:%>|').+/g, '')
69+
.replace(/!hasDontEnumBug *\|\|/g, '');
70+ }
71+
if (isMobile) {
6772
source = replaceVar(source, 'isKeysFast', 'false');
6873
}
6974
vm.runInNewContext(source, sandbox);

lodash.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162

163163
function ctor() { this.x = 1; }
164164
ctor.prototype = { 'valueOf': 1, 'y': 1 };
165-
166165
for (var prop in new ctor) { props.push(prop); }
167166
for (prop in arguments) { noArgsEnum = !prop; }
168167

@@ -417,6 +416,12 @@
417416
' } else {' +
418417
' <% } %>' +
419418

419+
// Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
420+
// (if the prototype or a property on the prototype has been set)
421+
// incorrectly sets a function's `prototype` property [[Enumerable]]
422+
// value to `true`. Because of this Lo-Dash standardizes on skipping
423+
// the the `prototype` property of functions regardless of its
424+
// [[Enumerable]] value.
420425
' <% if (!hasDontEnumBug) { %>\n' +
421426
' var skipProto = typeof iteratee == \'function\' && \n' +
422427
' propertyIsEnumerable.call(iteratee, \'prototype\');\n' +
@@ -440,25 +445,15 @@
440445
' <% } else { %>\n' +
441446
' <%= objectBranch.beforeLoop %>;\n' +
442447
' for (index in iteratee) {' +
443-
' <% if (hasDontEnumBug) { %>\n' +
444-
' <% if (useHas) { %>if (hasOwnProperty.call(iteratee, index)) {\n <% } %>' +
448+
' <% if (!hasDontEnumBug || useHas) { %>\n if (<%' +
449+
' if (!hasDontEnumBug) { %>!(skipProto && index == \'prototype\')<% }' +
450+
' if (!hasDontEnumBug && useHas) { %> && <% }' +
451+
' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' +
452+
' %>) {' +
453+
' <% } %>\n' +
445454
' value = iteratee[index];\n' +
446455
' <%= objectBranch.inLoop %>;\n' +
447-
' <% if (useHas) { %>}<% } %>' +
448-
449-
// Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
450-
// (if the prototype or a property on the prototype has been set)
451-
// incorrectly sets a function's `prototype` property [[Enumerable]]
452-
// value to `true`. Because of this Lo-Dash standardizes on skipping
453-
// the the `prototype` property of functions regardless of its
454-
// [[Enumerable]] value.
455-
' <% } else { %>\n' +
456-
' if (!(skipProto && index == \'prototype\')<% if (useHas) { %> &&\n' +
457-
' hasOwnProperty.call(iteratee, index)<% } %>) {\n' +
458-
' value = iteratee[index];\n' +
459-
' <%= objectBranch.inLoop %>\n' +
460-
' }' +
461-
' <% } %>\n' +
456+
' <% if (!hasDontEnumBug || useHas) { %>}\n<% } %>' +
462457
' }' +
463458
' <% } %>' +
464459

0 commit comments

Comments
 (0)
0