diff --git a/src/utils/ast-helpers.ts b/src/utils/ast-helpers.ts index a94c7e6d..62dab9df 100644 --- a/src/utils/ast-helpers.ts +++ b/src/utils/ast-helpers.ts @@ -87,7 +87,7 @@ export function findMethodCallExpressions(node: Node, propName: string, fnName: } export function findClassPropertiesConstructorParameterByType(node: ClassDeclaration, type: string): string[] { - const query = `Constructor Parameter:has(TypeReference > Identifier[name="${type}"]):has(PublicKeyword,ProtectedKeyword,PrivateKeyword) > Identifier`; + const query = `Constructor Parameter:has(TypeReference > Identifier[name="${type}"]):has(PublicKeyword,ProtectedKeyword,PrivateKeyword,ReadonlyKeyword) > Identifier`; const result = tsquery(node, query); return result.map((n) => n.text); } diff --git a/tests/parsers/service.parser.spec.ts b/tests/parsers/service.parser.spec.ts index 3dc36d88..f3c59d0b 100644 --- a/tests/parsers/service.parser.spec.ts +++ b/tests/parsers/service.parser.spec.ts @@ -32,6 +32,25 @@ describe('ServiceParser', () => { expect(keys).to.deep.equal(['It works!']); }); + it('should locate TranslateService when injected with public, protected, private and readonly keyword', () => { + const ACCESSORS = ['public', 'protected', 'private', 'readonly']; + + ACCESSORS.forEach((accessor) => { + const contents = ` + @Component({ }) + export class AppComponent { + public constructor(${accessor} _translateService: TranslateService) { } + public test() { + this._translateService.get('Hello get'); + this._translateService.instant('Hello instant'); + this._translateService.stream('Hello stream'); + } + `; + const keys = parser.extract(contents, componentFilename)?.keys(); + expect(keys).to.deep.equal(['Hello get', 'Hello instant', 'Hello stream'], `Accessor value: "${accessor}"`); + }); + }); + it('should support extracting binary expressions', () => { const contents = ` @Component({ })