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 649fcbb

Browse filesBrowse files
kfarnungtargos
authored andcommitted
tools,doc: apilinks should handle root scenarios
* Prevent crash when setting root properties * Allow return outside of function PR-URL: #22721 Reviewed-By: Sam Ruby <rubys@intertwingly.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 9942117 commit 649fcbb
Copy full SHA for 649fcbb

File tree

Expand file treeCollapse file tree

3 files changed

+16
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-2
lines changed
Open diff view settings
Collapse file

‎test/fixtures/apilinks/root.js‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
// Set root member
4+
let foo = true;
5+
foo = false;
6+
7+
// Return outside of function
8+
if (!foo) {
9+
return;
10+
}
Collapse file

‎test/fixtures/apilinks/root.json‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Collapse file

‎tools/doc/apilinks.js‎

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

5353
// Parse source.
5454
const source = fs.readFileSync(file, 'utf8');
55-
const ast = acorn.parse(source, { ecmaVersion: 10, locations: true });
55+
const ast = acorn.parse(
56+
source,
57+
{ allowReturnOutsideFunction: true, ecmaVersion: 10, locations: true });
5658
const program = ast.body;
5759

5860
// Build link
@@ -68,8 +70,8 @@ process.argv.slice(2).forEach((file) => {
6870
if (expr.type !== 'AssignmentExpression') return;
6971

7072
let lhs = expr.left;
71-
if (expr.left.object.type === 'MemberExpression') lhs = lhs.object;
7273
if (lhs.type !== 'MemberExpression') return;
74+
if (lhs.object.type === 'MemberExpression') lhs = lhs.object;
7375
if (lhs.object.name === 'exports') {
7476
const name = lhs.property.name;
7577
if (expr.right.type === 'FunctionExpression') {

0 commit comments

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