From a9cf3399077e892cbb489634c1b5c07f381f9f1f Mon Sep 17 00:00:00 2001 From: Ido Rosenthal Date: Thu, 28 Sep 2023 09:46:57 +0300 Subject: [PATCH] fix: mix in st-scope with experimental experimentalSelectorInference --- packages/core/src/features/feature.ts | 8 +++- packages/core/src/features/st-scope.ts | 6 ++- packages/core/src/stylable-transformer.ts | 1 + packages/core/test/features/st-mixin.spec.ts | 45 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/core/src/features/feature.ts b/packages/core/src/features/feature.ts index 9f5d5793b..2e54fbf8f 100644 --- a/packages/core/src/features/feature.ts +++ b/packages/core/src/features/feature.ts @@ -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'; @@ -22,6 +27,7 @@ export interface FeatureTransformContext extends FeatureContext { evaluator: StylableEvaluator; getResolvedSymbols: (meta: StylableMeta) => MetaResolvedSymbols; passedThrough?: string[]; + inferredSelectorMixin?: InferredSelector; } export interface NodeTypes { diff --git a/packages/core/src/features/st-scope.ts b/packages/core/src/features/st-scope.ts index ceabf4494..2bea117f9 100644 --- a/packages/core/src/features/st-scope.ts +++ b/packages/core/src/features/st-scope.ts @@ -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; diff --git a/packages/core/src/stylable-transformer.ts b/packages/core/src/stylable-transformer.ts index 847651e18..aa284a8f9 100644 --- a/packages/core/src/stylable-transformer.ts +++ b/packages/core/src/stylable-transformer.ts @@ -208,6 +208,7 @@ export class StylableTransformer { evaluator, getResolvedSymbols: this.getResolvedSymbols, passedThrough: path.slice(), + inferredSelectorMixin, }; const transformResolveOptions = { context: transformContext, diff --git a/packages/core/test/features/st-mixin.spec.ts b/packages/core/test/features/st-mixin.spec.ts index a547ffdde..78f9a6d33 100644 --- a/packages/core/test/features/st-mixin.spec.ts +++ b/packages/core/test/features/st-mixin.spec.ts @@ -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); }); });