Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4e351405fb | ||
|
39a335638b | ||
|
3b9561916b | ||
|
5cef383f3b |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -10,8 +10,8 @@ npm-debug.log*
|
|||||||
dist
|
dist
|
||||||
|
|
||||||
# Extracted strings
|
# Extracted strings
|
||||||
template.json
|
strings.json
|
||||||
template.pot
|
strings.pot
|
||||||
|
|
||||||
# Dependency directory
|
# Dependency directory
|
||||||
node_modules
|
node_modules
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@biesbjerg/ngx-translate-extract",
|
"name": "@biesbjerg/ngx-translate-extract",
|
||||||
"version": "2.2.2",
|
"version": "2.2.5",
|
||||||
"description": "Extract strings from projects using ngx-translate",
|
"description": "Extract strings from projects using ngx-translate",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import { CompilerInterface } from './compiler.interface';
|
import { CompilerInterface } from './compiler.interface';
|
||||||
import { TranslationCollection } from '../utils/translation.collection';
|
import { TranslationCollection } from '../utils/translation.collection';
|
||||||
|
|
||||||
|
import * as flat from 'flat';
|
||||||
|
|
||||||
export class JsonCompiler implements CompilerInterface {
|
export class JsonCompiler implements CompilerInterface {
|
||||||
|
|
||||||
public indentation: string = '\t';
|
public indentation: string = '\t';
|
||||||
@@ -18,7 +20,15 @@ export class JsonCompiler implements CompilerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public parse(contents: string): TranslationCollection {
|
public parse(contents: string): TranslationCollection {
|
||||||
return new TranslationCollection(JSON.parse(contents));
|
let values: any = JSON.parse(contents);
|
||||||
|
if (this._isNamespacedJsonFormat(values)) {
|
||||||
|
values = flat.flatten(values);
|
||||||
|
}
|
||||||
|
return new TranslationCollection(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected _isNamespacedJsonFormat(values: any): boolean {
|
||||||
|
return Object.keys(values).some(key => typeof values[key] === 'object');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,11 @@ export class ServiceParser extends AbstractAstParser implements ParserInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parameter has no type
|
||||||
|
if (!parameter.type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure className is of the correct type
|
// Make sure className is of the correct type
|
||||||
const parameterType: ts.Identifier = (parameter.type as ts.TypeReferenceNode).typeName as ts.Identifier;
|
const parameterType: ts.Identifier = (parameter.type as ts.TypeReferenceNode).typeName as ts.Identifier;
|
||||||
if (!parameterType) {
|
if (!parameterType) {
|
||||||
|
@@ -151,4 +151,17 @@ describe('ServiceParser', () => {
|
|||||||
expect(keys).to.deep.equal(['You are expected at {{time}}']);
|
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([]);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user