MCPcopy
hub / github.com/vitejs/vite / patchTypes

Function patchTypes

packages/vite/rolldown.dts.config.ts:133–161  ·  view source on GitHub ↗

* Patch the types files before passing to dts plugin * 1. Validate unallowed dependency imports * 2. Replace confusing type names * 3. Strip leftover internal types * 4. Clean unnecessary comments

()

Source from the content-addressed store, hash-verified

131 * 4. Clean unnecessary comments
132 */
133function patchTypes(): Plugin {
134 return {
135 name: 'patch-types',
136 generateBundle: {
137 order: 'post',
138 handler(_opts, bundle) {
139 for (const chunk of Object.values(bundle)) {
140 if (chunk.type !== 'chunk') continue
141
142 const ast = parseAst(chunk.code, { lang: 'ts', sourceType: 'module' })
143 const importBindings = getAllImportBindings(ast)
144 if (
145 chunk.fileName.startsWith('module-runner') ||
146 // index and moduleRunner have a common chunk
147 chunk.fileName.startsWith('chunks/') ||
148 chunk.fileName.startsWith('types.d-')
149 ) {
150 validateRunnerChunk.call(this, chunk, importBindings)
151 } else {
152 validateChunkImports.call(this, chunk, importBindings)
153 replaceConfusingTypeNames.call(this, chunk, importBindings)
154 stripInternalTypes.call(this, chunk)
155 cleanUnnecessaryComments(chunk)
156 }
157 }
158 },
159 },
160 }
161}
162
163function stringifyModuleExportName(node: ModuleExportName): string {
164 if (node.type === 'Identifier') {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected