Skip to content

Commit f600e95

Browse files
vsemozhetbytjasnell
authored andcommitted
doc, tools: make type parsing more strict
PR-URL: #19881 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent fde5a6b commit f600e95

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

doc/api/addons.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,10 @@ has ended but before the JavaScript VM is terminated and Node.js shuts down.
10961096

10971097
#### void AtExit(callback, args)
10981098

1099-
* `callback` {void (\*)(void\*)} A pointer to the function to call at exit.
1100-
* `args` {void\*} A pointer to pass to the callback at exit.
1099+
* `callback` <span class="type">&lt;void (\*)(void\*)&gt;</span>
1100+
A pointer to the function to call at exit.
1101+
* `args` <span class="type">&lt;void\*&gt;</span>
1102+
A pointer to pass to the callback at exit.
11011103

11021104
Registers exit hooks that run after the event loop has ended but before the VM
11031105
is killed.

doc/api/deprecations.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,12 +890,13 @@ should start using the `async_context` variant of `MakeCallback` or
890890
`CallbackScope`, or the high-level `AsyncResource` class.
891891
892892
<a id="DEP0098"></a>
893-
### DEP0098: AsyncHooks Embedder AsyncResource.emit{Before,After} APIs
893+
### DEP0098: AsyncHooks Embedder AsyncResource.emitBefore and AsyncResource.emitAfter APIs
894894
895895
Type: Runtime
896896
897-
The embedded API provided by AsyncHooks exposes emit{Before,After} methods
898-
which are very easy to use incorrectly which can lead to unrecoverable errors.
897+
The embedded API provided by AsyncHooks exposes `.emitBefore()` and
898+
`.emitAfter()` methods which are very easy to use incorrectly which can lead
899+
to unrecoverable errors.
899900
900901
Use [`asyncResource.runInAsyncScope()`][] API instead which provides a much
901902
safer, and more convenient, alternative. See

doc/api/http2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ authentication details.
25322532
added: v8.4.0
25332533
-->
25342534

2535-
* {http2.Http2Stream}
2535+
* {Http2Stream}
25362536

25372537
The [`Http2Stream`][] object backing the request.
25382538

@@ -2948,7 +2948,7 @@ an empty string.
29482948
added: v8.4.0
29492949
-->
29502950

2951-
* {http2.Http2Stream}
2951+
* {Http2Stream}
29522952

29532953
The [`Http2Stream`][] object backing the response.
29542954

doc/api/process.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ the child process.
8989

9090
The listener callback is invoked with the following arguments:
9191
* `message` {Object} a parsed JSON object or primitive value.
92-
* `sendHandle` {Handle object} a [`net.Socket`][] or [`net.Server`][] object, or
93-
undefined.
92+
* `sendHandle` {net.Server|net.Socket} a [`net.Server`][] or [`net.Socket`][]
93+
object, or undefined.
9494

9595
The message goes through serialization and parsing. The resulting message might
9696
not be the same as what is originally sent.
@@ -1531,7 +1531,7 @@ added: v0.5.9
15311531
-->
15321532

15331533
* `message` {Object}
1534-
* `sendHandle` {Handle object}
1534+
* `sendHandle` {net.Server|net.Socket}
15351535
* `options` {Object}
15361536
* `callback` {Function}
15371537
* Returns: {boolean}

tools/doc/type-parser.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
const jsDocPrefix = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/';
44

5-
const jsPrimitiveUrl = `${jsDocPrefix}Data_structures`;
5+
const jsDataStructuresUrl = `${jsDocPrefix}Data_structures`;
66
const jsPrimitives = {
7-
'boolean': 'Boolean',
8-
'integer': 'Number', // Not a primitive, used for clarification.
9-
'null': 'Null',
10-
'number': 'Number',
11-
'string': 'String',
12-
'symbol': 'Symbol',
13-
'undefined': 'Undefined'
7+
boolean: 'Boolean',
8+
integer: 'Number', // Not a primitive, used for clarification.
9+
null: 'Null',
10+
number: 'Number',
11+
string: 'String',
12+
symbol: 'Symbol',
13+
undefined: 'Undefined'
1414
};
1515

