|
98 | 98 | 'every': ['createCallback', 'isArray'],
|
99 | 99 | 'filter': ['createCallback', 'isArray'],
|
100 | 100 | 'find': ['createCallback', 'forEach', 'isArray'],
|
101 |
| - 'findIndex': [], |
102 |
| - 'findKey': [], |
| 101 | + 'findIndex': ['createCallback'], |
| 102 | + 'findKey': ['createCallback'], |
103 | 103 | 'first': [],
|
104 | 104 | 'flatten': ['createCallback', 'isArray'],
|
105 | 105 | 'forEach': ['createCallback', 'isArguments', 'isArray', 'isString'],
|
|
190 | 190 | 'arrays',
|
191 | 191 | 'bottom',
|
192 | 192 | 'firstArg',
|
| 193 | + 'init', |
193 | 194 | 'loop',
|
194 | 195 | 'shadowedProps',
|
195 | 196 | 'top',
|
196 |
| - 'useHas' |
| 197 | + 'useHas', |
| 198 | + 'useKeys' |
197 | 199 |
10000
]; |
198 | 200 |
|
199 | 201 | /** List of all Lo-Dash methods */
|
|
923 | 925 | *
|
924 | 926 | * @private
|
925 | 927 | * @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. |
927 | 929 | * @returns {String} Returns the modified source.
|
928 | 930 | */
|
929 |
| - function removeFromCreateIterator(source, varName) { |
930 |
| - var snippet = matchFunction(source, 'createIterator'); |
| 931 | + function removeFromCreateIterator(source, identifier) { |
| 932 | + var snippet = matchFunction(source, 'createIterator'); |
931 | 933 | if (!snippet) {
|
932 | 934 | return source;
|
933 | 935 | }
|
934 | 936 | // 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 | + |
936 | 941 | source = source.replace(snippet, function() {
|
937 | 942 | return modified;
|
938 | 943 | });
|
|
941 | 946 | snippet = modified.match(/Function\([\s\S]+$/)[0];
|
942 | 947 |
|
943 | 948 | modified = snippet
|
944 |
| - .replace(RegExp('\\b' + varName + '\\b,? *', 'g'), '') |
| 949 | + .replace(RegExp('\\b' + identifier + '\\b,? *', 'g'), '') |
945 | 950 | .replace(/, *',/, "',")
|
946 | 951 | .replace(/,\s*\)/, ')')
|
947 | 952 |
|
|
1019 | 1024 | * @returns {String} Returns the modified source.
|
1020 | 1025 | */
|
1021 | 1026 | function removeKeysOptimization(source) {
|
1022 |
| - source = removeVar(source, 'isJSC'); |
1023 |
| - source = removeSupportProp(source, 'fastKeys'); |
| 1027 | + source = removeFromCreateIterator(source, 'useKeys'); |
1024 | 1028 |
|
1025 | 1029 | // remove optimized branch in `iteratorTemplate`
|
1026 | 1030 | 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"); |
1028 | 1032 | });
|
1029 | 1033 |
|
1030 | 1034 | return source;
|
|
1826 | 1830 | source = replaceVar(source, varName, 'false');
|
1827 | 1831 | });
|
1828 | 1832 |
|
1829 |
| - _.each(['argsClass', 'fastBind', 'fastKeys'], function(propName) { |
| 1833 | + _.each(['argsClass', 'fastBind'], function(propName) { |
1830 | 1834 | source = replaceSupportProp(source, propName, 'false');
|
1831 | 1835 | });
|
1832 | 1836 |
|
|
2484 | 2488 | if (!isRemoved(source, 'keys')) {
|
2485 | 2489 | source = source.replace(
|
2486 | 2490 | 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 *= */, '') |
2488 | 2492 | );
|
2489 | 2493 |
|
2490 | 2494 | source = removeFunction(source, 'shimKeys');
|
2491 | 2495 | }
|
2492 | 2496 | // replace `_.isArguments` with fallback
|
2493 | 2497 | 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 | + }); |
2498 | 2505 |
|
2499 | 2506 | source = removeIsArgumentsFallback(source);
|
2500 | 2507 | }
|
|
0 commit comments