File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed
ng-generate/standalone-migration Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -286,11 +286,11 @@ function addPropertyToAngularDecorator(
286286 return node ;
287287 }
288288
289- return ts . factory . updateDecorator (
290- node ,
291- ts . factory . createCallExpression ( node . expression . expression , node . expression . typeArguments , [
292- ts . factory . createObjectLiteralExpression ( literalProperties , literalProperties . length > 1 )
293- ] ) ) ;
289+ // Use `createDecorator` instead of ` updateDecorator`, because
290+ // the latter ends up duplicating the node's leading comment.
291+ return ts . factory . createDecorator ( ts . factory . createCallExpression (
292+ node . expression . expression , node . expression . typeArguments ,
293+ [ ts . factory . createObjectLiteralExpression ( literalProperties , literalProperties . length > 1 ) ] ) ) ;
294294}
295295
296296/** Checks if a node is a `PropertyAssignment` with a name. */
Original file line number Diff line number Diff line change @@ -1294,6 +1294,34 @@ describe('standalone migration', () => {
12941294 ` ) ) ;
12951295 } ) ;
12961296
1297+ it ( 'should not duplicate doc strings' , async ( ) => {
1298+ writeFile ( 'module.ts' , `
1299+ import {NgModule, Directive} from '@angular/core';
1300+
1301+ /** Directive used for testing. */
1302+ @Directive({selector: '[dir]'})
1303+ export class MyDir {}
1304+
1305+ /** Module used for testing. */
1306+ @NgModule({declarations: [MyDir]})
1307+ export class Mod {}
1308+ ` ) ;
1309+
1310+ await runMigration ( 'convert-to-standalone' ) ;
1311+
1312+ expect ( stripWhitespace ( tree . readContent ( 'module.ts' ) ) ) . toBe ( stripWhitespace ( `
1313+ import {NgModule, Directive} from '@angular/core';
1314+
1315+ /** Directive used for testing. */
1316+ @Directive({selector: '[dir]', standalone: true})
1317+ export class MyDir {}
1318+
1319+ /** Module used for testing. */
1320+ @NgModule({imports: [MyDir]})
1321+ export class Mod {}
1322+ ` ) ) ;
1323+ } ) ;
1324+
12971325 it ( 'should remove a module that only has imports and exports' , async ( ) => {
12981326 writeFile ( 'app.module.ts' , `
12991327 import {NgModule} from '@angular/core';
You can’t perform that action at this time.
0 commit comments