(code: string)
| 13 | const contextOpaqueRe = /(?:^|[\s.])Context\s*\.\s*Opaque\s*</ |
| 14 | |
| 15 | export function getExportedModelNames(code: string): Array<string> { |
| 16 | const result: Array<string> = [] |
| 17 | const add = (name: string) => { |
| 18 | if (!result.includes(name)) result.push(name) |
| 19 | } |
| 20 | const classRe = /(^|\n)\s*export\s+class\s+(\w+)/g |
| 21 | const matches = Array.from(code.matchAll(classRe)) |
| 22 | for (const [index, match] of matches.entries()) { |
| 23 | const name = match[2]! |
| 24 | const start = match.index + match[1]!.length |
| 25 | // Take up to the next `export class` or 500 chars, whichever comes first, |
| 26 | // then trim further to only the extends clause (before the first `{`). |
| 27 | const nextClass = matches[index + 1]?.index |
| 28 | const rawWindow = code.slice(start, nextClass === undefined ? start + 500 : nextClass) |
| 29 | // Only look at the part before the class body opens. |
| 30 | const braceIdx = rawWindow.indexOf("{") |
| 31 | const extendsWindow = braceIdx === -1 ? rawWindow : rawWindow.slice(0, braceIdx) |
| 32 | if ( |
| 33 | baseClassWithEncodedRe.test(extendsWindow) |
| 34 | || (opaqueWithEncodedRe.test(extendsWindow) && !contextOpaqueRe.test(extendsWindow)) |
| 35 | || opaqueFacadeRe.test(extendsWindow) |
| 36 | // base mode: `export class X extends __X` (facade lives on the generated `__X`) |
| 37 | || new RegExp(`extends\\s+__${name}\\b`).test(extendsWindow) |
| 38 | ) { |
| 39 | add(name) |
| 40 | } |
| 41 | } |
| 42 | const facadeRe = /(^|\n)\s*export\s+const\s+(\w+)\s*:\s*\2\.Schema\s*=/g |
| 43 | for (const match of code.matchAll(facadeRe)) { |
| 44 | add(match[2]!) |
| 45 | } |
| 46 | return result |
| 47 | } |
| 48 | |
| 49 | // The extends-clause text of a model's defining class — checks the private `_X` |
| 50 | // (post-rewrite) first, then the exported `X` (pre-rewrite / already-facade). |
no test coverage detected
searching dependent graphs…