Fix declaration maps for export assignment expressions - #64460
Mariana Castro (maricastroc) wants to merge 1 commit into
Conversation
|
Mariana Castro (@maricastroc) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
1 similar comment
|
Mariana Castro (@maricastroc) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The modified class-expression and function-like branches lack declaration-map regression coverage.
Review effort: Balanced
Findings: 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
| tx.preserveJsDoc(classDecl, input) | ||
| // Reuse the same name node for the export so unique names resolve consistently | ||
| exportAssignment := tx.Factory().NewExportAssignment(nil, isExportEquals, nil, newId) | ||
| tx.EmitContext().AssignSourceMapRange(exportAssignment, input) |
There was a problem hiding this comment.
@microsoft-github-policy-service agree

Fixes #64433
Analysis
For
export default <expr>/export = <expr>with a non-identifier expression, declaration emit produces a synthesizeddeclare const _default: ...;followed byexport default _default;(orexport = _default;).transformExportAssignmentbuilds that export assignment withNewExportAssignment, so the synthesized export assignments were missing source-map ranges and the printer emitted no mapping for them. Before the logic moved into the sharedtransformExportAssignmentin microsoft/typescript-go#3388, it usedUpdateExportAssignment(input, ...), which kept the range.TypeScript 6.0 emits
"mappings":";;;;AAEA,wBAAwB"for this file; before this change the.d.ts.maphad"mappings":"". The identifier form (export = m2;indeclarationMaps) also lost its statement-level start/end mappings.Fix
Assign the original statement's source-map range to each synthesized export assignment in
transformExportAssignmentviaEmitContext().AssignSourceMapRange(exportAssignment, input). Only the source-map range is copied, notLocor the original node, so declaration output is unchanged. CopyingLocwas considered, but it reattaches source comments to the synthesized node (e.g.export default /** @type {P} */ _default;indeclarationEmitCastReusesTypeNode4).declarationMapsExportAssignmentExpression.ts, covering a non-identifierexport defaultand the sharedexport =path; the mappings now match TypeScript 6.0.declarationMapssource map baselines;declarationMaps.sourcemap.txtnow matches the TypeScript 6.0 baseline..d.tsoutput changed; only.js.mapand.sourcemap.txtbaselines differ.Copilot Checklist
I successfully ran the applicable command at the end of my session, and it completed without error:
npx hereby validatedid not complete cleanly. Compiler tests, lint, formatting, codegen, and extension tests passed, but each of two runs hit an unrelated flaky macOSfswatch/FSEvents test, on different subtests (TestFSEventsWatchFileDifferentCasing,TestFSEventsExpansionAliases/sharp-s). Those tests passed wheninternal/fswatchwas run on its own.npx hereby check:formatpassed.--apiis not applicable.AI disclosure (per CONTRIBUTING.md): this patch was written with Claude Code and reviewed by me before submission.