Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
var char, enter, length;

enter = function(nextMode) {
  var mode, sliceBegin;
  if (nextMode === mode) {
    return;
  }
  leave();
  sliceBegin = index;
  return mode = nextMode;
};

length = string.length;

while (++index < length) {
  char = string.charAt(index);
  if (char === ':') {
    if (mode === 'variable') {
      throw new Error(`cannot start variable right after variable at ${index}`);
    }
    enter('variable');
  } else if (char === '(') {
    leave();
    openParens++;
    regexString += '(?:';
  } else if (char === ')') {
    leave();
    openParens--;
    if (openParens < 0) {
      throw new Error(`did not expect ) at ${index}`);
    }
    regexString += ')?';
  } else if (char === '*') {
    leave();
    regexString += '(.*?)';
    names.push('_');
  } else {
    switch (mode) {
      case 'variable':
        if (!this.isAlphanumeric(char)) {
          enter('static');
        }
        break;
      case '?':
        enter('static');
    }
  }
}

if (openParens > 0) {
  throw new Error(`unclosed parentheses at ${index}`);
}

leave();
```

Response:
enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          throw new Error "cannot start variable right after variable at #{index}"
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'
      else if char is ')'
        leave()
        openParens--
        if openParens < 0
          throw new Error "did not expect ) at #{index}"
        regexString += ')?'
      else if char is '*'
        leave()
        regexString += '(.*?)'
        names.push '_'
      else
        switch mode
          when 'variable'
            unless this.isAlphanumeric char
              enter('static')
          when '?'
            enter('static')

    if openParens > 0
      throw new Error "unclosed parentheses at #{index}"

    leave()


Prompt:
enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          throw new Error "cannot start variable right after variable at #{index}"
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'
      else if char is ')'
        leave()

Response:
openParens--
        if openParens < 0
          throw new Error "did not expect ) at #{index}"
        regexString += ')?'
      else if char is '*'
        leave()
        regexString += '(.*?)'
        names.push '_'
      else
        switch mode
          when 'variable'
            unless this.isAlphanumeric char
              enter('static')
          when '?'
            enter('static')

    if openParens > 0
      throw new Error "unclosed parentheses at #{index}"

    leave()


Response:
regexString += '$'

    this.names = names
    this.regex = new RegExp regexString

  UrlPattern.newPattern = ->
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.')

  return UrlPattern
)


Prompt:
regexString += '$'

    this.names = names
    this.regex = new RegExp regexString

Response:
UrlPattern.newPattern = ->
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.')

  return UrlPattern
)


Response:
((root, factory) ->
  # AMD
  if ('function' is typeof define) and define.amd?
    define([], factory)
  # CommonJS
  else if exports?
    module.exports = factory()
  # no module system
  else
    root.UrlPattern = factory()
)(this, ->
  UrlPattern = (arg) ->
    # self awareness
    if arg instanceof UrlPattern
      this.isRegex = arg.isRegex
      this.regex = arg.regex
      this.names = arg.names
      return this

    this.isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or this.isRegex
      throw new TypeError 'argument must be a regex or a string'
    if this.isRegex
      this.regex = arg
    else
      this.compile(arg)
    return this

  UrlPattern.prototype.match = (url) ->
    match = this.regex.exec url
    unless match?
      return null

    captured = match.slice(1)
    if this.isRegex
      return captured

    bound = {}
    for value, i in captured
      name = this.names[i]
      # nothing captured for this binding
      unless value?
        continue
      # already bound
      if bound[name]?
        # capture multiple bindings for same name in an array
        unless Array.isArray bound[name]
          bound[name] = [bound[name]]
        bound[name].push value
      else


Prompt:
((root, factory) ->
  # AMD
  if ('function' is typeof define) and define.amd?
    define([], factory)
  # CommonJS
  else if exports?
    module.exports = factory()
  # no module system
  else
    root.UrlPattern = factory()
)(this, ->
  UrlPattern = (arg) ->
    # self awareness
    if arg instanceof UrlPattern
      this.isRegex = arg.isRegex
      this.regex = arg.regex
      this.names = arg.names
      return this

    this.isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or this.isRegex
      throw new TypeError 'argument must be a regex or a string'
    if this.isRegex
      this.regex = arg
    else

Response:
this.compile(arg)
    return this

  UrlPattern.prototype.match = (url) ->
    match = this.regex.exec url
    unless match?
      return null

    captured = match.slice(1)
    if this.isRegex
      return captured

    bound = {}
    for value, i in captured
      name = this.names[i]
      # nothing captured for this binding
      unless value?
        continue
      # already bound
      if bound[name]?
        # capture multiple bindings for same name in an array
        unless Array.isArray bound[name]
          bound[name] = [bound[name]]
        bound[name].push value
      else


Response:
alphanumericRegex = new RegExp '^[a-zA-Z0-9-_]+$'

  UrlPattern.prototype.isAlphanumeric = (string) ->
    alphanumericRegex.test(string)

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.compile = (string) ->
    names = []
    regexString = '^'
    mode = '?'
    sliceBegin = 0
    openParens = 0

    that = this

    index = -1

    leave = ->
      switch mode
        when 'variable'
          if (index - sliceBegin) < 2
            throw new Error "`:` must be followed by at least one alphanumeric character that is the variable name at #{index}"
          names.push string.slice(sliceBegin + 1, index)
          regexString += "([a-zA-Z0-9-_]+)"
        when 'static'
          regexString += that.escapeForRegex(string.slice(sliceBegin, index))
      mode = '?'

    enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          throw new Error "cannot start variable right after variable at #{index}"
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'
      else if char is ')'


Prompt:
alphanumericRegex = new RegExp '^[a-zA-Z0-9-_]+$'

  UrlPattern.prototype.isAlphanumeric = (string) ->
    alphanumericRegex.test(string)

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.compile = (string) ->
    names = []
    regexString = '^'
    mode = '?'
    sliceBegin = 0
    openParens = 0

    that = this

    index = -1

    leave = ->
      switch mode
        when 'variable'
          if (index - sliceBegin) < 2
            throw new Error "`:` must be followed by at least one alphanumeric character that is the variable name at #{index}"

Response:
names.push string.slice(sliceBegin + 1, index)
          regexString += "([a-zA-Z0-9-_]+)"
        when 'static'
          regexString += that.escapeForRegex(string.slice(sliceBegin, index))
      mode = '?'

    enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          throw new Error "cannot start variable right after variable at #{index}"
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'
      else if char is ')'


Response:
leave()
        openParens--
        if openParens < 0
          throw new Error "did not expect ) at #{index}"
        regexString += ')?'
      else if char is '*'
        leave()
        regexString += '(.*?)'
        names.push '_'
      else
        switch mode
          when 'variable'
            unless this.isAlphanumeric char
              enter('static')
          when '?'
            enter('static')


Prompt:
leave()
        openParens--
        if openParens < 0
          throw new Error "did not expect ) at #{index}"
        regexString += ')?'
      else if char is '*'
        leave()
        regexString += '(.*?)'

Response:
names.push '_'
      else
        switch mode
          when 'variable'
            unless this.isAlphanumeric char
              enter('static')
          when '?'
            enter('static')


Response:
if openParens > 0
      throw new Error "unclosed parentheses at #{index}"

    leave()

    regexString += '$'

    this.names = names
    this.regex = new RegExp regexString

  UrlPattern.newPattern = ->
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.')

  return UrlPattern
)


Prompt:
if openParens > 0
      throw new Error "unclosed parentheses at #{index}"

    leave()

    regexString += '$'

Response:
this.names = names
    this.regex = new RegExp regexString

  UrlPattern.newPattern = ->
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.')

  return UrlPattern
)


Response:
alphanumericRegex = new RegExp '^[a-zA-Z0-9]+$'

  UrlPattern.prototype.isAlphanumeric = (string) ->
    alphanumericRegex.test(string)

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.compile = (string) ->
    names = []
    regexString = '^'
    mode = '?'
    sliceBegin = 0
    openParens = 0

    that = this

    index = -1

    leave = ->
      switch mode
        when 'variable'
          if (index - sliceBegin) < 2
            throw new Error "`:` must be followed by at least one alphanumeric character that is the variable name at #{index}"
          names.push string.slice(sliceBegin + 1, index)
          regexString += "([a-zA-Z0-9]+)"
        when 'static'
          regexString += that.escapeForRegex(string.slice(sliceBegin, index))
      mode = '?'

    enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          throw new Error "cannot start variable right after variable at #{index}"
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'
      else if char is ')'


Prompt:
alphanumericRegex = new RegExp '^[a-zA-Z0-9]+$'

  UrlPattern.prototype.isAlphanumeric = (string) ->
    alphanumericRegex.test(string)

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.compile = (string) ->
    names = []
    regexString = '^'
    mode = '?'
    sliceBegin = 0
    openParens = 0

    that = this

    index = -1

    leave = ->
      switch mode
        when 'variable'
          if (index - sliceBegin) < 2
            throw new Error "`:` must be followed by at least one alphanumeric character that is the variable name at #{index}"

Response:
names.push string.slice(sliceBegin + 1, index)
          regexString += "([a-zA-Z0-9]+)"
        when 'static'
          regexString += that.escapeForRegex(string.slice(sliceBegin, index))
      mode = '?'

    enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          throw new Error "cannot start variable right after variable at #{index}"
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'
      else if char is ')'


Response:
alphanumericRegex = new RegExp '^[a-zA-Z0-9]+$'

  UrlPattern.prototype.isAlphanumeric = (string) ->
    alphanumericRegex.test(string)

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.compile = (string) ->
    names = []
    regexString = '^'
    mode = '?'
    sliceBegin = 0
    openParens = 0

    that = this

    index = -1

    leave = ->
      switch mode
        when 'variable'
          if (index - sliceBegin) < 2
            throw new Error '`:` must be followed by at least one alphanumeric character that is the variable name'
          names.push string.slice(sliceBegin + 1, index)
          regexString += "([a-zA-Z0-9]+)"
        when 'static'
          regexString += that.escapeForRegex(string.slice(sliceBegin, index))
      mode = '?'

    enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          # TODO print last variable name as well as position in the source string
          throw new Error 'cannot start variable right after variable'
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'


Prompt:
alphanumericRegex = new RegExp '^[a-zA-Z0-9]+$'

  UrlPattern.prototype.isAlphanumeric = (string) ->
    alphanumericRegex.test(string)

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.compile = (string) ->
    names = []
    regexString = '^'
    mode = '?'
    sliceBegin = 0
    openParens = 0

    that = this

    index = -1

    leave = ->
      switch mode
        when 'variable'
          if (index - sliceBegin) < 2
            throw new Error '`:` must be followed by at least one alphanumeric character that is the variable name'

Response:
names.push string.slice(sliceBegin + 1, index)
          regexString += "([a-zA-Z0-9]+)"
        when 'static'
          regexString += that.escapeForRegex(string.slice(sliceBegin, index))
      mode = '?'

    enter = (nextMode) ->
      if nextMode is mode
        return
      leave()
      sliceBegin = index
      mode = nextMode

    length = string.length
    while ++index < length
      char = string.charAt(index)
      if char is ':'
        if mode is 'variable'
          # TODO print last variable name as well as position in the source string
          throw new Error 'cannot start variable right after variable'
        enter('variable')
      else if char is '('
        leave()
        openParens++
        regexString += '(?:'


Response:
else if char is ')'
        leave()
        openParens--
        if openParens < 0
          throw new Error 'did not expect )'
        regexString += ')?'
      else if char is '*'
        leave()
        regexString += '(.*?)'
        names.push '_'
      else
        switch mode
          when 'variable'
            unless this.isAlphanumeric char
              enter('static')
          when '?'
            enter('static')


Prompt:
else if char is ')'
        leave()
        openParens--
        if openParens < 0
          throw new Error 'did not expect )'
        regexString += ')?'
      else if char is '*'
        leave()

Response:
regexString += '(.*?)'
        names.push '_'
      else
        switch mode
          when 'variable'
            unless this.isAlphanumeric char
              enter('static')
          when '?'
            enter('static')


Response:
if openParens > 0
      throw new Error 'unclosed parentheses'

    leave()

    regexString += '$'

    this.names = names
    this.regex = new RegExp regexString

  UrlPattern.newPattern = ->
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.')

  return UrlPattern
)


Prompt:
if openParens > 0
      throw new Error 'unclosed parentheses'

    leave()

    regexString += '$'

Response:
this.names = names
    this.regex = new RegExp regexString

  UrlPattern.newPattern = ->
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.')

  return UrlPattern
)


Response:
((root, factory) ->
  # AMD
  if ('function' is typeof define) and define.amd?
    define([], factory)
  # CommonJS
  else if exports?
    module.exports = factory()
  # no module system
  else
    root.UrlPattern = factory()
)(this, ->
  UrlPattern = (arg, separator) ->
    # self awareness
    if arg instanceof UrlPattern
      this.isRegex = arg.isRegex
      this.regex = arg.regex
      this.names = arg.names
      return this

    this.isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or this.isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    if this.isRegex
      this.regex = arg
    else
      this.regex = new RegExp this.toRegexString arg, separator
      this.names = this.getNames arg, separator
    return this

  UrlPattern.prototype.match = (url) ->
    match = this.regex.exec url
    return null unless match?

    captured = match.slice(1)
    if this.isRegex
      return captured


Prompt:
((root, factory) ->
  # AMD
  if ('function' is typeof define) and define.amd?
    define([], factory)
  # CommonJS
  else if exports?
    module.exports = factory()
  # no module system
  else
    root.UrlPattern = factory()
)(this, ->
  UrlPattern = (arg, separator) ->
    # self awareness
    if arg instanceof UrlPattern
      this.isRegex = arg.isRegex
      this.regex = arg.regex
      this.names = arg.names
      return this

Response:
this.isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or this.isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    if this.isRegex
      this.regex = arg
    else
      this.regex = new RegExp this.toRegexString arg, separator
      this.names = this.getNames arg, separator
    return this

  UrlPattern.prototype.match = (url) ->
    match = this.regex.exec url
    return null unless match?

    captured = match.slice(1)
    if this.isRegex
      return captured


Response:
bound = {}
    for value, i in captured
      name = this.names[i]
      unless value?
        continue
      if name is '_'
        bound._ ?= []
        bound._.push value
      else
        bound[name] = value

    return bound

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.getNames = (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = this.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'

    names = []
    results = regex.exec arg

    while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  UrlPattern.prototype.escapeSeparators = (string, separator = '/') ->
    escapedSeparator = UrlPattern.prototype.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator


Prompt:
bound = {}
    for value, i in captured
      name = this.names[i]
      unless value?
        continue
      if name is '_'
        bound._ ?= []
        bound._.push value
      else
        bound[name] = value

    return bound

  # source: http://stackoverflow.com/a/3561711
  UrlPattern.prototype.escapeForRegex = (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  UrlPattern.prototype.getNames = (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = this.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'

Response:
names = []
    results = regex.exec arg

    while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  UrlPattern.prototype.escapeSeparators = (string, separator = '/') ->
    escapedSeparator = UrlPattern.prototype.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator


Response:
UrlPattern.prototype.toRegexString = (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = UrlPattern.prototype.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = UrlPattern.prototype.escapeForRegex separator
    UrlPattern.prototype.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"

  UrlPattern.newPattern = () ->
    # helpful hint for new API
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.');

  return UrlPattern
)


Prompt:
UrlPattern.prototype.toRegexString = (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = UrlPattern.prototype.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the

Response:
# separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = UrlPattern.prototype.escapeForRegex separator
    UrlPattern.prototype.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"

  UrlPattern.newPattern = () ->
    # helpful hint for new API
    throw Error('`urlPattern.newPattern` is no longer supported.  Use `new Pattern` instead.');

  return UrlPattern
)


Response:
UrlPattern.prototype.toRegexString = (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = UrlPattern.prototype.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = UrlPattern.prototype.escapeForRegex separator
    UrlPattern.prototype.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"

  return UrlPattern
)


Prompt:
UrlPattern.prototype.toRegexString = (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = UrlPattern.prototype.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

Response:
# replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = UrlPattern.prototype.escapeForRegex separator
    UrlPattern.prototype.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"

  return UrlPattern
)


Response:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        unless value?
          continue
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        unless value?
          continue
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'
```

