From 3601b5985bbe68786f3aa5204572c5cdb85a28e0 Mon Sep 17 00:00:00 2001 From: Kim Biesbjerg Date: Thu, 8 Dec 2016 15:27:44 +0100 Subject: [PATCH] Make regexes more readable by not creating from string --- src/parsers/abstract-template.parser.ts | 4 ++-- src/parsers/pipe.parser.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/parsers/abstract-template.parser.ts b/src/parsers/abstract-template.parser.ts index 5b66fe9..607314e 100644 --- a/src/parsers/abstract-template.parser.ts +++ b/src/parsers/abstract-template.parser.ts @@ -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]; } diff --git a/src/parsers/pipe.parser.ts b/src/parsers/pipe.parser.ts index cce8479..65c44e4 100644 --- a/src/parsers/pipe.parser.ts +++ b/src/parsers/pipe.parser.ts @@ -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)) {