createSourceMap() — tailwindcss Function Reference
Architecture documentation for the createSourceMap() function in source-map.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD ce95eae1_6998_4776_5146_d52bb0aefb63["createSourceMap()"] 94f6a4ae_3b1f_8e71_a096_1f7d17efc49a["source-map.ts"] ce95eae1_6998_4776_5146_d52bb0aefb63 -->|defined in| 94f6a4ae_3b1f_8e71_a096_1f7d17efc49a 9c33d37f_aea4_85fa_1eb9_f13429950630["compile()"] 9c33d37f_aea4_85fa_1eb9_f13429950630 -->|calls| ce95eae1_6998_4776_5146_d52bb0aefb63 0204f9b9_80aa_c3e8_eb61_22170d608d65["createLineTable()"] ce95eae1_6998_4776_5146_d52bb0aefb63 -->|calls| 0204f9b9_80aa_c3e8_eb61_22170d608d65 ed78da58_8727_ad98_120c_61f35cea357a["walk()"] ce95eae1_6998_4776_5146_d52bb0aefb63 -->|calls| ed78da58_8727_ad98_120c_61f35cea357a 5bcf4886_1230_a8ff_7302_a26cc5a9a525["get()"] ce95eae1_6998_4776_5146_d52bb0aefb63 -->|calls| 5bcf4886_1230_a8ff_7302_a26cc5a9a525 style ce95eae1_6998_4776_5146_d52bb0aefb63 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/source-maps/source-map.ts lines 76–163
export function createSourceMap({ ast }: { ast: AstNode[] }) {
// Compute line tables for both the original and generated source lazily so we
// don't have to do it during parsing or printing.
let lineTables = new DefaultMap<Source, LineTable>((src) => createLineTable(src.code))
let sourceTable = new DefaultMap<Source, DecodedSource>((src) => ({
url: src.file,
content: src.code,
ignore: false,
}))
// Convert each mapping to a set of positions
let map: DecodedSourceMap = {
file: null,
sources: [],
mappings: [],
}
// Get all the indexes from the mappings
walk(ast, (node) => {
if (!node.src || !node.dst) return
let originalSource = sourceTable.get(node.src[0])
if (!originalSource.content) return
let originalTable = lineTables.get(node.src[0])
let generatedTable = lineTables.get(node.dst[0])
let originalSlice = originalSource.content.slice(node.src[1], node.src[2])
// Source maps only encode single locations — not multi-line ranges
// So to properly emulate this we'll scan the original text for multiple
// lines and create mappings for each of those lines that point to the
// destination node (whether it spans multiple lines or not)
//
// This is not 100% accurate if both the source and destination preserve
// their newlines but this only happens in the case of custom properties
//
// This is _good enough_
let offset = 0
for (let line of originalSlice.split('\n')) {
if (line.trim() !== '') {
let originalStart = originalTable.find(node.src[1] + offset)
let generatedStart = generatedTable.find(node.dst[1])
map.mappings.push({
name: null,
originalPosition: {
source: originalSource,
...originalStart,
},
generatedPosition: generatedStart,
})
}
offset += line.length
offset += 1
}
let originalEnd = originalTable.find(node.src[2])
let generatedEnd = generatedTable.find(node.dst[2])
map.mappings.push({
name: null,
originalPosition: {
source: originalSource,
...originalEnd,
},
generatedPosition: generatedEnd,
})
})
// Populate
for (let source of lineTables.keys()) {
map.sources.push(sourceTable.get(source))
}
// Sort the mappings in ascending order
map.mappings.sort((a, b) => {
return (
a.generatedPosition.line - b.generatedPosition.line ||
a.generatedPosition.column - b.generatedPosition.column ||
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does createSourceMap() do?
createSourceMap() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/source-maps/source-map.ts.
Where is createSourceMap() defined?
createSourceMap() is defined in packages/tailwindcss/src/source-maps/source-map.ts at line 76.
What does createSourceMap() call?
createSourceMap() calls 3 function(s): createLineTable, get, walk.
What calls createSourceMap()?
createSourceMap() is called by 1 function(s): compile.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free