From 70e13dc31e1e7cb784d5e91cc090f57411863dde Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Wed, 30 Sep 2020 08:54:04 -0700 Subject: [PATCH] fix(language-service): [Ivy] hybrid visitor should not locate let keyword (#39061) Fixed a boolean logic error that prevented hybrid visitor from returning undefined when a variable does not have value and cursor is not in the key span. PR Close #39061 --- packages/language-service/ivy/hybrid_visitor.ts | 8 +++++--- packages/language-service/ivy/test/hybrid_visitor_spec.ts | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/language-service/ivy/hybrid_visitor.ts b/packages/language-service/ivy/hybrid_visitor.ts index b68d3e782a..c8e8c3a152 100644 --- a/packages/language-service/ivy/hybrid_visitor.ts +++ b/packages/language-service/ivy/hybrid_visitor.ts @@ -27,9 +27,11 @@ export function findNodeAtPosition(ast: t.Node[], position: number): t.Node|e.AS } if (isTemplateNodeWithKeyAndValue(candidate)) { const {keySpan, valueSpan} = candidate; - // If cursor is within source span but not within key span or value span, - // do not return the node. - if (!isWithin(position, keySpan) && (valueSpan && !isWithin(position, valueSpan))) { + const isWithinKeyValue = + isWithin(position, keySpan) || (valueSpan && isWithin(position, valueSpan)); + if (!isWithinKeyValue) { + // If cursor is within source span but not within key span or value span, + // do not return the node. return; } } diff --git a/packages/language-service/ivy/test/hybrid_visitor_spec.ts b/packages/language-service/ivy/test/hybrid_visitor_spec.ts index 9d29535356..556ac0a601 100644 --- a/packages/language-service/ivy/test/hybrid_visitor_spec.ts +++ b/packages/language-service/ivy/test/hybrid_visitor_spec.ts @@ -504,8 +504,7 @@ describe('findNodeAtPosition for microsyntax expression', () => { const {errors, nodes, position} = parse(`
`); expect(errors).toBe(null); const node = findNodeAtPosition(nodes, position); - // TODO: this is currently wrong because node is currently pointing to - // "item". In this case, it should return undefined. + expect(node).toBeUndefined(); }); it('should locate let variable', () => {