UNPKG

1.34 kBPlain TextView Raw
1import { SyntaxKind } from 'ts-morph';
2import { StringifyArrowFunction } from './arrow-function.util';
3
4export function StringifyObjectLiteralExpression(ole) {
5 let returnedString = '{';
6
7 if (ole.properties && ole.properties.length > 0) {
8 ole.properties.forEach((property, index) => {
9 if (property.name) {
10 returnedString += property.name.text + ': ';
11 }
12 if (property.initializer) {
13 if (property.initializer.kind === SyntaxKind.StringLiteral) {
14 returnedString += `'` + property.initializer.text + `'`;
15 } else if (property.initializer.kind === SyntaxKind.TrueKeyword) {
16 returnedString += `true`;
17 } else if (property.initializer.kind === SyntaxKind.FalseKeyword) {
18 returnedString += `false`;
19 } else if (property.initializer.kind === SyntaxKind.ArrowFunction) {
20 returnedString += StringifyArrowFunction(property.initializer);
21 } else {
22 returnedString += property.initializer.text;
23 }
24 }
25 if (index < ole.properties.length - 1) {
26 returnedString += ', ';
27 }
28 });
29 }
30
31 returnedString += '}';
32
33 return returnedString;
34}