Skip to content

Commit

Permalink
rename utility parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredh159 committed Apr 1, 2024
1 parent a02ca87 commit 7ac5130
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
27 changes: 10 additions & 17 deletions src/ClassParser.ts → src/UtilityParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@ 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';
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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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 });
}
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7ac5130

Please sign in to comment.