Skip to content

fix(csslib): deep-clone selectors and preserve legacy pseudo-elements - #14

Merged
palmoni5 merged 7 commits into
mainfrom
palmoni5/csslib-selector-deep-clone-20261110
Nov 10, 2026
Merged

palmoni5 merged 7 commits into
mainfrom
palmoni5/csslib-selector-deep-clone-20261110

Conversation

@palmoni5

@palmoni5 palmoni5 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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 mutable Identifier objects; pseudo-selector function clones reused their arguments. In addition, PseudoElementSelector.clone() dropped isLegacy, changing :before into ::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.dart mutates 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 no Identifier is shared with the original. All six tests fail on main; the printing test also fails if isLegacy is dropped again (a:before becomes a::before now that SelectorGroup.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-infos and dart test (188 passed, 1 skipped) are clean in pkgs/csslib. Only CHANGELOG.md conflicts with the other open csslib PRs (#15-#19); tree.dart merges cleanly.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

PR Health ⚠️

Health checks are rerunning. These details are out-of-date.

@palmoni5
palmoni5 force-pushed the palmoni5/csslib-selector-deep-clone-20261110 branch from 207288d to 8ba5966 Compare November 10, 2026 20:00
@palmoni5
palmoni5 merged commit 6a9a5af into main Nov 10, 2026
17 checks passed
@palmoni5
palmoni5 deleted the palmoni5/csslib-selector-deep-clone-20261110 branch November 10, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant