From e12933a3aa686f6e63b8f1ac142e6d0e3f6d54b3 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 3 Dec 2019 08:36:38 +0000 Subject: [PATCH] test(ngcc): tidy up helper function (#34135) Thanks to @gkalpakl for the better regular expression approach. PR Close #34135 --- packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts index 8b161ac45e..13fe6d0a5d 100644 --- a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts +++ b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts @@ -1293,10 +1293,6 @@ runInEachFileSystem(() => { }); function countOccurrences(haystack: string, needle: string): number { - const regex = new RegExp(needle, 'g'); - let count = 0; - while (regex.exec(haystack)) { - count++; - } - return count; + const matches = haystack.match(new RegExp(needle, 'g')); + return matches !== null ? matches.length : 0; }