Skip to content

Commit 30b430a

Browse files
committed
fix negative numeric literal bug
1 parent 70948df commit 30b430a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/transformers/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,14 @@ export function convertValueToExpression(value: unknown): ts.Expression {
168168
if (typeof value === "string") {
169169
return ts.factory.createStringLiteral(value);
170170
} else if (typeof value === "number") {
171-
return ts.factory.createNumericLiteral(value);
171+
if (value < 0) {
172+
return ts.factory.createPrefixUnaryExpression(
173+
ts.SyntaxKind.MinusToken,
174+
ts.factory.createNumericLiteral(Math.abs(value)),
175+
);
176+
} else {
177+
return ts.factory.createNumericLiteral(value);
178+
}
172179
} else if (typeof value === "boolean") {
173180
if (value) {
174181
return ts.factory.createTrue();

0 commit comments

Comments
 (0)