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