Skip to content

Commit 055219c

Browse files
committed
fixup!
1 parent 140a438 commit 055219c

File tree

6 files changed

+25
-99
lines changed

6 files changed

+25
-99
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import parseSignature from './parseSignature.mjs';
22
import {
33
TYPED_LIST_STARTERS,
44
DEFAULT_EXPRESSION,
5-
LEADING_HYPHEN,
65
NAME_EXPRESSION,
76
TYPE_EXPRESSION,
87
} from '../../../utils/queries/regex.mjs';
@@ -72,7 +71,7 @@ export function parseListItem(child) {
7271
text = extractPattern(text, DEFAULT_EXPRESSION, 'default', current);
7372

7473
// Set the remaining text as the description, removing any leading hyphen
75-
current.desc = text.replace(LEADING_HYPHEN, '').trim() || undefined;
74+
current.desc = text.replace(/^-\s*/, '').trim() || undefined;
7675

7776
// Parse nested lists (options) recursively if present
7877
if (subList) {

src/parsers/markdown.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { coerce } from 'semver';
44

55
import { loadFromURL } from '../utils/parser.mjs';
66
import createQueries from '../utils/queries/index.mjs';
7-
import {
8-
LIST_ITEM,
9-
NODE_LTS_VERSION,
10-
NODE_VERSIONS,
11-
} from '../utils/queries/regex.mjs';
7+
import { MD_LINKED_LIST_ITEM, NODE_VERSIONS } from '../utils/queries/regex.mjs';
128
import { getRemark } from '../utils/remark.mjs';
139

10+
const LTS = 'long term support';
11+
1412
/**
1513
* Creates an API doc parser for a given Markdown API doc file
1614
*
@@ -79,7 +77,7 @@ export const parseChangelog = async path => {
7977

8078
return nodeMajors.map(match => ({
8179
version: coerce(match[1]),
82-
isLts: NODE_LTS_VERSION.test(match[2]),
80+
isLts: match[2].toLowerCase().includes(LTS),
8381
}));
8482
};
8583

@@ -92,7 +90,7 @@ export const parseChangelog = async path => {
9290
export const parseIndex = async path => {
9391
const index = await loadFromURL(path);
9492

95-
const items = Array.from(index.matchAll(LIST_ITEM));
93+
const items = Array.from(index.matchAll(MD_LINKED_LIST_ITEM));
9694

9795
return items.map(([, section, api]) => ({ section, api }));
9896
};

src/utils/queries/__tests__/regex.test.mjs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,6 @@ const testCases = {
187187
},
188188
],
189189

190-
NORMALIZE_TYPES: [
191-
{
192-
input: '{string}',
193-
matches: '{string}',
194-
},
195-
{
196-
input: 'Takes a {string} and returns an <Object>',
197-
matches: ['{string}', '<Object>'],
198-
},
199-
{
200-
input: '{Buffer|string}',
201-
matches: '{Buffer|string}',
202-
},
203-
],
204-
205190
LINKS_WITH_TYPES: [
206191
{
207192
input: 'Returns [`<Buffer>`](/api/buffer) or [`<string>`](/api/string)',
@@ -431,25 +416,6 @@ const testCases = {
431416
},
432417
],
433418

434-
LEADING_HYPHEN: [
435-
{
436-
input: '- item',
437-
matches: '- ',
438-
},
439-
{
440-
input: '- spaced item',
441-
matches: '- ',
442-
},
443-
{
444-
input: '* bullet point',
445-
matches: false,
446-
},
447-
{
448-
input: '- ',
449-
matches: '- ',
450-
},
451-
],
452-
453419
DEFAULT_EXPRESSION: [
454420
{
455421
input: '**Default:** `true`',
@@ -520,7 +486,7 @@ const testCases = {
520486
},
521487
],
522488

523-
LIST_ITEM: [
489+
MD_LINKED_LIST_ITEM: [
524490
{
525491
input: '* [Buffer](buffer.md)',
526492
matches: ['* [Buffer](buffer.md)'],
@@ -540,25 +506,6 @@ const testCases = {
540506
},
541507
],
542508

543-
NODE_LTS_VERSION: [
544-
{
545-
input: 'This is a Long Term Support version',
546-
matches: 'Long Term Support',
547-
},
548-
{
549-
input: 'long term support release',
550-
matches: 'long term support',
551-
},
552-
{
553-
input: 'LTS',
554-
matches: false,
555-
},
556-
{
557-
input: 'Long-term support',
558-
matches: false,
559-
},
560-
],
561-
562509
INTRODUCED_IN: [
563510
{
564511
input: '<!-- introduced_in=v10.0.0 -->',

src/utils/queries/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { getRemark } from '../remark.mjs';
1515
import { transformNodesToString } from '../unist.mjs';
1616
import {
1717
MARKDOWN_URL,
18-
NORMALIZE_TYPES,
1918
STABILITY_INDEX,
2019
STABILITY_INDEX_PREFIX,
20+
TYPE_EXPRESSION,
2121
UNIX_MANUAL_PAGE,
2222
} from './regex.mjs';
2323

@@ -181,7 +181,7 @@ const createQueries = () => {
181181
updateMarkdownLink,
182182
/** @param {Array<import('@types/mdast').Node>} args */
183183
updateTypeReference: (...args) =>
184-
updateReferences(NORMALIZE_TYPES, transformTypeToReferenceLink, ...args),
184+
updateReferences(TYPE_EXPRESSION, transformTypeToReferenceLink, ...args),
185185
/** @param {Array<import('@types/mdast').Node>} args */
186186
updateUnixManualReference: (...args) =>
187187
updateReferences(UNIX_MANUAL_PAGE, transformUnixManualToLink, ...args),

src/utils/queries/regex.mjs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export const EVENT_HEADING = /^Event: +`?['"]?([^'"]+)['"]?`?$/i;
119119
// TYPE AND REFERENCE PATTERNS
120120
// ============================================================================
121121

122+
const TYPE_SAFE = '[^<({})>]+';
123+
122124
/**
123125
* Matches API type references enclosed in curly braces or angle brackets.
124126
* Used to normalize type references across documentation.
@@ -127,7 +129,10 @@ export const EVENT_HEADING = /^Event: +`?['"]?([^'"]+)['"]?`?$/i;
127129
* - '{Buffer|string}'
128130
* - '<Object>'
129131
*/
130-
export const NORMALIZE_TYPES = /(\{|<)(?! )[^<({})>]+(?! )(\}|>)/g;
132+
export const TYPE_EXPRESSION = new RegExp(
133+
`(?:\\{|<)(${TYPE_SAFE})(?:\\}|>)`,
134+
'g'
135+
);
131136

132137
/**
133138
* Matches already-parsed API type references in Markdown link format.
@@ -136,7 +141,10 @@ export const NORMALIZE_TYPES = /(\{|<)(?! )[^<({})>]+(?! )(\}|>)/g;
136141
* - '[`<string>`](/api/string)'
137142
* - '[`<Buffer>`](/api/buffer)'
138143
*/
139-
export const LINKS_WITH_TYPES = /\[`<[^<({})>]+>`\]\((\S+)\)/g;
144+
export const LINKS_WITH_TYPES = new RegExp(
145+
`\\[\`<${TYPE_SAFE}>\`\\]\\((\\S+)\\)`,
146+
'g'
147+
);
140148

141149
/**
142150
* Matches headings that start typed lists in documentation.
@@ -149,15 +157,6 @@ export const LINKS_WITH_TYPES = /\[`<[^<({})>]+>`\]\((\S+)\)/g;
149157
*/
150158
export const TYPED_LIST_STARTERS = /^(Returns|Extends|Type):?\s*/;
151159

152-
/**
153-
* Matches type expressions in curly braces.
154-
* Examples:
155-
* - '{string}'
156-
* - '{Buffer|null}'
157-
* - '{Object}'
158-
*/
159-
export const TYPE_EXPRESSION = /^\{([^}]+)\}\s*/;
160-
161160
// ============================================================================
162161
// PARAMETER AND EXPRESSION PATTERNS
163162
// ============================================================================
@@ -188,14 +187,6 @@ export const PARAM_EXPRESSION = /\((.+)\);?$/;
188187
*/
189188
export const DEFAULT_EXPRESSION = /\s*\*\*Default:\*\*\s*([^]+)$/i;
190189

191-
/**
192-
* Matches leading hyphens in list items.
193-
* Examples:
194-
* - '- item'
195-
* - '- spaced item'
196-
*/
197-
export const LEADING_HYPHEN = /^-\s*/;
198-
199190
// ============================================================================
200191
// URL AND REFERENCE PATTERNS
201192
// ============================================================================
@@ -259,8 +250,7 @@ export const STABILITY_INDEX = new RegExp(
259250
* - '<!-- YAML foo bar -->'
260251
* - '<!-- description -->'
261252
*/
262-
export const YAML_INNER_CONTENT =
263-
/^<!--[ ]?(?:YAML([\s\S]*?)|([ \S]*?))?[ ]?-->/;
253+
export const YAML_INNER_CONTENT = /^<!-- *(?:YAML([\s\S]*?)|([ \S]*?))? *-->/;
264254

265255
/**
266256
* Matches code filename comments at the beginning of files.
@@ -276,14 +266,14 @@ export const EXTRACT_CODE_FILENAME_COMMENT = /^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/;
276266
* Examples:
277267
* - '<!-- introduced_in=v10.0.0 -->'
278268
*/
279-
export const INTRODUCED_IN = /<!--\s?introduced_in=.*-->/;
269+
export const INTRODUCED_IN = /<!-- *introduced_in=.*-->/;
280270

281271
/**
282272
* Matches HTML comments with LLM description metadata.
283273
* Examples:
284274
* - '<!-- llm_description=... -->'
285275
*/
286-
export const LLM_DESCRIPTION = /<!--\s?llm_description=.*-->/;
276+
export const LLM_DESCRIPTION = /<!-- *llm_description=.*-->/;
287277

288278
// ============================================================================
289279
// NODE.JS VERSION AND LIST PATTERNS
@@ -303,12 +293,4 @@ export const NODE_VERSIONS = /\* \[Node\.js ([0-9.]+)\]\S+ (.*)\r?\n/g;
303293
* - '* [Buffer](buffer.md)'
304294
* - '* [File System](fs.md)'
305295
*/
306-
export const LIST_ITEM = /\* \[(.*?)\]\((.*?)\.md\)/g;
307-
308-
/**
309-
* Matches Long Term Support indicators in version descriptions.
310-
* Examples:
311-
* - 'Long Term Support'
312-
* - 'long term support'
313-
*/
314-
export const NODE_LTS_VERSION = /Long Term Support/i;
296+
export const MD_LINKED_LIST_ITEM = /\* \[(.*?)\]\((.*?)\.md\)/g;

src/utils/queries/unist.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
LINKS_WITH_TYPES,
33
MARKDOWN_URL,
4-
NORMALIZE_TYPES,
4+
NAME_EXPRESSION,
55
STABILITY_INDEX,
66
TYPED_LIST_STARTERS,
77
UNIX_MANUAL_PAGE,
@@ -29,7 +29,7 @@ export const isYamlNode = ({ type, value }) =>
2929
* @returns {boolean}
3030
*/
3131
export const isTextWithType = ({ type, value }) =>
32-
type === 'text' && NORMALIZE_TYPES.test(value);
32+
type === 'text' && NAME_EXPRESSION.test(value);
3333

3434
/**
3535
* @param {import('@types/mdast').Text} text

0 commit comments

Comments
 (0)