Skip to content

Fix declaration maps for export assignment expressions - #64460

Open
Mariana Castro (maricastroc) wants to merge 2 commits into
microsoft:mainfrom
maricastroc:fix/declaration-map-export-assignment
Open

Mariana Castro (maricastroc) wants to merge 2 commits into
microsoft:mainfrom
maricastroc:fix/declaration-map-export-assignment

Conversation

@maricastroc

Copy link
Copy Markdown

Fixes #64433

Analysis

For export default <expr> / export = <expr> with a non-identifier expression, declaration emit produces a synthesized declare const _default: ...; followed by export default _default; (or export = _default;). transformExportAssignment builds that export assignment with NewExportAssignment, so the synthesized export assignments were missing source-map ranges and the printer emitted no mapping for them. Before the logic moved into the shared transformExportAssignment in microsoft/typescript-go#3388, it used UpdateExportAssignment(input, ...), which kept the range.

const b = 1;
const d = 2;
export default { b, d };

TypeScript 6.0 emits "mappings":";;;;AAEA,wBAAwB" for this file; before this change the .d.ts.map had "mappings":"". The identifier form (export = m2; in declarationMaps) also lost its statement-level start/end mappings.

Fix

Assign the original statement's source-map range to each synthesized export assignment in transformExportAssignment via EmitContext().AssignSourceMapRange(exportAssignment, input). Only the source-map range is copied, not Loc or the original node, so declaration output is unchanged. Copying Loc was considered, but it reattaches source comments to the synthesized node (e.g. export default /** @type {P} */ _default; in declarationEmitCastReusesTypeNode4).

  • Added declarationMapsExportAssignmentExpression.ts, covering a non-identifier export default and the shared export = path; the mappings now match TypeScript 6.0.
  • Updated the declarationMaps source map baselines; declarationMaps.sourcemap.txt now matches the TypeScript 6.0 baseline.
  • No .d.ts output changed; only .js.map and .sourcemap.txt baselines differ.

Copilot Checklist

I successfully ran the applicable command at the end of my session, and it completed without error:

  • npx hereby validate
  • npx hereby validate --api (for TypeScript API changes)

npx hereby validate did not complete cleanly. Compiler tests, lint, formatting, codegen, and extension tests passed, but each of two runs hit an unrelated flaky macOS fswatch/FSEvents test, on different subtests (TestFSEventsWatchFileDifferentCasing, TestFSEventsExpansionAliases/sharp-s). Those tests passed when internal/fswatch was run on its own. npx hereby check:format passed. --api is not applicable.

AI disclosure (per CONTRIBUTING.md): this patch was written with Claude Code and reviewed by me before submission.

Copilot AI balanced review requested due to automatic review settings September 26, 2026 01:57
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 26, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Sep 26, 2026

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.

Copilot review overview

🟡 Changes recommended

The modified class-expression and function-like branches lack declaration-map regression coverage.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Fixes declaration-map mappings for synthesized export assignments by preserving source-map ranges.

Changes:

  • Assigns source-map ranges across export-assignment transformation branches.
  • Adds regression coverage and updates declaration-map baselines.
File Description
tsc/​internal/​transformers/​declarations/​transform.go Preserves export-assignment source ranges.
tsc/​testdata/​tests/​cases/​compiler/​declarationMapsExportAssignmentExpression.ts Adds expression export tests.
tsc/​testdata/​baselines/​reference/​compiler/​declarationMapsExportAssignmentExpression.types Adds type baseline.
tsc/​testdata/​baselines/​reference/​compiler/​declarationMapsExportAssignmentExpression.symbols Adds symbol baseline.
tsc/​testdata/​baselines/​reference/​compiler/​declarationMapsExportAssignmentExpression.sourcemap.txt Adds readable map baseline.
tsc/​testdata/​baselines/​reference/​compiler/​declarationMapsExportAssignmentExpression.js.map Adds declaration-map output.
tsc/​testdata/​baselines/​reference/​compiler/​declarationMapsExportAssignmentExpression.js Adds emit baseline.
tsc/​testdata/​baselines/​reference/​compiler/​declarationMaps.sourcemap.txt Updates identifier mapping baseline.
tsc/​testdata/​baselines/​reference/​compiler/​declarationMaps.js.map Updates serialized declaration map.
Files not reviewed (1)
  • tsc/testdata/baselines/reference/compiler/declarationMapsExportAssignmentExpression.js: Generated file

Comment thread tsc/internal/transformers/declarations/transform.go
Cover the class-expression and function-like branches of
transformExportAssignment with `export = class {}` and an
`export default` arrow function, so their synthesized export
assignment mappings are baselined.
@maricastroc

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

empty mappings in .d.ts.map for export default of a non-identifier expression

3 participants