graphql 14.4.2 → 14.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/README.md +5 -10
  2. package/error/GraphQLError.d.ts +87 -0
  3. package/error/GraphQLError.js +7 -45
  4. package/error/GraphQLError.js.flow +1 -0
  5. package/error/GraphQLError.mjs +7 -45
  6. package/error/formatError.d.ts +39 -0
  7. package/error/formatError.js +5 -2
  8. package/error/formatError.js.flow +27 -3
  9. package/error/formatError.mjs +5 -2
  10. package/error/index.d.ts +4 -0
  11. package/error/locatedError.d.ts +13 -0
  12. package/error/locatedError.js.flow +2 -1
  13. package/error/locatedError.mjs +1 -1
  14. package/error/syntaxError.d.ts +12 -0
  15. package/error/syntaxError.js.flow +1 -0
  16. package/execution/execute.d.ts +190 -0
  17. package/execution/execute.js +55 -89
  18. package/execution/execute.js.flow +95 -133
  19. package/execution/execute.mjs +75 -80
  20. package/execution/index.d.ts +11 -0
  21. package/execution/index.js +8 -6
  22. package/execution/index.js.flow +3 -6
  23. package/execution/index.mjs +2 -1
  24. package/execution/values.d.ts +68 -0
  25. package/execution/values.js +119 -128
  26. package/execution/values.js.flow +150 -127
  27. package/execution/values.mjs +117 -125
  28. package/graphql.d.ts +88 -0
  29. package/graphql.js +5 -5
  30. package/graphql.js.flow +9 -5
  31. package/graphql.mjs +41 -1
  32. package/index.d.ts +446 -0
  33. package/index.js +6 -0
  34. package/index.js.flow +3 -1
  35. package/index.mjs +2 -1
  36. package/jsutils/ObjMap.js.flow +6 -0
  37. package/jsutils/Path.d.ts +14 -0
  38. package/jsutils/Path.js +33 -0
  39. package/jsutils/Path.js.flow +26 -0
  40. package/jsutils/Path.mjs +24 -0
  41. package/jsutils/PromiseOrValue.d.ts +1 -0
  42. package/jsutils/dedent.js +6 -24
  43. package/jsutils/dedent.mjs +6 -24
  44. package/jsutils/defineToStringTag.js.flow +1 -1
  45. package/jsutils/devAssert.js +14 -0
  46. package/jsutils/devAssert.js.flow +8 -0
  47. package/jsutils/devAssert.mjs +7 -0
  48. package/jsutils/inspect.js +1 -1
  49. package/jsutils/inspect.js.flow +1 -1
  50. package/jsutils/inspect.mjs +1 -1
  51. package/jsutils/invariant.js +1 -2
  52. package/jsutils/invariant.js.flow +2 -3
  53. package/jsutils/invariant.mjs +1 -2
  54. package/jsutils/mapValue.js +6 -24
  55. package/jsutils/mapValue.js.flow +2 -1
  56. package/jsutils/mapValue.mjs +6 -24
  57. package/jsutils/printPathArray.js +15 -0
  58. package/jsutils/printPathArray.js.flow +14 -0
  59. package/jsutils/printPathArray.mjs +8 -0
  60. package/jsutils/suggestionList.js +14 -34
  61. package/jsutils/suggestionList.js.flow +4 -6
  62. package/jsutils/suggestionList.mjs +14 -34
  63. package/jsutils/toObjMap.js +28 -0
  64. package/jsutils/toObjMap.js.flow +26 -0
  65. package/jsutils/toObjMap.mjs +18 -0
  66. package/language/ast.d.ts +573 -0
  67. package/language/blockString.d.ts +21 -0
  68. package/language/directiveLocation.d.ts +35 -0
  69. package/language/index.d.ts +96 -0
  70. package/language/kinds.d.ts +77 -0
  71. package/language/lexer.d.ts +60 -0
  72. package/language/lexer.js +2 -12
  73. package/language/lexer.js.flow +6 -12
  74. package/language/lexer.mjs +1 -9
  75. package/language/location.d.ts +15 -0
  76. package/language/parser.d.ts +89 -0
  77. package/language/parser.js +1329 -1302
  78. package/language/parser.js.flow +1289 -1298
  79. package/language/parser.mjs +1326 -1297
  80. package/language/predicates.d.ts +36 -0
  81. package/language/predicates.js.flow +1 -1
  82. package/language/printLocation.d.ts +16 -0
  83. package/language/printLocation.js.flow +1 -1
  84. package/language/printer.d.ts +7 -0
  85. package/language/printer.js.flow +1 -1
  86. package/language/source.d.ts +19 -0
  87. package/language/source.js +3 -3
  88. package/language/source.js.flow +3 -3
  89. package/language/source.mjs +3 -3
  90. package/language/tokenKind.d.ts +35 -0
  91. package/language/visitor.d.ts +264 -0
  92. package/language/visitor.js +2 -2
  93. package/language/visitor.js.flow +3 -1
  94. package/language/visitor.mjs +2 -2
  95. package/package.json +1 -1
  96. package/polyfills/find.js +2 -2
  97. package/polyfills/find.js.flow +1 -2
  98. package/polyfills/find.mjs +2 -2
  99. package/polyfills/flatMap.js +3 -3
  100. package/polyfills/flatMap.js.flow +2 -3
  101. package/polyfills/flatMap.mjs +3 -3
  102. package/subscription/asyncIteratorReject.d.ts +6 -0
  103. package/subscription/index.d.ts +5 -0
  104. package/subscription/mapAsyncIterator.d.ts +9 -0
  105. package/subscription/mapAsyncIterator.js.flow +1 -0
  106. package/subscription/subscribe.d.ts +86 -0
  107. package/subscription/subscribe.js +29 -10
  108. package/subscription/subscribe.js.flow +45 -24
  109. package/subscription/subscribe.mjs +27 -9
  110. package/tsutils/Maybe.d.ts +4 -0
  111. package/type/definition.d.ts +805 -0
  112. package/type/definition.js +154 -70
  113. package/type/definition.js.flow +217 -160
  114. package/type/definition.mjs +149 -66
  115. package/type/directives.d.ts +72 -0
  116. package/type/directives.js +20 -12
  117. package/type/directives.js.flow +34 -19
  118. package/type/directives.mjs +17 -10
  119. package/type/index.d.ts +155 -0
  120. package/type/index.js.flow +2 -2
  121. package/type/introspection.d.ts +40 -0
  122. package/type/introspection.js +24 -10
  123. package/type/introspection.js.flow +29 -8
  124. package/type/introspection.mjs +23 -10
  125. package/type/scalars.d.ts +11 -0
  126. package/type/scalars.js +2 -2
  127. package/type/scalars.js.flow +4 -1
  128. package/type/scalars.mjs +2 -2
  129. package/type/schema.d.ts +108 -0
  130. package/type/schema.js +74 -151
  131. package/type/schema.js.flow +75 -73
  132. package/type/schema.mjs +75 -149
  133. package/type/validate.d.ts +19 -0
  134. package/type/validate.js +227 -486
  135. package/type/validate.js.flow +13 -8
  136. package/type/validate.mjs +218 -477
  137. package/utilities/TypeInfo.d.ts +49 -0
  138. package/utilities/TypeInfo.js.flow +9 -6
  139. package/utilities/assertValidName.d.ts +15 -0
  140. package/utilities/assertValidName.js +3 -3
  141. package/utilities/assertValidName.js.flow +3 -2
  142. package/utilities/assertValidName.mjs +2 -2
  143. package/utilities/astFromValue.d.ts +25 -0
  144. package/utilities/astFromValue.js +22 -38
  145. package/utilities/astFromValue.js.flow +7 -4
  146. package/utilities/astFromValue.mjs +19 -36
  147. package/utilities/buildASTSchema.d.ts +114 -0
  148. package/utilities/buildASTSchema.js +37 -68
  149. package/utilities/buildASTSchema.js.flow +32 -30
  150. package/utilities/buildASTSchema.mjs +32 -64
  151. package/utilities/buildClientSchema.d.ts +21 -0
  152. package/utilities/buildClientSchema.js +23 -15
  153. package/utilities/buildClientSchema.js.flow +17 -16
  154. package/utilities/buildClientSchema.mjs +20 -12
  155. package/utilities/coerceInputValue.d.ts +17 -0
  156. package/utilities/coerceInputValue.js +161 -0
  157. package/utilities/coerceInputValue.js.flow +214 -0
  158. package/utilities/coerceInputValue.mjs +142 -0
  159. package/utilities/coerceValue.d.ts +23 -0
  160. package/utilities/coerceValue.js +21 -199
  161. package/utilities/coerceValue.js.flow +31 -223
  162. package/utilities/coerceValue.mjs +20 -195
  163. package/utilities/concatAST.d.ts +8 -0
  164. package/utilities/concatAST.js.flow +1 -0
  165. package/utilities/extendSchema.d.ts +45 -0
  166. package/utilities/extendSchema.js +64 -131
  167. package/utilities/extendSchema.js.flow +27 -24
  168. package/utilities/extendSchema.mjs +61 -129
  169. package/utilities/findBreakingChanges.d.ts +64 -0
  170. package/utilities/findBreakingChanges.js +194 -619
  171. package/utilities/findBreakingChanges.js.flow +8 -5
  172. package/utilities/findBreakingChanges.mjs +194 -619
  173. package/utilities/findDeprecatedUsages.d.ts +13 -0
  174. package/utilities/findDeprecatedUsages.js.flow +4 -1
  175. package/utilities/getOperationAST.d.ts +12 -0
  176. package/utilities/getOperationAST.js +13 -31
  177. package/utilities/getOperationAST.mjs +13 -31
  178. package/utilities/getOperationRootType.d.ts +14 -0
  179. package/utilities/getOperationRootType.js.flow +2 -0
  180. package/utilities/index.d.ts +127 -0
  181. package/utilities/index.js +8 -0
  182. package/utilities/index.js.flow +4 -1
  183. package/utilities/index.mjs +3 -1
  184. package/utilities/introspectionFromSchema.d.ts +16 -0
  185. package/utilities/introspectionFromSchema.js +5 -3
  186. package/utilities/introspectionFromSchema.js.flow +4 -2
  187. package/utilities/introspectionFromSchema.mjs +4 -2
  188. package/utilities/introspectionQuery.d.ts +177 -0
  189. package/utilities/isValidJSValue.d.ts +8 -0
  190. package/utilities/isValidJSValue.js +1 -1
  191. package/utilities/isValidJSValue.js.flow +3 -2
  192. package/utilities/isValidJSValue.mjs +2 -2
  193. package/utilities/isValidLiteralValue.d.ts +15 -0
  194. package/utilities/isValidLiteralValue.js +4 -4
  195. package/utilities/isValidLiteralValue.js.flow +8 -4
  196. package/utilities/isValidLiteralValue.mjs +2 -2
  197. package/utilities/lexicographicSortSchema.d.ts +6 -0
  198. package/utilities/lexicographicSortSchema.js +11 -8
  199. package/utilities/lexicographicSortSchema.js.flow +5 -3
  200. package/utilities/lexicographicSortSchema.mjs +9 -7
  201. package/utilities/schemaPrinter.d.ts +30 -0
  202. package/utilities/schemaPrinter.js +15 -32
  203. package/utilities/schemaPrinter.js.flow +14 -10
  204. package/utilities/schemaPrinter.mjs +14 -32
  205. package/utilities/separateOperations.d.ts +11 -0
  206. package/utilities/separateOperations.js +6 -6
  207. package/utilities/separateOperations.js.flow +2 -1
  208. package/utilities/separateOperations.mjs +6 -6
  209. package/utilities/stripIgnoredCharacters.d.ts +55 -0
  210. package/utilities/stripIgnoredCharacters.js.flow +1 -0
  211. package/utilities/typeComparators.d.ts +32 -0
  212. package/utilities/typeComparators.js.flow +1 -1
  213. package/utilities/typeComparators.mjs +1 -1
  214. package/utilities/typeFromAST.d.ts +29 -0
  215. package/utilities/typeFromAST.js +5 -3
  216. package/utilities/typeFromAST.js.flow +5 -3
  217. package/utilities/typeFromAST.mjs +14 -3
  218. package/utilities/valueFromAST.d.ts +29 -0
  219. package/utilities/valueFromAST.js +40 -74
  220. package/utilities/valueFromAST.js.flow +7 -4
  221. package/utilities/valueFromAST.mjs +39 -74
  222. package/utilities/valueFromASTUntyped.d.ts +23 -0
  223. package/utilities/valueFromASTUntyped.js +4 -3
  224. package/utilities/valueFromASTUntyped.js.flow +3 -2
  225. package/utilities/valueFromASTUntyped.mjs +3 -3
  226. package/validation/ValidationContext.d.ts +96 -0
  227. package/validation/ValidationContext.js +38 -86
  228. package/validation/ValidationContext.js.flow +22 -7
  229. package/validation/ValidationContext.mjs +37 -85
  230. package/validation/index.d.ts +126 -0
  231. package/validation/rules/ExecutableDefinitions.d.ts +14 -0
  232. package/validation/rules/ExecutableDefinitions.js +4 -23
  233. package/validation/rules/ExecutableDefinitions.js.flow +4 -2
  234. package/validation/rules/ExecutableDefinitions.mjs +4 -23
  235. package/validation/rules/FieldsOnCorrectType.d.ts +17 -0
  236. package/validation/rules/FieldsOnCorrectType.js +21 -57
  237. package/validation/rules/FieldsOnCorrectType.js.flow +7 -3
  238. package/validation/rules/FieldsOnCorrectType.mjs +21 -57
  239. package/validation/rules/FragmentsOnCompositeTypes.d.ts +20 -0
  240. package/validation/rules/FragmentsOnCompositeTypes.js.flow +5 -1
  241. package/validation/rules/KnownArgumentNames.d.ts +28 -0
  242. package/validation/rules/KnownArgumentNames.js +26 -79
  243. package/validation/rules/KnownArgumentNames.js.flow +10 -6
  244. package/validation/rules/KnownArgumentNames.mjs +22 -75
  245. package/validation/rules/KnownDirectives.d.ts +19 -0
  246. package/validation/rules/KnownDirectives.js +12 -48
  247. package/validation/rules/KnownDirectives.js.flow +8 -5
  248. package/validation/rules/KnownDirectives.mjs +12 -48
  249. package/validation/rules/KnownFragmentNames.d.ts +12 -0
  250. package/validation/rules/KnownFragmentNames.js.flow +2 -1
  251. package/validation/rules/KnownTypeNames.d.ts +15 -0
  252. package/validation/rules/KnownTypeNames.js +6 -24
  253. package/validation/rules/KnownTypeNames.js.flow +10 -6
  254. package/validation/rules/KnownTypeNames.mjs +6 -24
  255. package/validation/rules/LoneAnonymousOperation.d.ts +14 -0
  256. package/validation/rules/LoneAnonymousOperation.js.flow +3 -1
  257. package/validation/rules/LoneSchemaDefinition.d.ts +13 -0
  258. package/validation/rules/LoneSchemaDefinition.js.flow +2 -1
  259. package/validation/rules/NoFragmentCycles.d.ts +9 -0
  260. package/validation/rules/NoFragmentCycles.js +17 -35
  261. package/validation/rules/NoFragmentCycles.js.flow +4 -2
  262. package/validation/rules/NoFragmentCycles.mjs +17 -35
  263. package/validation/rules/NoUndefinedVariables.d.ts +16 -0
  264. package/validation/rules/NoUndefinedVariables.js +6 -24
  265. package/validation/rules/NoUndefinedVariables.js.flow +2 -1
  266. package/validation/rules/NoUndefinedVariables.mjs +6 -24
  267. package/validation/rules/NoUnusedFragments.d.ts +12 -0
  268. package/validation/rules/NoUnusedFragments.js +7 -25
  269. package/validation/rules/NoUnusedFragments.js.flow +2 -1
  270. package/validation/rules/NoUnusedFragments.mjs +7 -25
  271. package/validation/rules/NoUnusedVariables.d.ts +16 -0
  272. package/validation/rules/NoUnusedVariables.js +6 -24
  273. package/validation/rules/NoUnusedVariables.js.flow +2 -1
  274. package/validation/rules/NoUnusedVariables.mjs +6 -24
  275. package/validation/rules/OverlappingFieldsCanBeMerged.d.ts +24 -0
  276. package/validation/rules/OverlappingFieldsCanBeMerged.js +27 -46
  277. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +17 -8
  278. package/validation/rules/OverlappingFieldsCanBeMerged.mjs +25 -44
  279. package/validation/rules/PossibleFragmentSpreads.d.ts +22 -0
  280. package/validation/rules/PossibleFragmentSpreads.js +2 -2
  281. package/validation/rules/PossibleFragmentSpreads.js.flow +8 -3
  282. package/validation/rules/PossibleFragmentSpreads.mjs +2 -2
  283. package/validation/rules/PossibleTypeExtensions.d.ts +21 -0
  284. package/validation/rules/PossibleTypeExtensions.js +4 -22
  285. package/validation/rules/PossibleTypeExtensions.js.flow +6 -2
  286. package/validation/rules/PossibleTypeExtensions.mjs +4 -22
  287. package/validation/rules/ProvidedRequiredArguments.d.ts +29 -0
  288. package/validation/rules/ProvidedRequiredArguments.js +27 -79
  289. package/validation/rules/ProvidedRequiredArguments.js.flow +12 -8
  290. package/validation/rules/ProvidedRequiredArguments.mjs +25 -77
  291. package/validation/rules/ScalarLeafs.d.ts +20 -0
  292. package/validation/rules/ScalarLeafs.js.flow +6 -2
  293. package/validation/rules/SingleFieldSubscriptions.d.ts +14 -0
  294. package/validation/rules/SingleFieldSubscriptions.js.flow +4 -2
  295. package/validation/rules/UniqueArgumentNames.d.ts +12 -0
  296. package/validation/rules/UniqueArgumentNames.js.flow +2 -1
  297. package/validation/rules/UniqueDirectiveNames.d.ts +13 -0
  298. package/validation/rules/UniqueDirectiveNames.js.flow +2 -1
  299. package/validation/rules/UniqueDirectivesPerLocation.d.ts +14 -0
  300. package/validation/rules/UniqueDirectivesPerLocation.js +15 -69
  301. package/validation/rules/UniqueDirectivesPerLocation.js.flow +7 -4
  302. package/validation/rules/UniqueDirectivesPerLocation.mjs +15 -69
  303. package/validation/rules/UniqueEnumValueNames.d.ts +19 -0
  304. package/validation/rules/UniqueEnumValueNames.js +10 -28
  305. package/validation/rules/UniqueEnumValueNames.js.flow +2 -1
  306. package/validation/rules/UniqueEnumValueNames.mjs +10 -28
  307. package/validation/rules/UniqueFieldDefinitionNames.d.ts +21 -0
  308. package/validation/rules/UniqueFieldDefinitionNames.js +9 -27
  309. package/validation/rules/UniqueFieldDefinitionNames.js.flow +2 -1
  310. package/validation/rules/UniqueFieldDefinitionNames.mjs +9 -27
  311. package/validation/rules/UniqueFragmentNames.d.ts +11 -0
  312. package/validation/rules/UniqueFragmentNames.js.flow +2 -1
  313. package/validation/rules/UniqueInputFieldNames.d.ts +14 -0
  314. package/validation/rules/UniqueInputFieldNames.js.flow +2 -1
  315. package/validation/rules/UniqueOperationNames.d.ts +11 -0
  316. package/validation/rules/UniqueOperationNames.js.flow +2 -1
  317. package/validation/rules/UniqueOperationTypes.d.ts +13 -0
  318. package/validation/rules/UniqueOperationTypes.js +11 -30
  319. package/validation/rules/UniqueOperationTypes.js.flow +2 -1
  320. package/validation/rules/UniqueOperationTypes.mjs +10 -29
  321. package/validation/rules/UniqueTypeNames.d.ts +13 -0
  322. package/validation/rules/UniqueTypeNames.js.flow +3 -1
  323. package/validation/rules/UniqueVariableNames.d.ts +11 -0
  324. package/validation/rules/UniqueVariableNames.js.flow +4 -2
  325. package/validation/rules/ValuesOfCorrectType.d.ts +34 -0
  326. package/validation/rules/ValuesOfCorrectType.js +16 -34
  327. package/validation/rules/ValuesOfCorrectType.js.flow +11 -6
  328. package/validation/rules/ValuesOfCorrectType.mjs +12 -30
  329. package/validation/rules/VariablesAreInputTypes.d.ts +15 -0
  330. package/validation/rules/VariablesAreInputTypes.js.flow +6 -2
  331. package/validation/rules/VariablesInAllowedPosition.d.ts +15 -0
  332. package/validation/rules/VariablesInAllowedPosition.js +22 -40
  333. package/validation/rules/VariablesInAllowedPosition.js.flow +8 -3
  334. package/validation/rules/VariablesInAllowedPosition.mjs +18 -36
  335. package/validation/specifiedRules.d.ts +98 -0
  336. package/validation/validate.d.ts +56 -0
  337. package/validation/validate.js +35 -7
  338. package/validation/validate.js.flow +51 -9
  339. package/validation/validate.mjs +30 -7
  340. package/version.d.ts +14 -0
  341. package/version.js +3 -3
  342. package/version.js.flow +3 -3
  343. package/version.mjs +3 -3
@@ -6,26 +6,25 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.parse = parse;
7
7
  exports.parseValue = parseValue;
8
8
  exports.parseType = parseType;
9
- exports.parseConstValue = parseConstValue;
10
- exports.parseTypeReference = parseTypeReference;
11
- exports.parseNamedType = parseNamedType;
12
9
 
13
10
  var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
14
11
 
15
- var _defineToJSON = _interopRequireDefault(require("../jsutils/defineToJSON"));
12
+ var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
16
13
 
17
- var _source = require("./source");
14
+ var _defineToJSON = _interopRequireDefault(require("../jsutils/defineToJSON"));
18
15
 
19
16
  var _syntaxError = require("../error/syntaxError");
20
17
 
21
- var _tokenKind = require("./tokenKind");
18
+ var _kinds = require("./kinds");
22
19
 
23
- var _lexer = require("./lexer");
20
+ var _source = require("./source");
24
21
 
25
- var _kinds = require("./kinds");
22
+ var _lexer = require("./lexer");
26
23
 
27
24
  var _directiveLocation = require("./directiveLocation");
28
25
 
26
+ var _tokenKind = require("./tokenKind");
27
+
29
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
29
 
31
30
  /**
@@ -33,14 +32,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
32
  * Throws GraphQLError if a syntax error is encountered.
34
33
  */
35
34
  function parse(source, options) {
36
- var sourceObj = typeof source === 'string' ? new _source.Source(source) : source;
37
-
38
- if (!(sourceObj instanceof _source.Source)) {
39
- throw new TypeError("Must provide Source. Received: ".concat((0, _inspect.default)(sourceObj)));
40
- }
41
-
42
- var lexer = (0, _lexer.createLexer)(sourceObj, options || {});
43
- return parseDocument(lexer);
35
+ var parser = new Parser(source, options);
36
+ return parser.parseDocument();
44
37
  }
45
38
  /**
46
39
  * Given a string containing a GraphQL value (ex. `[42]`), parse the AST for
@@ -55,11 +48,10 @@ function parse(source, options) {
55
48
 
56
49
 
57
50
  function parseValue(source, options) {
58
- var sourceObj = typeof source === 'string' ? new _source.Source(source) : source;
59
- var lexer = (0, _lexer.createLexer)(sourceObj, options || {});
60
- expectToken(lexer, _tokenKind.TokenKind.SOF);
61
- var value = parseValueLiteral(lexer, false);
62
- expectToken(lexer, _tokenKind.TokenKind.EOF);
51
+ var parser = new Parser(source, options);
52
+ parser.expectToken(_tokenKind.TokenKind.SOF);
53
+ var value = parser.parseValueLiteral(false);
54
+ parser.expectToken(_tokenKind.TokenKind.EOF);
63
55
  return value;
64
56
  }
65
57
  /**
@@ -75,1319 +67,1462 @@ function parseValue(source, options) {
75
67
 
76
68
 
77
69
  function parseType(source, options) {
78
- var sourceObj = typeof source === 'string' ? new _source.Source(source) : source;
79
- var lexer = (0, _lexer.createLexer)(sourceObj, options || {});
80
- expectToken(lexer, _tokenKind.TokenKind.SOF);
81
- var type = parseTypeReference(lexer);
82
- expectToken(lexer, _tokenKind.TokenKind.EOF);
70
+ var parser = new Parser(source, options);
71
+ parser.expectToken(_tokenKind.TokenKind.SOF);
72
+ var type = parser.parseTypeReference();
73
+ parser.expectToken(_tokenKind.TokenKind.EOF);
83
74
  return type;
84
75
  }
85
- /**
86
- * Converts a name lex token into a name parse node.
87
- */
88
76
 
77
+ var Parser =
78
+ /*#__PURE__*/
79
+ function () {
80
+ function Parser(source, options) {
81
+ var sourceObj = typeof source === 'string' ? new _source.Source(source) : source;
82
+ sourceObj instanceof _source.Source || (0, _devAssert.default)(0, "Must provide Source. Received: ".concat((0, _inspect.default)(sourceObj)));
83
+ this._lexer = (0, _lexer.createLexer)(sourceObj);
84
+ this._options = options || {};
85
+ }
86
+ /**
87
+ * Converts a name lex token into a name parse node.
88
+ */
89
89
 
90
- function parseName(lexer) {
91
- var token = expectToken(lexer, _tokenKind.TokenKind.NAME);
92
- return {
93
- kind: _kinds.Kind.NAME,
94
- value: token.value,
95
- loc: loc(lexer, token)
96
- };
97
- } // Implements the parsing rules in the Document section.
98
-
99
- /**
100
- * Document : Definition+
101
- */
102
90
 
91
+ var _proto = Parser.prototype;
103
92
 
104
- function parseDocument(lexer) {
105
- var start = lexer.token;
106
- return {
107
- kind: _kinds.Kind.DOCUMENT,
108
- definitions: many(lexer, _tokenKind.TokenKind.SOF, parseDefinition, _tokenKind.TokenKind.EOF),
109
- loc: loc(lexer, start)
110
- };
111
- }
112
- /**
113
- * Definition :
114
- * - ExecutableDefinition
115
- * - TypeSystemDefinition
116
- * - TypeSystemExtension
117
- */
93
+ _proto.parseName = function parseName() {
94
+ var token = this.expectToken(_tokenKind.TokenKind.NAME);
95
+ return {
96
+ kind: _kinds.Kind.NAME,
97
+ value: token.value,
98
+ loc: this.loc(token)
99
+ };
100
+ } // Implements the parsing rules in the Document section.
118
101
 
102
+ /**
103
+ * Document : Definition+
104
+ */
105
+ ;
119
106
 
120
- function parseDefinition(lexer) {
121
- if (peek(lexer, _tokenKind.TokenKind.NAME)) {
122
- switch (lexer.token.value) {
123
- case 'query':
124
- case 'mutation':
125
- case 'subscription':
126
- case 'fragment':
127
- return parseExecutableDefinition(lexer);
128
-
129
- case 'schema':
130
- case 'scalar':
131
- case 'type':
132
- case 'interface':
133
- case 'union':
134
- case 'enum':
135
- case 'input':
136
- case 'directive':
137
- return parseTypeSystemDefinition(lexer);
138
-
139
- case 'extend':
140
- return parseTypeSystemExtension(lexer);
141
- }
142
- } else if (peek(lexer, _tokenKind.TokenKind.BRACE_L)) {
143
- return parseExecutableDefinition(lexer);
144
- } else if (peekDescription(lexer)) {
145
- return parseTypeSystemDefinition(lexer);
107
+ _proto.parseDocument = function parseDocument() {
108
+ var start = this._lexer.token;
109
+ return {
110
+ kind: _kinds.Kind.DOCUMENT,
111
+ definitions: this.many(_tokenKind.TokenKind.SOF, this.parseDefinition, _tokenKind.TokenKind.EOF),
112
+ loc: this.loc(start)
113
+ };
146
114
  }
115
+ /**
116
+ * Definition :
117
+ * - ExecutableDefinition
118
+ * - TypeSystemDefinition
119
+ * - TypeSystemExtension
120
+ *
121
+ * ExecutableDefinition :
122
+ * - OperationDefinition
123
+ * - FragmentDefinition
124
+ */
125
+ ;
126
+
127
+ _proto.parseDefinition = function parseDefinition() {
128
+ if (this.peek(_tokenKind.TokenKind.NAME)) {
129
+ switch (this._lexer.token.value) {
130
+ case 'query':
131
+ case 'mutation':
132
+ case 'subscription':
133
+ return this.parseOperationDefinition();
134
+
135
+ case 'fragment':
136
+ return this.parseFragmentDefinition();
137
+
138
+ case 'schema':
139
+ case 'scalar':
140
+ case 'type':
141
+ case 'interface':
142
+ case 'union':
143
+ case 'enum':
144
+ case 'input':
145
+ case 'directive':
146
+ return this.parseTypeSystemDefinition();
147
+
148
+ case 'extend':
149
+ return this.parseTypeSystemExtension();
150
+ }
151
+ } else if (this.peek(_tokenKind.TokenKind.BRACE_L)) {
152
+ return this.parseOperationDefinition();
153
+ } else if (this.peekDescription()) {
154
+ return this.parseTypeSystemDefinition();
155
+ }
147
156
 
148
- throw unexpected(lexer);
149
- }
150
- /**
151
- * ExecutableDefinition :
152
- * - OperationDefinition
153
- * - FragmentDefinition
154
- */
157
+ throw this.unexpected();
158
+ } // Implements the parsing rules in the Operations section.
155
159
 
160
+ /**
161
+ * OperationDefinition :
162
+ * - SelectionSet
163
+ * - OperationType Name? VariableDefinitions? Directives? SelectionSet
164
+ */
165
+ ;
156
166
 
157
- function parseExecutableDefinition(lexer) {
158
- if (peek(lexer, _tokenKind.TokenKind.NAME)) {
159
- switch (lexer.token.value) {
160
- case 'query':
161
- case 'mutation':
162
- case 'subscription':
163
- return parseOperationDefinition(lexer);
167
+ _proto.parseOperationDefinition = function parseOperationDefinition() {
168
+ var start = this._lexer.token;
164
169
 
165
- case 'fragment':
166
- return parseFragmentDefinition(lexer);
170
+ if (this.peek(_tokenKind.TokenKind.BRACE_L)) {
171
+ return {
172
+ kind: _kinds.Kind.OPERATION_DEFINITION,
173
+ operation: 'query',
174
+ name: undefined,
175
+ variableDefinitions: [],
176
+ directives: [],
177
+ selectionSet: this.parseSelectionSet(),
178
+ loc: this.loc(start)
179
+ };
167
180
  }
168
- } else if (peek(lexer, _tokenKind.TokenKind.BRACE_L)) {
169
- return parseOperationDefinition(lexer);
170
- }
171
-
172
- throw unexpected(lexer);
173
- } // Implements the parsing rules in the Operations section.
174
-
175
- /**
176
- * OperationDefinition :
177
- * - SelectionSet
178
- * - OperationType Name? VariableDefinitions? Directives? SelectionSet
179
- */
180
181
 
182
+ var operation = this.parseOperationType();
183
+ var name;
181
184
 
182
- function parseOperationDefinition(lexer) {
183
- var start = lexer.token;
185
+ if (this.peek(_tokenKind.TokenKind.NAME)) {
186
+ name = this.parseName();
187
+ }
184
188
 
185
- if (peek(lexer, _tokenKind.TokenKind.BRACE_L)) {
186
189
  return {
187
190
  kind: _kinds.Kind.OPERATION_DEFINITION,
188
- operation: 'query',
189
- name: undefined,
190
- variableDefinitions: [],
191
- directives: [],
192
- selectionSet: parseSelectionSet(lexer),
193
- loc: loc(lexer, start)
191
+ operation: operation,
192
+ name: name,
193
+ variableDefinitions: this.parseVariableDefinitions(),
194
+ directives: this.parseDirectives(false),
195
+ selectionSet: this.parseSelectionSet(),
196
+ loc: this.loc(start)
194
197
  };
195
198
  }
199
+ /**
200
+ * OperationType : one of query mutation subscription
201
+ */
202
+ ;
196
203
 
197
- var operation = parseOperationType(lexer);
198
- var name;
199
-
200
- if (peek(lexer, _tokenKind.TokenKind.NAME)) {
201
- name = parseName(lexer);
202
- }
203
-
204
- return {
205
- kind: _kinds.Kind.OPERATION_DEFINITION,
206
- operation: operation,
207
- name: name,
208
- variableDefinitions: parseVariableDefinitions(lexer),
209
- directives: parseDirectives(lexer, false),
210
- selectionSet: parseSelectionSet(lexer),
211
- loc: loc(lexer, start)
212
- };
213
- }
214
- /**
215
- * OperationType : one of query mutation subscription
216
- */
217
-
204
+ _proto.parseOperationType = function parseOperationType() {
205
+ var operationToken = this.expectToken(_tokenKind.TokenKind.NAME);
218
206
 
219
- function parseOperationType(lexer) {
220
- var operationToken = expectToken(lexer, _tokenKind.TokenKind.NAME);
207
+ switch (operationToken.value) {
208
+ case 'query':
209
+ return 'query';
221
210
 
222
- switch (operationToken.value) {
223
- case 'query':
224
- return 'query';
211
+ case 'mutation':
212
+ return 'mutation';
225
213
 
226
- case 'mutation':
227
- return 'mutation';
214
+ case 'subscription':
215
+ return 'subscription';
216
+ }
228
217
 
229
- case 'subscription':
230
- return 'subscription';
218
+ throw this.unexpected(operationToken);
231
219
  }
220
+ /**
221
+ * VariableDefinitions : ( VariableDefinition+ )
222
+ */
223
+ ;
232
224
 
233
- throw unexpected(lexer, operationToken);
234
- }
235
- /**
236
- * VariableDefinitions : ( VariableDefinition+ )
237
- */
238
-
225
+ _proto.parseVariableDefinitions = function parseVariableDefinitions() {
226
+ return this.optionalMany(_tokenKind.TokenKind.PAREN_L, this.parseVariableDefinition, _tokenKind.TokenKind.PAREN_R);
227
+ }
228
+ /**
229
+ * VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
230
+ */
231
+ ;
239
232
 
240
- function parseVariableDefinitions(lexer) {
241
- return peek(lexer, _tokenKind.TokenKind.PAREN_L) ? many(lexer, _tokenKind.TokenKind.PAREN_L, parseVariableDefinition, _tokenKind.TokenKind.PAREN_R) : [];
242
- }
243
- /**
244
- * VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
245
- */
233
+ _proto.parseVariableDefinition = function parseVariableDefinition() {
234
+ var start = this._lexer.token;
235
+ return {
236
+ kind: _kinds.Kind.VARIABLE_DEFINITION,
237
+ variable: this.parseVariable(),
238
+ type: (this.expectToken(_tokenKind.TokenKind.COLON), this.parseTypeReference()),
239
+ defaultValue: this.expectOptionalToken(_tokenKind.TokenKind.EQUALS) ? this.parseValueLiteral(true) : undefined,
240
+ directives: this.parseDirectives(true),
241
+ loc: this.loc(start)
242
+ };
243
+ }
244
+ /**
245
+ * Variable : $ Name
246
+ */
247
+ ;
248
+
249
+ _proto.parseVariable = function parseVariable() {
250
+ var start = this._lexer.token;
251
+ this.expectToken(_tokenKind.TokenKind.DOLLAR);
252
+ return {
253
+ kind: _kinds.Kind.VARIABLE,
254
+ name: this.parseName(),
255
+ loc: this.loc(start)
256
+ };
257
+ }
258
+ /**
259
+ * SelectionSet : { Selection+ }
260
+ */
261
+ ;
246
262
 
263
+ _proto.parseSelectionSet = function parseSelectionSet() {
264
+ var start = this._lexer.token;
265
+ return {
266
+ kind: _kinds.Kind.SELECTION_SET,
267
+ selections: this.many(_tokenKind.TokenKind.BRACE_L, this.parseSelection, _tokenKind.TokenKind.BRACE_R),
268
+ loc: this.loc(start)
269
+ };
270
+ }
271
+ /**
272
+ * Selection :
273
+ * - Field
274
+ * - FragmentSpread
275
+ * - InlineFragment
276
+ */
277
+ ;
278
+
279
+ _proto.parseSelection = function parseSelection() {
280
+ return this.peek(_tokenKind.TokenKind.SPREAD) ? this.parseFragment() : this.parseField();
281
+ }
282
+ /**
283
+ * Field : Alias? Name Arguments? Directives? SelectionSet?
284
+ *
285
+ * Alias : Name :
286
+ */
287
+ ;
288
+
289
+ _proto.parseField = function parseField() {
290
+ var start = this._lexer.token;
291
+ var nameOrAlias = this.parseName();
292
+ var alias;
293
+ var name;
294
+
295
+ if (this.expectOptionalToken(_tokenKind.TokenKind.COLON)) {
296
+ alias = nameOrAlias;
297
+ name = this.parseName();
298
+ } else {
299
+ name = nameOrAlias;
300
+ }
247
301
 
248
- function parseVariableDefinition(lexer) {
249
- var start = lexer.token;
250
- return {
251
- kind: _kinds.Kind.VARIABLE_DEFINITION,
252
- variable: parseVariable(lexer),
253
- type: (expectToken(lexer, _tokenKind.TokenKind.COLON), parseTypeReference(lexer)),
254
- defaultValue: expectOptionalToken(lexer, _tokenKind.TokenKind.EQUALS) ? parseValueLiteral(lexer, true) : undefined,
255
- directives: parseDirectives(lexer, true),
256
- loc: loc(lexer, start)
302
+ return {
303
+ kind: _kinds.Kind.FIELD,
304
+ alias: alias,
305
+ name: name,
306
+ arguments: this.parseArguments(false),
307
+ directives: this.parseDirectives(false),
308
+ selectionSet: this.peek(_tokenKind.TokenKind.BRACE_L) ? this.parseSelectionSet() : undefined,
309
+ loc: this.loc(start)
310
+ };
311
+ }
312
+ /**
313
+ * Arguments[Const] : ( Argument[?Const]+ )
314
+ */
315
+ ;
316
+
317
+ _proto.parseArguments = function parseArguments(isConst) {
318
+ var item = isConst ? this.parseConstArgument : this.parseArgument;
319
+ return this.optionalMany(_tokenKind.TokenKind.PAREN_L, item, _tokenKind.TokenKind.PAREN_R);
320
+ }
321
+ /**
322
+ * Argument[Const] : Name : Value[?Const]
323
+ */
324
+ ;
325
+
326
+ _proto.parseArgument = function parseArgument() {
327
+ var start = this._lexer.token;
328
+ var name = this.parseName();
329
+ this.expectToken(_tokenKind.TokenKind.COLON);
330
+ return {
331
+ kind: _kinds.Kind.ARGUMENT,
332
+ name: name,
333
+ value: this.parseValueLiteral(false),
334
+ loc: this.loc(start)
335
+ };
257
336
  };
258
- }
259
- /**
260
- * Variable : $ Name
261
- */
262
337
 
338
+ _proto.parseConstArgument = function parseConstArgument() {
339
+ var start = this._lexer.token;
340
+ return {
341
+ kind: _kinds.Kind.ARGUMENT,
342
+ name: this.parseName(),
343
+ value: (this.expectToken(_tokenKind.TokenKind.COLON), this.parseValueLiteral(true)),
344
+ loc: this.loc(start)
345
+ };
346
+ } // Implements the parsing rules in the Fragments section.
347
+
348
+ /**
349
+ * Corresponds to both FragmentSpread and InlineFragment in the spec.
350
+ *
351
+ * FragmentSpread : ... FragmentName Directives?
352
+ *
353
+ * InlineFragment : ... TypeCondition? Directives? SelectionSet
354
+ */
355
+ ;
356
+
357
+ _proto.parseFragment = function parseFragment() {
358
+ var start = this._lexer.token;
359
+ this.expectToken(_tokenKind.TokenKind.SPREAD);
360
+ var hasTypeCondition = this.expectOptionalKeyword('on');
361
+
362
+ if (!hasTypeCondition && this.peek(_tokenKind.TokenKind.NAME)) {
363
+ return {
364
+ kind: _kinds.Kind.FRAGMENT_SPREAD,
365
+ name: this.parseFragmentName(),
366
+ directives: this.parseDirectives(false),
367
+ loc: this.loc(start)
368
+ };
369
+ }
263
370
 
264
- function parseVariable(lexer) {
265
- var start = lexer.token;
266
- expectToken(lexer, _tokenKind.TokenKind.DOLLAR);
267
- return {
268
- kind: _kinds.Kind.VARIABLE,
269
- name: parseName(lexer),
270
- loc: loc(lexer, start)
271
- };
272
- }
273
- /**
274
- * SelectionSet : { Selection+ }
275
- */
371
+ return {
372
+ kind: _kinds.Kind.INLINE_FRAGMENT,
373
+ typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
374
+ directives: this.parseDirectives(false),
375
+ selectionSet: this.parseSelectionSet(),
376
+ loc: this.loc(start)
377
+ };
378
+ }
379
+ /**
380
+ * FragmentDefinition :
381
+ * - fragment FragmentName on TypeCondition Directives? SelectionSet
382
+ *
383
+ * TypeCondition : NamedType
384
+ */
385
+ ;
386
+
387
+ _proto.parseFragmentDefinition = function parseFragmentDefinition() {
388
+ var start = this._lexer.token;
389
+ this.expectKeyword('fragment'); // Experimental support for defining variables within fragments changes
390
+ // the grammar of FragmentDefinition:
391
+ // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
392
+
393
+ if (this._options.experimentalFragmentVariables) {
394
+ return {
395
+ kind: _kinds.Kind.FRAGMENT_DEFINITION,
396
+ name: this.parseFragmentName(),
397
+ variableDefinitions: this.parseVariableDefinitions(),
398
+ typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
399
+ directives: this.parseDirectives(false),
400
+ selectionSet: this.parseSelectionSet(),
401
+ loc: this.loc(start)
402
+ };
403
+ }
276
404
 
405
+ return {
406
+ kind: _kinds.Kind.FRAGMENT_DEFINITION,
407
+ name: this.parseFragmentName(),
408
+ typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
409
+ directives: this.parseDirectives(false),
410
+ selectionSet: this.parseSelectionSet(),
411
+ loc: this.loc(start)
412
+ };
413
+ }
414
+ /**
415
+ * FragmentName : Name but not `on`
416
+ */
417
+ ;
418
+
419
+ _proto.parseFragmentName = function parseFragmentName() {
420
+ if (this._lexer.token.value === 'on') {
421
+ throw this.unexpected();
422
+ }
277
423
 
278
- function parseSelectionSet(lexer) {
279
- var start = lexer.token;
280
- return {
281
- kind: _kinds.Kind.SELECTION_SET,
282
- selections: many(lexer, _tokenKind.TokenKind.BRACE_L, parseSelection, _tokenKind.TokenKind.BRACE_R),
283
- loc: loc(lexer, start)
284
- };
285
- }
286
- /**
287
- * Selection :
288
- * - Field
289
- * - FragmentSpread
290
- * - InlineFragment
291
- */
424
+ return this.parseName();
425
+ } // Implements the parsing rules in the Values section.
426
+
427
+ /**
428
+ * Value[Const] :
429
+ * - [~Const] Variable
430
+ * - IntValue
431
+ * - FloatValue
432
+ * - StringValue
433
+ * - BooleanValue
434
+ * - NullValue
435
+ * - EnumValue
436
+ * - ListValue[?Const]
437
+ * - ObjectValue[?Const]
438
+ *
439
+ * BooleanValue : one of `true` `false`
440
+ *
441
+ * NullValue : `null`
442
+ *
443
+ * EnumValue : Name but not `true`, `false` or `null`
444
+ */
445
+ ;
446
+
447
+ _proto.parseValueLiteral = function parseValueLiteral(isConst) {
448
+ var token = this._lexer.token;
449
+
450
+ switch (token.kind) {
451
+ case _tokenKind.TokenKind.BRACKET_L:
452
+ return this.parseList(isConst);
453
+
454
+ case _tokenKind.TokenKind.BRACE_L:
455
+ return this.parseObject(isConst);
456
+
457
+ case _tokenKind.TokenKind.INT:
458
+ this._lexer.advance();
292
459
 
460
+ return {
461
+ kind: _kinds.Kind.INT,
462
+ value: token.value,
463
+ loc: this.loc(token)
464
+ };
293
465
 
294
- function parseSelection(lexer) {
295
- return peek(lexer, _tokenKind.TokenKind.SPREAD) ? parseFragment(lexer) : parseField(lexer);
296
- }
297
- /**
298
- * Field : Alias? Name Arguments? Directives? SelectionSet?
299
- *
300
- * Alias : Name :
301
- */
466
+ case _tokenKind.TokenKind.FLOAT:
467
+ this._lexer.advance();
302
468
 
469
+ return {
470
+ kind: _kinds.Kind.FLOAT,
471
+ value: token.value,
472
+ loc: this.loc(token)
473
+ };
303
474
 
304
- function parseField(lexer) {
305
- var start = lexer.token;
306
- var nameOrAlias = parseName(lexer);
307
- var alias;
308
- var name;
475
+ case _tokenKind.TokenKind.STRING:
476
+ case _tokenKind.TokenKind.BLOCK_STRING:
477
+ return this.parseStringLiteral();
309
478
 
310
- if (expectOptionalToken(lexer, _tokenKind.TokenKind.COLON)) {
311
- alias = nameOrAlias;
312
- name = parseName(lexer);
313
- } else {
314
- name = nameOrAlias;
315
- }
479
+ case _tokenKind.TokenKind.NAME:
480
+ if (token.value === 'true' || token.value === 'false') {
481
+ this._lexer.advance();
316
482
 
317
- return {
318
- kind: _kinds.Kind.FIELD,
319
- alias: alias,
320
- name: name,
321
- arguments: parseArguments(lexer, false),
322
- directives: parseDirectives(lexer, false),
323
- selectionSet: peek(lexer, _tokenKind.TokenKind.BRACE_L) ? parseSelectionSet(lexer) : undefined,
324
- loc: loc(lexer, start)
325
- };
326
- }
327
- /**
328
- * Arguments[Const] : ( Argument[?Const]+ )
329
- */
483
+ return {
484
+ kind: _kinds.Kind.BOOLEAN,
485
+ value: token.value === 'true',
486
+ loc: this.loc(token)
487
+ };
488
+ } else if (token.value === 'null') {
489
+ this._lexer.advance();
330
490
 
491
+ return {
492
+ kind: _kinds.Kind.NULL,
493
+ loc: this.loc(token)
494
+ };
495
+ }
331
496
 
332
- function parseArguments(lexer, isConst) {
333
- var item = isConst ? parseConstArgument : parseArgument;
334
- return peek(lexer, _tokenKind.TokenKind.PAREN_L) ? many(lexer, _tokenKind.TokenKind.PAREN_L, item, _tokenKind.TokenKind.PAREN_R) : [];
335
- }
336
- /**
337
- * Argument[Const] : Name : Value[?Const]
338
- */
497
+ this._lexer.advance();
339
498
 
499
+ return {
500
+ kind: _kinds.Kind.ENUM,
501
+ value: token.value,
502
+ loc: this.loc(token)
503
+ };
340
504
 
341
- function parseArgument(lexer) {
342
- var start = lexer.token;
343
- var name = parseName(lexer);
344
- expectToken(lexer, _tokenKind.TokenKind.COLON);
345
- return {
346
- kind: _kinds.Kind.ARGUMENT,
347
- name: name,
348
- value: parseValueLiteral(lexer, false),
349
- loc: loc(lexer, start)
350
- };
351
- }
505
+ case _tokenKind.TokenKind.DOLLAR:
506
+ if (!isConst) {
507
+ return this.parseVariable();
508
+ }
352
509
 
353
- function parseConstArgument(lexer) {
354
- var start = lexer.token;
355
- return {
356
- kind: _kinds.Kind.ARGUMENT,
357
- name: parseName(lexer),
358
- value: (expectToken(lexer, _tokenKind.TokenKind.COLON), parseConstValue(lexer)),
359
- loc: loc(lexer, start)
360
- };
361
- } // Implements the parsing rules in the Fragments section.
510
+ break;
511
+ }
362
512
 
363
- /**
364
- * Corresponds to both FragmentSpread and InlineFragment in the spec.
365
- *
366
- * FragmentSpread : ... FragmentName Directives?
367
- *
368
- * InlineFragment : ... TypeCondition? Directives? SelectionSet
369
- */
513
+ throw this.unexpected();
514
+ };
370
515
 
516
+ _proto.parseStringLiteral = function parseStringLiteral() {
517
+ var token = this._lexer.token;
371
518
 
372
- function parseFragment(lexer) {
373
- var start = lexer.token;
374
- expectToken(lexer, _tokenKind.TokenKind.SPREAD);
375
- var hasTypeCondition = expectOptionalKeyword(lexer, 'on');
519
+ this._lexer.advance();
376
520
 
377
- if (!hasTypeCondition && peek(lexer, _tokenKind.TokenKind.NAME)) {
378
521
  return {
379
- kind: _kinds.Kind.FRAGMENT_SPREAD,
380
- name: parseFragmentName(lexer),
381
- directives: parseDirectives(lexer, false),
382
- loc: loc(lexer, start)
522
+ kind: _kinds.Kind.STRING,
523
+ value: token.value,
524
+ block: token.kind === _tokenKind.TokenKind.BLOCK_STRING,
525
+ loc: this.loc(token)
383
526
  };
384
527
  }
528
+ /**
529
+ * ListValue[Const] :
530
+ * - [ ]
531
+ * - [ Value[?Const]+ ]
532
+ */
533
+ ;
385
534
 
386
- return {
387
- kind: _kinds.Kind.INLINE_FRAGMENT,
388
- typeCondition: hasTypeCondition ? parseNamedType(lexer) : undefined,
389
- directives: parseDirectives(lexer, false),
390
- selectionSet: parseSelectionSet(lexer),
391
- loc: loc(lexer, start)
392
- };
393
- }
394
- /**
395
- * FragmentDefinition :
396
- * - fragment FragmentName on TypeCondition Directives? SelectionSet
397
- *
398
- * TypeCondition : NamedType
399
- */
535
+ _proto.parseList = function parseList(isConst) {
536
+ var _this = this;
400
537
 
538
+ var start = this._lexer.token;
401
539
 
402
- function parseFragmentDefinition(lexer) {
403
- var start = lexer.token;
404
- expectKeyword(lexer, 'fragment'); // Experimental support for defining variables within fragments changes
405
- // the grammar of FragmentDefinition:
406
- // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
540
+ var item = function item() {
541
+ return _this.parseValueLiteral(isConst);
542
+ };
407
543
 
408
- if (lexer.options.experimentalFragmentVariables) {
409
544
  return {
410
- kind: _kinds.Kind.FRAGMENT_DEFINITION,
411
- name: parseFragmentName(lexer),
412
- variableDefinitions: parseVariableDefinitions(lexer),
413
- typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)),
414
- directives: parseDirectives(lexer, false),
415
- selectionSet: parseSelectionSet(lexer),
416
- loc: loc(lexer, start)
545
+ kind: _kinds.Kind.LIST,
546
+ values: this.any(_tokenKind.TokenKind.BRACKET_L, item, _tokenKind.TokenKind.BRACKET_R),
547
+ loc: this.loc(start)
417
548
  };
418
549
  }
550
+ /**
551
+ * ObjectValue[Const] :
552
+ * - { }
553
+ * - { ObjectField[?Const]+ }
554
+ */
555
+ ;
419
556
 
420
- return {
421
- kind: _kinds.Kind.FRAGMENT_DEFINITION,
422
- name: parseFragmentName(lexer),
423
- typeCondition: (expectKeyword(lexer, 'on'), parseNamedType(lexer)),
424
- directives: parseDirectives(lexer, false),
425
- selectionSet: parseSelectionSet(lexer),
426
- loc: loc(lexer, start)
427
- };
428
- }
429
- /**
430
- * FragmentName : Name but not `on`
431
- */
432
-
433
-
434
- function parseFragmentName(lexer) {
435
- if (lexer.token.value === 'on') {
436
- throw unexpected(lexer);
437
- }
557
+ _proto.parseObject = function parseObject(isConst) {
558
+ var _this2 = this;
438
559
 
439
- return parseName(lexer);
440
- } // Implements the parsing rules in the Values section.
560
+ var start = this._lexer.token;
441
561
 
442
- /**
443
- * Value[Const] :
444
- * - [~Const] Variable
445
- * - IntValue
446
- * - FloatValue
447
- * - StringValue
448
- * - BooleanValue
449
- * - NullValue
450
- * - EnumValue
451
- * - ListValue[?Const]
452
- * - ObjectValue[?Const]
453
- *
454
- * BooleanValue : one of `true` `false`
455
- *
456
- * NullValue : `null`
457
- *
458
- * EnumValue : Name but not `true`, `false` or `null`
459
- */
562
+ var item = function item() {
563
+ return _this2.parseObjectField(isConst);
564
+ };
460
565
 
566
+ return {
567
+ kind: _kinds.Kind.OBJECT,
568
+ fields: this.any(_tokenKind.TokenKind.BRACE_L, item, _tokenKind.TokenKind.BRACE_R),
569
+ loc: this.loc(start)
570
+ };
571
+ }
572
+ /**
573
+ * ObjectField[Const] : Name : Value[?Const]
574
+ */
575
+ ;
576
+
577
+ _proto.parseObjectField = function parseObjectField(isConst) {
578
+ var start = this._lexer.token;
579
+ var name = this.parseName();
580
+ this.expectToken(_tokenKind.TokenKind.COLON);
581
+ return {
582
+ kind: _kinds.Kind.OBJECT_FIELD,
583
+ name: name,
584
+ value: this.parseValueLiteral(isConst),
585
+ loc: this.loc(start)
586
+ };
587
+ } // Implements the parsing rules in the Directives section.
461
588
 
462
- function parseValueLiteral(lexer, isConst) {
463
- var token = lexer.token;
589
+ /**
590
+ * Directives[Const] : Directive[?Const]+
591
+ */
592
+ ;
464
593
 
465
- switch (token.kind) {
466
- case _tokenKind.TokenKind.BRACKET_L:
467
- return parseList(lexer, isConst);
594
+ _proto.parseDirectives = function parseDirectives(isConst) {
595
+ var directives = [];
468
596
 
469
- case _tokenKind.TokenKind.BRACE_L:
470
- return parseObject(lexer, isConst);
597
+ while (this.peek(_tokenKind.TokenKind.AT)) {
598
+ directives.push(this.parseDirective(isConst));
599
+ }
471
600
 
472
- case _tokenKind.TokenKind.INT:
473
- lexer.advance();
474
- return {
475
- kind: _kinds.Kind.INT,
476
- value: token.value,
477
- loc: loc(lexer, token)
601
+ return directives;
602
+ }
603
+ /**
604
+ * Directive[Const] : @ Name Arguments[?Const]?
605
+ */
606
+ ;
607
+
608
+ _proto.parseDirective = function parseDirective(isConst) {
609
+ var start = this._lexer.token;
610
+ this.expectToken(_tokenKind.TokenKind.AT);
611
+ return {
612
+ kind: _kinds.Kind.DIRECTIVE,
613
+ name: this.parseName(),
614
+ arguments: this.parseArguments(isConst),
615
+ loc: this.loc(start)
616
+ };
617
+ } // Implements the parsing rules in the Types section.
618
+
619
+ /**
620
+ * Type :
621
+ * - NamedType
622
+ * - ListType
623
+ * - NonNullType
624
+ */
625
+ ;
626
+
627
+ _proto.parseTypeReference = function parseTypeReference() {
628
+ var start = this._lexer.token;
629
+ var type;
630
+
631
+ if (this.expectOptionalToken(_tokenKind.TokenKind.BRACKET_L)) {
632
+ type = this.parseTypeReference();
633
+ this.expectToken(_tokenKind.TokenKind.BRACKET_R);
634
+ type = {
635
+ kind: _kinds.Kind.LIST_TYPE,
636
+ type: type,
637
+ loc: this.loc(start)
478
638
  };
639
+ } else {
640
+ type = this.parseNamedType();
641
+ }
479
642
 
480
- case _tokenKind.TokenKind.FLOAT:
481
- lexer.advance();
643
+ if (this.expectOptionalToken(_tokenKind.TokenKind.BANG)) {
482
644
  return {
483
- kind: _kinds.Kind.FLOAT,
484
- value: token.value,
485
- loc: loc(lexer, token)
645
+ kind: _kinds.Kind.NON_NULL_TYPE,
646
+ type: type,
647
+ loc: this.loc(start)
486
648
  };
649
+ }
487
650
 
488
- case _tokenKind.TokenKind.STRING:
489
- case _tokenKind.TokenKind.BLOCK_STRING:
490
- return parseStringLiteral(lexer);
651
+ return type;
652
+ }
653
+ /**
654
+ * NamedType : Name
655
+ */
656
+ ;
491
657
 
492
- case _tokenKind.TokenKind.NAME:
493
- if (token.value === 'true' || token.value === 'false') {
494
- lexer.advance();
495
- return {
496
- kind: _kinds.Kind.BOOLEAN,
497
- value: token.value === 'true',
498
- loc: loc(lexer, token)
499
- };
500
- } else if (token.value === 'null') {
501
- lexer.advance();
502
- return {
503
- kind: _kinds.Kind.NULL,
504
- loc: loc(lexer, token)
505
- };
658
+ _proto.parseNamedType = function parseNamedType() {
659
+ var start = this._lexer.token;
660
+ return {
661
+ kind: _kinds.Kind.NAMED_TYPE,
662
+ name: this.parseName(),
663
+ loc: this.loc(start)
664
+ };
665
+ } // Implements the parsing rules in the Type Definition section.
666
+
667
+ /**
668
+ * TypeSystemDefinition :
669
+ * - SchemaDefinition
670
+ * - TypeDefinition
671
+ * - DirectiveDefinition
672
+ *
673
+ * TypeDefinition :
674
+ * - ScalarTypeDefinition
675
+ * - ObjectTypeDefinition
676
+ * - InterfaceTypeDefinition
677
+ * - UnionTypeDefinition
678
+ * - EnumTypeDefinition
679
+ * - InputObjectTypeDefinition
680
+ */
681
+ ;
682
+
683
+ _proto.parseTypeSystemDefinition = function parseTypeSystemDefinition() {
684
+ // Many definitions begin with a description and require a lookahead.
685
+ var keywordToken = this.peekDescription() ? this._lexer.lookahead() : this._lexer.token;
686
+
687
+ if (keywordToken.kind === _tokenKind.TokenKind.NAME) {
688
+ switch (keywordToken.value) {
689
+ case 'schema':
690
+ return this.parseSchemaDefinition();
691
+
692
+ case 'scalar':
693
+ return this.parseScalarTypeDefinition();
694
+
695
+ case 'type':
696
+ return this.parseObjectTypeDefinition();
697
+
698
+ case 'interface':
699
+ return this.parseInterfaceTypeDefinition();
700
+
701
+ case 'union':
702
+ return this.parseUnionTypeDefinition();
703
+
704
+ case 'enum':
705
+ return this.parseEnumTypeDefinition();
706
+
707
+ case 'input':
708
+ return this.parseInputObjectTypeDefinition();
709
+
710
+ case 'directive':
711
+ return this.parseDirectiveDefinition();
506
712
  }
713
+ }
507
714
 
508
- lexer.advance();
509
- return {
510
- kind: _kinds.Kind.ENUM,
511
- value: token.value,
512
- loc: loc(lexer, token)
513
- };
715
+ throw this.unexpected(keywordToken);
716
+ };
514
717
 
515
- case _tokenKind.TokenKind.DOLLAR:
516
- if (!isConst) {
517
- return parseVariable(lexer);
518
- }
718
+ _proto.peekDescription = function peekDescription() {
719
+ return this.peek(_tokenKind.TokenKind.STRING) || this.peek(_tokenKind.TokenKind.BLOCK_STRING);
720
+ }
721
+ /**
722
+ * Description : StringValue
723
+ */
724
+ ;
725
+
726
+ _proto.parseDescription = function parseDescription() {
727
+ if (this.peekDescription()) {
728
+ return this.parseStringLiteral();
729
+ }
730
+ }
731
+ /**
732
+ * SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ }
733
+ */
734
+ ;
735
+
736
+ _proto.parseSchemaDefinition = function parseSchemaDefinition() {
737
+ var start = this._lexer.token;
738
+ this.expectKeyword('schema');
739
+ var directives = this.parseDirectives(true);
740
+ var operationTypes = this.many(_tokenKind.TokenKind.BRACE_L, this.parseOperationTypeDefinition, _tokenKind.TokenKind.BRACE_R);
741
+ return {
742
+ kind: _kinds.Kind.SCHEMA_DEFINITION,
743
+ directives: directives,
744
+ operationTypes: operationTypes,
745
+ loc: this.loc(start)
746
+ };
747
+ }
748
+ /**
749
+ * OperationTypeDefinition : OperationType : NamedType
750
+ */
751
+ ;
752
+
753
+ _proto.parseOperationTypeDefinition = function parseOperationTypeDefinition() {
754
+ var start = this._lexer.token;
755
+ var operation = this.parseOperationType();
756
+ this.expectToken(_tokenKind.TokenKind.COLON);
757
+ var type = this.parseNamedType();
758
+ return {
759
+ kind: _kinds.Kind.OPERATION_TYPE_DEFINITION,
760
+ operation: operation,
761
+ type: type,
762
+ loc: this.loc(start)
763
+ };
764
+ }
765
+ /**
766
+ * ScalarTypeDefinition : Description? scalar Name Directives[Const]?
767
+ */
768
+ ;
769
+
770
+ _proto.parseScalarTypeDefinition = function parseScalarTypeDefinition() {
771
+ var start = this._lexer.token;
772
+ var description = this.parseDescription();
773
+ this.expectKeyword('scalar');
774
+ var name = this.parseName();
775
+ var directives = this.parseDirectives(true);
776
+ return {
777
+ kind: _kinds.Kind.SCALAR_TYPE_DEFINITION,
778
+ description: description,
779
+ name: name,
780
+ directives: directives,
781
+ loc: this.loc(start)
782
+ };
783
+ }
784
+ /**
785
+ * ObjectTypeDefinition :
786
+ * Description?
787
+ * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
788
+ */
789
+ ;
790
+
791
+ _proto.parseObjectTypeDefinition = function parseObjectTypeDefinition() {
792
+ var start = this._lexer.token;
793
+ var description = this.parseDescription();
794
+ this.expectKeyword('type');
795
+ var name = this.parseName();
796
+ var interfaces = this.parseImplementsInterfaces();
797
+ var directives = this.parseDirectives(true);
798
+ var fields = this.parseFieldsDefinition();
799
+ return {
800
+ kind: _kinds.Kind.OBJECT_TYPE_DEFINITION,
801
+ description: description,
802
+ name: name,
803
+ interfaces: interfaces,
804
+ directives: directives,
805
+ fields: fields,
806
+ loc: this.loc(start)
807
+ };
808
+ }
809
+ /**
810
+ * ImplementsInterfaces :
811
+ * - implements `&`? NamedType
812
+ * - ImplementsInterfaces & NamedType
813
+ */
814
+ ;
815
+
816
+ _proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
817
+ var types = [];
818
+
819
+ if (this.expectOptionalKeyword('implements')) {
820
+ // Optional leading ampersand
821
+ this.expectOptionalToken(_tokenKind.TokenKind.AMP);
822
+
823
+ do {
824
+ types.push(this.parseNamedType());
825
+ } while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) || // Legacy support for the SDL?
826
+ this._options.allowLegacySDLImplementsInterfaces && this.peek(_tokenKind.TokenKind.NAME));
827
+ }
519
828
 
520
- break;
829
+ return types;
521
830
  }
831
+ /**
832
+ * FieldsDefinition : { FieldDefinition+ }
833
+ */
834
+ ;
522
835
 
523
- throw unexpected(lexer);
524
- }
836
+ _proto.parseFieldsDefinition = function parseFieldsDefinition() {
837
+ // Legacy support for the SDL?
838
+ if (this._options.allowLegacySDLEmptyFields && this.peek(_tokenKind.TokenKind.BRACE_L) && this._lexer.lookahead().kind === _tokenKind.TokenKind.BRACE_R) {
839
+ this._lexer.advance();
525
840
 
526
- function parseStringLiteral(lexer) {
527
- var token = lexer.token;
528
- lexer.advance();
529
- return {
530
- kind: _kinds.Kind.STRING,
531
- value: token.value,
532
- block: token.kind === _tokenKind.TokenKind.BLOCK_STRING,
533
- loc: loc(lexer, token)
534
- };
535
- }
841
+ this._lexer.advance();
536
842
 
537
- function parseConstValue(lexer) {
538
- return parseValueLiteral(lexer, true);
539
- }
843
+ return [];
844
+ }
540
845
 
541
- function parseValueValue(lexer) {
542
- return parseValueLiteral(lexer, false);
543
- }
544
- /**
545
- * ListValue[Const] :
546
- * - [ ]
547
- * - [ Value[?Const]+ ]
548
- */
846
+ return this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseFieldDefinition, _tokenKind.TokenKind.BRACE_R);
847
+ }
848
+ /**
849
+ * FieldDefinition :
850
+ * - Description? Name ArgumentsDefinition? : Type Directives[Const]?
851
+ */
852
+ ;
853
+
854
+ _proto.parseFieldDefinition = function parseFieldDefinition() {
855
+ var start = this._lexer.token;
856
+ var description = this.parseDescription();
857
+ var name = this.parseName();
858
+ var args = this.parseArgumentDefs();
859
+ this.expectToken(_tokenKind.TokenKind.COLON);
860
+ var type = this.parseTypeReference();
861
+ var directives = this.parseDirectives(true);
862
+ return {
863
+ kind: _kinds.Kind.FIELD_DEFINITION,
864
+ description: description,
865
+ name: name,
866
+ arguments: args,
867
+ type: type,
868
+ directives: directives,
869
+ loc: this.loc(start)
870
+ };
871
+ }
872
+ /**
873
+ * ArgumentsDefinition : ( InputValueDefinition+ )
874
+ */
875
+ ;
549
876
 
877
+ _proto.parseArgumentDefs = function parseArgumentDefs() {
878
+ return this.optionalMany(_tokenKind.TokenKind.PAREN_L, this.parseInputValueDef, _tokenKind.TokenKind.PAREN_R);
879
+ }
880
+ /**
881
+ * InputValueDefinition :
882
+ * - Description? Name : Type DefaultValue? Directives[Const]?
883
+ */
884
+ ;
885
+
886
+ _proto.parseInputValueDef = function parseInputValueDef() {
887
+ var start = this._lexer.token;
888
+ var description = this.parseDescription();
889
+ var name = this.parseName();
890
+ this.expectToken(_tokenKind.TokenKind.COLON);
891
+ var type = this.parseTypeReference();
892
+ var defaultValue;
893
+
894
+ if (this.expectOptionalToken(_tokenKind.TokenKind.EQUALS)) {
895
+ defaultValue = this.parseValueLiteral(true);
896
+ }
550
897
 
551
- function parseList(lexer, isConst) {
552
- var start = lexer.token;
553
- var item = isConst ? parseConstValue : parseValueValue;
554
- return {
555
- kind: _kinds.Kind.LIST,
556
- values: any(lexer, _tokenKind.TokenKind.BRACKET_L, item, _tokenKind.TokenKind.BRACKET_R),
557
- loc: loc(lexer, start)
558
- };
559
- }
560
- /**
561
- * ObjectValue[Const] :
562
- * - { }
563
- * - { ObjectField[?Const]+ }
564
- */
898
+ var directives = this.parseDirectives(true);
899
+ return {
900
+ kind: _kinds.Kind.INPUT_VALUE_DEFINITION,
901
+ description: description,
902
+ name: name,
903
+ type: type,
904
+ defaultValue: defaultValue,
905
+ directives: directives,
906
+ loc: this.loc(start)
907
+ };
908
+ }
909
+ /**
910
+ * InterfaceTypeDefinition :
911
+ * - Description? interface Name Directives[Const]? FieldsDefinition?
912
+ */
913
+ ;
914
+
915
+ _proto.parseInterfaceTypeDefinition = function parseInterfaceTypeDefinition() {
916
+ var start = this._lexer.token;
917
+ var description = this.parseDescription();
918
+ this.expectKeyword('interface');
919
+ var name = this.parseName();
920
+ var directives = this.parseDirectives(true);
921
+ var fields = this.parseFieldsDefinition();
922
+ return {
923
+ kind: _kinds.Kind.INTERFACE_TYPE_DEFINITION,
924
+ description: description,
925
+ name: name,
926
+ directives: directives,
927
+ fields: fields,
928
+ loc: this.loc(start)
929
+ };
930
+ }
931
+ /**
932
+ * UnionTypeDefinition :
933
+ * - Description? union Name Directives[Const]? UnionMemberTypes?
934
+ */
935
+ ;
936
+
937
+ _proto.parseUnionTypeDefinition = function parseUnionTypeDefinition() {
938
+ var start = this._lexer.token;
939
+ var description = this.parseDescription();
940
+ this.expectKeyword('union');
941
+ var name = this.parseName();
942
+ var directives = this.parseDirectives(true);
943
+ var types = this.parseUnionMemberTypes();
944
+ return {
945
+ kind: _kinds.Kind.UNION_TYPE_DEFINITION,
946
+ description: description,
947
+ name: name,
948
+ directives: directives,
949
+ types: types,
950
+ loc: this.loc(start)
951
+ };
952
+ }
953
+ /**
954
+ * UnionMemberTypes :
955
+ * - = `|`? NamedType
956
+ * - UnionMemberTypes | NamedType
957
+ */
958
+ ;
959
+
960
+ _proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
961
+ var types = [];
962
+
963
+ if (this.expectOptionalToken(_tokenKind.TokenKind.EQUALS)) {
964
+ // Optional leading pipe
965
+ this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
966
+
967
+ do {
968
+ types.push(this.parseNamedType());
969
+ } while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
970
+ }
565
971
 
972
+ return types;
973
+ }
974
+ /**
975
+ * EnumTypeDefinition :
976
+ * - Description? enum Name Directives[Const]? EnumValuesDefinition?
977
+ */
978
+ ;
979
+
980
+ _proto.parseEnumTypeDefinition = function parseEnumTypeDefinition() {
981
+ var start = this._lexer.token;
982
+ var description = this.parseDescription();
983
+ this.expectKeyword('enum');
984
+ var name = this.parseName();
985
+ var directives = this.parseDirectives(true);
986
+ var values = this.parseEnumValuesDefinition();
987
+ return {
988
+ kind: _kinds.Kind.ENUM_TYPE_DEFINITION,
989
+ description: description,
990
+ name: name,
991
+ directives: directives,
992
+ values: values,
993
+ loc: this.loc(start)
994
+ };
995
+ }
996
+ /**
997
+ * EnumValuesDefinition : { EnumValueDefinition+ }
998
+ */
999
+ ;
566
1000
 
567
- function parseObject(lexer, isConst) {
568
- var start = lexer.token;
1001
+ _proto.parseEnumValuesDefinition = function parseEnumValuesDefinition() {
1002
+ return this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseEnumValueDefinition, _tokenKind.TokenKind.BRACE_R);
1003
+ }
1004
+ /**
1005
+ * EnumValueDefinition : Description? EnumValue Directives[Const]?
1006
+ *
1007
+ * EnumValue : Name
1008
+ */
1009
+ ;
1010
+
1011
+ _proto.parseEnumValueDefinition = function parseEnumValueDefinition() {
1012
+ var start = this._lexer.token;
1013
+ var description = this.parseDescription();
1014
+ var name = this.parseName();
1015
+ var directives = this.parseDirectives(true);
1016
+ return {
1017
+ kind: _kinds.Kind.ENUM_VALUE_DEFINITION,
1018
+ description: description,
1019
+ name: name,
1020
+ directives: directives,
1021
+ loc: this.loc(start)
1022
+ };
1023
+ }
1024
+ /**
1025
+ * InputObjectTypeDefinition :
1026
+ * - Description? input Name Directives[Const]? InputFieldsDefinition?
1027
+ */
1028
+ ;
1029
+
1030
+ _proto.parseInputObjectTypeDefinition = function parseInputObjectTypeDefinition() {
1031
+ var start = this._lexer.token;
1032
+ var description = this.parseDescription();
1033
+ this.expectKeyword('input');
1034
+ var name = this.parseName();
1035
+ var directives = this.parseDirectives(true);
1036
+ var fields = this.parseInputFieldsDefinition();
1037
+ return {
1038
+ kind: _kinds.Kind.INPUT_OBJECT_TYPE_DEFINITION,
1039
+ description: description,
1040
+ name: name,
1041
+ directives: directives,
1042
+ fields: fields,
1043
+ loc: this.loc(start)
1044
+ };
1045
+ }
1046
+ /**
1047
+ * InputFieldsDefinition : { InputValueDefinition+ }
1048
+ */
1049
+ ;
569
1050
 
570
- var item = function item() {
571
- return parseObjectField(lexer, isConst);
572
- };
573
-
574
- return {
575
- kind: _kinds.Kind.OBJECT,
576
- fields: any(lexer, _tokenKind.TokenKind.BRACE_L, item, _tokenKind.TokenKind.BRACE_R),
577
- loc: loc(lexer, start)
578
- };
579
- }
580
- /**
581
- * ObjectField[Const] : Name : Value[?Const]
582
- */
583
-
584
-
585
- function parseObjectField(lexer, isConst) {
586
- var start = lexer.token;
587
- var name = parseName(lexer);
588
- expectToken(lexer, _tokenKind.TokenKind.COLON);
589
- return {
590
- kind: _kinds.Kind.OBJECT_FIELD,
591
- name: name,
592
- value: parseValueLiteral(lexer, isConst),
593
- loc: loc(lexer, start)
594
- };
595
- } // Implements the parsing rules in the Directives section.
596
-
597
- /**
598
- * Directives[Const] : Directive[?Const]+
599
- */
600
-
601
-
602
- function parseDirectives(lexer, isConst) {
603
- var directives = [];
604
-
605
- while (peek(lexer, _tokenKind.TokenKind.AT)) {
606
- directives.push(parseDirective(lexer, isConst));
1051
+ _proto.parseInputFieldsDefinition = function parseInputFieldsDefinition() {
1052
+ return this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseInputValueDef, _tokenKind.TokenKind.BRACE_R);
607
1053
  }
1054
+ /**
1055
+ * TypeSystemExtension :
1056
+ * - SchemaExtension
1057
+ * - TypeExtension
1058
+ *
1059
+ * TypeExtension :
1060
+ * - ScalarTypeExtension
1061
+ * - ObjectTypeExtension
1062
+ * - InterfaceTypeExtension
1063
+ * - UnionTypeExtension
1064
+ * - EnumTypeExtension
1065
+ * - InputObjectTypeDefinition
1066
+ */
1067
+ ;
1068
+
1069
+ _proto.parseTypeSystemExtension = function parseTypeSystemExtension() {
1070
+ var keywordToken = this._lexer.lookahead();
1071
+
1072
+ if (keywordToken.kind === _tokenKind.TokenKind.NAME) {
1073
+ switch (keywordToken.value) {
1074
+ case 'schema':
1075
+ return this.parseSchemaExtension();
1076
+
1077
+ case 'scalar':
1078
+ return this.parseScalarTypeExtension();
1079
+
1080
+ case 'type':
1081
+ return this.parseObjectTypeExtension();
1082
+
1083
+ case 'interface':
1084
+ return this.parseInterfaceTypeExtension();
1085
+
1086
+ case 'union':
1087
+ return this.parseUnionTypeExtension();
1088
+
1089
+ case 'enum':
1090
+ return this.parseEnumTypeExtension();
1091
+
1092
+ case 'input':
1093
+ return this.parseInputObjectTypeExtension();
1094
+ }
1095
+ }
608
1096
 
609
- return directives;
610
- }
611
- /**
612
- * Directive[Const] : @ Name Arguments[?Const]?
613
- */
614
-
615
-
616
- function parseDirective(lexer, isConst) {
617
- var start = lexer.token;
618
- expectToken(lexer, _tokenKind.TokenKind.AT);
619
- return {
620
- kind: _kinds.Kind.DIRECTIVE,
621
- name: parseName(lexer),
622
- arguments: parseArguments(lexer, isConst),
623
- loc: loc(lexer, start)
624
- };
625
- } // Implements the parsing rules in the Types section.
626
-
627
- /**
628
- * Type :
629
- * - NamedType
630
- * - ListType
631
- * - NonNullType
632
- */
633
-
634
-
635
- function parseTypeReference(lexer) {
636
- var start = lexer.token;
637
- var type;
1097
+ throw this.unexpected(keywordToken);
1098
+ }
1099
+ /**
1100
+ * SchemaExtension :
1101
+ * - extend schema Directives[Const]? { OperationTypeDefinition+ }
1102
+ * - extend schema Directives[Const]
1103
+ */
1104
+ ;
1105
+
1106
+ _proto.parseSchemaExtension = function parseSchemaExtension() {
1107
+ var start = this._lexer.token;
1108
+ this.expectKeyword('extend');
1109
+ this.expectKeyword('schema');
1110
+ var directives = this.parseDirectives(true);
1111
+ var operationTypes = this.optionalMany(_tokenKind.TokenKind.BRACE_L, this.parseOperationTypeDefinition, _tokenKind.TokenKind.BRACE_R);
1112
+
1113
+ if (directives.length === 0 && operationTypes.length === 0) {
1114
+ throw this.unexpected();
1115
+ }
638
1116
 
639
- if (expectOptionalToken(lexer, _tokenKind.TokenKind.BRACKET_L)) {
640
- type = parseTypeReference(lexer);
641
- expectToken(lexer, _tokenKind.TokenKind.BRACKET_R);
642
- type = {
643
- kind: _kinds.Kind.LIST_TYPE,
644
- type: type,
645
- loc: loc(lexer, start)
1117
+ return {
1118
+ kind: _kinds.Kind.SCHEMA_EXTENSION,
1119
+ directives: directives,
1120
+ operationTypes: operationTypes,
1121
+ loc: this.loc(start)
646
1122
  };
647
- } else {
648
- type = parseNamedType(lexer);
649
1123
  }
1124
+ /**
1125
+ * ScalarTypeExtension :
1126
+ * - extend scalar Name Directives[Const]
1127
+ */
1128
+ ;
1129
+
1130
+ _proto.parseScalarTypeExtension = function parseScalarTypeExtension() {
1131
+ var start = this._lexer.token;
1132
+ this.expectKeyword('extend');
1133
+ this.expectKeyword('scalar');
1134
+ var name = this.parseName();
1135
+ var directives = this.parseDirectives(true);
1136
+
1137
+ if (directives.length === 0) {
1138
+ throw this.unexpected();
1139
+ }
650
1140
 
651
- if (expectOptionalToken(lexer, _tokenKind.TokenKind.BANG)) {
652
1141
  return {
653
- kind: _kinds.Kind.NON_NULL_TYPE,
654
- type: type,
655
- loc: loc(lexer, start)
1142
+ kind: _kinds.Kind.SCALAR_TYPE_EXTENSION,
1143
+ name: name,
1144
+ directives: directives,
1145
+ loc: this.loc(start)
656
1146
  };
657
1147
  }
658
-
659
- return type;
660
- }
661
- /**
662
- * NamedType : Name
663
- */
664
-
665
-
666
- function parseNamedType(lexer) {
667
- var start = lexer.token;
668
- return {
669
- kind: _kinds.Kind.NAMED_TYPE,
670
- name: parseName(lexer),
671
- loc: loc(lexer, start)
672
- };
673
- } // Implements the parsing rules in the Type Definition section.
674
-
675
- /**
676
- * TypeSystemDefinition :
677
- * - SchemaDefinition
678
- * - TypeDefinition
679
- * - DirectiveDefinition
680
- *
681
- * TypeDefinition :
682
- * - ScalarTypeDefinition
683
- * - ObjectTypeDefinition
684
- * - InterfaceTypeDefinition
685
- * - UnionTypeDefinition
686
- * - EnumTypeDefinition
687
- * - InputObjectTypeDefinition
688
- */
689
-
690
-
691
- function parseTypeSystemDefinition(lexer) {
692
- // Many definitions begin with a description and require a lookahead.
693
- var keywordToken = peekDescription(lexer) ? lexer.lookahead() : lexer.token;
694
-
695
- if (keywordToken.kind === _tokenKind.TokenKind.NAME) {
696
- switch (keywordToken.value) {
697
- case 'schema':
698
- return parseSchemaDefinition(lexer);
699
-
700
- case 'scalar':
701
- return parseScalarTypeDefinition(lexer);
702
-
703
- case 'type':
704
- return parseObjectTypeDefinition(lexer);
705
-
706
- case 'interface':
707
- return parseInterfaceTypeDefinition(lexer);
708
-
709
- case 'union':
710
- return parseUnionTypeDefinition(lexer);
711
-
712
- case 'enum':
713
- return parseEnumTypeDefinition(lexer);
714
-
715
- case 'input':
716
- return parseInputObjectTypeDefinition(lexer);
717
-
718
- case 'directive':
719
- return parseDirectiveDefinition(lexer);
1148
+ /**
1149
+ * ObjectTypeExtension :
1150
+ * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
1151
+ * - extend type Name ImplementsInterfaces? Directives[Const]
1152
+ * - extend type Name ImplementsInterfaces
1153
+ */
1154
+ ;
1155
+
1156
+ _proto.parseObjectTypeExtension = function parseObjectTypeExtension() {
1157
+ var start = this._lexer.token;
1158
+ this.expectKeyword('extend');
1159
+ this.expectKeyword('type');
1160
+ var name = this.parseName();
1161
+ var interfaces = this.parseImplementsInterfaces();
1162
+ var directives = this.parseDirectives(true);
1163
+ var fields = this.parseFieldsDefinition();
1164
+
1165
+ if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
1166
+ throw this.unexpected();
720
1167
  }
721
- }
722
-
723
- throw unexpected(lexer, keywordToken);
724
- }
725
-
726
- function peekDescription(lexer) {
727
- return peek(lexer, _tokenKind.TokenKind.STRING) || peek(lexer, _tokenKind.TokenKind.BLOCK_STRING);
728
- }
729
- /**
730
- * Description : StringValue
731
- */
732
1168
 
733
-
734
- function parseDescription(lexer) {
735
- if (peekDescription(lexer)) {
736
- return parseStringLiteral(lexer);
1169
+ return {
1170
+ kind: _kinds.Kind.OBJECT_TYPE_EXTENSION,
1171
+ name: name,
1172
+ interfaces: interfaces,
1173
+ directives: directives,
1174
+ fields: fields,
1175
+ loc: this.loc(start)
1176
+ };
737
1177
  }
738
- }
739
- /**
740
- * SchemaDefinition : schema Directives[Const]? { OperationTypeDefinition+ }
741
- */
742
-
743
-
744
- function parseSchemaDefinition(lexer) {
745
- var start = lexer.token;
746
- expectKeyword(lexer, 'schema');
747
- var directives = parseDirectives(lexer, true);
748
- var operationTypes = many(lexer, _tokenKind.TokenKind.BRACE_L, parseOperationTypeDefinition, _tokenKind.TokenKind.BRACE_R);
749
- return {
750
- kind: _kinds.Kind.SCHEMA_DEFINITION,
751
- directives: directives,
752
- operationTypes: operationTypes,
753
- loc: loc(lexer, start)
754
- };
755
- }
756
- /**
757
- * OperationTypeDefinition : OperationType : NamedType
758
- */
759
-
760
-
761
- function parseOperationTypeDefinition(lexer) {
762
- var start = lexer.token;
763
- var operation = parseOperationType(lexer);
764
- expectToken(lexer, _tokenKind.TokenKind.COLON);
765
- var type = parseNamedType(lexer);
766
- return {
767
- kind: _kinds.Kind.OPERATION_TYPE_DEFINITION,
768
- operation: operation,
769
- type: type,
770
- loc: loc(lexer, start)
771
- };
772
- }
773
- /**
774
- * ScalarTypeDefinition : Description? scalar Name Directives[Const]?
775
- */
776
-
777
-
778
- function parseScalarTypeDefinition(lexer) {
779
- var start = lexer.token;
780
- var description = parseDescription(lexer);
781
- expectKeyword(lexer, 'scalar');
782
- var name = parseName(lexer);
783
- var directives = parseDirectives(lexer, true);
784
- return {
785
- kind: _kinds.Kind.SCALAR_TYPE_DEFINITION,
786
- description: description,
787
- name: name,
788
- directives: directives,
789
- loc: loc(lexer, start)
790
- };
791
- }
792
- /**
793
- * ObjectTypeDefinition :
794
- * Description?
795
- * type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition?
796
- */
797
-
798
-
799
- function parseObjectTypeDefinition(lexer) {
800
- var start = lexer.token;
801
- var description = parseDescription(lexer);
802
- expectKeyword(lexer, 'type');
803
- var name = parseName(lexer);
804
- var interfaces = parseImplementsInterfaces(lexer);
805
- var directives = parseDirectives(lexer, true);
806
- var fields = parseFieldsDefinition(lexer);
807
- return {
808
- kind: _kinds.Kind.OBJECT_TYPE_DEFINITION,
809
- description: description,
810
- name: name,
811
- interfaces: interfaces,
812
- directives: directives,
813
- fields: fields,
814
- loc: loc(lexer, start)
815
- };
816
- }
817
- /**
818
- * ImplementsInterfaces :
819
- * - implements `&`? NamedType
820
- * - ImplementsInterfaces & NamedType
821
- */
822
-
823
-
824
- function parseImplementsInterfaces(lexer) {
825
- var types = [];
826
-
827
- if (expectOptionalKeyword(lexer, 'implements')) {
828
- // Optional leading ampersand
829
- expectOptionalToken(lexer, _tokenKind.TokenKind.AMP);
1178
+ /**
1179
+ * InterfaceTypeExtension :
1180
+ * - extend interface Name Directives[Const]? FieldsDefinition
1181
+ * - extend interface Name Directives[Const]
1182
+ */
1183
+ ;
1184
+
1185
+ _proto.parseInterfaceTypeExtension = function parseInterfaceTypeExtension() {
1186
+ var start = this._lexer.token;
1187
+ this.expectKeyword('extend');
1188
+ this.expectKeyword('interface');
1189
+ var name = this.parseName();
1190
+ var directives = this.parseDirectives(true);
1191
+ var fields = this.parseFieldsDefinition();
1192
+
1193
+ if (directives.length === 0 && fields.length === 0) {
1194
+ throw this.unexpected();
1195
+ }
830
1196
 
831
- do {
832
- types.push(parseNamedType(lexer));
833
- } while (expectOptionalToken(lexer, _tokenKind.TokenKind.AMP) || // Legacy support for the SDL?
834
- lexer.options.allowLegacySDLImplementsInterfaces && peek(lexer, _tokenKind.TokenKind.NAME));
1197
+ return {
1198
+ kind: _kinds.Kind.INTERFACE_TYPE_EXTENSION,
1199
+ name: name,
1200
+ directives: directives,
1201
+ fields: fields,
1202
+ loc: this.loc(start)
1203
+ };
835
1204
  }
1205
+ /**
1206
+ * UnionTypeExtension :
1207
+ * - extend union Name Directives[Const]? UnionMemberTypes
1208
+ * - extend union Name Directives[Const]
1209
+ */
1210
+ ;
1211
+
1212
+ _proto.parseUnionTypeExtension = function parseUnionTypeExtension() {
1213
+ var start = this._lexer.token;
1214
+ this.expectKeyword('extend');
1215
+ this.expectKeyword('union');
1216
+ var name = this.parseName();
1217
+ var directives = this.parseDirectives(true);
1218
+ var types = this.parseUnionMemberTypes();
1219
+
1220
+ if (directives.length === 0 && types.length === 0) {
1221
+ throw this.unexpected();
1222
+ }
836
1223
 
837
- return types;
838
- }
839
- /**
840
- * FieldsDefinition : { FieldDefinition+ }
841
- */
842
-
843
-
844
- function parseFieldsDefinition(lexer) {
845
- // Legacy support for the SDL?
846
- if (lexer.options.allowLegacySDLEmptyFields && peek(lexer, _tokenKind.TokenKind.BRACE_L) && lexer.lookahead().kind === _tokenKind.TokenKind.BRACE_R) {
847
- lexer.advance();
848
- lexer.advance();
849
- return [];
1224
+ return {
1225
+ kind: _kinds.Kind.UNION_TYPE_EXTENSION,
1226
+ name: name,
1227
+ directives: directives,
1228
+ types: types,
1229
+ loc: this.loc(start)
1230
+ };
850
1231
  }
1232
+ /**
1233
+ * EnumTypeExtension :
1234
+ * - extend enum Name Directives[Const]? EnumValuesDefinition
1235
+ * - extend enum Name Directives[Const]
1236
+ */
1237
+ ;
1238
+
1239
+ _proto.parseEnumTypeExtension = function parseEnumTypeExtension() {
1240
+ var start = this._lexer.token;
1241
+ this.expectKeyword('extend');
1242
+ this.expectKeyword('enum');
1243
+ var name = this.parseName();
1244
+ var directives = this.parseDirectives(true);
1245
+ var values = this.parseEnumValuesDefinition();
1246
+
1247
+ if (directives.length === 0 && values.length === 0) {
1248
+ throw this.unexpected();
1249
+ }
851
1250
 
852
- return peek(lexer, _tokenKind.TokenKind.BRACE_L) ? many(lexer, _tokenKind.TokenKind.BRACE_L, parseFieldDefinition, _tokenKind.TokenKind.BRACE_R) : [];
853
- }
854
- /**
855
- * FieldDefinition :
856
- * - Description? Name ArgumentsDefinition? : Type Directives[Const]?
857
- */
858
-
859
-
860
- function parseFieldDefinition(lexer) {
861
- var start = lexer.token;
862
- var description = parseDescription(lexer);
863
- var name = parseName(lexer);
864
- var args = parseArgumentDefs(lexer);
865
- expectToken(lexer, _tokenKind.TokenKind.COLON);
866
- var type = parseTypeReference(lexer);
867
- var directives = parseDirectives(lexer, true);
868
- return {
869
- kind: _kinds.Kind.FIELD_DEFINITION,
870
- description: description,
871
- name: name,
872
- arguments: args,
873
- type: type,
874
- directives: directives,
875
- loc: loc(lexer, start)
876
- };
877
- }
878
- /**
879
- * ArgumentsDefinition : ( InputValueDefinition+ )
880
- */
881
-
882
-
883
- function parseArgumentDefs(lexer) {
884
- if (!peek(lexer, _tokenKind.TokenKind.PAREN_L)) {
885
- return [];
1251
+ return {
1252
+ kind: _kinds.Kind.ENUM_TYPE_EXTENSION,
1253
+ name: name,
1254
+ directives: directives,
1255
+ values: values,
1256
+ loc: this.loc(start)
1257
+ };
886
1258
  }
1259
+ /**
1260
+ * InputObjectTypeExtension :
1261
+ * - extend input Name Directives[Const]? InputFieldsDefinition
1262
+ * - extend input Name Directives[Const]
1263
+ */
1264
+ ;
1265
+
1266
+ _proto.parseInputObjectTypeExtension = function parseInputObjectTypeExtension() {
1267
+ var start = this._lexer.token;
1268
+ this.expectKeyword('extend');
1269
+ this.expectKeyword('input');
1270
+ var name = this.parseName();
1271
+ var directives = this.parseDirectives(true);
1272
+ var fields = this.parseInputFieldsDefinition();
1273
+
1274
+ if (directives.length === 0 && fields.length === 0) {
1275
+ throw this.unexpected();
1276
+ }
887
1277
 
888
- return many(lexer, _tokenKind.TokenKind.PAREN_L, parseInputValueDef, _tokenKind.TokenKind.PAREN_R);
889
- }
890
- /**
891
- * InputValueDefinition :
892
- * - Description? Name : Type DefaultValue? Directives[Const]?
893
- */
894
-
895
-
896
- function parseInputValueDef(lexer) {
897
- var start = lexer.token;
898
- var description = parseDescription(lexer);
899
- var name = parseName(lexer);
900
- expectToken(lexer, _tokenKind.TokenKind.COLON);
901
- var type = parseTypeReference(lexer);
902
- var defaultValue;
903
-
904
- if (expectOptionalToken(lexer, _tokenKind.TokenKind.EQUALS)) {
905
- defaultValue = parseConstValue(lexer);
1278
+ return {
1279
+ kind: _kinds.Kind.INPUT_OBJECT_TYPE_EXTENSION,
1280
+ name: name,
1281
+ directives: directives,
1282
+ fields: fields,
1283
+ loc: this.loc(start)
1284
+ };
906
1285
  }
907
-
908
- var directives = parseDirectives(lexer, true);
909
- return {
910
- kind: _kinds.Kind.INPUT_VALUE_DEFINITION,
911
- description: description,
912
- name: name,
913
- type: type,
914
- defaultValue: defaultValue,
915
- directives: directives,
916
- loc: loc(lexer, start)
917
- };
918
- }
919
- /**
920
- * InterfaceTypeDefinition :
921
- * - Description? interface Name Directives[Const]? FieldsDefinition?
922
- */
923
-
924
-
925
- function parseInterfaceTypeDefinition(lexer) {
926
- var start = lexer.token;
927
- var description = parseDescription(lexer);
928
- expectKeyword(lexer, 'interface');
929
- var name = parseName(lexer);
930
- var directives = parseDirectives(lexer, true);
931
- var fields = parseFieldsDefinition(lexer);
932
- return {
933
- kind: _kinds.Kind.INTERFACE_TYPE_DEFINITION,
934
- description: description,
935
- name: name,
936
- directives: directives,
937
- fields: fields,
938
- loc: loc(lexer, start)
939
- };
940
- }
941
- /**
942
- * UnionTypeDefinition :
943
- * - Description? union Name Directives[Const]? UnionMemberTypes?
944
- */
945
-
946
-
947
- function parseUnionTypeDefinition(lexer) {
948
- var start = lexer.token;
949
- var description = parseDescription(lexer);
950
- expectKeyword(lexer, 'union');
951
- var name = parseName(lexer);
952
- var directives = parseDirectives(lexer, true);
953
- var types = parseUnionMemberTypes(lexer);
954
- return {
955
- kind: _kinds.Kind.UNION_TYPE_DEFINITION,
956
- description: description,
957
- name: name,
958
- directives: directives,
959
- types: types,
960
- loc: loc(lexer, start)
961
- };
962
- }
963
- /**
964
- * UnionMemberTypes :
965
- * - = `|`? NamedType
966
- * - UnionMemberTypes | NamedType
967
- */
968
-
969
-
970
- function parseUnionMemberTypes(lexer) {
971
- var types = [];
972
-
973
- if (expectOptionalToken(lexer, _tokenKind.TokenKind.EQUALS)) {
1286
+ /**
1287
+ * DirectiveDefinition :
1288
+ * - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
1289
+ */
1290
+ ;
1291
+
1292
+ _proto.parseDirectiveDefinition = function parseDirectiveDefinition() {
1293
+ var start = this._lexer.token;
1294
+ var description = this.parseDescription();
1295
+ this.expectKeyword('directive');
1296
+ this.expectToken(_tokenKind.TokenKind.AT);
1297
+ var name = this.parseName();
1298
+ var args = this.parseArgumentDefs();
1299
+ var repeatable = this.expectOptionalKeyword('repeatable');
1300
+ this.expectKeyword('on');
1301
+ var locations = this.parseDirectiveLocations();
1302
+ return {
1303
+ kind: _kinds.Kind.DIRECTIVE_DEFINITION,
1304
+ description: description,
1305
+ name: name,
1306
+ arguments: args,
1307
+ repeatable: repeatable,
1308
+ locations: locations,
1309
+ loc: this.loc(start)
1310
+ };
1311
+ }
1312
+ /**
1313
+ * DirectiveLocations :
1314
+ * - `|`? DirectiveLocation
1315
+ * - DirectiveLocations | DirectiveLocation
1316
+ */
1317
+ ;
1318
+
1319
+ _proto.parseDirectiveLocations = function parseDirectiveLocations() {
974
1320
  // Optional leading pipe
975
- expectOptionalToken(lexer, _tokenKind.TokenKind.PIPE);
1321
+ this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
1322
+ var locations = [];
976
1323
 
977
1324
  do {
978
- types.push(parseNamedType(lexer));
979
- } while (expectOptionalToken(lexer, _tokenKind.TokenKind.PIPE));
980
- }
981
-
982
- return types;
983
- }
984
- /**
985
- * EnumTypeDefinition :
986
- * - Description? enum Name Directives[Const]? EnumValuesDefinition?
987
- */
988
-
989
-
990
- function parseEnumTypeDefinition(lexer) {
991
- var start = lexer.token;
992
- var description = parseDescription(lexer);
993
- expectKeyword(lexer, 'enum');
994
- var name = parseName(lexer);
995
- var directives = parseDirectives(lexer, true);
996
- var values = parseEnumValuesDefinition(lexer);
997
- return {
998
- kind: _kinds.Kind.ENUM_TYPE_DEFINITION,
999
- description: description,
1000
- name: name,
1001
- directives: directives,
1002
- values: values,
1003
- loc: loc(lexer, start)
1004
- };
1005
- }
1006
- /**
1007
- * EnumValuesDefinition : { EnumValueDefinition+ }
1008
- */
1009
-
1010
-
1011
- function parseEnumValuesDefinition(lexer) {
1012
- return peek(lexer, _tokenKind.TokenKind.BRACE_L) ? many(lexer, _tokenKind.TokenKind.BRACE_L, parseEnumValueDefinition, _tokenKind.TokenKind.BRACE_R) : [];
1013
- }
1014
- /**
1015
- * EnumValueDefinition : Description? EnumValue Directives[Const]?
1016
- *
1017
- * EnumValue : Name
1018
- */
1019
-
1020
-
1021
- function parseEnumValueDefinition(lexer) {
1022
- var start = lexer.token;
1023
- var description = parseDescription(lexer);
1024
- var name = parseName(lexer);
1025
- var directives = parseDirectives(lexer, true);
1026
- return {
1027
- kind: _kinds.Kind.ENUM_VALUE_DEFINITION,
1028
- description: description,
1029
- name: name,
1030
- directives: directives,
1031
- loc: loc(lexer, start)
1032
- };
1033
- }
1034
- /**
1035
- * InputObjectTypeDefinition :
1036
- * - Description? input Name Directives[Const]? InputFieldsDefinition?
1037
- */
1038
-
1039
-
1040
- function parseInputObjectTypeDefinition(lexer) {
1041
- var start = lexer.token;
1042
- var description = parseDescription(lexer);
1043
- expectKeyword(lexer, 'input');
1044
- var name = parseName(lexer);
1045
- var directives = parseDirectives(lexer, true);
1046
- var fields = parseInputFieldsDefinition(lexer);
1047
- return {
1048
- kind: _kinds.Kind.INPUT_OBJECT_TYPE_DEFINITION,
1049
- description: description,
1050
- name: name,
1051
- directives: directives,
1052
- fields: fields,
1053
- loc: loc(lexer, start)
1054
- };
1055
- }
1056
- /**
1057
- * InputFieldsDefinition : { InputValueDefinition+ }
1058
- */
1059
-
1060
-
1061
- function parseInputFieldsDefinition(lexer) {
1062
- return peek(lexer, _tokenKind.TokenKind.BRACE_L) ? many(lexer, _tokenKind.TokenKind.BRACE_L, parseInputValueDef, _tokenKind.TokenKind.BRACE_R) : [];
1063
- }
1064
- /**
1065
- * TypeSystemExtension :
1066
- * - SchemaExtension
1067
- * - TypeExtension
1068
- *
1069
- * TypeExtension :
1070
- * - ScalarTypeExtension
1071
- * - ObjectTypeExtension
1072
- * - InterfaceTypeExtension
1073
- * - UnionTypeExtension
1074
- * - EnumTypeExtension
1075
- * - InputObjectTypeDefinition
1076
- */
1077
-
1078
-
1079
- function parseTypeSystemExtension(lexer) {
1080
- var keywordToken = lexer.lookahead();
1325
+ locations.push(this.parseDirectiveLocation());
1326
+ } while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
1081
1327
 
1082
- if (keywordToken.kind === _tokenKind.TokenKind.NAME) {
1083
- switch (keywordToken.value) {
1084
- case 'schema':
1085
- return parseSchemaExtension(lexer);
1086
-
1087
- case 'scalar':
1088
- return parseScalarTypeExtension(lexer);
1089
-
1090
- case 'type':
1091
- return parseObjectTypeExtension(lexer);
1092
-
1093
- case 'interface':
1094
- return parseInterfaceTypeExtension(lexer);
1328
+ return locations;
1329
+ }
1330
+ /*
1331
+ * DirectiveLocation :
1332
+ * - ExecutableDirectiveLocation
1333
+ * - TypeSystemDirectiveLocation
1334
+ *
1335
+ * ExecutableDirectiveLocation : one of
1336
+ * `QUERY`
1337
+ * `MUTATION`
1338
+ * `SUBSCRIPTION`
1339
+ * `FIELD`
1340
+ * `FRAGMENT_DEFINITION`
1341
+ * `FRAGMENT_SPREAD`
1342
+ * `INLINE_FRAGMENT`
1343
+ *
1344
+ * TypeSystemDirectiveLocation : one of
1345
+ * `SCHEMA`
1346
+ * `SCALAR`
1347
+ * `OBJECT`
1348
+ * `FIELD_DEFINITION`
1349
+ * `ARGUMENT_DEFINITION`
1350
+ * `INTERFACE`
1351
+ * `UNION`
1352
+ * `ENUM`
1353
+ * `ENUM_VALUE`
1354
+ * `INPUT_OBJECT`
1355
+ * `INPUT_FIELD_DEFINITION`
1356
+ */
1357
+ ;
1358
+
1359
+ _proto.parseDirectiveLocation = function parseDirectiveLocation() {
1360
+ var start = this._lexer.token;
1361
+ var name = this.parseName();
1362
+
1363
+ if (_directiveLocation.DirectiveLocation[name.value] !== undefined) {
1364
+ return name;
1365
+ }
1095
1366
 
1096
- case 'union':
1097
- return parseUnionTypeExtension(lexer);
1367
+ throw this.unexpected(start);
1368
+ } // Core parsing utility functions
1098
1369
 
1099
- case 'enum':
1100
- return parseEnumTypeExtension(lexer);
1370
+ /**
1371
+ * Returns a location object, used to identify the place in
1372
+ * the source that created a given parsed object.
1373
+ */
1374
+ ;
1101
1375
 
1102
- case 'input':
1103
- return parseInputObjectTypeExtension(lexer);
1376
+ _proto.loc = function loc(startToken) {
1377
+ if (!this._options.noLocation) {
1378
+ return new Loc(startToken, this._lexer.lastToken, this._lexer.source);
1104
1379
  }
1105
1380
  }
1381
+ /**
1382
+ * Determines if the next token is of a given kind
1383
+ */
1384
+ ;
1106
1385
 
1107
- throw unexpected(lexer, keywordToken);
1108
- }
1109
- /**
1110
- * SchemaExtension :
1111
- * - extend schema Directives[Const]? { OperationTypeDefinition+ }
1112
- * - extend schema Directives[Const]
1113
- */
1114
-
1115
-
1116
- function parseSchemaExtension(lexer) {
1117
- var start = lexer.token;
1118
- expectKeyword(lexer, 'extend');
1119
- expectKeyword(lexer, 'schema');
1120
- var directives = parseDirectives(lexer, true);
1121
- var operationTypes = peek(lexer, _tokenKind.TokenKind.BRACE_L) ? many(lexer, _tokenKind.TokenKind.BRACE_L, parseOperationTypeDefinition, _tokenKind.TokenKind.BRACE_R) : [];
1122
-
1123
- if (directives.length === 0 && operationTypes.length === 0) {
1124
- throw unexpected(lexer);
1386
+ _proto.peek = function peek(kind) {
1387
+ return this._lexer.token.kind === kind;
1125
1388
  }
1389
+ /**
1390
+ * If the next token is of the given kind, return that token after advancing
1391
+ * the lexer. Otherwise, do not change the parser state and throw an error.
1392
+ */
1393
+ ;
1126
1394
 
1127
- return {
1128
- kind: _kinds.Kind.SCHEMA_EXTENSION,
1129
- directives: directives,
1130
- operationTypes: operationTypes,
1131
- loc: loc(lexer, start)
1132
- };
1133
- }
1134
- /**
1135
- * ScalarTypeExtension :
1136
- * - extend scalar Name Directives[Const]
1137
- */
1395
+ _proto.expectToken = function expectToken(kind) {
1396
+ var token = this._lexer.token;
1138
1397
 
1398
+ if (token.kind === kind) {
1399
+ this._lexer.advance();
1139
1400
 
1140
- function parseScalarTypeExtension(lexer) {
1141
- var start = lexer.token;
1142
- expectKeyword(lexer, 'extend');
1143
- expectKeyword(lexer, 'scalar');
1144
- var name = parseName(lexer);
1145
- var directives = parseDirectives(lexer, true);
1401
+ return token;
1402
+ }
1146
1403
 
1147
- if (directives.length === 0) {
1148
- throw unexpected(lexer);
1404
+ throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected ".concat(kind, ", found ").concat(getTokenDesc(token)));
1149
1405
  }
1406
+ /**
1407
+ * If the next token is of the given kind, return that token after advancing
1408
+ * the lexer. Otherwise, do not change the parser state and return undefined.
1409
+ */
1410
+ ;
1150
1411
 
1151
- return {
1152
- kind: _kinds.Kind.SCALAR_TYPE_EXTENSION,
1153
- name: name,
1154
- directives: directives,
1155
- loc: loc(lexer, start)
1156
- };
1157
- }
1158
- /**
1159
- * ObjectTypeExtension :
1160
- * - extend type Name ImplementsInterfaces? Directives[Const]? FieldsDefinition
1161
- * - extend type Name ImplementsInterfaces? Directives[Const]
1162
- * - extend type Name ImplementsInterfaces
1163
- */
1412
+ _proto.expectOptionalToken = function expectOptionalToken(kind) {
1413
+ var token = this._lexer.token;
1164
1414
 
1415
+ if (token.kind === kind) {
1416
+ this._lexer.advance();
1165
1417
 
1166
- function parseObjectTypeExtension(lexer) {
1167
- var start = lexer.token;
1168
- expectKeyword(lexer, 'extend');
1169
- expectKeyword(lexer, 'type');
1170
- var name = parseName(lexer);
1171
- var interfaces = parseImplementsInterfaces(lexer);
1172
- var directives = parseDirectives(lexer, true);
1173
- var fields = parseFieldsDefinition(lexer);
1418
+ return token;
1419
+ }
1174
1420
 
1175
- if (interfaces.length === 0 && directives.length === 0 && fields.length === 0) {
1176
- throw unexpected(lexer);
1421
+ return undefined;
1177
1422
  }
1178
-
1179
- return {
1180
- kind: _kinds.Kind.OBJECT_TYPE_EXTENSION,
1181
- name: name,
1182
- interfaces: interfaces,
1183
- directives: directives,
1184
- fields: fields,
1185
- loc: loc(lexer, start)
1186
- };
1187
- }
1188
- /**
1189
- * InterfaceTypeExtension :
1190
- * - extend interface Name Directives[Const]? FieldsDefinition
1191
- * - extend interface Name Directives[Const]
1192
- */
1193
-
1194
-
1195
- function parseInterfaceTypeExtension(lexer) {
1196
- var start = lexer.token;
1197
- expectKeyword(lexer, 'extend');
1198
- expectKeyword(lexer, 'interface');
1199
- var name = parseName(lexer);
1200
- var directives = parseDirectives(lexer, true);
1201
- var fields = parseFieldsDefinition(lexer);
1202
-
1203
- if (directives.length === 0 && fields.length === 0) {
1204
- throw unexpected(lexer);
1423
+ /**
1424
+ * If the next token is a given keyword, advance the lexer.
1425
+ * Otherwise, do not change the parser state and throw an error.
1426
+ */
1427
+ ;
1428
+
1429
+ _proto.expectKeyword = function expectKeyword(value) {
1430
+ var token = this._lexer.token;
1431
+
1432
+ if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
1433
+ this._lexer.advance();
1434
+ } else {
1435
+ throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat(getTokenDesc(token)));
1436
+ }
1205
1437
  }
1438
+ /**
1439
+ * If the next token is a given keyword, return "true" after advancing
1440
+ * the lexer. Otherwise, do not change the parser state and return "false".
1441
+ */
1442
+ ;
1206
1443
 
1207
- return {
1208
- kind: _kinds.Kind.INTERFACE_TYPE_EXTENSION,
1209
- name: name,
1210
- directives: directives,
1211
- fields: fields,
1212
- loc: loc(lexer, start)
1213
- };
1214
- }
1215
- /**
1216
- * UnionTypeExtension :
1217
- * - extend union Name Directives[Const]? UnionMemberTypes
1218
- * - extend union Name Directives[Const]
1219
- */
1444
+ _proto.expectOptionalKeyword = function expectOptionalKeyword(value) {
1445
+ var token = this._lexer.token;
1220
1446
 
1447
+ if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
1448
+ this._lexer.advance();
1221
1449
 
1222
- function parseUnionTypeExtension(lexer) {
1223
- var start = lexer.token;
1224
- expectKeyword(lexer, 'extend');
1225
- expectKeyword(lexer, 'union');
1226
- var name = parseName(lexer);
1227
- var directives = parseDirectives(lexer, true);
1228
- var types = parseUnionMemberTypes(lexer);
1450
+ return true;
1451
+ }
1229
1452
 
1230
- if (directives.length === 0 && types.length === 0) {
1231
- throw unexpected(lexer);
1453
+ return false;
1232
1454
  }
1233
-
1234
- return {
1235
- kind: _kinds.Kind.UNION_TYPE_EXTENSION,
1236
- name: name,
1237
- directives: directives,
1238
- types: types,
1239
- loc: loc(lexer, start)
1240
- };
1241
- }
1242
- /**
1243
- * EnumTypeExtension :
1244
- * - extend enum Name Directives[Const]? EnumValuesDefinition
1245
- * - extend enum Name Directives[Const]
1246
- */
1247
-
1248
-
1249
- function parseEnumTypeExtension(lexer) {
1250
- var start = lexer.token;
1251
- expectKeyword(lexer, 'extend');
1252
- expectKeyword(lexer, 'enum');
1253
- var name = parseName(lexer);
1254
- var directives = parseDirectives(lexer, true);
1255
- var values = parseEnumValuesDefinition(lexer);
1256
-
1257
- if (directives.length === 0 && values.length === 0) {
1258
- throw unexpected(lexer);
1455
+ /**
1456
+ * Helper function for creating an error when an unexpected lexed token
1457
+ * is encountered.
1458
+ */
1459
+ ;
1460
+
1461
+ _proto.unexpected = function unexpected(atToken) {
1462
+ var token = atToken || this._lexer.token;
1463
+ return (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token)));
1259
1464
  }
1465
+ /**
1466
+ * Returns a possibly empty list of parse nodes, determined by
1467
+ * the parseFn. This list begins with a lex token of openKind
1468
+ * and ends with a lex token of closeKind. Advances the parser
1469
+ * to the next lex token after the closing token.
1470
+ */
1471
+ ;
1472
+
1473
+ _proto.any = function any(openKind, parseFn, closeKind) {
1474
+ this.expectToken(openKind);
1475
+ var nodes = [];
1476
+
1477
+ while (!this.expectOptionalToken(closeKind)) {
1478
+ nodes.push(parseFn.call(this));
1479
+ }
1260
1480
 
1261
- return {
1262
- kind: _kinds.Kind.ENUM_TYPE_EXTENSION,
1263
- name: name,
1264
- directives: directives,
1265
- values: values,
1266
- loc: loc(lexer, start)
1267
- };
1268
- }
1269
- /**
1270
- * InputObjectTypeExtension :
1271
- * - extend input Name Directives[Const]? InputFieldsDefinition
1272
- * - extend input Name Directives[Const]
1273
- */
1274
-
1275
-
1276
- function parseInputObjectTypeExtension(lexer) {
1277
- var start = lexer.token;
1278
- expectKeyword(lexer, 'extend');
1279
- expectKeyword(lexer, 'input');
1280
- var name = parseName(lexer);
1281
- var directives = parseDirectives(lexer, true);
1282
- var fields = parseInputFieldsDefinition(lexer);
1283
-
1284
- if (directives.length === 0 && fields.length === 0) {
1285
- throw unexpected(lexer);
1481
+ return nodes;
1286
1482
  }
1483
+ /**
1484
+ * Returns a list of parse nodes, determined by the parseFn.
1485
+ * It can be empty only if open token is missing otherwise it will always
1486
+ * return non-empty list that begins with a lex token of openKind and ends
1487
+ * with a lex token of closeKind. Advances the parser to the next lex token
1488
+ * after the closing token.
1489
+ */
1490
+ ;
1491
+
1492
+ _proto.optionalMany = function optionalMany(openKind, parseFn, closeKind) {
1493
+ if (this.expectOptionalToken(openKind)) {
1494
+ var nodes = [];
1495
+
1496
+ do {
1497
+ nodes.push(parseFn.call(this));
1498
+ } while (!this.expectOptionalToken(closeKind));
1499
+
1500
+ return nodes;
1501
+ }
1287
1502
 
1288
- return {
1289
- kind: _kinds.Kind.INPUT_OBJECT_TYPE_EXTENSION,
1290
- name: name,
1291
- directives: directives,
1292
- fields: fields,
1293
- loc: loc(lexer, start)
1294
- };
1295
- }
1296
- /**
1297
- * DirectiveDefinition :
1298
- * - Description? directive @ Name ArgumentsDefinition? `repeatable`? on DirectiveLocations
1299
- */
1300
-
1301
-
1302
- function parseDirectiveDefinition(lexer) {
1303
- var start = lexer.token;
1304
- var description = parseDescription(lexer);
1305
- expectKeyword(lexer, 'directive');
1306
- expectToken(lexer, _tokenKind.TokenKind.AT);
1307
- var name = parseName(lexer);
1308
- var args = parseArgumentDefs(lexer);
1309
- var repeatable = expectOptionalKeyword(lexer, 'repeatable');
1310
- expectKeyword(lexer, 'on');
1311
- var locations = parseDirectiveLocations(lexer);
1312
- return {
1313
- kind: _kinds.Kind.DIRECTIVE_DEFINITION,
1314
- description: description,
1315
- name: name,
1316
- arguments: args,
1317
- repeatable: repeatable,
1318
- locations: locations,
1319
- loc: loc(lexer, start)
1320
- };
1321
- }
1322
- /**
1323
- * DirectiveLocations :
1324
- * - `|`? DirectiveLocation
1325
- * - DirectiveLocations | DirectiveLocation
1326
- */
1327
-
1328
-
1329
- function parseDirectiveLocations(lexer) {
1330
- // Optional leading pipe
1331
- expectOptionalToken(lexer, _tokenKind.TokenKind.PIPE);
1332
- var locations = [];
1333
-
1334
- do {
1335
- locations.push(parseDirectiveLocation(lexer));
1336
- } while (expectOptionalToken(lexer, _tokenKind.TokenKind.PIPE));
1337
-
1338
- return locations;
1339
- }
1340
- /*
1341
- * DirectiveLocation :
1342
- * - ExecutableDirectiveLocation
1343
- * - TypeSystemDirectiveLocation
1344
- *
1345
- * ExecutableDirectiveLocation : one of
1346
- * `QUERY`
1347
- * `MUTATION`
1348
- * `SUBSCRIPTION`
1349
- * `FIELD`
1350
- * `FRAGMENT_DEFINITION`
1351
- * `FRAGMENT_SPREAD`
1352
- * `INLINE_FRAGMENT`
1353
- *
1354
- * TypeSystemDirectiveLocation : one of
1355
- * `SCHEMA`
1356
- * `SCALAR`
1357
- * `OBJECT`
1358
- * `FIELD_DEFINITION`
1359
- * `ARGUMENT_DEFINITION`
1360
- * `INTERFACE`
1361
- * `UNION`
1362
- * `ENUM`
1363
- * `ENUM_VALUE`
1364
- * `INPUT_OBJECT`
1365
- * `INPUT_FIELD_DEFINITION`
1366
- */
1367
-
1368
-
1369
- function parseDirectiveLocation(lexer) {
1370
- var start = lexer.token;
1371
- var name = parseName(lexer);
1372
-
1373
- if (_directiveLocation.DirectiveLocation[name.value] !== undefined) {
1374
- return name;
1503
+ return [];
1375
1504
  }
1505
+ /**
1506
+ * Returns a non-empty list of parse nodes, determined by
1507
+ * the parseFn. This list begins with a lex token of openKind
1508
+ * and ends with a lex token of closeKind. Advances the parser
1509
+ * to the next lex token after the closing token.
1510
+ */
1511
+ ;
1512
+
1513
+ _proto.many = function many(openKind, parseFn, closeKind) {
1514
+ this.expectToken(openKind);
1515
+ var nodes = [];
1376
1516
 
1377
- throw unexpected(lexer, start);
1378
- } // Core parsing utility functions
1379
-
1380
- /**
1381
- * Returns a location object, used to identify the place in
1382
- * the source that created a given parsed object.
1383
- */
1517
+ do {
1518
+ nodes.push(parseFn.call(this));
1519
+ } while (!this.expectOptionalToken(closeKind));
1384
1520
 
1521
+ return nodes;
1522
+ };
1385
1523
 
1386
- function loc(lexer, startToken) {
1387
- if (!lexer.options.noLocation) {
1388
- return new Loc(startToken, lexer.lastToken, lexer.source);
1389
- }
1390
- }
1524
+ return Parser;
1525
+ }();
1391
1526
 
1392
1527
  function Loc(startToken, endToken, source) {
1393
1528
  this.start = startToken.start;
@@ -1405,118 +1540,10 @@ function Loc(startToken, endToken, source) {
1405
1540
  };
1406
1541
  });
1407
1542
  /**
1408
- * Determines if the next token is of a given kind
1409
- */
1410
-
1411
- function peek(lexer, kind) {
1412
- return lexer.token.kind === kind;
1413
- }
1414
- /**
1415
- * If the next token is of the given kind, return that token after advancing
1416
- * the lexer. Otherwise, do not change the parser state and throw an error.
1543
+ * A helper function to describe a token as a string for debugging
1417
1544
  */
1418
1545
 
1419
-
1420
- function expectToken(lexer, kind) {
1421
- var token = lexer.token;
1422
-
1423
- if (token.kind === kind) {
1424
- lexer.advance();
1425
- return token;
1426
- }
1427
-
1428
- throw (0, _syntaxError.syntaxError)(lexer.source, token.start, "Expected ".concat(kind, ", found ").concat((0, _lexer.getTokenDesc)(token)));
1429
- }
1430
- /**
1431
- * If the next token is of the given kind, return that token after advancing
1432
- * the lexer. Otherwise, do not change the parser state and return undefined.
1433
- */
1434
-
1435
-
1436
- function expectOptionalToken(lexer, kind) {
1437
- var token = lexer.token;
1438
-
1439
- if (token.kind === kind) {
1440
- lexer.advance();
1441
- return token;
1442
- }
1443
-
1444
- return undefined;
1445
- }
1446
- /**
1447
- * If the next token is a given keyword, advance the lexer.
1448
- * Otherwise, do not change the parser state and throw an error.
1449
- */
1450
-
1451
-
1452
- function expectKeyword(lexer, value) {
1453
- var token = lexer.token;
1454
-
1455
- if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
1456
- lexer.advance();
1457
- } else {
1458
- throw (0, _syntaxError.syntaxError)(lexer.source, token.start, "Expected \"".concat(value, "\", found ").concat((0, _lexer.getTokenDesc)(token)));
1459
- }
1460
- }
1461
- /**
1462
- * If the next token is a given keyword, return "true" after advancing
1463
- * the lexer. Otherwise, do not change the parser state and return "false".
1464
- */
1465
-
1466
-
1467
- function expectOptionalKeyword(lexer, value) {
1468
- var token = lexer.token;
1469
-
1470
- if (token.kind === _tokenKind.TokenKind.NAME && token.value === value) {
1471
- lexer.advance();
1472
- return true;
1473
- }
1474
-
1475
- return false;
1476
- }
1477
- /**
1478
- * Helper function for creating an error when an unexpected lexed token
1479
- * is encountered.
1480
- */
1481
-
1482
-
1483
- function unexpected(lexer, atToken) {
1484
- var token = atToken || lexer.token;
1485
- return (0, _syntaxError.syntaxError)(lexer.source, token.start, "Unexpected ".concat((0, _lexer.getTokenDesc)(token)));
1486
- }
1487
- /**
1488
- * Returns a possibly empty list of parse nodes, determined by
1489
- * the parseFn. This list begins with a lex token of openKind
1490
- * and ends with a lex token of closeKind. Advances the parser
1491
- * to the next lex token after the closing token.
1492
- */
1493
-
1494
-
1495
- function any(lexer, openKind, parseFn, closeKind) {
1496
- expectToken(lexer, openKind);
1497
- var nodes = [];
1498
-
1499
- while (!expectOptionalToken(lexer, closeKind)) {
1500
- nodes.push(parseFn(lexer));
1501
- }
1502
-
1503
- return nodes;
1504
- }
1505
- /**
1506
- * Returns a non-empty list of parse nodes, determined by
1507
- * the parseFn. This list begins with a lex token of openKind
1508
- * and ends with a lex token of closeKind. Advances the parser
1509
- * to the next lex token after the closing token.
1510
- */
1511
-
1512
-
1513
- function many(lexer, openKind, parseFn, closeKind) {
1514
- expectToken(lexer, openKind);
1515
- var nodes = [parseFn(lexer)];
1516
-
1517
- while (!expectOptionalToken(lexer, closeKind)) {
1518
- nodes.push(parseFn(lexer));
1519
- }
1520
-
1521
- return nodes;
1546
+ function getTokenDesc(token) {
1547
+ var value = token.value;
1548
+ return value ? "".concat(token.kind, " \"").concat(value, "\"") : token.kind;
1522
1549
  }