lodash: Fix syntax error in IE < 9 related to return throw …. [jddalton]

Former-commit-id: 8de2886801d447d6c0db119fe061d2fafd49958b
This commit is contained in:
John-David Dalton
2012-04-26 11:29:13 -04:00
parent 5caca9175d
commit 947fc9ce97
3 changed files with 110 additions and 108 deletions

View File

@@ -266,6 +266,7 @@
}
var args = options.args,
exits = options.exits,
firstArg = /^[^,]+/.exec(args)[0],
init = options.init,
iterate = options.iterate,
@@ -285,7 +286,8 @@
('var index, result' + (init ? '=' + init : '')) + ';\n' +
// exit early if first argument, e.g. `collection`, is nullish or custom expression
'if (' + (options.exitsExp || firstArg + ' == undefined') + ')\n' +
'return ' + (options.exits || 'result') + ';\n' +
// IE < 9 JScript will throw a syntax error if it encounters `return throw ...`
(/^throw\b/.test(exits) ? '' : 'return ') + (exits || 'result') + ';\n' +
// add code after the exits if-statement but before the array/object iteration branches
(options.top || '') + ';\n' +
// the following branch is for iterating arrays and array-like objects