From 1ece2283bd1c3a9ad8968df657c2699098df8d67 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 12 Nov 2019 16:44:21 +0530 Subject: [PATCH] more types improved --- remix-tests/src/compiler.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/remix-tests/src/compiler.ts b/remix-tests/src/compiler.ts index 52ca31590a..a87cc689b0 100644 --- a/remix-tests/src/compiler.ts +++ b/remix-tests/src/compiler.ts @@ -75,7 +75,7 @@ const isBrowser = !(typeof (window) === 'undefined' || userAgent.indexOf(' elect // TODO: replace this with remix's own compiler code export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: any, cb: Function) { let compiler: any - let accounts: any[] = opts.accounts || [] + const accounts: any[] = opts.accounts || [] const sources: SrcIfc = { 'tests.sol': { content: require('../sol/tests.sol.js') }, 'remix_tests.sol': { content: require('../sol/tests.sol.js') }, @@ -130,19 +130,20 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts: } } -export function compileContractSources(sources: SrcIfc, versionUrl: any, usingWorker: any, importFileCb: any, opts: any, cb: Function) { +export function compileContractSources(sources: SrcIfc, versionUrl: any, usingWorker: boolean, importFileCb: any, opts: any, cb: Function) { let compiler, filepath: string - let accounts = opts.accounts || [] + const accounts = opts.accounts || [] // Iterate over sources keys. Inject test libraries. Inject test library import statements. if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) { sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') } sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) } } - const s = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm - let includeTestLibs = '\nimport \'remix_tests.sol\';\n' + const testFileImportRegEx: RegExp = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm + + let includeTestLibs: string = '\nimport \'remix_tests.sol\';\n' for (let file in sources) { - const c = sources[file].content - if (file.indexOf('_test.sol') > 0 && c && regexIndexOf(c, s) < 0) { + const c: string = sources[file].content + if (file.includes('_test.sol') && c && regexIndexOf(c, testFileImportRegEx) < 0) { sources[file].content = includeTestLibs.concat(c) } }