add offsetToLineColumnConverter to remix-lib

pull/5370/head
Iuri Matias 6 years ago
parent 888e01a6a7
commit 00e15ce815
  1. 2
      remix-lib/index.js
  2. 32
      remix-lib/src/offsetToLineColumnConverter.js

@ -5,6 +5,7 @@ var uiHelper = require('./src/helpers/uiHelper')
var compilerHelper = require('./src/helpers/compilerHelper') var compilerHelper = require('./src/helpers/compilerHelper')
var SourceMappingDecoder = require('./src/sourceMappingDecoder') var SourceMappingDecoder = require('./src/sourceMappingDecoder')
var SourceLocationTracker = require('./src/sourceLocationTracker') var SourceLocationTracker = require('./src/sourceLocationTracker')
var OffsetToColumnConverter = require('./src/offsetToLineColumnConverter')
var init = require('./src/init') var init = require('./src/init')
var util = require('./src/util') var util = require('./src/util')
var Web3Providers = require('./src/web3Provider/web3Providers') var Web3Providers = require('./src/web3Provider/web3Providers')
@ -56,6 +57,7 @@ function modules () {
}, },
SourceMappingDecoder: SourceMappingDecoder, SourceMappingDecoder: SourceMappingDecoder,
SourceLocationTracker: SourceLocationTracker, SourceLocationTracker: SourceLocationTracker,
OffsetToColumnConverter: OffsetToColumnConverter,
Storage: Storage, Storage: Storage,
init: init, init: init,
util: util, util: util,

@ -0,0 +1,32 @@
'use strict'
var SourceMappingDecoder = require('./sourceMappingDecoder')
function offsetToColumnConverter (compilerEvent) {
this.lineBreakPositionsByContent = {}
this.sourceMappingDecoder = new SourceMappingDecoder()
var self = this
if (compilerEvent) {
compilerEvent.register('compilationFinished', function (success, data, source) {
self.clear()
})
}
}
offsetToColumnConverter.prototype.offsetToLineColumn = function (rawLocation, file, sources, asts) {
if (!this.lineBreakPositionsByContent[file]) {
for (var filename in asts) {
var source = asts[filename]
if (source.id === file) {
this.lineBreakPositionsByContent[file] = this.sourceMappingDecoder.getLinebreakPositions(sources[filename].content)
break
}
}
}
return this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file])
}
offsetToColumnConverter.prototype.clear = function () {
this.lineBreakPositionsByContent = {}
}
module.exports = offsetToColumnConverter
Loading…
Cancel
Save