From 2ca21998d3d830879e0dc8d5f3fffa4ee618841e Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sun, 2 Sep 2018 10:23:13 -0400 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- Makefile | 6 ++++-- test/fixtures/apilinks/class.js | 12 ++++++++++++ test/fixtures/apilinks/class.json | 5 +++++ tools/doc/apilinks.js | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/apilinks/class.js create mode 100644 test/fixtures/apilinks/class.json diff --git a/Makefile b/Makefile index 50c5e2ed906a3e..7f9a57804b7760 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/test/fixtures/apilinks/class.js b/test/fixtures/apilinks/class.js new file mode 100644 index 00000000000000..7db5c008e623f1 --- /dev/null +++ b/test/fixtures/apilinks/class.js @@ -0,0 +1,12 @@ +'use strict'; + +// An exported class using ES2015 class syntax. + +class Class { + constructor() {}; + method() {}; +} + +module.exports = { + Class +}; diff --git a/test/fixtures/apilinks/class.json b/test/fixtures/apilinks/class.json new file mode 100644 index 00000000000000..091a041510188e --- /dev/null +++ b/test/fixtures/apilinks/class.json @@ -0,0 +1,5 @@ +{ + "Class": "class.js#L5", + "new Class": "class.js#L6", + "class.method": "class.js#L7" +} diff --git a/tools/doc/apilinks.js b/tools/doc/apilinks.js index 35183912d31870..b0a221cf014179 100644 --- a/tools/doc/apilinks.js +++ b/tools/doc/apilinks.js @@ -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}`; + } + }); } });