Repository navigation
Rewrite relative dynamic imports in scripts - #65825
Open
Muhammad Faizan (MuhammadFaizan-prog) wants to merge 2 commits into
Open
Muhammad Faizan (MuhammadFaizan-prog) wants to merge 2 commits into
Muhammad Faizan (MuhammadFaizan-prog) wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 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
requirecalls. - 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
Author
|
@microsoft-github-policy-service agree |
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.

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
requirecalls 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 --allrun was stopped during setup because the workspace was out of disk space.