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: initial mapped-selector infer with experimentalSelectorInference #2908

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
21 changes: 19 additions & 2 deletions packages/core/src/stylable-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export class StylableTransformer {
// reset current anchor for all except last selector
context.inferredSelector = new InferredSelector(
this,
context.inferredSelectorContext
context.inferredSelectorStart
);
}
}
Expand Down Expand Up @@ -680,7 +680,10 @@ export class InferredSelector {
constructor(
private api: Pick<
StylableTransformer,
'getResolvedSymbols' | 'createSelectorContext' | 'scopeSelectorAst'
| 'getResolvedSymbols'
| 'createSelectorContext'
| 'scopeSelectorAst'
| 'createInferredSelector'
>,
resolve?: InferredResolve[] | InferredSelector
) {
Expand Down Expand Up @@ -886,6 +889,17 @@ export class InferredSelector {
selectorStr
);
internalContext.isStandaloneSelector = isFirstInSelector;
if (!structureMode && experimentalSelectorInference) {
internalContext.inferredSelectorStart.set(
this.api.createInferredSelector(meta, {
name: 'root',
type: 'class',
})
);
internalContext.inferredSelector.set(
internalContext.inferredSelectorStart
);
}
const customAstSelectors = this.api.scopeSelectorAst(internalContext);
const inferred =
customAstSelectors.length === 1 || experimentalSelectorInference
Expand Down Expand Up @@ -1020,6 +1034,8 @@ export class ScopeContext {
public lastInferredSelectorNode: SelectorNode | undefined;
// selector is not a continuation of another selector
public isStandaloneSelector = true;
// used as initial selector
public inferredSelectorStart: InferredSelector;
// used as initial selector or after combinators
public inferredSelectorContext: InferredSelector;
// used for nesting selector
Expand Down Expand Up @@ -1072,6 +1088,7 @@ export class ScopeContext {
// set selector data
this.selectorStr = selectorStr || stringifySelector(selectorAst);
this.inferredSelectorContext = new InferredSelector(this.transformer, inferredContext);
this.inferredSelectorStart = new InferredSelector(this.transformer, inferredContext);
this.inferredSelectorNest = inferredSelectorNest || this.inferredSelectorContext.clone();
this.inferredSelector = new InferredSelector(
this.transformer,
Expand Down
26 changes: 26 additions & 0 deletions packages/core/test/features/css-pseudo-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,32 @@ describe('features/css-pseudo-element', () => {
}
);
});
it('should transform custom element with multiple selector inside nested pseudo-classes', () => {
// ToDo: with experimentalSelectorInference=true, the nested selector will be transformed inlined
testStylableCore(
`
@custom-selector :--part .partA, .partB;
@custom-selector :--nestedPart ::part, .partC;

/* @rule(1 level) .entry__root:not(.entry__partA,.entry__partB) */
.root:not(::part) {}

/*
notice: partB is pushed at the end because of how custom selectors are
processed atm.

@rule(2 levels) .entry__root:not(.entry__partA,.entry__partC,.entry__partB)
*/
.root:not(::nestedPart) {}

/* @rule(custom-selector syntax)
.entry__root:not(.entry__partA, .entry__partB)
*/
.root:not(:--part) {}
`,
{ stylableConfig: { experimentalSelectorInference: true } }
);
});
});
});
describe('st-import', () => {
Expand Down