From a9541d8218294047201b8a0f1447deae0912bae1 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 15 Dec 2020 14:29:14 +0530 Subject: [PATCH] source imports updated --- .../src/source/offsetToLineColumnConverter.ts | 7 +++--- .../src/source/sourceLocationTracker.ts | 22 ++++++++----------- .../src/source/sourceMappingDecoder.ts | 5 ++--- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/libs/remix-debug/src/source/offsetToLineColumnConverter.ts b/libs/remix-debug/src/source/offsetToLineColumnConverter.ts index ac943d514c..f2089cb71e 100644 --- a/libs/remix-debug/src/source/offsetToLineColumnConverter.ts +++ b/libs/remix-debug/src/source/offsetToLineColumnConverter.ts @@ -1,5 +1,5 @@ 'use strict' -const SourceMappingDecoder = require('./sourceMappingDecoder') +import { getLinebreakPositions, convertOffsetToLineColumn } from './sourceMappingDecoder' export class OffsetToColumnConverter { @@ -8,7 +8,6 @@ export class OffsetToColumnConverter { constructor(compilerEvent) { this.lineBreakPositionsByContent = {} - this.sourceMappingDecoder = new SourceMappingDecoder() if (compilerEvent) { compilerEvent.register('compilationFinished', (success, data, source) => { this.clear() @@ -23,12 +22,12 @@ export class OffsetToColumnConverter { // source id was string before. in newer versions it has been changed to an integer so we need to check the type here if (typeof source.id === 'string') source.id = parseInt(source.id, 10) if (source.id === file) { - this.lineBreakPositionsByContent[file] = this.sourceMappingDecoder.getLinebreakPositions(sources[filename].content) + this.lineBreakPositionsByContent[file] = getLinebreakPositions(sources[filename].content) break } } } - return this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) + return convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) } clear () { diff --git a/libs/remix-debug/src/source/sourceLocationTracker.ts b/libs/remix-debug/src/source/sourceLocationTracker.ts index f491c0697b..006fd6c34b 100644 --- a/libs/remix-debug/src/source/sourceLocationTracker.ts +++ b/libs/remix-debug/src/source/sourceLocationTracker.ts @@ -1,10 +1,8 @@ 'use strict' -const EventManager = require('../eventManager') -const helper = require('../trace/traceHelper') -const SourceMappingDecoder = require('./sourceMappingDecoder') -const remixLib = require('@remix-project/remix-lib') -const { map } = require('jquery') -const util = remixLib.util +import { EventManager } from '../eventManager' +import { isContractCreation } from '../trace/traceHelper' +import { atIndex } from './sourceMappingDecoder' +import { util } from '@remix-project/remix-lib' /** * Process the source code location for the current executing bytecode @@ -14,7 +12,6 @@ export class SourceLocationTracker { opts codeManager event - sourceMappingDecoder sourceMapByAddress constructor (_codeManager, { debugWithGeneratedSources }) { @@ -23,7 +20,6 @@ export class SourceLocationTracker { } this.codeManager = _codeManager this.event = new EventManager() - this.sourceMappingDecoder = new SourceMappingDecoder() this.sourceMapByAddress = {} } @@ -36,7 +32,7 @@ export class SourceLocationTracker { */ async getSourceLocationFromInstructionIndex (address, index, contracts) { const sourceMap = await this.extractSourceMap(this, this.codeManager, address, contracts) - return this.sourceMappingDecoder.atIndex(index, sourceMap['map']) + return atIndex(index, sourceMap['map']) } /** @@ -49,7 +45,7 @@ export class SourceLocationTracker { async getSourceLocationFromVMTraceIndex (address, vmtraceStepIndex, contracts) { const sourceMap = await this.extractSourceMap(this, this.codeManager, address, contracts) const index = this.codeManager.getInstructionIndex(address, vmtraceStepIndex) - return this.sourceMappingDecoder.atIndex(index, sourceMap['map']) + return atIndex(index, sourceMap['map']) } /** @@ -72,7 +68,7 @@ export class SourceLocationTracker { * @param {Object} contractDetails - AST of compiled contracts */ async getValidSourceLocationFromVMTraceIndex (address, vmtraceStepIndex, contracts) { - let map = { file: -1} + let map: Record = { file: -1} while (vmtraceStepIndex >= 0 && map.file === -1) { map = await this.getSourceLocationFromVMTraceIndex(address, vmtraceStepIndex, contracts) vmtraceStepIndex = vmtraceStepIndex - 1 @@ -85,7 +81,7 @@ export class SourceLocationTracker { } private getSourceMap (address, code, contracts) { - const isCreation = helper.isContractCreation(address) + const isCreation = isContractCreation(address) let bytes for (let file in contracts) { for (let contract in contracts[file]) { @@ -111,7 +107,7 @@ export class SourceLocationTracker { codeManager.getCode(address).then((result) => { const sourceMap = this.getSourceMap(address, result.bytecode, contracts) if (sourceMap) { - if (!helper.isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap + if (!isContractCreation(address)) self.sourceMapByAddress[address] = sourceMap return resolve(sourceMap) } reject('no sourcemap associated with the code ' + address) diff --git a/libs/remix-debug/src/source/sourceMappingDecoder.ts b/libs/remix-debug/src/source/sourceMappingDecoder.ts index 90762d07a2..74d1cf317c 100644 --- a/libs/remix-debug/src/source/sourceMappingDecoder.ts +++ b/libs/remix-debug/src/source/sourceMappingDecoder.ts @@ -1,7 +1,6 @@ 'use strict' -const { AstWalker } = require('@remix-project/remix-astwalker') -const remixLib = require('@remix-project/remix-lib') -const util = remixLib.util +import { AstWalker } from '@remix-project/remix-astwalker' +import { util } from '@remix-project/remix-lib' /** * Decompress the source mapping given by solc-bin.js