Skip to content

Commit 106dd0b

Browse files
committed
fix(metadata): link class types whose name starts with an acronym
Class names like TLSSocket and FSWatcher were not detected as classes, so their links dropped the class- prefix and pointed at anchors that do not exist. Signed-off-by: Nikhil Kumar Rajak <ryzrr.official@gmail.com>
1 parent 91c9fc6 commit 106dd0b

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@doc-kit/core': patch
3+
---
4+
5+
fix(metadata): link class types whose name starts with an acronym

packages/core/src/generators/metadata/utils/__tests__/transformers.test.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ describe('resolveTypeReference', () => {
4747
strictEqual(resolveTypeReference('vm.Module'), 'vm.html#class-vmmodule');
4848
});
4949

50+
it('uses the class prefix for names starting with an acronym', () => {
51+
strictEqual(
52+
resolveTypeReference('tls.TLSSocket'),
53+
'tls.html#class-tlstlssocket'
54+
);
55+
});
56+
5057
it('does not use the class prefix for non-class members', () => {
5158
strictEqual(resolveTypeReference('vm.constants'), 'vm.html#vmconstants');
59+
strictEqual(resolveTypeReference('os.EOL'), 'os.html#oseol');
5260
});
5361

5462
it('prefers the map over the dotted heuristic', () => {

packages/core/src/generators/metadata/utils/transformers.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const resolveTypeReference = (name, typeMap) => {
7272
// Transform Node.js types like 'vm.Something'.
7373
if (MODULE_QUALIFIED_NAME.test(name)) {
7474
const [mod, ...pieces] = name.split('.');
75-
const isClass = pieces.at(-1).match(/^[A-Z][a-z]/);
75+
const isClass = pieces.at(-1).match(/^[A-Z](?=.*[a-z])/);
7676

7777
return `${mod}.html#${isClass ? 'class-' : ''}${slug(name)}`;
7878
}

0 commit comments

Comments
 (0)