Skip to content

Commit 8132392

Browse files
authored
fix(valid-types): try parsing whole item before splitting into commas; fixes #1464 (#1465)
1 parent 09ee4ab commit 8132392

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

docs/rules/valid-types.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,5 +888,19 @@ function quux() {
888888
/**
889889
* @returns {@link SomeType}
890890
*/
891+
892+
/**
893+
* @template {string} Selector
894+
* @template {keyof GlobalEventHandlersEventMap} TEventType
895+
* @template {Element} [TElement=import('typed-query-selector/parser').ParseSelector<Selector, HTMLElement>]
896+
* @param {Selector} selector
897+
* @param {TEventType} type
898+
* @param {import('delegate-it').DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>} callback
899+
* @param {Omit<AddEventListenerOptions, 'once' | 'signal'>} [options]
900+
* @returns {void}
901+
*/
902+
export function onGlobalEvent (selector, type, callback, options) {
903+
delegate(document, selector, type, callback, options)
904+
}
891905
````
892906

src/rules/validTypes.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,15 @@ export default iterateJsdoc(({
358358

359359
if (hasNameOrNamepathPosition) {
360360
if (mode !== 'jsdoc' && tag.tag === 'template') {
361-
for (const namepath of utils.parseClosureTemplateTag(tag)) {
362-
validNamepathParsing(namepath);
361+
if (!tryParsePathIgnoreError(
362+
// May be an issue with the commas of
363+
// `utils.parseClosureTemplateTag`, so first try a raw
364+
// value; we really need a proper parser instead, however.
365+
tag.name.trim().replace(/^\[?(?<name>.*?)=.*$/v, '$<name>'),
366+
)) {
367+
for (const namepath of utils.parseClosureTemplateTag(tag)) {
368+
validNamepathParsing(namepath);
369+
}
363370
}
364371
} else {
365372
validNamepathParsing(tag.name, tag.tag);

test/rules/assertions/validTypes.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,5 +1869,22 @@ export default /** @type {import('../index.js').TestCases} */ ({
18691869
*/
18701870
`,
18711871
},
1872+
{
1873+
code: `
1874+
/**
1875+
* @template {string} Selector
1876+
* @template {keyof GlobalEventHandlersEventMap} TEventType
1877+
* @template {Element} [TElement=import('typed-query-selector/parser').ParseSelector<Selector, HTMLElement>]
1878+
* @param {Selector} selector
1879+
* @param {TEventType} type
1880+
* @param {import('delegate-it').DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>} callback
1881+
* @param {Omit<AddEventListenerOptions, 'once' | 'signal'>} [options]
1882+
* @returns {void}
1883+
*/
1884+
export function onGlobalEvent (selector, type, callback, options) {
1885+
delegate(document, selector, type, callback, options)
1886+
}
1887+
`,
1888+
},
18721889
],
18731890
});

0 commit comments

Comments
 (0)