Skip to content

Commit 264afe5

Browse files
committed
refactor: move DEPRECATION_HEADING_REGEX to legacy-html constants, drop apiStem check
1 parent 89b457d commit 264afe5

3 files changed

Lines changed: 11 additions & 17 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
// Matches deprecation headings (e.g., "DEP0001: some title") and captures
4+
// the deprecation code (e.g., "DEP0001") as the first group
5+
export const DEPRECATION_HEADING_REGEX = /^(DEP\d+):/;

src/generators/legacy-html/utils/__tests__/slugger.test.mjs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('createLegacySlugger', () => {
3838
});
3939

4040
describe('deprecation headings', () => {
41-
it('returns the DEP code for deprecation headings in the deprecations doc', () => {
41+
it('returns the DEP code for a deprecation heading', () => {
4242
const getLegacySlug = createLegacySlugger();
4343
assert.strictEqual(
4444
getLegacySlug(
@@ -59,13 +59,5 @@ describe('createLegacySlugger', () => {
5959
'DEP0190'
6060
);
6161
});
62-
63-
it('does not apply deprecation special-casing outside the deprecations doc', () => {
64-
const getLegacySlug = createLegacySlugger();
65-
assert.notStrictEqual(
66-
getLegacySlug('DEP0190: some heading', 'child_process'),
67-
'DEP0190'
68-
);
69-
});
7062
});
7163
});

src/generators/legacy-html/utils/slugger.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
'use strict';
22

3-
// Matches headings in the deprecations API doc (e.g., "DEP0001: some title")
4-
// and captures the deprecation code (e.g., "DEP0001") as the first group
5-
const DEPRECATION_HEADING_REGEX = /^(DEP\d+):/;
3+
import { DEPRECATION_HEADING_REGEX } from '../constants.mjs';
64

75
/**
86
* Creates a stateful slugger for legacy anchor links.
97
*
108
* Generates underscore-separated slugs in the form `{apiStem}_{text}`,
119
* appending `_{n}` for duplicates to preserve historical anchor compatibility.
1210
*
13-
* For the deprecations API doc, headings matching the `DEP####:` pattern use
14-
* just the deprecation code (e.g., `DEP0001`) as the anchor, matching the
15-
* behavior of the old tooling and preserving existing external links.
11+
* Headings matching the `DEP####:` pattern return just the deprecation code
12+
* (e.g., `DEP0001`) as the anchor, matching the behavior of the old tooling
13+
* and preserving existing external links.
1614
*
1715
* @returns {(text: string, apiStem: string) => string}
1816
*/
1917
export const createLegacySlugger =
2018
(counters = {}) =>
2119
(text, apiStem) => {
22-
const depMatch =
23-
apiStem === 'deprecations' && DEPRECATION_HEADING_REGEX.exec(text);
20+
const depMatch = DEPRECATION_HEADING_REGEX.exec(text);
2421

2522
if (depMatch) {
2623
return depMatch[1];

0 commit comments

Comments
 (0)