Merge pull request #578 from ethereum/fixbytedecoding

add new api function to source mapping decoder
pull/7/head
yann300 7 years ago committed by GitHub
commit 3a62b5d900
  1. 49
      src/util/sourceMappingDecoder.js

@ -9,6 +9,15 @@ function SourceMappingDecoder () {
// s:l:f:j // s:l:f:j
} }
/**
* get a list of nodes that are at the given @arg position
*
* @param {String} astNodeType - type of node to return
* @param {Int} position - cursor position
* @return {Object} ast object given by the compiler
*/
SourceMappingDecoder.prototype.nodesAtPosition = nodesAtPosition
/** /**
* Decode the source mapping for the given @arg index * Decode the source mapping for the given @arg index
* *
@ -18,6 +27,23 @@ function SourceMappingDecoder () {
*/ */
SourceMappingDecoder.prototype.atIndex = atIndex SourceMappingDecoder.prototype.atIndex = atIndex
/**
* Decode the given @arg value
*
* @param {string} value - source location to decode ( should be start:length:file )
* @return {Object} returns the decompressed source mapping {start, length, file}
*/
SourceMappingDecoder.prototype.decode = function (value) {
if (value) {
value = value.split(':')
return {
start: parseInt(value[0]),
length: parseInt(value[1]),
file: parseInt(value[2])
}
}
}
/** /**
* Decode the source mapping for the given compressed mapping * Decode the source mapping for the given compressed mapping
* *
@ -139,6 +165,29 @@ function findNodeAtSourceLocation (astNodeType, sourceLocation, ast) {
return found return found
} }
function nodesAtPosition (astNodeType, position, ast) {
var astWalker = new AstWalker()
var callback = {}
var found = []
callback['*'] = function (node) {
var nodeLocation = sourceLocationFromAstNode(node)
if (!nodeLocation) {
return
}
if (nodeLocation.start <= position && nodeLocation.start + nodeLocation.length >= position) {
if (!astNodeType || astNodeType === node.name) {
found.push(node)
if (astNodeType) return false
}
return true
} else {
return false
}
}
astWalker.walk(ast.AST, callback)
return found
}
function atIndex (index, mapping) { function atIndex (index, mapping) {
var ret = {} var ret = {}
var map = mapping.split(';') var map = mapping.split(';')

Loading…
Cancel
Save