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

Function parseOptionValue

test/fixtures/snapshot/typescript.js:40613–40681  ·  view source on GitHub ↗
(args, i, diagnostics, opt, options, errors)

Source from the content-addressed store, hash-verified

40611 }
40612 ts.parseCommandLineWorker = parseCommandLineWorker;
40613 function parseOptionValue(args, i, diagnostics, opt, options, errors) {
40614 if (opt.isTSConfigOnly) {
40615 var optValue = args[i];
40616 if (optValue === "null") {
40617 options[opt.name] = undefined;
40618 i++;
40619 }
40620 else if (opt.type === "boolean") {
40621 if (optValue === "false") {
40622 options[opt.name] = validateJsonOptionValue(opt, /*value*/ false, errors);
40623 i++;
40624 }
40625 else {
40626 if (optValue === "true")
40627 i++;
40628 errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_false_or_null_on_command_line, opt.name));
40629 }
40630 }
40631 else {
40632 errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_null_on_command_line, opt.name));
40633 if (optValue && !ts.startsWith(optValue, "-"))
40634 i++;
40635 }
40636 }
40637 else {
40638 // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
40639 if (!args[i] && opt.type !== "boolean") {
40640 errors.push(ts.createCompilerDiagnostic(diagnostics.optionTypeMismatchDiagnostic, opt.name, getCompilerOptionValueTypeString(opt)));
40641 }
40642 if (args[i] !== "null") {
40643 switch (opt.type) {
40644 case "number":
40645 options[opt.name] = validateJsonOptionValue(opt, parseInt(args[i]), errors);
40646 i++;
40647 break;
40648 case "boolean":
40649 // boolean flag has optional value true, false, others
40650 var optValue = args[i];
40651 options[opt.name] = validateJsonOptionValue(opt, optValue !== "false", errors);
40652 // consume next argument as boolean flag value
40653 if (optValue === "false" || optValue === "true") {
40654 i++;
40655 }
40656 break;
40657 case "string":
40658 options[opt.name] = validateJsonOptionValue(opt, args[i] || "", errors);
40659 i++;
40660 break;
40661 case "list":
40662 var result = parseListTypeOption(opt, args[i], errors);
40663 options[opt.name] = result || [];
40664 if (result) {
40665 i++;
40666 }
40667 break;
40668 // If not a primitive, the possible types are specified in what is effectively a map of options.
40669 default:
40670 options[opt.name] = parseCustomTypeOption(opt, args[i], errors);

Callers 1

parseStringsFunction · 0.85

Calls 5

validateJsonOptionValueFunction · 0.85
parseListTypeOptionFunction · 0.85
parseCustomTypeOptionFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected