diff --git a/src/rules/variables.ts b/src/rules/variables.ts index 35f4a57..4c11a51 100644 --- a/src/rules/variables.ts +++ b/src/rules/variables.ts @@ -32,7 +32,7 @@ export const cssProperty: Rule[] = [ const [prop, ...rest] = body.split(':') const value = rest.join(':') - if (!isURI(body) && prop.match(/^[a-z-]+$/) && isValidCSSBody(value)) { + if (!isURI(body) && /^[a-z-]+$/.test(prop) && isValidCSSBody(value)) { const parsed = h.bracket(`[${value}]`) if (parsed) return { [prop]: parsed } diff --git a/src/utils/handlers/handlers.ts b/src/utils/handlers/handlers.ts index dfc1878..755efc0 100644 --- a/src/utils/handlers/handlers.ts +++ b/src/utils/handlers/handlers.ts @@ -45,7 +45,7 @@ export function auto(str: string) { export function rem(str: string) { if (!str) return - if (str.match(unitOnlyRE)) + if (unitOnlyRE.test(str)) return `1${str}` const match = str.match(numberWithUnitRE) if (!match) @@ -60,7 +60,7 @@ export function rem(str: string) { } export function remToRpx(str: string) { - if (str.match(unitOnlyRE)) + if (unitOnlyRE.test(str)) return `1${str}` const match = str.match(numberWithUnitRE) if (!match) @@ -78,7 +78,7 @@ export function remToRpx(str: string) { // 小程序 rpx export function rpx(str: string) { - if (str.match(unitOnlyRE)) + if (unitOnlyRE.test(str)) return `${unitOnlyMap[str]}${str}` const match = str.match(numberWithUnitRE) if (!match) @@ -93,7 +93,7 @@ export function rpx(str: string) { } export function px(str: string) { - if (str.match(unitOnlyRE)) + if (unitOnlyRE.test(str)) return `${unitOnlyMap[str]}${str}` const match = str.match(numberWithUnitRE) if (!match) diff --git a/src/utils/utilities.ts b/src/utils/utilities.ts index ceaf0db..a80ed11 100644 --- a/src/utils/utilities.ts +++ b/src/utils/utilities.ts @@ -132,7 +132,7 @@ export function parseColor(body: string, theme: Theme, key?: ThemeColorKeys): Pa if (!color) { let colorData const [scale] = colors.slice(-1) - if (scale.match(/^\d+$/)) { + if (/^\d+$/.test(scale)) { no = scale colorData = getThemeColor(theme, colors.slice(0, -1)) if (!colorData || typeof colorData === 'string')