Skip to content

Commit ab964b4

Browse files
authored
Fix compileString options in asc.d.ts (AssemblyScript#1077)
1 parent 34c34f3 commit ab964b4

File tree

3 files changed

+95
-6
lines changed

3 files changed

+95
-6
lines changed

cli/asc.d.ts

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,92 @@ export interface MemoryStream extends OutputStream {
5050
toString(): string;
5151
}
5252

53-
/** Compiler API options. */
53+
/** Compiler options. */
5454
interface CompilerOptions {
55+
/** Prints just the compiler's version and exits. */
56+
version?: boolean;
57+
/** Prints the help message and exits. */
58+
help?: boolean;
59+
/** Optimizes the module. */
60+
optimize?: boolean;
61+
/** How much to focus on optimizing code. */
62+
optimizeLevel?: number;
63+
/** How much to focus on shrinking code size. */
64+
shrinkLevel?: number;
65+
/** Re-optimizes until no further improvements can be made. */
66+
converge?: boolean;
67+
/** Validates the module using Binaryen. Exits if invalid. */
68+
validate?: boolean;
69+
/** Specifies the base directory of input and output files. */
70+
baseDir?: string;
71+
/** Specifies the output file. File extension indicates format. */
72+
outFile?: string;
73+
/** Specifies the binary output file (.wasm). */
74+
binaryFile?: string;
75+
/** Specifies the text output file (.wat). */
76+
textFile?: string;
77+
/** Specifies the asm.js output file (.js). */
78+
asmjsFile?: string;
79+
/** Specifies the WebIDL output file (.webidl). */
80+
idlFile?: string;
81+
/** Specifies the TypeScript definition output file (.d.ts). */
82+
tsdFile?: string;
83+
/** Enables source map generation. Optionally takes the URL. */
84+
sourceMap?: boolean | string;
85+
/** Specifies the runtime variant to include in the program. */
86+
runtime?: string;
87+
/** Disallows the use of unsafe features in user code. */
88+
noUnsafe?: boolean;
89+
/** Enables debug information in emitted binaries. */
90+
debug?: boolean;
91+
/** Replaces assertions with just their value without trapping. */
92+
noAssert?: boolean;
93+
/** Performs compilation as usual but does not emit code. */
94+
noEmit?: boolean;
95+
/** Imports the memory provided as 'env.memory'. */
96+
importMemory?: boolean;
97+
/** Declare memory as shared by settings the max shared memory. */
98+
sharedMemory?: number;
99+
/** Sets the start offset of compiler-generated static memory. */
100+
memoryBase?: number;
101+
/** Imports the function table provided as 'env.table'. */
102+
importTable?: boolean;
103+
/** Exports the function table as 'table'. */
104+
exportTable?: boolean;
105+
/** Exports an explicit start function to be called manually. */
106+
explicitStart?: boolean;
107+
/** "Adds one or multiple paths to custom library components. */
108+
lib?: string | string[];
109+
/** Adds one or multiple paths to package resolution. */
110+
path?: string | string[];
111+
/** Aliases a global object under another name. */
112+
use?: string | string[];
113+
/** Sets the trap mode to use. */
114+
trapMode?: "allow" | "clamp" | "js";
115+
/** Specifies additional Binaryen passes to run. */
116+
runPasses?: string | string[];
117+
/** Enables WebAssembly features that are disabled by default. */
118+
enable?: string | string[];
119+
/** Disables WebAssembly features that are enabled by default. */
120+
disable?: string | string[];
121+
/** Specifies the path to a custom transform to 'require'. */
122+
transform?: string | string[];
123+
/** Make yourself sad for no good reason. */
124+
pedantic?: boolean;
125+
/** Enables tracing of package resolution. */
126+
traceResolution?: boolean;
127+
/** Lists files to be compiled and exits. */
128+
listFiles?: boolean;
129+
/** Prints measuring information on I/O and compile times. */
130+
measure?: boolean;
131+
/** Prints the module's runtime type information to stderr. */
132+
printrtti?: boolean;
133+
/** Disables terminal colors. */
134+
noColors?: boolean;
135+
}
136+
137+
/** Compiler API options. */
138+
interface APIOptions {
55139
/** Standard output stream to use. */
56140
stdout?: OutputStream;
57141
/** Standard error stream to use. */
@@ -77,7 +161,7 @@ export function compileString(sources: { [key: string]: string } | string, optio
77161
}
78162

79163
/** Runs the command line utility using the specified arguments array. */
80-
export function main(argv: string[], options: CompilerOptions, callback?: (err: Error | null) => number): number;
164+
export function main(argv: string[], options: APIOptions, callback?: (err: Error | null) => number): number;
81165
export function main(argv: string[], callback?: (err: Error | null) => number): number;
82166

83167
/** Checks diagnostics emitted so far for errors. */

cli/asc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ exports.compileString = (sources, options) => {
110110
];
111111
Object.keys(options || {}).forEach(key => {
112112
var val = options[key];
113-
if (Array.isArray(val)) val.forEach(val => argv.push("--" + key, String(val)));
114-
else argv.push("--" + key, String(val));
113+
var opt = exports.options[key];
114+
if (opt && opt.type === "b") {
115+
if (val) argv.push("--" + key);
116+
} else {
117+
if (Array.isArray(val)) val.forEach(val => argv.push("--" + key, String(val)));
118+
else argv.push("--" + key, String(val));
119+
}
115120
});
116121
exports.main(argv.concat(Object.keys(sources)), {
117122
stdout: output.stdout,

tests/browser-asc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if (typeof asc.definitionFiles.portable !== "string") throw Error("missing bundl
55

66
const stdout = asc.createMemoryStream();
77
const stderr = asc.createMemoryStream();
8-
const files = { "module.ts": `import "allocator/arena";` };
8+
const files = { "module.ts": `export function test(): void {}` };
99

1010
console.log("# asc --version");
1111

@@ -73,7 +73,7 @@ process.stdout.write(stderr.toString());
7373

7474
console.log("\n# asc.compileString");
7575

76-
const output = asc.compileString(`import "allocator/arena";`, { optimizeLevel: 2 });
76+
const output = asc.compileString(`export function test(): void {}`, { optimizeLevel: 3, runtime: "none", exportTable: true, measure: true });
7777
console.log(">>> .stdout >>>");
7878
process.stdout.write(output.stdout.toString());
7979
console.log(">>> .stderr >>>");

0 commit comments

Comments
 (0)