forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser-asc.js
83 lines (72 loc) · 2.19 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
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
const asc = require("../dist/asc.js");
if (typeof asc.definitionFiles.assembly !== "string") throw Error("missing bundled assembly.d.ts");
if (typeof asc.definitionFiles.portable !== "string") throw Error("missing bundled portable.d.ts");
const stdout = asc.createMemoryStream();
const stderr = asc.createMemoryStream();
const files = { "module.ts": `export function test(): void {}` };
console.log("# asc --version");
asc.main([
"--version"
], {
stdout: stdout,
stderr: stderr
}, err => {
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
stdout.reset();
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
stderr.reset();
});
console.log("\n# asc --help");
asc.main([
"--help"
], {
stdout: stdout,
stderr: stderr
}, err => {
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
stdout.reset();
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
stderr.reset();
});
console.log("\n# asc module.ts --textFile");
asc.main([
"module.ts",
"--textFile"
], {
stdout: stdout,
stderr: stderr,
readFile: (name, baseDir) => {
console.log("readFile: " + name + ", baseDir=" + baseDir);
if (Object.prototype.hasOwnProperty.call(files, name)) return files[name];
return null;
},
writeFile: (name, data, baseDir) => {
console.log("writeFile: " + name + ", baseDir=" + baseDir);
},
listFiles: (dirname, baseDir) => {
console.log("listFiles: " + dirname + ", baseDir=" + baseDir);
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(`export function test(): void {}`, { optimizeLevel: 3, exportTable: true, measure: true });
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");