fix: throw better error when JS parse fails
This should help debugging challenges with invalid syntax.pull/44035/head
parent
da9e6ad0c1
commit
3e5cffba0f
|
@ -6,8 +6,14 @@ const parser = acorn.Parser;
|
||||||
function extractComments(js) {
|
function extractComments(js) {
|
||||||
let comments = [];
|
let comments = [];
|
||||||
const file = { data: {} };
|
const file = { data: {} };
|
||||||
|
try {
|
||||||
parser.parse(js, { onComment: comments, ecmaVersion: 2020 });
|
parser.parse(js, { onComment: comments, ecmaVersion: 2020 });
|
||||||
|
} catch {
|
||||||
|
throw Error(`extract-js-comments could not parse the code below, this challenge have invalid syntax:
|
||||||
|
|
||||||
|
${js}
|
||||||
|
`);
|
||||||
|
}
|
||||||
comments
|
comments
|
||||||
.map(({ value }) => value.trim())
|
.map(({ value }) => value.trim())
|
||||||
.forEach(comment => commentToData(file, comment));
|
.forEach(comment => commentToData(file, comment));
|
||||||
|
|
Loading…
Reference in New Issue