Skip to content

Commit

Permalink
Merge pull request #3653 from bobrippling/fix/sanity-check-acorn
Browse files Browse the repository at this point in the history
sanitycheck: parse ecma2020 constructs (`??`)
  • Loading branch information
bobrippling authored Nov 28, 2024
2 parents f34a9bf + 2fe22ec commit 478a43f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 41 deletions.
30 changes: 17 additions & 13 deletions bin/sanitycheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ apploader.init({
DEVICEID : "BANGLEJS2"
});*/

var jsparse = (() => {
var acorn;
try {
acorn = require("acorn");
} catch (e) {
console.log("=====================================================");
console.log(" ACORN NOT FOUND");
console.log(" ---------------");
console.log("");
console.log(" This means we won't sanity-check uploaded JSON");
console.log("=====================================================");
return str => {throw new Error("no acorn")};
}

var acorn;
try {
acorn = require("acorn");
} catch (e) {
console.log("=====================================================");
console.log(" ACORN NOT FOUND");
console.log(" ---------------");
console.log("");
console.log(" This means we won't sanity-check uploaded JSON");
console.log("=====================================================");
}
return str => acorn.parse(str, { ecmaVersion: 2020 });
})();

var BASEDIR = __dirname+"/../";
var APPSDIR_RELATIVE = "apps/";
Expand Down Expand Up @@ -399,7 +403,7 @@ apps.forEach((app,appIdx) => {
if (file.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`, {file:metadataFile});
if (file.evaluate) {
try {
acorn.parse("("+fileContents+")");
jsparse("("+fileContents+")");
} catch(e) {
console.log("=====================================================");
console.log(" PARSE OF "+appDir+file.url+" failed.");
Expand All @@ -415,7 +419,7 @@ apps.forEach((app,appIdx) => {
// TODO: actual lint?
var ast;
try {
ast = acorn.parse(fileContents);
ast = jsparse(fileContents);
} catch(e) {
console.log("=====================================================");
console.log(" PARSE OF "+appDir+file.url+" failed.");
Expand Down
35 changes: 8 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"update-local-apps": "apps/*/metadata.json"
},
"dependencies": {
"acorn": "^7.2.0"
"acorn": "^8.0.0"
}
}

0 comments on commit 478a43f

Please sign in to comment.