A class's plugin definitions: its attributes and its docblock's annotations, each with an `id`.
(content: string, declarations: readonly AttributedDeclaration[])
| 560 | |
| 561 | /** A class's plugin definitions: its attributes and its docblock's annotations, each with an `id`. */ |
| 562 | function pluginDefinitions(content: string, declarations: readonly AttributedDeclaration[]): { type: string; id: string; className: string; line: number }[] { |
| 563 | const out: { type: string; id: string; className: string; line: number }[] = []; |
| 564 | const seen = new Set<string>(); |
| 565 | const add = (type: string, id: string, className: string, line: number): void => { |
| 566 | const key = `${type}:${id}:${className}`; |
| 567 | if (seen.has(key)) return; |
| 568 | seen.add(key); |
| 569 | out.push({ type, id, className, line }); |
| 570 | }; |
| 571 | for (const decl of declarations) { |
| 572 | if (!decl.className) continue; |
| 573 | for (const attribute of decl.attributes) { |
| 574 | if (NOT_PLUGIN_ATTRIBUTES.has(attribute.name)) continue; |
| 575 | const id = firstArgument(attribute.args, 'id') ?? /\bid\s*:\s*['"]([^'"]+)['"]/.exec(attribute.args)?.[1]; |
| 576 | if (id) add(attribute.name, id, decl.className, decl.line); |
| 577 | } |
| 578 | } |
| 579 | const lineOf = makeLineAt(content, 1); |
| 580 | const doc = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*(?:#\[[^\n]*\n\s*)*(?:(?:abstract|final|readonly)\s+)*class\s+([A-Za-z_]\w*)/g; |
| 581 | let m: RegExpExecArray | null; |
| 582 | while ((m = doc.exec(content)) !== null) { |
| 583 | const bodyAt = m.index + 3; |
| 584 | const annotation = /^[ \t]*\*[ \t]*@([A-Z]\w*)\s*\(/gm; |
| 585 | annotation.lastIndex = 0; |
| 586 | let a: RegExpExecArray | null; |
| 587 | while ((a = annotation.exec(m[1]!)) !== null) { |
| 588 | const open = a.index + a[0].length - 1; |
| 589 | const close = matchBracket(m[1]!, open); |
| 590 | if (close < 0) continue; |
| 591 | const body = m[1]!.slice(open, close); |
| 592 | const id = /(?:^|[\s,(])id\s*=\s*"([^"]+)"/.exec(body)?.[1] ?? /^\(\s*"([^"]+)"/.exec(body)?.[1]; |
| 593 | if (id) add(a[1]!, id, m[2]!, lineOf(bodyAt + a.index + a[0].indexOf('@'))); |
| 594 | annotation.lastIndex = close; |
| 595 | } |
| 596 | } |
| 597 | return out; |
| 598 | } |
| 599 | |
| 600 | function extractDrupalPlugins( |
| 601 | filePath: string, |
no test coverage detected