Skip to content

fix: preserve casing of custom-ident identifiers (--foo) across all printers#232

Merged
bartveneman merged 2 commits into
mainfrom
claude/print-identifier-helper
Jul 20, 2026
Merged

fix: preserve casing of custom-ident identifiers (--foo) across all printers#232
bartveneman merged 2 commits into
mainfrom
claude/print-identifier-helper

Conversation

@bartveneman

Copy link
Copy Markdown
Member

Summary

  • Several printers 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() was silently lowercased to --myfunc(), corrupting it.
  • Added a shared 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

  • Added preserves casing of a custom function name in test/values.test.ts covering the --myFunc() fix
  • Added lowercases attribute selector names in test/selectors.test.ts (previously untested)
  • npx tsc --noEmit, npx vitest run, npx oxlint, npx oxfmt --check all clean
  • Differential test against main confirms the only behavioral change is the custom-function-name fix

Generated by Claude Code

…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.
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Package Size Increase

📦 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.
Comment thread test/selectors.test.ts
let expected = `[href] {}`
expect(actual).toEqual(expected)
})

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another test to prove that attribute selector's value remains intact in terms of quoting.

@bartveneman bartveneman changed the title Preserve casing of custom-ident identifiers (--foo) across all printers fix: preserve casing of custom-ident identifiers (--foo) across all printers Jul 20, 2026
@bartveneman
bartveneman merged commit ef3103a into main Jul 20, 2026
8 checks passed
@bartveneman
bartveneman deleted the claude/print-identifier-helper branch July 20, 2026 17:44
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.
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.

2 participants