Skip to content

Commit

Permalink
Call StyleSheet / StyleSheetExit in visitors passed to composeVisitors
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 25, 2024
1 parent 7f29035 commit 9fa6dc4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions node/composeVisitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function composeVisitors(visitors) {

/** @type Visitor */
let res = {};
composeSimpleVisitors(res, visitors, 'StyleSheet');
composeSimpleVisitors(res, visitors, 'StyleSheetExit');
composeObjectVisitors(res, visitors, 'Rule', ruleVisitor, wrapUnknownAtRule);
composeObjectVisitors(res, visitors, 'RuleExit', ruleVisitor, wrapUnknownAtRule);
composeObjectVisitors(res, visitors, 'Declaration', declarationVisitor, wrapCustomProperty);
Expand Down
33 changes: 33 additions & 0 deletions node/test/composeVisitors.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,37 @@ test('variables', () => {
assert.equal(res.code.toString(), 'body{padding:20px;width:600px}');
});

test('StyleSheet', () => {
let styleSheetCalledCount = 0;
let styleSheetExitCalledCount = 0;
transform({
filename: 'test.css',
code: Buffer.from(`
body {
color: blue;
}
`),
visitor: composeVisitors([
{
StyleSheet() {
styleSheetCalledCount++
},
StyleSheetExit() {
styleSheetExitCalledCount++
}
},
{
StyleSheet() {
styleSheetCalledCount++
},
StyleSheetExit() {
styleSheetExitCalledCount++
}
}
])
});
assert.equal(styleSheetCalledCount, 2);
assert.equal(styleSheetExitCalledCount, 2);
});

test.run();

0 comments on commit 9fa6dc4

Please sign in to comment.