diff --git a/packages/language-service/src/locate_symbol.ts b/packages/language-service/src/locate_symbol.ts index ba123ee0af..9951e0d02e 100644 --- a/packages/language-service/src/locate_symbol.ts +++ b/packages/language-service/src/locate_symbol.ts @@ -148,14 +148,14 @@ function findAttribute(info: AstResult, position: number): Attribute|undefined { return path.first(Attribute); } -function findParentOfDirectivePropertyAst(ast: TemplateAst[], binding: BoundDirectivePropertyAst) { +function findParentOfBinding(ast: TemplateAst[], binding: BoundDirectivePropertyAst) { let res: DirectiveAst|undefined; const visitor = new class extends RecursiveTemplateAstVisitor { visitDirective(ast: DirectiveAst) { const result = this.visitChildren(ast, visit => { visit(ast.inputs); }); return result; } - visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any) { + visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: DirectiveAst) { if (ast === binding) { res = context; } @@ -167,7 +167,7 @@ function findParentOfDirectivePropertyAst(ast: TemplateAst[], binding: BoundDire function findInputBinding( info: AstResult, path: TemplateAstPath, binding: BoundDirectivePropertyAst): Symbol|undefined { - const directiveAst = findParentOfDirectivePropertyAst(info.templateAst, binding); + const directiveAst = findParentOfBinding(info.templateAst, binding); if (directiveAst) { const invertedInput = invertMap(directiveAst.directive.inputs); const fieldName = invertedInput[binding.templateName]; diff --git a/packages/language-service/test/definitions_spec.ts b/packages/language-service/test/definitions_spec.ts index 5564d44d7f..3c13af8087 100644 --- a/packages/language-service/test/definitions_spec.ts +++ b/packages/language-service/test/definitions_spec.ts @@ -13,6 +13,8 @@ import {TypeScriptServiceHost} from '../src/typescript_host'; import {MockTypescriptHost} from './test_utils'; +const TEST_TEMPLATE = '/app/test.ng'; + describe('definitions', () => { const mockHost = new MockTypescriptHost(['/app/main.ts']); const service = ts.createLanguageService(mockHost); @@ -263,21 +265,17 @@ describe('definitions', () => { }); it('should be able to find a structural directive', () => { - const fileName = mockHost.addCode(` - @Component({ - template: '
' - }) - export class MyComponent { }`); + mockHost.override(TEST_TEMPLATE, `
`); // Get the marker for ngIf in the code added above. - const marker = mockHost.getReferenceMarkerFor(fileName, 'ngIf'); + const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'ngIf'); - const result = ngService.getDefinitionAt(fileName, marker.start); + const result = ngService.getDefinitionAt(TEST_TEMPLATE, marker.start); expect(result).toBeDefined(); const {textSpan, definitions} = result !; // Get the marker for bounded text in the code added above - const boundedText = mockHost.getLocationMarkerFor(fileName, 'my'); + const boundedText = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'my'); expect(textSpan).toEqual(boundedText); expect(definitions).toBeDefined(); @@ -292,22 +290,18 @@ describe('definitions', () => { }); it('should be able to find a two-way binding', () => { - const fileName = mockHost.addCode(` - @Component({ - template: '' - }) - export class MyComponent { - test = ""; - }`); + mockHost.override( + TEST_TEMPLATE, + ``); // Get the marker for «model» in the code added above. - const marker = mockHost.getReferenceMarkerFor(fileName, 'model'); + const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'model'); - const result = ngService.getDefinitionAt(fileName, marker.start); + const result = ngService.getDefinitionAt(TEST_TEMPLATE, marker.start); expect(result).toBeDefined(); const {textSpan, definitions} = result !; // Get the marker for bounded text in the code added above - const boundedText = mockHost.getLocationMarkerFor(fileName, 'my'); + const boundedText = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'my'); expect(textSpan).toEqual(boundedText); // There should be exactly 1 definition diff --git a/packages/language-service/test/hover_spec.ts b/packages/language-service/test/hover_spec.ts index 914be473ec..d3c8a4e273 100644 --- a/packages/language-service/test/hover_spec.ts +++ b/packages/language-service/test/hover_spec.ts @@ -149,13 +149,9 @@ describe('hover', () => { }); it('should be able to find a structural directive', () => { - const fileName = mockHost.addCode(` - @Component({ - template: '
' - }) - export class MyComponent { }`); - const marker = mockHost.getDefinitionMarkerFor(fileName, 'ngIf'); - const quickInfo = ngLS.getHoverAt(fileName, marker.start); + mockHost.override(TEST_TEMPLATE, `
`); + const marker = mockHost.getDefinitionMarkerFor(TEST_TEMPLATE, 'ngIf'); + const quickInfo = ngLS.getHoverAt(TEST_TEMPLATE, marker.start); expect(quickInfo).toBeTruthy(); const {textSpan, displayParts} = quickInfo !; expect(textSpan).toEqual(marker); @@ -163,15 +159,9 @@ describe('hover', () => { }); it('should be able to find a reference to a two-way binding', () => { - const fileName = mockHost.addCode(` - @Component({ - template: '' - }) - export class MyComponent { - test = ""; - }`); - const marker = mockHost.getDefinitionMarkerFor(fileName, 'model'); - const quickInfo = ngLS.getHoverAt(fileName, marker.start); + mockHost.override(TEST_TEMPLATE, ``); + const marker = mockHost.getDefinitionMarkerFor(TEST_TEMPLATE, 'model'); + const quickInfo = ngLS.getHoverAt(TEST_TEMPLATE, marker.start); expect(quickInfo).toBeTruthy(); const {textSpan, displayParts} = quickInfo !; expect(textSpan).toEqual(marker);