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

[JavaScript] Fix regression with ternary operators #4025

Merged

Conversation

deathaxe
Copy link
Collaborator

@deathaxe deathaxe commented Aug 5, 2024

This PR fixes a regression, introduced by #3986, which breaks syntax highlighting in objects, as comma is no longer consumed as key-value-pair separator.

It's not the ternary expression, which allows commas, but the for statement, which allows multiple expressions, separated by comma after in keyword.

for (var in <expr>, <expr>, ...)

expr: any valid expression, maybe ternary, maybe function-call

The change to ternary expressions is reverted and for-condition context is modified instead to allow multiple expressions after in keyword.

Also scope ; invalid if there are too many.

This commit fixes a regression, introduced by sublimehq#3986, which breaks syntax
highlighting in objects, as comma is no longer consumed as key-value-pair
separator.

It's not the ternary expression, which allows commas, but the for statement,
which allows multiple expressions, separated by comma after `in` keyword.

    for (var in <expr>, <expr>, ...)

    expr: any valid expression, maybe ternary, maybe function-call

The change to ternary expressions is reverted and for-condition context is
modified instead to allow multiple expressions after `in` keyword.

Also scope `;` invalid if there are too many.
This commit...

1. adds a `pop: 1` to the pattern of `for-condition` to make sure at most
   one opening parenthesis after for is consumed as loop condition.

   The following may have happened before.

       for (...) (...)

2. Tweaks how `meta.group` is applied as it sometimes makes a difference,
   whether a scope is a `meta_scope` or not, especially related with
   `clear_scopes` keyword.
@deathaxe deathaxe merged commit 214c07c into sublimehq:master Aug 6, 2024
1 check passed
@deathaxe deathaxe deleted the pr/javascript/fix-ternary-operator-2 branch August 6, 2024 08:17
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.

3 participants