@@ -98,15 +98,10 @@ export function convertNgModuleDeclarationToStandalone(
9898 decl , allDeclarations , tracker , typeChecker , importRemapper ) ;
9999
100100 if ( importsToAdd . length > 0 ) {
101- const hasTrailingComma = importsToAdd . length > 2 &&
102- ! ! extractMetadataLiteral ( directiveMeta . decorator ) ?. properties . hasTrailingComma ;
103101 decorator = addPropertyToAngularDecorator (
104102 decorator ,
105103 ts . factory . createPropertyAssignment (
106- 'imports' ,
107- ts . factory . createArrayLiteralExpression (
108- // Create a multi-line array when it has a trailing comma.
109- ts . factory . createNodeArray ( importsToAdd , hasTrailingComma ) , hasTrailingComma ) ) ) ;
104+ 'imports' , ts . factory . createArrayLiteralExpression ( importsToAdd ) ) ) ;
110105 }
111106 }
112107
@@ -220,9 +215,6 @@ function moveDeclarationsToImports(
220215 const declarationsToCopy : ts . Expression [ ] = [ ] ;
221216 const properties : ts . ObjectLiteralElementLike [ ] = [ ] ;
222217 const importsProp = findLiteralProperty ( literal , 'imports' ) ;
223- const hasAnyArrayTrailingComma = literal . properties . some (
224- prop => ts . isPropertyAssignment ( prop ) && ts . isArrayLiteralExpression ( prop . initializer ) &&
225- prop . initializer . elements . hasTrailingComma ) ;
226218
227219 // Separate the declarations that we want to keep and ones we need to copy into the `imports`.
228220 if ( ts . isPropertyAssignment ( declarationsProp ) ) {
@@ -256,9 +248,7 @@ function moveDeclarationsToImports(
256248 // If there are no `imports`, create them with the declarations we want to copy.
257249 if ( ! importsProp && declarationsToCopy . length > 0 ) {
258250 properties . push ( ts . factory . createPropertyAssignment (
259- 'imports' ,
260- ts . factory . createArrayLiteralExpression ( ts . factory . createNodeArray (
261- declarationsToCopy , hasAnyArrayTrailingComma && declarationsToCopy . length > 2 ) ) ) ) ;
251+ 'imports' , ts . factory . createArrayLiteralExpression ( declarationsToCopy ) ) ) ;
262252 }
263253
264254 for ( const prop of literal . properties ) {
@@ -270,13 +260,8 @@ function moveDeclarationsToImports(
270260 // If we have declarations to preserve, update the existing property, otherwise drop it.
271261 if ( prop === declarationsProp ) {
272262 if ( declarationsToPreserve . length > 0 ) {
273- const hasTrailingComma = ts . isArrayLiteralExpression ( prop . initializer ) ?
274- prop . initializer . elements . hasTrailingComma :
275- hasAnyArrayTrailingComma ;
276263 properties . push ( ts . factory . updatePropertyAssignment (
277- prop , prop . name ,
278- ts . factory . createArrayLiteralExpression ( ts . factory . createNodeArray (
279- declarationsToPreserve , hasTrailingComma && declarationsToPreserve . length > 2 ) ) ) ) ;
264+ prop , prop . name , ts . factory . createArrayLiteralExpression ( declarationsToPreserve ) ) ) ;
280265 }
281266 continue ;
282267 }
@@ -288,16 +273,10 @@ function moveDeclarationsToImports(
288273
289274 if ( ts . isArrayLiteralExpression ( prop . initializer ) ) {
290275 initializer = ts . factory . updateArrayLiteralExpression (
291- prop . initializer ,
292- ts . factory . createNodeArray (
293- [ ...prop . initializer . elements , ...declarationsToCopy ] ,
294- prop . initializer . elements . hasTrailingComma ) ) ;
276+ prop . initializer , [ ...prop . initializer . elements , ...declarationsToCopy ] ) ;
295277 } else {
296- initializer = ts . factory . createArrayLiteralExpression ( ts . factory . createNodeArray (
297- [ ts . factory . createSpreadElement ( prop . initializer ) , ...declarationsToCopy ] ,
298- // Expect the declarations to be greater than 1 since
299- // we have the pre-existing initializer already.
300- hasAnyArrayTrailingComma && declarationsToCopy . length > 1 ) ) ;
278+ initializer = ts . factory . createArrayLiteralExpression (
279+ [ ts . factory . createSpreadElement ( prop . initializer ) , ...declarationsToCopy ] ) ;
301280 }
302281
303282 properties . push ( ts . factory . updatePropertyAssignment ( prop , prop . name , initializer ) ) ;
@@ -309,9 +288,7 @@ function moveDeclarationsToImports(
309288 }
310289
311290 tracker . replaceNode (
312- literal ,
313- ts . factory . updateObjectLiteralExpression (
314- literal , ts . factory . createNodeArray ( properties , literal . properties . hasTrailingComma ) ) ,
291+ literal , ts . factory . updateObjectLiteralExpression ( literal , properties ) ,
315292 ts . EmitHint . Expression ) ;
316293}
317294
@@ -336,12 +313,10 @@ function addPropertyToAngularDecorator(
336313 }
337314
338315 let literalProperties : ts . ObjectLiteralElementLike [ ] ;
339- let hasTrailingComma = false ;
340316
341317 if ( node . expression . arguments . length === 0 ) {
342318 literalProperties = [ property ] ;
343319 } else if ( ts . isObjectLiteralExpression ( node . expression . arguments [ 0 ] ) ) {
344- hasTrailingComma = node . expression . arguments [ 0 ] . properties . hasTrailingComma ;
345320 literalProperties = [ ...node . expression . arguments [ 0 ] . properties , property ] ;
346321 } else {
347322 // Unsupported case (e.g. `@Component(SOME_CONST)`). Return the original node.
@@ -352,9 +327,7 @@ function addPropertyToAngularDecorator(
352327 // the latter ends up duplicating the node's leading comment.
353328 return ts . factory . createDecorator ( ts . factory . createCallExpression (
354329 node . expression . expression , node . expression . typeArguments ,
355- [ ts . factory . createObjectLiteralExpression (
356- ts . factory . createNodeArray ( literalProperties , hasTrailingComma ) ,
357- literalProperties . length > 1 ) ] ) ) ;
330+ [ ts . factory . createObjectLiteralExpression ( literalProperties , literalProperties . length > 1 ) ] ) ) ;
358331}
359332
360333/** Checks if a node is a `PropertyAssignment` with a name. */
@@ -586,16 +559,12 @@ export function migrateTestDeclarations(
586559 }
587560
588561 if ( importsToAdd && importsToAdd . size > 0 ) {
589- const hasTrailingComma = importsToAdd . size > 2 &&
590- ! ! extractMetadataLiteral ( decorator . node ) ?. properties . hasTrailingComma ;
591- const importsArray = ts . factory . createNodeArray ( Array . from ( importsToAdd ) , hasTrailingComma ) ;
592-
593562 tracker . replaceNode (
594563 decorator . node ,
595564 addPropertyToAngularDecorator (
596565 newDecorator ,
597566 ts . factory . createPropertyAssignment (
598- 'imports' , ts . factory . createArrayLiteralExpression ( importsArray ) ) ) ) ;
567+ 'imports' , ts . factory . createArrayLiteralExpression ( Array . from ( importsToAdd ) ) ) ) ) ;
599568 } else {
600569 tracker . replaceNode ( decorator . node , newDecorator ) ;
601570 }
0 commit comments