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:
parent
66f563dec7
commit
3bdc61d4d1
10
test/fixtures/apilinks/root.js
vendored
Normal file
10
test/fixtures/apilinks/root.js
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Set root member
|
||||||
|
let foo = true;
|
||||||
|
foo = false;
|
||||||
|
|
||||||
|
// Return outside of function
|
||||||
|
if (!foo) {
|
||||||
|
return;
|
||||||
|
}
|
2
test/fixtures/apilinks/root.json
vendored
Normal file
2
test/fixtures/apilinks/root.json
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
@ -52,7 +52,9 @@ process.argv.slice(2).forEach((file) => {
|
|||||||
|
|
||||||
// Parse source.
|
// Parse source.
|
||||||
const source = fs.readFileSync(file, 'utf8');
|
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;
|
const program = ast.body;
|
||||||
|
|
||||||
// Build link
|
// Build link
|
||||||
@ -68,8 +70,8 @@ process.argv.slice(2).forEach((file) => {
|
|||||||
if (expr.type !== 'AssignmentExpression') return;
|
if (expr.type !== 'AssignmentExpression') return;
|
||||||
|
|
||||||
let lhs = expr.left;
|
let lhs = expr.left;
|
||||||
if (expr.left.object.type === 'MemberExpression') lhs = lhs.object;
|
|
||||||
if (lhs.type !== 'MemberExpression') return;
|
if (lhs.type !== 'MemberExpression') return;
|
||||||
|
if (lhs.object.type === 'MemberExpression') lhs = lhs.object;
|
||||||
if (lhs.object.name === 'exports') {
|
if (lhs.object.name === 'exports') {
|
||||||
const name = lhs.property.name;
|
const name = lhs.property.name;
|
||||||
if (expr.right.type === 'FunctionExpression') {
|
if (expr.right.type === 'FunctionExpression') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user