Repository navigation
Keep sibling combinators when a nested selector references the parent with & - #546
Usman Tahir Qureshi (UsmanQT) wants to merge 1 commit into
Conversation
… with `&`
When a parent selector contains `+` or `~` and a nested rule references
it with `&` (e.g. `.foo + .bar { .baz & {} }`), the hover preview left
`.foo` at the top level and only moved `.bar` under `.baz`.
- processSelector now moves the whole parent context out of the root
- cloneWithParent also clones preceding siblings on the path
- clone keeps LabelElement so `⋮` still prints as a label
Fixes microsoft/vscode#169900
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@microsoft-github-policy-service agree |
Martin Aeschlimann (aeschli)
left a comment
There was a problem hiding this comment.
Coordinate label cloning with #545 before merging both
This change passes independently, but combining it with #545 produces a runtime preview regression. The new LabelElement.clone() reads this.findAttribute("name"), while #545 moves the element/label name to ELEMENT_NAME (<>). After both changes the lookup returns null.
Reproduction:
.foo ~ .bar {
.baz & { color: red; }
}The combined HTML preview prints literal null where the sibling placeholder should be ⋮. Descendant placeholders can similarly become null instead of ….
Please update the clone lookup to use the same name storage as #545 when integrating these PRs, and run the combined CSS/SCSS sibling-reference tests. This was reproduced after clean three-way application; it is an integration defect, not a standalone failure of this head. In the full combined PR suite, both the CSS and SCSS sibling-reference tests fail on this mismatch.
Reviewed commit: c502ce2. Location: src/services/selectorPrinting.ts, LabelElement.clone() around line 88.
Fixes microsoft/vscode#169900
When a parent selector contains a sibling combinator (
+or~) and a nested rule references it with&, the hover preview splits the sibling chain apart:Before:
After:
The same happens with
~(the⋮marker is now kept too) and in Less.Cause
SelectorElementBuilder.processSelectorremoved only the root of the last element (.bar) from the tree when it saw&, so.foowas left behind at the top level.Element.cloneWithParent()cloned only the ancestor chain of the referenced element, so preceding siblings in the same parent were dropped (for exampleo1 o2 + o3 { .baz & {} }losto2).Change
processSelectormoves the whole parent context out of the root when&is used, instead of only the last element.cloneWithParent()also clones the preceding siblings of each element on the path. When the element is at the top level, those clones go under a newRootElement.clone()keepsLabelElement(⋮), so it still prints as a label after cloning.Tests
src/test/scss/selectorPrinting.test.ts: element-tree assertions for+,~, a descendant-plus-sibling parent,&:hoveron a sibling chain, and a plain nested rule under a sibling chain.src/test/css/selectorPrinting.test.ts: checks the HTML preview from the issue for both SCSS and Less. It deliberately checks only the HTML part, not specificity, so it doesn't overlap with Include parent rules in the specificity of nested selectors #525.npm testpasses (361/361) and lint passes.🤖 Generated with Claude Code