Skip to content

Commit

Permalink
feat: enable jit features all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadsammy committed Dec 12, 2021
1 parent 6a8183f commit 84f281b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 53 deletions.
60 changes: 17 additions & 43 deletions src/cli/core/ClassnamesGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ export class ClassnamesGenerator {
};
};

private isJitModeEnabled = (): boolean => this._configParser.getMode() === 'jit';

private layout = (): Layout | Record<keyof Layout | 'content', string[]> => {
const classnames = {
return {
...nonConfigurableClassNames.layout,
objectPosition: Object.keys(this._theme.objectPosition).map(x => 'object-' + x),
inset: Object.keys(this._theme.inset).flatMap(insetValue => {
Expand All @@ -93,13 +91,8 @@ export class ClassnamesGenerator {
zIndex: Object.keys(this._theme.zIndex).flatMap(zIndexValue =>
zIndexValue.startsWith('-') ? `-z-${zIndexValue.substring(1)}` : `z-${zIndexValue}`,
),
content: Object.keys(this._theme.content).map(x => 'content-' + x),
};

if (this.isJitModeEnabled()) {
return {...classnames, content: Object.keys(this._theme.content).map(x => 'content-' + x)};
} else {
return classnames;
}
};

private backgrounds = (): Backgrounds => {
Expand All @@ -117,7 +110,7 @@ export class ClassnamesGenerator {
};

private borders = (): Borders | Record<keyof Borders | 'caretColor', string[]> => {
const classnames = {
return {
// Add all non configurable classes in `borders` plugin.
// These are utilities that their names never change e.g. border styles (dashed, solid etc.)
...nonConfigurableClassNames.borders,
Expand All @@ -133,7 +126,7 @@ export class ClassnamesGenerator {
const sides = ['t', 'r', 'b', 'l'];
return sides.map(side => `border-${side}-${width}`).concat(`border-${width}`);
}),

caretColor: this.generateClassesWithColors('caretColor'),
/* Dynamic divide utilities */
divideColor: this.generateClassesWithColors('divideColor'),
divideOpacity: this.getGeneratedClassesWithOpacities().divideOpacities,
Expand All @@ -154,10 +147,6 @@ export class ClassnamesGenerator {
ringOffsetColor: this.generateClassesWithColors('ringOffsetColor'),
ringOffsetWidth: Object.keys(this._theme.ringOffsetWidth).map(x => 'ring-offset-' + x),
};

return this.isJitModeEnabled()
? {...classnames, caretColor: this.generateClassesWithColors('caretColor')}
: classnames;
};

private tables = (): Tables => {
Expand Down Expand Up @@ -425,33 +414,23 @@ export class ClassnamesGenerator {
`${key}.${regularClassGroupKey}`,
) as string[];

// If JIT compiler mode is enabled...
if (this.isJitModeEnabled()) {
// Duplicate classnames with an important (!) prefix
const generatedClassGroupWithImportantPrefix = generatedClassGroup.map(
cls => '!' + cls,
);
// Duplicate classnames with an important (!) prefix
const generatedClassGroupWithImportantPrefix = generatedClassGroup.map(cls => '!' + cls);

// Append the classnames with important prefix to the regular classnames
generatedClassGroup = generatedClassGroup.concat(
generatedClassGroupWithImportantPrefix,
);
// Append the classnames with important prefix to the regular classnames
generatedClassGroup = generatedClassGroup.concat(generatedClassGroupWithImportantPrefix);

// Append the classnames with important prefix to the pseudo classes array
generatedClassGroupWithImportantPrefix.map(cls => pseudoClasses.push(cls));
}
// Append the classnames with important prefix to the pseudo classes array
generatedClassGroupWithImportantPrefix.map(cls => pseudoClasses.push(cls));

// For every member of the found regular classes group...
generatedClassGroup.map(classname => {
const isDarkModeEnabled = this._darkMode !== false;

// If JIT compiler mode is enabled...
if (this.isJitModeEnabled()) {
// Enable all variants
pseudoClassesVariantsForKey = allVariants;
// Add 'peer' utility classname. used with peer-* classnames
pseudoClasses.push('peer');
}
// Enable all variants
pseudoClassesVariantsForKey = allVariants;
// Add 'peer' utility classname. used with peer-* classnames
pseudoClasses.push('peer');

// Generate the classname of each variant...
pseudoClassesVariantsForKey.map(variant => {
Expand Down Expand Up @@ -535,7 +514,7 @@ export class ClassnamesGenerator {
if (typeof colorValue === 'object' && colorValue !== null) {
// Loop over the deep objects and return the result for each key of the object.
return Object.keys(colorValue).flatMap(shade => {
if (utilName === 'border' && this.isJitModeEnabled()) {
if (utilName === 'border') {
return ['', 't', 'r', 'b', 'l'].map(
side => `${utilName}-${side.length > 0 ? side + '-' : ''}${colorName}-${shade}`,
);
Expand All @@ -547,7 +526,7 @@ export class ClassnamesGenerator {
// Otherwise...
else {
// Return the result of merging the utility name with color value
if (utilName === 'border' && this.isJitModeEnabled()) {
if (utilName === 'border') {
return ['', 't', 'r', 'b', 'l'].map(
side => `${utilName}-${side.length > 0 ? side + '-' : ''}${colorName}`,
);
Expand All @@ -562,12 +541,7 @@ export class ClassnamesGenerator {
this._configParser.getTheme().opacity,
).flatMap(op => classnamesWithColors.map(cls => cls + '/' + op));

// Return the result classnames based on whether JIT mode is enabled or not
if (this.isJitModeEnabled()) {
return classnamesWithColors.concat(classnamesWithColorsAndOpacitySuffix);
} else {
return classnamesWithColors;
}
return classnamesWithColors.concat(classnamesWithColorsAndOpacitySuffix);
};

private getGeneratedClassesWithOpacities = (): ClassesWithOpacities => {
Expand Down
15 changes: 5 additions & 10 deletions src/cli/core/TailwindConfigParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ export class TailwindConfigParser {
this._pluginsConfig = plugins;
}

/**
* Gets the config mode value
*/
public getMode = (): string | undefined => this._mode;

/**
* Gets the config prefix value
*/
Expand Down Expand Up @@ -190,11 +185,11 @@ class ThemeClosuresEvaluator {
/**
* Creates evaluator for `theme()` functions/closures in config file
*/
private makeThemePathResolver = (theme: Partial<TThemeItems>) => (
path: string,
): Record<string, unknown> => {
return _.get(theme, _.trim(path, `'"`)) as Record<string, Record<string, string> | string>;
};
private makeThemePathResolver =
(theme: Partial<TThemeItems>) =>
(path: string): Record<string, unknown> => {
return _.get(theme, _.trim(path, `'"`)) as Record<string, Record<string, string> | string>;
};

/**
* Evaluate `negative()` functions/closures
Expand Down

0 comments on commit 84f281b

Please sign in to comment.