Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Add missing diagnostic context setting logic for newer js declaration emit features - #4306

Merged
Wesley Wigham (weswigham) merged 1 commit into
microsoft:mainfrom
weswigham:add-missing-diagnostic-sets
Jun 13, 2026
Merged

Wesley Wigham (weswigham) merged 1 commit into
microsoft:mainfrom
weswigham:add-missing-diagnostic-sets

Conversation

@weswigham

Copy link
Copy Markdown
Member

Preferred alternative to #3379

@weswigham Wesley Wigham (weswigham) changed the title Add missing diagnostic context setting logic for newwer js declaration emit features Add missing diagnostic context setting logic for newer js declaration emit features Jun 13, 2026

==== /index.cjs (1 errors) ====
Object.defineProperty(exports, "api", { value: require("pkg") });
~~~~~

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll note the error actually has a sensible span, rather than being, y'know, the whole file.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves JS declaration-emit symbol accessibility diagnostics for newer CommonJS export patterns (notably Object.defineProperty(exports, ...)) by ensuring the correct diagnostic context is set at the right time, and adds a regression test/baselines to lock in the expected error span and message.

Changes:

  • Add a new compiler test case covering Object.defineProperty(exports, "api", { value: require("pkg") }) with an inaccessible type leak.
  • Refactor diagnostic-context setup/cleanup in the declaration transformer into a helper and apply it to additional JS emit paths.
  • Introduce call-expression diagnostic-context support for the Object.defineProperty export pattern.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
testdata/tests/cases/compiler/cjsObjectDefinePropertyPrivateModuleDeclarationEmit.ts New regression test for CJS Object.defineProperty(exports, ...) declaration-emit diagnostics.
testdata/baselines/reference/compiler/cjsObjectDefinePropertyPrivateModuleDeclarationEmit.types New types baseline for the added test.
testdata/baselines/reference/compiler/cjsObjectDefinePropertyPrivateModuleDeclarationEmit.symbols New symbols baseline for the added test.
testdata/baselines/reference/compiler/cjsObjectDefinePropertyPrivateModuleDeclarationEmit.errors.txt New errors baseline asserting correct diagnostic message and span.
internal/transformers/declarations/util.go Expands diagnostic-context eligibility to cover the new JS export shape (needs narrowing to bindable defineProperty calls).
internal/transformers/declarations/transform.go Refactors diagnostic-context handling into setupDiagnosticContext and applies it in more JS decl-emit paths.
internal/transformers/declarations/diagnostics.go Adds CallExpression diagnostic context (needs gating to avoid panics/incorrect diagnostics on non-defineProperty calls).

@weswigham
Wesley Wigham (weswigham) added this pull request to the merge queue Jun 13, 2026
Merged via the queue into microsoft:main with commit c78d39e Jun 13, 2026
21 checks passed
@weswigham
Wesley Wigham (weswigham) deleted the add-missing-diagnostic-sets branch June 13, 2026 02:29
Jake Bailey (jakebailey) pushed a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants