* 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)
| 352 | * pass here. |
| 353 | */ |
| 354 | function 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` |