Skip to content

Commit 4b73edb

Browse files
feat: add --disableWarning option to disable compilation warning (#2341)
Co-authored-by: Max Graey <[email protected]>
1 parent 9d8d4fa commit 4b73edb

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Diff for: cli/index.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ export async function main(argv, options) {
621621
stats.parseTime += stats.end(begin);
622622
}
623623
}
624-
const numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
624+
const numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
625625
if (numErrors) {
626626
const err = Error(`${numErrors} parse error(s)`);
627627
err.stack = err.message; // omit stack
@@ -730,7 +730,7 @@ export async function main(argv, options) {
730730
? assemblyscript.getBinaryenModuleRef(module)
731731
: module.ref
732732
);
733-
var numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
733+
var numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
734734
if (numErrors) {
735735
const err = Error(`${numErrors} compile error(s)`);
736736
err.stack = err.message; // omit stack
@@ -743,7 +743,7 @@ export async function main(argv, options) {
743743
if (error) return prepareResult(error);
744744
}
745745

746-
numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
746+
numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
747747
if (numErrors) {
748748
const err = Error(`${numErrors} afterCompile error(s)`);
749749
err.stack = err.message; // omit stack
@@ -1123,17 +1123,22 @@ async function getConfig(file, baseDir, readFile) {
11231123
}
11241124

11251125
/** Checks diagnostics emitted so far for errors. */
1126-
export function checkDiagnostics(program, stderr, reportDiagnostic, useColors) {
1126+
export function checkDiagnostics(program, stderr, disableWarning, reportDiagnostic, useColors) {
11271127
if (typeof useColors === "undefined" && stderr) useColors = stderr.isTTY;
11281128
var numErrors = 0;
11291129
do {
11301130
let diagnostic = assemblyscript.nextDiagnostic(program);
11311131
if (!diagnostic) break;
11321132
if (stderr) {
1133-
stderr.write(
1134-
assemblyscript.formatDiagnostic(diagnostic, useColors, true) +
1135-
EOL + EOL
1136-
);
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+
}
11371142
}
11381143
if (reportDiagnostic) {
11391144
function wrapRange(range) {

Diff for: cli/options.json

+8-1
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)