interopNamedImports() — vite Function Reference
Architecture documentation for the interopNamedImports() function in importAnalysis.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 56b889e3_7358_a651_5888_fcaa50d129e3["interopNamedImports()"] 5a7b98e4_4eb1_dfca_508b_2d43e2a077e6["importAnalysis.ts"] 56b889e3_7358_a651_5888_fcaa50d129e3 -->|defined in| 5a7b98e4_4eb1_dfca_508b_2d43e2a077e6 a1fc1de5_905b_efe7_d960_3597604fbdfe["importAnalysisPlugin()"] a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| 56b889e3_7358_a651_5888_fcaa50d129e3 3a38e2b3_ce45_c2a5_72d3_4509df0e86d9["getLineBreaks()"] 56b889e3_7358_a651_5888_fcaa50d129e3 -->|calls| 3a38e2b3_ce45_c2a5_72d3_4509df0e86d9 df4b153e_b429_d51a_4d38_896cbcb5f010["transformCjsImport()"] 56b889e3_7358_a651_5888_fcaa50d129e3 -->|calls| df4b153e_b429_d51a_4d38_896cbcb5f010 style 56b889e3_7358_a651_5888_fcaa50d129e3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/importAnalysis.ts lines 927–982
export function interopNamedImports(
str: MagicString,
importSpecifier: ImportSpecifier,
rewrittenUrl: string,
importIndex: number,
importer: string,
isNodeMode: boolean,
config: ResolvedConfig,
): void {
const source = str.original
const {
s: start,
e: end,
ss: expStart,
se: expEnd,
d: dynamicIndex,
} = importSpecifier
const exp = source.slice(expStart, expEnd)
if (dynamicIndex > -1) {
const inconsistentCjsInterop = !!config.legacy?.inconsistentCjsInterop
// rewrite `import('package')` to expose the default directly
str.overwrite(
expStart,
expEnd,
`import('${rewrittenUrl}').then(m => (${interopHelperStr})(m.default, ${inconsistentCjsInterop ? 0 : 1}))` +
getLineBreaks(exp),
{ contentOnly: true },
)
} else {
const rawUrl = source.slice(start, end)
const rewritten = transformCjsImport(
exp,
rewrittenUrl,
rawUrl,
importIndex,
importer,
isNodeMode,
config,
)
if (rewritten) {
str.overwrite(expStart, expEnd, rewritten + getLineBreaks(exp), {
contentOnly: true,
})
} else {
// #1439 export * from '...'
str.overwrite(
start,
end,
rewrittenUrl + getLineBreaks(source.slice(start, end)),
{
contentOnly: true,
},
)
}
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does interopNamedImports() do?
interopNamedImports() is a function in the vite codebase, defined in packages/vite/src/node/plugins/importAnalysis.ts.
Where is interopNamedImports() defined?
interopNamedImports() is defined in packages/vite/src/node/plugins/importAnalysis.ts at line 927.
What does interopNamedImports() call?
interopNamedImports() calls 2 function(s): getLineBreaks, transformCjsImport.
What calls interopNamedImports()?
interopNamedImports() is called by 1 function(s): importAnalysisPlugin.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free