Skip to content

Commit bb39c7c

Browse files
ryanking13hoodmane
andauthored
FIX Fix a bug that comment of the arrow function in the interface is not rendered (#284)
* Fix bug that comment of arrow function in the interface is not preserved * Update sphinx_js/js/convertTopLevel.ts Co-authored-by: Hood Chatham <[email protected]> * changelog --------- Co-authored-by: Hood Chatham <[email protected]>
1 parent e8e3261 commit bb39c7c

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### 5.0.1: (September 17th, 2025)
4+
- Fixed a bug that comment of the arrow function in the interface is not rendered correctly.
5+
(pyodide/sphinx-js#284)
6+
37
### 5.0.0: (July 2nd, 2025)
48

59
- Dropped support for Python 3.9 (pyodide/sphinx-js-fork#7)

sphinx_js/js/convertTopLevel.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,15 @@ export class Converter {
537537
// Render {f: () => void} like {f(): void}
538538
// TODO: unclear if this is the right behavior. Maybe there should be a
539539
// way to pick?
540-
return [this.functionToIR(prop.type.declaration), []];
540+
const functionIR = this.functionToIR(prop.type.declaration);
541+
542+
// Preserve the property's own documentation if it exists
543+
functionIR.description = renderCommentSummary(prop.comment);
544+
545+
// Preserve the optional flag from the original property
546+
functionIR.is_optional = prop.flags.isOptional;
547+
548+
return [functionIR, []];
541549
}
542550
let type: Type;
543551
if (prop.comment?.modifierTags.has("@hidetype")) {

tests/test_build_ts/source/class.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ export class ExportedClass {
4343
export class ConstructorlessClass {}
4444

4545
export interface OptionalThings {
46+
/**
47+
* foop should preserve this documentation
48+
*/
4649
foop?(): void;
50+
/**
51+
* boop should preserve this documentation
52+
*/
4753
boop?: boolean;
54+
/**
55+
* noop should preserve this documentation
56+
*/
57+
noop?: () => void;
4858
}
4959

5060
/**

tests/test_build_ts/test_build_ts.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ def test_optional_members(self):
9898
"\n"
9999
" type: boolean\n"
100100
"\n"
101-
" OptionalThings.foop?()\n",
101+
" boop should preserve this documentation\n"
102+
"\n"
103+
" OptionalThings.foop?()\n"
104+
"\n"
105+
" foop should preserve this documentation\n"
106+
"\n"
107+
" OptionalThings.noop?()\n"
108+
"\n"
109+
" noop should preserve this documentation\n",
102110
)
103111

104112
def test_deprecated(self):

0 commit comments

Comments
 (0)