Skip to content

Commit

Permalink
fix: #1289
Browse files Browse the repository at this point in the history
Add minus(-) and plus(+) operator detection @ getInitializerValue when
metadataGenerating.
  • Loading branch information
jackey8616 committed Oct 6, 2022
1 parent c92ee38 commit 2d9d1e9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/cli/src/metadataGeneration/initializer-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ export const getInitializerValue = (initializer?: ts.Expression | ts.ImportSpeci
return true;
case ts.SyntaxKind.FalseKeyword:
return false;
case ts.SyntaxKind.PrefixUnaryExpression: {
const prefixUnary = initializer as ts.PrefixUnaryExpression;
switch (prefixUnary.operator) {
case ts.SyntaxKind.PlusToken:
return Number((prefixUnary.operand as ts.NumericLiteral).text);
case ts.SyntaxKind.MinusToken:
return Number(`-${(prefixUnary.operand as ts.NumericLiteral).text}`);
default:
throw new Error(`Unsupport prefix operator token: ${prefixUnary.operator}`);
}
}
case ts.SyntaxKind.NumberKeyword:
case ts.SyntaxKind.FirstLiteralToken:
return Number((initializer as ts.NumericLiteral).text);
Expand Down

0 comments on commit 2d9d1e9

Please sign in to comment.