1616
const jsGlobalObjectsUrl = `${jsDocPrefix}Reference/Global_Objects/`;
@@ -25,13 +25,15 @@ const jsGlobalTypes = [
2525
];
2626

2727
const customTypesMap = {
28+
'any': `${jsDataStructuresUrl}#Data_types`,
29+
30+
'this': `${jsDocPrefix}Reference/Operators/this`,
31+
2832
'Iterable':
2933
`${jsDocPrefix}Reference/Iteration_protocols#The_iterable_protocol`,
3034
'Iterator':
3135
`${jsDocPrefix}Reference/Iteration_protocols#The_iterator_protocol`,
3236

33-
'this': `${jsDocPrefix}Reference/Operators/this`,
34-
3537
'AsyncHook': 'async_hooks.html#async_hooks_async_hooks_createhook_callbacks',
3638

3739
'Buffer': 'buffer.html#buffer_class_buffer',
@@ -63,12 +65,14 @@ const customTypesMap = {
6365
'http.Server': 'http.html#http_class_http_server',
6466
'http.ServerResponse': 'http.html#http_class_http_serverresponse',
6567

68+
'ClientHttp2Session': 'http2.html#http2_class_clienthttp2session',
6669
'ClientHttp2Stream': 'http2.html#http2_class_clienthttp2stream',
6770
'HTTP/2 Headers Object': 'http2.html#http2_headers_object',
6871
'HTTP/2 Settings Object': 'http2.html#http2_settings_object',
6972
'http2.Http2ServerRequest': 'http2.html#http2_class_http2_http2serverrequest',
7073
'http2.Http2ServerResponse':
7174
'http2.html#http2_class_http2_http2serverresponse',
75+
'Http2SecureServer': 'http2.html#http2_class_http2secureserver',
7276
'Http2Server': 'http2.html#http2_class_http2server',
7377
'Http2Session': 'http2.html#http2_class_http2session',
7478
'Http2Stream': 'http2.html#http2_class_http2stream',
@@ -83,6 +87,8 @@ const customTypesMap = {
8387
'os.constants.dlopen': 'os.html#os_dlopen_constants',
8488

8589
'PerformanceEntry': 'perf_hooks.html#perf_hooks_class_performanceentry',
90+
'PerformanceNodeTiming':
91+
'perf_hooks.html#perf_hooks_class_performancenodetiming_extends_performanceentry', // eslint-disable-line max-len
8692
'PerformanceObserver':
8793
'perf_hooks.html#perf_hooks_class_performanceobserver_callback',
8894
'PerformanceObserverEntryList':
@@ -123,10 +129,10 @@ function toLink(typeInput) {
123129
const typeTextFull = typeText;
124130
typeText = typeText.replace(arrayPart, '');
125131

126-
const primitive = jsPrimitives[typeText.toLowerCase()];
132+
const primitive = jsPrimitives[typeText];
127133

128134
if (primitive !== undefined) {
129-
typeUrl = `${jsPrimitiveUrl}#${primitive}_type`;
135+
typeUrl = `${jsDataStructuresUrl}#${primitive}_type`;
130136
} else if (jsGlobalTypes.includes(typeText)) {
131137
typeUrl = `${jsGlobalObjectsUrl}${typeText}`;
132138
} else if (customTypesMap[typeText]) {
@@ -137,7 +143,10 @@ function toLink(typeInput) {
137143
typeLinks.push(
138144
`<a href="${typeUrl}" class="type">&lt;${typeTextFull}&gt;</a>`);
139145
} else {
140-
typeLinks.push(`<span class="type">&lt;${typeTextFull}&gt;</span>`);
146+
throw new Error(
147+
`Unrecognized type: '${typeTextFull}'.\n` +
148+
"Please, edit the type or update the 'tools/doc/type-parser.js'."
149+
);
141150
}
142151
} else {
143152
throw new Error(`Empty type slot: ${typeInput}`);

0 commit comments

Comments
 (0)