Skip to content

Commit 89250e0

Browse files
author
Willem Wyndham
authored
fix: allow wat files to be created if no outDir is specified (#6)
1 parent 3e458c8 commit 89250e0

7 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function compileProject(
173173
const watFile = path.relative(baseDir, path.join(outDir, name + ".wat"));
174174
const wasmFile = path.relative(baseDir, path.join(outDir, name + ".wasm"));
175175

176-
if (args.wat && (args.outDir && !(hasOutput(ascArgv, ".wat") || config.options?.textFile))) {
176+
if (args.wat && (!(hasOutput(ascArgv, ".wat") || config.options?.textFile))) {
177177
ascArgv.push("--textFile", watFile);
178178
}
179179
if (args.outDir || !(hasOutput(ascArgv, ".wasm") || (config.options?.binaryFile))) {

test/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import * as fs from "fs";
55

66
let binary: Uint8Array;
7+
let textFile: string;
78
let stderr: string;
89

910
let args = process.argv.slice(2);
@@ -19,6 +20,8 @@ main(args, {
1920
mapFiles.set(name, contents);
2021
if (name.endsWith(".wasm")) {
2122
binary = contents;
23+
} else if (name.endsWith(".wat")) {
24+
textFile = contents;
2225
}
2326
},
2427
stderr: {
@@ -37,6 +40,7 @@ main(args, {
3740
const jsonPath = path.join(process.cwd(), "expected.json");
3841
if (fs.existsSync(jsonPath) && stderr) {
3942
const actual = JSON.parse(stderr).options;
43+
console.log(actual)
4044
const expected = require(jsonPath);
4145
let errored = false;
4246
for (let name of Object.getOwnPropertyNames(expected)) {
@@ -65,7 +69,7 @@ main(args, {
6569
}
6670

6771

68-
if (!binary) {
72+
if (!binary && !textFile) {
6973
console.error("No binary was generated for the asconfig test in " + process.cwd());
7074
process.exit(1);
7175
}

test/wat/asconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"targets": {
3+
"debug": {
4+
"debug": true
5+
},
6+
"release": {
7+
"optimize": true
8+
}
9+
},
10+
"options": {
11+
"noAssert": true
12+
}
13+
}

test/wat/assembly/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (!ASC_NO_ASSERT) {
2+
assert(false, "noAssert should be true");
3+
}

test/wat/assembly/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": [
4+
"./**/*.ts"
5+
]
6+
}

test/wat/expected.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"debug": false,
3+
"optimize": true,
4+
"textFile": "build/release/wat.wat"
5+
}

test/wat/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "wat",
3+
"license": "MIT",
4+
"scripts": {
5+
"test": "ts-node .. --wat -- --showConfig"
6+
}
7+
}

0 commit comments

Comments
 (0)