@@ -128,17 +128,23 @@ export function generateControllersModule(opts: ResolvedStimulusOptions, root: s
128128 return render ( [ ...controllers . values ( ) ] , isDev ) ;
129129}
130130
131+ // Stimulus identifier normalization: `_` -> `-`, `/` -> `--` (e.g. `foo/bar_baz` -> `foo--bar-baz`).
132+ function normalizeIdentifier ( id : string ) : string {
133+ return id . replace ( / _ / g, '-' ) . replace ( / \/ / g, '--' ) ;
134+ }
135+
131136function thirdPartyIdentifier (
132137 packageName : string ,
133138 controllerName : string ,
134139 pkgName ?: string ,
135140 userName ?: string
136141) : string {
142+ // Explicit user/package names keep their underscores; only the slash separator is collapsed.
137143 if ( userName ) return userName . replace ( / \/ / g, '--' ) ;
138144 if ( pkgName ) return pkgName . replace ( / \/ / g, '--' ) ;
139145 let id = `${ packageName } /${ controllerName } ` ;
140146 if ( id . startsWith ( '@' ) ) id = id . slice ( 1 ) ;
141- return id . replace ( / _ / g , '-' ) . replace ( / \/ / g , '--' ) ;
147+ return normalizeIdentifier ( id ) ;
142148}
143149
144150function render ( controllers : ResolvedController [ ] , isDev : boolean ) : string {
@@ -196,5 +202,5 @@ function listLocalControllers(dir: string): string[] {
196202
197203function localIdentifier ( rel : string ) : string {
198204 const base = slash ( rel ) . replace ( / [ - _ ] c o n t r o l l e r \. [ j t ] s $ / , '' ) ;
199- return base . replace ( / _ / g , '-' ) . replace ( / \/ / g , '--' ) ;
205+ return normalizeIdentifier ( base ) ;
200206}
0 commit comments