convertToObject: handle negative numbers in JSON

Fixes: #19551
This commit is contained in:
Klaus Meinhardt
2017-10-28 20:06:33 +02:00
parent b5f292d932
commit 4895d16645
2 changed files with 25 additions and 0 deletions

View File

@@ -1138,6 +1138,13 @@ namespace ts {
reportInvalidOptionValue(option && option.type !== "number");
return Number((<NumericLiteral>valueExpression).text);
case SyntaxKind.PrefixUnaryExpression:
if ((<PrefixUnaryExpression>valueExpression).operator !== SyntaxKind.MinusToken || (<PrefixUnaryExpression>valueExpression).operand.kind !== SyntaxKind.NumericLiteral) {
break; // not valid JSON syntax
}
reportInvalidOptionValue(option && option.type !== "number");
return -Number((<NumericLiteral>(<PrefixUnaryExpression>valueExpression).operand).text);
case SyntaxKind.ObjectLiteralExpression:
reportInvalidOptionValue(option && option.type !== "object");
const objectLiteralExpression = <ObjectLiteralExpression>valueExpression;

View File

@@ -421,6 +421,24 @@ namespace ts {
);
});
it("Convert negative numbers in tsconfig.json ", () => {
assertCompilerOptions(
{
"compilerOptions": {
"allowJs": true,
"maxNodeModuleJsDepth": -1
}
}, "tsconfig.json",
{
compilerOptions: {
allowJs: true,
maxNodeModuleJsDepth: -1
},
errors: []
}
);
});
// jsconfig.json
it("Convert correctly format jsconfig.json to compiler-options ", () => {
assertCompilerOptions(