Skip to content

Commit

Permalink
fix: Fix TranslateService not resolved when injected with readonly ke…
Browse files Browse the repository at this point in the history
…yword (#39)

Closes #37
  • Loading branch information
pmpak authored Mar 8, 2024
1 parent 2d1a292 commit 7c639d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/ast-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Identifier>(node, query);
return result.map((n) => n.text);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/parsers/service.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({ })
Expand Down

0 comments on commit 7c639d1

Please sign in to comment.