Fix crash when constructor parameter has no type. Closes #38
This commit is contained in:
parent
5cef383f3b
commit
3b9561916b
4
.gitignore
vendored
4
.gitignore
vendored
@ -10,8 +10,8 @@ npm-debug.log*
|
||||
dist
|
||||
|
||||
# Extracted strings
|
||||
template.json
|
||||
template.pot
|
||||
strings.json
|
||||
strings.pot
|
||||
|
||||
# Dependency directory
|
||||
node_modules
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@biesbjerg/ngx-translate-extract",
|
||||
"version": "2.2.3",
|
||||
"version": "2.2.4",
|
||||
"description": "Extract strings from projects using ngx-translate",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
|
@ -49,6 +49,11 @@ export class ServiceParser extends AbstractAstParser implements ParserInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parameter has no type
|
||||
if (!parameter.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure className is of the correct type
|
||||
const parameterType: ts.Identifier = (parameter.type as ts.TypeReferenceNode).typeName as ts.Identifier;
|
||||
if (!parameterType) {
|
||||
|
@ -151,4 +151,17 @@ describe('ServiceParser', () => {
|
||||
expect(keys).to.deep.equal(['You are expected at {{time}}']);
|
||||
});
|
||||
|
||||
it('should not crash when constructor parameter has no type', () => {
|
||||
const contents = `
|
||||
@Component({ })
|
||||
export class AppComponent {
|
||||
public constructor(protected _translateService) { }
|
||||
public test() {
|
||||
this._translateService.instant('Hello World');
|
||||
}
|
||||
`;
|
||||
const keys = parser.extract(contents, componentFilename).keys();
|
||||
expect(keys).to.deep.equal([]);
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user