summaryrefslogtreecommitdiff
path: root/tools/doc/apilinks.js
diff options
context:
space:
mode:
authorKyle Farnung <kfarnung@microsoft.com>2018-09-05 14:52:26 -0700
committerKyle Farnung <kfarnung@microsoft.com>2018-09-09 17:48:56 -0700
commit3bdc61d4d194e2057f5e692036ceb2b3a24cc476 (patch)
treef1ca3d67973f82ea622794023906da0c12b7f816 /tools/doc/apilinks.js
parent66f563dec783fdfdcbf60d2d453d2bad620edc26 (diff)
downloadandroid-node-v8-3bdc61d4d194e2057f5e692036ceb2b3a24cc476.tar.gz
android-node-v8-3bdc61d4d194e2057f5e692036ceb2b3a24cc476.tar.bz2
android-node-v8-3bdc61d4d194e2057f5e692036ceb2b3a24cc476.zip
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>
Diffstat (limited to 'tools/doc/apilinks.js')
-rw-r--r--tools/doc/apilinks.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/doc/apilinks.js b/tools/doc/apilinks.js
index 0a33125a17..d7ec5684b7 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') {