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

Function convertToObjectWorker

test/fixtures/snapshot/typescript.js:40968–41129  ·  view source on GitHub ↗
(sourceFile, rootExpression, errors, returnValue, knownRootOptions, jsonConversionNotifier)

Source from the content-addressed store, hash-verified

40966 */
40967 /*@internal*/
40968 function convertToObjectWorker(sourceFile, rootExpression, errors, returnValue, knownRootOptions, jsonConversionNotifier) {
40969 if (!rootExpression) {
40970 return returnValue ? {} : undefined;
40971 }
40972 return convertPropertyValueToJson(rootExpression, knownRootOptions);
40973 function isRootOptionMap(knownOptions) {
40974 return knownRootOptions && knownRootOptions.elementOptions === knownOptions;
40975 }
40976 function convertObjectLiteralExpressionToJson(node, knownOptions, extraKeyDiagnostics, parentOption) {
40977 var result = returnValue ? {} : undefined;
40978 var _loop_4 = function (element) {
40979 if (element.kind !== 296 /* SyntaxKind.PropertyAssignment */) {
40980 errors.push(ts.createDiagnosticForNodeInSourceFile(sourceFile, element, ts.Diagnostics.Property_assignment_expected));
40981 return "continue";
40982 }
40983 if (element.questionToken) {
40984 errors.push(ts.createDiagnosticForNodeInSourceFile(sourceFile, element.questionToken, ts.Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, "?"));
40985 }
40986 if (!isDoubleQuotedString(element.name)) {
40987 errors.push(ts.createDiagnosticForNodeInSourceFile(sourceFile, element.name, ts.Diagnostics.String_literal_with_double_quotes_expected));
40988 }
40989 var textOfKey = ts.isComputedNonLiteralName(element.name) ? undefined : ts.getTextOfPropertyName(element.name);
40990 var keyText = textOfKey && ts.unescapeLeadingUnderscores(textOfKey);
40991 var option = keyText && knownOptions ? knownOptions.get(keyText) : undefined;
40992 if (keyText && extraKeyDiagnostics && !option) {
40993 if (knownOptions) {
40994 errors.push(createUnknownOptionError(keyText, extraKeyDiagnostics, function (message, arg0, arg1) { return ts.createDiagnosticForNodeInSourceFile(sourceFile, element.name, message, arg0, arg1); }));
40995 }
40996 else {
40997 errors.push(ts.createDiagnosticForNodeInSourceFile(sourceFile, element.name, extraKeyDiagnostics.unknownOptionDiagnostic, keyText));
40998 }
40999 }
41000 var value = convertPropertyValueToJson(element.initializer, option);
41001 if (typeof keyText !== "undefined") {
41002 if (returnValue) {
41003 result[keyText] = value;
41004 }
41005 // Notify key value set, if user asked for it
41006 if (jsonConversionNotifier &&
41007 // Current callbacks are only on known parent option or if we are setting values in the root
41008 (parentOption || isRootOptionMap(knownOptions))) {
41009 var isValidOptionValue = isCompilerOptionsValue(option, value);
41010 if (parentOption) {
41011 if (isValidOptionValue) {
41012 // Notify option set in the parent if its a valid option value
41013 jsonConversionNotifier.onSetValidOptionKeyValueInParent(parentOption, option, value);
41014 }
41015 }
41016 else if (isRootOptionMap(knownOptions)) {
41017 if (isValidOptionValue) {
41018 // Notify about the valid root key value being set
41019 jsonConversionNotifier.onSetValidOptionKeyValueInRoot(keyText, element.name, value, element.initializer);
41020 }
41021 else if (!option) {
41022 // Notify about the unknown root key value being set
41023 jsonConversionNotifier.onSetUnknownOptionKeyValueInRoot(keyText, element.name, value, element.initializer);
41024 }
41025 }

Callers 2

convertToObjectFunction · 0.85

Calls 1

Tested by

no test coverage detected