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

Inline comments within parameters moved before previous comma #650

Closed
jakebailey opened this issue Jul 18, 2024 · 6 comments · Fixed by #651
Closed

Inline comments within parameters moved before previous comma #650

jakebailey opened this issue Jul 18, 2024 · 6 comments · Fixed by #651
Labels
bug Something isn't working priority: high

Comments

@jakebailey
Copy link
Contributor

Describe the bug

dprint-plugin-typescript version: 0.91.3

Input Code

function foo(arg: number, /** @deferred */ cb: () => void): void {}

interface Foo {
  method<T>(
    arg: { new(...args: any[]): T }, // This is a comment
    arg2: (instance: T) => HTMLElement | undefined,
  ): Disposable;

  method2<T>(
    arg: { new(...args: any[]): T },
    arg2: (instance: T) => HTMLElement | undefined, // This is a comment
  ): Disposable;
}

Expected Output

function foo(arg: number, /** @deferred */ cb: () => void): void {}

interface Foo {
  method<T>(
    arg: { new(...args: any[]): T }, // This is a comment
    arg2: (instance: T) => HTMLElement | undefined,
  ): Disposable;

  method2<T>(
    arg: { new(...args: any[]): T },
    arg2: (instance: T) => HTMLElement | undefined, // This is a comment
  ): Disposable;
}

Actual Output

function foo(arg: number /** @deferred */, cb: () => void): void {}

interface Foo {
  method<T>(
    arg: { new(...args: any[]): T } // This is a comment
    ,
    arg2: (instance: T) => HTMLElement | undefined,
  ): Disposable;

  method2<T>(
    arg: { new(...args: any[]): T },
    arg2: (instance: T) => HTMLElement | undefined // This is a comment
    ,
  ): Disposable;
}

Noticed this when updating DT; 30 some files had instances of this.

This is particularly scary because microsoft/TypeScript#58729 introduces a parameter JSDoc comment that shouldn't be moved around.

@jakebailey
Copy link
Contributor Author

A bisect pointed to #630; maybe something in deno_ast?

@dsherret dsherret added bug Something isn't working priority: high labels Jul 19, 2024
@dsherret
Copy link
Member

Not sure how we haven't got a report about this in Deno. It might be something that's only triggered with certain config. I'll take a look tomorrow.

@dsherret
Copy link
Member

dsherret commented Jul 19, 2024

Caused because swc started incorrectly setting the text range for BindingIdent to not include the type annotation. I'll do a quick fix and then try to fix this in swc.

@dsherret
Copy link
Member

dsherret commented Jul 19, 2024

Opened swc-project/swc#9290

Temporarily patched this in our wrapper: dprint/dprint-swc-ext#62 (we had to introduce a wrapper around swc's spans because the first index was shifted from 0 to 1 in order to make 0 a magic number)

@jakebailey
Copy link
Contributor Author

Thank you once again!

@dsherret
Copy link
Member

I opened #652 to catch this sooner in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: high
Projects
None yet
2 participants