Skip to content

[cli] fallback to _start value for --exportStart if argument was skipped #2343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions tests/cli/options.js
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"]);