mapSourcePosition() — vite Function Reference
Architecture documentation for the mapSourcePosition() function in interceptor.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD f5792b49_242f_3f04_074c_c9ee1ff25728["mapSourcePosition()"] 95cae2f2_ad8c_91c1_5a74_93d939dbc47b["interceptor.ts"] f5792b49_242f_3f04_074c_c9ee1ff25728 -->|defined in| 95cae2f2_ad8c_91c1_5a74_93d939dbc47b f40eaafa_db1a_03b4_c837_94e817990f37["mapEvalOrigin()"] f40eaafa_db1a_03b4_c837_94e817990f37 -->|calls| f5792b49_242f_3f04_074c_c9ee1ff25728 b30dd025_db49_148b_f0bc_60f33ba97a2d["wrapCallSite()"] b30dd025_db49_148b_f0bc_60f33ba97a2d -->|calls| f5792b49_242f_3f04_074c_c9ee1ff25728 94a96327_7ba3_9fa8_c1c1_02a5f405e143["getRunnerSourceMap()"] f5792b49_242f_3f04_074c_c9ee1ff25728 -->|calls| 94a96327_7ba3_9fa8_c1c1_02a5f405e143 06f9b71d_962e_e798_0173_2861abfd51c7["retrieveSourceMap()"] f5792b49_242f_3f04_074c_c9ee1ff25728 -->|calls| 06f9b71d_962e_e798_0173_2861abfd51c7 63f2556d_48de_27dc_3e1e_e91767d1afcf["supportRelativeURL()"] f5792b49_242f_3f04_074c_c9ee1ff25728 -->|calls| 63f2556d_48de_27dc_3e1e_e91767d1afcf ce370f58_aa9b_2bcc_e6ca_6347a7feef3a["getOriginalPosition()"] f5792b49_242f_3f04_074c_c9ee1ff25728 -->|calls| ce370f58_aa9b_2bcc_e6ca_6347a7feef3a style f5792b49_242f_3f04_074c_c9ee1ff25728 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/module-runner/sourcemap/interceptor.ts lines 173–235
function mapSourcePosition(position: OriginalMapping) {
if (!position.source) return position
let sourceMap = getRunnerSourceMap(position)
if (!sourceMap) sourceMap = sourceMapCache[position.source]
if (!sourceMap) {
// Call the (overridable) retrieveSourceMap function to get the source map.
const urlAndMap = retrieveSourceMap(position.source)
if (urlAndMap && urlAndMap.map) {
const url = urlAndMap.url
sourceMap = sourceMapCache[position.source] = {
url,
map: new DecodedMap(
typeof urlAndMap.map === 'string'
? JSON.parse(urlAndMap.map)
: urlAndMap.map,
url,
),
}
const contents = sourceMap.map?.map.sourcesContent
// Load all sources stored inline with the source map into the file cache
// to pretend like they are already loaded. They may not exist on disk.
if (sourceMap.map && contents) {
sourceMap.map.resolvedSources.forEach((source, i) => {
const content = contents[i]
if (content && source && url) {
const contentUrl = supportRelativeURL(url, source)
fileContentsCache[contentUrl] = content
}
})
}
} else {
sourceMap = sourceMapCache[position.source] = {
url: null,
map: null,
}
}
}
// Resolve the source URL relative to the URL of the source map
if (sourceMap.map && sourceMap.url) {
const originalPosition = getOriginalPosition(sourceMap.map, position)
// Only return the original position if a matching line was found. If no
// matching line is found then we return position instead, which will cause
// the stack trace to print the path and line for the compiled file. It is
// better to give a precise location in the compiled file than a vague
// location in the original file.
if (originalPosition && originalPosition.source != null) {
originalPosition.source = supportRelativeURL(
sourceMap.url,
originalPosition.source,
)
if (sourceMap.vite) {
// @ts-expect-error vite is not defined
originalPosition._vite = true
}
return originalPosition
}
}
return position
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does mapSourcePosition() do?
mapSourcePosition() is a function in the vite codebase, defined in packages/vite/src/module-runner/sourcemap/interceptor.ts.
Where is mapSourcePosition() defined?
mapSourcePosition() is defined in packages/vite/src/module-runner/sourcemap/interceptor.ts at line 173.
What does mapSourcePosition() call?
mapSourcePosition() calls 4 function(s): getOriginalPosition, getRunnerSourceMap, retrieveSourceMap, supportRelativeURL.
What calls mapSourcePosition()?
mapSourcePosition() is called by 2 function(s): mapEvalOrigin, wrapCallSite.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free