From fd9d44bcdcd66f966ec3054cf777fd1a7fdd04dc Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Wed, 10 Oct 2018 17:47:54 -0700 Subject: [PATCH] Add returns to function declaration --- packages/sol-meta/src/unparser.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/sol-meta/src/unparser.ts b/packages/sol-meta/src/unparser.ts index 9631e0f7f3..b4f6f81767 100644 --- a/packages/sol-meta/src/unparser.ts +++ b/packages/sol-meta/src/unparser.ts @@ -53,11 +53,14 @@ const visitor = { `modifier ${name}${Array.isArray(parameters) ? '' : unparse(parameters)} ${unparse(body)}`, // Note: when there is no parameter block, instead of an ASTNode there is a [] - FunctionDefinition: ({visibility, name, parameters, body, modifiers, isConstructor, stateMutability}) => + FunctionDefinition: ({visibility, name, parameters, body, modifiers, isConstructor, stateMutability, returnParameters}) => // TODO Return type (isConstructor ? 'constructor' : `function ${name}`) + - unparse(parameters) + ' ' + - (visibility && visibility != 'default' ? visibility + ' ' : '') + (stateMutability || '') + '\n' + - indent(modifiers.map(unparse).join('\n')) + '\n' + + unparse(parameters) + '\n' + + indent( + (visibility && visibility != 'default' ? visibility + ' ' : '') + (stateMutability || '') + + modifiers.map(unparse).join('\n') + + (returnParameters ? `\nreturns ${unparse(returnParameters)}` : '') + ) + '\n' + (body ? unparse(body) : ';'), ParameterList: ({parameters}) => @@ -79,7 +82,7 @@ const visitor = { (initialValue ? ` = ${unparse(initialValue)};` : ';'), ExpressionStatement: ({expression}) => - `${unparse(expression)};`, + `${unparen(unparse(expression))};`, EmitStatement: ({eventCall}) => `emit ${unparen(unparse(eventCall))};`, @@ -195,7 +198,7 @@ const visitor = { `switch ${unparse(expression)}\n${cases.map(unparse).join('\n')}`, AssemblyCase: ({value, block}) => - `case ${unparse(value)} ${unparse(block)}` + `case ${unparse(value)} ${unparse(block)}`, DecimalNumber: ({ value }) => value,