Prettier: Comments in decorators are moved to top when class is exported

Created on 4 Jun 2017  Â·  3Comments  Â·  Source: prettier/prettier

Stumbled across this while formatting an Angular codebase.

Input:

@NgModule({
  // Imports.
  imports: [
    // Angular modules.
    BrowserModule,

    // App modules.
    CoreModule,
    SharedModule,
  ],
})
export class AppModule {}

Output:

// Imports.
// Angular modules.
// App modules.
@NgModule({
  imports: [BrowserModule, CoreModule, SharedModule],
})
export class AppModule {}

Expected:

No difference between input and output.


The problem goes away when export is removed from export class AppModule {}.

A reproduction of this issue can be found here.

locked-due-to-inactivity bug

Most helpful comment

I just published 1.4.3 which fixes it. Thanks for reporting it!

All 3 comments

Turns out this isn't TypeScript specific. Happens with Babylon, too.

Perhaps related, adding // prettier-ignore above the decorator removes it entirely, comments and class are preserved though. Again, removing export fixes the issue.

I just published 1.4.3 which fixes it. Thanks for reporting it!

Was this page helpful?
0 / 5 - 0 ratings