Skip to content

Align declaration emit printer options with strada#3812

Merged
jakebailey merged 4 commits into
mainfrom
copilot/fix-dts-map-inline-sources
May 12, 2026
Merged

Align declaration emit printer options with strada#3812
jakebailey merged 4 commits into
mainfrom
copilot/fix-dts-map-inline-sources

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

.d.ts.map files incorrectly include sourcesContent when inlineSources is enabled, and the declaration printer options bag was generally out of date with strada's emitDeclarationFileOrBundle.

  • Update the full declaration printer options in emitDeclarationFile to match strada's emitDeclarationFileOrBundle (emitter.ts:924-936):
    • NoEmitHelpers hardcoded to true (declarations never need helpers)
    • Added Target from options.GetEmitScriptTarget()
    • SourceMap now gated on e.emitOnly != EmitOnlyForcedDts (matching strada's BuilderSignature guard)
    • InlineSources excluded (per strada)
    • Added OmitBraceSourceMapPositions: true
    • Added NYI comments for Module, ModuleResolution, ExtendedDiagnostics
  • Add compiler test declarationMapInlineSourcesContent covering the inlineSources + declarationMap case

Declaration map files should never include sourcesContent, matching the
behavior of the TypeScript compiler which explicitly does not pass through
the inlineSources option to the declaration printer.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/4d1946b0-e287-4fb5-bece-559959fd446a

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix .d.ts.map includes sourcesContent when inlineSources is enabled Exclude sourcesContent from .d.ts.map when inlineSources is enabled May 12, 2026
Copilot AI requested a review from jakebailey May 12, 2026 16:03
@jakebailey jakebailey marked this pull request as ready for review May 12, 2026 17:55
@jakebailey jakebailey requested review from Copilot and weswigham May 12, 2026 17:55
@jakebailey
Copy link
Copy Markdown
Member

@weswigham Surprised we didn't include maps on d.ts files but it does seem that we didn't before.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Aligns tsgo’s declaration map emission behavior with the TypeScript compiler by ensuring .d.ts.map does not embed sourcesContent when inlineSources is enabled.

Changes:

  • Updates declaration emit printer options to avoid propagating inlineSources into .d.ts.map generation.
  • Adds a new compiler test case covering inlineSources + declarationMap to ensure .d.ts.map omits sourcesContent.
  • Adds/updates corresponding reference baselines for the new test.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
testdata/tests/cases/compiler/declarationMapInlineSourcesContent.ts New compiler test exercising inlineSources with declarationMap.
testdata/baselines/reference/compiler/declarationMapInlineSourcesContent.types Baseline for type output of the new test.
testdata/baselines/reference/compiler/declarationMapInlineSourcesContent.symbols Baseline for symbol output of the new test.
testdata/baselines/reference/compiler/declarationMapInlineSourcesContent.sourcemap.txt Baseline verifying sourcemap details, including absence of sourcesContent for .d.ts.map.
testdata/baselines/reference/compiler/declarationMapInlineSourcesContent.js.map Baseline JSON for .js.map and .d.ts.map outputs.
testdata/baselines/reference/compiler/declarationMapInlineSourcesContent.js Baseline emitted JS + .d.ts output.
internal/compiler/emitter.go Adjusts declaration emit printer options related to inline sourcemap/source content behavior.
Files not reviewed (1)
  • testdata/baselines/reference/compiler/declarationMapInlineSourcesContent.js: Language not supported

Comment thread internal/compiler/emitter.go Outdated
Comment on lines 238 to 243
@@ -239,7 +239,7 @@ func (e *emitter) emitDeclarationFile(sourceFile *ast.SourceFile, declarationFil
NoEmitHelpers: options.NoEmitHelpers.IsTrue(),
SourceMap: options.DeclarationMap.IsTrue(),
InlineSourceMap: options.InlineSourceMap.IsTrue(),
InlineSources: options.InlineSources.IsTrue(),
// Explicitly do not passthru either `inline` option
// !!!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The original code says:

sourceMap: emitOnly !== EmitOnly.BuilderSignature && compilerOptions.declarationMap,
inlineSourceMap: compilerOptions.inlineSourceMap,

So this is correct, but the doc needs updating and maybe the BuilderSignature thing needs to be investigated.

@copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the comment in f2e73f3 to say // Explicitly do not passthru \inlineSources`instead of referencing both inline options, sinceinlineSourceMap` is correctly passed through.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These options look a bit off in general - NoEmitHelpers, for example is... yeah.

Can we update the whole options bag while we're here to

	printerOptions := printer.PrinterOptions{
		RemoveComments: options.RemoveComments.IsTrue(),
		NewLine:        options.NewLine,
		NoEmitHelpers:  true,
		// Module: 			   options.Module, // NYI
		// ModuleResolution:	options.ModuleResolution, // NYI
		Target:          options.GetEmitScriptTarget(),
		SourceMap:       e.emitOnly != EmitOnlyForcedDts && options.DeclarationMap.IsTrue(),
		InlineSourceMap: options.InlineSourceMap.IsTrue(),
		// InlineSources:       options.InlineSources.IsTrue(), // ignored, per strada
		// ExtendedDiagnostics: options.ExtendedDiagnostics.IsTrue(), // NYI
		OnlyPrintJSDocStyle:         true,
		OmitBraceSourceMapPositions: true,
	}

to more faithfully match strada?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Mostly because I imagine this options object first got ported without most of these implemented)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot Make it match and see if it works, see the above for what to copy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the full options bag to match strada in f8583b5. Changes: NoEmitHelpers: true (hardcoded), added Target, SourceMap now guarded with e.emitOnly != EmitOnlyForcedDts, added OmitBraceSourceMapPositions: true, and NYI comments for Module, ModuleResolution, ExtendedDiagnostics. The declarationMaps submodule test baseline diff got smaller as a result.

Copilot AI changed the title Exclude sourcesContent from .d.ts.map when inlineSources is enabled Align declaration emit printer options with strada May 12, 2026
@jakebailey jakebailey enabled auto-merge May 12, 2026 20:28
@jakebailey jakebailey added this pull request to the merge queue May 12, 2026
Merged via the queue into main with commit 507c80e May 12, 2026
21 checks passed
@jakebailey jakebailey deleted the copilot/fix-dts-map-inline-sources branch May 12, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.d.ts.map includes sourcesContent when inlineSources is enabled

4 participants