Repository navigation
Preserve nested CommonJS bindings in declaration emit - #65720
Open
Ankit Das (ecryptoguru) wants to merge 1 commit into
Open
Ankit Das (ecryptoguru) wants to merge 1 commit into
Ankit Das (ecryptoguru) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change preserving nested CommonJS bindings in declaration output.
No open issues 🎉
What changed in this PR
Fixes #65628 by preserving nested CommonJS require() bindings in TypeScript declaration output, preventing exports from referencing undeclared names.
Changes:
- Reuses the importability check to route non-importable bindings through typed declaration emission while retaining direct imports.
- Adds regression coverage and baselines for nested objects, nested arrays, mixed direct bindings, and nested-only declarations.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/declarationEmitCommonjsRequireNestedBinding.ts |
Adds nested-binding regression cases. |
tsc/testdata/baselines/reference/compiler/declarationEmitCommonjsRequireNestedBinding.types |
Records inferred binding types. |
tsc/testdata/baselines/reference/compiler/declarationEmitCommonjsRequireNestedBinding.symbols |
Records binding and export symbols. |
tsc/testdata/baselines/reference/compiler/declarationEmitCommonjsRequireNestedBinding.js |
Records preserved imports and typed declarations. |
tsc/internal/transformers/declarations/transform.go |
Routes non-importable bindings through the existing declaration fallback. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65628.
In CommonJS JavaScript, destructuring
require()into a nested object or array could emit an export with no declaration. Only direct bindings can become named imports. The existing fallback now emits typed declarations for the other bindings and keeps the direct imports.The regression case covers nested objects and arrays alongside a direct binding, plus a declaration with only a nested binding. With a compiler built from
main, a separate consumer of the emitted declarations reported TS2304 for the dropped names. The consumer type checks after this change. Focused declaration baselines,hereby tidy, andhereby check:formatpassed.The full
hereby validate --allrun passed on macOS withTMPDIRset to its resolved path under/private/tmp. This included the compiler, extension, native and WebAssembly API, code generation, smoke, lint, and formatting checks.hereby tidyleft the branch clean.Prepared with Codex assistance.