graphql 0.0.1-test.1

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