Avoid Firefox's unoptimized Function constructor.

Former-commit-id: 7cc5fc63c0cebd1410edde47c88e580c64fa2b98
This commit is contained in:
John-David Dalton
2012-11-22 23:53:16 -06:00
parent 77bac4cf9e
commit 383b1a5769
4 changed files with 96 additions and 47 deletions

View File

@@ -246,6 +246,9 @@
// add newline to `+"__p+='"` in underscore.js `_.template`
source = source.replace(/\+"__p\+='"/g, '+"\\n__p+=\'"');
// add newline to `body + '}'` in `createFunction`
source = source.replace(/body *\+ *'}'/, 'body+"\\n}"');
// remove whitespace from `_.template` related regexes
source = source.replace(/(?:reEmptyString\w+|reInsertVariable) *=.+/g, function(match) {
return match.replace(/ |\\n/g, '');
@@ -318,7 +321,9 @@
modified = snippet;
// add brackets to whitelisted properties so the Closure Compiler won't mung them
modified = modified.replace(RegExp('\\.(' + iteratorOptions.join('|') + ')\\b', 'g'), "['$1']");
modified = modified.replace(RegExp('\\.(' + iteratorOptions.join('|') + ')\\b', 'g'), function(match, prop) {
return "['" + prop.replace(/['\n\r\t]/g, '\\$&') + "']";
});
if (isCreateIterator) {
// replace with modified snippet early and clip snippet to the `factory`