From 0d7d25ca27b97dfb61061b10f59505160d882f61 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 27 Jun 2022 11:58:38 +0300 Subject: [PATCH 1/4] allow quoted args. Print error is exportStart missing argument --- cli/index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cli/index.js b/cli/index.js index ab5a6eb179..0299ecde6f 100644 --- a/cli/index.js +++ b/cli/index.js @@ -62,6 +62,13 @@ function toUpperSnakeCase(str) { return str.replace(/-/g, "_").toUpperCase(); } +function unquote(value) { + if (typeof value === "string") { + return value.replace(/['"]+/g, ""); + } + return value; +} + /** Ensures that an object is a wrapper class instead of just a pointer. */ // function __wrap(ptrOrObj, wrapperClass) { // if (typeof ptrOrObj === "number") { @@ -238,7 +245,7 @@ export async function main(argv, options) { // Load additional options from asconfig.json const seenAsconfig = new Set(); seenAsconfig.add(configPath); - const target = opts.target || "release"; + const target = unquote(opts.target) || "release"; while (config) { // Merge target first if (config.targets) { @@ -293,7 +300,7 @@ export async function main(argv, options) { // Set up options var program, runtime; const compilerOptions = assemblyscript.newOptions(); - switch (opts.runtime) { + switch (unquote(opts.runtime)) { case "stub": runtime = 0; break; case "minimal": runtime = 1; break; /* incremental */ @@ -309,7 +316,11 @@ 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 (typeof opts.exportStart === "string" && unquote(opts.exportStart) !== "") { + assemblyscript.setExportStart(compilerOptions, unquote(opts.exportStart)); + } else { + return prepareResult(Error("exportStart option required string argument")); + } assemblyscript.setMemoryBase(compilerOptions, opts.memoryBase >>> 0); assemblyscript.setTableBase(compilerOptions, opts.tableBase >>> 0); assemblyscript.setSourceMap(compilerOptions, opts.sourceMap != null); @@ -318,7 +329,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 && unquote(opts.runtime) === "incremental") { opts.stackSize = assemblyscript.DEFAULT_STACK_SIZE; } assemblyscript.setStackSize(compilerOptions, opts.stackSize); From 50b477ee9229df3567ed1e52fd7a329e64c6aba3 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 27 Jun 2022 12:07:56 +0300 Subject: [PATCH 2/4] fix --- cli/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cli/index.js b/cli/index.js index 0299ecde6f..8fffc070c8 100644 --- a/cli/index.js +++ b/cli/index.js @@ -316,10 +316,12 @@ export async function main(argv, options) { assemblyscript.setSharedMemory(compilerOptions, opts.sharedMemory); assemblyscript.setImportTable(compilerOptions, opts.importTable); assemblyscript.setExportTable(compilerOptions, opts.exportTable); - if (typeof opts.exportStart === "string" && unquote(opts.exportStart) !== "") { - assemblyscript.setExportStart(compilerOptions, unquote(opts.exportStart)); - } else { - return prepareResult(Error("exportStart option required string argument")); + if (opts.exportStart) { + if (typeof opts.exportStart === "string" && unquote(opts.exportStart) !== "") { + assemblyscript.setExportStart(compilerOptions, unquote(opts.exportStart)); + } else { + return prepareResult(Error("exportStart option required string argument")); + } } assemblyscript.setMemoryBase(compilerOptions, opts.memoryBase >>> 0); assemblyscript.setTableBase(compilerOptions, opts.tableBase >>> 0); From b1f7d6e03fc89798b1dc32e4887da1fac6e0465c Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 27 Jun 2022 14:56:01 +0300 Subject: [PATCH 3/4] remove unqute helpter. SOme minor fixes --- cli/index.js | 17 +++++------------ tests/cli/options.js | 9 +++++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cli/index.js b/cli/index.js index 8fffc070c8..d48bc7ed2b 100644 --- a/cli/index.js +++ b/cli/index.js @@ -62,13 +62,6 @@ function toUpperSnakeCase(str) { return str.replace(/-/g, "_").toUpperCase(); } -function unquote(value) { - if (typeof value === "string") { - return value.replace(/['"]+/g, ""); - } - return value; -} - /** Ensures that an object is a wrapper class instead of just a pointer. */ // function __wrap(ptrOrObj, wrapperClass) { // if (typeof ptrOrObj === "number") { @@ -245,7 +238,7 @@ export async function main(argv, options) { // Load additional options from asconfig.json const seenAsconfig = new Set(); seenAsconfig.add(configPath); - const target = unquote(opts.target) || "release"; + const target = opts.target || "release"; while (config) { // Merge target first if (config.targets) { @@ -300,7 +293,7 @@ export async function main(argv, options) { // Set up options var program, runtime; const compilerOptions = assemblyscript.newOptions(); - switch (unquote(opts.runtime)) { + switch (opts.runtime) { case "stub": runtime = 0; break; case "minimal": runtime = 1; break; /* incremental */ @@ -317,8 +310,8 @@ export async function main(argv, options) { assemblyscript.setImportTable(compilerOptions, opts.importTable); assemblyscript.setExportTable(compilerOptions, opts.exportTable); if (opts.exportStart) { - if (typeof opts.exportStart === "string" && unquote(opts.exportStart) !== "") { - assemblyscript.setExportStart(compilerOptions, unquote(opts.exportStart)); + if (typeof opts.exportStart === "string" && opts.exportStart !== "") { + assemblyscript.setExportStart(compilerOptions, opts.exportStart); } else { return prepareResult(Error("exportStart option required string argument")); } @@ -331,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 && unquote(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"]); From d9757f35b5bc3fbd685ba8b48a80893522ff6c4c Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Mon, 27 Jun 2022 15:03:55 +0300 Subject: [PATCH 4/4] fallback to _start instead error --- cli/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/index.js b/cli/index.js index d48bc7ed2b..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") { @@ -310,11 +314,7 @@ export async function main(argv, options) { assemblyscript.setImportTable(compilerOptions, opts.importTable); assemblyscript.setExportTable(compilerOptions, opts.exportTable); if (opts.exportStart) { - if (typeof opts.exportStart === "string" && opts.exportStart !== "") { - assemblyscript.setExportStart(compilerOptions, opts.exportStart); - } else { - return prepareResult(Error("exportStart option required string argument")); - } + assemblyscript.setExportStart(compilerOptions, isNonEmptyString(opts.exportStart) ? opts.exportStart : "_start"); } assemblyscript.setMemoryBase(compilerOptions, opts.memoryBase >>> 0); assemblyscript.setTableBase(compilerOptions, opts.tableBase >>> 0);