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
This commit is contained in:
parent
246de9aaad
commit
70e13dc31e
|
@ -27,9 +27,11 @@ export function findNodeAtPosition(ast: t.Node[], position: number): t.Node|e.AS
|
||||||
}
|
}
|
||||||
if (isTemplateNodeWithKeyAndValue(candidate)) {
|
if (isTemplateNodeWithKeyAndValue(candidate)) {
|
||||||
const {keySpan, valueSpan} = candidate;
|
const {keySpan, valueSpan} = candidate;
|
||||||
// If cursor is within source span but not within key span or value span,
|
const isWithinKeyValue =
|
||||||
// do not return the node.
|
isWithin(position, keySpan) || (valueSpan && isWithin(position, valueSpan));
|
||||||
if (!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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -504,8 +504,7 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
||||||
const {errors, nodes, position} = parse(`<div *ngFor="l¦et item of items"></div>`);
|
const {errors, nodes, position} = parse(`<div *ngFor="l¦et item of items"></div>`);
|
||||||
expect(errors).toBe(null);
|
expect(errors).toBe(null);
|
||||||
const node = findNodeAtPosition(nodes, position);
|
const node = findNodeAtPosition(nodes, position);
|
||||||
// TODO: this is currently wrong because node is currently pointing to
|
expect(node).toBeUndefined();
|
||||||
// "item". In this case, it should return undefined.
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should locate let variable', () => {
|
it('should locate let variable', () => {
|
||||||
|
|
Loading…
Reference in New Issue