-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
104 lines (96 loc) · 4.55 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// TODO collect html4 and html5 definitions
// https://github.com/jarib/webidl/blob/master/spec/fixtures/html5.idl - added as html5.idl
// https://github.com/heycam/webidl
// http://www.w3.org/TR/html/webappapis.html#idl-definitions
// http://www.w3.org/TR/html4/
var WebIDL2 = require("webidl2");
var fs = require("fs");
var xmldoc = require("xmldoc");
var idlClasses = {};
var idlDirName = ".\\dom\\";
var idlDir = fs.readdirSync(idlDirName);
for (var fileIndex in idlDir) {
if (!idlDir.hasOwnProperty(fileIndex)) continue;
var file = idlDir[fileIndex];
var code = fs.readFileSync(idlDirName + file, "utf8");
//var code = fs.readFileSync("./short.idl", "utf8");
fs.writeSync(1, "parsing " + file + "\n");
var tree = WebIDL2.parse(code);
for (var treeElemIndex in tree) {
var treeElem = tree[treeElemIndex];
if (!idlClasses[treeElem.name]) idlClasses[treeElem.name] = {};
else fs.writeSync(1, "Class '" + treeElem.name + "' overloaded.\n");
var idlClass = idlClasses[treeElem.name];
for (var treeElemMemberIndex in treeElem.members) {
var treeElemMember = treeElem.members[treeElemMemberIndex];
var idlClassMember = {
readonly: treeElemMember.readonly,
type:treeElemMember.idlType.idlType,
kind:treeElemMember.type === "operation" ? "method" : "property"
};
if (treeElemMember.type === "operation") {
idlClassMember.parameters = [];
for (var i=0; i < treeElemMember.arguments.length; i++) {
idlClassMember.parameters.push({
name:treeElemMember.arguments[i].name,
optional:treeElemMember.arguments[i].optional,
type:treeElemMember.arguments[i].idlType.idlType
});
}
}
idlClass[treeElemMember.name] = idlClassMember;
}
}
fs.writeSync(1, "IDL: " + file + "\n");
fs.writeSync(1, JSON.stringify(tree) + "\n");
}
var stubsDirName = "C:\\idea_src\\ultimate\\plugins\\JavaScriptLanguage\\javascript-psi-impl\\src\\com\\intellij\\lang\\javascript\\index\\predefined\\";
var stubsDir = fs.readdirSync(stubsDirName);
/** @type {Object.<string, Object.<string, *>>} */
var stubsClasses = {};
for (var fileIndex in stubsDir) {
if (!stubsDir.hasOwnProperty(fileIndex)) continue;
var file = stubsDir[fileIndex];
if (file.indexOf(".xml") == -1) continue;
if (file.indexOf("EcmaScript") != -1) continue;
fs.writeSync(1, "Stub: " + file + "\n");
var stub = fs.readFileSync(stubsDirName + file, "utf8");
var stubDoc = new xmldoc.XmlDocument(stub);
stubDoc.eachChild(function(topElement) {
if (topElement.name === "class") {
var className = topElement.attr.name;
if (!stubsClasses[className]) stubsClasses[className] = {};
else fs.writeSync(1, "Class '" + className + "' overloaded.\n");
var classMembers = stubsClasses[className];
topElement.eachChild(function(topElementMember) {
var classMember = {
readonly:topElementMember.attr.readonly,
type:topElementMember.name === "method" ? topElementMember.attr.returnType : topElementMember.attr.type,
kind:topElementMember.name
};
if (topElementMember.name == "method" && topElementMember.children) {
classMember.parameters = [];
for (var i = 0; i < topElementMember.children.length; i++) {
classMember.parameters.push({
name:topElementMember.children[i].attr.name,
optional:Boolean(topElementMember.children[i].attr.optional),
type:topElementMember.children[i].attr.type
});
}
}
classMembers[topElementMember.attr.name] = classMember;
});
}
else {
fs.writeSync(1, "Undefined element: " + topElement.name + "\n");
}
});
var lib = stubDoc.childNamed("class");
fs.writeSync(1, JSON.stringify(lib) + "\n\n");
}
// use http://ulitink.github.io/JsonDiff/ for result diff
fs.writeSync(1, "Stubs classes: \n " + JSON.stringify(stubsClasses) + "\n");
fs.writeSync(1, "IDL classes: \n " + JSON.stringify(idlClasses) + "\n");
// sync writes instead of console.log
// http://stackoverflow.com/questions/6471004/how-can-i-write-blocking-in-stdout-with-node-js
fs.fsyncSync(1);