UNPKG

@twstyled/babel-preset

Version:

Babel plugin for twstyled -- the full-featured Tailwind CSS + CSS in JS Compiler

45 lines (44 loc) 3.03 kB
import { TaggedTemplateExpression, JSXExpressionContainer, JSXElement, JSXFragment, StringLiteral, Identifier, TemplateLiteral, Expression, SourceLocation, SpreadElement, Node } from '@babel/types'; import type babelCore from '@babel/core'; import type { CorePluginState } from '../types'; export declare function asTemplateLiteral({ types: t }: { types: typeof babelCore.types; }, item: JSXExpressionContainer | StringLiteral | TaggedTemplateExpression | JSXElement | JSXFragment): TemplateLiteral; export declare function asTemplateLiteralFromArray({ types: t }: { types: typeof babelCore.types; }, prefix: string, items: Array<Expression | null | SpreadElement>): TemplateLiteral; /** * Utility function to wrap a given expression that might appear in a JSX tag * <Component twstyled="bg-blue-500" /> or <Component twstyled="{`bg-blue-500 ${mixin}`}" /> etc. * The function returns a tagged template literal wrapped with the specified starting and ending strings * <Component className={css`bg-blue-500;`} /> or <Component className={css`bg-blue-500 ${mixin};`} /> * @param param0 Babel * @param value The expression to wrap * @param tag The target tag of the tagged template literal, e.g., css * @param startString The string to insert at the beginning e.g. "@tailwind " * @param endString The string to insert at the end e.g, ";" */ export declare function wrapExpression({ types: t }: { types: typeof babelCore.types; }, node: JSXExpressionContainer | StringLiteral | TaggedTemplateExpression, tag: string, startReplacement?: string, endReplacement?: string): TaggedTemplateExpression | StringLiteral; export declare function prefixTemplateLiteral({ types: t }: { types: typeof babelCore.types; }, templateLiteral: TemplateLiteral, startReplacement: string, endReplacement: string): TemplateLiteral; /** * Utility function to wrap a given expression that might appear in a JSX tag * <Component twstyled="bg-blue-500" /> or <Component twstyled="{`bg-blue-500 ${mixin}`}" /> etc. * The function returns a tagged template literal wrapped with the specified starting and ending strings * <Component className={css`bg-blue-500;`} /> or <Component className={css`bg-blue-500 ${mixin};`} /> * @param param0 Babel * @param value The expression to wrap * @param tag The target tag of the tagged template literal, e.g., css * @param startString The string to insert at the beginning e.g. "@tailwind " * @param endString The string to insert at the end e.g, ";" */ export declare function combineExpressions({ types: t }: { types: typeof babelCore.types; }, leftExpression: TaggedTemplateExpression | StringLiteral, rightExpression: JSXExpressionContainer | StringLiteral): StringLiteral | JSXExpressionContainer; export declare function assureImport({ types: t }: { types: typeof babelCore.types; }, state: CorePluginState, importName: 'css' | 'styled', importSource: string): Identifier; export declare function withLoc<T extends Node>(element: T, loc: SourceLocation | null): T;