Skip to content

Commit

Permalink
fix: at-rule mixin collecting extra rules regression (#2915)
Browse files Browse the repository at this point in the history
  • Loading branch information
idoros committed Oct 5, 2023
1 parent c9fd6a8 commit af2e587
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/helpers/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ export function createSubsetAst<T extends postcss.Root | postcss.AtRule | postcs
node.name === 'container'
) {
let scopeSelector = node.name === 'st-scope' ? node.params : '';
let atruleHasMixin = isNestedInMixin || false;
if (scopeSelector) {
const ast = parseSelectorWithCache(scopeSelector, { clone: true });
const matchesSelectors = isRoot
? ast
: ast.filter((node) => containsPrefix(node));
if (matchesSelectors.length) {
isNestedInMixin = true;
atruleHasMixin = true;
scopeSelector = stringifySelector(
matchesSelectors.map((selectorNode) => {
if (!isRoot) {
Expand All @@ -133,7 +134,7 @@ export function createSubsetAst<T extends postcss.Root | postcss.AtRule | postcs
}),
isRoot,
getCustomSelector,
isNestedInMixin
atruleHasMixin
);
if (atRuleSubset.nodes) {
mixinRoot.append(atRuleSubset);
Expand Down
27 changes: 27 additions & 0 deletions packages/core/test/features/st-mixin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,33 @@ describe(`features/st-mixin`, () => {

shouldReportNoDiagnostics(meta);
});
it('should collect only st-scope nested rules', () => {
const { sheets } = testStylableCore({
'/mix.st.css': `
.before { color: RED; }
@st-scope .mix {
.inside { color: green; }
}
.after { color: RED; }
`,
'/entry.st.css': `
@st-import [mix] from './mix.st.css';
.into {-st-mixin: mix;}
`,
});

const { meta } = sheets['/entry.st.css'];

shouldReportNoDiagnostics(meta);

expect(deindent(meta.targetAst!.toString())).to.eql(
deindent(`
.entry__into {}
.entry__into .mix__inside { color: green; }
`)
);
});
});
describe(`higher-level feature integrations`, () => {
// ToDo: move to their higher level feature spec when created
Expand Down

0 comments on commit af2e587

Please sign in to comment.