-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrowser-asc.js
48 lines (42 loc) · 1.28 KB
/
browser-asc.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
const asc = require("../dist/asc.js");
console.log("# asc.main");
const stdout = asc.createMemoryStream(arg => console.log("out:", arg));
const stderr = asc.createMemoryStream(arg => console.log("err:", arg));
const files = { "module.ts": `import "allocator/arena";` };
asc.main([
"module.ts",
"--textFile"
], {
stdout: stdout,
stderr: stderr,
readFile: (name) => {
console.log("readFile: " + name);
if (files.hasOwnProperty(name)) return files[name];
return null;
},
writeFile: (name, data) => {
console.log("writeFile: " + name);
},
listFiles: (dirname) => {
console.log("listFiles: " + dirname);
return [];
}
}, err => {
if (err) {
console.log(">>> THROWN >>>");
console.log(err);
}
});
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
console.log("\n# asc.compileString");
const output = asc.compileString(`import "allocator/arena";`, { optimize: 2 });
console.log(">>> .stdout >>>");
process.stdout.write(output.stdout.toString());
console.log(">>> .stderr >>>");
process.stdout.write(output.stderr.toString());
console.log(">>> .text >>>");
process.stdout.write(output.text);
console.log(">>> .binary >>> " + output.binary.length + " bytes");