(info: ClassDeclInfo)
| 137 | |
| 138 | /** Build the replacement text for a migrated declaration. */ |
| 139 | const 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. */ |
| 160 | const findClassDecls = (source: ts.SourceFile): ClassDeclInfo[] => { |
no outgoing calls
no test coverage detected