diff --git a/build.js b/build.js index 7c56a2f38..c0910c8bc 100755 --- a/build.js +++ b/build.js @@ -1167,6 +1167,22 @@ ) || methodName; } + /** + * Gets the `templateSettings` assignment from `source`. + * + * @private + * @param {String} source The source to inspect. + * @returns {String} Returns the `templateSettings`. + */ + function getTemplateSettings(source) { + var result = source.match(RegExp( + multilineComment + + '( *)(?:var +|lodash\\.)templateSettings *=[\\s\\S]+?\\n\\1};\\n' + )); + + return result ? result[0] : ''; + } + /** * Creates a sorted array of all variables defined outside of Lo-Dash methods. * @@ -1448,6 +1464,22 @@ return source; } + /** + * Removes all references to `getIndexOf` from `source`. + * + * @private + * @param {String} source The source to process. + * @returns {String} Returns the modified source. + */ + function removeGetIndexOf(source) { + source = removeFunction(source, 'getIndexOf'); + + // replace all `getIndexOf` calls with `basicEach` + source = source.replace(/\bgetIndexOf\(\)/g, 'basicEach'); + + return source; + } + /** * Removes the `_.isArguments` fork from `source`. * @@ -1889,6 +1921,17 @@ }); } + /** + * Removes the `templateSettings` assignment from `source`. + * + * @private + * @param {String} source The source to inspect. + * @returns {String} Returns the modified source. + */ + function removeTemplateSettings(source) { + return source.replace(getTemplateSettings(source), ''); + } + /** * Removes a given variable from `source`. * @@ -3677,9 +3720,8 @@ ].join('\n' + indent); }); } - if (isExcluded('template')) { - // remove `templateSettings` assignment - source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *lodash\.templateSettings[\s\S]+?};\n/, ''); + if (!_.contains(includeVars, 'templateSettings') && isExcluded('template')) { + source = removeTemplateSettings(source); } if (isExcluded('value')) { source = removeLodashWrapper(source); @@ -3710,8 +3752,10 @@ if (isNoDep) { source = removeFromCreateIterator(source, 'lodash'); - // replace `lodash.createCallback` references with `createCallback` - source = source.replace(/\blodash\.(createCallback\()\b/g, '$1'); + source = removeGetIndexOf(source); + + // remove`lodash` namespace from properties + source = source.replace(/\blodash\.(\w+)\b(?!\s*=)/g, '$1'); // remove all horizontal rule comment separators source = source.replace(/^ *\/\*-+\*\/\n/gm, '');