MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / buildReplacement

Function buildReplacement

scripts/migrate-schema-class.ts:139–157  ·  view source on GitHub ↗
(info: ClassDeclInfo)

Source from the content-addressed store, hash-verified

137
138/** Build the replacement text for a migrated declaration. */
139const buildReplacement = (info: ClassDeclInfo): string => {
140 const exportPrefix = info.isExported ? "export " : "";
141 const identifierAnnotation =
142 info.kind === "Class" && info.identifier && info.identifier !== info.name
143 ? `.annotate({ identifier: ${JSON.stringify(info.identifier)} })`
144 : "";
145
146 if (info.kind === "Class") {
147 return (
148 `${exportPrefix}const ${info.name} = Schema.Struct(${info.fieldsText})${identifierAnnotation};\n` +
149 `${exportPrefix}type ${info.name} = typeof ${info.name}.Type;`
150 );
151 }
152 // TaggedClass
153 return (
154 `${exportPrefix}const ${info.name} = Schema.TaggedStruct(${JSON.stringify(info.identifier)}, ${info.fieldsText});\n` +
155 `${exportPrefix}type ${info.name} = typeof ${info.name}.Type;`
156 );
157};
158
159/** Find all migrate-able ClassDeclarations in a file. */
160const findClassDecls = (source: ts.SourceFile): ClassDeclInfo[] => {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected