Skip to content

Commit 2980db7

Browse files
Merge branch 'main' into Issue-2289
2 parents 76d0c2e + 24a908d commit 2980db7

File tree

226 files changed

+46462
-94625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+46462
-94625
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- uses: dcodeIO/setup-node-nvm@master
7272
with:
7373
node-mirror: https://nodejs.org/download/v8-canary/
74-
node-version: 18.0.0-v8-canary20211115037fd7ae8d
74+
node-version: 19.0.0-v8-canary20220719f8973d8de1
7575
- name: Install dependencies
7676
run: npm ci --no-audit
7777
- name: Build

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

NOTICE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ under the licensing terms detailed in LICENSE:
4747
* Yasushi Ando <[email protected]>
4848
* Syed Jafri <[email protected]>
4949
* Peter Hayman <[email protected]>
50+
* ApsarasX <[email protected]>
51+
* Adrien Zinger <[email protected]>
52+
* Ruixiang Chen <[email protected]>
5053

5154
Portions of this software are derived from third-party works licensed under
5255
the following terms:

bin/asc.js

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ if ((!hasSourceMaps || ~posCustomArgs) && !isDeno) {
1919
nodeArgs.push(...args.slice(posCustomArgs + 1));
2020
args.length = posCustomArgs;
2121
}
22-
(await import("child_process")).spawnSync(
22+
const { status, signal } = (await import("child_process")).spawnSync(
2323
nodePath,
2424
[...nodeArgs, thisPath, ...args],
2525
{ stdio: "inherit" }
2626
);
27+
if (status || signal) process.exitCode = 1;
2728
} else {
28-
const { error } = (await import("../dist/asc.js")).main(process.argv.slice(2), {
29+
const apiResult = (await import("../dist/asc.js")).main(process.argv.slice(2), {
2930
stdout: process.stdout,
3031
stderr: process.stderr
3132
});
33+
const { error } = await apiResult;
3234
if (error) process.exitCode = 1;
3335
}

cli/index.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ function toUpperSnakeCase(str) {
6262
return str.replace(/-/g, "_").toUpperCase();
6363
}
6464

65+
function isNonEmptyString(value) {
66+
return typeof value === "string" && value !== "";
67+
}
68+
6569
/** Ensures that an object is a wrapper class instead of just a pointer. */
6670
// function __wrap(ptrOrObj, wrapperClass) {
6771
// if (typeof ptrOrObj === "number") {
@@ -309,7 +313,9 @@ export async function main(argv, options) {
309313
assemblyscript.setSharedMemory(compilerOptions, opts.sharedMemory);
310314
assemblyscript.setImportTable(compilerOptions, opts.importTable);
311315
assemblyscript.setExportTable(compilerOptions, opts.exportTable);
312-
assemblyscript.setExportStart(compilerOptions, typeof opts.exportStart === "string" ? opts.exportStart : null);
316+
if (opts.exportStart) {
317+
assemblyscript.setExportStart(compilerOptions, isNonEmptyString(opts.exportStart) ? opts.exportStart : "_start");
318+
}
313319
assemblyscript.setMemoryBase(compilerOptions, opts.memoryBase >>> 0);
314320
assemblyscript.setTableBase(compilerOptions, opts.tableBase >>> 0);
315321
assemblyscript.setSourceMap(compilerOptions, opts.sourceMap != null);
@@ -318,7 +324,7 @@ export async function main(argv, options) {
318324
assemblyscript.setLowMemoryLimit(compilerOptions, opts.lowMemoryLimit >>> 0);
319325
assemblyscript.setExportRuntime(compilerOptions, opts.exportRuntime);
320326
assemblyscript.setBundleVersion(compilerOptions, bundleMajorVersion, bundleMinorVersion, bundlePatchVersion);
321-
if (!opts.stackSize && opts.runtime == "incremental") {
327+
if (!opts.stackSize && runtime === 2 /* incremental */) {
322328
opts.stackSize = assemblyscript.DEFAULT_STACK_SIZE;
323329
}
324330
assemblyscript.setStackSize(compilerOptions, opts.stackSize);
@@ -615,7 +621,7 @@ export async function main(argv, options) {
615621
stats.parseTime += stats.end(begin);
616622
}
617623
}
618-
const numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
624+
const numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
619625
if (numErrors) {
620626
const err = Error(`${numErrors} parse error(s)`);
621627
err.stack = err.message; // omit stack
@@ -724,7 +730,7 @@ export async function main(argv, options) {
724730
? assemblyscript.getBinaryenModuleRef(module)
725731
: module.ref
726732
);
727-
var numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
733+
var numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
728734
if (numErrors) {
729735
const err = Error(`${numErrors} compile error(s)`);
730736
err.stack = err.message; // omit stack
@@ -737,7 +743,7 @@ export async function main(argv, options) {
737743
if (error) return prepareResult(error);
738744
}
739745

740-
numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
746+
numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
741747
if (numErrors) {
742748
const err = Error(`${numErrors} afterCompile error(s)`);
743749
err.stack = err.message; // omit stack
@@ -835,7 +841,7 @@ export async function main(argv, options) {
835841
}
836842
if (next.length >= last.length) {
837843
if (next.length > last.length) {
838-
stderr.write(`Last converge was suboptimial.${EOL}`);
844+
stderr.write(`Last converge was suboptimal.${EOL}`);
839845
}
840846
break;
841847
}
@@ -1117,17 +1123,22 @@ async function getConfig(file, baseDir, readFile) {
11171123
}
11181124

11191125
/** Checks diagnostics emitted so far for errors. */
1120-
export function checkDiagnostics(program, stderr, reportDiagnostic, useColors) {
1126+
export function checkDiagnostics(program, stderr, disableWarning, reportDiagnostic, useColors) {
11211127
if (typeof useColors === "undefined" && stderr) useColors = stderr.isTTY;
11221128
var numErrors = 0;
11231129
do {
11241130
let diagnostic = assemblyscript.nextDiagnostic(program);
11251131
if (!diagnostic) break;
11261132
if (stderr) {
1127-
stderr.write(
1128-
assemblyscript.formatDiagnostic(diagnostic, useColors, true) +
1129-
EOL + EOL
1130-
);
1133+
const isDisabledWarning = (diagnostic) => {
1134+
if (disableWarning == null) return false;
1135+
if (!disableWarning.length) return true;
1136+
const code = assemblyscript.getDiagnosticCode(diagnostic);
1137+
return disableWarning.includes(code);
1138+
};
1139+
if (assemblyscript.isError(diagnostic) || !isDisabledWarning(diagnostic)) {
1140+
stderr.write(assemblyscript.formatDiagnostic(diagnostic, useColors, true) + EOL + EOL);
1141+
}
11311142
}
11321143
if (reportDiagnostic) {
11331144
function wrapRange(range) {

cli/options.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
},
283283
"runPasses": {
284284
"category": "Binaryen",
285-
"description": [
285+
"description": [
286286
"Specifies additional Binaryen passes to run after other",
287287
"optimizations, if any. See: Binaryen/src/passes/pass.cpp"
288288
],
@@ -313,6 +313,13 @@
313313
"type": "b",
314314
"default": false
315315
},
316+
"disableWarning": {
317+
"description": [
318+
"Disables warnings matching the given diagnostic code.",
319+
"If no diagnostic code is given, all warnings are disabled."
320+
],
321+
"type": "I"
322+
},
316323
"noEmit": {
317324
"description": "Performs compilation as usual but does not emit code.",
318325
"type": "b",

0 commit comments

Comments
 (0)