Skip to content

Fix #10967, allow boolean flags to have explicit value #11798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,13 @@ namespace ts {
i++;
break;
case "boolean":
options[opt.name] = true;
// boolean flag has optional value true, false, others
let optValue = args[i];
options[opt.name] = optValue !== "false";
// consume next argument as boolean flag value
if (optValue === "false" || optValue === "true") {
i++;
}
break;
case "string":
options[opt.name] = args[i] || "";
Expand Down
35 changes: 34 additions & 1 deletion src/harness/unittests/commandLineParsing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="..\harness.ts" />
/// <reference path="..\harness.ts" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the diff here? BOM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. -<U+FEFF>/// <reference path="..\harness.ts" /> reported in git command line

/// <reference path="..\..\compiler\commandLineParser.ts" />

namespace ts {
Expand Down Expand Up @@ -338,5 +338,38 @@ namespace ts {
}
});
});

it("Parse explicit boolean flag value", () => {
assertParseResult(["--strictNullChecks", "false", "0.ts"],
{
errors: [],
fileNames: ["0.ts"],
options: {
strictNullChecks: false,
}
});
});

it("Parse non boolean argument after boolean flag", () => {
assertParseResult(["--noImplicitAny", "t", "0.ts"],
{
errors: [],
fileNames: ["t", "0.ts"],
options: {
noImplicitAny: true,
}
});
});

it("Parse implicit boolean flag value", () => {
assertParseResult(["--strictNullChecks"],
{
errors: [],
fileNames: [],
options: {
strictNullChecks: true,
}
});
});
});
}