From 6be64b363c728cccbedd5dd0eb9c17f7aca01f67 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 30 Jun 2013 10:49:55 -0700 Subject: [PATCH] Make `getFunctionSource` support number values for `indent` in build.js. Former-commit-id: 5f977d8058f6773fdffa09f01a59135e9ea3337a --- build.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build.js b/build.js index 8e92792b2..8645a4c97 100755 --- a/build.js +++ b/build.js @@ -783,7 +783,7 @@ } var filePath = path.join(directory, filename), text = fs.readFileSync(filePath, 'utf8'), - precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options))), + precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options), 2)), prop = filename.replace(/\..*$/, ''); source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', ''); @@ -1057,13 +1057,15 @@ * * @private * @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. */ function getFunctionSource(func, indent) { var source = func.source || (func + ''); - if (indent == null) { - indent = ' '; + + indent || (indent = ''); + if (typeof indent == 'number') { + indent = Array(indent + 1).join(' '); } // format leading whitespace return source.replace(/\n(?:.*)/g, function(match, index) {