* Every declaration that carries attributes. Read from the source, not from * `stripCommentsForRegex`, to which a `#[` is a comment like any other `#`.
(content: string)
| 490 | * `stripCommentsForRegex`, to which a `#[` is a comment like any other `#`. |
| 491 | */ |
| 492 | function attributedDeclarations(content: string): AttributedDeclaration[] { |
| 493 | const out: AttributedDeclaration[] = []; |
| 494 | const lineOf = makeLineAt(content, 1); |
| 495 | ATTRIBUTE_START.lastIndex = 0; |
| 496 | let m: RegExpExecArray | null; |
| 497 | while ((m = ATTRIBUTE_START.exec(content)) !== null) { |
| 498 | const start = m.index + m[0].length - 2; |
| 499 | const attributes: Attribute[] = []; |
| 500 | let at = start; |
| 501 | while (content.startsWith('#[', at)) { |
| 502 | const close = matchBracket(content, at + 1); |
| 503 | if (close < 0) break; |
| 504 | const body = /^\s*\\?([\w\\]+)\s*(\()?/.exec(content.slice(at + 2, close)); |
| 505 | if (body) { |
| 506 | const open = at + 2 + body[0].length - 1; |
| 507 | const end = body[2] ? matchBracket(content, open) : -1; |
| 508 | attributes.push({ name: body[1]!.split('\\').pop()!, args: end > 0 ? content.slice(open + 1, end) : '' }); |
| 509 | } |
| 510 | at = skipTrivia(content, close + 1); |
| 511 | } |
| 512 | ATTRIBUTE_START.lastIndex = Math.max(at, m.index + m[0].length); |
| 513 | DECLARATION.lastIndex = at; |
| 514 | const decl = DECLARATION.exec(content); |
| 515 | if (!decl) continue; |
| 516 | out.push({ attributes, line: lineOf(start), offset: at, method: decl[1], className: decl[2] }); |
| 517 | } |
| 518 | return out; |
| 519 | } |
| 520 | |
| 521 | /** The first string an attribute's arguments open with, by position or as `name:`. */ |
| 522 | function firstArgument(args: string, name: string): string | null { |
no test coverage detected