aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/src/source_maps.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-01-14 21:48:59 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2019-01-14 21:52:00 +0800
commit83b46cbf71abd897b434ff510035171297a51255 (patch)
treedd2c80a54e6a9bd2f2058afa587f4ad2c0a6b6ce /packages/sol-tracing-utils/src/source_maps.ts
parent4689309857126669563dc9ea0e912ec9cec74157 (diff)
downloaddexon-sol-tools-83b46cbf71abd897b434ff510035171297a51255.tar
dexon-sol-tools-83b46cbf71abd897b434ff510035171297a51255.tar.gz
dexon-sol-tools-83b46cbf71abd897b434ff510035171297a51255.tar.bz2
dexon-sol-tools-83b46cbf71abd897b434ff510035171297a51255.tar.lz
dexon-sol-tools-83b46cbf71abd897b434ff510035171297a51255.tar.xz
dexon-sol-tools-83b46cbf71abd897b434ff510035171297a51255.tar.zst
dexon-sol-tools-83b46cbf71abd897b434ff510035171297a51255.zip
Rename mappins to have a direct naming scheme instead of a reverse one
Diffstat (limited to 'packages/sol-tracing-utils/src/source_maps.ts')
-rw-r--r--packages/sol-tracing-utils/src/source_maps.ts24
1 files changed, 12 insertions, 12 deletions
diff --git a/packages/sol-tracing-utils/src/source_maps.ts b/packages/sol-tracing-utils/src/source_maps.ts
index ae004c2ec..0a2d3c88a 100644
--- a/packages/sol-tracing-utils/src/source_maps.ts
+++ b/packages/sol-tracing-utils/src/source_maps.ts
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import { getPcToInstructionIndexMapping } from './instructions';
-import { LocationByOffset, SourceRange } from './types';
+import { OffsetToLocation, SourceRange } from './types';
const RADIX = 10;
@@ -15,19 +15,19 @@ export interface SourceLocation {
* Receives a string with newlines and returns a map of byte offset to LineColumn
* @param str A string to process
*/
-export function getLocationByOffset(str: string): LocationByOffset {
- const locationByOffset: LocationByOffset = { 0: { line: 1, column: 0 } };
+export function getOffsetToLocation(str: string): OffsetToLocation {
+ const offsetToLocation: OffsetToLocation = { 0: { line: 1, column: 0 } };
let currentOffset = 0;
for (const char of str.split('')) {
- const location = locationByOffset[currentOffset];
+ const location = offsetToLocation[currentOffset];
const isNewline = char === '\n';
- locationByOffset[currentOffset + 1] = {
+ offsetToLocation[currentOffset + 1] = {
line: location.line + (isNewline ? 1 : 0),
column: isNewline ? 0 : location.column + 1,
};
currentOffset++;
}
- return locationByOffset;
+ return offsetToLocation;
}
/**
@@ -46,9 +46,9 @@ export function parseSourceMap(
): { [programCounter: number]: SourceRange } {
const bytecode = Uint8Array.from(Buffer.from(bytecodeHex, 'hex'));
const pcToInstructionIndex: { [programCounter: number]: number } = getPcToInstructionIndexMapping(bytecode);
- const locationByOffsetByFileIndex: { [fileIndex: number]: LocationByOffset } = {};
+ const fileIndexToOffsetToLocation: { [fileIndex: number]: OffsetToLocation } = {};
_.map(sourceCodes, (sourceCode: string, fileIndex: number) => {
- locationByOffsetByFileIndex[fileIndex] = _.isUndefined(sourceCode) ? {} : getLocationByOffset(sourceCode);
+ fileIndexToOffsetToLocation[fileIndex] = _.isUndefined(sourceCode) ? {} : getOffsetToLocation(sourceCode);
});
const entries = srcMap.split(';');
let lastParsedEntry: SourceLocation = {} as any;
@@ -69,12 +69,12 @@ export function parseSourceMap(
length,
fileIndex,
};
- if (parsedEntry.fileIndex !== -1 && !_.isUndefined(locationByOffsetByFileIndex[parsedEntry.fileIndex])) {
- const locationByOffset = locationByOffsetByFileIndex[parsedEntry.fileIndex];
+ if (parsedEntry.fileIndex !== -1 && !_.isUndefined(fileIndexToOffsetToLocation[parsedEntry.fileIndex])) {
+ const offsetToLocation = fileIndexToOffsetToLocation[parsedEntry.fileIndex];
const sourceRange = {
location: {
- start: locationByOffset[parsedEntry.offset],
- end: locationByOffset[parsedEntry.offset + parsedEntry.length],
+ start: offsetToLocation[parsedEntry.offset],
+ end: offsetToLocation[parsedEntry.offset + parsedEntry.length],
},
fileName: sources[parsedEntry.fileIndex],
};