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: https://github.com/nodejs/node/pull/22656
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
pull/22650/merge
Sam Ruby 2018-09-02 10:23:13 -04:00 committed by Daniel Bevenius
parent d4cdb2ce66
commit 441391b9eb
4 changed files with 40 additions and 2 deletions

View File

@ -653,10 +653,12 @@ out/apilinks.json: $(wildcard lib/*.js) tools/doc/apilinks.js
$(call available-node, $(gen-apilink))
out/doc/api/%.json out/doc/api/%.html: doc/api/%.md tools/doc/generate.js \
tools/doc/html.js tools/doc/json.js | out/apilinks.json
tools/doc/html.js tools/doc/json.js tools/doc/apilinks.js | \
out/apilinks.json
$(call available-node, $(gen-api))
out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js
out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js \
tools/doc/apilinks.js
$(call available-node, tools/doc/allhtml.js)
out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.js

12
test/fixtures/apilinks/class.js vendored 100644
View File

@ -0,0 +1,12 @@
'use strict';
// An exported class using ES2015 class syntax.
class Class {
constructor() {};
method() {};
}
module.exports = {
Class
};

View File

@ -0,0 +1,5 @@
{
"Class": "class.js#L5",
"new Class": "class.js#L6",
"class.method": "class.js#L7"
}

View File

@ -107,6 +107,7 @@ process.argv.slice(2).forEach((file) => {
// ClassName.foo = ...;
// ClassName.prototype.foo = ...;
// function Identifier(...) {...};
// class Foo {...}
//
const indirect = {};
@ -153,6 +154,24 @@ process.argv.slice(2).forEach((file) => {
if (basename.startsWith('_')) return;
definition[`${basename}.${name}`] =
`${link}#L${statement.loc.start.line}`;
} else if (statement.type === 'ClassDeclaration') {
if (!exported.constructors.includes(statement.id.name)) return;
definition[statement.id.name] = `${link}#L${statement.loc.start.line}`;
const name = statement.id.name.slice(0, 1).toLowerCase() +
statement.id.name.slice(1);
statement.body.body.forEach((defn) => {
if (defn.type !== 'MethodDefinition') return;
if (defn.kind === 'method') {
definition[`${name}.${defn.key.name}`] =
`${link}#L${defn.loc.start.line}`;
} else if (defn.kind === 'constructor') {
definition[`new ${statement.id.name}`] =
`${link}#L${defn.loc.start.line}`;
}
});
}
});