Skip to content

Commit

Permalink
fix(codegen): create negative numbers with createPrefixUnaryExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
tevariou committed Apr 18, 2024
1 parent 774d9de commit 84bd801
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/codegen/src/tscodegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export function createLiteral(v: string | boolean | number) {
case "boolean":
return v ? factory.createTrue() : factory.createFalse();
case "number":
return factory.createNumericLiteral(String(v));
return String(v).charAt(0) === "-" ?
factory.createPrefixUnaryExpression(
ts.SyntaxKind.MinusToken,
factory.createNumericLiteral(String(-v))
) : factory.createNumericLiteral(String(v))
}
}

Expand Down

0 comments on commit 84bd801

Please sign in to comment.