summaryrefslogtreecommitdiff
path: root/tools/doc
diff options
context:
space:
mode:
authorSam Ruby <rubys@intertwingly.net>2018-09-05 09:44:42 -0400
committerSam Ruby <rubys@intertwingly.net>2018-09-08 13:42:41 -0400
commit8737683ba09252d6fe6b29df7ffcc818cd5cfb2b (patch)
treeec567969e2fadb4cccb91b86b1fce535fe66588a /tools/doc
parent9f06a057959edc258fd0014223d9fb0ec917525f (diff)
downloadandroid-node-v8-8737683ba09252d6fe6b29df7ffcc818cd5cfb2b.tar.gz
android-node-v8-8737683ba09252d6fe6b29df7ffcc818cd5cfb2b.tar.bz2
android-node-v8-8737683ba09252d6fe6b29df7ffcc818cd5cfb2b.zip
tools: add [src] links to child-process.html
handle exports. as an alternative to module.exports PR-URL: https://github.com/nodejs/node/pull/22706 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'tools/doc')
-rw-r--r--tools/doc/apilinks.js66
1 files changed, 41 insertions, 25 deletions
diff --git a/tools/doc/apilinks.js b/tools/doc/apilinks.js
index b0a221cf01..0a33125a17 100644
--- a/tools/doc/apilinks.js
+++ b/tools/doc/apilinks.js
@@ -61,6 +61,7 @@ process.argv.slice(2).forEach((file) => {
// Scan for exports.
const exported = { constructors: [], identifiers: [] };
+ const indirect = {};
program.forEach((statement) => {
if (statement.type === 'ExpressionStatement') {
const expr = statement.expression;
@@ -69,35 +70,52 @@ process.argv.slice(2).forEach((file) => {
let lhs = expr.left;
if (expr.left.object.type === 'MemberExpression') lhs = lhs.object;
if (lhs.type !== 'MemberExpression') return;
- if (lhs.object.name !== 'module') return;
- if (lhs.property.name !== 'exports') return;
-
- let rhs = expr.right;
- while (rhs.type === 'AssignmentExpression') rhs = rhs.right;
-
- if (rhs.type === 'NewExpression') {
- exported.constructors.push(rhs.callee.name);
- } else if (rhs.type === 'ObjectExpression') {
- rhs.properties.forEach((property) => {
- if (property.value.type === 'Identifier') {
- exported.identifiers.push(property.value.name);
- if (/^[A-Z]/.test(property.value.name[0])) {
- exported.constructors.push(property.value.name);
- }
+ if (lhs.object.name === 'exports') {
+ const name = lhs.property.name;
+ if (expr.right.type === 'FunctionExpression') {
+ definition[`${basename}.${name}`] =
+ `${link}#L${statement.loc.start.line}`;
+ } else if (expr.right.type === 'Identifier') {
+ if (expr.right.name === name) {
+ indirect[name] = `${basename}.${name}`;
}
- });
- } else if (rhs.type === 'Identifier') {
- exported.identifiers.push(rhs.name);
+ } else {
+ exported.identifiers.push(name);
+ }
+ } else if (lhs.object.name === 'module') {
+ if (lhs.property.name !== 'exports') return;
+
+ let rhs = expr.right;
+ while (rhs.type === 'AssignmentExpression') rhs = rhs.right;
+
+ if (rhs.type === 'NewExpression') {
+ exported.constructors.push(rhs.callee.name);
+ } else if (rhs.type === 'ObjectExpression') {
+ rhs.properties.forEach((property) => {
+ if (property.value.type === 'Identifier') {
+ exported.identifiers.push(property.value.name);
+ if (/^[A-Z]/.test(property.value.name[0])) {
+ exported.constructors.push(property.value.name);
+ }
+ }
+ });
+ } else if (rhs.type === 'Identifier') {
+ exported.identifiers.push(rhs.name);
+ }
}
} else if (statement.type === 'VariableDeclaration') {
for (const decl of statement.declarations) {
let init = decl.init;
while (init && init.type === 'AssignmentExpression') init = init.left;
if (!init || init.type !== 'MemberExpression') continue;
- if (init.object.name !== 'module') continue;
- if (init.property.name !== 'exports') continue;
- exported.constructors.push(decl.id.name);
- definition[decl.id.name] = `${link}#L${statement.loc.start.line}`;
+ if (init.object.name === 'exports') {
+ definition[`${basename}.${init.property.name}`] =
+ `${link}#L${statement.loc.start.line}`;
+ } else if (init.object.name === 'module') {
+ if (init.property.name !== 'exports') continue;
+ exported.constructors.push(decl.id.name);
+ definition[decl.id.name] = `${link}#L${statement.loc.start.line}`;
+ }
}
}
});
@@ -107,10 +125,8 @@ process.argv.slice(2).forEach((file) => {
// ClassName.foo = ...;
// ClassName.prototype.foo = ...;
// function Identifier(...) {...};
- // class Foo {...}
+ // class Foo {...};
//
- const indirect = {};
-
program.forEach((statement) => {
if (statement.type === 'ExpressionStatement') {
const expr = statement.expression;