Repository navigation
Visit each dynamic import once when the specifier contains import - #65536
Closed
Josué Barros (joshbarros) wants to merge 1 commit into
Closed
Josué Barros (joshbarros) wants to merge 1 commit into
Josué Barros (joshbarros) wants to merge 1 commit into
Conversation
ForEachDynamicImportOrRequireCall scans the source text for the keywords and resolves each hit to a node. A specifier such as "./imported.ts" contains the text "import", so the same import call was visited twice. collectExternalModuleReferences appended the specifier twice, and willRenameFiles then produced two overlapping text edits for one range and panicked with 'changes overlap'. Track visited nodes and invoke the callback once per node. Adds a fourslash willRenameFiles test for a .ts dynamic import specifier.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the dynamic-import rename fix.
No open issues 🎉
What changed in this PR
Fixes #65505 by preventing repeated visits to the same dynamic import node, avoiding overlapping rename edits that crash the language server.
Changes:
- Tracks visited nodes during import/require text scanning so each node invokes the callback at most once.
- Adds a fourslash regression test verifying that renaming a file referenced by
import("./imported.ts")produces the expected specifier update.
| File | Description |
|---|---|
tsc/internal/fourslash/tests/getEditsForFileRename_dynamicImportTsSpecifier_test.go |
Tests moving a dynamically imported .ts file and updating its specifier. |
tsc/internal/ast/utilities.go |
Deduplicates nodes encountered during import/require scanning. |
Review effort: Balanced
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 #65505
ForEachDynamicImportOrRequireCallscans the source text forimport/requireand resolves each hit to a node. A specifier such as"./imported.ts"itself contains the textimport, so the same import call was visited twice.collectExternalModuleReferencesappended the specifier twice, andworkspace/willRenameFilesthen produced two overlapping text edits for one range and panicked withchanges overlap.This tracks visited nodes and invokes the callback once per node. The add is scoped to the scan loop; the returned imports for a
.jsspecifier are unchanged.The new fourslash test renames
/imported.tsto/sub/moved.tsin the issue'simport("./imported.ts")project and expects the single specifier edit. On the unfixed compiler the test panics in the server.Validation:
go test ./tsc/internal/fourslash/tests -run TestGetEditsForFileRename_dynamicImportTsSpecifier -count=1: panics without the change, passes with it.go test ./tsc/internal/fourslash/tests -run 'GetEditsForFileRename|WillRename' -count=1: pass.go test ./tsc/internal/ast ./tsc/internal/parser ./tsc/internal/lsp ./tsc/internal/ls -count=1: pass.gofmt: clean.Drafted with assistance from an AI assistant. I reviewed the diff and ran the tests above.