Skip to content

Commit 2ca2199

Browse files
rubystargos
authored andcommitted
tools: add [src] links to async_hooks.html
handle ES2015 Class, contructor, and instance methods unrelated: update Makefile so that generated HTML is out of date whenever tools/doc/apilinks.js is updated. PR-URL: #22656 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent dd772c1 commit 2ca2199

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,12 @@ out/apilinks.json: $(wildcard lib/*.js) tools/doc/apilinks.js
653653
$(call available-node, $(gen-apilink))
654654

655655
out/doc/api/%.json out/doc/api/%.html: doc/api/%.md tools/doc/generate.js \
656-
tools/doc/html.js tools/doc/json.js | out/apilinks.json
656+
tools/doc/html.js tools/doc/json.js tools/doc/apilinks.js | \
657+
out/apilinks.json
657658
$(call available-node, $(gen-api))
658659

659-
out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js
660+
out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js \
661+
tools/doc/apilinks.js
660662
$(call available-node, tools/doc/allhtml.js)
661663

662664
out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.js

test/fixtures/apilinks/class.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
// An exported class using ES2015 class syntax.
4+
5+
class Class {
6+
constructor() {};
7+
method() {};
8+
}
9+
10+
module.exports = {
11+
Class
12+
};

test/fixtures/apilinks/class.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Class": "class.js#L5",
3+
"new Class": "class.js#L6",
4+
"class.method": "class.js#L7"
5+
}

tools/doc/apilinks.js

+19
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ process.argv.slice(2).forEach((file) => {
107107
// ClassName.foo = ...;
108108
// ClassName.prototype.foo = ...;
109109
// function Identifier(...) {...};
110+
// class Foo {...}
110111
//
111112
const indirect = {};
112113

@@ -153,6 +154,24 @@ process.argv.slice(2).forEach((file) => {
153154
if (basename.startsWith('_')) return;
154155
definition[`${basename}.${name}`] =
155156
`${link}#L${statement.loc.start.line}`;
157+
158+
} else if (statement.type === 'ClassDeclaration') {
159+
if (!exported.constructors.includes(statement.id.name)) return;
160+
definition[statement.id.name] = `${link}#L${statement.loc.start.line}`;
161+
162+
const name = statement.id.name.slice(0, 1).toLowerCase() +
163+
statement.id.name.slice(1);
164+
165+
statement.body.body.forEach((defn) => {
166+
if (defn.type !== 'MethodDefinition') return;
167+
if (defn.kind === 'method') {
168+
definition[`${name}.${defn.key.name}`] =
169+
`${link}#L${defn.loc.start.line}`;
170+
} else if (defn.kind === 'constructor') {
171+
definition[`new ${statement.id.name}`] =
172+
`${link}#L${defn.loc.start.line}`;
173+
}
174+
});
156175
}
157176
});
158177

0 commit comments

Comments
 (0)