fix: render constructors as new ClassName(params) format#11
fix: render constructors as new ClassName(params) format#11davanesh wants to merge 6 commits intowebpack:mainfrom
new ClassName(params) format#11Conversation
|
@davanesh Can you rebase? |
6c923d3 to
e72176d
Compare
|
Done! Rebased and force pushed. |
avivkeller
left a comment
There was a problem hiding this comment.
I have a few changes that I think will be nice, but this is some great great work and I can't wait to see more!
plugins/theme/index.mjs
Outdated
| //DEBUG | ||
| // console.log("KIND:", model.kind, "NAME:", model.name, "CONSTRUCTOR KIND:", ReflectionKind.Constructor); |
There was a problem hiding this comment.
Let's remove this debug comment
plugins/theme/index.mjs
Outdated
| declarationTitle: (model) => { | ||
| return this.helpers.typedListItem({ | ||
| name: model.name, | ||
| type: model.type, | ||
| comment: model.comment, | ||
| }); | ||
| }, |
There was a problem hiding this comment.
| declarationTitle: (model) => { | |
| return this.helpers.typedListItem({ | |
| name: model.name, | |
| type: model.type, | |
| comment: model.comment, | |
| }); | |
| }, | |
| declarationTitle: this.helpers.typedListItem, |
plugins/theme/index.mjs
Outdated
| memberContainer: (model, options) => { | ||
| const md = []; | ||
| if (!this.router.hasOwnDocument(model) && | ||
| ![ReflectionKind.Constructor].includes(model.kind)) { | ||
| md.push( | ||
| "#".repeat(options.headingLevel) + " " + | ||
| this.partials.memberTitle(model) | ||
| ); | ||
| } | ||
| md.push(this.partials.member(model, { | ||
| headingLevel: options.headingLevel + 1, // ← methods get #### | ||
| nested: options.nested, | ||
| })); | ||
| return md.filter(Boolean).join("\n\n"); | ||
| }, |
There was a problem hiding this comment.
I think overriding the constructor in memberTitle is better than outright skipping it? WDYT?
There was a problem hiding this comment.
Oh that's a much cleaner approach! On it 🔥
e72176d to
2f0b9c9
Compare
|
(Rebased for CI/CD). Note that you'll need to run |
2f0b9c9 to
e2b9d89
Compare
alexander-akait
left a comment
There was a problem hiding this comment.
@avivkeller We currently only support @deprecated, if we want to add them we need to add them to our schema generator, @experimental is not a problem, @beta and @legacy - not sure we need it, because @deprecated already handle such things
|
On it! |
|
Done, reverted blockquote changes and moved constructor logic into a buildConstructorTitle helper 😊 |
|
Addressed all feedback, reverted blockquote changes and extracted constructor logic into |
plugins/theme/helpers/index.mjs
Outdated
| buildConstructorTitle(model) { | ||
| const params = model.signatures?.[0]?.parameters ?? []; | ||
| const className = model.parent?.name ?? model.name; | ||
| const allOptional = | ||
| params.length > 0 && params.every((p) => p.flags?.isOptional); | ||
| const paramStr = allOptional | ||
| ? `[${params.map((p) => p.name).join(", ")}]` | ||
| : params.map((p) => (p.flags?.isOptional ? `[${p.name}]` : p.name)).join(", "); | ||
| return `\`new ${className}(${paramStr})\``; | ||
| }, |
There was a problem hiding this comment.
Let's redo this as a signatureTitle helper that returns ${className}(${paramsStr}), and re use for constructors, and all members
There was a problem hiding this comment.
Replaced with a generic signatureTitle(name, params) helper reused for both constructors and all members
| return entries.map(ctx.helpers.typedListItem).join("\n"); | ||
| }, | ||
|
|
||
| stabilityBlockquote(comment) { |
| 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"); | ||
| }, | ||
|
|
||
| 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, | ||
| }) | ||
| ]; | ||
| }) | ||
| .filter(Boolean) | ||
| .join("\n\n"); | ||
| }, | ||
|
|
||
| body: (model, options) => { | ||
| if (model.groups?.length) { | ||
| return ctx.partials.groups(model, { | ||
| headingLevel: options.headingLevel, | ||
| kind: model.kind, | ||
| }); | ||
| } | ||
| return ""; | ||
| }, | ||
|
|
||
| declarationTitle: (model) => { | ||
| return ctx.helpers.typedListItem({ | ||
| name: model.name, | ||
| type: model.type, | ||
| comment: model.comment, | ||
| }); | ||
| }, | ||
|
|
…elper, restore templates
Closes #2
What this does
Overrides the
constructorpartial to render constructors in the Node.js doc format instead of the default TypeDoc output.Before:
Constructors
Constructor
options{ContainerPluginOptions}After:
new ContainerPlugin(options)options{ContainerPluginOptions}Changes
constructorpartial to format asnew ClassName(params)new Stats([options])### Constructors / Methods / Propertiesgroup headings***horizontal rule separators between membersmemberContainerto correctly pass heading levels down the chain