Skip to content

Commit 4895d16

Browse files
committed
convertToObject: handle negative numbers in JSON
Fixes: #19551
1 parent b5f292d commit 4895d16

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,13 @@ namespace ts {
11381138
reportInvalidOptionValue(option && option.type !== "number");
11391139
return Number((<NumericLiteral>valueExpression).text);
11401140

1141+
case SyntaxKind.PrefixUnaryExpression:
1142+
if ((<PrefixUnaryExpression>valueExpression).operator !== SyntaxKind.MinusToken || (<PrefixUnaryExpression>valueExpression).operand.kind !== SyntaxKind.NumericLiteral) {
1143+
break; // not valid JSON syntax
1144+
}
1145+
reportInvalidOptionValue(option && option.type !== "number");
1146+
return -Number((<NumericLiteral>(<PrefixUnaryExpression>valueExpression).operand).text);
1147+
11411148
case SyntaxKind.ObjectLiteralExpression:
11421149
reportInvalidOptionValue(option && option.type !== "object");
11431150
const objectLiteralExpression = <ObjectLiteralExpression>valueExpression;

src/harness/unittests/convertCompilerOptionsFromJson.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,24 @@ namespace ts {
421421
);
422422
});
423423

424+
it("Convert negative numbers in tsconfig.json ", () => {
425+
assertCompilerOptions(
426+
{
427+
"compilerOptions": {
428+
"allowJs": true,
429+
"maxNodeModuleJsDepth": -1
430+
}
431+
}, "tsconfig.json",
432+
{
433+
compilerOptions: {
434+
allowJs: true,
435+
maxNodeModuleJsDepth: -1
436+
},
437+
errors: []
438+
}
439+
);
440+
});
441+
424442
// jsconfig.json
425443
it("Convert correctly format jsconfig.json to compiler-options ", () => {
426444
assertCompilerOptions(

0 commit comments

Comments
 (0)