(
program: ts.Program,
input: ts.ClassDeclaration,
importer: (name: string, module: string) => void
)
| 259 | } |
| 260 | |
| 261 | function generateCloneBody( |
| 262 | program: ts.Program, |
| 263 | input: ts.ClassDeclaration, |
| 264 | importer: (name: string, module: string) => void |
| 265 | ): ts.Block { |
| 266 | const propertiesToSerialize = input.members |
| 267 | .filter(m => ts.isPropertyDeclaration(m) && isCloneMember(m)) |
| 268 | .map(m => m as ts.PropertyDeclaration); |
| 269 | |
| 270 | const bodyStatements = propertiesToSerialize.reduce((stmts, prop) => { |
| 271 | stmts.push(...generateClonePropertyStatements(prop, program, importer)); |
| 272 | return stmts; |
| 273 | }, [] as ts.Statement[]); |
| 274 | |
| 275 | return ts.factory.createBlock( |
| 276 | [ |
| 277 | // const clone = new Type(); |
| 278 | ts.factory.createVariableStatement( |
| 279 | undefined, |
| 280 | ts.factory.createVariableDeclarationList( |
| 281 | [ |
| 282 | ts.factory.createVariableDeclaration( |
| 283 | 'clone', |
| 284 | undefined, |
| 285 | undefined, |
| 286 | ts.factory.createNewExpression(ts.factory.createIdentifier(input.name!.text), undefined, []) |
| 287 | ) |
| 288 | ], |
| 289 | ts.NodeFlags.Const |
| 290 | ) |
| 291 | ), |
| 292 | ...bodyStatements, |
| 293 | // return json; |
| 294 | ts.factory.createReturnStatement(ts.factory.createIdentifier('clone')) |
| 295 | ], |
| 296 | true |
| 297 | ); |
| 298 | } |
| 299 | |
| 300 | function createCloneMethod( |
| 301 | program: ts.Program, |
no test coverage detected