Skip to content

fix: honor forced module detection in compiler source files - #1688

Open
pranav256 wants to merge 1 commit into
dsherret:latestfrom
pranav256:fix/force-module-detection
Open

pranav256 wants to merge 1 commit into
dsherret:latestfrom
pranav256:fix/force-module-detection

Conversation

@pranav256

Copy link
Copy Markdown

Fixes #1611.

Summary

The document registry passes only the language target into source-file creation,
so TypeScript's compiler-option-aware external-module classification is missing.
With moduleDetection: Force, otherwise unrelated files are therefore treated
as scripts sharing the global scope.

  • Pass TypeScript's existing module classifier through source-file creation and
    update paths via CreateSourceFileOptions.
  • Add a typed internal wrapper following the existing TypeScript-wrapper convention.
  • Preserve the target/script kind/version, declaration-file globals, and Legacy
    behavior. Existing compiler-option invalidation also reparses cached files
    correctly with the classification metadata.

Reproduction and regression coverage

Two forced-module files each containing const a = 'a'; currently produce two
false TS2451 diagnostics, whereas native TypeScript produces none. Conversely,
an unimported interface from another file incorrectly becomes visible and hides
the TS2304 error native TypeScript reports.

Registry and project tests compare against native TypeScript and cover both
diagnostic directions, declaration globals, acquisition/update/keyed updates,
manipulation/reparsing, language-service diagnostics, retained node identity,
and warmed Legacy-to-Force / Force-to-Legacy option changes.

Validation

  • Before fix: four registry and four project regressions fail; six controls pass.
  • After fix: all 14 targeted cases pass.
  • Full source workspace suite: 5,407 passing, 2 existing pending
    (933 common + 84 bootstrap + 4390 ts-morph).
  • Recursive canonical compile and code-verification tasks: pass.
  • dprint check and git diff --check: pass.
  • Common runtime/declarations rebuilt successfully; tracked generated files and
    lockfiles have no changes.

An initial whole-workspace build exceeded the local timeout during declaration
generation. Subsequent canonical source compile/code checks and the complete
workspace test suite all completed successfully. A supplemental direct tsc
run reports the same 391 diagnostic-code counts on baseline and patched
ts-morph source; common/bootstrap direct checks pass.

AI assistance was used for investigation, implementation and regression tests.
The source changes, native TypeScript control cases, and validation evidence
were reviewed before submission.

@pranav256
pranav256 force-pushed the fix/force-module-detection branch from 202280c to d12d13c Compare October 29, 2026 06:48
@pranav256
pranav256 force-pushed the fix/force-module-detection branch from d12d13c to 85724a1 Compare October 29, 2026 07:34

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

moduleDetection force compiler setting does not work

1 participant