findNodeAtSourceLocation bugfixes

pull/7/head
rocky 6 years ago
parent 283705cbed
commit f0b2046c4e
  1. 11
      remix-astwalker/src/sourceMappings.ts

@ -66,18 +66,17 @@ export class SourceMappings {
return found; return found;
} }
findNodeAtSourceLocation(astNodeType: string, sourceLocation: Location, ast: AstNode | null) { findNodeAtSourceLocation(astNodeType: string | undefined, sourceLocation: Location, ast: AstNode | null): AstNode | null {
const astWalker = new AstWalker() const astWalker = new AstWalker()
const callback = {};
let found = null; let found = null;
/* FIXME: Looking at AST walker code, /* FIXME: Looking at AST walker code,
I don't understand a need to return a boolean. */ I don't understand a need to return a boolean. */
callback['*'] = function(node: AstNode) { const callback = function(node: AstNode) {
let nodeLocation = sourceLocationFromAstNode(node); let nodeLocation = sourceLocationFromAstNode(node);
if (nodeLocation && if (nodeLocation &&
nodeLocation.start <= sourceLocation.start && nodeLocation.start == sourceLocation.start &&
nodeLocation.start + nodeLocation.length >= sourceLocation.start + sourceLocation.length) { nodeLocation.length == sourceLocation.length) {
if (astNodeType === node.nodeType) { if (astNodeType == undefined || astNodeType === node.nodeType) {
found = node; found = node;
} }
} }

Loading…
Cancel
Save