diff --git a/lib/instrumenter.js b/lib/instrumenter.js index 338b685..5aab842 100644 --- a/lib/instrumenter.js +++ b/lib/instrumenter.js @@ -61,8 +61,6 @@ class Instrumenter { // First, we run over the original contract to get the source mapping. let ast = SolidityParser.parse(contract.source, {range: true}); - //console.log(JSON.stringify(ast, null, ' ')) - parse[ast.type](contract, ast); const retValue = JSON.parse(JSON.stringify(contract)); // Possibly apotropaic. diff --git a/lib/parse.js b/lib/parse.js index ca053be..d2affd9 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -70,10 +70,13 @@ parse.FunctionCall = function(contract, expression, skipStatementRegistry) { } }; -parse.Conditional = function(contract, expression) { - register.statement(contract, expression); - // TODO: Investigate node structure - // There are potential substatements here we aren't measuring +parse.Conditional = function(contract, expression, skipStatementRegistry) { + if (!skipStatementRegistry){ + register.statement(contract, expression); + } + + parse[expression.condition.type] && + parse[expression.condition.type](contract, expression.condition, skipStatementRegistry); }; parse.ContractDefinition = function(contract, expression) { diff --git a/test/sources/solidity/contracts/return/ternary-return.sol b/test/sources/solidity/contracts/return/ternary-return.sol new file mode 100644 index 0000000..4887670 --- /dev/null +++ b/test/sources/solidity/contracts/return/ternary-return.sol @@ -0,0 +1,11 @@ +pragma solidity ^0.5.0; + +contract Test { + function a(uint x) public pure returns (uint) { + return x > 3 ? x : 1; + } + + function b(uint x) public pure returns (uint) { + return (x > 3) ? x : 1; + } +} diff --git a/test/units/expressions.js b/test/units/expressions.js index 8c71880..1e8d948 100644 --- a/test/units/expressions.js +++ b/test/units/expressions.js @@ -17,8 +17,13 @@ describe('generic expressions / misc', () => { util.report(info.solcOutput.errors); }); - it('should compile after instrumenting function the returns void', () => { + it('should compile after instrumenting function that returns void', () => { const info = util.instrumentAndCompile('return/empty-return'); util.report(info.solcOutput.errors); }); + + it('should compile after instrumenting function that returns via ternary conditional', () => { + const info = util.instrumentAndCompile('return/ternary-return'); + util.report(info.solcOutput.errors); + }); });