Align declaration emit printer options with strada#3812
Conversation
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>
|
@weswigham Surprised we didn't include maps on d.ts files but it does seem that we didn't before. |
There was a problem hiding this comment.
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
inlineSourcesinto.d.ts.mapgeneration. - Adds a new compiler test case covering
inlineSources+declarationMapto ensure.d.ts.mapomitssourcesContent. - 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
| @@ -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 | |||
| // !!! | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Updated the comment in f2e73f3 to say // Explicitly do not passthru \inlineSources`instead of referencing both inline options, sinceinlineSourceMap` is correctly passed through.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
(Mostly because I imagine this options object first got ported without most of these implemented)
There was a problem hiding this comment.
@copilot Make it match and see if it works, see the above for what to copy
There was a problem hiding this comment.
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.
…options Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/8d630e28-fa86-4891-93e8-05f5132aa1d0 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/8713d7db-0f39-41b5-a68f-ac57ebac32c4 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
.d.ts.mapfiles incorrectly includesourcesContentwheninlineSourcesis enabled, and the declaration printer options bag was generally out of date with strada'semitDeclarationFileOrBundle.emitDeclarationFileto match strada'semitDeclarationFileOrBundle(emitter.ts:924-936):NoEmitHelpershardcoded totrue(declarations never need helpers)Targetfromoptions.GetEmitScriptTarget()SourceMapnow gated one.emitOnly != EmitOnlyForcedDts(matching strada'sBuilderSignatureguard)InlineSourcesexcluded (per strada)OmitBraceSourceMapPositions: trueModule,ModuleResolution,ExtendedDiagnosticsdeclarationMapInlineSourcesContentcovering theinlineSources+declarationMapcase