Skip to content

Visit each dynamic import once when the specifier contains import - #65536

Closed
Josué Barros (joshbarros) wants to merge 1 commit into
microsoft:mainfrom
joshbarros:fix/65505-willrename-dynamic-import-duplicate
Closed

Josué Barros (joshbarros) wants to merge 1 commit into
microsoft:mainfrom
joshbarros:fix/65505-willrename-dynamic-import-duplicate

Conversation

@joshbarros

Copy link
Copy Markdown

Fixes #65505

ForEachDynamicImportOrRequireCall scans the source text for import/require and resolves each hit to a node. A specifier such as "./imported.ts" itself contains the text import, so the same import call was visited twice. collectExternalModuleReferences appended the specifier twice, and workspace/willRenameFiles then produced two overlapping text edits for one range and panicked with changes 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 .js specifier are unchanged.

The new fourslash test renames /imported.ts to /sub/moved.ts in the issue's import("./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.

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.
Copilot AI balanced review requested due to automatic review settings November 16, 2026 19:00
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 16, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 16, 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.

🟢 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

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

workspace/willRenameFiles panics with "changes overlap" when the renamed file is loaded by import() with a .ts specifier

3 participants