Skip to content

Commit 287b545

Browse files
HerringtonDarkholmemhegazy
authored andcommitted
Fix #10967, allow boolean flags to have explicit value (#11798)
* Fix #10967, allow boolean flag to have explicit value * add commandLineParsing test for boolean flags
1 parent e38c004 commit 287b545

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,13 @@ namespace ts {
599599
i++;
600600
break;
601601
case "boolean":
602-
options[opt.name] = true;
602+
// boolean flag has optional value true, false, others
603+
let optValue = args[i];
604+
options[opt.name] = optValue !== "false";
605+
// consume next argument as boolean flag value
606+
if (optValue === "false" || optValue === "true") {
607+
i++;
608+
}
603609
break;
604610
case "string":
605611
options[opt.name] = args[i] || "";

src/harness/unittests/commandLineParsing.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="..\harness.ts" />
1+
/// <reference path="..\harness.ts" />
22
/// <reference path="..\..\compiler\commandLineParser.ts" />
33

44
namespace ts {
@@ -338,5 +338,38 @@ namespace ts {
338338
}
339339
});
340340
});
341+
342+
it("Parse explicit boolean flag value", () => {
343+
assertParseResult(["--strictNullChecks", "false", "0.ts"],
344+
{
345+
errors: [],
346+
fileNames: ["0.ts"],
347+
options: {
348+
strictNullChecks: false,
349+
}
350+
});
351+
});
352+
353+
it("Parse non boolean argument after boolean flag", () => {
354+
assertParseResult(["--noImplicitAny", "t", "0.ts"],
355+
{
356+
errors: [],
357+
fileNames: ["t", "0.ts"],
358+
options: {
359+
noImplicitAny: true,
360+
}
361+
});
362+
});
363+
364+
it("Parse implicit boolean flag value", () => {
365+
assertParseResult(["--strictNullChecks"],
366+
{
367+
errors: [],
368+
fileNames: [],
369+
options: {
370+
strictNullChecks: true,
371+
}
372+
});
373+
});
341374
});
342375
}

0 commit comments

Comments
 (0)