Skip to content

Renaming namespace import from another project will rename its first symbol #45659

@esdmr

Description

@esdmr

Bug Report

Renaming namespace (star) imports to a file in a different project than the current file will cause the first unexported symbol (variable, function, import, …) to be renamed to the same name as the import itself, if that project was either opened in the editor or referenced by the current tsconfig.json.

🔎 Search Terms

Rename refactor, Namespace import, project, composite, tsconfig, folders, directories

🕗 Version & Regression Information

This was not fixed in the most recent nightly version 4.5.0-dev.20210831.

  • This changed between versions 3.7.7 and 3.8.2
  • This changed between nightly versions 3.8.0-dev.20200131 and 3.8.0-dev.20200201

⏯ Playground Link

Typescript workbench apparently does not support JSON files, therefore it can not create multiple projects required to reproduce this bug.

Here is the link to GitHub MWE Repo.

💻 Code

  1. Create two directories. One at lib, and the other at src.
  2. In both directories create a tsconfig.json with any content. An empty object will do.
  3. At lib/lib.ts create a file with the following content:
    const unrelatedLocalVariable = 123;
    export const someExportedVariable = unrelatedLocalVariable;
  4. At src/main.ts create a file with the following content:
    import * as lib from '../lib/lib.js';
  5. Close all tabs.
  6. Open lib/lib.ts and then open src/main.ts.
  7. Rename lib in src/main.ts.

🙁 Actual behavior

If lib/lib.ts has an unexported symbol at the very top of the file (unrelatedLocalVariable), it will rename it to the same name as the import in src/main.ts.

🙂 Expected behavior

Renaming a namespace import should not modify any external files.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions