-
Notifications
You must be signed in to change notification settings - Fork 26
fix: render constructors as new ClassName(params) format
#11
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e72176d
fix: render constructors as \`new ClassName(params)\` format (closes #2)
davanesh e2b9d89
refactor: move changes to helpers/index and partials/index
davanesh b587f4c
Merge branch 'main' into fix/constructor-rendering
davanesh 8e0768f
refactor: extract constructor title into buildConstructorTitle helper
davanesh 362bbf9
Merge branch 'main' into fix/constructor-rendering
davanesh 7e24ed9
refactor: replace buildConstructorTitle with generic signatureTitle h…
davanesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,11 +36,7 @@ export default (ctx) => ({ | |
| ? model.comment | ||
| : model.comment || model.parent?.comment; | ||
|
|
||
| const stability = ctx.helpers.stabilityBlockquote(comment); | ||
|
|
||
| return [ | ||
| stability, | ||
| stability && "", | ||
| model.typeParameters?.length && | ||
| ctx.partials.typeParametersList(model.typeParameters, { | ||
| headingLevel: options.headingLevel, | ||
|
|
@@ -66,31 +62,95 @@ export default (ctx) => ({ | |
| }, | ||
|
|
||
| memberTitle(model) { | ||
| const params = model.signatures?.[0]?.parameters ?? []; | ||
| if (model.kind === ReflectionKind.Constructor) { | ||
| const className = model.parent?.name ?? model.name; | ||
| return ctx.helpers.signatureTitle(`new ${className}`, params); | ||
| } | ||
| const prefix = getMemberPrefix(model); | ||
| const params = model.signatures?.[0]?.parameters; | ||
| if (!params.length) return `${prefix}\`${model.name}\``; | ||
| return `${prefix}${ctx.helpers.signatureTitle(model.name, params)}`; | ||
| }, | ||
|
|
||
| if (!params) { | ||
| return `${prefix}\`${model.name}\``; | ||
| memberContainer: (model, options) => { | ||
| const md = []; | ||
| if (!ctx.router.hasOwnDocument(model)) { | ||
| md.push( | ||
| "#".repeat(options.headingLevel) + " " + | ||
| ctx.partials.memberTitle(model) | ||
| ); | ||
| } | ||
| md.push(ctx.partials.member(model, { | ||
| headingLevel: options.headingLevel + 1, | ||
| nested: options.nested, | ||
| })); | ||
| return md.filter(Boolean).join("\n\n"); | ||
| }, | ||
|
|
||
| const paramsString = params | ||
| .map((param, index) => { | ||
| const paramName = param.name; | ||
| if (param.flags?.isOptional) { | ||
| // For optional params, wrap comma + name in brackets (except for first param) | ||
| return index === 0 ? `[${paramName}]` : `[, ${paramName}]`; | ||
| } else { | ||
| // For required params, add comma separator (except for first param) | ||
| return index === 0 ? paramName : `, ${paramName}`; | ||
| } | ||
| constructor: (model, options) => { | ||
| return model.signatures?.map(signature => { | ||
| const params = signature.parameters ?? []; | ||
| return params.length ? ctx.helpers.typedList(params) : ""; | ||
| }).filter(Boolean).join("\n\n") ?? ""; | ||
| }, | ||
|
|
||
| members: (model, options) => { | ||
| const items = model.filter( | ||
| (item) => !ctx.router.hasOwnDocument(item) | ||
| ); | ||
| return items | ||
| .map(item => | ||
| ctx.partials.memberContainer(item, { | ||
| headingLevel: options.headingLevel, | ||
| groupTitle: options.groupTitle, | ||
| }) | ||
| ) | ||
| .filter(Boolean) | ||
| .join("\n\n"); | ||
| }, | ||
|
|
||
| groups: (model, options) => { | ||
| return (model.groups ?? []) | ||
| .flatMap(group => { | ||
| const isPropertiesGroup = group.children?.every( | ||
| child => child.kind === ReflectionKind.Property | ||
| ); | ||
| if (isPropertiesGroup) return []; | ||
| const children = group.children?.filter( | ||
| child => child.isDeclaration() | ||
| ) ?? []; | ||
| if (!children.length) return []; | ||
| return [ | ||
| ctx.partials.members(children, { | ||
| headingLevel: options.headingLevel, | ||
| groupTitle: group.title, | ||
| }) | ||
| ]; | ||
| }) | ||
| .join(""); | ||
| .filter(Boolean) | ||
| .join("\n\n"); | ||
| }, | ||
|
|
||
| body: (model, options) => { | ||
| if (model.groups?.length) { | ||
| return ctx.partials.groups(model, { | ||
| headingLevel: options.headingLevel, | ||
| kind: model.kind, | ||
| }); | ||
| } | ||
| return ""; | ||
| }, | ||
|
|
||
| return `${prefix}\`${model.name}(${paramsString})\``; | ||
| declarationTitle: (model) => { | ||
| return ctx.helpers.typedListItem({ | ||
| name: model.name, | ||
| type: model.type, | ||
| comment: model.comment, | ||
| }); | ||
| }, | ||
|
|
||
|
Comment on lines
+75
to
+151
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated |
||
| parametersList: ctx.helpers.typedList, | ||
| typedParametersList: ctx.helpers.typedList, | ||
| typeDeclarationList: ctx.helpers.typedList, | ||
| propertiesTable: ctx.helpers.typedList, | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated removal