diff --git a/Makefile b/Makefile index 8769b5b95c9f58..bb1f1ad6dd3e62 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}`; + } + }); } });