fix(language-service): apply suggested change. (#34564)

PR Close #34564
This commit is contained in:
ivanwonder 2020-01-06 10:37:49 +08:00 committed by atscott
parent 6f916c1240
commit 1a453872c8
2 changed files with 8 additions and 7 deletions

View File

@ -148,12 +148,16 @@ function findAttribute(info: AstResult, position: number): Attribute|undefined {
return path.first(Attribute); return path.first(Attribute);
} }
// TODO: remove this function after the path includes 'DirectiveAst'.
// Find the directive that corresponds to the specified 'binding'
// at the specified 'position' in the 'ast'.
function findParentOfBinding( function findParentOfBinding(
ast: TemplateAst[], binding: BoundDirectivePropertyAst, position: number) { ast: TemplateAst[], binding: BoundDirectivePropertyAst, position: number): DirectiveAst|
undefined {
let res: DirectiveAst|undefined; let res: DirectiveAst|undefined;
const visitor = new class extends RecursiveTemplateAstVisitor { const visitor = new class extends RecursiveTemplateAstVisitor {
visit(ast: TemplateAst): any { visit(ast: TemplateAst): any {
let span = spanOf(ast); const span = spanOf(ast);
if (!inSpan(position, span)) { if (!inSpan(position, span)) {
// Returning a value here will result in the children being skipped. // Returning a value here will result in the children being skipped.
return true; return true;

View File

@ -314,11 +314,8 @@ describe('definitions', () => {
expect(def.name).toBe('model'); expect(def.name).toBe('model');
expect(def.kind).toBe('property'); expect(def.kind).toBe('property');
const content = mockHost.readFile(refFileName) !; const content = mockHost.readFile(refFileName) !;
const ref = `@Input() model: string = 'model';`; expect(content.substring(def.textSpan.start, def.textSpan.start + def.textSpan.length))
expect(def.textSpan).toEqual({ .toEqual(`@Input() model: string = 'model';`);
start: content.indexOf(ref),
length: ref.length,
});
}); });
it('should be able to find a template from a url', () => { it('should be able to find a template from a url', () => {