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
33 changes: 33 additions & 0 deletions src/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,39 @@ describe('Core Nodes', () => {
expect(decl2.type).toBe(DECLARATION)
})

test('@font-feature-values with nested at-rules', () => {
const root = parse(
'@font-feature-values Font One { @styleset { nice-style: 12; } @swash { fancy: 1 } } a {}',
)
const rule = root.first_child! as Atrule
expect(rule.name).toBe('font-feature-values')
expect(rule.next_sibling!.type).toBe(STYLE_RULE)
expect(rule.next_sibling!.next_sibling).toBeNull()

const [styleset, swash] = rule.block!.children as Atrule[]
expect(styleset.type).toBe(AT_RULE)
expect(styleset.name).toBe('styleset')
expect(styleset.block!.first_child!.type).toBe(DECLARATION)
expect(swash.name).toBe('swash')
expect(swash.block!.first_child!.type).toBe(DECLARATION)
})

test('@page with nested margin at-rules', () => {
const root = parse(
'@page :first { margin: 1in; @top-left { content: "a"; } @bottom-right-corner { color: red } } a {}',
)
const page = root.first_child! as Atrule
expect(page.name).toBe('page')
expect(page.next_sibling!.type).toBe(STYLE_RULE)

const [margin, top_left, bottom_right] = page.block!.children as Atrule[]
expect(margin.type).toBe(DECLARATION)
expect(top_left.name).toBe('top-left')
expect(top_left.block!.first_child!.type).toBe(DECLARATION)
expect(bottom_right.name).toBe('bottom-right-corner')
expect(bottom_right.block!.first_child!.type).toBe(DECLARATION)
})

test('@page', () => {
const source = '@page { margin: 1in; }'
const root = parse(source)
Expand Down
24 changes: 22 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,28 @@ export interface ParserOptions {
// Static at-rule lookup sets for fast classification
const DECLARATION_AT_RULES = new Set([
'font-face',
'font-feature-values',
'page',
'styleset',
'stylistic',
'character-variant',
'swash',
'ornaments',
'annotation',
'top-left-corner',
'top-left',
'top-center',
'top-right',
'top-right-corner',
'bottom-left-corner',
'bottom-left',
'bottom-center',
'bottom-right',
'bottom-right-corner',
'left-top',
'left-middle',
'left-bottom',
'right-top',
'right-middle',
'right-bottom',
'property',
'counter-style',
'color-profile',
Expand Down
Loading