Make regexes more readable by not creating from string

This commit is contained in:
Kim Biesbjerg 2016-12-08 15:27:44 +01:00
parent fdf26d6af5
commit 3601b5985b
2 changed files with 3 additions and 3 deletions

View File

@ -5,14 +5,14 @@ export abstract class AbstractTemplateParser {
* makes the assumption that it is an Angular Component
*/
protected _isAngularComponent(filePath: string): boolean {
return new RegExp('\.(ts|js)$', 'i').test(filePath);
return new RegExp(/\.(ts|js)$/, 'i').test(filePath);
}
/**
* Extracts inline template from components
*/
protected _extractInlineTemplate(contents: string): string {
const match = new RegExp('template\\s?:\\s?("|\'|`)((.|[\\r\\n])+?[^\\\\])\\1').exec(contents);
const match = new RegExp(/template\s?:\s?("|\'|`)((.|[\r\n])+?[^\\])\1/).exec(contents);
if (match !== null) {
return match[2];
}

View File

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