Skip to content

Commit 1ad05ee

Browse files
committed
fixup!
1 parent 06049e8 commit 1ad05ee

File tree

9 files changed

+78
-50
lines changed

9 files changed

+78
-50
lines changed

src/generators/jsx-ast/utils/buildContent.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export const processEntry = (entry, remark) => {
229229
// Transform typed lists into property tables
230230
visit(
231231
content,
232-
createQueries.UNIST.isTypedList,
232+
createQueries.UNIST.isStronglyTypedList,
233233
(node, idx, parent) => (parent.children[idx] = createPropertyTable(node))
234234
);
235235

src/generators/jsx-ast/utils/buildPropertyTable.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const parseListIntoProperties = node => {
124124

125125
// Clean up leading whitespace in remaining description
126126
if (children[0]?.type === 'text') {
127-
children[0].value = children[0].value.trimStart();
127+
children[0].value = children[0].value.replace(/^[\s:]+/, '');
128128
}
129129

130130
properties.push({
@@ -133,7 +133,7 @@ export const parseListIntoProperties = node => {
133133
// The remaining children are the description
134134
desc: children,
135135
// Is there a list within this list?
136-
sublist: sublists.find(createQueries.UNIST.isTypedList),
136+
sublist: sublists.find(createQueries.UNIST.isLooselyTypedList),
137137
});
138138
}
139139

src/generators/jsx-ast/utils/buildSignature.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const getFullName = ({ name, text }, fallback = name) => {
8989
*/
9090
export default ({ children }, { data }, idx) => {
9191
// Try to locate the parameter list immediately following the heading
92-
const listIdx = children.findIndex(createQueries.UNIST.isTypedList);
92+
const listIdx = children.findIndex(createQueries.UNIST.isStronglyTypedList);
9393

9494
// Parse parameters from the list, if found
9595
const params =

src/generators/legacy-json/utils/buildSection.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const createSectionBuilder = () => {
5353

5454
meta.changes = changes;
5555

56-
if (n_api_version?.length) {
56+
if (typeof n_api_version === 'number' || n_api_version?.length) {
5757
meta.napiVersion = enforceArray(n_api_version);
5858
}
5959

src/generators/legacy-json/utils/parseList.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const extractPattern = (text, pattern, key, current) => {
4747
export function parseListItem(child) {
4848
const current = {};
4949

50-
const subList = child.children.find(createQueries.UNIST.isTypedList);
50+
const subList = child.children.find(createQueries.UNIST.isLooselyTypedList);
5151

5252
// Extract and clean raw text from the node, excluding nested lists
5353
current.textRaw = transformTypeReferences(
@@ -89,7 +89,7 @@ export function parseListItem(child) {
8989
* @param {import('@types/mdast').RootContent[]} nodes
9090
*/
9191
export function parseList(section, nodes) {
92-
const listIdx = nodes.findIndex(createQueries.UNIST.isTypedList);
92+
const listIdx = nodes.findIndex(createQueries.UNIST.isStronglyTypedList);
9393
const list = nodes[listIdx];
9494

9595
const values = list ? list.children.map(parseListItem) : [];

src/utils/parser/constants.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const DOC_API_HEADING_TYPES = [
5050
'i'
5151
),
5252
},
53-
{ type: 'event', regex: /^Event: +`'?([^']+)'`$/i },
53+
{ type: 'event', regex: /^Event: +`'?([^`]*?)'?`$/i },
5454
{
5555
type: 'class',
5656
regex: new RegExp(

src/utils/queries/constants.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
export const DOC_API_STABILITY_SECTION_REF_URL =
55
'documentation.html#stability-index';
66

7-
export const VALID_JAVASCRIPT_PROPERTY = /^[.a-z0-9$_]+$/i;
7+
export const VALID_JAVASCRIPT_PROPERTY = /^[.a-z0-9$_'-]+$/i;

src/utils/queries/index.mjs

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import { u as createTree } from 'unist-builder';
44
import { SKIP } from 'unist-util-visit';
55

6-
import {
7-
DOC_API_STABILITY_SECTION_REF_URL,
8-
VALID_JAVASCRIPT_PROPERTY,
9-
} from './constants.mjs';
6+
import { DOC_API_STABILITY_SECTION_REF_URL } from './constants.mjs';
107
import {
118
extractYamlContent,
129
parseHeadingIntoMetadata,
@@ -16,6 +13,7 @@ import {
1613
} from '../parser/index.mjs';
1714
import { getRemark } from '../remark.mjs';
1815
import { transformNodesToString } from '../unist.mjs';
16+
import { isTypedList } from './utils.mjs';
1917

2018
/**
2119
* Creates an instance of the Query Manager, which allows to do multiple sort
@@ -272,46 +270,28 @@ createQueries.UNIST = {
272270
* @param {import('@types/mdast').List} list
273271
* @returns {boolean}
274272
*/
275-
isTypedList: list => {
276-
// Exit early if not a list node
277-
if (list.type !== 'list') {
278-
return false;
279-
}
280-
281-
// Get the content nodes of the first list item's paragraph
282-
const [node, ...contentNodes] =
283-
list?.children?.[0]?.children?.[0]?.children ?? [];
284-
285-
// Exit if no node
286-
if (!node) {
287-
return false;
288-
}
289-
290-
const possibleProperty = node?.value?.trimStart();
291-
292-
// Check for other starters
293-
if (possibleProperty?.match(createQueries.QUERIES.typedListStarters)) {
294-
return true;
295-
}
273+
isLooselyTypedList: list => Boolean(isTypedList(list)),
296274

297-
// Check for direct type link pattern (starts with '<')
298-
if (node.type === 'link' && node.children?.[0]?.value?.[0] === '<') {
299-
return true;
300-
}
301-
302-
// Check for inline code + space + type link pattern
303-
if (
304-
node.type === 'inlineCode' &&
305-
possibleProperty?.match(VALID_JAVASCRIPT_PROPERTY) &&
306-
contentNodes[0]?.value?.trim() === '' &&
307-
contentNodes[1]?.type === 'link' &&
308-
contentNodes[1]?.children?.[0]?.value?.[0] === '<'
309-
) {
310-
return true;
275+
/**
276+
* @param {import('@types/mdast').List} list
277+
* @returns {boolean}
278+
*/
279+
isStronglyTypedList: list => {
280+
const confidence = isTypedList(list);
281+
282+
if (confidence === 1) {
283+
// This is a loosely typed list, but we can still check if it is strongly typed.
284+
const [, secondNode, thirdNode] =
285+
list.children?.[0]?.children?.[0]?.children ?? [];
286+
287+
return (
288+
secondNode?.value?.trim() === '' &&
289+
thirdNode?.type === 'link' &&
290+
thirdNode?.children?.[0]?.value?.[0] === '<'
291+
);
311292
}
312293

313-
// Not a typed list
314-
return false;
294+
return Boolean(confidence);
315295
},
316296
};
317297

src/utils/queries/utils.mjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { VALID_JAVASCRIPT_PROPERTY } from './constants.mjs';
2+
import createQueries from './index.mjs';
3+
4+
/**
5+
* @param {import('@types/mdast').List} list
6+
* @returns {0 | 1 | 2} confidence
7+
*
8+
* 0: This is not a typed list
9+
* 1: This is a loosely typed list
10+
* 2: This is a strongly typed list
11+
*/
12+
export const isTypedList = list => {
13+
if (!list || list.type !== 'list') {
14+
return 0;
15+
}
16+
17+
const firstNode = list.children?.[0]?.children?.[0]?.children[0];
18+
19+
if (!firstNode) {
20+
return 0;
21+
}
22+
23+
const value = firstNode?.value?.trimStart();
24+
25+
// Typed list starters (strong signal)
26+
if (value && createQueries.QUERIES.typedListStarters.test(value)) {
27+
return 2;
28+
}
29+
30+
// Direct type link: <Type>
31+
if (
32+
firstNode.type === 'link' &&
33+
firstNode.children?.[0]?.value?.startsWith('<')
34+
) {
35+
return 2;
36+
}
37+
38+
// inlineCode + space (weaker signal)
39+
if (
40+
firstNode.type === 'inlineCode' &&
41+
value &&
42+
VALID_JAVASCRIPT_PROPERTY.test(value)
43+
) {
44+
return 1;
45+
}
46+
47+
return 0;
48+
};

0 commit comments

Comments
 (0)