From e4e2658a3b410d6ad17fb6b3a5420074c3d5c190 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 14 May 2012 18:43:32 -0400 Subject: [PATCH] Make pre-compile.js avoid erroring when lodash functions are missing. Former-commit-id: 61f56f206225e1bb0232faea5624d541bc905aa0 --- build/pre-compile.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/build/pre-compile.js b/build/pre-compile.js index 597153f70..9874f6b2f 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -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;