|
|
@ -10,7 +10,7 @@ import {ParseError, parseTemplate} from '@angular/compiler';
|
|
|
|
import * as e from '@angular/compiler/src/expression_parser/ast'; // e for expression AST
|
|
|
|
import * as e from '@angular/compiler/src/expression_parser/ast'; // e for expression AST
|
|
|
|
import * as t from '@angular/compiler/src/render3/r3_ast'; // t for template AST
|
|
|
|
import * as t from '@angular/compiler/src/render3/r3_ast'; // t for template AST
|
|
|
|
|
|
|
|
|
|
|
|
import {getTargetAtPosition} from '../../template_target';
|
|
|
|
import {getTargetAtPosition, TargetNodeKind} from '../../template_target';
|
|
|
|
import {isExpressionNode, isTemplateNode} from '../../utils';
|
|
|
|
import {isExpressionNode, isTemplateNode} from '../../utils';
|
|
|
|
|
|
|
|
|
|
|
|
interface ParseResult {
|
|
|
|
interface ParseResult {
|
|
|
@ -36,7 +36,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate element in opening tag', () => {
|
|
|
|
it('should locate element in opening tag', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<di¦v></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<di¦v></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -44,7 +45,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate element in closing tag', () => {
|
|
|
|
it('should locate element in closing tag', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div></di¦v>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div></di¦v>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -52,7 +54,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate element when cursor is at the beginning', () => {
|
|
|
|
it('should locate element when cursor is at the beginning', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<¦div></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<¦div></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -60,7 +63,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate element when cursor is at the end', () => {
|
|
|
|
it('should locate element when cursor is at the end', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div¦></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div¦></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -68,7 +72,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate attribute key', () => {
|
|
|
|
it('should locate attribute key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div cla¦ss="foo"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div cla¦ss="foo"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -76,7 +81,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate attribute value', () => {
|
|
|
|
it('should locate attribute value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div class="fo¦o"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div class="fo¦o"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
// TODO: Note that we do not have the ability to detect the RHS (yet)
|
|
|
|
// TODO: Note that we do not have the ability to detect the RHS (yet)
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
@ -85,7 +91,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate bound attribute key', () => {
|
|
|
|
it('should locate bound attribute key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp [fo¦o]="bar"></test-cmp>`);
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp [fo¦o]="bar"></test-cmp>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -93,7 +100,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate bound attribute value', () => {
|
|
|
|
it('should locate bound attribute value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp [foo]="b¦ar"></test-cmp>`);
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp [foo]="b¦ar"></test-cmp>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -108,7 +116,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate bound event key', () => {
|
|
|
|
it('should locate bound event key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp (fo¦o)="bar()"></test-cmp>`);
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp (fo¦o)="bar()"></test-cmp>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundEvent);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundEvent);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -116,7 +125,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate bound event value', () => {
|
|
|
|
it('should locate bound event value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp (foo)="b¦ar()"></test-cmp>`);
|
|
|
|
const {errors, nodes, position} = parse(`<test-cmp (foo)="b¦ar()"></test-cmp>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.MethodCall);
|
|
|
|
expect(node).toBeInstanceOf(e.MethodCall);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -124,7 +134,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate element children', () => {
|
|
|
|
it('should locate element children', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div><sp¦an></span></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div><sp¦an></span></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect((node as t.Element).name).toBe('span');
|
|
|
|
expect((node as t.Element).name).toBe('span');
|
|
|
@ -133,7 +144,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate element reference', () => {
|
|
|
|
it('should locate element reference', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div #my¦div></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div #my¦div></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -141,7 +153,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template text attribute', () => {
|
|
|
|
it('should locate template text attribute', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template ng¦If></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template ng¦If></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -149,7 +162,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template bound attribute key', () => {
|
|
|
|
it('should locate template bound attribute key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [ng¦If]="foo"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [ng¦If]="foo"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -157,7 +171,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template bound attribute value', () => {
|
|
|
|
it('should locate template bound attribute value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [ngIf]="f¦oo"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [ngIf]="f¦oo"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -165,7 +180,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template bound attribute key in two-way binding', () => {
|
|
|
|
it('should locate template bound attribute key in two-way binding', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [(f¦oo)]="bar"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [(f¦oo)]="bar"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('foo');
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('foo');
|
|
|
@ -174,7 +190,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template bound attribute value in two-way binding', () => {
|
|
|
|
it('should locate template bound attribute value in two-way binding', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [(foo)]="b¦ar"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template [(foo)]="b¦ar"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('bar');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('bar');
|
|
|
@ -183,7 +200,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template bound event key', () => {
|
|
|
|
it('should locate template bound event key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template (cl¦ick)="foo()"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template (cl¦ick)="foo()"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundEvent);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundEvent);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -191,14 +209,16 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template bound event value', () => {
|
|
|
|
it('should locate template bound event value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template (click)="f¦oo()"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template (click)="f¦oo()"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(node).toBeInstanceOf(e.MethodCall);
|
|
|
|
expect(node).toBeInstanceOf(e.MethodCall);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should locate template attribute key', () => {
|
|
|
|
it('should locate template attribute key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template i¦d="foo"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template i¦d="foo"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -206,7 +226,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template attribute value', () => {
|
|
|
|
it('should locate template attribute value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template id="f¦oo"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template id="f¦oo"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
// TODO: Note that we do not have the ability to detect the RHS (yet)
|
|
|
|
// TODO: Note that we do not have the ability to detect the RHS (yet)
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
@ -215,7 +236,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template reference key via the # notation', () => {
|
|
|
|
it('should locate template reference key via the # notation', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template #f¦oo></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template #f¦oo></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect((node as t.Reference).name).toBe('foo');
|
|
|
|
expect((node as t.Reference).name).toBe('foo');
|
|
|
@ -224,7 +246,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template reference key via the ref- notation', () => {
|
|
|
|
it('should locate template reference key via the ref- notation', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template ref-fo¦o></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template ref-fo¦o></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect((node as t.Reference).name).toBe('foo');
|
|
|
|
expect((node as t.Reference).name).toBe('foo');
|
|
|
@ -233,7 +256,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template reference value via the # notation', () => {
|
|
|
|
it('should locate template reference value via the # notation', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template #foo="export¦As"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template #foo="export¦As"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect((node as t.Reference).value).toBe('exportAs');
|
|
|
|
expect((node as t.Reference).value).toBe('exportAs');
|
|
|
@ -243,7 +267,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template reference value via the ref- notation', () => {
|
|
|
|
it('should locate template reference value via the ref- notation', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template ref-foo="export¦As"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template ref-foo="export¦As"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect(node).toBeInstanceOf(t.Reference);
|
|
|
|
expect((node as t.Reference).value).toBe('exportAs');
|
|
|
|
expect((node as t.Reference).value).toBe('exportAs');
|
|
|
@ -253,7 +278,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template variable key', () => {
|
|
|
|
it('should locate template variable key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template let-f¦oo="bar"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template let-f¦oo="bar"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -261,7 +287,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template variable value', () => {
|
|
|
|
it('should locate template variable value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template let-foo="b¦ar"></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template let-foo="b¦ar"></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -269,7 +296,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate template children', () => {
|
|
|
|
it('should locate template children', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template><d¦iv></div></ng-template>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-template><d¦iv></div></ng-template>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -277,7 +305,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate ng-content', () => {
|
|
|
|
it('should locate ng-content', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<ng-co¦ntent></ng-content>`);
|
|
|
|
const {errors, nodes, position} = parse(`<ng-co¦ntent></ng-content>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Content);
|
|
|
|
expect(node).toBeInstanceOf(t.Content);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -285,7 +314,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate ng-content attribute key', () => {
|
|
|
|
it('should locate ng-content attribute key', () => {
|
|
|
|
const {errors, nodes, position} = parse('<ng-content cla¦ss="red"></ng-content>');
|
|
|
|
const {errors, nodes, position} = parse('<ng-content cla¦ss="red"></ng-content>');
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -293,7 +323,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate ng-content attribute value', () => {
|
|
|
|
it('should locate ng-content attribute value', () => {
|
|
|
|
const {errors, nodes, position} = parse('<ng-content class="r¦ed"></ng-content>');
|
|
|
|
const {errors, nodes, position} = parse('<ng-content class="r¦ed"></ng-content>');
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
// TODO: Note that we do not have the ability to detect the RHS (yet)
|
|
|
|
// TODO: Note that we do not have the ability to detect the RHS (yet)
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
@ -302,7 +333,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should not locate implicit receiver', () => {
|
|
|
|
it('should not locate implicit receiver', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div [foo]="¦bar"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div [foo]="¦bar"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -310,7 +342,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate bound attribute key in two-way binding', () => {
|
|
|
|
it('should locate bound attribute key in two-way binding', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<cmp [(f¦oo)]="bar"></cmp>`);
|
|
|
|
const {errors, nodes, position} = parse(`<cmp [(f¦oo)]="bar"></cmp>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('foo');
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('foo');
|
|
|
@ -319,7 +352,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate bound attribute value in two-way binding', () => {
|
|
|
|
it('should locate bound attribute value in two-way binding', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<cmp [(foo)]="b¦ar"></cmp>`);
|
|
|
|
const {errors, nodes, position} = parse(`<cmp [(foo)]="b¦ar"></cmp>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('bar');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('bar');
|
|
|
@ -328,7 +362,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
it('should locate switch value in ICUs', () => {
|
|
|
|
it('should locate switch value in ICUs', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<span i18n>{sw¦itch, plural, other {text}}"></span>`);
|
|
|
|
const {errors, nodes, position} = parse(`<span i18n>{sw¦itch, plural, other {text}}"></span>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('switch');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('switch');
|
|
|
@ -338,7 +373,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
const {errors, nodes, position} = parse(
|
|
|
|
const {errors, nodes, position} = parse(
|
|
|
|
`<span i18n>{expr, plural, other { {ne¦sted, plural, =1 { {{nestedInterpolation}} }} }}"></span>`);
|
|
|
|
`<span i18n>{expr, plural, other { {ne¦sted, plural, =1 { {{nestedInterpolation}} }} }}"></span>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('nested');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('nested');
|
|
|
@ -348,7 +384,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
const {errors, nodes, position} =
|
|
|
|
const {errors, nodes, position} =
|
|
|
|
parse(`<span i18n>{expr, plural, other { {{ i¦nterpolation }} }}"></span>`);
|
|
|
|
parse(`<span i18n>{expr, plural, other { {{ i¦nterpolation }} }}"></span>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('interpolation');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('interpolation');
|
|
|
@ -358,7 +395,8 @@ describe('getTargetAtPosition for template AST', () => {
|
|
|
|
const {errors, nodes, position} = parse(
|
|
|
|
const {errors, nodes, position} = parse(
|
|
|
|
`<span i18n>{expr, plural, other { {nested, plural, =1 { {{n¦estedInterpolation}} }} }}"></span>`);
|
|
|
|
`<span i18n>{expr, plural, other { {nested, plural, =1 { {{n¦estedInterpolation}} }} }}"></span>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('nestedInterpolation');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('nestedInterpolation');
|
|
|
@ -369,7 +407,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should not locate implicit receiver', () => {
|
|
|
|
it('should not locate implicit receiver', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ ¦title }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ ¦title }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('title');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('title');
|
|
|
@ -378,7 +417,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate property read', () => {
|
|
|
|
it('should locate property read', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ ti¦tle }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ ti¦tle }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('title');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('title');
|
|
|
@ -387,7 +427,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate safe property read', () => {
|
|
|
|
it('should locate safe property read', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ foo?¦.bar }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ foo?¦.bar }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.SafePropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.SafePropertyRead);
|
|
|
|
expect((node as e.SafePropertyRead).name).toBe('bar');
|
|
|
|
expect((node as e.SafePropertyRead).name).toBe('bar');
|
|
|
@ -396,7 +437,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate keyed read', () => {
|
|
|
|
it('should locate keyed read', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ foo['bar']¦ }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ foo['bar']¦ }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.KeyedRead);
|
|
|
|
expect(node).toBeInstanceOf(e.KeyedRead);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -404,7 +446,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate property write', () => {
|
|
|
|
it('should locate property write', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div (foo)="b¦ar=$event"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div (foo)="b¦ar=$event"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyWrite);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyWrite);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -412,7 +455,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate keyed write', () => {
|
|
|
|
it('should locate keyed write', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div (foo)="bar['baz']¦=$event"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div (foo)="bar['baz']¦=$event"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.KeyedWrite);
|
|
|
|
expect(node).toBeInstanceOf(e.KeyedWrite);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -420,7 +464,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate binary', () => {
|
|
|
|
it('should locate binary', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ 1 +¦ 2 }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ 1 +¦ 2 }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.Binary);
|
|
|
|
expect(node).toBeInstanceOf(e.Binary);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -428,7 +473,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate binding pipe with an identifier', () => {
|
|
|
|
it('should locate binding pipe with an identifier', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ title | p¦ }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ title | p¦ }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.BindingPipe);
|
|
|
|
expect(node).toBeInstanceOf(e.BindingPipe);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -439,7 +485,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
expect(errors![0].toString())
|
|
|
|
expect(errors![0].toString())
|
|
|
|
.toContain(
|
|
|
|
.toContain(
|
|
|
|
'Unexpected end of input, expected identifier or keyword at the end of the expression');
|
|
|
|
'Unexpected end of input, expected identifier or keyword at the end of the expression');
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
// TODO: We want this to be a BindingPipe.
|
|
|
|
// TODO: We want this to be a BindingPipe.
|
|
|
|
expect(node).toBeInstanceOf(e.Interpolation);
|
|
|
|
expect(node).toBeInstanceOf(e.Interpolation);
|
|
|
@ -451,7 +498,7 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
// parser throws an error. This case is important for autocomplete.
|
|
|
|
// parser throws an error. This case is important for autocomplete.
|
|
|
|
// const {errors, nodes, position} = parse(`{{ title | ¦ }}`);
|
|
|
|
// const {errors, nodes, position} = parse(`{{ title | ¦ }}`);
|
|
|
|
// expect(errors).toBe(null);
|
|
|
|
// expect(errors).toBe(null);
|
|
|
|
// const {node} = findNodeAtPosition(nodes, position)!;
|
|
|
|
// const {nodeInContext} = findNodeAtPosition(nodes, position)!;
|
|
|
|
// expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
// expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
// expect(node).toBeInstanceOf(e.BindingPipe);
|
|
|
|
// expect(node).toBeInstanceOf(e.BindingPipe);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -460,7 +507,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate method call', () => {
|
|
|
|
it('should locate method call', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ title.toString(¦) }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ title.toString(¦) }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.MethodCall);
|
|
|
|
expect(node).toBeInstanceOf(e.MethodCall);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -468,7 +516,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate safe method call', () => {
|
|
|
|
it('should locate safe method call', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ title?.toString(¦) }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ title?.toString(¦) }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.SafeMethodCall);
|
|
|
|
expect(node).toBeInstanceOf(e.SafeMethodCall);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -476,7 +525,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate literal primitive in interpolation', () => {
|
|
|
|
it('should locate literal primitive in interpolation', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ title.indexOf('t¦') }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ title.indexOf('t¦') }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralPrimitive);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralPrimitive);
|
|
|
|
expect((node as e.LiteralPrimitive).value).toBe('t');
|
|
|
|
expect((node as e.LiteralPrimitive).value).toBe('t');
|
|
|
@ -485,7 +535,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate literal primitive in binding', () => {
|
|
|
|
it('should locate literal primitive in binding', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div [id]="'t¦'"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div [id]="'t¦'"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralPrimitive);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralPrimitive);
|
|
|
|
expect((node as e.LiteralPrimitive).value).toBe('t');
|
|
|
|
expect((node as e.LiteralPrimitive).value).toBe('t');
|
|
|
@ -494,7 +545,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate empty expression', () => {
|
|
|
|
it('should locate empty expression', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div [id]="¦"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div [id]="¦"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.EmptyExpr);
|
|
|
|
expect(node).toBeInstanceOf(e.EmptyExpr);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -502,7 +554,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate literal array', () => {
|
|
|
|
it('should locate literal array', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ [1, 2,¦ 3] }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ [1, 2,¦ 3] }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralArray);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralArray);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -510,7 +563,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate literal map', () => {
|
|
|
|
it('should locate literal map', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ { hello:¦ "world" } }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ { hello:¦ "world" } }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralMap);
|
|
|
|
expect(node).toBeInstanceOf(e.LiteralMap);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -518,7 +572,8 @@ describe('getTargetAtPosition for expression AST', () => {
|
|
|
|
it('should locate conditional', () => {
|
|
|
|
it('should locate conditional', () => {
|
|
|
|
const {errors, nodes, position} = parse(`{{ cond ?¦ true : false }}`);
|
|
|
|
const {errors, nodes, position} = parse(`{{ cond ?¦ true : false }}`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.Conditional);
|
|
|
|
expect(node).toBeInstanceOf(e.Conditional);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -528,7 +583,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate template key', () => {
|
|
|
|
it('should locate template key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ng¦If="foo"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ng¦If="foo"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -536,7 +592,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate template value', () => {
|
|
|
|
it('should locate template value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngIf="f¦oo"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngIf="f¦oo"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -546,7 +603,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
// ngFor is a text attribute because the desugared form is
|
|
|
|
// ngFor is a text attribute because the desugared form is
|
|
|
|
// <ng-template ngFor let-item [ngForOf]="items">
|
|
|
|
// <ng-template ngFor let-item [ngForOf]="items">
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBeTrue();
|
|
|
|
expect(isTemplateNode(node!)).toBeTrue();
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.TextAttribute);
|
|
|
|
expect((node as t.TextAttribute).name).toBe('ngFor');
|
|
|
|
expect((node as t.TextAttribute).name).toBe('ngFor');
|
|
|
@ -562,7 +620,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate let variable', () => {
|
|
|
|
it('should locate let variable', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let i¦tem of items"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let i¦tem of items"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
expect((node as t.Variable).name).toBe('item');
|
|
|
|
expect((node as t.Variable).name).toBe('item');
|
|
|
@ -571,7 +630,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate bound attribute key', () => {
|
|
|
|
it('should locate bound attribute key', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item o¦f items"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item o¦f items"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForOf');
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForOf');
|
|
|
@ -580,8 +640,9 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate bound attribute key when cursor is at the start', () => {
|
|
|
|
it('should locate bound attribute key when cursor is at the start', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item ¦of items"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item ¦of items"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
const node = nodeInContext.node;
|
|
|
|
|
|
|
|
expect(isTemplateNode(node)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForOf');
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForOf');
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -590,7 +651,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
const {errors, nodes, position} =
|
|
|
|
const {errors, nodes, position} =
|
|
|
|
parse(`<div *ngFor="let item of items; trac¦kBy: trackByFn"></div>`);
|
|
|
|
parse(`<div *ngFor="let item of items; trac¦kBy: trackByFn"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForTrackBy');
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForTrackBy');
|
|
|
@ -603,7 +665,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
const {errors, nodes, position} =
|
|
|
|
const {errors, nodes, position} =
|
|
|
|
parse(`<div *ngFor="let item o¦f items; trackBy: trackByFn"></div>`);
|
|
|
|
parse(`<div *ngFor="let item o¦f items; trackBy: trackByFn"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect(node).toBeInstanceOf(t.BoundAttribute);
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForOf');
|
|
|
|
expect((node as t.BoundAttribute).name).toBe('ngForOf');
|
|
|
@ -612,7 +675,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate bound attribute value', () => {
|
|
|
|
it('should locate bound attribute value', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item of it¦ems"></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item of it¦ems"></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect((node as e.PropertyRead).name).toBe('items');
|
|
|
|
expect((node as e.PropertyRead).name).toBe('items');
|
|
|
@ -621,7 +685,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate template children', () => {
|
|
|
|
it('should locate template children', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<di¦v *ngIf></div>`);
|
|
|
|
const {errors, nodes, position} = parse(`<di¦v *ngIf></div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node, context} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext, template: context} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect(node).toBeInstanceOf(t.Element);
|
|
|
|
expect((node as t.Element).name).toBe('div');
|
|
|
|
expect((node as t.Element).name).toBe('div');
|
|
|
@ -634,7 +699,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
{{ i¦ }}
|
|
|
|
{{ i¦ }}
|
|
|
|
</div>`);
|
|
|
|
</div>`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(isExpressionNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
expect(node).toBeInstanceOf(e.PropertyRead);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -642,7 +708,8 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate LHS of variable declaration', () => {
|
|
|
|
it('should locate LHS of variable declaration', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item of items; let i¦=index">`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item of items; let i¦=index">`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
// TODO: Currently there is no way to distinguish LHS from RHS
|
|
|
|
// TODO: Currently there is no way to distinguish LHS from RHS
|
|
|
@ -652,10 +719,27 @@ describe('findNodeAtPosition for microsyntax expression', () => {
|
|
|
|
it('should locate RHS of variable declaration', () => {
|
|
|
|
it('should locate RHS of variable declaration', () => {
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item of items; let i=in¦dex">`);
|
|
|
|
const {errors, nodes, position} = parse(`<div *ngFor="let item of items; let i=in¦dex">`);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
const {node} = getTargetAtPosition(nodes, position)!;
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
const {node} = nodeInContext;
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(isTemplateNode(node!)).toBe(true);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
expect(node).toBeInstanceOf(t.Variable);
|
|
|
|
// TODO: Currently there is no way to distinguish LHS from RHS
|
|
|
|
// TODO: Currently there is no way to distinguish LHS from RHS
|
|
|
|
expect((node as t.Variable).value).toBe('index');
|
|
|
|
expect((node as t.Variable).value).toBe('index');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should locate an element in its tag context', () => {
|
|
|
|
|
|
|
|
const {errors, nodes, position} = parse(`<div¦ attr></div>`);
|
|
|
|
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
expect(nodeInContext.kind).toBe(TargetNodeKind.ElementInTagContext);
|
|
|
|
|
|
|
|
expect(nodeInContext.node).toBeInstanceOf(t.Element);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should locate an element in its body context', () => {
|
|
|
|
|
|
|
|
const {errors, nodes, position} = parse(`<div ¦ attr></div>`);
|
|
|
|
|
|
|
|
expect(errors).toBe(null);
|
|
|
|
|
|
|
|
const {nodeInContext} = getTargetAtPosition(nodes, position)!;
|
|
|
|
|
|
|
|
expect(nodeInContext.kind).toBe(TargetNodeKind.ElementInBodyContext);
|
|
|
|
|
|
|
|
expect(nodeInContext.node).toBeInstanceOf(t.Element);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|