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
6 changes: 5 additions & 1 deletion packages/core/src/declarers/core.group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export default function coreGroup(this: SyntaxRule, value: string) {
const indexOfColon = propertyName.indexOf(':')
if (indexOfColon !== -1) {
const propName = propertyName.slice(0, indexOfColon)
declarations[propName] = propertyName.slice(indexOfColon + 1)
// `|` is the class-name-safe space separator (used because spaces
// would break HTML class attribute parsing). Inside `{ … }` group
// values the literal pipe must be expanded back to a space, otherwise
// the browser sees `paint-order:stroke|fill` and rejects the rule.
declarations[propName] = propertyName.slice(indexOfColon + 1).replace(/\|/g, ' ')
}
}
const handleRule = (rule: SyntaxRule) => {
Expand Down
32 changes: 32 additions & 0 deletions packages/core/tests/issue-363-fallback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, test, expect } from 'vitest'
import { MasterCSS, config as defaultConfig } from '../src'

describe('issue #363: `|` separator inside `{...}` groups', () => {
test('{paint-order:stroke|fill} expands `|` to space inside group', () => {
const css = new MasterCSS(undefined, defaultConfig)
const rule = css.create('{paint-order:stroke|fill}')
expect(rule?.text).toContain('paint-order:stroke fill')
expect(rule?.text).not.toContain('paint-order:stroke|fill')
})

test('{paint-order:stroke} single value still works (regression)', () => {
const css = new MasterCSS(undefined, defaultConfig)
expect(css.create('{paint-order:stroke}')?.text).toContain('paint-order:stroke')
})

test('regular bg:white|red still treats `|` as space (regression)', () => {
const css = new MasterCSS(undefined, defaultConfig)
const rule = css.create('bg:white|red')
// bg expects multi-token; `|` is a class-safe space
expect(rule?.text).toBeTruthy()
// `|` may legitimately appear in the escaped class selector, but never in declarations
const declStart = rule!.text.indexOf('{')
expect(rule!.text.slice(declStart)).not.toContain('|')
})

test('three-value list works in group', () => {
const css = new MasterCSS(undefined, defaultConfig)
expect(css.create('{paint-order:stroke|fill|markers}')?.text)
.toContain('paint-order:stroke fill markers')
})
})
Loading