substituteAtImports() — tailwindcss Function Reference
Architecture documentation for the substituteAtImports() function in at-import.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 65cd5723_5f2b_da42_e83b_2add05ebc004["substituteAtImports()"] 95cb326e_6b59_0903_0c96_d221fca5c2b1["parseCss()"] 95cb326e_6b59_0903_0c96_d221fca5c2b1 -->|calls| 65cd5723_5f2b_da42_e83b_2add05ebc004 a32bba76_f60d_883f_1ff1_276a0bb9db9f["walk()"] 65cd5723_5f2b_da42_e83b_2add05ebc004 -->|calls| a32bba76_f60d_883f_1ff1_276a0bb9db9f ddd2db68_c731_a9de_a974_10945491851d["parseImportParams()"] 65cd5723_5f2b_da42_e83b_2add05ebc004 -->|calls| ddd2db68_c731_a9de_a974_10945491851d a36324cc_cbd0_023c_1dc6_8ce6c9c41dda["context()"] 65cd5723_5f2b_da42_e83b_2add05ebc004 -->|calls| a36324cc_cbd0_023c_1dc6_8ce6c9c41dda 510b91a2_860c_62c6_54c4_43c0ad2f601c["buildImportNodes()"] 65cd5723_5f2b_da42_e83b_2add05ebc004 -->|calls| 510b91a2_860c_62c6_54c4_43c0ad2f601c 253418a1_4f08_cf0e_5b8e_c6392b9959eb["parse()"] 65cd5723_5f2b_da42_e83b_2add05ebc004 -->|calls| 253418a1_4f08_cf0e_5b8e_c6392b9959eb style 65cd5723_5f2b_da42_e83b_2add05ebc004 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/at-import.ts lines 16–81
export async function substituteAtImports(
ast: AstNode[],
base: string,
loadStylesheet: LoadStylesheet,
recurseCount = 0,
track = false,
) {
let features = Features.None
let promises: Promise<void>[] = []
walk(ast, (node) => {
if (node.kind === 'at-rule' && (node.name === '@import' || node.name === '@reference')) {
let parsed = parseImportParams(ValueParser.parse(node.params))
if (parsed === null) return
if (node.name === '@reference') {
parsed.media = 'reference'
}
features |= Features.AtImport
let { uri, layer, media, supports } = parsed
// Skip importing data or remote URIs
if (uri.startsWith('data:')) return
if (uri.startsWith('http://') || uri.startsWith('https://')) return
let contextNode = context({}, [])
promises.push(
(async () => {
// Since we do not have fully resolved paths in core, we can't
// reliably detect circular imports. Instead, we try to limit the
// recursion depth to a number that is too large to be reached in
// practice.
if (recurseCount > 100) {
throw new Error(
`Exceeded maximum recursion depth while resolving \`${uri}\` in \`${base}\`)`,
)
}
let loaded = await loadStylesheet(uri, base)
let ast = CSS.parse(loaded.content, { from: track ? loaded.path : undefined })
await substituteAtImports(ast, loaded.base, loadStylesheet, recurseCount + 1, track)
contextNode.nodes = buildImportNodes(
node,
[context({ base: loaded.base }, ast)],
layer,
media,
supports,
)
})(),
)
// The resolved Stylesheets already have their transitive @imports
// resolved, so we can skip walking them.
return WalkAction.ReplaceSkip(contextNode)
}
})
if (promises.length > 0) {
await Promise.all(promises)
}
return features
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does substituteAtImports() do?
substituteAtImports() is a function in the tailwindcss codebase.
What does substituteAtImports() call?
substituteAtImports() calls 5 function(s): buildImportNodes, context, parse, parseImportParams, walk.
What calls substituteAtImports()?
substituteAtImports() is called by 1 function(s): parseCss.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free