Response:
module.exports = {
  PatternPrototype: {
    match: function(url) {
      var bound, captured, i, j, len, match, name, value;
      match = this.regex.exec(url);
      if (match == null) {
        return null;
      }
      captured = match.slice(1);
      if (this.isRegex) {
        return captured;
      }
      bound = {};
      for (i = j = 0, len = captured.length; j < len; i = ++j) {
        value = captured[i];
        name = this.names[i];
        if (value == null) {
          continue;
        }
        if (name === '_') {
          if (bound._ == null) {
            bound._ = [];
          }
          bound._.push(value);
        } else {
          bound[name] = value;
        }
      }
      return bound;
    }
  },
  newPattern: function(arg, separator = '/') {
    var isRegex, pattern, regexString;
    isRegex = arg instanceof RegExp;
    if (!(('string' === typeof arg) || isRegex)) {
      throw new TypeError('argument must be a regex or a string');
    }
    [':', '*'].forEach(function(forbidden) {
      if (separator === forbidden) {
        throw new Error(`separator can't be ${forbidden}`);
      }
    });
    pattern = Object.create(module.exports.PatternPrototype);
    pattern.isRegex = isRegex;
    pattern.regex = isRegex ? arg : (regexString = module.exports.toRegexString(arg, separator), new RegExp(regexString));
    if (!isRegex) {
      pattern.names = module.exports.getNames(arg, separator);
    }
    return pattern;
  },
  // source: http://stackoverflow.com/a/3561711
  escapeForRegex: function(string) {
    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  },
  getNames: function(arg, separator = '/') {
    var escapedSeparator, regex;
    if (arg instanceof RegExp) {
      return [];
    }
    escapedSeparator = module.exports.escapeForRegex(separator);
    return regex = new RegExp(`((:?:[^${escapedSeparator}\(\)]+)|(?:[\*]))`, 'g');
  }
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
module.exports = {
  PatternPrototype: {
    match: function(url) {
      var bound, captured, i, j, len, match, name, value;
      match = this.regex.exec(url);
      if (match == null) {
        return null;
      }
      captured = match.slice(1);
      if (this.isRegex) {
        return captured;
      }
      bound = {};
      for (i = j = 0, len = captured.length; j < len; i = ++j) {
        value = captured[i];
        name = this.names[i];
        if (value == null) {
          continue;
        }
        if (name === '_') {
          if (bound._ == null) {
            bound._ = [];
          }
          bound._.push(value);
        } else {
          bound[name] = value;
        }
      }
      return bound;
    }
  },
  newPattern: function(arg, separator = '/') {
    var isRegex, pattern, regexString;
    isRegex = arg instanceof RegExp;
    if (!(('string' === typeof arg) || isRegex)) {
      throw new TypeError('argument must be a regex or a string');
    }
    [':', '*'].forEach(function(forbidden) {
      if (separator === forbidden) {
        throw new Error(`separator can't be ${forbidden}`);
      }
    });
    pattern = Object.create(module.exports.PatternPrototype);
    pattern.isRegex = isRegex;
    pattern.regex = isRegex ? arg : (regexString = module.exports.toRegexString(arg, separator), new RegExp(regexString));
    if (!isRegex) {
      pattern.names = module.exports.getNames(arg, separator);
    }
    return pattern;
  },
  // source: http://stackoverflow.com/a/3561711
  escapeForRegex: function(string) {
    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  },
  getNames: function(arg, separator = '/') {
    var escapedSeparator, regex;
    if (arg instanceof RegExp) {
      return [];
    }
    escapedSeparator = module.exports.escapeForRegex(separator);
    return regex = new RegExp(`((:?:[^${escapedSeparator}\(\)]+)|(?:[\*]))`, 'g');
  }
};
```

Response:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        unless value?
          continue
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'


Prompt:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        unless value?
          continue
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->

Response:
isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'


Response:
names = []
    results = regex.exec arg

    while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

  toRegexString: (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"


Prompt:
names = []
    results = regex.exec arg

    while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

Response:
toRegexString: (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"


Response:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        continue if value is undefined
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'

    names = []


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        continue if value is undefined
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'

    names = []
```

Response:
module.exports = {
  PatternPrototype: {
    match: function(url) {
      var bound, captured, i, j, len, match, name, value;
      match = this.regex.exec(url);
      if (match == null) {
        return null;
      }
      captured = match.slice(1);
      if (this.isRegex) {
        return captured;
      }
      bound = {};
      for (i = j = 0, len = captured.length; j < len; i = ++j) {
        value = captured[i];
        name = this.names[i];
        if (value === void 0) {
          continue;
        }
        if (name === '_') {
          if (bound._ == null) {
            bound._ = [];
          }
          bound._.push(value);
        } else {
          bound[name] = value;
        }
      }
      return bound;
    }
  },
  newPattern: function(arg, separator = '/') {
    var isRegex, pattern, regexString;
    isRegex = arg instanceof RegExp;
    if (!(('string' === typeof arg) || isRegex)) {
      throw new TypeError('argument must be a regex or a string');
    }
    [':', '*'].forEach(function(forbidden) {
      if (separator === forbidden) {
        throw new Error(`separator can't be ${forbidden}`);
      }
    });
    pattern = Object.create(module.exports.PatternPrototype);
    pattern.isRegex = isRegex;
    pattern.regex = isRegex ? arg : (regexString = module.exports.toRegexString(arg, separator), new RegExp(regexString));
    if (!isRegex) {
      pattern.names = module.exports.getNames(arg, separator);
    }
    return pattern;
  },
  // source: http://stackoverflow.com/a/3561711
  escapeForRegex: function(string) {
    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  },
  getNames: function(arg, separator = '/') {
    var escapedSeparator, names, regex;
    if (arg instanceof RegExp) {
      return [];
    }
    escapedSeparator = module.exports.escapeForRegex(separator);
    regex = new RegExp(`((:?:[^${escapedSeparator}\(\)]+)|(?:[\*]))`, 'g');
    return names = [];
  }
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
module.exports = {
  PatternPrototype: {
    match: function(url) {
      var bound, captured, i, j, len, match, name, value;
      match = this.regex.exec(url);
      if (match == null) {
        return null;
      }
      captured = match.slice(1);
      if (this.isRegex) {
        return captured;
      }
      bound = {};
      for (i = j = 0, len = captured.length; j < len; i = ++j) {
        value = captured[i];
        name = this.names[i];
        if (value === void 0) {
          continue;
        }
        if (name === '_') {
          if (bound._ == null) {
            bound._ = [];
          }
          bound._.push(value);
        } else {
          bound[name] = value;
        }
      }
      return bound;
    }
  },
  newPattern: function(arg, separator = '/') {
    var isRegex, pattern, regexString;
    isRegex = arg instanceof RegExp;
    if (!(('string' === typeof arg) || isRegex)) {
      throw new TypeError('argument must be a regex or a string');
    }
    [':', '*'].forEach(function(forbidden) {
      if (separator === forbidden) {
        throw new Error(`separator can't be ${forbidden}`);
      }
    });
    pattern = Object.create(module.exports.PatternPrototype);
    pattern.isRegex = isRegex;
    pattern.regex = isRegex ? arg : (regexString = module.exports.toRegexString(arg, separator), new RegExp(regexString));
    if (!isRegex) {
      pattern.names = module.exports.getNames(arg, separator);
    }
    return pattern;
  },
  // source: http://stackoverflow.com/a/3561711
  escapeForRegex: function(string) {
    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  },
  getNames: function(arg, separator = '/') {
    var escapedSeparator, names, regex;
    if (arg instanceof RegExp) {
      return [];
    }
    escapedSeparator = module.exports.escapeForRegex(separator);
    regex = new RegExp(`((:?:[^${escapedSeparator}\(\)]+)|(?:[\*]))`, 'g');
    return names = [];
  }
};
```

Response:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        continue if value is undefined
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'

    names = []


Prompt:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        continue if value is undefined
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex

Response:
throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}\(\)]+)|(?:[\*]))", 'g'

    names = []


Response:
results = regex.exec arg

    while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

  toRegexString: (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"


Prompt:
results = regex.exec arg

    while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

  toRegexString: (string, separator = '/') ->

Response:
# escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    stringWithEscapedSeparators = stringWithEscapedSeparators
      # replace optional param
      .replace(/\((.*?)\)/g, '(?:$1)?')
      # replace wildcard patterns
      .replace(/\*/g, '(.*?)')

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    return "^#{stringWithEscapedSeparators}$"


Response:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}]+)|(?:[\*]))", 'g'

    names = []
    results = regex.exec arg


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}]+)|(?:[\*]))", 'g'

    names = []
    results = regex.exec arg
```

Response:
module.exports = {
  PatternPrototype: {
    match: function(url) {
      var bound, captured, i, j, len, match, name, value;
      match = this.regex.exec(url);
      if (match == null) {
        return null;
      }
      captured = match.slice(1);
      if (this.isRegex) {
        return captured;
      }
      bound = {};
      for (i = j = 0, len = captured.length; j < len; i = ++j) {
        value = captured[i];
        name = this.names[i];
        if (name === '_') {
          if (bound._ == null) {
            bound._ = [];
          }
          bound._.push(value);
        } else {
          bound[name] = value;
        }
      }
      return bound;
    }
  },
  newPattern: function(arg, separator = '/') {
    var isRegex, pattern, regexString;
    isRegex = arg instanceof RegExp;
    if (!(('string' === typeof arg) || isRegex)) {
      throw new TypeError('argument must be a regex or a string');
    }
    [':', '*'].forEach(function(forbidden) {
      if (separator === forbidden) {
        throw new Error(`separator can't be ${forbidden}`);
      }
    });
    pattern = Object.create(module.exports.PatternPrototype);
    pattern.isRegex = isRegex;
    pattern.regex = isRegex ? arg : (regexString = module.exports.toRegexString(arg, separator), new RegExp(regexString));
    if (!isRegex) {
      pattern.names = module.exports.getNames(arg, separator);
    }
    return pattern;
  },
  // source: http://stackoverflow.com/a/3561711
  escapeForRegex: function(string) {
    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  },
  getNames: function(arg, separator = '/') {
    var escapedSeparator, names, regex, results;
    if (arg instanceof RegExp) {
      return [];
    }
    escapedSeparator = module.exports.escapeForRegex(separator);
    regex = new RegExp(`((:?:[^${escapedSeparator}]+)|(?:[\*]))`, 'g');
    names = [];
    return results = regex.exec(arg);
  }
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
module.exports = {
  PatternPrototype: {
    match: function(url) {
      var bound, captured, i, j, len, match, name, value;
      match = this.regex.exec(url);
      if (match == null) {
        return null;
      }
      captured = match.slice(1);
      if (this.isRegex) {
        return captured;
      }
      bound = {};
      for (i = j = 0, len = captured.length; j < len; i = ++j) {
        value = captured[i];
        name = this.names[i];
        if (name === '_') {
          if (bound._ == null) {
            bound._ = [];
          }
          bound._.push(value);
        } else {
          bound[name] = value;
        }
      }
      return bound;
    }
  },
  newPattern: function(arg, separator = '/') {
    var isRegex, pattern, regexString;
    isRegex = arg instanceof RegExp;
    if (!(('string' === typeof arg) || isRegex)) {
      throw new TypeError('argument must be a regex or a string');
    }
    [':', '*'].forEach(function(forbidden) {
      if (separator === forbidden) {
        throw new Error(`separator can't be ${forbidden}`);
      }
    });
    pattern = Object.create(module.exports.PatternPrototype);
    pattern.isRegex = isRegex;
    pattern.regex = isRegex ? arg : (regexString = module.exports.toRegexString(arg, separator), new RegExp(regexString));
    if (!isRegex) {
      pattern.names = module.exports.getNames(arg, separator);
    }
    return pattern;
  },
  // source: http://stackoverflow.com/a/3561711
  escapeForRegex: function(string) {
    return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  },
  getNames: function(arg, separator = '/') {
    var escapedSeparator, names, regex, results;
    if (arg instanceof RegExp) {
      return [];
    }
    escapedSeparator = module.exports.escapeForRegex(separator);
    regex = new RegExp(`((:?:[^${escapedSeparator}]+)|(?:[\*]))`, 'g');
    names = [];
    return results = regex.exec(arg);
  }
};
```

Response:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'
    [':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}]+)|(?:[\*]))", 'g'

    names = []
    results = regex.exec arg


Prompt:
module.exports =

  PatternPrototype:
    match: (url) ->
      match = this.regex.exec url
      return null unless match?

      captured = match.slice(1)
      return captured if this.isRegex

      bound = {}
      for value, i in captured
        name = this.names[i]
        if name is '_'
          bound._ ?= []
          bound._.push value
        else
          bound[name] = value

      return bound

  newPattern: (arg, separator = '/') ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
      throw new TypeError 'argument must be a regex or a string'

Response:
[':', '*'].forEach (forbidden) ->
      if separator is forbidden
        throw new Error "separator can't be #{forbidden}"
    pattern = Object.create module.exports.PatternPrototype
    pattern.isRegex = isRegex
    pattern.regex =
      if isRegex
        arg
      else
        regexString = module.exports.toRegexString arg, separator
        new RegExp regexString
    pattern.names = module.exports.getNames arg, separator unless isRegex
    return pattern

  # source: http://stackoverflow.com/a/3561711
  escapeForRegex: (string) ->
    string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')

  getNames: (arg, separator = '/') ->
    return [] if arg instanceof RegExp
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp "((:?:[^#{escapedSeparator}]+)|(?:[\*]))", 'g'

    names = []
    results = regex.exec arg


Response:
while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

  toRegexString: (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    # finally replace wildcard patterns
    '^'  + stringWithEscapedSeparators.replace(/\*/g, '(.*)') + '$'


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

  toRegexString: (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    # finally replace wildcard patterns
    '^'  + stringWithEscapedSeparators.replace(/\*/g, '(.*)') + '$'
```

Response:
var name, results,
  indexOf = [].indexOf;

while (results != null) {
  name = results[1].slice(1);
  if (name === '_') {
    throw new TypeError(`:_ can't be used as a pattern name in pattern ${arg}`);
  }
  if (indexOf.call(names, name) >= 0) {
    throw new TypeError(`duplicate pattern name :${name} in pattern ${arg}`);
  }
  names.push(name || '_');
  results = regex.exec(arg);
}

names;

({
  escapeSeparators: function(string, separator = '/') {
    var escapedSeparator, regex;
    escapedSeparator = module.exports.escapeForRegex(separator);
    regex = new RegExp(escapedSeparator, 'g');
    return string.replace(regex, escapedSeparator);
  },
  toRegexString: function(string, separator = '/') {
    var escapedSeparator, stringWithEscapedSeparators;
    // escape the seperators in the pattern string such that
    // regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators(string, separator);
    // replace named segment pattern strings (:pattern) with
    // regexes that capture and match everything until the \\ char (in case the
    // separator was escaped) or the separator char (in case the separator
    // didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex(separator);
    module.exports.getNames(string, separator).forEach(function(name) {
      return stringWithEscapedSeparators = stringWithEscapedSeparators.replace(':' + name, `([^\\${separator}]+)`);
    });
    // finally replace wildcard patterns
    return '^' + stringWithEscapedSeparators.replace(/\*/g, '(.*)') + '$';
  }
});


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
var name, results,
  indexOf = [].indexOf;

while (results != null) {
  name = results[1].slice(1);
  if (name === '_') {
    throw new TypeError(`:_ can't be used as a pattern name in pattern ${arg}`);
  }
  if (indexOf.call(names, name) >= 0) {
    throw new TypeError(`duplicate pattern name :${name} in pattern ${arg}`);
  }
  names.push(name || '_');
  results = regex.exec(arg);
}

names;

({
  escapeSeparators: function(string, separator = '/') {
    var escapedSeparator, regex;
    escapedSeparator = module.exports.escapeForRegex(separator);
    regex = new RegExp(escapedSeparator, 'g');
    return string.replace(regex, escapedSeparator);
  },
  toRegexString: function(string, separator = '/') {
    var escapedSeparator, stringWithEscapedSeparators;
    // escape the seperators in the pattern string such that
    // regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators(string, separator);
    // replace named segment pattern strings (:pattern) with
    // regexes that capture and match everything until the \\ char (in case the
    // separator was escaped) or the separator char (in case the separator
    // didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex(separator);
    module.exports.getNames(string, separator).forEach(function(name) {
      return stringWithEscapedSeparators = stringWithEscapedSeparators.replace(':' + name, `([^\\${separator}]+)`);
    });
    // finally replace wildcard patterns
    return '^' + stringWithEscapedSeparators.replace(/\*/g, '(.*)') + '$';
  }
});
```

Response:
while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

  toRegexString: (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    # finally replace wildcard patterns
    '^'  + stringWithEscapedSeparators.replace(/\*/g, '(.*)') + '$'


Prompt:
while results?
      name = results[1].slice(1)

      if name is '_'
        throw new TypeError(":_ can't be used as a pattern name in pattern #{arg}")

      if name in names
        throw new TypeError("duplicate pattern name :#{name} in pattern #{arg}")

      names.push name || '_'
      results = regex.exec arg
    names

  escapeSeparators: (string, separator = '/') ->
    escapedSeparator = module.exports.escapeForRegex separator
    regex = new RegExp escapedSeparator, 'g'
    string.replace regex, escapedSeparator

Response:
toRegexString: (string, separator = '/') ->
    # escape the seperators in the pattern string such that
    # regex command chars (., ^, $, ...) can be used as separators
    stringWithEscapedSeparators = module.exports.escapeSeparators string, separator

    # replace named segment pattern strings (:pattern) with
    # regexes that capture and match everything until the \\ char (in case the
    # separator was escaped) or the separator char (in case the separator
    # didn't need escaping)
    escapedSeparator = module.exports.escapeForRegex separator
    module.exports.getNames(string, separator).forEach (name) ->
      stringWithEscapedSeparators = stringWithEscapedSeparators
        .replace(':' + name,"([^\\#{separator}]+)")

    # finally replace wildcard patterns
    '^'  + stringWithEscapedSeparators.replace(/\*/g, '(.*)') + '$'


Response:
util = require './util'

patternPrototype =
  match: (url) ->
    match = this.regex.exec url
    return null unless match?

    captured = match.slice(1)
    return captured if this.isRegex

    bound = {}
    for value, i in captured
      name = this.names[i]
      if name is '_'
        bound._ ?= []
        bound._.push value
      else
        bound[name] = value

    return bound

module.exports = (arg, separator = '/') ->
  isRegex = arg instanceof RegExp
  unless ('string' is typeof arg) or isRegex
    throw new TypeError 'argument must be a regex or a string'
  pattern = Object.create patternPrototype
  pattern.isRegex = isRegex
  pattern.regex = if isRegex then arg else new RegExp util.toRegexString arg
  pattern.names = util.getNames arg unless isRegex
  return pattern


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
util = require './util'

patternPrototype =
  match: (url) ->
    match = this.regex.exec url
    return null unless match?

    captured = match.slice(1)
    return captured if this.isRegex

    bound = {}
    for value, i in captured
      name = this.names[i]
      if name is '_'
        bound._ ?= []
        bound._.push value
      else
        bound[name] = value

    return bound

module.exports = (arg, separator = '/') ->
  isRegex = arg instanceof RegExp
  unless ('string' is typeof arg) or isRegex
    throw new TypeError 'argument must be a regex or a string'
  pattern = Object.create patternPrototype
  pattern.isRegex = isRegex
  pattern.regex = if isRegex then arg else new RegExp util.toRegexString arg
  pattern.names = util.getNames arg unless isRegex
  return pattern
```

Response:
var patternPrototype, util;

util = require('./util');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        if (bound._ == null) {
          bound._ = [];
        }
        bound._.push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg, separator = '/') {
  var isRegex, pattern;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  pattern = Object.create(patternPrototype);
  pattern.isRegex = isRegex;
  pattern.regex = isRegex ? arg : new RegExp(util.toRegexString(arg));
  if (!isRegex) {
    pattern.names = util.getNames(arg);
  }
  return pattern;
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
var patternPrototype, util;

util = require('./util');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        if (bound._ == null) {
          bound._ = [];
        }
        bound._.push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg, separator = '/') {
  var isRegex, pattern;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  pattern = Object.create(patternPrototype);
  pattern.isRegex = isRegex;
  pattern.regex = isRegex ? arg : new RegExp(util.toRegexString(arg));
  if (!isRegex) {
    pattern.names = util.getNames(arg);
  }
  return pattern;
};
```

Response:
util = require './util'

patternPrototype =
  match: (url) ->
    match = this.regex.exec url
    return null unless match?

    captured = match.slice(1)
    return captured if this.isRegex

    bound = {}
    for value, i in captured
      name = this.names[i]
      if name is '_'
        bound._ ?= []
        bound._.push value
      else
        bound[name] = value

    return bound

module.exports = (arg, separator = '/') ->
  isRegex = arg instanceof RegExp
  unless ('string' is typeof arg) or isRegex
    throw new TypeError 'argument must be a regex or a string'
  pattern = Object.create patternPrototype
  pattern.isRegex = isRegex
  pattern.regex = if isRegex then arg else new RegExp util.toRegexString arg
  pattern.names = util.getNames arg unless isRegex
  return pattern


Prompt:
util = require './util'

patternPrototype =
  match: (url) ->
    match = this.regex.exec url
    return null unless match?

    captured = match.slice(1)
    return captured if this.isRegex

    bound = {}
    for value, i in captured
      name = this.names[i]
      if name is '_'
        bound._ ?= []

Response:
bound._.push value
      else
        bound[name] = value

    return bound

module.exports = (arg, separator = '/') ->
  isRegex = arg instanceof RegExp
  unless ('string' is typeof arg) or isRegex
    throw new TypeError 'argument must be a regex or a string'
  pattern = Object.create patternPrototype
  pattern.isRegex = isRegex
  pattern.regex = if isRegex then arg else new RegExp util.toRegexString arg
  pattern.names = util.getNames arg unless isRegex
  return pattern


Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name is '_'
            bound._ ?= []
            bound._.push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name is '_'
            bound._ ?= []
            bound._.push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p
```

Response:
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        if (bound._ == null) {
          bound._ = [];
        }
        bound._.push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        if (bound._ == null) {
          bound._ = [];
        }
        bound._.push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};
```

Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name is '_'
            bound._ ?= []
            bound._.push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name is '_'
            bound._ ?= []

Response:
bound._.push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name == '_'
            bound[name] = bound[name] || []
            bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name == '_'
            bound[name] = bound[name] || []
            bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p
```

Response:
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        bound[name] = bound[name] || [];
        bound[name].push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        bound[name] = bound[name] || [];
        bound[name].push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};
