forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.js
65 lines (56 loc) · 2.06 KB
/
browser.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
import * as asc from "../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 files = { "index.ts": `export function test(): void {}` };
console.log("# asc --version");
{
const { stdout, stderr } = await asc.main([ "--version" ]);
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
}
console.log("\n# asc --help");
{
const { stdout, stderr } = await asc.main([ "--help" ]);
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
}
console.log("\n# asc index.ts --textFile");
{
const { error, stdout, stderr } = await asc.main([ "index.ts", "--textFile" ], {
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 [];
}
});
if (error) {
console.log(">>> THROWN >>>");
console.log(error);
}
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
}
console.log("\n# asc.compileString");
{
const { stdout, stderr, text, binary } = await asc.compileString(`export function test(): void {}`, { optimizeLevel: 3, exportTable: true, stats: true });
console.log(">>> .stdout >>>");
process.stdout.write(stdout.toString());
console.log(">>> .stderr >>>");
process.stdout.write(stderr.toString());
console.log(">>> .text >>>");
process.stdout.write(text);
console.log(">>> .binary >>> " + binary.length + " bytes");
}