8000 Tweak how the build handles `support` property cleanup and ensure the… · lodash/lodash@07078bd · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07078bd

Browse files
committed
Tweak how the build handles support property cleanup and ensure the mobile build fixes some old WebKit bugs.
Former-commit-id: 34c3aeb2b58cf83a5a141ffc423245922082a714
1 parent 03657a9 commit 07078bd

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

build.js

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,11 +1735,14 @@
17351735
dependencyMap.defer = _.without(dependencyMap.defer, 'bind');
17361736
}
17371737
if (isModern) {
1738-
dependencyMap.isEmpty = _.without(dependencyMap.isEmpty, 'isArguments');
1739-
dependencyMap.isEqual = _.without(dependencyMap.isEqual, 'isArguments');
1740-
dependencyMap.isPlainObject = _.without(dependencyMap.isPlainObject, 'isArguments');
1741-
dependencyMap.keys = _.without(dependencyMap.keys, 'isArguments');
17421738
dependencyMap.reduceRight = _.without(dependencyMap.reduceRight, 'isString');
1739+
1740+
if (!isMobile) {
1741+
dependencyMap.isEmpty = _.without(dependencyMap.isEmpty, 'isArguments');
1742+
dependencyMap.isEqual = _.without(dependencyMap.isEqual, 'isArguments');
1743+
dependencyMap.isPlainObject = _.without(dependencyMap.isPlainObject, 'isArguments');
1744+
dependencyMap.keys = _.without(dependencyMap.keys, 'isArguments');
1745+
}
17431746
}
17441747
if (isUnderscore) {
17451748
dependencyMap.contains = _.without(dependencyMap.contains, 'isString');
@@ -1763,16 +1766,16 @@
17631766
}
17641767
if (isModern || isUnderscore) {
17651768
dependencyMap.at = _.without(dependencyMap.at, 'isString');
1766-
dependencyMap.forEach = _.without(dependencyMap.forEach, 'isArguments', 'isString');
1767-
dependencyMap.forIn = _.without(dependencyMap.forIn, 'isArguments');
1768-
dependencyMap.forOwn = _.without(dependencyMap.forOwn, 'isArguments');
1769+
dependencyMap.forEach = _.without(dependencyMap.forEach, 'isString');
17691770
dependencyMap.toArray = _.without(dependencyMap.toArray, 'isString');
17701771

17711772
if (!isMobile) {
17721773
dependencyMap.every = _.without(dependencyMap.every, 'isArray');
17731774
dependencyMap.find = _.without(dependencyMap.find, 'isArray');
17741775
dependencyMap.filter = _.without(dependencyMap.filter, 'isArray');
1775-
dependencyMap.forEach = _.without(dependencyMap.forEach, 'isArray');
1776+
dependencyMap.forEach = _.without(dependencyMap.forEach, 'isArguments', 'isArray');
1777+
dependencyMap.forIn = _.without(dependencyMap.forIn, 'isArguments');
1778+
dependencyMap.forOwn = _.without(dependencyMap.forOwn, 'isArguments');
17761779
dependencyMap.map = _.without(dependencyMap.map, 'isArray');
17771780
dependencyMap.max.push('forEach');
17781781
dependencyMap.min.push('forEach');
@@ -1891,13 +1894,17 @@
18911894
source = removeSupportSpliceObjects(source);
18921895
source = removeIsArgumentsFallback(source);
18931896

1894-
// remove `_.isPlainObject` fallback
1895-
source = source.replace(matchFunction(source, 'isPlainObject'), function(match) {
1896-
return match.replace(/!getPrototypeOf[^:]+:\s*/, '');
1897-
});
1898-
1899-
if (!isMobile) {
1897+
if (isMobile) {
1898+
source = replaceSupportProp(source, 'enumPrototypes', 'true');
1899+
source = replaceSupportProp(source, 'nonEnumArgs', 'true');
1900+
}
1901+
else {
19001902
source = removeIsFunctionFallback(source);
1903+
1904+
// remove `shimIsPlainObject` from `_.isPlainObject`
1905+
source = source.replace(matchFunction(source, 'isPlainObject'), function(match) {
1906+
return match.replace(/!getPrototypeOf[^:]+:\s*/, '');
1907+
});
19011908
}
19021909
}
19031910
if (isMobile || isUnderscore) {
@@ -1907,12 +1914,12 @@
19071914
if (isModern || isUnderscore) {
19081915
source = removeSupportArgsClass(source);
19091916
source = removeSupportNonEnumShadows(source);
1910-
source = removeSupportEnumPrototypes(source);
19111917
source = removeSupportOwnLast(source);
19121918
source = removeSupportUnindexedChars(source);
19131919
source = removeSupportNodeClass(source);
19141920

19151921
if (!isMobile) {
1922+
source = removeSupportEnumPrototypes(source);
19161923
source = removeSupportNonEnumArgs(source);
19171924

19181925
// replace `_.forEach`
@@ -2866,19 +2873,33 @@
28662873
source = removeVar(source, 'iteratorTemplate');
28672874
source = removeVar(source, 'templateIterator');
28682875
source = removeSupportNonEnumShadows(source);
2869-
source = removeSupportEnumPrototypes(source);
2870-
}
2871-
if (!/support\.(?:enumPrototypes|nonEnumShadows|ownLast)\b/.test(source)) {
2872-
// remove code used to resolve unneeded `support` properties
2873-
source = source.replace(/^ *\(function[\s\S]+?\n(( *)var ctor *= *function[\s\S]+?(?:\n *for.+)+\n)([\s\S]+?)}\(1\)\);\n/m, function(match, setup, indent, body) {
2874-
if (/support\.spliceObjects\b/.test(match)) {
2875-
return match.replace(setup, indent + "var object = { '0': 1, 'length': 1 };\n");
2876-
} else if (/support\.nonEnumArgs\b/.test(match)) {
2877-
return match.replace(setup, indent + 'for (var prop in arguments) { }\n');
2878-
}
2879-
return body.replace(RegExp('^' + indent, 'gm'), indent.slice(0, -2));
2880-
});
28812876
}
2877+
// remove code used to resolve unneeded `support` properties
2878+
source = source.replace(/^ *\(function[\s\S]+?\n(( *)var ctor *= *function[\s\S]+?(?:\n *for.+)+\n)([\s\S]+?)}\(1\)\);\n/m, function(match, setup, indent, body) {
2879+
var modified = setup;
2880+
if (!/support\.spliceObjects *=(?! *(?:false|true))/.test(match)) {
2881+
modified = modified.replace(/^ *object *=.+\n/m, '');
2882+
}
2883+
if (!/support\.enumPrototypes *=(?! *(?:false|true))/.test(match) &&
2884+
!/support\.nonEnumShadows *=(?! *(?:false|true))/.test(match) &&
2885+
!/support\.ownLast *=(?! *(?:false|true))/.test(match)) {
2886+
modified = modified
2887+
.replace(/\bctor *=.+\s+/, '')
2888+
.replace(/^ *ctor\.prototype.+\s+.+\n/m, '')
2889+
.replace(/(?:,\n)? *props *=[^;]+/, '')
2890+
.replace(/^ *for *\((?=prop)/, '$&var ')
2891+
}
2892+
if (!/support\.nonEnumArgs *=(?! *(?:false|true))/.test(match)) {
2893+
modified = modified.replace(/^ *for *\(.+? arguments.+\n/m, '' 8560 ;);
2894+
}
2895+
// cleanup the empty var statement
2896+
modified = modified.replace(/^ *var;\n/m, '');
2897+
2898+
// if no setup then remove IIFE
2899+
return /^\s*$/.test(modified)
2900+
? body.replace(RegExp('^' + indent, 'gm'), indent.slice(0, -2))
2901+
: match.replace(setup, modified);
2902+
});
28822903
}
28832904
if (_.size(source.match(/\bfreeModule\b/g)) < 2) {
28842905
source = removeVar(source, 'freeModule');

0 commit comments

Comments
 (0)
0