(fn: CodeGenFunction)
| 46 | } |
| 47 | |
| 48 | export const generateFunctionCode = (fn: CodeGenFunction): ArrayJoinInput<string>[] => { |
| 49 | const inputs = arrayifyFields( |
| 50 | `function ${fn.name}(`, |
| 51 | fn.inputs.map(f => f.definition), |
| 52 | `) ${fn.location}${fn.visibility ? ` ${fn.visibility}` : ''}` |
| 53 | ); |
| 54 | const code: ArrayJoinInput<string>[] = [ |
| 55 | ...(fn.natspecLines ? toNatspec(fn.natspecLines) : []), |
| 56 | ...inputs.slice(0, inputs.length - 1) |
| 57 | ]; |
| 58 | |
| 59 | if (fn.outputs.length) { |
| 60 | suffixLastString(inputs, ' returns ('); |
| 61 | code.push(...arrayifyFields( |
| 62 | inputs[inputs.length - 1] as string, |
| 63 | fn.outputs.map(f => f.definition), |
| 64 | `) {` |
| 65 | )); |
| 66 | } else { |
| 67 | suffixLastString(inputs, ' {') |
| 68 | code.push(...arrayifyFields( |
| 69 | inputs[inputs.length - 1] as string, |
| 70 | '', |
| 71 | `` |
| 72 | )) |
| 73 | } |
| 74 | code.push(fn.body, '}'); |
| 75 | return code; |
| 76 | } |
| 77 | |
| 78 | export const buildFunctionBlock = ( |
| 79 | name: string, |
no test coverage detected