(refactor) simplify extraction of string literals

This commit is contained in:
Kim Biesbjerg
2019-06-13 11:23:37 +02:00
parent 02fc705bc0
commit 4fd7efa2dc
5 changed files with 71 additions and 77 deletions

View File

@@ -19,9 +19,11 @@ describe('FunctionParser', () => {
_('Hello world');
_(['I', 'am', 'extracted']);
otherFunction('But I am not');
_(message || 'binary expression');
_(message ? message : 'conditional operator');
`;
const keys = parser.extract(contents, componentFilename).keys();
expect(keys).to.deep.equal(['Hello world', 'I', 'am', 'extracted']);
expect(keys).to.deep.equal(['Hello world', 'I', 'am', 'extracted', 'binary expression', 'conditional operator']);
});
});

View File

@@ -16,6 +16,34 @@ describe('ServiceParser', () => {
parser = new TestServiceParser();
});
it('should support extracting binary expressions', () => {
const contents = `
@Component({ })
export class AppComponent {
public constructor(protected _translateService: TranslateService) { }
public test() {
const message = 'The Message';
this._translateService.get(message || 'Fallback message');
}
`;
const keys = parser.extract(contents, componentFilename).keys();
expect(keys).to.deep.equal(['Fallback message']);
});
it('should support conditional operator', () => {
const contents = `
@Component({ })
export class AppComponent {
public constructor(protected _translateService: TranslateService) { }
public test() {
const message = 'The Message';
this._translateService.get(message ? message : 'Fallback message');
}
`;
const keys = parser.extract(contents, componentFilename).keys();
expect(keys).to.deep.equal(['Fallback message']);
});
it('should extract strings in TranslateService\'s get() method', () => {
const contents = `
@Component({ })