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

Function syncCtor

packages/eslint-codegen-model/src/cli.ts:50–66  ·  view source on GitHub ↗

* Keep each model's `Opaque` base-class clause in sync with the block mode (idempotent): * - make → `S.OpaqueShape ` * - type → `S.OpaqueType ` * - plain → `S.Opaque ` (revert) * * Only `Opaque`-family clauses for the model's own `Self`/`

(source: string, modelNames: ReadonlyArray<string>, mode: CtorMode)

Source from the content-addressed store, hash-verified

48 * `<X|X.Type, X.Encoded[, X.Make]>`); `Class`/`TaggedClass` models are left untouched.
49 */
50function syncCtor(source: string, modelNames: ReadonlyArray<string>, mode: CtorMode): string {
51 let out = source
52 for (const name of modelNames) {
53 const n = escapeRe(name)
54 const re = new RegExp(
55 `((?:[A-Za-z_$][\\w$]*\\.)?)(?:Opaque|OpaqueType|OpaqueShape)<\\s*${n}(?:\\.Type)?\\s*,\\s*${n}\\.Encoded(?:\\s*,\\s*${n}\\.Make)?\\s*>`,
56 "g"
57 )
58 const target = mode === "make"
59 ? `$1OpaqueShape<${name}.Type, ${name}.Encoded, ${name}.Make>`
60 : mode === "type"
61 ? `$1OpaqueType<${name}.Type, ${name}.Encoded>`
62 : `$1Opaque<${name}, ${name}.Encoded>`
63 out = out.replace(re, target)
64 }
65 return out
66}
67
68function findMatchingBrace(source: string, openIndex: number): number {
69 let depth = 0

Callers 1

syncModelSourceFunction · 0.85

Calls 2

escapeReFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…