Skip to content

feat: support case-sensitive attribute flag (s) per Selectors L4#327

Open
abhu85 wants to merge 1 commit into
postcss:mainfrom
abhu85:fix/attribute-case-sensitive-flag
Open

feat: support case-sensitive attribute flag (s) per Selectors L4#327
abhu85 wants to merge 1 commit into
postcss:mainfrom
abhu85:fix/attribute-case-sensitive-flag

Conversation

@abhu85

@abhu85 abhu85 commented Jul 20, 2026

Copy link
Copy Markdown

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-insensitive i/I flag.

Fixes #309

Problem

The parser only recognized i/I. For [class="foo" s] it left insensitive: false and dumped the s into raws.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

  • Recognize s/S in the attribute parser and set a new sensitive boolean on the node.
  • Add Attribute#sensitive (get/set) and Attribute#sensitiveFlag ('s' | ''), preserving the original S notation in raws.sensitiveFlag. The setter clears raws.sensitiveFlag when set to false, mirroring insensitive.
  • Serialize the flag from sensitiveFlag when present; i/I and non-standard flags (via raws.insensitiveFlag) are unchanged. The flag reuses the existing insensitive positional/space slot, so offsetOf/spaces behavior is untouched.
  • Update TypeScript declarations (all additive).

Test Plan

Added parse + .toString() round-trip tests for [href="foo" s], [href="foo" S], and unquoted [href=test s], asserting sensitive/sensitiveFlag are set and that s is no longer mis-filed into raws.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.insensitiveFlag behavior is unchanged and all prior tests pass (including the [href="foo" y] non-standard-modifier case). The AST is public; sensitive, sensitiveFlag, and raws.sensitiveFlag are new fields. Happy to adjust the API shape if you'd prefer a different modeling.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attribute selector's case-sensitivity identifier s

1 participant