Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mixin bug with experimentalSelectorInference #2909

Merged
merged 1 commit into from
Oct 1, 2023
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
8 changes: 7 additions & 1 deletion packages/core/src/features/feature.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { StylableMeta } from '../stylable-meta';
import type { ScopeContext, StylableExports, StylableTransformer } from '../stylable-transformer';
import type {
InferredSelector,
ScopeContext,
StylableExports,
StylableTransformer,
} from '../stylable-transformer';
import type { StylableResolver, MetaResolvedSymbols } from '../stylable-resolver';
import type { StylableEvaluator, EvalValueData } from '../functions';
import type * as postcss from 'postcss';
Expand All @@ -22,6 +27,7 @@ export interface FeatureTransformContext extends FeatureContext {
evaluator: StylableEvaluator;
getResolvedSymbols: (meta: StylableMeta) => MetaResolvedSymbols;
passedThrough?: string[];
inferredSelectorMixin?: InferredSelector;
}

export interface NodeTypes {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/features/st-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ export const hooks = createFeature<{ IMMUTABLE_SELECTOR: ImmutablePseudoClass }>
toRemove.push(() => node.replaceWith(node.nodes || []));
}
},
transformAtRuleNode({ context: { meta }, atRule, transformer }) {
transformAtRuleNode({ context: { meta, inferredSelectorMixin }, atRule, transformer }) {
if (isStScopeStatement(atRule)) {
const { selector, inferredSelector } = transformer.scopeSelector(
meta,
atRule.params,
atRule
atRule,
undefined,
inferredSelectorMixin
);
// transform selector in params
atRule.params = selector;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/stylable-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class StylableTransformer {
evaluator,
getResolvedSymbols: this.getResolvedSymbols,
passedThrough: path.slice(),
inferredSelectorMixin,
};
const transformResolveOptions = {
context: transformContext,
Expand Down
45 changes: 45 additions & 0 deletions packages/core/test/features/st-mixin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,51 @@ describe(`features/st-mixin`, () => {

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

shouldReportNoDiagnostics(meta);
});
it('should collect mixin from st-sope selector (experimentalSelectorInference)', () => {
const { sheets } = testStylableCore(
{
'/mix.st.css': `
@st-scope .mix {
.part { color: green; }
.part2 { color: purple; }
&:state { color: gold; }
}
@st-scope .mix.compoundAfter {
.part { color: blue; }
}
@st-scope .compoundBefore.mix {
.part { color: pink; }
}
@st-scope .mix, .notMix, .mix[extra] {
.part { color: white; }
}
.mix {
-st-states: state;
}
`,
'/entry.st.css': `
@st-import [mix] from './mix.st.css';

/*
@rule(descendant)[1] .entry__into .mix__part {color: green;}
@rule(descendant2)[2] .entry__into .mix__part2 {color: purple;}
@rule(state)[3] .entry__into.mix--state {color: gold;}
@rule(+after)[4] .entry__into.mix__compoundAfter .mix__part {color: blue;}
@rule(+before)[5] .entry__into.mix__compoundBefore .mix__part {color: pink;}
@rule(multi selector)[6] .entry__into .mix__part, .entry__into[extra] .mix__part {color: white;}
*/
.into {
-st-mixin: mix;
}
`,
},
{ stylableConfig: { experimentalSelectorInference: true } }
);

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

shouldReportNoDiagnostics(meta);
});
});
Expand Down