File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -338,7 +338,20 @@ const hasAssociatedLabelViaHtmlFor = (openingElement: TSESTree.JSXOpeningElement
338338 if ( info . kind === "template" ) {
339339 const templ = info . template as string ;
340340 const src = getSourceText ( context ) ;
341- return new RegExp ( `<(?:Label|label)[^>]*\\bhtmlFor\\s*=\\s*\\{\\s*${ escapeForRegExp ( templ ) } \\s*\\}` , "i" ) . test ( src ) ;
341+ // Build a pattern which matches the template's literal parts but allows any expression
342+ // inside `${...}` placeholders. This lets templates with non-Identifier expressions
343+ // (e.g. `${a.b}`) match the canonicalized template produced from the AST.
344+ const placeholderRe = / \$ \{ [ ^ } ] * \} / g;
345+ let pattern = "" ;
346+ let idx = 0 ;
347+ let m : RegExpExecArray | null ;
348+ while ( ( m = placeholderRe . exec ( templ ) ) !== null ) {
349+ pattern += escapeForRegExp ( templ . slice ( idx , m . index ) ) ;
350+ pattern += "\\$\\{[^}]*\\}" ;
351+ idx = m . index + m [ 0 ] . length ;
352+ }
353+ pattern += escapeForRegExp ( templ . slice ( idx ) ) ;
354+ return new RegExp ( `<(?:Label|label)[^>]*\\bhtmlFor\\s*=\\s*\\{\\s*${ pattern } \\s*\\}` , "i" ) . test ( src ) ;
342355 }
343356
344357 return false ;
You can’t perform that action at this time.
0 commit comments