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

Function stripInternalTypes

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

* While we already enable `compilerOptions.stripInternal`, some internal comments * like internal parameters are still not stripped by TypeScript, so we run another * pass here.

(this: PluginContext, chunk: OutputChunk)

Source from the content-addressed store, hash-verified

352 * pass here.
353 */
354function stripInternalTypes(this: PluginContext, chunk: OutputChunk) {
355 if (chunk.code.includes('@internal')) {
356 const s = new MagicString(chunk.code)
357 // need to parse with babel to get the comments
358 const ast = parseWithBabel(chunk.code, {
359 plugins: ['typescript'],
360 sourceType: 'module',
361 })
362
363 walk(ast as any, {
364 enter(node: any) {
365 if (removeInternal(s, node)) {
366 this.skip()
367 }
368 },
369 })
370
371 chunk.code = s.toString()
372
373 if (chunk.code.includes('@internal')) {
374 this.warn(`${chunk.fileName} has unhandled @internal declarations`)
375 process.exitCode = 1
376 }
377 }
378}
379
380/**
381 * Remove `@internal` comments not handled by `compilerOptions.stripInternal`

Callers

nothing calls this directly

Calls 2

walkFunction · 0.85
warnMethod · 0.65

Tested by

no test coverage detected