From c20285dd3655a9685b52205229e675c797cd4418 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 7 Feb 2019 12:30:54 +0100 Subject: Fix the undefined opts bug --- packages/sol-compiler/CHANGELOG.json | 4 ++++ packages/sol-compiler/src/compiler.ts | 4 ++-- packages/sol-compiler/test/compiler_test.ts | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json index dd65f3aed..a0d2250aa 100644 --- a/packages/sol-compiler/CHANGELOG.json +++ b/packages/sol-compiler/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Fix a bug when smart recompilation wasn't working because of remappings", "pr": 1575 + }, + { + "note": "Fix a bug when opts could not be undefined", + "pr": "TODO" } ] }, diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index c5dea1155..686ba4f82 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -96,12 +96,12 @@ export class Compiler { * @return An instance of the Compiler class. */ 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 const config: CompilerOptions = fs.existsSync(CONFIG_FILE) ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString()) : {}; - const passedOpts = opts || {}; assert.doesConformToSchema('compiler.json', config, compilerOptionsSchema); this._contractsDir = path.resolve(passedOpts.contractsDir || config.contractsDir || DEFAULT_CONTRACTS_DIR); this._solcVersionIfExists = passedOpts.solcVersion || config.solcVersion; diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts index 464aa8bb6..5cc7e41ce 100644 --- a/packages/sol-compiler/test/compiler_test.ts +++ b/packages/sol-compiler/test/compiler_test.ts @@ -23,6 +23,9 @@ describe('#Compiler', function(): void { contractsDir, 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 () => { compilerOpts.contracts = ['Exchange']; -- cgit v1.2.3