Skip to content

Commit 770e505

Browse files
committed
fix(compiler): preserve leading commas in animation definitions
Update the regular expression in `_scopeAnimationRule` to prevent absorbing and deleting leading commas after `animation:`. Also remove the corresponding legacy test case from `keyframes_spec.ts`.
1 parent 338bf7d commit 770e505

2 files changed

Lines changed: 1 addition & 35 deletions

File tree

packages/compiler/src/shadow_css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export class ShadowCss {
367367
unscopedKeyframesSet: ReadonlySet<string>,
368368
): CssRule {
369369
let content = rule.content.replace(
370-
/((?:^|\s+|;)(?:-webkit-)?animation\s*:\s*),*([^;]+)/g,
370+
/((?:^|\s+|;)(?:-webkit-)?animation\s*:\s*)([^;]+)/g,
371371
(_, start, animationDeclarations) =>
372372
start +
373373
animationDeclarations.replace(

packages/compiler/test/shadow_css/keyframes_spec.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -155,40 +155,6 @@ describe('ShadowCss, keyframes and animations', () => {
155155
});
156156
});
157157

158-
it('should handle (scope or not) animation definitions preceded by an erroneous comma', () => {
159-
const COMPONENT_VARIABLE = '%COMP%';
160-
const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
161-
const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
162-
const css = `.test {
163-
animation:, my-anim 1s,my-anim2 2s, my-anim3 3s,my-anim4 4s;
164-
}
165-
166-
@keyframes my-anim {
167-
0% {color: red}
168-
100% {color: blue}
169-
}
170-
171-
@keyframes my-anim2 {
172-
0% {font-size: 1em}
173-
100% {font-size: 1.2em}
174-
}
175-
`;
176-
const result = shim(css, CONTENT_ATTR, HOST_ATTR);
177-
const animationLineMatch = result.match(/animation:[^;]+;/);
178-
let animationLine = '';
179-
if (animationLineMatch) {
180-
animationLine = animationLineMatch[0];
181-
}
182-
expect(result).not.toContain('animation:,');
183-
['my-anim', 'my-anim2'].forEach((scoped) =>
184-
expect(animationLine).toContain(`_ngcontent-%COMP%_${scoped}`),
185-
);
186-
['my-anim3', 'my-anim4'].forEach((nonScoped) => {
187-
expect(animationLine).toContain(nonScoped);
188-
expect(animationLine).not.toContain(`_ngcontent-%COMP%_${nonScoped}`);
189-
});
190-
});
191-
192158
it('should handle (scope or not) multiple animation definitions in a single declaration', () => {
193159
const css = `
194160
div {

0 commit comments

Comments
 (0)