Repository navigation
fix(csslib): deep-clone selectors and preserve legacy pseudo-elements - #14
Merged
Merged
Conversation
PR Health
|
palmoni5
marked this pull request as ready for review
November 10, 2026 18:33
palmoni5
force-pushed
the
palmoni5/csslib-selector-deep-clone-20261110
branch
from
November 10, 2026 20:00
207288d to
8ba5966
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cloning a CSS selector tree did not create an independent AST.
SelectorGroup.clone()returned the same mutable selector list;SimpleSelectorSequence.clone()reused the child selector; many leaf selectors reused mutableIdentifierobjects; pseudo-selector function clones reused their arguments. In addition,PseudoElementSelector.clone()droppedisLegacy, changing:beforeinto::before.Fix
Deep-copy selector groups, sequences, identifier/namespace/value AST nodes, functional pseudo arguments, and negation arguments. Preserve the legacy pseudo-element syntax and existing source spans and public APIs.
Regression coverage
test/selector_clone_test.dartmutates original identifiers, clone lists and combinators, and checks functional pseudo/legacy syntax isolation. An end-to-end test clones a parsed style sheet (legacy:before, namespaces, attributes,:nth-child,:not,:host()), checks that it prints identically and that noIdentifieris shared with the original. All six tests fail onmain; the printing test also fails ifisLegacyis dropped again (a:beforebecomesa::beforenow thatSelectorGroup.clone()reaches the pseudo-element).Relation to Otzaria
This fixes correctness for consumers transforming parsed CSS ASTs and complements the prior parser optimizations. No Otzaria dependency pin update or runtime behavior change is made.
QA
dart format --output=none --set-exit-if-changed .,dart analyze --fatal-infosanddart test(188 passed, 1 skipped) are clean inpkgs/csslib. OnlyCHANGELOG.mdconflicts with the other open csslib PRs (#15-#19);tree.dartmerges cleanly.