diff --git a/packages/core/schematics/migrations/static-queries/angular/declaration_usage_visitor.ts b/packages/core/schematics/migrations/static-queries/angular/declaration_usage_visitor.ts index 1a5a3732a6..62972e61fa 100644 --- a/packages/core/schematics/migrations/static-queries/angular/declaration_usage_visitor.ts +++ b/packages/core/schematics/migrations/static-queries/angular/declaration_usage_visitor.ts @@ -35,7 +35,8 @@ export class DeclarationUsageVisitor { return; } - const callExprSymbol = this.typeChecker.getSymbolAtLocation(node); + const callExprType = this.typeChecker.getTypeAtLocation(node); + const callExprSymbol = callExprType.getSymbol(); if (!callExprSymbol || !callExprSymbol.valueDeclaration || !isFunctionLikeDeclaration(callExprSymbol.valueDeclaration)) { diff --git a/packages/core/schematics/test/static_queries_migration_spec.ts b/packages/core/schematics/test/static_queries_migration_spec.ts index dc23eae3b0..849ebae5fe 100644 --- a/packages/core/schematics/test/static_queries_migration_spec.ts +++ b/packages/core/schematics/test/static_queries_migration_spec.ts @@ -711,6 +711,35 @@ describe('static-queries migration', () => { .toContain(`@${queryType}('test', { static: true }) query2: any;`); }); + it('should detect static queries used in external function-like declaration', () => { + writeFile('/index.ts', ` + import {Component, ${queryType}} from '@angular/core'; + import {externalFn} from './external'; + + @Component({template: ''}) + export class MyComp { + private @${queryType}('test') query: any; + + ngOnInit() { + externalFn(this); + } + } + `); + + writeFile('/external.ts', ` + import {MyComp} from './index'; + + export function externalFn(ctx: MyComp) { + ctx.query.usedStatically(); + } + `); + + runMigration(); + + expect(tree.readContent('/index.ts')) + .toContain(`@${queryType}('test', { static: true }) query: any;`); + }); + it('should properly handle multiple tsconfig files', () => { writeFile('/src/index.ts', ` import {Component, ${queryType}} from '@angular/core';