From c49bca140550c37d779a0442c221e9413ccf2d1f Mon Sep 17 00:00:00 2001 From: hlomzik Date: Wed, 20 Dec 2023 15:53:00 +0000 Subject: [PATCH 1/2] fix: LEAP-381: Remove excess regexp from BEM module --- src/utils/bem.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/bem.tsx b/src/utils/bem.tsx index ba27352f..c55acebe 100644 --- a/src/utils/bem.tsx +++ b/src/utils/bem.tsx @@ -110,10 +110,8 @@ const assembleClass = (block: string, elem?: string, mix?: CNMix | CNMix[], mod? finalClass.push(...Array.from(new Set(mixMap))); } - const attachNamespace = (cls: string) => { - if (new RegExp(CSS_PREFIX).test(cls)) return cls; - else return `${CSS_PREFIX}${cls}`; - }; + const attachNamespace = (cls: string) => + cls.startsWith(CSS_PREFIX) ? cls : `${CSS_PREFIX}${cls}`; return finalClass.map(attachNamespace).join(" "); }; From 4f212743edf3004a6b26733134e8f309166fb5e2 Mon Sep 17 00:00:00 2001 From: hlomzik Date: Wed, 27 Dec 2023 15:14:12 +0000 Subject: [PATCH 2/2] Allow incorrect usage and add warning about it --- src/utils/bem.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/bem.tsx b/src/utils/bem.tsx index c55acebe..9a808d19 100644 --- a/src/utils/bem.tsx +++ b/src/utils/bem.tsx @@ -110,8 +110,10 @@ const assembleClass = (block: string, elem?: string, mix?: CNMix | CNMix[], mod? finalClass.push(...Array.from(new Set(mixMap))); } - const attachNamespace = (cls: string) => - cls.startsWith(CSS_PREFIX) ? cls : `${CSS_PREFIX}${cls}`; + const attachNamespace = (cls: string) => { + if (typeof cls !== 'string') console.error('Non-string classname: ', cls); + return String(cls).startsWith(CSS_PREFIX) ? cls : `${CSS_PREFIX}${cls}`; + }; return finalClass.map(attachNamespace).join(" "); };