Skip to content
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

Unable to rename bindingElement with usePrefixAndSuffixTextForRename:true #1488

Open
huntye1 opened this issue Jan 19, 2024 · 0 comments
Open

Comments

@huntye1
Copy link

huntye1 commented Jan 19, 2024

Describe the bug

Version: 21.0.1

To Reproduce

import { Project, ts } from "ts-morph";

const project = new Project({
  manipulationSettings: {
    usePrefixAndSuffixTextForRename: true,
  },
});

const sourceFile = project.createSourceFile(
  "foo.ts",
  `const fn = ({ p, baz }) => {
    set({ p, baz });
  };
  `
);

const fns = [...sourceFile.getDescendantsOfKind(ts.SyntaxKind.ArrowFunction)];

fns.forEach((fn) => {
  const bindingElements = fn.getDescendantsOfKind(ts.SyntaxKind.BindingElement);
  bindingElements.forEach((b) => {
    b.rename("inner" + b.getName());
  });
});

Expected behavior

expect output code:

const fn = ({ p: innerP, baz: innerBaz }) => {
    set({ p: innerP, baz: innerBaz) });
  };

Actrual behavior

node_modules/.pnpm/ts-morph@21.0.1/node_modules/ts-morph/dist/ts-morph.js:3042
            throw new common.errors.InvalidOperationError(message);
                  ^
InvalidOperationError: Attempted to get information from a node that was removed or forgotten.

Node text: baz
    at BindingElement.get compilerNode [as compilerNode] (node_modules/.pnpm/ts-morph@21.0.1/node_modules/ts-morph/dist/ts-morph.js:3042:19)
    at BindingElement.getNameNode (node_modules/.pnpm/ts-morph@21.0.1/node_modules/ts-morph/dist/ts-morph.js:9467:55)
    at BindingElement.getName (node_modules/.pnpm/ts-morph@21.0.1/node_modules/ts-morph/dist/ts-morph.js:9470:25)
    at test/ts-m.ts:22:26
    at Array.forEach (<anonymous>)
    at test/ts-m.ts:21:20
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (test/ts-m.ts:19:5)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module.m._compile (node_modules/.pnpm/ts-node@10.9.2_@types+node@20.11.4_typescript@5.3.3/node_modules/ts-node/src/index.ts:1618:23)
    ```

<!-- A description of what you expected to happen. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant