Further optimize _.template by controlling how the with-statement is inserted.

Former-commit-id: a62331e771302f9390d5aca04f878b839fe11b69
This commit is contained in:
John-David Dalton
2012-07-05 11:26:17 -04:00
parent a5fe1eb5fb
commit fe6aa8a6fc
4 changed files with 109 additions and 69 deletions

View File

@@ -224,12 +224,17 @@
});
// remove whitespace from `_.template` related regexpes
source = source.replace(/(?:reEmptyString\w+|reInsertVariable) *=.+/g, function(match) {
return match.replace(/ /g, '');
source = source.replace(/(?:reDelimiterCode\w+|reEmptyString\w+|reInsertVariable) *=.+/g, function(match) {
return match.replace(/ |\\n/g, '');
});
// remove newline from double-quoted string in `_.template`
source = source.replace('"\';\\n"', '"\';"');
// remove newline from double-quoted strings in `_.template`
source = source
.replace('"\';\\n__with ("', '"\';__with("')
.replace('"\\n}__\\n__p += \'"', '"}____p+=\'"')
.replace('"__p = \'"', '"__p=\'"')
.replace('"\';\\n"', '"\';"')
.replace("') {\\n'", "'){'")
// remove `useSourceURL` variable
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *try *\{(?:\s*\/\/.*\n)* *var useSourceURL[\s\S]+?catch[^}]+}\n/, '');