Skip to content

Rewrite relative dynamic imports in scripts - #65825

Open
Muhammad Faizan (MuhammadFaizan-prog) wants to merge 2 commits into
microsoft:mainfrom
MuhammadFaizan-prog:fix/65775-script-import-extensions
Open

Muhammad Faizan (MuhammadFaizan-prog) wants to merge 2 commits into
microsoft:mainfrom
MuhammadFaizan-prog:fix/65775-script-import-extensions

Conversation

@MuhammadFaizan-prog

Copy link
Copy Markdown

Fixes #65775.

The ES module transform skipped script files even when they contained dynamic imports. Visit scripts that contain dynamic imports when relative extension rewriting is enabled. This preserves script output without adding a module marker or changing CommonJS-style require calls in scripts.

The compiler regression covers literal and computed imports in ESNext and Preserve output, including when computed-path rewriting is disabled. The unpatched compiler emitted a path that failed at runtime in Node.js; the fixed build loads the emitted file. The full compiler test runner package, 20 focused configurations, scoped Go vet, and format checks passed. The local hereby validate --all run was stopped during setup because the workspace was out of disk space.

Copilot AI balanced review requested due to automatic review settings December 5, 2026 19:49
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Dec 5, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Dec 5, 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 regression tests never exercise the JavaScript-only guard, leaving preservation of require calls alongside rewritten dynamic imports unverified.

1 open issue
What changed in this PR

Fixes #65775 by rewriting relative dynamic imports in scripts without adding module markers or changing script require calls.

Changes:

  • Visits scripts containing dynamic imports when extension rewriting is enabled.
  • Preserves existing handling of JavaScript script require calls.
  • Adds ESNext and Preserve baselines with computed-path rewriting enabled and disabled.
File Description
tsc/​testdata/​tests/​cases/​compiler/​rewriteRelativeImportExtensionsDynamicImportScript.ts Tests literal and computed dynamic imports.
tsc/​testdata/​baselines/​reference/​compiler/​rewriteRelativeImportExtensionsDynamicImportScript(disabledynamicimportextensionrewriting=true,module=preserve).js Preserve output with literal-only rewriting.
tsc/​testdata/​baselines/​reference/​compiler/​rewriteRelativeImportExtensionsDynamicImportScript(disabledynamicimportextensionrewriting=true,module=esnext).js ESNext output with literal-only rewriting.
tsc/​testdata/​baselines/​reference/​compiler/​rewriteRelativeImportExtensionsDynamicImportScript(disabledynamicimportextensionrewriting=false,module=preserve).js Preserve output with the runtime rewriting helper.
tsc/​testdata/​baselines/​reference/​compiler/​rewriteRelativeImportExtensionsDynamicImportScript(disabledynamicimportextensionrewriting=false,module=esnext).js ESNext output with the runtime rewriting helper.
tsc/​internal/​transformers/​moduletransforms/​esmodule.go Enables script import rewriting while preserving require calls.

Review effort: Balanced

@MuhammadFaizan-prog

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

--rewriteRelativeImportExtensions helpers not emitted for global/script files

2 participants