Files
metabuilder/tools/refactoring/io/build-function-content.ts

31 lines
765 B
TypeScript

import { FunctionInfo } from '../lambda/types'
export function buildFunctionContent(func: FunctionInfo, imports: string[], types: string[]): string {
let content = ''
if (imports.length > 0) {
content += imports.join('\n') + '\n\n'
}
if (types.length > 0) {
content += types.join('\n') + '\n\n'
}
if (func.comments.length > 0) {
content += func.comments.join('\n') + '\n'
}
const asyncKeyword = func.isAsync ? 'async ' : ''
const exportKeyword = 'export '
content += `${exportKeyword}${asyncKeyword}function ${func.name}${func.params}${func.returnType} {\n`
const bodyLines = func.body.split('\n')
const actualBody = bodyLines.slice(1, -1).join('\n')
content += actualBody + '\n'
content += '}\n'
return content
}