Repository navigation
fix: add export {} when inline exports leave no export statement - #310
harshit-d3v wants to merge 1 commit into
Conversation
A .d.ts file without an `export { ... }`, `export *` or `export =`
statement exports every top-level declaration. Since declarations are
exported inline, a chunk can end up without one, and the declarations it
never exported become public. Add `export {}` in that case, as tsc does.
Fixes rolldown/tsdown#1087
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Top-level TSDeclareFunction declarations may still leak as public exports.
Review effort: Lite
Findings: None
What changed in this PR
This PR prevents private declarations from leaking from bundled .d.ts files by adding export {} when inline exports leave no export scope.
Changes:
- Adds export-scope detection and marker generation.
- Adds regression coverage for private declarations.
- Updates affected declaration snapshots.
Review note: top-level TSDeclareFunction declarations still require handling in the export-scope guard.
| File | Summary |
|---|---|
tests/rollup-plugin-dts/variadic-tuple-types/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/using-namespace-import/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/using-namespace-import-multiple/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-typeof/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-this/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-template-literals/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-nodes/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-mapped/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-literal/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-index/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-function/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-constructor/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/type-conditional/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/ts48/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/ts47/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/ts43-staticindex/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/ts43-override/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/ts43-getset/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/ts42-tuple-rest/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/ts42-abstract/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/shadowing/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/remove-private/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/remapped-mapped-types/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/overrides/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/namespace-references/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/keep-referenced-interface/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/keep-extended-interface/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/issue-254/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/issue-236/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/issue-220/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/issue-160-global-namespace/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/issue-106-inline-import-generic/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/inline-import/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/inline-import-namespace/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/inline-import-generic/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/import-renamed/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/import-referenced-interface/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/import-default-interface/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/implements-expression/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/has-class/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/getters-setters/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/generics/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/export-simple-alias/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/export-default-abstract/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/constructor-shorthands/snapshot.d.ts |
Updated declaration snapshot. |
tests/rollup-plugin-dts/computed-property/snapshot.d.ts |
Updated declaration snapshot. |
tests/index.test.ts |
Adds regression test coverage. |
tests/fixtures/export-decl-private.ts |
Adds the private-declaration fixture. |
tests/__snapshots__/index.test.ts.snap |
Updates integration snapshots. |
src/fake-js/index.ts |
Adds conditional export {} insertion; TSDeclareFunction handling remains incomplete. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
checked the |
…mments Applies two fixes to the built dist/index.mjs of 0.28.6: - sxzz/rolldown-plugin-dts#310 (open, for rolldown/tsdown#1087): add `export {}` when a chunk has a declaration it doesn't export and no `export { ... }`, `export *` or `export =`. Without it TypeScript treats every top-level declaration as exported, which is how @warp-drive/ember's unexported `Tag` type got an API page. - Keep an entry's file-level doc comment when its first statement is an import or `export ... from`. The comment was attached to that statement, which the plugin keeps without comments, so the `@module` comment of @warp-drive/ember's entries was dropped. It's restored only for the chunk's facade module, not for the modules the chunk inlines. There is no upstream PR for this one yet. Drop the patch once a release includes both.
… replace The ember-rolldown and rolldown-plugin-dts patches now do what these did: - the templateTagDeclarationMaps plugin, and its @jridgewell/remapping dependency and catalog entry: ember-rolldown traces .gts declaration maps through content-tag's map itself (NullVoxPopuli/ember.nvp#140). - the ember `footer` that appended `export {}`, and the `footer` pass-through: rolldown-plugin-dts adds it where it's needed (sxzz/rolldown-plugin-dts#310). - the ember `banner` that copied each entry's `@module` comment back, and the `banner` pass-through, which had no other user: rolldown-plugin-dts keeps that comment itself. The ember dist .d.ts and .d.ts.map files are unchanged by this, apart from index.d.ts and experiments.d.ts losing the `export {}` they never needed: both already end with an `export { ... }` list.
…ed types (#11353) * docs(ember): keep each entry's @module comment in the built declarations The d.ts bundler keeps only comments attached to declarations, so it dropped the file-level @module comment from install.ts and experiments.ts, and every tag but @mergeModuleWith from index.ts. TypeDoc reads these dist files, so the install and experiments API pages rendered with no summary or text. Copy each entry's own @module comment, found with the TypeScript parser, onto its declaration chunk. * docs(ember): link ember API pages to their .gts sources @warp-drive/ember's TypeDoc entry points are its built dist/*.d.ts, so every "Defined in" link pointed at dist, which is not committed. The declaration maps could not fix that on their own: for a .gts module they named a src/-private/*.ts file that does not exist, at the line content-tag's output put it on. The shared tsdown config now chains each .d.ts.map through the sourcemap of a template-tag module as loaded, so the maps name the .gts file and line. The source-links TypeDoc plugin now follows the declaration map of any .d.ts, not only an installed copy's, and links the source it names. * docs(ember): stop the install declarations from exporting Tag TypeScript treats every top-level declaration in a .d.ts module as exported unless the file has an export declaration, and an export modifier does not count. The d.ts bundler wrote install.d.ts with modifiers only, so the unexported type Tag became an export and got its own API page. End each ember declaration chunk with an empty export {}, which keeps exactly the exports the source has. * docs(ember): say the experiments entry point holds only pagination today Point readers at @warp-drive/experiments for the other experiments, such as storage resources. * docs(ember): explain what importing @warp-drive/ember/install does The install module's comment had only an @summary, which never renders, so its API page showed no text. It now says the import calls setupSignals(buildSignalConfig), where to add it and that addons add it only in tests, linking the Ember installation guide. * chore(deps): patch @nullvoxpopuli/ember-rolldown with its unreleased .gts map fixes Applies two upstream changes to the built dist/index.js of 2.9.0: - NullVoxPopuli/ember.nvp#140 (merged, not released): traces each .d.ts.map through content-tag's map in generateBundle, so the maps name the .gts file at its own lines. - NullVoxPopuli/ember.nvp#143 (open): the .gts specifier rewrite maps exact columns through magic-string, and a .gts with no <template> loads with an identity map that names the .gts file. Both import packages 2.9.0 doesn't depend on, so a packageExtensions entry adds @jridgewell/remapping and magic-string, at the ranges upstream uses. Drop the patch and the extension once a release includes both PRs. * chore(deps): patch rolldown-plugin-dts for export {} and entry doc comments Applies two fixes to the built dist/index.mjs of 0.28.6: - sxzz/rolldown-plugin-dts#310 (open, for rolldown/tsdown#1087): add `export {}` when a chunk has a declaration it doesn't export and no `export { ... }`, `export *` or `export =`. Without it TypeScript treats every top-level declaration as exported, which is how @warp-drive/ember's unexported `Tag` type got an API page. - Keep an entry's file-level doc comment when its first statement is an import or `export ... from`. The comment was attached to that statement, which the plugin keeps without comments, so the `@module` comment of @warp-drive/ember's entries was dropped. It's restored only for the chunk's facade module, not for the modules the chunk inlines. There is no upstream PR for this one yet. Drop the patch once a release includes both. * chore(build): drop the ember .d.ts workarounds the dependency patches replace The ember-rolldown and rolldown-plugin-dts patches now do what these did: - the templateTagDeclarationMaps plugin, and its @jridgewell/remapping dependency and catalog entry: ember-rolldown traces .gts declaration maps through content-tag's map itself (NullVoxPopuli/ember.nvp#140). - the ember `footer` that appended `export {}`, and the `footer` pass-through: rolldown-plugin-dts adds it where it's needed (sxzz/rolldown-plugin-dts#310). - the ember `banner` that copied each entry's `@module` comment back, and the `banner` pass-through, which had no other user: rolldown-plugin-dts keeps that comment itself. The ember dist .d.ts and .d.ts.map files are unchanged by this, apart from index.d.ts and experiments.d.ts losing the `export {}` they never needed: both already end with an `export { ... }` list. * chore: link the upstream PR for the rolldown-plugin-dts @module fix * chore(deps): bump @nullvoxpopuli/ember-rolldown to 2.10.0 and drop its patch 2.10.0 ships NullVoxPopuli/ember.nvp#140 and #143, so the patch and the packageExtensions entry that added their dependencies are no longer needed. 2.10.0 is younger than minimumReleaseAge, so it is excluded by exact version.
|
This also breaks consumers of |
|
thanks for confirming. @sxzz this is showing up downstream now in TanStack/table#6619, could you take a look when you get a chance? |
Refs #310, #312 Co-authored-by: Harshit <[email protected]>
|
Thanks for the fix! Incorporated it in 004032f, with the scope checks combined into a single pass and a snapshot regression test. Your contribution is credited in the commit’s co-author trailer. |
|
thanks for landing it! |
Fixes rolldown/tsdown#1087
since 0.28.2 declarations are exported inline, so a chunk can end up with no
export { ... }statement. a .d.ts withoutexport { ... },export *orexport =exports every top-level declaration, so types that were never exported become public:import type { Internal } from 'pkg'compiles against that. this addsexport {};when a chunk has a declaration that isn't exported and nothing that limits the exports, same as tsc. imports and ambient modules don't count.export {};, each one had a private declaration leaking (e.g.declare class Bin remove-private)[Internal, Foo]to[Foo]export {};now