Skip to content

Commit

Permalink
fix(codegen): handle negative numbers correctly
Browse files Browse the repository at this point in the history
create negative numbers with createNumericLiteral in combination with createPrefixUnaryExpression (#625)

fix #626
  • Loading branch information
tevariou committed Apr 23, 2024
1 parent 810c3fa commit 4bd4d63
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/codegen/src/tscodegen.ts
Expand Up @@ -40,7 +40,12 @@ 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 4bd4d63

Please sign in to comment.