Skip to content

Commit 7c2fa2b

Browse files
committed
hack to put props first
1 parent b3608b7 commit 7c2fa2b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/migrator/utils.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@ import type {
77
} from 'ts-morph';
88
import { SyntaxKind } from 'ts-morph';
99

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+
};
1628

1729
export const addPropertyArray = (mainObject: ObjectLiteralExpression, propName: string, initializer = '[]'): ArrayLiteralExpression => mainObject
1830
.addPropertyAssignment({

0 commit comments

Comments
 (0)