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

Fix continuing first line of explicit [/{ literal #5397

Merged
merged 6 commits into from
Jan 26, 2022

Conversation

edemaine
Copy link
Contributor

This PR makes two changes to fix continuing a nonempty first line of an explicit [ array or { object literal:

  1. Do not allow implicit call with an implicit object body from first line of [ array or { object literal (as hinted at in comments, but not previously implemented), as in:

    [x
     y: 2
    ]
    {x
     y: 2
    }

    Previously, these were treated as function calls where x is a function.

  2. Support continuing an explicit { object literal when the first line has an item on it, as in:

    {x: 1
     y: 2
    }

    Previously, this was treated as {x: 1, {y: 2}} which was invalid.

Fixes #5368

* Do not allow implicit call from first line of `[` array or `{` object
  literal (as hinted at in comments).
* Support continuing an explicit `{` object literal when the first line
  has an item on it.

Fixes jashkenas#5368
@edemaine
Copy link
Contributor Author

FYI, I tried extending this to handle #5330 also, but that seems substantially harder. 😕

@@ -183,6 +183,7 @@ exports.Rewriter = class Rewriter
[prevTag] = prevToken = if i > 0 then tokens[i - 1] else []
[nextTag] = nextToken = if i < tokens.length - 1 then tokens[i + 1] else []
stackTop = -> stack[stack.length - 1]
stackTop2 = -> stack[stack.length - 2]
Copy link
Collaborator

Choose a reason for hiding this comment

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

A name like stackTop2 implies to me that it’s returning two elements, not that it’s referring to the second highest item in the stack. Maybe stackSecond?

Or maybe do without the helper function? It’s only called in one place, we could just put stack[stack.length - 2] there.

@GeoffreyBooth GeoffreyBooth merged commit 3d39d20 into jashkenas:main Jan 26, 2022
@edemaine
Copy link
Contributor Author

Thanks @GeoffreyBooth for the review!

@GeoffreyBooth GeoffreyBooth mentioned this pull request Apr 19, 2022
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.

Bug: Destructuring Assignment edge case error
2 participants