File tree 1 file changed +18
-6
lines changed
1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,24 @@ import type {
7
7
} from 'ts-morph' ;
8
8
import { SyntaxKind } from 'ts-morph' ;
9
9
10
- export const addPropertyObject = ( mainObject : ObjectLiteralExpression , propName : string , initializer = '{}' ) : ObjectLiteralExpression => mainObject
11
- . addPropertyAssignment ( {
12
- name : propName ,
13
- initializer,
14
- } )
15
- . getFirstDescendantByKindOrThrow ( SyntaxKind . ObjectLiteralExpression ) ;
10
+ export const addPropertyObject = ( mainObject : ObjectLiteralExpression , propName : string , initializer = '{}' ) : ObjectLiteralExpression => {
11
+ if ( propName === 'props' ) {
12
+ // put props as first property
13
+ return mainObject
14
+ . insertPropertyAssignment ( 0 , {
15
+ name : propName ,
16
+ initializer,
17
+ } )
18
+ . getFirstDescendantByKindOrThrow ( SyntaxKind . ObjectLiteralExpression ) ;
19
+ } else {
20
+ return mainObject
21
+ . addPropertyAssignment ( {
22
+ name : propName ,
23
+ initializer,
24
+ } )
25
+ . getFirstDescendantByKindOrThrow ( SyntaxKind . ObjectLiteralExpression ) ;
26
+ }
27
+ } ;
16
28
17
29
export const addPropertyArray = ( mainObject : ObjectLiteralExpression , propName : string , initializer = '[]' ) : ArrayLiteralExpression => mainObject
18
30
. addPropertyAssignment ( {
You can’t perform that action at this time.
0 commit comments