docs: expand JSDoc coverage across plugin source#236
Conversation
Add comprehensive JSDoc to the public API (`Options`, `GeneralOptions`,
`TscOptions`, `TsgoOptions`, `OptionsResolved`, `dts`) and to the
plugin-internal helpers in `src/fake-js.ts`, `src/generate.ts`,
`src/dts-input.ts`, `src/resolver.ts`, `src/tsgo.ts`, `src/filename.ts`,
`src/debug.ts`, and the `src/tsc/` directory. Comments use `{@linkcode}`
cross-references and `@example` blocks where useful.
Alongside the documentation pass:
- Fix typo: `RuntimeBindingVariableDeclration` →
`RuntimeBindingVariableDeclaration` (snapshots updated).
- Rename `comment` → `comments` in `collectReferenceDirectives` to match
the array shape.
- Drop redundant `as t.ExportSpecifier` cast — the surrounding type guard
already narrows.
- Remove no-op `Omit<TscOptions, 'programs'>` in `generate.ts`;
`programs` is not a key of `TscOptions`.
- DRY internal `TscOptions` to extend `Pick<Options, …>` instead of
redeclaring shared fields.
- Refactor `createDtsInputPlugin`, `createFakeJsPlugin`,
`createGeneratePlugin`, `createDtsResolvePlugin`, `resolveOptions`,
`createTsProgram`, and `createTsProgramFromParsedConfig` to take a
single named options parameter so JSDoc has a clean `@param` target.
- Correct `Options.tsconfig` default: was documented as
`'tsconfig.json'`, but `resolveOptions` treats `true` and `undefined`
identically (upward search via `get-tsconfig`). Now documented as
`@default true` with each branch (`true` / `string` / `false`)
explained, matching `tsdown` and `rolldown` conventions.
No runtime behavior changes.
commit: |
|
Looks like it's generated by AI. |
some of it yeah, the majority of the JSDocs especially the added links and fixed defaults and the added examples were my doing, I am slowly working towards finishing rolldown/tsdown#679, and this PR contributes to that as well. |
|
Thanks for the PR. I'm leaning towards not accepting this as-is. Adding comments to almost every piece of code does not provide much value in my opinion, and mostly adds noise to the codebase. That said, I do agree that some public APIs could use more detailed documentation. I’d be happy to keep or review changes that focus specifically on improving docs for public-facing APIs. |
no problem, I'll adjust the PR accordingly. |
Description
Adds comprehensive JSDoc across the plugin's public API and internal helpers, and folds in a small set of trivial cleanups noticed along the way. No runtime behavior changes.
What changed
Documentation (the bulk)
JSDoc blocks added to:
Options,GeneralOptions,TscOptions,TsgoOptions,OptionsResolved,resolveOptions,dts(src/options.ts,src/index.ts).src/fake-js.ts,src/generate.ts,src/dts-input.ts,src/resolver.ts,src/tsgo.ts,src/filename.ts,src/debug.ts.src/tsc/directory (context.ts,emit-build.ts,emit-compiler.ts,index.ts,resolver.ts,system.ts,types.ts,utils.ts,volar.ts,worker.ts).Comments document parameter contracts, return shapes, defaults, and invariants, using
{@linkcode}cross-references and@exampleblocks (notably forentry,tsgo,cjsDefault, andinvalidateContextFile).Correctness / cleanup fixes
RuntimeBindingVariableDeclration→RuntimeBindingVariableDeclaration(src/fake-js.ts; snapshots updated under__snapshots__/tsnapi/).comment→commentsincollectReferenceDirectives(src/fake-js.ts).node.specifiers[0] as t.ExportSpecifier(src/fake-js.ts); the surrounding type guard already narrows.Omit:Omit<TscOptions, 'programs'>→TscOptions(src/generate.ts);programswas never a key.TscOptionsinsrc/tsc/types.tsnow extendsRequired<Pick<Options, …>>&Pick<Options, …>instead of redeclaringtsconfig,tsconfigRaw,cwd,build,incremental,sourcemap,vue,tsMacro.tsconfigdefault:Options.tsconfigwas documented as@default 'tsconfig.json', butresolveOptionstreatstrueand omitted identically (upward search viaget-tsconfig, not a literalpath.resolve(cwd, 'tsconfig.json')). Now documented as@default truewith the three input branches (true/string/false) each explained, matchingtsdownandrolldown.Stylistic refactor (intentional, doc-driven)
Seven functions switched from inline-destructured params to a single named param destructured in the body, so JSDoc has a clean
@paramtarget:createDtsInputPlugin(src/dts-input.ts)createFakeJsPlugin(src/fake-js.ts)createGeneratePlugin(src/generate.ts)createDtsResolvePlugin(src/resolver.ts)resolveOptions(src/options.ts) - usesletbecause several destructured bindings are reassigned during normalization.createTsProgram,createTsProgramFromParsedConfig(src/tsc/emit-compiler.ts).Why
The plugin's public surface had thin documentation. Hovering an option in an editor, or generating an API reference, surfaced little beyond the type. This PR fixes that without touching runtime behavior, and sweeps up a handful of pre-existing nits encountered along the way.
Verification
pnpm run build- typecheck + bundle pass.pnpm test- snapshot suite passes; updated snapshots reflect the identifier typo fix only.dts,Options,GeneralOptions,TscOptions,TsgoOptions.Out of scope (future work)
TscOptionsexist (public insrc/options.tsand internal insrc/tsc/types.ts). They are intentionally distinct but share a name, which is confusing - worth renaming the internal one in a follow-up.Linked Issues
Additional context