Fix bug in PipeParser

This commit is contained in:
Kim Biesbjerg 2017-01-13 09:34:34 +01:00
parent 7822916e28
commit fcd37fd000
3 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@biesbjerg/ng2-translate-extract",
"version": "0.5.0",
"version": "0.5.1",
"description": "Extract strings from projects using ng2-translate",
"main": "dist/index.js",
"typings": "dist/index.d.ts",

View File

@ -15,7 +15,7 @@ export class PipeParser extends AbstractTemplateParser implements ParserInterfac
protected _parseTemplate(template: string): TranslationCollection {
let collection: TranslationCollection = new TranslationCollection();
const regExp: RegExp = /(['"`])([^\1\r\n]*?)\1\s*\|\s*translate/g;
const regExp: RegExp = /(['"`])([^>\1\r\n]*?)\1\s*\|\s*translate/g;
let matches: RegExpExecArray;
while (matches = regExp.exec(template)) {
collection = collection.add(matches[2]);

View File

@ -12,6 +12,12 @@ describe('PipeParser', () => {
parser = new PipeParser();
});
it('should only extract string using pipe', () => {
const contents = `<button [style.background]="'lime'">{{ 'SomeKey_NotWorking' | translate }}</button>`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['SomeKey_NotWorking']);
});
it('should extract interpolated strings using translate pipe', () => {
const contents = `Hello {{ 'World' | translate }}`;
const keys = parser.extract(contents, templateFilename).keys();