| 124 | * argument is the literal `true` (Roku BrightScript has no named args). |
| 125 | */ |
| 126 | export function extractBrightScriptNavigationCalls( |
| 127 | content: string, |
| 128 | helperNames: string[] |
| 129 | ): ShowScreenCall[] { |
| 130 | const out: ShowScreenCall[] = []; |
| 131 | if (helperNames.length === 0) return out; |
| 132 | const lines = content.split("\n"); |
| 133 | const alternation = helperNames.map((h) => h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"); |
| 134 | const pattern = new RegExp( |
| 135 | `\\b(?:${alternation})\\s*\\(\\s*([^),]+?)\\s*(?:,\\s*(true|false|\\w+))?\\s*\\)`, |
| 136 | "gi" |
| 137 | ); |
| 138 | for (let i = 0; i < lines.length; i++) { |
| 139 | const line = lines[i]; |
| 140 | pattern.lastIndex = 0; |
| 141 | let m: RegExpExecArray | null; |
| 142 | while ((m = pattern.exec(line)) !== null) { |
| 143 | const target = m[1].trim(); |
| 144 | // Skip obvious non-targets (empty string literal, string literal, number) |
| 145 | if (!target || /^["']/.test(target) || /^\d/.test(target)) continue; |
| 146 | const second = (m[2] ?? "").trim().toLowerCase(); |
| 147 | out.push({ |
| 148 | target, |
| 149 | modal: second === "true", |
| 150 | helper: "show", |
| 151 | line: i + 1, |
| 152 | }); |
| 153 | } |
| 154 | } |
| 155 | return out; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Extract screen-stack navigation call-sites. |