From 2bd2a59ae2ce01adfec6a903de71486255d4487d Mon Sep 17 00:00:00 2001 From: Ultroncn <82553854+Ultroncn@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:43:03 +0000 Subject: [PATCH 1/2] fix(dasherize): keep acronyms intact in mid-name and trailing positions 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 #372 --- src/dasherize.ts | 7 ++++++- test/dasherize.ts | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dasherize.ts b/src/dasherize.ts index b0699f84..3df542b5 100644 --- a/src/dasherize.ts +++ b/src/dasherize.ts @@ -1,6 +1,11 @@ export const dasherize = (str: unknown): string => String(typeof str === 'symbol' ? str.description : str) - .replace(/([A-Z]($|[a-z]))/g, '-$1') + // Split an acronym from a following capitalized word (`URLBar` -> `URL-Bar`, + // `mySVGIcon` -> `mySVG-Icon`). + .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2') + // 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') .replace(/--/g, '-') .replace(/^-|-$/, '') .toLowerCase() diff --git a/test/dasherize.ts b/test/dasherize.ts index 0fbf0fb1..b0924223 100644 --- a/test/dasherize.ts +++ b/test/dasherize.ts @@ -9,6 +9,12 @@ describe('dasherize', () => { ['autofocusWhenReady', 'autofocus-when-ready'], ['URLBar', 'url-bar'], ['ClipX', 'clip-x'], + ['UserIDListElement', 'user-id-list-element'], + ['CopyURLElement', 'copy-url-element'], + ['mySVGIcon', 'my-svg-icon'], + ['srcURL', 'src-url'], + ['data-URL', 'data-url'], + ['data-srcURL', 'data-src-url'], [Symbol('helloWorld'), 'hello-world'] ] From 795f0d4577e2a7f8c0ca1b93c3e97bb679e6b367 Mon Sep 17 00:00:00 2001 From: Ultroncn <82553854+Ultroncn@users.noreply.github.com> Date: Tue, 17 Nov 2026 04:23:05 +0000 Subject: [PATCH 2/2] fix(dasherize): preserve boundaries after non-ASCII letters and underscores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/dasherize.ts | 6 ++++-- test/dasherize.ts | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dasherize.ts b/src/dasherize.ts index 3df542b5..f18fdc59 100644 --- a/src/dasherize.ts +++ b/src/dasherize.ts @@ -4,8 +4,10 @@ export const dasherize = (str: unknown): string => // `mySVGIcon` -> `mySVG-Icon`). .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2') // 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') + // `srcURL` -> `src-URL`). Boundaries are also kept after other non-uppercase + // characters, so `CaféBarElement` keeps its `café-Bar` boundary and `Foo_BarElement` + // keeps its `Foo_-Bar` boundary (both still register after `-element` is stripped). + .replace(/([^A-Z])([A-Z])/g, '$1-$2') .replace(/--/g, '-') .replace(/^-|-$/, '') .toLowerCase() diff --git a/test/dasherize.ts b/test/dasherize.ts index b0924223..47e78cd8 100644 --- a/test/dasherize.ts +++ b/test/dasherize.ts @@ -15,6 +15,9 @@ describe('dasherize', () => { ['srcURL', 'src-url'], ['data-URL', 'data-url'], ['data-srcURL', 'data-src-url'], + // Boundaries after non-ASCII letters and underscores are preserved (see #373 review). + ['CaféBarElement', 'café-bar-element'], + ['Foo_BarElement', 'foo_-bar-element'], [Symbol('helloWorld'), 'hello-world'] ]