Skip to content

Commit

Permalink
Add handling for bigint literals in default values
Browse files Browse the repository at this point in the history
Ref: #2721
  • Loading branch information
Gerrit0 committed Oct 3, 2024
1 parent 1dbfe3a commit bdd610c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug Fixes

- Correctly handle external link resolver link text when referencing an external symbol, #2700.
- Big integer literals are now supported as default values, #2721.
- Corrected handling of `@link` tags present in comments at the start of source files.

### Thanks!
Expand Down
9 changes: 8 additions & 1 deletion src/lib/converter/convert-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ export function convertExpression(expression: ts.Expression): string {
case ts.SyntaxKind.FalseKeyword:
case ts.SyntaxKind.NullKeyword:
case ts.SyntaxKind.NumericLiteral:
case ts.SyntaxKind.PrefixUnaryExpression:
case ts.SyntaxKind.BigIntLiteral:
case ts.SyntaxKind.Identifier:
return expression.getText();
}

if (ts.isPrefixUnaryExpression(expression)) {
const inner = convertExpression(expression.operand);
if (inner != "...") {
return expression.getText();
}
}

if (
ts.isArrayLiteralExpression(expression) &&
expression.elements.length === 0
Expand Down
3 changes: 3 additions & 0 deletions src/test/converter2/issues/gh2721.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const big = 123n;

export const neg = -123n;
6 changes: 6 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1780,4 +1780,10 @@ describe("Issue Tests", () => {
{ display: "resolver caption", target: "https://typedoc.org" },
]);
});

it("#2721 handles bigint literals in default values", () => {
const project = convert();
equal(query(project, "big").defaultValue, "123n");
equal(query(project, "neg").defaultValue, "-123n");
});
});

0 comments on commit bdd610c

Please sign in to comment.