MCPcopy Create free account
hub / github.com/d1ll0n/stack-packer / generateFunctionCode

Function generateFunctionCode

src/code-gen/codegen-helpers.ts:48–76  ·  view source on GitHub ↗
(fn: CodeGenFunction)

Source from the content-addressed store, hash-verified

46}
47
48export 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
78export const buildFunctionBlock = (
79 name: string,

Callers 2

addFunctionsMethod · 0.90
generateExternalCoderFunction · 0.90

Calls 3

toNatspecFunction · 0.90
suffixLastStringFunction · 0.90
arrayifyFieldsFunction · 0.85

Tested by

no test coverage detected