Skip to content

Commit fd373f2

Browse files
amilajackcrisbeto
authored andcommitted
refactor(animations): optimize resolveTimeExpression (#62927)
This moves a regexp expression into a const to optimize performance. PR Close #62927
1 parent 294fc88 commit fd373f2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/animations/browser/src/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ export function resolveTiming(
6565
: parseTimeExpression(<string | number>timings, errors, allowNegativeValues);
6666
}
6767

68+
const PARSE_TIME_EXPRESSION_REGEX =
69+
/^(-?[\.\d]+)(m?s)(?:\s+(-?[\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?$/i;
6870
function parseTimeExpression(
6971
exp: string | number,
7072
errors: Error[],
7173
allowNegativeValues?: boolean,
7274
): AnimateTimings {
73-
const regex = /^(-?[\.\d]+)(m?s)(?:\s+(-?[\.\d]+)(m?s))?(?:\s+([-a-z]+(?:\(.+?\))?))?$/i;
7475
let duration: number;
7576
let delay: number = 0;
7677
let easing: string = '';
7778
if (typeof exp === 'string') {
78-
const matches = exp.match(regex);
79+
const matches = exp.match(PARSE_TIME_EXPRESSION_REGEX);
7980
if (matches === null) {
8081
errors.push(invalidTimingValue(exp));
8182
return {duration: 0, delay: 0, easing: ''};

packages/core/test/bundling/animations-standalone/bundle.golden_symbols.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
"OperatorSubscriber",
193193
"PARAM_REGEX",
194194
"PARENT",
195+
"PARSE_TIME_EXPRESSION_REGEX",
195196
"PLATFORM_BROWSER_ID",
196197
"PLATFORM_DESTROY_LISTENERS",
197198
"PLATFORM_ID",

0 commit comments

Comments
 (0)