diff --git a/test/fixtures/apilinks/root.js b/test/fixtures/apilinks/root.js new file mode 100644 index 00000000000000..6cf9fee945ac24 --- /dev/null +++ b/test/fixtures/apilinks/root.js @@ -0,0 +1,10 @@ +'use strict'; + +// Set root member +let foo = true; +foo = false; + +// Return outside of function +if (!foo) { + return; +} diff --git a/test/fixtures/apilinks/root.json b/test/fixtures/apilinks/root.json new file mode 100644 index 00000000000000..2c63c0851048d8 --- /dev/null +++ b/test/fixtures/apilinks/root.json @@ -0,0 +1,2 @@ +{ +} diff --git a/tools/doc/apilinks.js b/tools/doc/apilinks.js index 0a33125a17b103..d7ec5684b79705 100644 --- a/tools/doc/apilinks.js +++ b/tools/doc/apilinks.js @@ -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') {