|
|
|
@ -1,6 +1,16 @@ |
|
|
|
|
const SolExplore = require('sol-explore'); |
|
|
|
|
const SolidityParser = require('solidity-parser-sc'); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Splices enclosing brackets into `contract` around `expression`; |
|
|
|
|
* @param {String} contract solidity source |
|
|
|
|
* @param {Object} expression AST node to bracket |
|
|
|
|
* @return {String} contract |
|
|
|
|
*/ |
|
|
|
|
function blockWrap(contract, expression) { |
|
|
|
|
return contract.slice(0, expression.start) + '{' + contract.slice(expression.start, expression.end) + '}' + contract.slice(expression.end); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Parses the AST tree to remove pure, constant and view modifiers |
|
|
|
|
* @param {Object} ast AST tree |
|
|
|
@ -34,6 +44,7 @@ function removeViewPureConst(ast, contract) { |
|
|
|
|
*/ |
|
|
|
|
function bracketUnbStatements(ast, contract) { |
|
|
|
|
const brkList = []; |
|
|
|
|
let offset = 0; |
|
|
|
|
SolExplore.traverse(ast, { |
|
|
|
|
enter(node, parent) { // eslint-disable-line no-loop-func
|
|
|
|
|
// If consequents
|
|
|
|
@ -83,6 +94,11 @@ function bracketUnbStatements(ast, contract) { |
|
|
|
|
check = brkList[i].end <= brkList[i - 1].end; |
|
|
|
|
} |
|
|
|
|
brkList[i].nested = check; |
|
|
|
|
const elem = Object.assign(brkList[i]); |
|
|
|
|
elem.start += offset; |
|
|
|
|
elem.end += offset; |
|
|
|
|
contract = blockWrap(contract, elem); |
|
|
|
|
offset += 2; |
|
|
|
|
} |
|
|
|
|
return contract; |
|
|
|
|
} |
|
|
|
|