8000 Ensure `_.keys` use in `createIterator` is consistent per build. · lodash/lodash@743aa47 · GitHub
[go: up one dir, main page]

10000
Skip to content

Commit 743aa47

Browse files
committed
Ensure _.keys use in createIterator is consistent per build.
Former-commit-id: a4e0aef177d4d1c26ed5ce088574b591a6666d0d
1 parent ba85d5d commit 743aa47

File tree

10 files changed

+836
-846
lines changed

10 files changed

+836
-846
lines changed

build.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
'every': ['createCallback', 'isArray'],
9999
'filter': ['createCallback', 'isArray'],
100100
'find': ['createCallback', 'forEach', 'isArray'],
101-
'findIndex': [],
102-
'findKey': [],
101+
'findIndex': ['createCallback'],
102+
'findKey': ['createCallback'],
103103
'first': [],
104104
'flatten': ['createCallback', 'isArray'],
105105
'forEach': ['createCallback', 'isArguments', 'isArray', 'isString'],
@@ -190,10 +190,12 @@
190190
'arrays',
191191
'bottom',
192192
'firstArg',
193+
'init',
193194
'loop',
194195
'shadowedProps',
195196
'top',
196-
'useHas'
197+
'useHas',
198+
'useKeys'
197199 10000
];
198200

199201
/** List of all Lo-Dash methods */
@@ -923,16 +925,19 @@
923925
*
924926
* @private
925927
* @param {String} source The source to process.
926-
* @param {String} varName The name of the variable to remove.
928+
* @param {String} identifier The name of the variable or property to remove.
927929
* @returns {String} Returns the modified source.
928930
*/
929-
function removeFromCreateIterator(source, varName) {
930-
var snippet = matchFunction(source, 'createIterator');
931+
function removeFromCreateIterator(source, identifier) {
932+
var snippet = matchFunction(source, 'createIterator');
931933
if (!snippet) {
932934
return source;
933935
}
934936
// remove data object property assignment
935-
var modified = snippet.replace(RegExp("^(?: *\\/\\/.*\\n)* *'" + varName + "': *" + varName + '.+\\n+', 'm'), '');
937+
var modified = snippet
938+
.replace(RegExp("^(?: *\\/\\/.*\\n)* *'" + identifier + "':.+\\n+", 'm'), '')
939+
.replace(/,(?=\s*})/, '');
940+
936941
source = source.replace(snippet, function() {
937942
return modified;
938943
});
@@ -941,7 +946,7 @@
941946
snippet = modified.match(/Function\([\s\S]+$/)[0];
942947

943948
modified = snippet
944-
.replace(RegExp('\\b' + varName + '\\b,? *', 'g'), '')
949+
.replace(RegExp('\\b' + identifier + '\\b,? *', 'g'), '')
945950
.replace(/, *',/, "',")
946951
.replace(/,\s*\)/, ')')
947952

@@ -1019,12 +1024,11 @@
10191024
* @returns {String} Returns the modified source.
10201025
*/
10211026
function removeKeysOptimization(source) {
1022-
source = removeVar(source, 'isJSC');
1023-
source = removeSupportProp(source, 'fastKeys');
1027+
source = removeFromCreateIterator(source, 'useKeys');
10241028

10251029
// remove optimized branch in `iteratorTemplate`
10261030
source = source.replace(getIteratorTemplate(source), function(match) {
1027-
return match.replace(/^(?: *\/\/.*\n)* *["']( *)<% *if *\(support\.fastKeys[\s\S]+?["']\1<% *} *else *{ *%>.+\n([\s\S]+?) *["']\1<% *} *%>.+/m, "'\\n' +\n$2");
1031+
return match.replace(/^(?: *\/\/.*\n)* *["']( *)<% *if *\(useHas *&& *useKeys[\s\S]+?["']\1<% *} *else *{ *%>.+\n([\s\S]+?) *["']\1<% *} *%>.+/m, "'\\n' +\n$2");
10281032
});
10291033

10301034
return source;
@@ -1826,7 +1830,7 @@
18261830
source = replaceVar(source, varName, 'false');
18271831
});
18281832

1829-
_.each(['argsClass', 'fastBind', 'fastKeys'], function(propName) {
1833+
_.each(['argsClass', 'fastBind'], function(propName) {
18301834
source = replaceSupportProp(source, propName, 'false');
18311835
});
18321836

@@ -2484,17 +2488,20 @@
24842488
if (!isRemoved(source, 'keys')) {
24852489
source = source.replace(
24862490
matchFunction(source, 'keys').replace(/[\s\S]+?var keys *= */, ''),
2487-
matchFunction(source, 'shimKeys').replace(/[\s\S]+?function shimKeys/, 'function').replace(/}\n$/, '};\n')
2491+
matchFunction(source, 'shimKeys').replace(/[\s\S]+?var shimKeys *= */, '')
24882492
);
24892493

24902494
source = removeFunction(source, 'shimKeys');
24912495
}
24922496
// replace `_.isArguments` with fallback
24932497
if (!isRemoved(source, 'isArguments')) {
2494-
source = source.replace(
2495-
matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''),
2496-
getIsArgumentsFallback(source).match(/isArguments *= *function([\s\S]+?) *};/)[1] + ' }\n'
2497-
);
2498+
source = source.replace(matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''), function() {
2499+
var fallback = getIsArgumentsFallback(source),
2500+
body = fallback.match(/isArguments *= *function([\s\S]+? *});/)[1],
2501+
indent = getIndent(fallback);
2502+
2503+
return body.replace(RegExp('^' + indent, 'gm'), indent.slice(0, -2)) + '\n';
2504+
});
24982505

24992506
source = removeIsArgumentsFallback(source);
25002507
}

build/pre-compile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
'isString',
2222
'iterable',
2323
'length',
24+
'keys',
2425
'lodash',
25-
'nativeKeys',
2626
'object',
2727
'objectTypes',
2828
'ownIndex',
@@ -39,10 +39,12 @@
3939
'arrays',
4040
'bottom',
4141
'firstArg',
42+
'init',
4243
'loop',
4344
'shadowedProps',
4445
'top',
45-
'useHas'
46+
'useHas',
47+
'useKeys'
4648
];
4749

4850
/** Used to minify variables and string values to a single character */

0 commit comments

Comments
 (0)
0