Skip to content

Commit

Permalink
tools: add [src] links to async_hooks.html
Browse files Browse the repository at this point in the history
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 <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
rubys authored and targos committed Sep 5, 2018
1 parent dd772c1 commit 2ca2199
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/apilinks/class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

// An exported class using ES2015 class syntax.

class Class {
constructor() {};
method() {};
}

module.exports = {
Class
};
5 changes: 5 additions & 0 deletions test/fixtures/apilinks/class.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Class": "class.js#L5",
"new Class": "class.js#L6",
"class.method": "class.js#L7"
}
19 changes: 19 additions & 0 deletions tools/doc/apilinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ process.argv.slice(2).forEach((file) => {
// ClassName.foo = ...;
// ClassName.prototype.foo = ...;
// function Identifier(...) {...};
// class Foo {...}
//
const indirect = {};

Expand Down Expand Up @@ -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}`;
}
});
}
});

Expand Down

0 comments on commit 2ca2199

Please sign in to comment.