diff options
author | perissology <perissology@protonmail.com> | 2018-06-15 02:17:04 +0800 |
---|---|---|
committer | perissology <perissology@protonmail.com> | 2018-06-15 02:17:04 +0800 |
commit | 7a41a5249fcb8457cb8beb823ce9a1362cdbfa98 (patch) | |
tree | b7f03fab37dde2f652984c9aef486bde23f560d6 /packages/sol-cov/src/source_maps.ts | |
parent | 0e354e5ea1f9951088331a310999bf87c8f8f4b3 (diff) | |
download | dexon-sol-tools-7a41a5249fcb8457cb8beb823ce9a1362cdbfa98.tar dexon-sol-tools-7a41a5249fcb8457cb8beb823ce9a1362cdbfa98.tar.gz dexon-sol-tools-7a41a5249fcb8457cb8beb823ce9a1362cdbfa98.tar.bz2 dexon-sol-tools-7a41a5249fcb8457cb8beb823ce9a1362cdbfa98.tar.lz dexon-sol-tools-7a41a5249fcb8457cb8beb823ce9a1362cdbfa98.tar.xz dexon-sol-tools-7a41a5249fcb8457cb8beb823ce9a1362cdbfa98.tar.zst dexon-sol-tools-7a41a5249fcb8457cb8beb823ce9a1362cdbfa98.zip |
Collect coverage for provided sources
When solidity generates source maps during contract compilation, the
contracts are referred to by an id, which corresponds to an array index.
We may not want to cover all sources that were included in a compilation,
but because we use array indexes (vs. the id that is provided by solidity
compiler) to map the contract to the sourceMap, the provided sourceCodes
array must include the code at the correct index. This can result in
empty slots in the sourceCodes array.
This commit allows the coverage to only be collected for the contracts
with provided sourceCode.
Diffstat (limited to 'packages/sol-cov/src/source_maps.ts')
-rw-r--r-- | packages/sol-cov/src/source_maps.ts | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/packages/sol-cov/src/source_maps.ts b/packages/sol-cov/src/source_maps.ts index f9503e16c..c95c7d2b0 100644 --- a/packages/sol-cov/src/source_maps.ts +++ b/packages/sol-cov/src/source_maps.ts @@ -12,6 +12,9 @@ export interface SourceLocation { } export function getLocationByOffset(str: string): LocationByOffset { + if (_.isUndefined(str)) { + return {}; + } const locationByOffset: LocationByOffset = { 0: { line: 1, column: 0 } }; let currentOffset = 0; for (const char of str.split('')) { @@ -56,7 +59,7 @@ export function parseSourceMap( length, fileIndex, }; - if (parsedEntry.fileIndex !== -1) { + if (parsedEntry.fileIndex !== -1 && !_.isUndefined(locationByOffsetByFileIndex[parsedEntry.fileIndex])) { const sourceRange = { location: { start: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset], |