Skip to content

Commit

Permalink
tools: apilinks.js skip file if unable to be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Feb 17, 2020
1 parent 4725ac6 commit 45c5232
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions test/fixtures/apilinks/private_fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

// Acorn does not support private fields.
// Verify that apilinks creates empty output
// instead of crashing.

class Foo {
#a = 1;
}
1 change: 1 addition & 0 deletions test/fixtures/apilinks/private_fields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 9 additions & 4 deletions tools/doc/apilinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ inputs.forEach((file) => {

// Parse source.
const source = fs.readFileSync(file, 'utf8');
const ast = acorn.parse(
source,
{ allowReturnOutsideFunction: true, ecmaVersion: 10, locations: true });
const program = ast.body;
let program;
try {
const ast = acorn.parse(
source,
{ allowReturnOutsideFunction: true, ecmaVersion: 10, locations: true });
program = ast.body;
} catch {
return;
}

// Build link
const link = `https://github.com/${repo}/blob/${tag}/` +
Expand Down

0 comments on commit 45c5232

Please sign in to comment.