@@ -181,27 +181,36 @@ export default iterateJsdoc(({
181181 * }}
182182 */
183183 const findExpectedIndex = ( jsdocTags , indexAtFunctionParams ) => {
184- const remainingRoots = functionParameterNames . slice ( indexAtFunctionParams || 0 ) ;
184+ // Get the parameters that come after the current index in the flattened order
185+ const remainingFlattenedRoots = flattenedRoots . slice ( ( indexAtFunctionParams || 0 ) + 1 ) ;
186+
187+ // Find the first existing tag that comes after the current parameter in the flattened order
185188 const foundIndex = jsdocTags . findIndex ( ( {
186189 name,
187190 newAdd,
188191 } ) => {
189- return ! newAdd && remainingRoots . some ( ( remainingRoot ) => {
190- if ( Array . isArray ( remainingRoot ) ) {
191- return (
192- /**
193- * @type {import('../jsdocUtils.js').FlattendRootInfo & {
194- * annotationParamName?: string|undefined;
195- * }}
196- */ ( remainingRoot [ 1 ] ) . names . includes ( name )
197- ) ;
192+ if ( newAdd ) {
193+ return false ;
194+ }
195+
196+ // Check if the tag name matches any of the remaining flattened roots
197+ return remainingFlattenedRoots . some ( ( flattenedRoot ) => {
198+ // The flattened roots don't have the root prefix (e.g., "bar", "bar.baz")
199+ // but JSDoc tags do (e.g., "root0", "root0.bar", "root0.bar.baz")
200+ // So we need to check if the tag name ends with the flattened root
201+
202+ // Check if tag name ends with ".<flattenedRoot>"
203+ if ( name . endsWith ( `.${ flattenedRoot } ` ) ) {
204+ return true ;
198205 }
199206
200- if ( typeof remainingRoot === 'object' ) {
201- return name === remainingRoot . name ;
207+ // Also check if tag name exactly matches the flattenedRoot
208+ // (for single-level params)
209+ if ( name === flattenedRoot ) {
210+ return true ;
202211 }
203212
204- return name === remainingRoot ;
213+ return false ;
205214 } ) ;
206215 } ) ;
207216
0 commit comments