Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a7e8949

Browse filesBrowse files
rubystargos
authored andcommitted
tools: add [src] links to child-process.html
handle exports. as an alternative to module.exports PR-URL: #22706 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6579d05 commit a7e8949
Copy full SHA for a7e8949

File tree

Expand file treeCollapse file tree

3 files changed

+60
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+60
-25
lines changed
Open diff view settings
Collapse file

‎test/fixtures/apilinks/exports.js‎

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
// Support `exports` as an alternative to `module.exports`.
4+
5+
function Buffer() {};
6+
7+
exports.Buffer = Buffer;
8+
exports.fn1 = function fn1() {};
9+
10+
var fn2 = exports.fn2 = function() {};
11+
12+
function fn3() {};
13+
exports.fn3 = fn3;
Collapse file
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"exports.Buffer": "exports.js#L5",
3+
"exports.fn1": "exports.js#L8",
4+
"exports.fn2": "exports.js#L10",
5+
"exports.fn3": "exports.js#L12"
6+
}
Collapse file

‎tools/doc/apilinks.js‎

Copy file name to clipboardExpand all lines: tools/doc/apilinks.js
+41-25Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ process.argv.slice(2).forEach((file) => {
6161

6262
// Scan for exports.
6363
const exported = { constructors: [], identifiers: [] };
64+
const indirect = {};
6465
program.forEach((statement) => {
6566
if (statement.type === 'ExpressionStatement') {
6667
const expr = statement.expression;
@@ -69,35 +70,52 @@ process.argv.slice(2).forEach((file) => {
6970
let lhs = expr.left;
7071
if (expr.left.object.type === 'MemberExpression') lhs = lhs.object;
7172
if (lhs.type !== 'MemberExpression') return;
72-
if (lhs.object.name !== 'module') return;
73-
if (lhs.property.name !== 'exports') return;
74-
75-
let rhs = expr.right;
76-
while (rhs.type === 'AssignmentExpression') rhs = rhs.right;
77-
78-
if (rhs.type === 'NewExpression') {
79-
exported.constructors.push(rhs.callee.name);
80-
} else if (rhs.type === 'ObjectExpression') {
81-
rhs.properties.forEach((property) => {
82-
if (property.value.type === 'Identifier') {
83-
exported.identifiers.push(property.value.name);
84-
if (/^[A-Z]/.test(property.value.name[0])) {
85-
exported.constructors.push(property.value.name);
86-
}
73+
if (lhs.object.name === 'exports') {
74+
const name = lhs.property.name;
75+
if (expr.right.type === 'FunctionExpression') {
76+
definition[`${basename}.${name}`] =
77+
`${link}#L${statement.loc.start.line}`;
78+
} else if (expr.right.type === 'Identifier') {
79+
if (expr.right.name === name) {
80+
indirect[name] = `${basename}.${name}`;
8781
}
88-
});
89-
} else if (rhs.type === 'Identifier') {
90-
exported.identifiers.push(rhs.name);
82+
} else {
83+
exported.identifiers.push(name);
84+
}
85+
} else if (lhs.object.name === 'module') {
86+
if (lhs.property.name !== 'exports') return;
87+
88+
let rhs = expr.right;
89+
while (rhs.type === 'AssignmentExpression') rhs = rhs.right;
90+
91+
if (rhs.type === 'NewExpression') {
92+
exported.constructors.push(rhs.callee.name);
93+
} else if (rhs.type === 'ObjectExpression') {
94+
rhs.properties.forEach((property) => {
95+
if (property.value.type === 'Identifier') {
96+
exported.identifiers.push(property.value.name);
97+
if (/^[A-Z]/.test(property.value.name[0])) {
98+
exported.constructors.push(property.value.name);
99+
}
100+
}
101+
});
102+
} else if (rhs.type === 'Identifier') {
103+
exported.identifiers.push(rhs.name);
104+
}
91105
}
92106
} else if (statement.type === 'VariableDeclaration') {
93107
for (const decl of statement.declarations) {
94108
let init = decl.init;
95109
while (init && init.type === 'AssignmentExpression') init = init.left;
96110
if (!init || init.type !== 'MemberExpression') continue;
97-
if (init.object.name !== 'module') continue;
98-
if (init.property.name !== 'exports') continue;
99-
exported.constructors.push(decl.id.name);
100-
definition[decl.id.name] = `${link}#L${statement.loc.start.line}`;
111+
if (init.object.name === 'exports') {
112+
definition[`${basename}.${init.property.name}`] =
113+
`${link}#L${statement.loc.start.line}`;
114+
} else if (init.object.name === 'module') {
115+
if (init.property.name !== 'exports') continue;
116+
exported.constructors.push(decl.id.name);
117+
definition[decl.id.name] = `${link}#L${statement.loc.start.line}`;
118+
}
101119
}
102120
}
103121
});
@@ -107,10 +125,8 @@ process.argv.slice(2).forEach((file) => {
107125
// ClassName.foo = ...;
108126
// ClassName.prototype.foo = ...;
109127
// function Identifier(...) {...};
110-
// class Foo {...}
128+
// class Foo {...};
111129
//
112-
const indirect = {};
113-
114130
program.forEach((statement) => {
115131
if (statement.type === 'ExpressionStatement') {
116132
const expr = statement.expression;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.