Skip to content

Commit 7f9051e

Browse files
committed
Stop triple-negating negative numeric literals
1 parent 78adb94 commit 7f9051e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/checker/nodebuilder.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,11 @@ func (b *NodeBuilder) typeToTypeNode(t *Type) *ast.TypeNode {
27692769
if t.flags&TypeFlagsNumberLiteral != 0 {
27702770
value := t.AsLiteralType().value.(jsnum.Number)
27712771
b.ctx.approximateLength += len(value.String())
2772-
return b.f.NewLiteralTypeNode(core.IfElse(value < 0, b.f.NewPrefixUnaryExpression(ast.KindMinusToken, b.f.NewNumericLiteral("-"+value.String())), b.f.NewNumericLiteral(value.String())))
2772+
if value < 0 {
2773+
return b.f.NewLiteralTypeNode(b.f.NewPrefixUnaryExpression(ast.KindMinusToken, b.f.NewNumericLiteral(value.String()[1:])))
2774+
} else {
2775+
return b.f.NewLiteralTypeNode(b.f.NewNumericLiteral(value.String()))
2776+
}
27732777
}
27742778
if t.flags&TypeFlagsBigIntLiteral != 0 {
27752779
b.ctx.approximateLength += len(pseudoBigIntToString(getBigIntLiteralValue(t))) + 1

0 commit comments

Comments
 (0)