@@ -3221,30 +3221,44 @@ module ts {
32213221 }
32223222 }
32233223
3224- // If we had "(" followed by "{" or "[", this could be the start of a binding pattern.
3225- let possiblyInArrayBindingPattern = false ;
3226- let possiblyInObjectBindingPattern = false ;
3227- while ( second === SyntaxKind . OpenBraceToken || second === SyntaxKind . OpenBracketToken ) {
3228- possiblyInObjectBindingPattern = second === SyntaxKind . OpenBraceToken ;
3229- possiblyInArrayBindingPattern = second === SyntaxKind . OpenBracketToken ;
3230- second = nextToken ( ) ;
3224+ // If encounter "([", this could be the start of an array binding pattern.
3225+ // Examples:
3226+ // ([ x ]) => { }
3227+ // ([ x ])
3228+ if ( second === SyntaxKind . OpenBracketToken ) {
3229+ // If the next token is not ",", "...", "[", "{", or an identifier, then this could either be
3230+ // an arrow function with an array binding pattern or a parenthesized array literal expression.
3231+ // Otherwise, it cannot be an array binding pattern.
3232+ let third = nextToken ( ) ;
3233+ if ( isIdentifierOrPattern ( ) || third === SyntaxKind . CommaToken || third === SyntaxKind . DotDotDotToken ) {
3234+ return Tristate . Unknown ;
3235+ }
3236+
3237+ return Tristate . False ;
32313238 }
32323239
3233- if ( possiblyInArrayBindingPattern ) {
3234- // If we are possibly in an array binding pattern, skip empty elements
3235- while ( second === SyntaxKind . CommaToken ) {
3236- second = nextToken ( ) ;
3240+ // If we encounter "({", this could be the start of an object binding pattern.
3241+ // Examples:
3242+ // ({ x }) => { }
3243+ // ({ x })
3244+ // ({ *x() { })
3245+ if ( second === SyntaxKind . OpenBraceToken ) {
3246+ // If we encountered an asterisk, then this is a generator method on an
3247+ // object literal and cannot be a binding pattern.
3248+ if ( nextToken ( ) === SyntaxKind . AsteriskToken ) {
3249+ return Tristate . False ;
32373250 }
3251+
3252+ return Tristate . Unknown ;
32383253 }
32393254
3240- // Simple case: "(..." or "([...", but not "({..."
3255+ // Simple case: "(..."
32413256 // This is an arrow function with a rest parameter.
3242- if ( second === SyntaxKind . DotDotDotToken && ! possiblyInObjectBindingPattern ) {
3243- // if we are possibly in an array binding pattern, then this may be a lambda, otherwise it must be a lambda.
3244- return possiblyInArrayBindingPattern ? Tristate . Unknown : Tristate . True ;
3257+ if ( second === SyntaxKind . DotDotDotToken ) {
3258+ return Tristate . True ;
32453259 }
32463260
3247- // If we had "(" followed by something that's not an identifier,
3261+ // If we had something like "(" followed by something that's not an identifier,
32483262 // then this definitely doesn't look like a lambda.
32493263 // Note: we could be a little more lenient and allow
32503264 // "(public" or "(private". These would not ever actually be allowed,
@@ -3253,9 +3267,9 @@ module ts {
32533267 return Tristate . False ;
32543268 }
32553269
3256- // If we have something like "(a:", but not "({ a:", then we must have a
3270+ // If we have something like "(a:", then we may have a
32573271 // type-annotated parameter in an arrow function expression.
3258- if ( nextToken ( ) === SyntaxKind . ColonToken && ! possiblyInObjectBindingPattern ) {
3272+ if ( nextToken ( ) === SyntaxKind . ColonToken ) {
32593273 return Tristate . True ;
32603274 }
32613275
0 commit comments