(refactor) simplify extraction of string literals
This commit is contained in:
@@ -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']);
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -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({ })
|
||||
|
Reference in New Issue
Block a user