```

Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name == '_'
            bound[name] = bound[name] || []
            bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
common = require './common'

patternPrototype =
    match: (url) ->
        match = this.regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if this.isRegex

        bound = {}
        for value, i in captured
          name = this.names[i]
          if name == '_'
            bound[name] = bound[name] || []

Response:
bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}
        for value, i in captured
          name = @names[i]
          if name == '_'
            bound[name] = bound[name] || []
            bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}
        for value, i in captured
          name = @names[i]
          if name == '_'
            bound[name] = bound[name] || []
            bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p
```

Response:
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        bound[name] = bound[name] || [];
        bound[name].push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, len, match, name, value;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, len = captured.length; j < len; i = ++j) {
      value = captured[i];
      name = this.names[i];
      if (name === '_') {
        bound[name] = bound[name] || [];
        bound[name].push(value);
      } else {
        bound[name] = value;
      }
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};
```

Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}
        for value, i in captured
          name = @names[i]
          if name == '_'
            bound[name] = bound[name] || []
            bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}
        for value, i in captured
          name = @names[i]
          if name == '_'
            bound[name] = bound[name] || []

Response:
bound[name].push value
          else
            bound[name] = value

        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}
        bound[@names[i]] = captured[i] for i in [0...captured.length]
        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
Convert this CoffeeScript to JavaScript.
```coffeescript
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}
        bound[@names[i]] = captured[i] for i in [0...captured.length]
        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p
