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