diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index a9f40ab053c..cd05bb0b2c8 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -530,14 +530,14 @@ namespace ts { } function parseListTypeOption(opt: CommandLineOptionOfListType, value: string): (number | string)[] { - const values = (value || "").split(",").filter(v => { return v != undefined; }); + const values = (value.trim() || "").split(","); switch (opt.element.type) { case "number": return ts.map(values, parseInt); case "string": return ts.map(values, v => v || ""); default: - return ts.map(values, v => parseCustomTypeOption(opt.element, v)).filter(v => { return v != undefined; }); + return ts.filter(ts.map(values, v => parseCustomTypeOption(opt.element, v)), v => !!v); } } } @@ -793,6 +793,6 @@ namespace ts { } function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: any[], basePath: string, errors: Diagnostic[]): any[] { - return ts.map(values, v => convertJsonOption(option.element, v, basePath, errors)).filter(v => { return v != undefined; }); + return ts.filter(ts.map(values, v => convertJsonOption(option.element, v, basePath, errors)), v => !!v); } } diff --git a/tests/cases/unittests/commandLineParsing.ts b/tests/cases/unittests/commandLineParsing.ts index a77d1e56494..275bba54f01 100644 --- a/tests/cases/unittests/commandLineParsing.ts +++ b/tests/cases/unittests/commandLineParsing.ts @@ -94,6 +94,26 @@ namespace ts { }); }); + it("Parse incorrect form of library flags with trailing white-space ", () => { + // --lib es5, es7 0.ts + assertParseResult(["--lib", "es5, ", "es7", "0.ts"], + { + errors: [{ + messageText: "", + category: ts.Diagnostics.Arguments_for_library_option_must_be_Colon_0.category, + code: ts.Diagnostics.Arguments_for_library_option_must_be_Colon_0.code, + + file: undefined, + start: undefined, + length: undefined, + }], + fileNames: ["es7", "0.ts"], + options: { + lib: ["lib.es5.d.ts"] + } + }); + }); + it("Parse multiple compiler flags with input files at the end", () => { // --lib es5,es6.symbol.wellknown --target es5 0.ts assertParseResult(["--lib", "es5,es6.symbol.wellknown", "--target", "es5", "0.ts"],