Merge pull request #156 from sc-forks/fix/parse-everything

Handle *.sol files that are invalid Solidity
pull/117/merge
c-g-e-w-e-k-e- 7 years ago committed by GitHub
commit 4342743e1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      lib/app.js
  2. 5
      lib/preprocessor.js
  3. 1
      test/util/mockTruffle.js

@ -286,9 +286,15 @@ class App {
postProcessPure(env) {
shell.ls(`${env}/**/*.sol`).forEach(file => {
const contractPath = this.platformNeutralPath(file);
let contract = fs.readFileSync(contractPath).toString();
contract = preprocessor.run(contract);
fs.writeFileSync(contractPath, contract);
const contract = fs.readFileSync(contractPath).toString();
const contractProcessed = preprocessor.run(contract);
if (contractProcessed.name && contractProcessed.name === 'SyntaxError' && file.slice(-15) !== 'SimpleError.sol') {
console.log(`Warning: The file at ${file} was identified as a Solidity Contract, ` +
'but did not parse correctly. You may ignore this warning if it is not a Solidity file, ' +
'or your project does not use it');
} else {
fs.writeFileSync(contractPath, contractProcessed);
}
});
}

@ -26,6 +26,7 @@ module.exports.run = function r(contract) {
let keepRunning = true;
while (keepRunning) {
try {
const ast = SolidityParser.parse(contract);
keepRunning = false;
SolExplore.traverse(ast, {
@ -62,6 +63,10 @@ module.exports.run = function r(contract) {
}
},
});
} catch (err) {
contract = err;
keepRunning = false;
}
}
return contract;
};

@ -51,6 +51,7 @@ module.exports.install = function install(contract, test, config, _trufflejs, _t
shell.mkdir('./mock/contracts');
shell.mkdir('./mock/migrations');
shell.mkdir('./mock/assets');
shell.cp('./test/sources/cli/SimpleError.sol', './mock/assets/SimpleError.sol');
shell.mkdir('./mock/node_modules');
shell.mkdir('./mock/test');

Loading…
Cancel
Save