fix(pipe-parser): add support for more sophisticated expressions that worked in version 4.2.0 with the regex based parser (#185)
* fix(pipe-parser): add support for more sophisticated expressions
This commit is contained in:
committed by
GitHub
parent
5e0da552b0
commit
619b3c56ea
@@ -47,12 +47,48 @@ describe('PipeParser', () => {
|
||||
expect(keys).to.deep.equal(['Hello', 'World']);
|
||||
});
|
||||
|
||||
it('should extract strings from ternary operators right expression', () => {
|
||||
const contents = `{{ condition ? null : ('World' | translate) }}`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['World']);
|
||||
});
|
||||
|
||||
it('should extract strings from ternary operators inside attribute bindings', () => {
|
||||
const contents = `<span [attr]="condition ? null : ('World' | translate)"></span>`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['World']);
|
||||
});
|
||||
|
||||
it('should extract strings from ternary operators left expression', () => {
|
||||
const contents = `{{ condition ? ('World' | translate) : null }}`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['World']);
|
||||
});
|
||||
|
||||
it('should extract strings inside string concatenation', () => {
|
||||
const contents = `{{ 'a' + ('Hello' | translate) + 'b' + 'c' + ('World' | translate) + 'd' }}`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['Hello', 'World']);
|
||||
});
|
||||
|
||||
it('should extract strings from object', () => {
|
||||
const contents = `{{ { foo: 'Hello' | translate, bar: ['World' | translate], deep: { nested: { baz: 'Yes' | translate } } } | json }}`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['Hello', 'World', 'Yes']);
|
||||
});
|
||||
|
||||
it('should extract strings from ternary operators inside attribute bindings', () => {
|
||||
const contents = `<span [attr]="(condition ? 'Hello' : 'World') | translate"></span>`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['Hello', 'World']);
|
||||
});
|
||||
|
||||
it('should extract strings from nested expressions', () => {
|
||||
const contents = `<span [attr]="{ foo: ['a' + ((condition ? 'Hello' : 'World') | translate) + 'b'] }"></span>`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
expect(keys).to.deep.equal(['Hello', 'World']);
|
||||
});
|
||||
|
||||
it('should extract strings from nested ternary operators ', () => {
|
||||
const contents = `<h3>{{ (condition ? 'Hello' : anotherCondition ? 'Nested' : 'World' ) | translate }}</h3>`;
|
||||
const keys = parser.extract(contents, templateFilename).keys();
|
||||
|
Reference in New Issue
Block a user