Skip to content

Commit

Permalink
fix(pipe): fatal error with operators in template
Browse files Browse the repository at this point in the history
  • Loading branch information
bartholomej committed Nov 23, 2021
1 parent 2761a9a commit 1775dd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/parsers/pipe.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class PipeParser implements ParserInterface {
// string concatenation, e.g.:
// - 'foo' + 'bar' + ('baz' | translate)
if (ast instanceof Binary) {
return this.getTranslatablesFromAsts([ast.left, ast.right]);
if (ast?.left && ast?.right) {
return this.getTranslatablesFromAsts([ast.left, ast.right]);
}
}

// a pipe on the outer expression, but not the translate pipe - ignore the pipe, visit the expression, e.g.:
Expand Down
8 changes: 8 additions & 0 deletions tests/parsers/pipe.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,12 @@ describe('PipeParser', () => {
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([`Hello`, `World`]);
});

it('should not break extraction in this special case with operators in template', () => {
const contents = `
<div [class.active]="+variable === -variable.item2">Active</div>
`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([]);
});
});

0 comments on commit 1775dd8

Please sign in to comment.