Skip to content

Commit e7463ab

Browse files
committed
feat: add --disableWarning option to disable compilation warning
1 parent 1465322 commit e7463ab

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

cli/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ export async function main(argv, options) {
615615
stats.parseTime += stats.end(begin);
616616
}
617617
}
618-
const numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
618+
const numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
619619
if (numErrors) {
620620
const err = Error(`${numErrors} parse error(s)`);
621621
err.stack = err.message; // omit stack
@@ -724,7 +724,7 @@ export async function main(argv, options) {
724724
? assemblyscript.getBinaryenModuleRef(module)
725725
: module.ref
726726
);
727-
var numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
727+
var numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
728728
if (numErrors) {
729729
const err = Error(`${numErrors} compile error(s)`);
730730
err.stack = err.message; // omit stack
@@ -737,7 +737,7 @@ export async function main(argv, options) {
737737
if (error) return prepareResult(error);
738738
}
739739

740-
numErrors = checkDiagnostics(program, stderr, options.reportDiagnostic, stderrColors.enabled);
740+
numErrors = checkDiagnostics(program, stderr, opts.disableWarning, options.reportDiagnostic, stderrColors.enabled);
741741
if (numErrors) {
742742
const err = Error(`${numErrors} afterCompile error(s)`);
743743
err.stack = err.message; // omit stack
@@ -1117,17 +1117,23 @@ async function getConfig(file, baseDir, readFile) {
11171117
}
11181118

11191119
/** Checks diagnostics emitted so far for errors. */
1120-
export function checkDiagnostics(program, stderr, reportDiagnostic, useColors) {
1120+
export function checkDiagnostics(program, stderr, disableWarning, reportDiagnostic, useColors) {
11211121
if (typeof useColors === "undefined" && stderr) useColors = stderr.isTTY;
11221122
var numErrors = 0;
11231123
do {
11241124
let diagnostic = assemblyscript.nextDiagnostic(program);
11251125
if (!diagnostic) break;
11261126
if (stderr) {
1127-
stderr.write(
1128-
assemblyscript.formatDiagnostic(diagnostic, useColors, true) +
1129-
EOL + EOL
1130-
);
1127+
const checkWarningPrint = (diagnostic) => {
1128+
const code = assemblyscript.getDiagnosticCode(diagnostic);
1129+
if (disableWarning === undefined) return true;
1130+
if (disableWarning.length === 0) return false;
1131+
if (disableWarning.includes(code)) return false;
1132+
return true;
1133+
}
1134+
if (assemblyscript.isError(diagnostic) || checkWarningPrint(diagnostic)) {
1135+
stderr.write(assemblyscript.formatDiagnostic(diagnostic, useColors, true) + EOL + EOL);
1136+
}
11311137
}
11321138
if (reportDiagnostic) {
11331139
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 specified warning output",
319+
"not define specified warning number will disable all kinds of warning"
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)