diff --git a/cli/index.js b/cli/index.js index ab5a6eb179..1c999bf219 100644 --- a/cli/index.js +++ b/cli/index.js @@ -62,6 +62,10 @@ function toUpperSnakeCase(str) { return str.replace(/-/g, "_").toUpperCase(); } +function isNonEmptyString(value) { + return typeof value === "string" && value !== ""; +} + /** Ensures that an object is a wrapper class instead of just a pointer. */ // function __wrap(ptrOrObj, wrapperClass) { // if (typeof ptrOrObj === "number") { @@ -309,7 +313,9 @@ export async function main(argv, options) { assemblyscript.setSharedMemory(compilerOptions, opts.sharedMemory); assemblyscript.setImportTable(compilerOptions, opts.importTable); assemblyscript.setExportTable(compilerOptions, opts.exportTable); - assemblyscript.setExportStart(compilerOptions, typeof opts.exportStart === "string" ? opts.exportStart : null); + if (opts.exportStart) { + assemblyscript.setExportStart(compilerOptions, isNonEmptyString(opts.exportStart) ? opts.exportStart : "_start"); + } assemblyscript.setMemoryBase(compilerOptions, opts.memoryBase >>> 0); assemblyscript.setTableBase(compilerOptions, opts.tableBase >>> 0); assemblyscript.setSourceMap(compilerOptions, opts.sourceMap != null); @@ -318,7 +324,7 @@ export async function main(argv, options) { assemblyscript.setLowMemoryLimit(compilerOptions, opts.lowMemoryLimit >>> 0); assemblyscript.setExportRuntime(compilerOptions, opts.exportRuntime); assemblyscript.setBundleVersion(compilerOptions, bundleMajorVersion, bundleMinorVersion, bundlePatchVersion); - if (!opts.stackSize && opts.runtime == "incremental") { + if (!opts.stackSize && runtime === 2 /* incremental */) { opts.stackSize = assemblyscript.DEFAULT_STACK_SIZE; } assemblyscript.setStackSize(compilerOptions, opts.stackSize); diff --git a/tests/cli/options.js b/tests/cli/options.js index 93fb81fdcd..7cf2d42e0d 100644 --- a/tests/cli/options.js +++ b/tests/cli/options.js @@ -1,5 +1,5 @@ import assert from "assert"; -import * as optionsUtil from "../../cli/util/options.js"; +import * as optionsUtil from "../../util/options.js"; const config = { "enable": { @@ -40,10 +40,15 @@ optionsUtil.addDefaults(config, merged = { other: ["y"] }); assert.deepStrictEqual(merged.other, ["y"]); // Complete usage test -var result = optionsUtil.parse(["--enable", "a", "--disable", "b"], config, false); +var result = optionsUtil.parse([ + "--enable", "a", + "--disable", "b", +], config, false); + merged = optionsUtil.merge(config, result.options, { enable: ["b", "c"] }); merged = optionsUtil.merge(config, merged, { disable: ["a", "d"] }); optionsUtil.addDefaults(config, merged); + assert.deepStrictEqual(merged.enable, ["a", "c"]); assert.deepStrictEqual(merged.disable, ["b", "d"]); assert.deepStrictEqual(merged.other, ["x"]);