or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdindex.mdmacros.mdtransformation.md
tile.json

transformation.mddocs/

CSS Transformation

Core transformation functions for optimizing CSS expressions, styled components, and JSX attributes during Babel compilation.

Capabilities

CSS Call Expression Transformation

Transforms CSS call expressions for optimization, minification, and source map generation.

/**
 * Transform CSS call expressions for optimization
 * @param state - Babel plugin state containing options and context
 * @param babel - Babel instance with types and utilities
 * @param path - AST path to the CSS call expression
 * @param sourceMap - Optional source map string for debugging
 * @param annotateAsPure - Whether to add /*#__PURE__*/ comment (default: true)
 */
function transformCssCallExpression(params: TransformCssParams): void;

interface TransformCssParams {
  state: any;
  babel: any;
  path: any;
  sourceMap?: string;
  annotateAsPure?: boolean;
}

Usage Example:

// Input
const styles = css`
  color: red;
  font-size: 16px;
`;

// After transformation
const styles = /*#__PURE__*/ css('color:red;font-size:16px;');

CSS Array Expression Transformation

Transforms CSS array expressions in JSX attributes without css wrapper function.

/**
 * Transform CSS array expressions without css wrapper
 * @param state - Babel plugin state
 * @param babel - Babel instance
 * @param path - AST path to the array expression
 */
function transformCsslessArrayExpression(params: TransformParams): void;

Usage Example:

// Input JSX
<div css={[baseStyles, { color: 'blue' }]} />

// Gets transformed to optimized form

CSS Object Expression Transformation

Transforms CSS object expressions in JSX attributes without css wrapper function.

/**
 * Transform CSS object expressions without css wrapper
 * @param state - Babel plugin state  
 * @param babel - Babel instance
 * @param path - AST path to the object expression
 * @param cssImport - CSS import information for the transformation
 */
function transformCsslessObjectExpression(params: TransformObjectParams): void;

interface TransformObjectParams extends TransformParams {
  cssImport: { importSource: string; cssExport: string };
}

Usage Example:

// Input JSX
<div css={{ color: 'red', fontSize: 16 }} />

// Gets transformed and optimized

Style Expression Transformation

Core utility for transforming style expressions with labeling and optimization.

/**
 * Core utility for transforming expressions containing styles
 * @param babel - Babel instance
 * @param state - Plugin state with options
 * @param path - AST path to transform
 * @param shouldLabel - Whether to add automatic labels
 * @param sourceMap - Source map information
 * @returns Transformed AST node or null
 */
function transformExpressionWithStyles(params: TransformExpressionParams): any | null;

interface TransformExpressionParams {
  babel: any;
  state: any;
  path: any;
  shouldLabel: boolean;
  sourceMap?: string;
}

Styled Component Options

Extracts and processes options for styled components during transformation.

/**
 * Extract styled component options from AST
 * @param t - Babel types
 * @param path - AST path to styled component
 * @param state - Plugin state
 * @returns Styled component options object
 */
function getStyledOptions(t: any, path: any, state: any): any;

Usage Example:

// Input
const Button = styled.button.withConfig({
  displayName: 'MyButton',
  componentId: 'sc-123'
})`
  padding: 10px;
`;

// Options extracted and processed during transformation

Import Management

Utility for adding imports to transformed code.

/**
 * Utility for adding import statements to transformed code
 * @param t - Babel types
 * @param path - AST path where import should be added
 * @param importName - Name to import
 * @param importSource - Module to import from
 * @returns Import identifier
 */
function addImport(t: any, path: any, importName: string, importSource: string): any;

String Utilities

Utilities for string manipulation during CSS optimization.

/**
 * Append string-returning expression to function arguments
 */
function appendStringReturningExpressionToArguments(
  t: any,
  args: any[],
  expression: any
): void;

/**
 * Join consecutive string literals in argument list
 */
function joinStringLiterals(t: any, expressions: any[]): any[];

Object to String Conversion

Converts style objects to optimized string format.

/**
 * Convert style objects to optimized string format
 * @param obj - Style object to convert
 * @returns Simplified string representation
 */
function simplifyObject(obj: any): string;

Usage Example:

// Input object
{ color: 'red', fontSize: '16px', marginTop: '10px' }

// Simplified output
'color:red;font-size:16px;margin-top:10px;'

Source Map Generation

Generates source map information for transformed styles.

/**
 * Generate source map information for debugging
 * @param location - Source location information
 * @param state - Plugin state with source map options
 * @returns Source map string
 */
function getSourceMap(location: any, state: any): string;

Label Generation

Generates contextual labels for CSS classes from AST paths.

/**
 * Generate labels for CSS classes from AST paths
 * @param path - AST path to analyze
 * @param labelFormat - Format string for label generation
 * @returns Generated label string
 */
function getLabelFromPath(path: any, labelFormat?: string): string;

Target Class Name Resolution

Determines target class name for styled components.

/**
 * Determine target class name for styled components
 * @param path - AST path to styled component
 * @returns Target class name string
 */
function getTargetClassName(path: any): string;

CSS Minification

Minifies CSS template literals using Stylis compiler for size optimization.

/**
 * Minify CSS template literals for size optimization
 * @param path - AST path to template literal
 * @param t - Babel types
 */
function minify(path: any, t: any): void;

Usage Example:

// Input template literal
css`
  color: red;
  
  &:hover {
    color: blue;
  }
`;

// After minification
css('color:red;&:hover{color:blue;}');

TypeScript Transpilation Utilities

Utilities for handling TypeScript-transpiled template literals.

/**
 * Get TypeScript makeTemplateObject path from transpiled output
 * @param path - AST path to analyze
 * @returns Template object path or null
 */
function getTypeScriptMakeTemplateObjectPath(path: any): any | null;

/**
 * Check if tagged template was transpiled by Babel
 * @param path - AST path to check
 * @returns True if transpiled by Babel
 */
function isTaggedTemplateTranspiledByBabel(path: any): boolean;

Types

interface TransformParams {
  state: any;
  babel: any;
  path: any;
}

interface TransformCssParams extends TransformParams {
  sourceMap?: string;
  annotateAsPure?: boolean;
}

interface TransformExpressionParams extends TransformParams {
  shouldLabel: boolean;
  sourceMap?: string;
}

interface TransformObjectParams extends TransformParams {
  cssImport: { importSource: string; cssExport: string };
}