mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Make getFunctionSource support number values for indent in build.js.
Former-commit-id: 5f977d8058f6773fdffa09f01a59135e9ea3337a
This commit is contained in:
10
build.js
10
build.js
@@ -783,7 +783,7 @@
|
|||||||
}
|
}
|
||||||
var filePath = path.join(directory, filename),
|
var filePath = path.join(directory, filename),
|
||||||
text = fs.readFileSync(filePath, 'utf8'),
|
text = fs.readFileSync(filePath, 'utf8'),
|
||||||
precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options))),
|
precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options), 2)),
|
||||||
prop = filename.replace(/\..*$/, '');
|
prop = filename.replace(/\..*$/, '');
|
||||||
|
|
||||||
source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', '');
|
source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', '');
|
||||||
@@ -1057,13 +1057,15 @@
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Function} func The function to process.
|
* @param {Function} func The function to process.
|
||||||
* @param {String} indent The function indent.
|
* @param {Number|String} [indent=0] The level to indent.
|
||||||
* @returns {String} Returns the formatted source.
|
* @returns {String} Returns the formatted source.
|
||||||
*/
|
*/
|
||||||
function getFunctionSource(func, indent) {
|
function getFunctionSource(func, indent) {
|
||||||
var source = func.source || (func + '');
|
var source = func.source || (func + '');
|
||||||
if (indent == null) {
|
|
||||||
indent = ' ';
|
indent || (indent = '');
|
||||||
|
if (typeof indent == 'number') {
|
||||||
|
indent = Array(indent + 1).join(' ');
|
||||||
}
|
}
|
||||||
// format leading whitespace
|
// format leading whitespace
|
||||||
return source.replace(/\n(?:.*)/g, function(match, index) {
|
return source.replace(/\n(?:.*)/g, function(match, index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user