Skip to content

Commit

Permalink
clean: a bit of refacto for readibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren committed Oct 28, 2024
1 parent 59e1d0b commit ff71eb9
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/core/jsDocTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,19 +514,37 @@ function createObjectLiteralExpression(
): ts.ObjectLiteralExpression {
const properties = Object.entries(obj).map(([key, value]) => {
const propertyName = f.createStringLiteral(key);
let initializer: ts.Expression;
if (typeof value === "string") initializer = f.createStringLiteral(value);
else if (typeof value === "number")
initializer = f.createNumericLiteral(value);
else if (typeof value === "boolean")
initializer = value ? f.createTrue() : f.createFalse();
else if (value === null) initializer = f.createNull();
else if (Array.isArray(value))
initializer = createArrayLiteralExpression(value);
else if (typeof value === "object")
initializer = createObjectLiteralExpression(value);
else initializer = f.createStringLiteral(String(value));
return f.createPropertyAssignment(propertyName, initializer);
if (typeof value === "string")
return f.createPropertyAssignment(
propertyName,
f.createStringLiteral(value)
);
if (typeof value === "number")
return f.createPropertyAssignment(
propertyName,
f.createNumericLiteral(value)
);
if (typeof value === "boolean")
return f.createPropertyAssignment(
propertyName,
value ? f.createTrue() : f.createFalse()
);
if (value === null)
return f.createPropertyAssignment(propertyName, f.createNull());
if (Array.isArray(value))
return f.createPropertyAssignment(
propertyName,
createArrayLiteralExpression(value)
);
if (typeof value === "object")
return f.createPropertyAssignment(
propertyName,
createObjectLiteralExpression(value)
);
return f.createPropertyAssignment(
propertyName,
f.createStringLiteral(String(value))
);
});
return f.createObjectLiteralExpression(properties);
}

0 comments on commit ff71eb9

Please sign in to comment.