Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Support injecting into single-param arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyra Naeseth committed Jul 18, 2017
1 parent 5de641b commit c9e7f35
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/utils.js
Expand Up @@ -14,6 +14,8 @@ var OUTPUT_SUFFIX_PRIVATE = '_'

var NODE_NAME_RE = /^[!?+%]?[a-zA-Z_*][-a-zA-Z0-9_]*(?:[.][a-zA-Z_][a-zA-Z0-9_]*)*(?:[._](?:[0-9]+|[*]))?$/

var SINGLE_PARAM_ARROW_FN_RE = /^(\w+)\s+=>/

var DYNAMIC_NODE_REF = '_dynamic'
var INPUT_ARG_PREFIX = 'args.'
var LAZY_ARG_PREFIX = 'lazyargs.'
Expand Down Expand Up @@ -549,12 +551,19 @@ function parseFnParams(fn) {
keywordIndex = ctorMatch.index
}

var lParenIdx = fnStr.indexOf('(', keywordIndex)
var arrowMatch = SINGLE_PARAM_ARROW_FN_RE.exec(fnStr)
, lParenIdx = fnStr.indexOf('(', keywordIndex)
, rParenIdx = fnStr.indexOf(')', keywordIndex)
, paramsStr
, params
, i

// ES6 arrow functions with a single parameter don't require parentheses
// around the parameter, so we must handle them separately
if (arrowMatch) {
return [arrowMatch[1]]
}

// Check for existence of parentheses
if (lParenIdx === -1 || rParenIdx === -1) {
throw new Error('Invalid function')
Expand Down

0 comments on commit c9e7f35

Please sign in to comment.