Fix the undefined opts bug

This commit is contained in:
Leonid Logvinov 2019-02-07 12:30:54 +01:00
parent 7e19c944b9
commit c20285dd36
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4
3 changed files with 9 additions and 2 deletions

View File

@ -5,6 +5,10 @@
{ {
"note": "Fix a bug when smart recompilation wasn't working because of remappings", "note": "Fix a bug when smart recompilation wasn't working because of remappings",
"pr": 1575 "pr": 1575
},
{
"note": "Fix a bug when opts could not be undefined",
"pr": "TODO"
} }
] ]
}, },

View File

@ -96,12 +96,12 @@ export class Compiler {
* @return An instance of the Compiler class. * @return An instance of the Compiler class.
*/ */
constructor(opts?: CompilerOptions) { constructor(opts?: CompilerOptions) {
assert.doesConformToSchema('opts', opts, compilerOptionsSchema); const passedOpts = opts || {};
assert.doesConformToSchema('opts', passedOpts, compilerOptionsSchema);
// TODO: Look for config file in parent directories if not found in current directory // TODO: Look for config file in parent directories if not found in current directory
const config: CompilerOptions = fs.existsSync(CONFIG_FILE) const config: CompilerOptions = fs.existsSync(CONFIG_FILE)
? JSON.parse(fs.readFileSync(CONFIG_FILE).toString()) ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString())
: {}; : {};
const passedOpts = opts || {};
assert.doesConformToSchema('compiler.json', config, compilerOptionsSchema); assert.doesConformToSchema('compiler.json', config, compilerOptionsSchema);
this._contractsDir = path.resolve(passedOpts.contractsDir || config.contractsDir || DEFAULT_CONTRACTS_DIR); this._contractsDir = path.resolve(passedOpts.contractsDir || config.contractsDir || DEFAULT_CONTRACTS_DIR);
this._solcVersionIfExists = passedOpts.solcVersion || config.solcVersion; this._solcVersionIfExists = passedOpts.solcVersion || config.solcVersion;

View File

@ -23,6 +23,9 @@ describe('#Compiler', function(): void {
contractsDir, contractsDir,
contracts: constants.contracts, contracts: constants.contracts,
}; };
it('should create a Compiler with empty opts', async () => {
const _compiler = new Compiler();
});
it('should create an Exchange artifact with the correct unlinked binary', async () => { it('should create an Exchange artifact with the correct unlinked binary', async () => {
compilerOpts.contracts = ['Exchange']; compilerOpts.contracts = ['Exchange'];