Merge pull request #3653 from bobrippling/fix/sanity-check-acorn

sanitycheck: parse ecma2020 constructs (`??`)
pull/3675/head^2
Rob Pilling 2024-11-28 12:32:56 +00:00 committed by GitHub
commit 478a43fcff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 41 deletions

View File

@ -10,18 +10,22 @@ apploader.init({
DEVICEID : "BANGLEJS2" 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; return str => acorn.parse(str, { ecmaVersion: 2020 });
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("=====================================================");
}
var BASEDIR = __dirname+"/../"; var BASEDIR = __dirname+"/../";
var APPSDIR_RELATIVE = "apps/"; var APPSDIR_RELATIVE = "apps/";
@ -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.supports && !Array.isArray(file.supports)) ERROR(`App ${app.id} file ${file.name} supports field is not an array`, {file:metadataFile});
if (file.evaluate) { if (file.evaluate) {
try { try {
acorn.parse("("+fileContents+")"); jsparse("("+fileContents+")");
} catch(e) { } catch(e) {
console.log("====================================================="); console.log("=====================================================");
console.log(" PARSE OF "+appDir+file.url+" failed."); console.log(" PARSE OF "+appDir+file.url+" failed.");
@ -415,7 +419,7 @@ apps.forEach((app,appIdx) => {
// TODO: actual lint? // TODO: actual lint?
var ast; var ast;
try { try {
ast = acorn.parse(fileContents); ast = jsparse(fileContents);
} catch(e) { } catch(e) {
console.log("====================================================="); console.log("=====================================================");
console.log(" PARSE OF "+appDir+file.url+" failed."); console.log(" PARSE OF "+appDir+file.url+" failed.");

35
package-lock.json generated
View File

@ -9,7 +9,7 @@
"version": "0.0.1", "version": "0.0.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"acorn": "^7.2.0" "acorn": "^8.0.0"
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.8.0", "@typescript-eslint/eslint-plugin": "^7.8.0",
@ -444,9 +444,10 @@
"dev": true "dev": true
}, },
"node_modules/acorn": { "node_modules/acorn": {
"version": "7.4.1", "version": "8.14.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
"license": "MIT",
"bin": { "bin": {
"acorn": "bin/acorn" "acorn": "bin/acorn"
}, },
@ -1309,18 +1310,6 @@
"url": "https://opencollective.com/eslint" "url": "https://opencollective.com/eslint"
} }
}, },
"node_modules/espree/node_modules/acorn": {
"version": "8.11.3",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
"dev": true,
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/esquery": { "node_modules/esquery": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz",
@ -3777,9 +3766,9 @@
"dev": true "dev": true
}, },
"acorn": { "acorn": {
"version": "7.4.1", "version": "8.14.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==" "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="
}, },
"acorn-jsx": { "acorn-jsx": {
"version": "5.3.2", "version": "5.3.2",
@ -4424,14 +4413,6 @@
"acorn": "^8.9.0", "acorn": "^8.9.0",
"acorn-jsx": "^5.3.2", "acorn-jsx": "^5.3.2",
"eslint-visitor-keys": "^3.4.1" "eslint-visitor-keys": "^3.4.1"
},
"dependencies": {
"acorn": {
"version": "8.11.3",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
"dev": true
}
} }
}, },
"esquery": { "esquery": {

View File

@ -27,6 +27,6 @@
"update-local-apps": "apps/*/metadata.json" "update-local-apps": "apps/*/metadata.json"
}, },
"dependencies": { "dependencies": {
"acorn": "^7.2.0" "acorn": "^8.0.0"
} }
} }