Skip to content

Commit 478a43f

Browse files
authored
Merge pull request espruino#3653 from bobrippling/fix/sanity-check-acorn
sanitycheck: parse ecma2020 constructs (`??`)
2 parents f34a9bf + 2fe22ec commit 478a43f

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

bin/sanitycheck.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ apploader.init({
1010
DEVICEID : "BANGLEJS2"
1111
});*/
1212

13+
var jsparse = (() => {
14+
var acorn;
15+
try {
16+
acorn = require("acorn");
17+
} catch (e) {
18+
console.log("=====================================================");
19+
console.log(" ACORN NOT FOUND");
20+
console.log(" ---------------");
21+
console.log("");
22+
console.log(" This means we won't sanity-check uploaded JSON");
23+
console.log("=====================================================");
24+
return str => {throw new Error("no acorn")};
25+
}
1326

14-
var acorn;
15-
try {
16-
acorn = require("acorn");
17-
} catch (e) {
18-
console.log("=====================================================");
19-
console.log(" ACORN NOT FOUND");
20-
console.log(" ---------------");
21-
console.log("");
22-
console.log(" This means we won't sanity-check uploaded JSON");
23-
console.log("=====================================================");
24-
}
27+
return str => acorn.parse(str, { ecmaVersion: 2020 });
28+
})();
2529

2630
var BASEDIR = __dirname+"/../";
2731
var APPSDIR_RELATIVE = "apps/";
@@ -399,7 +403,7 @@ apps.forEach((app,appIdx) => {
399403
if (file.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`, {file:metadataFile});
400404
if (file.evaluate) {
401405
try {
402-
acorn.parse("("+fileContents+")");
406+
jsparse("("+fileContents+")");
403407
} catch(e) {
404408
console.log("=====================================================");
405409
console.log(" PARSE OF "+appDir+file.url+" failed.");
@@ -415,7 +419,7 @@ apps.forEach((app,appIdx) => {
415419
// TODO: actual lint?
416420
var ast;
417421
try {
418-
ast = acorn.parse(fileContents);
422+
ast = jsparse(fileContents);
419423
} catch(e) {
420424
console.log("=====================================================");
421425
console.log(" PARSE OF "+appDir+file.url+" failed.");

package-lock.json

Lines changed: 8 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"update-local-apps": "apps/*/metadata.json"
2828
},
2929
"dependencies": {
30-
"acorn": "^7.2.0"
30+
"acorn": "^8.0.0"
3131
}
3232
}

0 commit comments

Comments
 (0)