Make pre-compile.js and post-compile.js support underscore.js.

Former-commit-id: 76d040f630faf03bd5a8eb168259814f5662ba50
This commit is contained in:
John-David Dalton
2012-09-02 15:24:30 -07:00
parent 3a7661b111
commit 87d70f29a1
2 changed files with 23 additions and 7 deletions

View File

@@ -231,7 +231,11 @@
'where',
'without',
'wrap',
'zip'
'zip',
// properties used by underscore.js
'_chain',
'_wrapped'
];
/*--------------------------------------------------------------------------*/
@@ -272,6 +276,9 @@
// remove brackets from `_.escape()` in `_.template`
source = source.replace(/__e *= *_\['escape']/g, '__e=_.escape');
// remove brackets from `_.escape()` in underscore.js `_.template`
source = source.replace(/_\['escape'\]\(__t'/g, '_.escape(__t');
// remove brackets from `collection.indexOf` in `_.contains`
source = source.replace("collection['indexOf'](target)", 'collection.indexOf(target)');
@@ -286,6 +293,9 @@
});
});
// add newline to `+"__p+='"` in underscore.js `_.template`
source = source.replace(/\+"__p\+='"/g, '+"\\n__p+=\'"');
// remove whitespace from `_.template` related regexes
source = source.replace(/(?:reDelimiterCode\w+|reEmptyString\w+|reInsertVariable) *=.+/g, function(match) {
return match.replace(/ |\\n/g, '');