Home / File/ ast.bench.ts — tailwindcss Source File

ast.bench.ts — tailwindcss Source File

Architecture documentation for ast.bench.ts, a typescript file in the tailwindcss codebase. 5 imports, 0 dependents.

File typescript Oxide Scanner 5 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  a2ef882b_7487_6c59_65f1_90f22f9499ea["ast.bench.ts"]
  b9cbffa4_c352_cf3c_268f_cbb174fb3a47["ast.ts"]
  a2ef882b_7487_6c59_65f1_90f22f9499ea --> b9cbffa4_c352_cf3c_268f_cbb174fb3a47
  dbd80fa4_4b36_fb8e_fb6e_f2aec789aa6b["cloneAstNode"]
  a2ef882b_7487_6c59_65f1_90f22f9499ea --> dbd80fa4_4b36_fb8e_fb6e_f2aec789aa6b
  9b49f3c6_0c8d_5c62_965c_30a1db6499f8["toCss"]
  a2ef882b_7487_6c59_65f1_90f22f9499ea --> 9b49f3c6_0c8d_5c62_965c_30a1db6499f8
  8be42ab2_7e92_957a_da93_ffe4c7d161fe["css-parser.ts"]
  a2ef882b_7487_6c59_65f1_90f22f9499ea --> 8be42ab2_7e92_957a_da93_ffe4c7d161fe
  f1e05e5f_c1b2_a3f5_b2e8_3317b9243ac3["vitest"]
  a2ef882b_7487_6c59_65f1_90f22f9499ea --> f1e05e5f_c1b2_a3f5_b2e8_3317b9243ac3
  style a2ef882b_7487_6c59_65f1_90f22f9499ea fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { bench, describe } from 'vitest'
import { cloneAstNode, toCss, type AstNode } from './ast'
import * as CSS from './css-parser'

const css = String.raw
const input = css`
  @theme {
    --color-primary: #333;
  }
  @tailwind utilities;
  .foo {
    color: red;
    /* comment */
    &:hover {
      color: blue;
      @apply font-bold;
    }
  }
`
const ast = CSS.parse(input)

describe('AST to CSS', () => {
  bench('toCss', () => {
    toCss(ast)
  })

  bench('toCss with source maps', () => {
    toCss(ast, true)
  })
})

describe('Cloning AST nodes', () => {
  bench('cloneAstNode()', () => {
    ast.map(cloneAstNode)
  })

  bench('cloneAstNode (with spread)', () => {
    ast.map(cloneAstNodeSpread)
  })

  bench('structuredClone()', () => {
    structuredClone(ast)
  })
})

function cloneAstNodeSpread<T extends AstNode>(node: T): T {
  switch (node.kind) {
    case 'rule':
    case 'at-rule':
    case 'at-root':
      return { ...node, nodes: node.nodes.map(cloneAstNodeSpread) }

    case 'context':
      return { ...node, context: { ...node.context }, nodes: node.nodes.map(cloneAstNodeSpread) }

    case 'declaration':
    case 'comment':
      return { ...node }

    default:
      node satisfies never
      throw new Error(`Unknown node kind: ${(node as any).kind}`)
  }
}

Domain

Subdomains

Frequently Asked Questions

What does ast.bench.ts do?
ast.bench.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the Oxide domain, Scanner subdomain.
What functions are defined in ast.bench.ts?
ast.bench.ts defines 1 function(s): cloneAstNodeSpread.
What does ast.bench.ts depend on?
ast.bench.ts imports 5 module(s): ast.ts, cloneAstNode, css-parser.ts, toCss, vitest.
Where is ast.bench.ts in the architecture?
ast.bench.ts is located at packages/tailwindcss/src/ast.bench.ts (domain: Oxide, subdomain: Scanner, directory: packages/tailwindcss/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free