From 7ac5130d6dde7125d56488076785d928ca4d3d69 Mon Sep 17 00:00:00 2001 From: Jared Henderson Date: Mon, 1 Apr 2024 14:06:29 -0400 Subject: [PATCH] rename utility parser --- src/{ClassParser.ts => UtilityParser.ts} | 27 +++++++++--------------- src/create.ts | 6 +++--- 2 files changed, 13 insertions(+), 20 deletions(-) rename src/{ClassParser.ts => UtilityParser.ts} (94%) diff --git a/src/ClassParser.ts b/src/UtilityParser.ts similarity index 94% rename from src/ClassParser.ts rename to src/UtilityParser.ts index a85233c..fe8d559 100644 --- a/src/ClassParser.ts +++ b/src/UtilityParser.ts @@ -9,14 +9,7 @@ import { isOrientation, isPlatform } from './types'; import fontFamily from './resolve/font-family'; import { color, colorOpacity } from './resolve/color'; import { border, borderRadius } from './resolve/borders'; -import { - getCompleteStyle, - getDirection, - unconfiggedStyle, - warn, - complete, - parseNumericValue, -} from './helpers'; +import * as h from './helpers'; import { inset } from './resolve/inset'; import { flexGrowShrink, flexBasis, flex, gap } from './resolve/flex'; import { widthHeight, minMaxWidthHeight } from './resolve/width-height'; @@ -24,7 +17,7 @@ import { letterSpacing } from './resolve/letter-spacing'; import { opacity } from './resolve/opacity'; import { shadowOpacity, shadowOffset } from './resolve/shadow'; -export default class ClassParser { +export default class UtilityParser { private position = 0; private string: string; private char?: string; @@ -91,7 +84,7 @@ export default class ClassParser { if (match) { const prop = this.char === `m` ? `margin` : `padding`; this.advance((match[0]?.length ?? 0) + 1); - const spacingDirection = getDirection(match[1]); + const spacingDirection = h.getDirection(match[1]); const style = spacing( prop, spacingDirection, @@ -159,9 +152,9 @@ export default class ClassParser { if (this.consumePeeked(`aspect-`)) { if (this.consumePeeked(`ratio-`)) { - warn(`\`aspect-ratio-{ratio}\` is deprecated, use \`aspect-{ratio}\` instead`); + h.warn(`\`aspect-ratio-{ratio}\` is deprecated, use \`aspect-{ratio}\` instead`); } - style = getCompleteStyle(`aspectRatio`, this.rest, { fractions: true }); + style = h.getCompleteStyle(`aspectRatio`, this.rest, { fractions: true }); if (style) return style; } @@ -269,7 +262,7 @@ export default class ClassParser { } if (this.consumePeeked(`shadow-radius-`)) { - style = unconfiggedStyle(`shadowRadius`, this.rest); + style = h.unconfiggedStyle(`shadowRadius`, this.rest); if (style) return style; } @@ -281,7 +274,7 @@ export default class ClassParser { if (this.consumePeeked(`elevation-`)) { const elevation = parseInt(this.rest, 10); if (!Number.isNaN(elevation)) { - return complete({ elevation }); + return h.complete({ elevation }); } } @@ -298,11 +291,11 @@ export default class ClassParser { if (this.consumePeeked(`z-`)) { const zIndex = Number(theme?.zIndex?.[this.rest] ?? this.rest); if (!Number.isNaN(zIndex)) { - return complete({ zIndex: this.isNegative ? -zIndex : zIndex }); + return h.complete({ zIndex: this.isNegative ? -zIndex : zIndex }); } } - warn(`\`${this.rest}\` unknown or invalid utility`); + h.warn(`\`${this.rest}\` unknown or invalid utility`); return null; } @@ -321,7 +314,7 @@ export default class ClassParser { const windowDims = this.context.device.windowDimensions; const [, type = ``, dir = ``, amount = ``] = match; const checkDimension = dir === `w` ? windowDims.width : windowDims.height; - const parsedAmount = parseNumericValue(amount, this.context); + const parsedAmount = h.parseNumericValue(amount, this.context); if (parsedAmount === null) { this.isNull = true; return true; diff --git a/src/create.ts b/src/create.ts index 9ecf705..3494e3c 100644 --- a/src/create.ts +++ b/src/create.ts @@ -12,7 +12,7 @@ import type { } from './types'; import type { TwConfig } from './tw-config'; import Cache from './cache'; -import ClassParser from './ClassParser'; +import UtilityParser from './UtilityParser'; import { configColor, removeOpacityHelpers } from './resolve/color'; import { parseInputs } from './parse-inputs'; import { complete, warn } from './helpers'; @@ -100,7 +100,7 @@ export function create(customConfig: TwConfig, platform: Platform): TailwindFn { for (const utility of utilities) { let styleIr = cache.getIr(utility); if (!styleIr) { - const parser = new ClassParser(utility, config, cache, device, platform); + const parser = new UtilityParser(utility, config, cache, device, platform); styleIr = parser.parse(); } @@ -184,7 +184,7 @@ export function create(customConfig: TwConfig, platform: Platform): TailwindFn { if (cached !== undefined) { return cached; } - const parser = new ClassParser(`${joined}:flex`, config, cache, device, platform); + const parser = new UtilityParser(`${joined}:flex`, config, cache, device, platform); const ir = parser.parse(); const prefixMatches = ir.kind !== `null`; cache.setPrefixMatch(joined, prefixMatches);