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

Brace block improvements, including & statements #1179

Merged
merged 4 commits into from
Apr 22, 2024
Merged

Brace block improvements, including & statements #1179

merged 4 commits into from
Apr 22, 2024

Conversation

edemaine
Copy link
Collaborator

Fixes #1176

I unified a place where we were manually bracing a block into a call to braceBlock. But they differed in the closing brace: the new use ended with } while other instances ended with }. I'm somewhat tempted to switch to the spaced version throughout, which would lead to changes like this:

switch x
  {a: y, b: y}
    y
↓↓↓
   if(typeof x === 'object' && x != null && 'a' in x && 'b' in x) {
     const {a: y1, b: y2} = x;
     const y = [y1, y2];
-    y }
+    y}

But this would involve changing ~70 tests. Do you think it's worth it?

Copy link
Contributor

@STRd6 STRd6 left a comment

Choose a reason for hiding this comment

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

Looks good!

As for the space before the closing brace I've actually been leaning towards not inserting any spaces/newlines to keep the generated code as close as possible to the original source. There are fewer $loc tokens to keep track of and it usually doesn't look too bad visually since it is closer to the original.

@edemaine
Copy link
Collaborator Author

Good point; makes sense. I looked at unifying braceBlock in the other direction and I get only two failing tests:

-(x): void => { console.log(x)}
+(x): void => { console.log(x) }

-const ignore = <T, U>(a: T, b: U) : void => { null}
+const ignore = <T, U>(a: T, b: U) : void => { null }

It's just a bit uglier that I hesitate to do it... but it would simplify the code slightly (no second argument to braceBlock). I guess I'll go for it.

@edemaine edemaine merged commit 2ca3fa0 into main Apr 22, 2024
2 checks passed
@edemaine edemaine deleted the brace-block branch April 22, 2024 19:33
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.

& doesn't always work in if statement
2 participants