tools,doc: apilinks should handle root scenarios

* Prevent crash when setting root properties
* Allow return outside of function

PR-URL: https://github.com/nodejs/node/pull/22721
Reviewed-By: Sam Ruby <rubys@intertwingly.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Kyle Farnung authored and Michaël Zasso committed 2018-09-10 18:23:44 +02:00
1 parent 9942117e6e
commit 649fcbba6f
3 files changed
+16 -2

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
'use strict';
// Set root member
let foo = true;
foo = false;
// Return outside of function
if (!foo) {
return;
}
+2
View File
@@ -0,0 +1,2 @@
{
}
+4 -2
View File
@@ -52,7 +52,9 @@ process.argv.slice(2).forEach((file) => {
// Parse source.
const source = fs.readFileSync(file, 'utf8');
const ast = acorn.parse(source, { ecmaVersion: 10, locations: true });
const ast = acorn.parse(
source,
{ allowReturnOutsideFunction: true, ecmaVersion: 10, locations: true });
const program = ast.body;
// Build link
@@ -68,8 +70,8 @@ process.argv.slice(2).forEach((file) => {
if (expr.type !== 'AssignmentExpression') return;
let lhs = expr.left;
if (expr.left.object.type === 'MemberExpression') lhs = lhs.object;
if (lhs.type !== 'MemberExpression') return;
if (lhs.object.type === 'MemberExpression') lhs = lhs.object;
if (lhs.object.name === 'exports') {
const name = lhs.property.name;
if (expr.right.type === 'FunctionExpression') {