diff --git a/src/util.js b/src/util.js index 6a06c399b..3b94cb62b 100644 --- a/src/util.js +++ b/src/util.js @@ -206,9 +206,18 @@ function hasSpaces(text, index, opts) { } function locStart(node) { + // Handle nodes with decorators. They should start at the first decorator + if ( + node.declaration && + node.declaration.decorators && + node.declaration.decorators.length > 0 + ) { + return locStart(node.declaration.decorators[0]); + } if (node.decorators && node.decorators.length > 0) { return locStart(node.decorators[0]); } + if (node.range) { return node.range[0]; } diff --git a/tests/decorators/__snapshots__/jsfmt.spec.js.snap b/tests/decorators/__snapshots__/jsfmt.spec.js.snap index 6fcf12111..95c70dee4 100644 --- a/tests/decorators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/decorators/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,20 @@ var x = 100 class X { } + + +@NgModule({ + // Imports. + imports: [ + // Angular modules. + BrowserModule, + + // App modules. + CoreModule, + SharedModule, + ], +}) +export class AppModule {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = 100; @@ -21,6 +35,19 @@ var x = 100; }) class X {} +@NgModule({ + // Imports. + imports: [ + // Angular modules. + BrowserModule, + + // App modules. + CoreModule, + SharedModule + ] +}) +export class AppModule {} + `; exports[`methods.js 1`] = ` diff --git a/tests/decorators/comments.js b/tests/decorators/comments.js index a3848746f..9b5bf8ce6 100644 --- a/tests/decorators/comments.js +++ b/tests/decorators/comments.js @@ -8,3 +8,17 @@ var x = 100 class X { } + + +@NgModule({ + // Imports. + imports: [ + // Angular modules. + BrowserModule, + + // App modules. + CoreModule, + SharedModule, + ], +}) +export class AppModule {}