Skip to content

Commit 6dbe132

Browse files
committed
feat: Add support for CSS Shadow Parts module with ::part() pseudo-element
1 parent 85ac77d commit 6dbe132

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/syntax-definitions.ts

+8
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ export const cssModules = {
496496
String: ['highlight']
497497
}
498498
}
499+
},
500+
'css-shadow-parts-1': {
501+
latest: true,
502+
pseudoElements: {
503+
definitions: {
504+
Selector: ['part']
505+
}
506+
}
499507
}
500508
} satisfies Record<string, SyntaxDefinition & {latest?: true}>;
501509

test/modules.test.ts

+62
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,68 @@ describe('CSS Modules', () => {
431431
});
432432
});
433433

434+
describe('css-shadow-parts-1', () => {
435+
it('should parse ::part pseudo-element', () => {
436+
const parse = createParser({
437+
modules: ['css-shadow-parts-1']
438+
});
439+
440+
expect(parse('::part(button)')).toEqual(
441+
ast.selector({
442+
rules: [
443+
ast.rule({
444+
items: [
445+
ast.pseudoElement({
446+
name: 'part',
447+
argument: ast.selector({
448+
rules: [
449+
ast.rule({
450+
items: [ast.tagName({name: 'button'})]
451+
})
452+
]
453+
})
454+
})
455+
]
456+
})
457+
]
458+
})
459+
);
460+
461+
expect(parse('::part(button-primary)')).toEqual(
462+
ast.selector({
463+
rules: [
464+
ast.rule({
465+
items: [
466+
ast.pseudoElement({
467+
name: 'part',
468+
argument: ast.selector({
469+
rules: [
470+
ast.rule({
471+
items: [ast.tagName({name: 'button-primary'})]
472+
})
473+
]
474+
})
475+
})
476+
]
477+
})
478+
]
479+
})
480+
);
481+
});
482+
483+
it('should reject ::part when module is not enabled', () => {
484+
const parse = createParser({
485+
syntax: {
486+
pseudoElements: {
487+
unknown: 'reject'
488+
}
489+
}
490+
});
491+
492+
expect(() => parse('::part(button)')).toThrow('Unknown pseudo-element "part".');
493+
});
494+
});
495+
434496
describe('Multiple modules', () => {
435497
it('should support multiple modules at once', () => {
436498
const parse = createParser({

0 commit comments

Comments
 (0)