Skip to content
Permalink
Browse files

Fix: `getNodeByRangeIndex` performance issue (fixes #4989)

  • Loading branch information...
mysticatea committed Jan 18, 2016
1 parent be9be2f commit 990f8da6ac5c0271b3ce4904a5f3bf31d9548447
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/util/source-code.js
@@ -256,11 +256,13 @@ SourceCode.prototype = {
*/
getNodeByRangeIndex: function(index) {
var result = null;
var resultParent = null;

estraverse.traverse(this.ast, {
enter: function(node, parent) {
if (node.range[0] <= index && index < node.range[1]) {
result = assign({ parent: parent }, node);
result = node;
resultParent = parent;
} else {
this.skip();
}
@@ -272,7 +274,7 @@ SourceCode.prototype = {
}
});

return result;
return result ? assign({parent: resultParent}, result) : null;
},

/**

0 comments on commit 990f8da

Please sign in to comment.
You can’t perform that action at this time.