Permalink
Browse files

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>
  • Loading branch information...
kfarnung committed Sep 5, 2018
1 parent 66f563d commit 3bdc61d4d194e2057f5e692036ceb2b3a24cc476
Showing with 16 additions and 2 deletions.
  1. +10 −0 test/fixtures/apilinks/root.js
  2. +2 −0 test/fixtures/apilinks/root.json
  3. +4 −2 tools/doc/apilinks.js
@@ -0,0 +1,10 @@
'use strict';
// Set root member
let foo = true;
foo = false;
// Return outside of function
if (!foo) {
return;
}
@@ -0,0 +1,2 @@
{
}
View
@@ -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') {

0 comments on commit 3bdc61d

Please sign in to comment.