-
Notifications
You must be signed in to change notification settings - Fork 18
feat: json, json-all generators #287
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #287 +/- ##
==========================================
+ Coverage 74.60% 82.42% +7.81%
==========================================
Files 112 140 +28
Lines 10700 15034 +4334
Branches 722 1027 +305
==========================================
+ Hits 7983 12392 +4409
+ Misses 2714 2637 -77
- Partials 3 5 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@flakey5 is this still in progress? Need any help? |
|
Still in progress just haven't been committing, I do wanna get this ready for review within the next coming weeks though |
a4cd425 to
d711fee
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
2d10df1 to
e4dbbe4
Compare
6bfc555 to
1bcf93d
Compare
|
Bulk of this is done, with only two main things left:
I'm leaving this as a draft until those are done, but the rest is ready for review |
avivkeller
left a comment
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.
the rest is ready for review
I've left a first round of reviews. Thank you so much for this effort!
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.
Do we need a seperate generator error?
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.
It exists just to give the general spot in the ast that an error happens to assist with debugging, can definitely be removed if unwanted
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.
@nodejs/web-infra im +1 on removing, WDYT?
src/generators/json/constants.mjs
Outdated
| 'use strict'; | ||
|
|
||
| // Grabs the default value if present | ||
| export const DEFAULT_EXPRESSION = /^(D|d)efault(s|):$/; |
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.
Let's re-use the DEFAULT_EXPRESSION constant from the legacy generator
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.
We can't since this is used for matching against the text in the ast which doesn't have the asterisks, while the one in the legacy generator is going off of the stringified version in textRaw which does
ee1684d to
b37daee
Compare
Closes #214 Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
b37daee to
8ebb3d6
Compare
|
Marking ready for review, should be all there minus #287 (comment) |
| input.forEach(section => { | ||
| const copiedSection = {}; | ||
|
|
||
| Object.keys(section).forEach(key => { | ||
| if (!propertiesToIgnore.includes(key)) { | ||
| copiedSection[key] = section[key]; | ||
| } | ||
| }); |
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.
| input.forEach(section => { | |
| const copiedSection = {}; | |
| Object.keys(section).forEach(key => { | |
| if (!propertiesToIgnore.includes(key)) { | |
| copiedSection[key] = section[key]; | |
| } | |
| }); | |
| input.forEach({ ignoreThisKey, ...section } => { |
WDYT?
| switch (section.type) { | ||
| case 'module': | ||
| generatedValue.modules.push(copiedSection); | ||
| break; | ||
| case 'text': | ||
| generatedValue.text.push(copiedSection); | ||
| break; | ||
| default: | ||
| throw new TypeError(`unsupported root section type ${section.type}`); | ||
| } |
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.
| switch (section.type) { | |
| case 'module': | |
| generatedValue.modules.push(copiedSection); | |
| break; | |
| case 'text': | |
| generatedValue.text.push(copiedSection); | |
| break; | |
| default: | |
| throw new TypeError(`unsupported root section type ${section.type}`); | |
| } | |
| generatedValue[type === 'module' ? 'modules' : type].push(copiedSection) |
nit
src/generators/json-all/index.mjs
Outdated
| */ | ||
| async generate(input, { version, output }) { | ||
| const generatedValue = { | ||
| $schema: `${BASE_URL}/docs/${DOC_NODE_VERSION}/api/node-doc-all-schema.jsonc`, |
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.
Can we make a SCHEMA_URL constant?
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.
Not really since it intakes the version given by the generator options, same for the rest of the schema url instances
| * @param {string} version | ||
| */ | ||
| export function generateJsonSchema(version) { | ||
| const jsonSchemaUrl = `${BASE_URL}/docs/${version}/api/node-doc-schema.json`; |
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.
Ditto on the constant
| // Returns: {string} | ||
| // Returns {string} | ||
| // Returns: {string} bla bla bla | ||
| export const METHOD_RETURN_TYPE_EXTRACTOR = /^(?:R|r)eturns(:?) {(.*)}( .*)?$/; |
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.
I'd rather do a case insensitive search
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.
This isn't just checking if it starts with Returns: though, it's extracting the type information and possible description from it as well
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.
Can we change it to /^Returns(:?) {(.*)}( .*)?$/i?
| } | ||
|
|
||
| return { | ||
| $schema: `${BASE_URL}docs/${version}/api/node-doc-schema.json`, |
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.
Ditto on the constant
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.
@nodejs/web-infra im +1 on removing, WDYT?
Co-authored-by: Aviv Keller <me@aviv.sh>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
| ); | ||
| } | ||
|
|
||
| if (rest[0]?.type === 'link') { |
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.
Can we have these specific extractors on dedicated function for ... extracting these? Also are the types here only link and "else"?
|
|
||
| parameter['@name'] = 'value'; | ||
|
|
||
| const { types, endingIndex } = parseTypeList(parameterAst.children); |
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.
Feels like we could dedup this
|
|
||
| break; | ||
| } | ||
| case 'text': { |
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.
Looks like more duped code
| // it | ||
| const { types, endingIndex } = parseTypeList(paragraph.children, 2); | ||
|
|
||
| if (types.length === 0) { |
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.
Looks like more duped code
| } | ||
| case 'link': { | ||
| const { types, endingIndex } = parseTypeList(paragraph.children, 1); | ||
| if (types.length === 0) { |
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.
Looks like more duped code
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.
Can we mhave this file output be in a different folder? Like a generated folder?
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.
Shouldn't this be automatically generated?
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.
The schema should be maintained by hand. It doesn't need to be in a standalone json file though, we could have it be a function like with the json-all's schema. Only reason it is standalone currently is to make it so we can have better intellisense/autocomplete in editors when modifying the schema
ovflowd
left a comment
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.
Mostly LGTM, I think that we can dedup lots of the code, extract many of the utility functions within parsing things (such as event, property) into dedicated tiny functions that do one thing and then unit test them.
Makes the parent functions simpler, easier to read the code and understand what pieces does what, reusability and unit testing.
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
|
@flakey5 Is there a reason why many properties start with |
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.
Pull request overview
This PR introduces new JSON generators (json and json-all) for the Node.js documentation toolkit, providing machine-readable JSON representations of API documentation.
Key Changes:
- New
jsongenerator that outputs individual JSON files for each API module with comprehensive type information, method signatures, properties, and events - New
json-allgenerator that combines all JSON outputs into a single file - Comprehensive JSON schema definition with TypeScript type generation support
Reviewed changes
Copilot reviewed 39 out of 44 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
src/generators/json/index.mjs |
Main JSON generator implementation |
src/generators/json-all/index.mjs |
Aggregator generator for combined JSON output |
src/generators/json/schema.jsonc |
JSON schema definition for documentation structure |
src/generators/json/utils/sections/*.mjs |
Section parsers for modules, classes, methods, properties, and events |
src/generators/json/utils/parseTypeList.mjs |
Type list parsing utility |
src/generators/json/utils/createParameterGroupings.mjs |
Method signature parameter grouping logic |
src/utils/buildHierarchy.mjs |
Shared utility for building hierarchical entry structures |
src/utils/assertAstType.mjs |
AST node type assertion utilities |
src/utils/generator-error.mjs |
Custom error class for generator errors |
src/utils/unist.mjs |
Enhanced node transformation with support for break, delete, and link nodes |
scripts/generate-json-types.mjs |
Script to generate TypeScript definitions from JSON schema |
package.json |
New dependencies for JSON parsing and schema validation |
.github/workflows/generate.yml |
CI workflow integration for JSON generator |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Parse the JSON schema into an object | ||
| const schema = await parse(schemaString); | ||
|
|
||
| // Compile the the JSON schema into TypeScript typedefs |
Copilot
AI
Dec 3, 2025
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.
The comment "the the" contains a duplicate word. It should be "the JSON schema".
| // Compile the the JSON schema into TypeScript typedefs | |
| // Compile the JSON schema into TypeScript typedefs |
| // TODO: if the type of the parameter is `object`, sometimes it's followed | ||
| // by a `list` node that contains the properties expected on that object. | ||
| // I'd really like those to be included in the json output, but for now | ||
| // they're not going to be for simplicitly sakes (they still should be in |
Copilot
AI
Dec 3, 2025
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.
The comment "for simplicitly sakes" contains a spelling error. It should be "for simplicity's sake" or "for simplicity sake".
|
|
||
| /** | ||
| * Given a list of parameter names in the order that they should appear and | ||
| * a map of paramter names to their type info, let's create the signature |
Copilot
AI
Dec 3, 2025
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.
The comment contains a grammatical error. "a map of paramter names" should be "a map of parameter names".
| assert.equal(base.changes, undefined); | ||
| assert.equal(base['@since'], undefined); | ||
| assert.equal(base.napiVersion, undefined); | ||
| assert.equal(base.removedIn, undefined); | ||
| assert.equal(base['@deprecated'], undefined); |
Copilot
AI
Dec 3, 2025
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.
[nitpick] The assertion uses assert.equal() which performs loose equality. For more explicit comparison, consider using assert.strictEqual() instead.
| assert.equal(base.changes, undefined); | |
| assert.equal(base['@since'], undefined); | |
| assert.equal(base.napiVersion, undefined); | |
| assert.equal(base.removedIn, undefined); | |
| assert.equal(base['@deprecated'], undefined); | |
| assert.strictEqual(base.changes, undefined); | |
| assert.strictEqual(base['@since'], undefined); | |
| assert.strictEqual(base.napiVersion, undefined); | |
| assert.strictEqual(base.removedIn, undefined); | |
| assert.strictEqual(base['@deprecated'], undefined); |
| "additionalProperties": false | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| "Class": { | ||
| "allOf": [ | ||
| { "$ref": "#/definitions/SectionBase" }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["class"], | ||
| }, | ||
| "@constructor": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/MethodSignature" }, | ||
| }, | ||
| "methods": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/Method" }, | ||
| }, | ||
| "staticMethods": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/Method" }, | ||
| }, | ||
| "properties": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/Property" }, | ||
| }, | ||
| "events": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/Event" }, | ||
| }, | ||
| }, | ||
| "required": [ | ||
| "type", | ||
| ], | ||
| "additionalProperties": false | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| "Method": { | ||
| "description": "A JavaScript function.", | ||
| "allOf": [ | ||
| { "$ref": "#/definitions/SectionBase" }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["method"], | ||
| }, | ||
| "signatures": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/MethodSignature" }, | ||
| }, | ||
| }, | ||
| "required": ["type", "signatures"], | ||
| "additionalProperties": false | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| "MethodSignature": { | ||
| "type": "object", | ||
| "properties": { | ||
| "parameters": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/MethodParameter" }, | ||
| }, | ||
| "@returns": { | ||
| "$ref": "#/definitions/MethodReturnType", | ||
| }, | ||
| }, | ||
| "required": ["parameters", "@returns"], | ||
| "additionalProperties": false | ||
| }, | ||
|
|
||
| "MethodParameter": { | ||
| "type": "object", | ||
| "properties": { | ||
| "@name": { | ||
| "type": "string", | ||
| "description": "Name of the parameter.", | ||
| }, | ||
| "@type": { | ||
| "description": "Type of the parameter", | ||
| "oneOf": [ | ||
| { | ||
| "type": "string", | ||
| "examples": ["string"], | ||
| }, | ||
| { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string", | ||
| }, | ||
| "minItems": 1, | ||
| }, | ||
| ], | ||
| }, | ||
| "description": { | ||
| "type": "string", | ||
| }, | ||
| "@default": { | ||
| "type": "string", | ||
| "description": "The parameter's default value", | ||
| "examples": ["foo"], | ||
| }, | ||
| }, | ||
| "required": ["@name", "@type"], | ||
| "additionalProperties": false | ||
| }, | ||
|
|
||
| "MethodReturnType": { | ||
| "type": "object", | ||
| "description": "A method signature's return type.", | ||
| "properties": { | ||
| "description": { | ||
| "type": "string", | ||
| }, | ||
| "@type": { | ||
| "description": "The method signature's return type.", | ||
| "oneOf": [ | ||
| { | ||
| "type": "string", | ||
| "examples": ["string"], | ||
| }, | ||
| { | ||
| "type": "array", | ||
| "items": { "type": "string" }, | ||
| "examples": [["string", "Promise<string>"]], | ||
| "minItems": 1, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| "required": ["@type"], | ||
| "additionalProperties": false | ||
| }, | ||
|
|
||
| "Global": { | ||
| "type": "object", | ||
| "properties": {}, | ||
| "required": [], | ||
| }, | ||
|
|
||
| "Property": { | ||
| "description": "A property on a JavaScript object or class.", | ||
| "allOf": [ | ||
| { "$ref": "#/definitions/SectionBase" }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["property"], | ||
| }, | ||
| "@type": { | ||
| "description": "JavaScript type of the property.", | ||
| "oneOf": [ | ||
| { | ||
| "type": "string", | ||
| "examples": ["string"], | ||
| }, | ||
| { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string", | ||
| }, | ||
| "minItems": 1, | ||
| }, | ||
| ], | ||
| }, | ||
| "mutable": { | ||
| "type": "boolean", | ||
| "description": "Is this property modifiable by user code?", | ||
| "default": false, | ||
| }, | ||
| }, | ||
| "required": ["type"], | ||
| "additionalProperties": false | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| "Event": { | ||
| "description": "An event that can be emitted by the parent object or class.", | ||
| "allOf": [ | ||
| { "$ref": "#/definitions/SectionBase" }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "type": "string", | ||
| "enum": ["event"], | ||
| }, | ||
| "parameters": { | ||
| "type": "array", | ||
| "items": { "$ref": "#/definitions/MethodParameter" }, | ||
| }, | ||
| }, | ||
| "required": ["type", "parameters"], | ||
| "additionalProperties": false |
Copilot
AI
Dec 3, 2025
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.
[nitpick] Inconsistent indentation: the additionalProperties: false statements on lines 156, 195, 217, 234, 270, 297, 340, 362, and 399 are not indented consistently with the surrounding JSON structure. They should be indented at the same level as the other properties in their respective objects.
| "$ref": "#/definitions/MethodReturnType", | ||
| }, | ||
| }, | ||
| "required": ["parameters", "@returns"], |
Copilot
AI
Dec 3, 2025
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.
[nitpick] The MethodSignature.parameters property is defined as required (line 233), but in several places in the code, signatures are created with an empty parameters array instead of omitting it when there are no parameters. Consider making this property optional or consistently handling empty arrays.
| "required": ["parameters", "@returns"], | |
| "required": ["@returns"], |
| export function createSection(head, entries, version) { | ||
| const entryHierarchy = buildHierarchy(entries); | ||
|
|
||
| if (entryHierarchy.length != 1) { |
Copilot
AI
Dec 3, 2025
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.
[nitpick] Inconsistent comparison operator: The code uses != (loose inequality) instead of !== (strict inequality). For consistency with modern JavaScript best practices, use strict equality operators.
| */ | ||
| let section; | ||
| try { | ||
| section = createSectionBase(entry, parent?.type); |
Copilot
AI
Dec 3, 2025
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.
Superfluous argument passed to function createSectionBase.
| * - Run `scripts/generate-json-types.mjs` and ensure there aren't type errors | ||
| */ | ||
|
|
||
| "$schema": "http://json-schema.org/draft-07/schema#", |
Copilot
AI
Dec 3, 2025
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.
The $schema reference uses an http URL, which enables man-in-the-middle tampering when tools fetch the JSON Schema for validation. An attacker intercepting the connection could serve a modified schema to alter validation behavior or inject malicious constraints. Fix by switching to https:
"$schema": "https://json-schema.org/draft-07/schema#"| "$schema": "http://json-schema.org/draft-07/schema#", | |
| "$schema": "https://json-schema.org/draft-07/schema#", |
avivkeller
left a comment
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.
More comments :-)
|
|
||
| // Not code, let's stringify it and add it to the description. | ||
| section.description ??= ''; | ||
| section.description += `${transformNodeToString(node)}${node.type === 'paragraph' ? '\n' : ' '}`; |
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.
Is this added newline needed?
|
|
||
| if (section.description) { | ||
| section.description = section.description.trim(); | ||
| } |
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.
| } | |
| section.description &&= section.description.trim(); |
| } else { | ||
| section['@example'] = node.value; | ||
| } | ||
|
|
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.
| const examples = [...enforceArray(section['@example']), node.value]; | |
| section['@example'] = examples.length === 1 ? examples[0] : examples; |
| value = Number(value); | ||
|
|
||
| if (isNaN(value)) { | ||
| throw new GeneratorError(`Stability index ${stability.index} NaN`); | ||
| } | ||
| } | ||
|
|
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.
| value = Number(value); | |
| if (isNaN(value)) { | |
| throw new GeneratorError(`Stability index ${stability.index} NaN`); | |
| } | |
| } | |
| const value = parseFloat(stability.index); |
Do we really need to throw an error if it's NaN? I'd rather produce JSON with the NaN (even though this should never happen) than error the entire generator?
| section.stability = { | ||
| value, | ||
| text: stability.description, | ||
| }; | ||
| } |
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.
Can we just do section.stability = stability? Like keep the { index, description } format?
| if (entryHierarchy.length != 1) { | ||
| throw new TypeError(`${head.api_doc_source} has multiple root elements`); | ||
| } | ||
|
|
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.
- I don't think there will ever be more than one root, right?
- Let's just ignore the extra data, not error on it
| if (section.type !== 'module' && section.type !== 'text') { | ||
| throw new GeneratorError( | ||
| `expected root section to be a module or text, got ${section.type}`, | ||
| { entry: head } | ||
| ); | ||
| } | ||
|
|
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.
I think these if checks are too strict, IMO. I feel like there's nothing wrong with it having the wrong type (like, the generator should still work)
| // Returns: {string} | ||
| // Returns {string} | ||
| // Returns: {string} bla bla bla | ||
| export const METHOD_RETURN_TYPE_EXTRACTOR = /^(?:R|r)eturns(:?) {(.*)}( .*)?$/; |
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.
Can we change it to /^Returns(:?) {(.*)}( .*)?$/i?
| * @returns {Promise<object>} | ||
| */ | ||
| async generate(input, { version, output }) { | ||
| const versionString = `v${version.toString()}`; |
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.
nit
| const versionString = `v${version.toString()}`; | |
| const versionString = `v${version.raw}`; |
| export function findParentSection(section, type) { | ||
| type = enforceArray(type); | ||
|
|
||
| let parent = section.parent; | ||
|
|
||
| while (parent) { | ||
| if (type.includes(parent.type)) { | ||
| return parent; | ||
| } | ||
|
|
||
| parent = parent.parent; | ||
| } | ||
|
|
||
| return undefined; | ||
| } |
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.
| export function findParentSection(section, type) { | |
| type = enforceArray(type); | |
| let parent = section.parent; | |
| while (parent) { | |
| if (type.includes(parent.type)) { | |
| return parent; | |
| } | |
| parent = parent.parent; | |
| } | |
| return undefined; | |
| } | |
| export function findParentSection({ parent }, type) { | |
| type = enforceArray(type); | |
| while (parent) { | |
| if (type.includes(parent.type)) { | |
| return parent; | |
| } | |
| parent = parent.parent; | |
| } | |
| return undefined; | |
| } |
Closes #214
TODO: