Skip to content

Filter out more diagnostics from content mapper synthesized code - #65573

Open
Andrew Branch (andrewbranch) wants to merge 1 commit into
mainfrom
content-mapper-ignored-diagnostics
Open

Andrew Branch (andrewbranch) wants to merge 1 commit into
mainfrom
content-mapper-ignored-diagnostics

Conversation

@andrewbranch

Copy link
Copy Markdown
Member

Filters out verbatimModuleSyntax and isolatedModules diagnostics 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 when verbatimModuleSyntax is on). These diagnostics are concerned with JS emit—for verbatimModuleSyntax, the human understandability of what's going to be emitted; for isolatedModules, 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)

Copilot AI balanced review requested due to automatic review settings November 19, 2026 00:49
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 19, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants