nodesAtCursorPosition

pull/7/head
yann300 7 years ago
parent d46b09ac32
commit 8351bdf6a5
  1. 32
      src/util/sourceMappingDecoder.js

@ -9,6 +9,15 @@ function SourceMappingDecoder () {
// 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
*
@ -156,6 +165,29 @@ function findNodeAtSourceLocation (astNodeType, sourceLocation, ast) {
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[node.name] = node
if (astNodeType) return false
}
return true
} else {
return false
}
}
astWalker.walk(ast.AST, callback)
return found
}
function atIndex (index, mapping) {
var ret = {}
var map = mapping.split(';')

Loading…
Cancel
Save