|
|
|
@ -26,42 +26,47 @@ module.exports.run = function r(contract) { |
|
|
|
|
let keepRunning = true; |
|
|
|
|
|
|
|
|
|
while (keepRunning) { |
|
|
|
|
const ast = SolidityParser.parse(contract); |
|
|
|
|
keepRunning = false; |
|
|
|
|
SolExplore.traverse(ast, { |
|
|
|
|
enter(node, parent) { // eslint-disable-line no-loop-func
|
|
|
|
|
// If consequents
|
|
|
|
|
if (node.type === 'IfStatement' && node.consequent.type !== 'BlockStatement') { |
|
|
|
|
contract = blockWrap(contract, node.consequent); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
// If alternates
|
|
|
|
|
} else if ( |
|
|
|
|
node.type === 'IfStatement' && |
|
|
|
|
node.alternate && |
|
|
|
|
node.alternate.type !== 'BlockStatement') { |
|
|
|
|
contract = blockWrap(contract, node.alternate); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
// Loops
|
|
|
|
|
} else if ( |
|
|
|
|
(node.type === 'ForStatement' || node.type === 'WhileStatement') && |
|
|
|
|
node.body.type !== 'BlockStatement') { |
|
|
|
|
contract = blockWrap(contract, node.body); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
} else if (node.type === 'FunctionDeclaration' && node.modifiers) { |
|
|
|
|
// We want to remove constant / pure / view from functions
|
|
|
|
|
for (let i = 0; i < node.modifiers.length; i++) { |
|
|
|
|
if (['pure', 'constant', 'view'].indexOf(node.modifiers[i].name) > -1) { |
|
|
|
|
contract = contract.slice(0, node.modifiers[i].start) + contract.slice(node.modifiers[i].end); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
try { |
|
|
|
|
const ast = SolidityParser.parse(contract); |
|
|
|
|
keepRunning = false; |
|
|
|
|
SolExplore.traverse(ast, { |
|
|
|
|
enter(node, parent) { // eslint-disable-line no-loop-func
|
|
|
|
|
// If consequents
|
|
|
|
|
if (node.type === 'IfStatement' && node.consequent.type !== 'BlockStatement') { |
|
|
|
|
contract = blockWrap(contract, node.consequent); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
// If alternates
|
|
|
|
|
} else if ( |
|
|
|
|
node.type === 'IfStatement' && |
|
|
|
|
node.alternate && |
|
|
|
|
node.alternate.type !== 'BlockStatement') { |
|
|
|
|
contract = blockWrap(contract, node.alternate); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
// Loops
|
|
|
|
|
} else if ( |
|
|
|
|
(node.type === 'ForStatement' || node.type === 'WhileStatement') && |
|
|
|
|
node.body.type !== 'BlockStatement') { |
|
|
|
|
contract = blockWrap(contract, node.body); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
} else if (node.type === 'FunctionDeclaration' && node.modifiers) { |
|
|
|
|
// We want to remove constant / pure / view from functions
|
|
|
|
|
for (let i = 0; i < node.modifiers.length; i++) { |
|
|
|
|
if (['pure', 'constant', 'view'].indexOf(node.modifiers[i].name) > -1) { |
|
|
|
|
contract = contract.slice(0, node.modifiers[i].start) + contract.slice(node.modifiers[i].end); |
|
|
|
|
keepRunning = true; |
|
|
|
|
this.stopTraversal(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} catch (err) { |
|
|
|
|
contract = err; |
|
|
|
|
keepRunning = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return contract; |
|
|
|
|
}; |
|
|
|
|