(classText: string, name: string, indent: string)
| 248 | // (lighter than the Opaque class). Returns null for any body content (statics, |
| 249 | // getters, methods) or non-Opaque bases — those keep the class form. |
| 250 | function tryStructPrivate(classText: string, name: string, indent: string): string | null { |
| 251 | const open = findClassBodyOpen(classText, 0) |
| 252 | if (open === -1) return null |
| 253 | const close = findMatchingBrace(classText, open) |
| 254 | if (close === -1) return null |
| 255 | const body = classText.slice(open + 1, close).replace(/\/\/[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "").trim() |
| 256 | if (body.length > 0) return null // has statics/getters/methods -> keep class |
| 257 | // Extract STRUCT from `extends (prefix)Opaque<X, X.Encoded>()(STRUCT)`. |
| 258 | const m = /\bextends\s+(?:[A-Za-z_$][\w$]*\.)?Opaque\s*<[^(]*>\s*\(\s*\)\s*\(/.exec(classText.slice(0, open)) |
| 259 | if (!m) return null // OpaqueType/OpaqueShape/Class/etc -> keep class form |
| 260 | const argOpen = m.index + m[0].length - 1 // index of the `(` before STRUCT |
| 261 | let depth = 0 |
| 262 | let k = argOpen |
| 263 | for (; k < classText.length; k++) { |
| 264 | if (classText[k] === "(") depth++ |
| 265 | else if (classText[k] === ")") { |
| 266 | depth-- |
| 267 | if (depth === 0) break |
| 268 | } |
| 269 | } |
| 270 | const struct = classText.slice(argOpen + 1, k).trim() |
| 271 | return `${indent}const _${name} = ${struct}` |
| 272 | } |
| 273 | |
| 274 | function syncFacade(source: string, modelNames: ReadonlyArray<string>, enabled: boolean): string { |
| 275 | let out = source |
no test coverage detected
searching dependent graphs…