MCPcopy Create free account
hub / github.com/effect-app/libs / tryStructPrivate

Function tryStructPrivate

packages/eslint-codegen-model/src/cli.ts:250–272  ·  view source on GitHub ↗
(classText: string, name: string, indent: string)

Source from the content-addressed store, hash-verified

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.
250function 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
274function syncFacade(source: string, modelNames: ReadonlyArray<string>, enabled: boolean): string {
275 let out = source

Callers 1

syncFacadeFunction · 0.85

Calls 4

findClassBodyOpenFunction · 0.85
findMatchingBraceFunction · 0.85
execMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…