--annotateTransforms
switch to add transformer diagnostics to Source Maps
#51307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds an
--annotateTransforms
compiler option that can (eventually) be used as a debugging tool for compiler transforms. When--annotateTransforms
is set, along with--sourceMap
(and/or--declarationMap
), an extrax_ms_ts_annotations
property is added to the output source map containing annotations associated with a line/character in the generated output.However, this isn't extremely useful on its own. In addition to this, we would need to publish a VS Code extension capable of reading the source map that can then add hovers or text editor decorations to display the diagnostic information. The end result would be something not unlike VS Code's own "Developer: Inspect Editor Tokens and Scopes" command, allowing you to inspect which transformers lead to a specific node being included in the output.
Most of this was originally part of #50820, but I'm pulling the functionality out of that PR. The original version injected comments into the output, but that made the output file difficult to read and thus defeated the purpose.
The format of the
x_ms_ts_annotations
field is not yet set in stone and is likely to change before (if) this becomes available. The information stored inx_ms_ts_annotations
is intentionally generic: an "Annotation" is an object consisting of a name (a string) and a value (any valid JSON). One or more annotations can be associated with a generated line/character:The provided name need not be unique. All annotations will be included at the generated position since multiple nodes can share the same generated start and end positions.
In addition, this adds a public
decodeSourceMapAnnotations
function that can be used to deserialize thex_ms_ts_annotations
property into eachDecodedSourceMapAnnotation
entry.When
--annotateTransforms
is enabled, the following annotations are written before and after eachNode
:Since this can be fairly chatty, this information is only written to the source map when
--annotateTransforms
is enabled.