Skip to content

Commit bdd610c

Browse files
committed
Add handling for bigint literals in default values
Ref: #2721
1 parent 1dbfe3a commit bdd610c

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Bug Fixes
88

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

1213
### Thanks!

src/lib/converter/convert-expression.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ export function convertExpression(expression: ts.Expression): string {
2424
case ts.SyntaxKind.FalseKeyword:
2525
case ts.SyntaxKind.NullKeyword:
2626
case ts.SyntaxKind.NumericLiteral:
27-
case ts.SyntaxKind.PrefixUnaryExpression:
27+
case ts.SyntaxKind.BigIntLiteral:
2828
case ts.SyntaxKind.Identifier:
2929
return expression.getText();
3030
}
3131

32+
if (ts.isPrefixUnaryExpression(expression)) {
33+
const inner = convertExpression(expression.operand);
34+
if (inner != "...") {
35+
return expression.getText();
36+
}
37+
}
38+
3239
if (
3340
ts.isArrayLiteralExpression(expression) &&
3441
expression.elements.length === 0

src/test/converter2/issues/gh2721.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const big = 123n;
2+
3+
export const neg = -123n;

src/test/issues.c2.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,4 +1780,10 @@ describe("Issue Tests", () => {
17801780
{ display: "resolver caption", target: "https://typedoc.org" },
17811781
]);
17821782
});
1783+
1784+
it("#2721 handles bigint literals in default values", () => {
1785+
const project = convert();
1786+
equal(query(project, "big").defaultValue, "123n");
1787+
equal(query(project, "neg").defaultValue, "-123n");
1788+
});
17831789
});

0 commit comments

Comments
 (0)