Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct negative numeric literal nodes via createPrefixUnaryExpression + createNumericLiteral #1480

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading