MCPcopy Index your code
hub / github.com/nodejs/node / convertPropertyValueToJson

Function convertPropertyValueToJson

test/fixtures/snapshot/typescript.js:41043–41125  ·  view source on GitHub ↗
(valueExpression, option)

Source from the content-addressed store, hash-verified

41041 return ts.filter(elements.map(function (element) { return convertPropertyValueToJson(element, elementOption); }), function (v) { return v !== undefined; });
41042 }
41043 function convertPropertyValueToJson(valueExpression, option) {
41044 var invalidReported;
41045 switch (valueExpression.kind) {
41046 case 110 /* SyntaxKind.TrueKeyword */:
41047 reportInvalidOptionValue(option && option.type !== "boolean");
41048 return validateValue(/*value*/ true);
41049 case 95 /* SyntaxKind.FalseKeyword */:
41050 reportInvalidOptionValue(option && option.type !== "boolean");
41051 return validateValue(/*value*/ false);
41052 case 104 /* SyntaxKind.NullKeyword */:
41053 reportInvalidOptionValue(option && option.name === "extends"); // "extends" is the only option we don't allow null/undefined for
41054 return validateValue(/*value*/ null); // eslint-disable-line no-null/no-null
41055 case 10 /* SyntaxKind.StringLiteral */:
41056 if (!isDoubleQuotedString(valueExpression)) {
41057 errors.push(ts.createDiagnosticForNodeInSourceFile(sourceFile, valueExpression, ts.Diagnostics.String_literal_with_double_quotes_expected));
41058 }
41059 reportInvalidOptionValue(option && (ts.isString(option.type) && option.type !== "string"));
41060 var text = valueExpression.text;
41061 if (option && !ts.isString(option.type)) {
41062 var customOption = option;
41063 // Validate custom option type
41064 if (!customOption.type.has(text.toLowerCase())) {
41065 errors.push(createDiagnosticForInvalidCustomType(customOption, function (message, arg0, arg1) { return ts.createDiagnosticForNodeInSourceFile(sourceFile, valueExpression, message, arg0, arg1); }));
41066 invalidReported = true;
41067 }
41068 }
41069 return validateValue(text);
41070 case 8 /* SyntaxKind.NumericLiteral */:
41071 reportInvalidOptionValue(option && option.type !== "number");
41072 return validateValue(Number(valueExpression.text));
41073 case 219 /* SyntaxKind.PrefixUnaryExpression */:
41074 if (valueExpression.operator !== 40 /* SyntaxKind.MinusToken */ || valueExpression.operand.kind !== 8 /* SyntaxKind.NumericLiteral */) {
41075 break; // not valid JSON syntax
41076 }
41077 reportInvalidOptionValue(option && option.type !== "number");
41078 return validateValue(-Number(valueExpression.operand.text));
41079 case 205 /* SyntaxKind.ObjectLiteralExpression */:
41080 reportInvalidOptionValue(option && option.type !== "object");
41081 var objectLiteralExpression = valueExpression;
41082 // Currently having element option declaration in the tsconfig with type "object"
41083 // determines if it needs onSetValidOptionKeyValueInParent callback or not
41084 // At moment there are only "compilerOptions", "typeAcquisition" and "typingOptions"
41085 // that satifies it and need it to modify options set in them (for normalizing file paths)
41086 // vs what we set in the json
41087 // If need arises, we can modify this interface and callbacks as needed
41088 if (option) {
41089 var _a = option, elementOptions = _a.elementOptions, extraKeyDiagnostics = _a.extraKeyDiagnostics, optionName = _a.name;
41090 return validateValue(convertObjectLiteralExpressionToJson(objectLiteralExpression, elementOptions, extraKeyDiagnostics, optionName));
41091 }
41092 else {
41093 return validateValue(convertObjectLiteralExpressionToJson(objectLiteralExpression, /* knownOptions*/ undefined,
41094 /*extraKeyDiagnosticMessage */ undefined, /*parentOption*/ undefined));
41095 }
41096 case 204 /* SyntaxKind.ArrayLiteralExpression */:
41097 reportInvalidOptionValue(option && option.type !== "list");
41098 return validateValue(convertArrayLiteralExpressionToJson(valueExpression.elements, option && option.element));
41099 }
41100 // Not in expected format

Callers 3

convertToObjectWorkerFunction · 0.85
_loop_4Function · 0.85

Calls 8

reportInvalidOptionValueFunction · 0.85
validateValueFunction · 0.85
isDoubleQuotedStringFunction · 0.85
hasMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected