diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-18 21:01:18 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-03-18 21:01:18 +0800 |
commit | 4948551703fb3cb9f8470d9f4a61a9a5473e5afa (patch) | |
tree | 2e7d4d2e9c98cb6bebf7bdd17444d4b351220018 /packages/sol-cov/src/source_maps.ts | |
parent | d7bf003d511321ec6cb8814cb1549c46b4efba86 (diff) | |
parent | d4c1b3b0bd26e730ce6687469cdf7283877543e1 (diff) | |
download | dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.gz dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.bz2 dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.lz dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.xz dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.zst dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.zip |
merge development
Diffstat (limited to 'packages/sol-cov/src/source_maps.ts')
-rw-r--r-- | packages/sol-cov/src/source_maps.ts | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/packages/sol-cov/src/source_maps.ts b/packages/sol-cov/src/source_maps.ts index 9b3ea9e24..694171442 100644 --- a/packages/sol-cov/src/source_maps.ts +++ b/packages/sol-cov/src/source_maps.ts @@ -12,12 +12,12 @@ export interface SourceLocation { } export function getLocationByOffset(str: string): LocationByOffset { - const locationByOffset: LocationByOffset = {}; + const locationByOffset: LocationByOffset = { 0: { line: 1, column: 0 } }; let currentOffset = 0; for (const char of str.split('')) { - const location = locationByOffset[currentOffset - 1] || { line: 1, column: 0 }; + const location = locationByOffset[currentOffset]; const isNewline = char === '\n'; - locationByOffset[currentOffset] = { + locationByOffset[currentOffset + 1] = { line: location.line + (isNewline ? 1 : 0), column: isNewline ? 0 : location.column + 1, }; @@ -59,9 +59,8 @@ export function parseSourceMap( if (parsedEntry.fileIndex !== -1) { const sourceRange = { location: { - start: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset - 1], - end: - locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset + parsedEntry.length - 1], + start: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset], + end: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset + parsedEntry.length], }, fileName: sources[parsedEntry.fileIndex], }; |