Skip to content

Commit 643530e

Browse files
committed
Move MODULE_QUALIFIED_NAME into constants, simplify slightly
Signed-off-by: Tim Perry <pimterry@gmail.com>
1 parent 2f77a39 commit 643530e

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

packages/core/src/generators/metadata/constants.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export const DOC_API_SLUGS_REPLACEMENTS = [
1515
// Matches Node.js deprecation headings such as "DEP0001: Description".
1616
export const DEPRECATION_HEADING_REGEX = /^(DEP\d+):/;
1717

18+
// A dotted identifier path, e.g. `vm.Module` or `os.constants.dlopen`. Names
19+
// that merely contain a dot (prose, `Object.<string, string>`, `1.5`) must not
20+
// be turned into a module link.
21+
export const MODULE_QUALIFIED_NAME = /^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)+$/;
22+
1823
// These are regular expressions used to determine if a given Markdown heading
1924
// is a specific type of API Doc entry (e.g., Event, Class, Method, etc)
2025
// and to extract the inner content of said Heading to be used as the API doc entry name

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { DOC_MAN_BASE_URL, DOC_API_HEADING_TYPES } from '../constants.mjs';
1+
import {
2+
DOC_MAN_BASE_URL,
3+
DOC_API_HEADING_TYPES,
4+
MODULE_QUALIFIED_NAME,
5+
} from '../constants.mjs';
26
import { slug } from './slugger.mjs';
37
import { transformNodesToString } from '../../../utils/unist.mjs';
48
import BUILTIN_TYPE_MAP from '../maps/builtin.json' with { type: 'json' };
@@ -48,11 +52,6 @@ export const lookupTypeName = (name, typeMap) => {
4852
return '';
4953
};
5054

51-
// A dotted identifier path, e.g. `vm.Module` or `os.constants.dlopen`. Names
52-
// that merely contain a dot (prose, `Object.<string, string>`) must not be
53-
// turned into a module link.
54-
const MODULE_QUALIFIED_NAME = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/;
55-
5655
/**
5756
* Resolves a type identifier to a documentation URL: map lookups first, then
5857
* the dotted-name heuristic for Node.js types like `vm.Module` (which links

0 commit comments

Comments
 (0)