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

Multiline signature destructuring #45

Closed
barneycarroll opened this issue Sep 21, 2017 · 6 comments
Closed

Multiline signature destructuring #45

barneycarroll opened this issue Sep 21, 2017 · 6 comments
Labels

Comments

@barneycarroll
Copy link

New lines seem to break signature syntax highlighting:

screen shot 2017-09-21 at 16 38 26

@bathos
Copy link
Owner

bathos commented Sep 21, 2017

This is one of those tricky spots that come from having no way to see beyond the current line at any given point, a limitation of SublimeText. At "({", there’s no way to tell if it’s an object literal, arguments with destructuring, or regular assignment destructuring. In this case it’s assumed object literal at the start and doesn’t recover nicely (even after the second line, it’d still be ambiguous, just less so).

I should be able to tweak this to avoid the "invalid" scope, but unfortunately it will never be possible to actually highlight the arguments as such in a case like this :(

@bathos bathos added the bug label Sep 21, 2017
@barneycarroll
Copy link
Author

That's interesting. So this is limited to arrows. There is (I think?) a problem case that can be addressed within this constraint whereby the first line contains a default assignment…

@bathos
Copy link
Owner

bathos commented Sep 21, 2017

That’s true, yep. There is some handling for similar cases already that tries to "recover", which is what we’ll need to introduce here. This one is complicated a bit extra because at that stage we can know it’s an object binding pattern, but not whether it’s function parameters or an assignment expression (not detectable until the fifth line).

@barneycarroll
Copy link
Author

Oh I see… So there's a dilemma of erring on the side of caution (we can't tell that this is valid code) and trusting the author (param assignment indicates a signature, we'll assume you know what you're doing until proven otherwise)… Because if it is an object literal, leaving the syntax error to the last line will be totally misleading 🤔

@bathos
Copy link
Owner

bathos commented Sep 21, 2017

Well, not quite that — I would say the current behavior is a bug / oversight. The = disambiguates the {} structure as a binding pattern, since it would only be valid there, and we can proceed as if that was what we thought it was all along from that point on with a bit of sneakiness (though there’s no way to go back and correct the scopes for stuff prior). But the = does not tell us it’s parameters; it could still ultimately be an assignment expression, and we don’t know until we see either = or =>:

({
  foo=bar
} = baz);

So even once we handle recovery here, foo will not be scoped as variable.parameter, it will be scoped as variable.other.readwrite.

@bathos bathos closed this as completed in 76f3a8b Dec 1, 2017
@bathos
Copy link
Owner

bathos commented Dec 1, 2017

@barneycarroll There’s now an escape route for recovering from ambiguity in this position. Although it will always get the first n lines scoped wrong, and it won’t know in a case like this that the binding pattern belongs to parameters, it now at least knows that if it sees an assignment, it should switch to interpreting the remainder as a binding pattern; and existing recovery logic already takes care of the arrow.

screen shot 2017-12-01 at 6 20 17 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants