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

Function buildFunctionBlock

src/code-gen/codegen-helpers.ts:78–107  ·  view source on GitHub ↗
(
  name: string,
  input: string[] | string,
  output: string[] | string,
  lines: ArrayJoinInput<string>
)

Source from the content-addressed store, hash-verified

76}
77
78export const buildFunctionBlock = (
79 name: string,
80 input: string[] | string,
81 output: string[] | string,
82 lines: ArrayJoinInput<string>
83) => {
84 const withInputs = arrayifyFields(
85 `function ${name}(`,
86 input,
87 `) internal pure`
88 );
89 let outputs: ArrayJoinInput<string>[] = []
90 if (output.length) {
91 suffixLastString(withInputs, ' returns (');
92 outputs = arrayifyFields(
93 withInputs[withInputs.length - 1] as string,
94 output,
95 `) {`
96 );
97 } else {
98 suffixLastString(withInputs, ' {')
99 outputs = arrayifyFields(
100 withInputs[withInputs.length - 1] as string,
101 '',
102 ``
103 );
104 }
105 const allButLastInput = withInputs.slice(0, withInputs.length - 1);
106 return [...allButLastInput, ...outputs, lines, "}"];
107};
108
109export function buildImportStatement(file: string, imports: string[]) {
110 if (imports.length == 0) return [`import "./${file}";`];

Callers 3

getThrowFunctionFunction · 0.90
getEmitFunctionFunction · 0.90
getCallFunctionFunction · 0.90

Calls 2

suffixLastStringFunction · 0.90
arrayifyFieldsFunction · 0.85

Tested by

no test coverage detected