MCPcopy
hub / github.com/microsoft/vscode / parse

Function parse

src/vs/base/common/json.ts:846–890  ·  view source on GitHub ↗
(text: string, errors: ParseError[] = [], options: ParseOptions = ParseOptions.DEFAULT)

Source from the content-addressed store, hash-verified

844 * Therefore always check the errors list to find out if the input was valid.
845 */
846export function parse(text: string, errors: ParseError[] = [], options: ParseOptions = ParseOptions.DEFAULT): any {
847 let currentProperty: string | null = null;
848 let currentParent: any = [];
849 const previousParents: any[] = [];
850
851 function onValue(value: unknown) {
852 if (Array.isArray(currentParent)) {
853 currentParent.push(value);
854 } else if (currentProperty !== null) {
855 currentParent[currentProperty] = value;
856 }
857 }
858
859 const visitor: JSONVisitor = {
860 onObjectBegin: () => {
861 const object = {};
862 onValue(object);
863 previousParents.push(currentParent);
864 currentParent = object;
865 currentProperty = null;
866 },
867 onObjectProperty: (name: string) => {
868 currentProperty = name;
869 },
870 onObjectEnd: () => {
871 currentParent = previousParents.pop();
872 },
873 onArrayBegin: () => {
874 const array: any[] = [];
875 onValue(array);
876 previousParents.push(currentParent);
877 currentParent = array;
878 currentProperty = null;
879 },
880 onArrayEnd: () => {
881 currentParent = previousParents.pop();
882 },
883 onLiteralValue: onValue,
884 onError: (error: ParseErrorCode, offset: number, length: number) => {
885 errors.push({ error, offset, length });
886 }
887 };
888 visit(text, visitor, options);
889 return currentParent[0];
890}
891
892
893/**

Callers 15

readArgvConfigSyncFunction · 0.90
writeFileFunction · 0.90
_readTasksJsonMethod · 0.90
doWriteConfigurationMethod · 0.90
runStepCommandMethod · 0.90
actionsMethod · 0.90
deserializeMethod · 0.90
deserializeMethod · 0.90
deserializeMethod · 0.90
_readConfigFileMethod · 0.90

Calls 4

onValueFunction · 0.70
visitFunction · 0.70
pushMethod · 0.65
popMethod · 0.45

Tested by 6

testConfigurationFunction · 0.72
parseOkFunction · 0.72
assertValidParseFunction · 0.72
assertInvalidParseFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…