Fix bug where keys were being extracted when not accessing TranslationService property
This commit is contained in:
		| @@ -12,7 +12,7 @@ export class ServiceParser implements ParserInterface { | ||||
| 		} | ||||
|  | ||||
| 		const methodRegExp: RegExp = /(?:get|instant)\s*\(\s*(\[?\s*(['"`])([^\1\r\n]*)\2\s*\]?)/; | ||||
| 		const regExp: RegExp = new RegExp(`${translateServiceVar}\.${methodRegExp.source}`, 'g'); | ||||
| 		const regExp: RegExp = new RegExp(`\\.${translateServiceVar}\\.${methodRegExp.source}`, 'g'); | ||||
|  | ||||
| 		let matches: RegExpExecArray; | ||||
| 		while (matches = regExp.exec(contents)) { | ||||
|   | ||||
| @@ -123,18 +123,18 @@ describe('ServiceParser', () => { | ||||
| 		expect(keys).to.deep.equal(['Hello', 'World', 'How', 'Are', 'You', 'Today']); | ||||
| 	}); | ||||
|  | ||||
| 	it('should extract strings with params', () => { | ||||
| 	it('should not extract string when not accessing property', () => { | ||||
| 		const contents = ` | ||||
| 			@Component({ }) | ||||
| 			export class AppComponent { | ||||
| 				public constructor(protected trans: TranslateService) { } | ||||
| 				public test() { | ||||
| 					trans.get("You are expected at {{time}}", {time: moment.format('H:mm')}).subscribe(); | ||||
| 					trans.get('Hello World'); | ||||
| 				} | ||||
| 			} | ||||
| 		`; | ||||
| 		const keys = parser.extract(contents, componentFilename).keys(); | ||||
| 		expect(keys).to.deep.equal(['You are expected at {{time}}']); | ||||
| 		expect(keys).to.deep.equal([]); | ||||
| 	}); | ||||
|  | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user