prepare_report.js: Replace var with const/let + minor cleanup

This commit is contained in:
Kamil Śliwak 2020-12-21 20:47:00 +01:00
parent 42786c2d29
commit a036cbea19

View File

@ -1,42 +1,40 @@
#!/usr/bin/env node #!/usr/bin/env node
var process = require('process') const process = require('process')
var fs = require('fs') const fs = require('fs')
var compiler = require('./solc-js/wrapper.js')(require('./solc-js/soljson.js')) const compiler = require('./solc-js/wrapper.js')(require('./solc-js/soljson.js'))
for (var optimize of [false, true]) for (const optimize of [false, true])
{ {
for (var filename of process.argv.slice(2)) for (const filename of process.argv.slice(2))
{ {
if (filename !== undefined) if (filename !== undefined)
{ {
var inputs = {} const input = {
inputs[filename] = { content: fs.readFileSync(filename).toString() }
var input = {
language: 'Solidity', language: 'Solidity',
sources: inputs, sources: {
[filename]: {content: fs.readFileSync(filename).toString()}
},
settings: { settings: {
optimizer: { enabled: optimize }, optimizer: {enabled: optimize},
outputSelection: { '*': { '*': ['evm.bytecode.object', 'metadata'] } }, outputSelection: {'*': {'*': ['evm.bytecode.object', 'metadata']}},
"modelChecker": { "engine": "none" } "modelChecker": {"engine": "none"}
} }
} }
var result = JSON.parse(compiler.compile(JSON.stringify(input)))
const result = JSON.parse(compiler.compile(JSON.stringify(input)))
if ( if (
!('contracts' in result) || !('contracts' in result) ||
Object.keys(result['contracts']).length === 0 || Object.keys(result['contracts']).length === 0 ||
!result['contracts'][filename] || !result['contracts'][filename] ||
Object.keys(result['contracts'][filename]).length === 0 Object.keys(result['contracts'][filename]).length === 0
) )
{
// NOTE: do not exit here because this may be run on source which cannot be compiled // NOTE: do not exit here because this may be run on source which cannot be compiled
console.log(filename + ': ERROR') console.log(filename + ': ERROR')
}
else else
for (const contractName in result['contracts'][filename])
{ {
for (var contractName in result['contracts'][filename]) const contractData = result['contracts'][filename][contractName];
{
var contractData = result['contracts'][filename][contractName];
if (contractData.evm !== undefined && contractData.evm.bytecode !== undefined) if (contractData.evm !== undefined && contractData.evm.bytecode !== undefined)
console.log(filename + ':' + contractName + ' ' + contractData.evm.bytecode.object) console.log(filename + ':' + contractName + ' ' + contractData.evm.bytecode.object)
else else
@ -45,5 +43,4 @@ for (var optimize of [false, true])
} }
} }
} }
}
} }