mirror of https://github.com/nodejs/node.git
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>pull/22721/head
parent
66f563dec7
commit
3bdc61d4d1
|
@ -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 @@
|
|||
{
|
||||
}
|
|
@ -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') {
|
||||
|
|
Loading…
Reference in New Issue