Skip to content

Renaming alias in export specifier no longer works in 3.8 RC when name equals propertyName #36695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dsherret opened this issue Feb 8, 2020 · 3 comments · Fixed by #36790
Closed
Assignees
Labels
Bug A bug in TypeScript

Comments

@dsherret
Copy link
Contributor

dsherret commented Feb 8, 2020

TypeScript Version: 3.8.0-dev.20200208

Search Terms: rename export specifier alias

This actually works for me in VS code for some reason when using @next, but not when using the compiler api directly. Maybe my VS code setup is wrong though.

Why?

This bug will block me from doing a ts-morph release unless I come up with a new solution for renaming only the exported name. Previously it worked to change the export to export { name } to export { name as name} then use rename on the language service to go to export { name as newAlias }.

Code

// a.ts
export class name {}

// b.ts
import { name } from "./a"; export { name as name /* rename this identifier */ };

// c.ts
import { name } from "./b";

Expected behavior:

// a.ts
export class name {}

// b.ts
import { name } from "./a"; export { name as newAlias };

// c.ts
import { newAlias } from "./b";

Actual behavior:

// a.ts
export class newAlias {}

// b.ts
import { newAlias } from "./a"; export { newAlias as newAlias };

// c.ts
import { newAlias } from "./b";

Result of calling languageService.findRenameLocations("/b.ts", 45, false, false, false):

[ { textSpan: { start: 9, length: 4 },
    fileName: '/b.ts',
    contextSpan: { start: 0, length: 27 } },
  { textSpan: { start: 37, length: 4 },
    fileName: '/b.ts',
    contextSpan: { start: 28, length: 24 } },
  { textSpan: { start: 13, length: 4 },
    fileName: '/a.ts',
    contextSpan: { start: 0, length: 20 } },
  { textSpan: { start: 9, length: 4 },
    fileName: '/c.ts',
    contextSpan: { start: 0, length: 27 } },
  { textSpan: { start: 45, length: 4 },
    fileName: '/b.ts',
    contextSpan: { start: 28, length: 24 } } ]
@dsherret
Copy link
Contributor Author

dsherret commented Feb 12, 2020

Here's some reproduction steps (using @tsmorph/bootstrap for the setup because it's easier):

npm install --save-dev typescript@next @ts-morph/bootstrap
rm -rf node_modules/@ts-morph/common/node_modules/typescript #make it use typescript@next

Now the code:

// setup...
const { Project, ts } = require("@ts-morph/bootstrap");

console.log(ts.version); // 3.9.0-dev.20200212

const project = new Project({ useInMemoryFileSystem: true });

const fileA = project.createSourceFile("a.ts", "export class name{}");
const fileB = project.createSourceFile("b.ts", `import { name } from "./a"; export { name as name };`);
const fileC = project.createSourceFile("c.ts", `import { name } from "./b";`);

const languageService = project.getLanguageService();

// rename
const renameLocations = languageService.findRenameLocations("/b.ts", 45, false, false, false);

console.log(renameLocations)

Outputs what I mentioned in the original issue.

Expected output as is done in 3.7.5 is:

3.7.5
[
  {
    textSpan: { start: 45, length: 4 },
    fileName: '/b.ts',
    contextSpan: { start: 28, length: 24 }
  },
  {
    textSpan: { start: 9, length: 4 },
    fileName: '/c.ts',
    contextSpan: { start: 0, length: 27 }
  }
]

@andrewbranch andrewbranch added the Bug A bug in TypeScript label Feb 13, 2020
@andrewbranch andrewbranch self-assigned this Feb 13, 2020
@andrewbranch andrewbranch added this to the TypeScript 3.8.2 milestone Feb 13, 2020
@dsherret
Copy link
Contributor Author

@andrewbranch thanks for looking into this! Some more information... just figured out it only happens in the IDE when "rename shorthand properties" is unchecked:

image

issue36695

@andrewbranch
Copy link
Member

Oh thank you so much for that; I just started debugging VS Code’s TS Server vs. your project side-by-side. You probably just saved me the better part of an hour 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants