MCPcopy
hub / github.com/graphql/graphiql / expect

Function expect

packages/codemirror-graphql/src/utils/jsonParse.ts:139–156  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

137}
138
139function expect(str: string) {
140 if (kind === str) {
141 lex();
142 return;
143 }
144
145 let found;
146 if (kind === 'EOF') {
147 found = '[end of file]';
148 } else if (end - start > 1) {
149 found = '`' + string.slice(start, end) + '`';
150 } else {
151 const match = string.slice(start).match(/^.+?\b/);
152 found = '`' + (match ? match[0] : string[start]) + '`';
153 }
154
155 throw syntaxError(`Expected ${str} but found ${found}.`);
156}
157
158type SyntaxErrorPosition = { start: number; end: number };
159

Callers 15

js-grammar.spec.tsFile · 0.85
jsonParseFunction · 0.85
parseObjFunction · 0.85
parseMemberFunction · 0.85
parseArrFunction · 0.85

Calls 2

syntaxErrorFunction · 0.85
lexFunction · 0.70

Tested by 4

expectEscapedStringFunction · 0.68
expectSuggestionsFunction · 0.68
tokenFunction · 0.68
eolFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…