fix: preserve casing of custom-ident identifiers (--foo) across all printers#232
Merged
Conversation
…rinters Several call sites lowercased CSS identifiers unconditionally (function names, attribute selector names, pseudo names, type/universal selector names and namespaces, at-rule names), while only the declaration-property printer checked for a `--`-prefixed custom-ident first. This meant a dashed-ident custom function call like `--myFunc()` got silently lowercased to `--myfunc()`, corrupting it. Added a shared print_identifier() helper (lowercase unless the name starts with `--`) and applied it at every one of these call sites, so custom-idents keep their case everywhere, not just in declaration properties.
Contributor
|
| 📦 Package | 📏 Base Size | 📏 Source Size | 📈 Size Change |
|---|---|---|---|
| @projectwallace/format-css | 8.6 kB | 8.7 kB | +89 B |
bartveneman
pushed a commit
that referenced
this pull request
Jul 20, 2026
These two changes are broader than the at-rule prelude rework this PR is otherwise scoped to (they touch existing declaration/selector printing that predates this branch), so they're moving to their own PRs (#232 and #233) for focused review and testing. Reverted print_list's function-name lowercasing, format_declaration's property lowercasing, print_attribute_selector, print_pseudo_selector, the type/universal selector printer, and print_atrule's name lowercasing back to their original (unshared) form, and print_url back to its original quote-normalizing behavior with print_prelude_url restored as its own function. The two new call sites this branch actually introduces — print_media_feature and print_prelude_function's custom-property-style name handling — keep their `--`-aware lowercasing, just inlined instead of calling the (now removed from this branch) shared helper.
bartveneman
commented
Jul 20, 2026
| let expected = `[href] {}` | ||
| expect(actual).toEqual(expected) | ||
| }) | ||
|
|
Member
Author
There was a problem hiding this comment.
Add another test to prove that attribute selector's value remains intact in terms of quoting.
…lowercased Addresses review feedback on #232.
bartveneman
pushed a commit
that referenced
this pull request
Jul 20, 2026
#232 and #233 merged to main and landed in this branch via the merge of main above. Point print_media_feature and print_prelude_function at the real print_identifier() instead of their local duplicated ternaries. print_prelude_url stays a separate function from print_url, despite looking identical at a glance: an @import specifier's Url node can also be a bare string (@import "foo";) with no url( prefix, unlike value-position url() where a string is always its own String node type, never Url. Verified empirically -- unifying the two functions broke `@import "foo";` (prints as `@import url(";`) since print_url's now-unconditional slice(4) assumes a url( prefix that isn't always there in this context.
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
---prefixed custom-ident first.--myFunc()was silently lowercased to--myfunc(), corrupting it.print_identifier()helper (name.startsWith('--') ? name : name.toLowerCase()) and applied it at every identifier-printing call site, so custom-idents keep their case everywhere, not just in declaration properties.Test plan
preserves casing of a custom function nameintest/values.test.tscovering the--myFunc()fixlowercases attribute selector namesintest/selectors.test.ts(previously untested)npx tsc --noEmit,npx vitest run,npx oxlint,npx oxfmt --checkall cleanmainconfirms the only behavioral change is the custom-function-name fixGenerated by Claude Code