Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
} else if (node.type === STYLE_RULE) {
// Handle keyframe rules specially
if (inKeyframes && node.prelude) {
// In keyframes, the prelude is a SelectorList that may not have Selector children
// (e.g., "50%" is just a SelectorList with text, no Selector child)
if (node.prelude.type === SELECTOR_LIST && node.prelude.text) {
keyframeSelectors.p(node.prelude.text, toLoc(node.prelude))
if (node.prelude.type === SELECTOR_LIST && node.prelude.children.length > 0) {
for (let keyframe_selector of node.prelude.children) {
keyframeSelectors.p(keyframe_selector.text, toLoc(keyframe_selector))
}
}
// Don't count keyframe rules as regular rules, but continue walking
// children to count declarations inside keyframes
Expand Down
8 changes: 5 additions & 3 deletions src/selectors/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ test('counts <keyframes-selector>s', () => {
50% {
opacity: 0;
}
90%,
to {
opacity: 1;
}
Expand All @@ -219,14 +220,15 @@ test('counts <keyframes-selector>s', () => {
const actual = analyze(fixture).selectors
expect(actual.total).toBe(2)
expect(actual.keyframes).toEqual({
total: 4,
totalUnique: 3,
total: 5,
totalUnique: 4,
unique: {
from: 2,
'90%': 1,
to: 1,
'50%': 1,
},
uniquenessRatio: 3 / 4,
uniquenessRatio: 4 / 5,
})
})

Expand Down