Skip to content

Commit 08d9ba1

Browse files
committed
Improve bundled asc example a bit, see AssemblyScript#25
1 parent 60728c3 commit 08d9ba1

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

bin/asc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function main(argv, options, callback) {
4444
const readFile = options.readFile || readFileNode;
4545
const writeFile = options.writeFile || writeFileNode;
4646
const listFiles = options.listFiles || listFilesNode;
47+
const stats = options.stats || createStats();
4748

4849
// All of the above must be specified in browser environments
4950
if (!stdout) throw Error("'options.stdout' must be specified");
@@ -54,9 +55,6 @@ function main(argv, options, callback) {
5455
if (listFiles === listFilesNode) throw Error("'options.listFiles' must be specified");
5556
}
5657

57-
// Record compilation times
58-
const stats = createStats();
59-
6058
const args = parseArguments(argv);
6159
const indent = 24;
6260

@@ -507,6 +505,8 @@ function createStats() {
507505
};
508506
}
509507

508+
exports.createStats = createStats;
509+
510510
if (!process.hrtime)
511511
process.hrtime = require("browser-process-hrtime");
512512

tests/bundled-asc.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,40 @@ var asc = require("../dist/asc.js");
22

33
var stdout = asc.createMemoryStream();
44
var stderr = asc.createMemoryStream();
5+
var stats = asc.createStats();
56

67
process.exitCode = asc.main([
7-
"test.ts"
8+
"test.ts",
9+
"--validate",
10+
"--optimize",
11+
"--measure",
12+
"--textFile", // -> stdout
13+
"--binaryFile", "test.wasm",
14+
"--sourceMap"
815
], {
916
stdout: stdout,
1017
stderr: stderr,
18+
stats: stats,
1119
readFile: function(filename) {
12-
console.log("readFile: " + filename);
20+
console.log("<< readFile: " + filename);
1321
if (filename === "/test.ts") { // sic: browser path
1422
return "export function foo(): void {}";
1523
}
1624
throw Error("File not found: " + filename);
1725
},
1826
writeFile: function(filename, contents) {
19-
console.log("writeFile: " + filename);
27+
console.log(">> writeFile: " + filename + " (" + contents.length + " bytes)");
2028
},
2129
listFiles: function(dirname) {
22-
console.log("listFiles: " + dirname);
30+
console.log("<< listFiles: " + dirname);
2331
return [];
2432
}
2533
});
2634

27-
console.log("stdout >>>");
35+
console.log(">> stdout >>");
2836
console.log(stdout.toString());
2937

30-
console.log("stderr >>>");
38+
console.log(">> stderr >>");
3139
console.error(stderr.toString());
40+
41+
console.log(">> stats >>", stats);

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const bin = {
6868
const libFiles = require("glob").sync("**/*.ts", { cwd: libDir });
6969
const lib = {};
7070
libFiles.forEach(file => {
71+
// console.log("bundling '(lib)/" + file + "'");
7172
var source = fs.readFileSync(path.join(libDir, file), { encoding: "utf8" });
7273
lib["(lib)/" + file.replace(/\.ts$/, "")] = JSON.stringify(source);
7374
});

0 commit comments

Comments
 (0)