* Build the list of class-level decorator scopes, sorted by position. Each * scope runs from its decorator up to the next class decorator (of any kind), * which lets a method decorator find its enclosing class regardless of how * many classes share a file.
(safe: string)
| 647 | * many classes share a file. |
| 648 | */ |
| 649 | function buildClassScopes(safe: string): ClassScope[] { |
| 650 | const defs: Array<{ kind: ClassKind; name: string; prefixOf: (a: string) => string }> = [ |
| 651 | { kind: 'controller', name: 'Controller', prefixOf: parseControllerPrefix }, |
| 652 | { kind: 'resolver', name: 'Resolver', prefixOf: () => '' }, |
| 653 | { kind: 'gateway', name: 'WebSocketGateway', prefixOf: parseGatewayNamespace }, |
| 654 | { kind: 'other', name: 'Injectable', prefixOf: () => '' }, |
| 655 | { kind: 'other', name: 'Module', prefixOf: () => '' }, |
| 656 | { kind: 'other', name: 'Catch', prefixOf: () => '' }, |
| 657 | ]; |
| 658 | |
| 659 | const raw: Array<{ kind: ClassKind; prefix: string; index: number }> = []; |
| 660 | for (const def of defs) { |
| 661 | for (const hit of findDecorators(safe, [def.name])) { |
| 662 | raw.push({ kind: def.kind, prefix: def.prefixOf(hit.args), index: hit.index }); |
| 663 | } |
| 664 | } |
| 665 | raw.sort((a, b) => a.index - b.index); |
| 666 | |
| 667 | return raw.map((r, i) => ({ |
| 668 | kind: r.kind, |
| 669 | prefix: r.prefix, |
| 670 | start: r.index, |
| 671 | end: i + 1 < raw.length ? raw[i + 1]!.index : safe.length, |
| 672 | })); |
| 673 | } |
| 674 | |
| 675 | function scopeFor(scopes: ClassScope[], index: number): ClassScope | null { |
| 676 | for (const s of scopes) { |
no test coverage detected