Repository navigation
Filter out more diagnostics from content mapper synthesized code - #65573
Open
Andrew Branch (andrewbranch) wants to merge 1 commit into
Open
Andrew Branch (andrewbranch) wants to merge 1 commit into
Andrew Branch (andrewbranch) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The diagnostic filtering still drops valid errors spanning adjacent verbatim segments and fails to suppress two emit-only diagnostic kinds in synthesized code.
2 open issues
What changed in this PR
This PR reduces emit-related diagnostics in content-mapper virtual files, addressing part of #64182 while preserving checks in user-written verbatim ranges.
Changes:
- Filters selected module-syntax, isolated-transpilation, and erasable-syntax diagnostics from synthesized code.
- Adds tests comparing synthesized, atom, and verbatim mappings.
- Adds guidance to describe diagnostics rather than refer only to numeric codes.
| File | Description |
|---|---|
tsc/internal/compiler/program.go |
Adds diagnostic exclusions based on mapping fidelity. |
tsc/internal/compiler/contentmapper_test.go |
Tests diagnostic filtering across syntax and mapping modes. |
AGENTS.md |
Documents human-readable diagnostic references. |
Review effort: Balanced
| } | ||
| _, fidelity := file.SpanMap().VirtualToOriginalSpan(diag.Loc()) | ||
| if isExcludedDiagnosticForSynthesizedContentMapperCode(diag.Code()) { | ||
| return fidelity.IsExact() |
Comment on lines
+842
to
+856
| diagnostics.X_0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled.Code(), | ||
| diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled.Code(), | ||
| diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_0_is_enabled.Code(), | ||
| diagnostics.Re_exporting_a_type_when_0_is_enabled_requires_using_export_type.Code(), | ||
| diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_re_exported_using_a_type_only_re_export_when_1_is_enabled.Code(), | ||
| diagnostics.An_export_declaration_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration.Code(), | ||
| diagnostics.An_export_default_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration.Code(), | ||
| diagnostics.An_export_declaration_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type.Code(), | ||
| diagnostics.An_export_default_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type.Code(), | ||
| diagnostics.X_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_import_type_where_0_is_imported.Code(), | ||
| diagnostics.X_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default.Code(), | ||
| diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_import_type_where_0_is_imported.Code(), | ||
| diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default.Code(), | ||
| diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled.Code(), | ||
| diagnostics.Enum_member_following_a_non_literal_numeric_member_must_have_an_initializer_when_isolatedModules_is_enabled.Code(), |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Filters out
verbatimModuleSyntaxandisolatedModulesdiagnostics from synthesized code in content mapper virtual files. These diagnostics still apply inside verbatim ranges (e.g. you have to use ESM syntax in a<script>block the gets interpreted as ESM whenverbatimModuleSyntaxis on). These diagnostics are concerned with JS emit—forverbatimModuleSyntax, the human understandability of what's going to be emitted; forisolatedModules, the capability of a transpiler to do single-file emit. Content mapper output doesn't get emitted to JS, and the synthesized parts are never seen by a human, so there doesn't seem to be a strong reason to have these.The original motivation was that a content mapper doesn't automatically know whether it's in a CJS or ESM context, and vMS may be the only reason it needs to know, when named exports work just fine in either mode.
Happy to reconsider any of these filtered diagnostics if someone can think of a reason why it's sketchy.
Implements part of the suggestion in #64182 (comment)