Repository navigation
Conversation
dasherize() only treated an acronym as one word when it started the identifier (URLBar -> url-bar). Acronyms in the middle or at the end were mangled: CopyURLElement -> copyurl-element (register() then throws, as 'copyurl' is not a valid custom element name), srcURL -> srcur-l, and @attr URL -> data-ur-l instead of data-url as documented in docs/_guide/attrs-2.md. Split an acronym run from a following capitalized word first, then split a lowercase letter or digit from a following capital, so UserIDListElement -> user-id-list-element, CopyURLElement -> copy-url-element, mySVGIcon -> my-svg-icon and srcURL -> src-url, while all existing cases (URLBar, ClipX, fooBar, ...) stay the same. Fixes github#372
There was a problem hiding this comment.
🟡 Changes recommended
The boundary change breaks names containing non-ASCII letters or underscores, causing register() to throw for inputs such as CaféBarElement and Foo_BarElement.
1 open issue
What changed in this PR
This PR addresses #372 by updating Catalyst’s dasherize() helper to preserve acronyms in the middle and at the end of identifiers used for custom elements and attributes.
Changes:
- Separates acronym runs from following capitalized words and adds boundaries before acronyms.
- Adds six regression cases covering controller names and attribute names.
| File | Description |
|---|---|
| test/dasherize.ts | Adds six mid-name and trailing acronym cases. |
| src/dasherize.ts | Updates word-boundary rules and explanatory comments. |
Review effort: Balanced (adaptive)
| // Split a lowercase letter or digit from a following capital (`fooBar` -> `foo-Bar`, | ||
| // `srcURL` -> `src-URL`). | ||
| .replace(/([a-z0-9])([A-Z])/g, '$1-$2') |
There was a problem hiding this comment.
I checked this against the PR head and reproduced both regressions in Node: CaféBarElement changes from café-bar-element on main to cafébar-element, and Foo_BarElement changes from foo_-bar-element to foo_bar-element.
The proposed follow-up is to preserve those existing non-ASCII/underscore boundaries while retaining the acronym fix, with regression cases for both names alongside the existing acronym cases. Could a maintainer confirm that this bounded scope is welcome? I'll wait for confirmation before updating the implementation.
…scores The acronym fix restricted the preceding character to [a-z0-9], which dropped existing boundaries after non-ASCII letters and underscores: CaféBarElement became cafébar-element and Foo_BarElement became foo_bar-element, so register() threw after stripping -element. Use [^A-Z] as the preceding-character class instead, so a boundary is kept before a capital after any non-uppercase character, while acronym runs are still split by the first rule. Adds regression cases for both names.

Hi! This fixes #372.
Problem:
dasherize()only treated an acronym as one word when it started the identifier (URLBar->url-bar). Acronyms in the middle or at the end were mangled:CopyURLElement->copyurl-element, soregister()throws ('copyurl' is not a valid custom element name)srcURL->srcur-l,@attr URL->data-ur-linstead ofdata-urlas documented indocs/_guide/attrs-2.mdFix: in
src/dasherize.ts, split an acronym run from a following capitalized word first, then split a lowercase letter or digit from a following capital. NowUserIDListElement->user-id-list-element,CopyURLElement->copy-url-element,mySVGIcon->my-svg-icon,srcURL->src-url, while all existing cases (URLBar,ClipX,fooBar, …) stay the same. Added the six cases from the issue totest/dasherize.ts.Verification:
npm run build(tsc) passes, and the compiledlib/dasherize.jsreturns the expected output for all existing plus new cases. I could not runnpm testlocally because no usable Chrome is available in this environment (web-test-runner needs one), so the browser test suite will need CI to confirm — apologies for that.Fixes #372