From f0b2046c4ef5f47fb69e0b2bcd62dcd9141e0459 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 14 Jun 2019 19:53:23 -0400 Subject: [PATCH] findNodeAtSourceLocation bugfixes --- remix-astwalker/src/sourceMappings.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/remix-astwalker/src/sourceMappings.ts b/remix-astwalker/src/sourceMappings.ts index cbe4c0422f..ca1b845269 100644 --- a/remix-astwalker/src/sourceMappings.ts +++ b/remix-astwalker/src/sourceMappings.ts @@ -66,18 +66,17 @@ export class SourceMappings { 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 callback = {}; let found = null; /* FIXME: Looking at AST walker code, I don't understand a need to return a boolean. */ - callback['*'] = function(node: AstNode) { + const callback = function(node: AstNode) { let nodeLocation = sourceLocationFromAstNode(node); if (nodeLocation && - nodeLocation.start <= sourceLocation.start && - nodeLocation.start + nodeLocation.length >= sourceLocation.start + sourceLocation.length) { - if (astNodeType === node.nodeType) { + nodeLocation.start == sourceLocation.start && + nodeLocation.length == sourceLocation.length) { + if (astNodeType == undefined || astNodeType === node.nodeType) { found = node; } }