Make pre-compile.js avoid erroring when lodash functions are missing.

Former-commit-id: 61f56f206225e1bb0232faea5624d541bc905aa0
This commit is contained in:
John-David Dalton
2012-05-14 18:43:32 -04:00
parent ae8e7ae992
commit e4e2658a3b

View File

@@ -126,8 +126,13 @@
// minify `_.sortBy` internal properties
(function() {
// exit early if `_.sortBy` is not found
var snippet = (source.match(/( +)function sortBy[\s\S]+?\n\1}/) || [])[0];
if (!snippet) {
return;
}
var properties = ['criteria', 'value'],
snippet = source.match(/( +)function sortBy[\s\S]+?\n\1}/)[0],
result = snippet;
// minify property strings
@@ -140,7 +145,7 @@
}());
// minify all compilable snippets
source.match(
var snippets = source.match(
RegExp([
// match the `iterationTemplate`
'( +)var iteratorTemplate[\\s\\S]+?\\n\\1}',
@@ -149,10 +154,16 @@
// match the the `createIterator` function
'( +)function createIterator[\\s\\S]+?\\n\\3}',
// match methods created by `createIterator` calls
'createIterator\\((?:[\'{]|[a-zA-Z]+,)[\\s\\S]+?\\);\\n'
'createIterator\\((?:{|[a-zA-Z]+)[\\s\\S]+?\\);\\n'
].join('|'), 'g')
)
.forEach(function(snippet, index) {
);
// exit early if no compilable snippets
if (!snippets) {
return source;
}
snippets.forEach(function(snippet, index) {
var isCreateIterator = /function createIterator/.test(snippet),
isIteratorTemplate = /var iteratorTemplate/.test(snippet),
result = snippet;