Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix TranslateService not resolved when injected with readonly keyword #39

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading