Skip to content

Commit

Permalink
Construct negative numeric literal nodes via `createPrefixUnaryExpres…
Browse files Browse the repository at this point in the history
…sion` + `createNumericLiteral`

The following commit started to disallow construction of negative numeric literals solely with `createNumericLiteral` and now needs to be constructed via `createPrefixUnaryExpression` + `createNumericLiteral`

microsoft/TypeScript@f0c3c3f

PiperOrigin-RevId: 571839417
  • Loading branch information
tsjs-language-eng authored and copybara-github committed Oct 9, 2023
1 parent 1b5e61d commit 1448d70
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/enum_transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ export function enumTransformer(typeChecker: ts.TypeChecker):
const enumConstValue = typeChecker.getConstantValue(member);
if (typeof enumConstValue === 'number') {
enumIndex = enumConstValue + 1;
enumValue = ts.factory.createNumericLiteral(enumConstValue);
if (enumConstValue < 0) {
enumValue = ts.factory.createPrefixUnaryExpression(
ts.SyntaxKind.MinusToken,
ts.factory.createNumericLiteral(-enumConstValue));
} else {
enumValue = ts.factory.createNumericLiteral(enumConstValue);
}
} else if (typeof enumConstValue === 'string') {
// tsickle does not care about string enum values. However TypeScript expects compile
// time constant enum values to be replaced with their constant expression, and e.g.
Expand Down

0 comments on commit 1448d70

Please sign in to comment.