```

Response:
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, match, ref;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, ref = captured.length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
      bound[this.names[i]] = captured[i];
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};


Prompt:
Convert this JavaScript to CoffeeScript.
```javascript
var common, patternPrototype;

common = require('./common');

patternPrototype = {
  match: function(url) {
    var bound, captured, i, j, match, ref;
    match = this.regex.exec(url);
    if (match == null) {
      return null;
    }
    captured = match.slice(1);
    if (this.isRegex) {
      return captured;
    }
    bound = {};
    for (i = j = 0, ref = captured.length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
      bound[this.names[i]] = captured[i];
    }
    return bound;
  }
};

module.exports = function(arg) {
  var isRegex, p;
  isRegex = arg instanceof RegExp;
  if (!(('string' === typeof arg) || isRegex)) {
    throw new TypeError('argument must be a regex or a string');
  }
  p = Object.create(patternPrototype);
  p.isRegex = isRegex;
  p.regex = isRegex ? arg : new RegExp(common.toRegexString(arg));
  if (!isRegex) {
    p.names = common.getNames(arg);
  }
  return p;
};
```

Response:
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}
        bound[@names[i]] = captured[i] for i in [0...captured.length]
        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Prompt:
common = require './common'

patternPrototype =
    match: (url) ->
        match = @regex.exec url
        return null unless match?

        captured = match.slice(1)
        return captured if @isRegex

        bound = {}

Response:
bound[@names[i]] = captured[i] for i in [0...captured.length]
        bound

module.exports = (arg) ->
    isRegex = arg instanceof RegExp
    unless ('string' is typeof arg) or isRegex
        throw new TypeError 'argument must be a regex or a string'
    p = Object.create patternPrototype
    p.isRegex = isRegex
    p.regex = if isRegex then arg else new RegExp common.toRegexString arg
    p.names = common.getNames arg unless isRegex
    p


Response:
path = require('path')
fs = require('fs')

suite 'Tests specific to issues:', ->
  test 'Issue #239: Not possible to build a list of non-unique elements non-contiguously with JSON', ->

    obj = root:
      '#text1': [
        { node: 'value1' }
        { node: 'value2' }
      ]
      '#comment': 'comment node'
      '#text2': [
        { node: 'value3' }
        { node: 'value4' }
      ]

    doc = xml(obj, { headless: true })

    eq(
      doc.end({ pretty: true })
      """
      <root>
        <node>value1</node>
        <node>value2</node>
        <!-- comment node -->
        <node>value3</node>
        <node>value4</node>
      </root>
      """
    )