diff --git a/packages/compiler/src/shadow_css.ts b/packages/compiler/src/shadow_css.ts index 92ec3807d96..be70d3d3104 100644 --- a/packages/compiler/src/shadow_css.ts +++ b/packages/compiler/src/shadow_css.ts @@ -362,7 +362,7 @@ export class ShadowCss { unscopedKeyframesSet: ReadonlySet, ): CssRule { let content = rule.content.replace( - /((?:^|\s+|;)(?:-webkit-)?animation\s*:\s*)([^;]+)/g, + /((?:^|[\s;{])(?:-webkit-)?animation\s*:\s*)([^;}]+)/g, (_, start, animationDeclarations) => start + animationDeclarations.replace( @@ -393,7 +393,7 @@ export class ShadowCss { ), ); content = content.replace( - /((?:^|\s+|;)(?:-webkit-)?animation-name(?:\s*):(?:\s*))([^;]+)/g, + /((?:^|[\s;{])(?:-webkit-)?animation-name(?:\s*):(?:\s*))([^;}]+)/g, (_match, start, commaSeparatedKeyframes) => `${start}${commaSeparatedKeyframes .split(',') diff --git a/packages/compiler/test/shadow_css/keyframes_spec.ts b/packages/compiler/test/shadow_css/keyframes_spec.ts index b03e7da4907..884af6bbcc2 100644 --- a/packages/compiler/test/shadow_css/keyframes_spec.ts +++ b/packages/compiler/test/shadow_css/keyframes_spec.ts @@ -259,6 +259,17 @@ describe('ShadowCss, keyframes and animations', () => { expect(shim(css, 'host-a')).toEqual(expected); }); + it('should correctly process animations defined in minified rules nested in an at-rule', () => { + let css = '@keyframes foo {}@media screen{.test{animation:foo 1s forwards}}'; + let expected = + '@keyframes host-a_foo {}@media screen{.test[host-a]{animation:host-a_foo 1s forwards}}'; + expect(shim(css, 'host-a')).toEqual(expected); + css = '@keyframes foo {}@supports (display:grid){.test{animation-name:foo}}'; + expected = + '@keyframes host-a_foo {}@supports (display:grid){.test[host-a]{animation-name:host-a_foo}}'; + expect(shim(css, 'host-a')).toEqual(expected); + }); + it('should ignore keywords values when scoping local animations', () => { const css = ` div {