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
13 changes: 13 additions & 0 deletions src/node-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type {
PseudoElementSelector,
NthSelector,
MediaFeature,
MediaQuery,
LayerName,
Combinator,
Identifier,
Expand Down Expand Up @@ -341,6 +342,18 @@ describe('type narrowing — compile-time', () => {
expect(dim.type_name).toBe('Dimension')
})

test('MediaFeature exposes children, including extra hack nodes like 0\\0', () => {
const atrule = parse('@media (min-width:0\\0) {}').first_child! as Atrule
const query = atrule.prelude!.first_child! as MediaQuery
const feature = query.first_child as MediaFeature
expect(feature.has_children).toBeTypeOf('boolean')
expect(feature.child_count).toBeTypeOf('number')
expect(feature.has_children).toBe(true)
expect(feature.child_count).toBe(2)
expect([...feature].map((c) => c.type_name)).toEqual(['Number', 'Identifier'])
expect(feature.value?.type_name).toBe('Number')
})

test('ContainerQuery children include PreludeOperator for and/or/not, without casting', () => {
const atrule = parse('@container style(a: 1) and style(b: 2) {}').first_child! as Atrule
const containerQuery = atrule.prelude!.first_child! as ContainerQuery
Expand Down
19 changes: 10 additions & 9 deletions src/node-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,16 @@ export type MediaQuery = WithClone<
}
>

export type MediaFeature = Leaf<
typeof MEDIA_FEATURE,
'Feature',
{
/** Feature name, e.g. "min-width" */
readonly property: string
/** Feature value node (e.g. Dimension, Number, Identifier, Ratio), or null for boolean features like (hover) */
readonly value: CSSNode | null
}
export type MediaFeature = WithClone<
CSSNode &
WithChildren<Identifier | Number | Dimension | Ratio> & {
readonly type: typeof MEDIA_FEATURE
readonly type_name: 'Feature'
/** Feature name, e.g. "min-width" */
readonly property: string
/** Feature value node (Dimension, Number, Identifier or Ratio), or null for boolean features like (hover). Hacks like `0\0` add further children after it. */
readonly value: Identifier | Number | Dimension | Ratio | null
}
>

export type MediaType = Leaf<
Expand Down
Loading