Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow linebreak/indent in destructured for variable #5286

Merged
merged 4 commits into from Jan 1, 2020

Conversation

helixbass
Copy link
Collaborator

@GeoffreyBooth I ran into this when running the Prettier plugin against the Coffeescript codebase:

Things like this (with linebreaks inside the destructured variable of a for loop) currently aren't parsing:

for {
  something,
  somethingElse
}, y in z
  d

The grammar is already set up to accept this, it was just an issue of extending the logic for tagging tokens as eg FORIN

@@ -514,7 +514,7 @@ exports.Lexer = class Lexer

prev = @prev()
backslash = prev?[0] is '\\'
@seenFor = no unless backslash and @seenFor
@seenFor = no unless (backslash or @seenFor?.endsLength < @ends.length) and @seenFor
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was existing logic to "continue the for line" in the case of a backslash line continuer, so just extended that logic to additionally continue the for line (ie preserve @seenFor) if the linebreak is occurring inside a pair of delimiters ie {/} or [/] (as indicated by something having been pushed onto @ends since we saw the FOR token)

@GeoffreyBooth GeoffreyBooth merged commit ba41b44 into jashkenas:master Jan 1, 2020
@helixbass helixbass deleted the for-pattern-linebreak branch January 1, 2020 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants