Skip to content

Conversation

@rbuckton
Copy link
Contributor

@rbuckton rbuckton commented Apr 9, 2015

Fixes #2678, adds some additional tests to the isParenthesizedArrowFunctionExpressionWorker lookahead to allow for array and object patterns in the first parameter of a parenthesized arrow function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a --target=es6 test as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather, take all of these tests and duplicate them as ES6 tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already done.

@JsonFreeman
Copy link
Contributor

👍

@rbuckton
Copy link
Contributor Author

I simplified the look-ahead to go no more than 3 tokens to find some cases where we can shortcut out with Tristate.False.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thse seem so rare as to not need special handling. I would just do: if (second === OpenBracket || second === OpenBrace) ... return TriState.Unknown

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I picture arrow functions and destructuring parameters to not be very common in conjunction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picture arrow functions and destructuring parameters to not be very common in conjunction.

I tried writing one 2 days ago for the record.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing it often in conjunction with Promise.all:

Promise.all([a, b, c]).then(([a, b, c]) => {
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But won't your new code return ' unknown' on this case? I'm curious what cases were Will see that are common where we'll be able to effectively bail out early with this code b

-- Cyrus

From: Ron Bucktonmailto:notifications@github.com
Sent: ‎4/‎10/‎2015 9:20 AM
To: Microsoft/TypeScriptmailto:TypeScript@noreply.github.com
Cc: Cyrus Najmabadimailto:cyrusn@microsoft.com
Subject: Re: [TypeScript] Add support for parsing binding patterns in arrow function parameters (#2680)

In src/compiler/parser.tshttps://github.com//pull/2680#discussion_r28158593:

@@ -3221,6 +3221,37 @@ module ts {
}
}

  •            // If encounter "([", this could be the start of an array binding pattern.
    
  •            // Examples:
    
  •            //      ([ x ]) => { }
    
  •            //      ([ x ])
    
  •            if (second === SyntaxKind.OpenBracketToken) {
    

I'm seeing it often in conjunction with Promise.all:

Promise.all([a, b, c]).then(([a, b, c]) => {
});


Reply to this email directly or view it on GitHubhttps://github.com//pull/2680/files#r28158593.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and just made OpenBrace/OpenBracket return Tristate.Unknown. The tryParse will already be able to detect this after reading two tokens, so its not much of an added cost to be worth it.

rbuckton added a commit that referenced this pull request Apr 10, 2015
Add support for parsing binding patterns in arrow function parameters
@rbuckton rbuckton merged commit 6121730 into master Apr 10, 2015
@rbuckton rbuckton deleted the fixArrowBindingPattern branch April 10, 2015 18:38
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array and Object Binding Patterns are not supported in parenthesized arrow functions.

7 participants