Make build.js remove extraneous semicolons from inlined methods.

Former-commit-id: 061ed370a4c95a64669335c6b2a5da7ebc1015fd
This commit is contained in:
John-David Dalton
2013-05-14 08:11:56 -07:00
parent 4b3009a195
commit d3df072a22

View File

@@ -536,7 +536,7 @@
var filePath = path.join(directory, filename);
if (pattern.test(filename)) {
var text = fs.readFileSync(filePath, 'utf8'),
precompiled = getFunctionSource(_.template(text, null, options)),
precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options))),
prop = filename.replace(/\..*$/, '');
source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', '');
@@ -576,6 +576,17 @@
return string[0].toUpperCase() + string.toLowerCase().slice(1);
}
/**
* Removes unnecessary semicolons and whitespace from compiled code.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function cleanupCompiled(source) {
return source.replace(/([{}]) *;/g, '$1');
}
/**
* Removes unnecessary comments, whitespace, and pseudo private properties.
*
@@ -2788,7 +2799,7 @@
// extract, format, and inject the compiled function's source code
source = source.replace(reFunc, function(match, indent, left) {
return (indent + left) +
getFunctionSource(lodash[methodName], indent) + ';\n';
cleanupCompiled(getFunctionSource(lodash[methodName], indent)) + ';\n';
});
}
});
@@ -2851,7 +2862,7 @@
// inline `iteratorTemplate` template
source = source.replace(getIteratorTemplate(source), function(match) {
var indent = getIndent(match),
snippet = getFunctionSource(lodash._iteratorTemplate, indent);
snippet = cleanupCompiled(getFunctionSource(lodash._iteratorTemplate, indent));
// prepend data object references to property names to avoid having to
// use a with-statement
@@ -2867,7 +2878,6 @@
.replace(/__p *\+= *' *';/g, '')
.replace(/\s*\+\s*'';/g, ';')
.replace(/(__p *\+= *)' *' *\+/g, '$1')
.replace(/(?:; *)([{}])|([{}])(?: *;)/g, '$1$2')
.replace(/\(\(__t *= *\( *([^)]+?) *\)\) *== *null *\? *'' *: *__t\)/g, '($1)');
// remove the with-statement