@@ -33,6 +33,7 @@ import type {
3333 ParameterDeclaration ,
3434 PostfixUnaryExpression ,
3535 PostfixUnaryOperator ,
36+ PrefixUnaryOperator ,
3637 PrefixUnaryExpression ,
3738 PrivateIdentifier ,
3839 PropertyAccessExpression ,
@@ -92,6 +93,26 @@ export function createNumericLiteral(
9293 return core . ts . factory . createNumericLiteral ( value , numericLiteralFlags ) ;
9394}
9495
96+ export function createExpressionForNegativeOrPositiveNumber (
97+ value : number ,
98+ ) : Expression {
99+ if ( value < 0 ) {
100+ return createPrefixUnaryExpression (
101+ core . ts . SyntaxKind . MinusToken ,
102+ createNumericLiteral ( Math . abs ( value ) ) ,
103+ ) ;
104+ }
105+
106+ return createNumericLiteral ( value ) ;
107+ }
108+
109+ export function createPrefixUnaryExpression (
110+ unaryOperator : PrefixUnaryOperator ,
111+ operand : Expression ,
112+ ) : Expression {
113+ return core . ts . factory . createPrefixUnaryExpression ( unaryOperator , operand ) ;
114+ }
115+
95116export function createArrowFunction (
96117 block : ts . ConciseBody ,
97118 parameter : ReadonlyArray < ts . ParameterDeclaration > = [ ] ,
@@ -298,13 +319,13 @@ export function createLogicalNot(operand: Expression): PrefixUnaryExpression {
298319
299320export function createLiteral (
300321 type : LiteralType ,
301- ) : StringLiteral | NumericLiteral | BigIntLiteral {
322+ ) : StringLiteral | Expression | BigIntLiteral {
302323 if ( typeof type . value === 'string' ) {
303324 return createStringLiteral ( type . value ) ;
304325 }
305326
306327 if ( typeof type . value === 'number' ) {
307- return createNumericLiteral ( type . value ) ;
328+ return createExpressionForNegativeOrPositiveNumber ( type . value ) ;
308329 }
309330
310331 return core . ts . factory . createBigIntLiteral ( type . value ) ;
0 commit comments