Skip to content

Missing error for a destructuring pattern inside a rest binding element / rest parameter #2519

Closed

Description

The following is not allowed by the ES6 grammar:

function foo(...[a]) { }
var [...[b, c]] = [0, 1, 2];

The relevant grammar production is:

BindingRestElement[Yield, GeneratorParameter] :
    [+GeneratorParameter] ... BindingIdentifier[Yield]
    [~GeneratorParameter] ... BindingIdentifier[?Yield]

And a BindingIdentifier does not include a binding pattern.

Activity

  1. yuit commented on Apr 12, 2015

    @yuit
    Contributor

    Following code:

    function a(...{a, b}) { }
    function a1(...[a, b]) { }

    causes crash when compiling:

    D:\TS\built\local\tsc.js:26338
    emitDestructuring(p, false, tempParameters[tempIndex
    ^
    TypeError: Cannot read property '0' of undefined
    at D:\TS\built\local\tsc.js:26338:71
    at Object.forEach (D:\TS\built\local\tsc.js:693:30)
    at emitDefaultValueAssignments (D:\TS\built\local\tsc.js:26334:24)
    at emitFunctionBodyPreamble (D:\TS\built\local\tsc.js:26521:17)
    at emitBlockFunctionBody (D:\TS\built\local\tsc.js:26588:17)
    at emitSignatureAndBody (D:\TS\built\local\tsc.js:26506:21)
    at emitFunctionDeclaration (D:\TS\built\local\tsc.js:26450:17)
    at emitJavaScriptWorker (D:\TS\built\local\tsc.js:28256:32)
    at emitNodeWithoutSourceMap (D:\TS\built\local\tsc.js:28146:17)
    at emitLinesStartingAt (D:\TS\built\local\tsc.js:24527:21)

  2. added a commit that references this issue on Apr 14, 2015
    2d3b22c
  3. rauschma commented on Dec 28, 2015

    @rauschma

    ES7/ES2016 will allow this pattern: https://tc39.github.io/ecma262/#sec-destructuring-binding-patterns

    It was inconsistent with destructuring assignment that has always allowed it: http://www.ecma-international.org/ecma-262/6.0/#sec-destructuring-assignment

  4. DanielRosenwasser commented on Dec 28, 2015

    @DanielRosenwasser
    Member

    Thanks for the heads up Axel Rauschmayer (@rauschma)! I've filed #6275.

  5. locked and limited conversation to collaborators on Jun 18, 2018
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

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions