Skip to content

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

Closed
wants to merge 2 commits into from
Closed

fix(animations): handle structured AnimateTimings #31107

wants to merge 2 commits into from

Conversation

chrisguttandin
Copy link
Contributor

Fixes: #22752

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

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?

  • Yes
  • No

Other information

I would be happy to add an additional test for this but I wasn't able to find the corresponding test suite.

Sorry, something went wrong.

@chrisguttandin chrisguttandin requested a review from a team as a code owner June 18, 2019 15:04
@ngbot ngbot bot added this to the needsTriage milestone Jun 19, 2019
@jessicajaniuk
Copy link
Contributor

@crisbeto Could you review this PR? It looks pretty small, but you're the most familiar with the animations package.

@chrisguttandin
Copy link
Contributor Author

It's been a while since I created this PR. :-) Please let me know if anything needs to be changed.

@petebacondarwin
Copy link
Contributor

One addition that would be welcome is if you could put together a unit test that demonstrated the bug and passes after this fix.

@petebacondarwin
Copy link
Contributor

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 value was an object or a number?

Copy link
Member

@crisbeto crisbeto left a 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;
Copy link
Member

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);
}

Copy link
Contributor Author

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.

@jessicajaniuk
Copy link
Contributor

@chrisguttandin If you have a chance to respond to the comments here, that'd be great. We'd love to land this. Thanks!

@chrisguttandin
Copy link
Contributor Author

@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?

@jessicajaniuk jessicajaniuk self-requested a review February 4, 2022 00:17
@jessicajaniuk
Copy link
Contributor

@chrisguttandin It depends on where the test is exactly. You can try yarn bazel test packages/animations/browser/test and add --config=debug if you want to run them locally.

@jessicajaniuk jessicajaniuk added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Feb 11, 2022
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Feb 11, 2022
@chrisguttandin
Copy link
Contributor Author

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.

@jessicajaniuk jessicajaniuk self-assigned this Mar 21, 2022
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a 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!

@jessicajaniuk jessicajaniuk added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Mar 29, 2022
@jessicajaniuk jessicajaniuk removed the request for review from a team March 29, 2022 20:51
@jessicajaniuk
Copy link
Contributor

@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.

@jessicajaniuk jessicajaniuk added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Mar 29, 2022
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.
@jessicajaniuk jessicajaniuk added action: rerun CI at HEAD and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: rerun CI at HEAD labels Apr 4, 2022
@jessicajaniuk jessicajaniuk added the action: merge The PR is ready for merge by the caretaker label Apr 4, 2022
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit a3f344f.

AndrewKushnir pushed a commit that referenced this pull request Apr 5, 2022
This commit makes sure structured AnimateTimings are not procesed any further when building the AST.

Fixes: #22752

PR Close #31107
AndrewKushnir pushed a commit that referenced this pull request Apr 5, 2022
This commit adds a test for the buildAnimationAst() function.

PR Close #31107
AndrewKushnir pushed a commit that referenced this pull request Apr 5, 2022
This commit adds a test for the buildAnimationAst() function.

PR Close #31107
@chrisguttandin chrisguttandin deleted the handle-parsed-timing-information branch April 6, 2022 10:13
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Apr 9, 2022
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#&#8203;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 ([#&#8203;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>
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: animations cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AnimationAstBuilderVisitor.visitAnimate() can't handle AnimateTimings
7 participants