feat: support case-sensitive attribute flag (s) per Selectors L4#327
Open
abhu85 wants to merge 1 commit into
Open
feat: support case-sensitive attribute flag (s) per Selectors L4#327abhu85 wants to merge 1 commit into
abhu85 wants to merge 1 commit into
Conversation
Attribute selectors accept the explicit case-sensitive flag `s`/`S` (CSS Selectors Level 4), but the parser only modeled the case-insensitive flag `i`/`I`. For `[a=b s]` the `s` was dumped into `raws.insensitiveFlag` and left `insensitive` false, so the flag was not modeled at all. Model `s` analogously to `i`: add a `sensitive` boolean and a `sensitiveFlag` getter on Attribute, recognize `s`/`S` in the parser, and serialize the flag from `sensitiveFlag` when present. The original `S` notation is preserved in `raws.sensitiveFlag`. Non-standard flags still round-trip through `raws.insensitiveFlag` unchanged. Fixes postcss#309
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.
Summary
Adds support for the CSS Selectors Level 4 case-sensitive attribute flag
s/S(e.g.[a=b s]), modeled analogously to the existing case-insensitivei/Iflag.Fixes #309
Problem
The parser only recognized
i/I. For[class="foo" s]it leftinsensitive: falseand dumped thesintoraws.insensitiveFlag, so the explicit case-sensitive flag was never modeled on the AST. (It happened to round-trip via that mis-filed raw, but the parsed node did not reflect the flag.)Solution
s/Sin the attribute parser and set a newsensitiveboolean on the node.Attribute#sensitive(get/set) andAttribute#sensitiveFlag('s' | ''), preserving the originalSnotation inraws.sensitiveFlag. The setter clearsraws.sensitiveFlagwhen set tofalse, mirroringinsensitive.sensitiveFlagwhen present;i/Iand non-standard flags (viaraws.insensitiveFlag) are unchanged. The flag reuses the existinginsensitivepositional/space slot, sooffsetOf/spacesbehavior is untouched.Test Plan
Added parse +
.toString()round-trip tests for[href="foo" s],[href="foo" S], and unquoted[href=test s], assertingsensitive/sensitiveFlagare set and thatsis no longer mis-filed intoraws.insensitiveFlag. The AST-level assertions fail before the change and pass after. Full suite:783 passing; lint, typecheck, and coverage gates green.Compatibility
Fully additive and backward compatible — no existing property removed or repurposed;
insensitive/insensitiveFlag/raws.insensitiveFlagbehavior is unchanged and all prior tests pass (including the[href="foo" y]non-standard-modifier case). The AST is public;sensitive,sensitiveFlag, andraws.sensitiveFlagare new fields. Happy to adjust the API shape if you'd prefer a different modeling.