|
542 | 542 | function matchFunction(source, funcName) {
|
543 | 543 | var result = source.match(RegExp(
|
544 | 544 | // match multi-line comment block (could be on a single line)
|
545 |
| - '\\n +/\\*[^*]*\\*+(?:[^/][^*]*\\*+)*/\\n' + |
| 545 | + '(?:\\n +/\\*[^*]*\\*+(?:[^/][^*]*\\*+)*/\\n)?' + |
546 | 546 | // begin non-capturing group
|
547 | 547 | '(?:' +
|
548 | 548 | // match a function declaration
|
|
733 | 733 | source = source.replace(RegExp('(var ' + varName + ' *=)[\\s\\S]+?(true;\\n)'), '$1$2');
|
734 | 734 | }
|
735 | 735 | source = source.replace(RegExp(
|
736 |
| - // begin non-capturing group |
737 |
| - '(?:' + |
738 | 736 | // match multi-line comment block
|
739 | 737 | '(?:\\n +/\\*[^*]*\\*+(?:[^/][^*]*\\*+)*/)?\\n' +
|
740 | 738 | // match a variable declaration that's not part of a declaration list
|
741 | 739 | '( +)var ' + varName + ' *= *(?:.+?(?:;|&&\\n[^;]+;)|(?:\\w+\\(|{)[\\s\\S]+?\\n\\1.+?;)\\n|' +
|
742 | 740 | // match a variable in a declaration list
|
743 |
| - '\\n +' + varName + ' *=.+?,' + |
744 |
| - // end non-capturing group |
745 |
| - ')' |
| 741 | + '\\n +' + varName + ' *=.+?,' |
746 | 742 | ), '');
|
747 | 743 |
|
748 | 744 | // remove a varaible at the start of a variable declaration list
|
|
1050 | 1046 | source = removeVar(source, 'arrayLikeClasses');
|
1051 | 1047 | source = removeVar(source, 'cloneableClasses');
|
1052 | 1048 |
|
1053 |
| - // remove large array optimizations from `cachedContains` |
1054 |
| - source = source.replace(/( +)function cachedContains[\s\S]+?\n\1}/, [ |
1055 |
| - ' function cachedContains(array, fromIndex) {', |
1056 |
| - ' return function(value) {', |
1057 |
| - ' return indexOf(array, value, fromIndex || 0) > -1;', |
1058 |
| - ' };', |
| 1049 | + // remove large array optimizations |
| 1050 | + source = removeFunction(source, 'cachedContains'); |
| 1051 | + source = removeVar(source, 'largeArraySize'); |
| 1052 | + |
| 1053 | + // replace `_.clone` |
| 1054 | + source = source.replace(/( +)function clone[\s\S]+?\n\1}/, [ |
| 1055 | + ' function clone(value) {', |
| 1056 | + ' return value && objectTypes[typeof value]', |
| 1057 | + ' ? (isArray(value) ? slice.call(value) : extend({}, value))', |
| 1058 | + ' : value', |
1059 | 1059 | ' }'
|
1060 | 1060 | ].join('\n'));
|
1061 | 1061 |
|
1062 |
| - // reduce the number of arguments passed to `cachedContains` from 3 to 2 |
1063 |
| - source = source.replace(/(cachedContains\(\w+, *\w+), *\w+/g, '$1'); |
| 1062 | + // replace `_.difference` |
| 1063 | + source = source.replace(/( +)function difference[\s\S]+?\n\1}/, [ |
| 1064 | + ' function difference(array) {', |
| 1065 | + ' var index = -1,', |
| 1066 | + ' length = array.length,', |
| 1067 | + ' flattened = concat.apply(ArrayProto, arguments),', |
| 1068 | + ' result = [];', |
| 1069 | + '', |
| 1070 | + ' while (++index < length) {', |
| 1071 | + ' var value = array[index]', |
| 1072 | + ' if (indexOf(flattened, value, length) < 0) {', |
| 1073 | + ' result.push(value);', |
| 1074 | + ' }', |
| 1075 | + ' }', |
| 1076 | + ' return result', |
| 1077 | + ' }' |
| 1078 | + ].join('\n')); |
| 1079 | + |
| 1080 | + // replace `_.intersection` |
| 1081 | + source = source.replace(/( +)function intersection[\s\S]+?\n\1}/, [ |
| 1082 | + ' function intersection(array) {', |
| 1083 | + ' var argsLength = arguments.length,', |
| 1084 | + ' index = -1,', |
| 1085 | + ' length = array.length,', |
| 1086 | + ' result = [];', |
| 1087 | + '', |
| 1088 | + ' array: while (++index < length) {', |
| 1089 | + ' var value = array[index]', |
| 1090 | + ' if (indexOf(result, value) < 0) {', |
| 1091 | + ' for (var argsIndex = 1; argsIndex < argsLength; argsIndex++) {', |
| 1092 | + ' if (indexOf(arguments[argsIndex], value) < 0) {', |
| 1093 | + ' continue array;', |
| 1094 | + ' }', |
| 1095 | + ' }', |
| 1096 | + ' result.push(value);', |
| 1097 | + ' }', |
| 1098 | + ' }', |
| 1099 | + ' return result', |
| 1100 | + ' }' |
| 1101 | + ].join('\n')); |
| 1102 | + |
| 1103 | + // replace `_.without` |
| 1104 | + source = source.replace(/( +)function without[\s\S]+?\n\1}/, [ |
| 1105 | + ' function without(array) {', |
| 1106 | + ' var index = -1,', |
| 1107 | + ' length = array.length,', |
| 1108 | + ' result = [];', |
| 1109 | + '', |
| 1110 | + ' while (++index < length) {', |
| 1111 | + ' var value = array[index]', |
| 1112 | + ' if (indexOf(arguments, value, 1) < 0) {', |
| 1113 | + ' result.push(value);', |
| 1114 | + ' }', |
| 1115 | + ' }', |
| 1116 | + ' return result', |
| 1117 | + ' }' |
| 1118 | + ].join('\n')); |
1064 | 1119 |
|
1065 | 1120 | // replace `arrayLikeClasses` in `_.isEmpty`
|
1066 | 1121 | source = source.replace(/'if *\(arrayLikeClasses[\s\S]+?' \|\|\\n/, "'if (isArray(value) || className == stringClass ||");
|
|
1069 | 1124 | source = source.replace(/(?: *\/\/.*\n)*( +)var isArr *= *arrayLikeClasses[^}]+}/, '$1var isArr = isArray(a);');
|
1070 | 1125 |
|
1071 | 1126 | // remove "exit early" feature from `_.each`
|
1072 |
| - source = source.replace(/( )+var baseIteratorOptions *=[\s\S]+?\n\1.+?;/, function(match) { |
| 1127 | + source = source.replace(/( +)var baseIteratorOptions *=[\s\S]+?\n\1.+?;/, function(match) { |
1073 | 1128 | return match.replace(/if *\(callback[^']+/, 'callback(value, index, collection)');
|
1074 | 1129 | });
|
1075 | 1130 |
|
1076 |
| - // remove `deep` clone functionality |
1077 |
| - source = source.replace(/( +)function clone[\s\S]+?\n\1}/, [ |
1078 |
| - ' function clone(value) {', |
1079 |
| - ' return value && objectTypes[typeof value]', |
1080 |
| - ' ? (isArray(value) ? slice.call(value) : extend({}, value))', |
1081 |
| - ' : value', |
1082 |
| - ' }' |
1083 |
| - ].join('\n')); |
1084 |
| - |
1085 | 1131 | // remove unused features from `createBound`
|
1086 | 1132 | if (buildMethods.indexOf('partial') == -1) {
|
1087 | 1133 | source = source.replace(matchFunction(source, 'createBound'), function(match) {
|
|
0 commit comments