(
input: ts.ClassDeclaration,
serializable: TypeSchema,
importer: (name: string, module: string) => void
)
| 3 | import type { TypeSchema } from './TypeSchema'; |
| 4 | |
| 5 | function generateFromJsonBody( |
| 6 | input: ts.ClassDeclaration, |
| 7 | serializable: TypeSchema, |
| 8 | importer: (name: string, module: string) => void |
| 9 | ) { |
| 10 | importer('JsonHelper', '@coderline/alphatab/io/JsonHelper'); |
| 11 | |
| 12 | const serializerName = `${input.name!.text}Serializer`; |
| 13 | return ts.factory.createBlock( |
| 14 | [ |
| 15 | createNodeFromSource<ts.IfStatement>( |
| 16 | `if(!m) { |
| 17 | return; |
| 18 | }`, |
| 19 | ts.SyntaxKind.IfStatement |
| 20 | ), |
| 21 | serializable.isStrict |
| 22 | ? createNodeFromSource<ts.ExpressionStatement>( |
| 23 | `JsonHelper.forEach(m, (v, k) => ${serializerName}.setProperty(obj, k, v));`, |
| 24 | ts.SyntaxKind.ExpressionStatement |
| 25 | ) |
| 26 | : createNodeFromSource<ts.ExpressionStatement>( |
| 27 | `JsonHelper.forEach(m, (v, k) => ${serializerName}.setProperty(obj, k.toLowerCase(), v));`, |
| 28 | ts.SyntaxKind.ExpressionStatement |
| 29 | ) |
| 30 | ], |
| 31 | true |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | export function createFromJsonMethod( |
| 36 | input: ts.ClassDeclaration, |
no test coverage detected