-
Notifications
You must be signed in to change notification settings - Fork 27k
feat(compiler): Add support for multiple conditions for cases in switch control flow #58600
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
Conversation
…ch control flow Currently, the @switch/@case syntax is fairly limited, as cases may only have one guard. This often requires to either copy paste the body of the case-block or to refactor code to use @if / @else if syntax instead. This adds support for the highly requested feature of being able to define multiple guards to a single @case using the syntax @case(a; b; c)
c66b7d4 to
7954fb8
Compare
|
Also, I tried to implement the following syntax: But that was just way too difficult to do, as the BlockStart structure just wasn't flexible enough to allow for it easily. Nonetheless, I'll give it a try if it's preferred. |
|
I see at least 2 types of tests that we would need to add.
|
josephperrott
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reviewed-for: dev-infra
Add test
|
Took me a while to understand how the compiler tests work, but I did add a compliance test. I couldn't really think of anything that isn't already covered with other tests, but please hint me in the right direction if you think there need to be more tests. That said, when it comes to runtime tests, I tried to find examples where you cited them, but I couldn't find any control flow related tests there. |
|
Also on a side note, I'm pretty impressed that the minimizer can optimise ternary expressions so well, The I think one step could be to actually generate switch/case expressions, but that - again :( - seems to be a whole different beast for me. |
|
I just noticed that this PR got marked as draft. I assume it's because of the merge conflicts with I know that this PR was not solicitted by the Angular team, so I'm not sure if there's any chance this PR gets accepted if I update the PR to be compatible with the current |
|
@wartab We went through and marked all old PRs that haven't moved to draft. If you'd like to see this move forward though, please update and get it to a fresh reviewable state and we'll revisit. |
|
Given this isn't a trivial change, I'd just like to know if spending time on this even makes sense. I want this feature to be added, I want to help to make it happen, but for that I'd also like to know if there's a chance this will be accepted if I re-implement the feature and the tests. I say this because I didn't get a response to my question regarding tests and so the PR just ended up being in conflict over time. |
|
@wartab There was a conversation about this and the answer was that we do want this feature, but I think there were concerns about this implementation. So with that, it's probably best to close this for now. I know @alxhub has more thoughts here and I'll leave it to him to provide his thoughts. Thank you though! It's a great feature and we appreciate you for your effort. |
|
@thePunderWoman Thank you for your honesty. Just fyi, when you changed the PRs to drafts, I didn't get a notification, so people might miss that it happened. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Currently, the @switch/@case syntax is fairly limited, as cases may only have one guard. This often requires to either copy paste the body of the case-block or to refactor code to use @if / @else if syntax instead. This adds support for the highly requested feature of being able to define multiple guards to a single @case using the syntax @case(a; b; c)
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
You can't have multiple conditions in a single case block.
Issue Number: #14659
What is the new behavior?
Now you can
Does this PR introduce a breaking change?
Other information
I'm not certain if other tests are needed.
I made a few tests building this locally and this all works:
This does accurately not compile: