Created
May 14, 2019 22:34
-
-
Save brendandahl/98c2957edba69c0e90f24b2490e6dfa2 to your computer and use it in GitHub Desktop.
Check xul structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fs = require("fs"); | |
var { | |
Parser | |
} = require("saxen"); | |
function structure(filename) { | |
let contents = fs.readFileSync(filename, "utf8"); | |
let parser = new Parser(); | |
let indent = 0; | |
let out = ""; | |
parser.on("openTag", function(elementName, attrGetter, decodeEntities, selfClosing, getContext) { | |
out += " ".repeat(indent) + elementName + "\n"; | |
indent += 2; | |
}); | |
parser.on("closeTag", function(elementName, attrGetter, decodeEntities, selfClosing, getContext) { | |
indent -= 2; | |
// out += " ".repeat(indent) + ">" + elementName + "\n"; | |
}); | |
parser.ns({ | |
"http://www.w3.org/1999/xhtml": "html", | |
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul": "xul", | |
}); | |
parser.parse(contents); | |
return out; | |
} | |
function files(filename) { | |
let contents = fs.readFileSync(filename, "utf8"); | |
return contents.split("\n").map((name) => "../../gecko/" + name); | |
} | |
function counts(filenames) { | |
let unique = {}; | |
let errors = 0; | |
let errorFiles = []; | |
for (filename of filenames) { | |
let struct; | |
try { | |
struct = structure(filename); | |
} catch (e) { | |
errors++; | |
errorFiles.push(filename); | |
} | |
if (unique[struct]) { | |
unique[struct].count++; | |
unique[struct].files.push(filename); | |
} else { | |
unique[struct] = { count: 1, files: [filename], struct: struct }; | |
} | |
} | |
let sorted = []; | |
for (var key in unique) { | |
sorted.push(unique[key]); | |
} | |
sorted.sort((a, b) => (a.count > b.count) ? 1 : -1); | |
let onlyOne = 0; | |
for (let i = 0; i < sorted.length; i++) { | |
if (sorted[i].count == 1) { | |
onlyOne++; | |
} | |
} | |
console.log("Last: "); | |
for (let i = sorted.length - 25; i < sorted.length; i++) { | |
console.log(sorted[i].count + " " + sorted[i].struct); | |
console.log(sorted[i].files); | |
// for (let j = 0; j < sorted[i].files.length; j++) { | |
// console.log() | |
// } | |
} | |
console.log("Errors: " + errors); | |
console.log("Only one: " + onlyOne); | |
console.log("Number of unique structures: " + sorted.length); | |
// return sorted; | |
} | |
// test "../../gecko/xpfe/appshell/test/test_hiddenPrivateWindow.xul" | |
let xulFiles = files("xul_files.txt"); | |
counts(xulFiles); | |
// structure(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment