-
Notifications
You must be signed in to change notification settings - Fork 26.1k
fix(animations): handle structured AnimateTimings #31107
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(animations): handle structured AnimateTimings #31107
Conversation
@crisbeto Could you review this PR? It looks pretty small, but you're the most familiar with the animations package. |
It's been a while since I created this PR. :-) Please let me know if anything needs to be changed. |
One addition that would be welcome is if you could put together a unit test that demonstrated the bug and passes after this fix. |
I wonder if it would be better to just add the code from line 542-549 into an else block, so that it doesn't get run if the |
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.
Also as Pete mentioned, we should have a unit test for this.
@@ -533,6 +533,7 @@ function constructTimingAst(value: string | number | AnimateTimings, errors: any | |||
let timings: AnimateTimings|null = null; | |||
if (value.hasOwnProperty('duration')) { | |||
timings = value as AnimateTimings; | |||
return timings; |
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.
I would change the function to something like the following so it's easier to follow:
function constructTimingAst(value: string|number|AnimateTimings, errors: any[]) {
if (value.hasOwnProperty('duration')) {
return value as AnimateTimings;
}
if (typeof value == 'number') {
const duration = resolveTiming(value, errors).duration;
return makeTimingAst(duration, 0, '');
}
const strValue = value as string;
const isDynamic = strValue.split(/\s+/).some(v => v.charAt(0) == '{' && v.charAt(1) == '{');
if (isDynamic) {
const ast = makeTimingAst(0, 0, '') as any;
ast.dynamic = true;
ast.strValue = strValue;
return ast as DynamicTimingAst;
}
const timings = resolveTiming(strValue, errors);
return makeTimingAst(timings.duration, timings.delay, timings.easing);
}
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.
If I recall correctly I thought it would be better to fix the problem with the least amount of code possible when I initially created this PR. But I agree that your solution is much cleaner. I updated the PR accordingly.
@chrisguttandin If you have a chance to respond to the comments here, that'd be great. We'd love to land this. Thanks! |
@jessicajaniuk Sorry for the delay. I rebased the PR and applied the feedback but I did not yet add a test. I'm sure I'm missing something obvious but I can't find a guide on how to run the tests for the animations package locally. Is there a way to do this? |
@chrisguttandin It depends on where the test is exactly. You can try |
Thanks a lot @jessicajaniuk. I added a test case which resembles the example from the original issue #22752. I also rebased the branch again and resolved the conflicts. Please let me know if there is anything else that needs to be changed. |
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 🍪
Sorry for this taking so long to get approved!
@chrisguttandin Looks like there's been some linting changes since this PR last had CI run. If you can run the command in the lint CI failures to reformat the files, that would be wonderful. It's otherwise green ad can be landed as soon as you can push that. |
This commit makes sure structured AnimateTimings are not procesed any further when building the AST. Fixes: #22752
This commit adds a test for the buildAnimationAst() function.
This PR was merged into the repository by commit a3f344f. |
This commit adds a test for the buildAnimationAst() function. PR Close #31107
This commit adds a test for the buildAnimationAst() function. PR Close #31107
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@angular/animations](https://github.com/angular/angular) | dependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fanimations/13.3.1/13.3.2) | | [@angular/common](https://github.com/angular/angular) | dependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fcommon/13.3.1/13.3.2) | | [@angular/compiler](https://github.com/angular/angular) | dependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/13.3.1/13.3.2) | | [@angular/compiler-cli](https://github.com/angular/angular) | devDependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/13.3.1/13.3.2) | | [@angular/core](https://github.com/angular/angular) | dependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fcore/13.3.1/13.3.2) | | [@angular/forms](https://github.com/angular/angular) | dependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fforms/13.3.1/13.3.2) | | [@angular/platform-browser](https://github.com/angular/angular) | dependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/13.3.1/13.3.2) | | [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | patch | [`13.3.1` -> `13.3.2`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/13.3.1/13.3.2) | --- ### Release Notes <details> <summary>angular/angular</summary> ### [`v13.3.2`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#​1332-2022-04-06) [Compare Source](angular/angular@13.3.1...13.3.2) ##### animations | Commit | Type | Description | | -- | -- | -- | | [b46b25c562](angular/angular@b46b25c) | fix | handle structured AnimateTimings ([#​31107](angular/angular#31107)) | #### Special Thanks Alan Agius, Andrew Kushnir, Christoph Guttandin, Cédric Exbrayat, mgechev and piyush132000 <!-- CHANGELOG SPLIT MARKER --> </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: cabr2-bot <cabr2.help@gmail.com> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1285 Reviewed-by: crapStone <crapstone@noreply.codeberg.org> Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org> Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
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. |
Fixes: #22752
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?
Issue Number: 22752
What is the new behavior?
Due to the missing return statement structured AnimateTimings where tried to parse as if they were a string. Now the function returns early if there is no need to parse the input.
Does this PR introduce a breaking change?
Other information
I would be happy to add an additional test for this but I wasn't able to find the corresponding test suite.