Home / File/ ast.ts — tailwindcss Source File

ast.ts — tailwindcss Source File

Architecture documentation for ast.ts, a typescript file in the tailwindcss codebase. 11 imports, 3 dependents.

File typescript BuildIntegrations PostCSSPlugin 11 imports 3 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  25f462e7_c718_35c5_7ff1_b1b41cc176bf["ast.ts"]
  42640952_ea63_55f1_1ff1_00816e2980ae["ast.ts"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> 42640952_ea63_55f1_1ff1_00816e2980ae
  f9b19679_c1f0_28d6_4d1a_31a10c52e42d["atRule"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> f9b19679_c1f0_28d6_4d1a_31a10c52e42d
  96bdb9bb_93af_2fac_25bd_5a2e67895fa7["comment"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> 96bdb9bb_93af_2fac_25bd_5a2e67895fa7
  c203f636_607a_d332_b4c5_6a40c108f778["decl"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> c203f636_607a_d332_b4c5_6a40c108f778
  66319c06_7c38_f9ea_4bf0_2a0e18bac1a4["rule"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> 66319c06_7c38_f9ea_4bf0_2a0e18bac1a4
  ac7e86e1_459b_f374_4516_afecc84f2a17["line-table.ts"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> ac7e86e1_459b_f374_4516_afecc84f2a17
  0204f9b9_80aa_c3e8_eb61_22170d608d65["createLineTable"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> 0204f9b9_80aa_c3e8_eb61_22170d608d65
  224e6d20_656a_4689_b56d_bc18bf3b80d9["source.ts"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> 224e6d20_656a_4689_b56d_bc18bf3b80d9
  c056448b_f7a2_9149_54e8_f0f8470fe3aa["default-map.ts"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> c056448b_f7a2_9149_54e8_f0f8470fe3aa
  bf2992f6_4a37_8536_70f8_94b13631027d["DefaultMap"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> bf2992f6_4a37_8536_70f8_94b13631027d
  ba54c7c3_7b1e_9984_bfef_a693a3df2d84["postcss"]
  25f462e7_c718_35c5_7ff1_b1b41cc176bf --> ba54c7c3_7b1e_9984_bfef_a693a3df2d84
  afa9c75b_3990_72fb_2aba_c3e6b361eec3["ast.test.ts"]
  afa9c75b_3990_72fb_2aba_c3e6b361eec3 --> 25f462e7_c718_35c5_7ff1_b1b41cc176bf
  4d87ade3_79e3_f749_8b40_7a0e8f43b9dc["index.ts"]
  4d87ade3_79e3_f749_8b40_7a0e8f43b9dc --> 25f462e7_c718_35c5_7ff1_b1b41cc176bf
  41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1["stylesheet.ts"]
  41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1 --> 25f462e7_c718_35c5_7ff1_b1b41cc176bf
  style 25f462e7_c718_35c5_7ff1_b1b41cc176bf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type * as postcss from 'postcss'
import { atRule, comment, decl, rule, type AstNode } from '../../tailwindcss/src/ast'
import { createLineTable, type LineTable } from '../../tailwindcss/src/source-maps/line-table'
import type { Source, SourceLocation } from '../../tailwindcss/src/source-maps/source'
import { DefaultMap } from '../../tailwindcss/src/utils/default-map'

const EXCLAMATION_MARK = 0x21

export function cssAstToPostCssAst(
  postcss: postcss.Postcss,
  ast: AstNode[],
  source?: postcss.Source,
): postcss.Root {
  let inputMap = new DefaultMap<Source, postcss.Input>((src) => {
    return new postcss.Input(src.code, {
      map: source?.input.map,
      from: src.file ?? undefined,
    })
  })

  let lineTables = new DefaultMap<Source, LineTable>((src) => createLineTable(src.code))

  let root = postcss.root()
  root.source = source

  function toSource(loc: SourceLocation | undefined): postcss.Source | undefined {
    // Use the fallback if this node has no location info in the AST
    if (!loc) return
    if (!loc[0]) return

    let table = lineTables.get(loc[0])
    let start = table.find(loc[1])
    let end = table.find(loc[2])

    return {
      input: inputMap.get(loc[0]),
      start: {
        line: start.line,
        column: start.column + 1,
        offset: loc[1],
      },
      end: {
        line: end.line,
        column: end.column + 1,
        offset: loc[2],
      },
    }
  }

  function updateSource(astNode: postcss.ChildNode, loc: SourceLocation | undefined) {
    let source = toSource(loc)

    // The `source` property on PostCSS nodes must be defined if present because
    // `toJSON()` reads each property and tries to read from source.input if it
    // sees a `source` property. This means for a missing or otherwise absent
    // source it must be *missing* from the object rather than just `undefined`
    if (source) {
      astNode.source = source
    } else {
      delete astNode.source
// ... (130 more lines)

Subdomains

Frequently Asked Questions

What does ast.ts do?
ast.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the BuildIntegrations domain, PostCSSPlugin subdomain.
What functions are defined in ast.ts?
ast.ts defines 2 function(s): cssAstToPostCssAst, postCssAstToCssAst.
What does ast.ts depend on?
ast.ts imports 11 module(s): DefaultMap, ast.ts, atRule, comment, createLineTable, decl, default-map.ts, line-table.ts, and 3 more.
What files import ast.ts?
ast.ts is imported by 3 file(s): ast.test.ts, index.ts, stylesheet.ts.
Where is ast.ts in the architecture?
ast.ts is located at packages/@tailwindcss-postcss/src/ast.ts (domain: BuildIntegrations, subdomain: PostCSSPlugin, directory: packages/@tailwindcss-postcss/src).

Analyze Your Own Codebase

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

Try Supermodel Free