Skip to content

Commit 4a3f10a

Browse files
authored
fix(pipe-parser): detect keys inside template literals (#141)
1 parent 3f9affa commit 4a3f10a

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/parsers/pipe.parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
KeyedRead,
1919
ASTWithSource,
2020
ParenthesizedExpression,
21+
TemplateLiteral,
2122
} from '@angular/compiler';
2223

2324
import { getAST, getNodesFromSwitchBlockTmpl } from '../utils/ast-helpers.js';
@@ -230,6 +231,10 @@ export class PipeParser implements ParserInterface {
230231
return this.getTranslatablesFromAsts([ast.expression]);
231232
}
232233

234+
if (ast instanceof TemplateLiteral) {
235+
return this.getTranslatablesFromAsts(ast.expressions);
236+
}
237+
233238
return [];
234239
}
235240

tests/parsers/pipe.parser.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ describe('PipeParser', () => {
334334
expect(multipleConditionKeys).to.deep.equal(['translation.key']);
335335
});
336336

337+
it('should extract key from translate pipe inside template literals', () => {
338+
const contents = "<div>{{ `${'translation.key' | translate}, ${'another.key' | translate}` }}</div>";
339+
const keys = parser.extract(contents, templateFilename).keys();
340+
expect(keys).to.deep.equal(['translation.key', 'another.key']);
341+
});
342+
337343
it('should not extract empty strings as keys', () => {
338344
const contents = `<div>{{ '' | translate }}</div>`;
339345
const keys = parser.extract(contents, templateFilename).keys();

0 commit comments

Comments
 (0)