p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
119 stars 7 forks source link

Bug report: Comment node is removed after "Extract to function in module scope" #35

Closed aghArdeshir closed 1 year ago

aghArdeshir commented 1 year ago

Hi. When I refactor a callback in my JSX, which does something rather complicated, one of my comments are removed.

Code example:

//@ts-nocheck
/* eslint-disable */

export default function Something() {
  return (
    <SomeComponent
      aCallbackThatProducesAReactNode={() => {
        // this comment will be kept intact
        const someProps = {
          prop1: props.props1, // BUT THIS COMMENT WILL BE REMOVED :(

          prop2: props.props2 // this comment will be kept intact too
        };

        return <SomeOtherComponent {...someProps} />;
      }}
    />
  );
}

Try refactoring the whole callback into a function in module scope.

One: image

Two: image

Three: image

As you see one of my comments are removed.

Thanks.

lgrammel commented 1 year ago

Hi @aghArdeshir,

thanks for the bug report. It looks like the refactoring "Extract to function in module scope" comes with VS Code (built-in), not P42. P42 refactorings have a '[P42]' at the end of the action label in the context menu. If this is a P42 refactoring, please re-open the issue.

Best, Lars

aghArdeshir commented 1 year ago

Oops! :face_with_head_bandage: Why I didn't notice it!

lgrammel commented 1 year ago

Haha it's pretty easy to miss - you're not the first one.