Skip to content

Commit db68f33

Browse files
Merge pull request #1068 from Poimen/duplicated-keyframes-fix
fix: empty @Keyframes emitted
2 parents a0d4355 + bdf9223 commit db68f33

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,23 @@ module.exports = (options) => {
111111
while (rule.nodes.length > 0) {
112112
destination.append(rule.nodes[0]);
113113
}
114+
115+
// store the original rule parent before removal in case an atrule
116+
// becomes empty as a result of the removal
117+
const ruleParent = rule.parent;
118+
114119
// remove duplicated rule
115120
rule.remove();
116121

122+
// on removal of the node, the parent atrule could have no
123+
// declarations associated. This is an issue for @keyframes that
124+
// interpret @keyframes <name> {} as overwriting existing keyframe
125+
// transitions.
126+
if (ruleParent.type === 'atrule' && ruleParent.nodes.length === 0) {
127+
const ruleParentIndex = ruleParent.parent.index(ruleParent);
128+
ruleParent.parent.nodes[ruleParentIndex].remove();
129+
}
130+
117131
if (
118132
options.removeDuplicatedProperties ||
119133
options.removeDuplicatedValues

test/duplicated-css.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,39 @@ const cases = [
227227
background: green;
228228
}
229229
}
230-
@media print { }
231230
`,
232231
},
233232
{
234233
label: 'keyframe selectors with same percentage',
235234
input: '@keyframes a {0% { color: blue; } 0% { background: green; }}',
236235
expected: '@keyframes a {0% { color: blue; background: green; }}',
237236
},
237+
{
238+
label: 'keyframe selectors with duplicate animation properties',
239+
input: minify`
240+
@keyframes ping {
241+
75%,
242+
to {
243+
transform: scale(2);
244+
}
245+
}
246+
@keyframes ping {
247+
75%,
248+
to {
249+
opacity: 0;
250+
}
251+
}
252+
`,
253+
expected: minify`
254+
@keyframes ping {
255+
75%,
256+
to {
257+
transform: scale(2);
258+
opacity: 0;
259+
}
260+
}
261+
`,
262+
},
238263
{
239264
label: 'multiple print media queries with different case',
240265
input: minify`
@@ -256,7 +281,6 @@ const cases = [
256281
background: green;
257282
}
258283
}
259-
@MEDIA print { }
260284
`,
261285
},
262286
{

0 commit comments

Comments
 (0)