-
Notifications
You must be signed in to change notification settings - Fork 21
fix(legacy-json): more identical output #526
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ export const createSectionBuilder = () => { | |
|
|
||
| meta.changes = changes; | ||
|
|
||
| if (n_api_version?.length) { | ||
| if (typeof n_api_version === 'number' || n_api_version?.length) { | ||
| meta.napiVersion = enforceArray(n_api_version); | ||
| } | ||
|
|
||
|
|
@@ -102,13 +102,17 @@ export const createSectionBuilder = () => { | |
| * @param {Array} nodes - The remaining AST nodes. | ||
| * @param {import('../types.d.ts').HierarchizedEntry} entry - The entry providing stability information. | ||
| */ | ||
| const parseStability = (section, nodes, { stability }) => { | ||
| const stabilityInfo = stability.children.map(node => node.data)?.[0]; | ||
| const parseStability = (section, nodes, { stability, content }) => { | ||
ovflowd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const stabilityNode = stability.children[0]; | ||
|
|
||
| if (stabilityInfo) { | ||
| section.stability = Number(stabilityInfo.index); | ||
| section.stabilityText = stabilityInfo.description; | ||
| nodes.shift(); // Remove stability node from processing | ||
| if (stabilityNode) { | ||
| section.stability = Number(stabilityNode.data.index); | ||
| section.stabilityText = stabilityNode.data.description; | ||
|
|
||
| const nodeToRemove = content.children.findIndex( | ||
|
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. This feels like an expensive search, we should have the node index.
Member
Author
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. We don't have it stored anywhere
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. I'm pretty sure we have the Node IDs. |
||
| ({ data }) => data === stabilityNode.data | ||
| ); | ||
| nodes.splice(nodeToRemove - 1, 1); | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
|
|
||
|
|
@@ -153,7 +157,10 @@ export const createSectionBuilder = () => { | |
| * @param {import('../types.d.ts').Section} parent - The parent section. | ||
| */ | ||
| const addToParent = (section, parent) => { | ||
| const key = SECTION_TYPE_PLURALS[section.type] || 'miscs'; | ||
| const key = | ||
| SECTION_TYPE_PLURALS[section.__promote ?? section.type] || 'miscs'; | ||
|
|
||
| delete section.__promote; | ||
|
|
||
| parent[key] ??= []; | ||
| parent[key].push(section); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ export const extractPattern = (text, pattern, key, current) => { | |
| export function parseListItem(child) { | ||
| const current = {}; | ||
|
|
||
| const subList = child.children.find(createQueries.UNIST.isTypedList); | ||
| const subList = child.children.find(createQueries.UNIST.isLooselyTypedList); | ||
|
|
||
| // Extract and clean raw text from the node, excluding nested lists | ||
| current.textRaw = transformTypeReferences( | ||
|
|
@@ -89,10 +89,13 @@ export function parseListItem(child) { | |
| * @param {import('@types/mdast').RootContent[]} nodes | ||
| */ | ||
| export function parseList(section, nodes) { | ||
| const list = nodes[0]?.type === 'list' ? nodes.shift() : null; | ||
| const listIdx = nodes.findIndex(createQueries.UNIST.isStronglyTypedList); | ||
| const list = nodes[listIdx]; | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const values = list ? list.children.map(parseListItem) : []; | ||
|
|
||
| let removeList = true; | ||
|
|
||
| // Update the section based on its type and parsed values | ||
| switch (section.type) { | ||
| case 'ctor': | ||
|
|
@@ -109,7 +112,12 @@ export function parseList(section, nodes) { | |
| case 'property': | ||
| // For properties, update type and other details if values exist | ||
| if (values.length) { | ||
| leftHandAssign(section, values[0]); | ||
| delete values[0].name; | ||
|
|
||
| Object.assign(section, values[0]); | ||
|
|
||
| // TODO(@avivkeller): There is probably a better way to do this. | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| section.__promote = 'property'; | ||
|
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. What is this?
Member
Author
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. When we When promoting properties to their parent (moving the
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. I'm unfamiliar with the
Member
Author
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. My brain xD, I just added it for this purpose. It's deleted during promotion
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. When "promotion" happens? Can we avoid using dark hidden properties? |
||
| } | ||
| break; | ||
|
|
||
|
|
@@ -119,9 +127,10 @@ export function parseList(section, nodes) { | |
| break; | ||
|
|
||
| default: | ||
| // If no specific handling, re-add the list for further processing | ||
| if (list) { | ||
| nodes.unshift(list); | ||
| } | ||
| removeList = false; | ||
| } | ||
|
|
||
| if (removeList && list) { | ||
| nodes.splice(listIdx, 1); | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { VALID_JAVASCRIPT_PROPERTY } from './constants.mjs'; | ||
| import createQueries from './index.mjs'; | ||
|
|
||
| /** | ||
| * @param {import('@types/mdast').List} list | ||
| * @returns {0 | 1 | 2} confidence | ||
| * | ||
| * 0: This is not a typed list | ||
| * 1: This is a loosely typed list | ||
| * 2: This is a strongly typed list | ||
| */ | ||
| export const isTypedList = list => { | ||
| if (!list || list.type !== 'list') { | ||
| return 0; | ||
| } | ||
|
|
||
| const firstNode = list.children?.[0]?.children?.[0]?.children[0]; | ||
|
|
||
| if (!firstNode) { | ||
| return 0; | ||
| } | ||
|
|
||
| const value = firstNode?.value?.trimStart(); | ||
|
|
||
| // Typed list starters (strong signal) | ||
| if (value && createQueries.QUERIES.typedListStarters.test(value)) { | ||
| return 2; | ||
| } | ||
|
|
||
| // Direct type link: <Type> | ||
| if ( | ||
| firstNode.type === 'link' && | ||
| firstNode.children?.[0]?.value?.startsWith('<') | ||
| ) { | ||
| return 2; | ||
| } | ||
|
|
||
| // inlineCode + space (weaker signal) | ||
| if ( | ||
| firstNode.type === 'inlineCode' && | ||
| value && | ||
| VALID_JAVASCRIPT_PROPERTY.test(value) | ||
| ) { | ||
| return 1; | ||
| } | ||
|
|
||
| return 0; | ||
| }; | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
make the regex a constant