Skip to content

Commit a8f1aa9

Browse files
committed
sanitycheck: parse ecma2020 constructs (??)
1 parent d3dc3b4 commit a8f1aa9

File tree

3 files changed

+137
-15
lines changed

3 files changed

+137
-15
lines changed

bin/sanitycheck.js

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

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

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-
}
28+
var parser = acorn.Parser.extend(stage3)
29+
return str => parser.parse(str, { ecmaVersion: 2020 });
30+
})();
2531

2632
var BASEDIR = __dirname+"/../";
2733
var APPSDIR_RELATIVE = "apps/";
@@ -399,7 +405,7 @@ apps.forEach((app,appIdx) => {
399405
if (file.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`, {file:metadataFile});
400406
if (file.evaluate) {
401407
try {
402-
acorn.parse("("+fileContents+")");
408+
jsparse("("+fileContents+")");
403409
} catch(e) {
404410
console.log("=====================================================");
405411
console.log(" PARSE OF "+appDir+file.url+" failed.");
@@ -415,7 +421,7 @@ apps.forEach((app,appIdx) => {
415421
// TODO: actual lint?
416422
var ast;
417423
try {
418-
ast = acorn.parse(fileContents);
424+
ast = jsparse(fileContents);
419425
} catch(e) {
420426
console.log("=====================================================");
421427
console.log(" PARSE OF "+appDir+file.url+" failed.");

package-lock.json

Lines changed: 116 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"update-local-apps": "apps/*/metadata.json"
2828
},
2929
"dependencies": {
30-
"acorn": "^7.2.0"
30+
"acorn": "^7.2.0",
31+
"acorn-stage3": "^4.0.0"
3132
}
3233
}

0 commit comments

Comments
 (0)