Skip to content

Nodes: Compile error when using destructuring with a splat or expansion in an array #4878

Description

@MattKunze
foo = (list) ->
  [ first, ..., last ] = list

results in TypeError: Cannot read property 'indexOf' of undefined

That’s the simplest case I could come up with. It’s pretty finicky though, if you reference the values after the destructuring statement it compiles:

foo = (list) ->
  [ first, ..., last ] = list
  [ first, last ]

However other more complex variations also fail, for instance having that statement inside conditional assignment:

foo = (list) ->
  ret =
    if list.length
      [ first, ..., last ] = list
      [ first, last ]
    else
      []

removing the ret = part of the last example compiles fine

Not a huge deal, it can be replaced with code that explicitly uses list.slice -1, it’s just we had some code that was compiling previously and stopped working with a minor update somewhere along the way

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions