graphql 15.1.0 → 15.4.0
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.
- package/LICENSE +1 -1
- package/README.md +10 -12
- package/error/GraphQLError.js +5 -5
- package/error/GraphQLError.js.flow +5 -5
- package/error/GraphQLError.mjs +1 -1
- package/error/formatError.js +1 -1
- package/error/formatError.js.flow +2 -3
- package/error/index.js +4 -4
- package/error/index.js.flow +0 -1
- package/error/locatedError.d.ts +2 -2
- package/error/locatedError.js +10 -5
- package/error/locatedError.js.flow +11 -5
- package/error/locatedError.mjs +6 -4
- package/error/syntaxError.js +1 -1
- package/error/syntaxError.js.flow +1 -2
- package/execution/execute.d.ts +24 -16
- package/execution/execute.js +123 -105
- package/execution/execute.js.flow +169 -153
- package/execution/execute.mjs +101 -82
- package/execution/index.d.ts +2 -0
- package/execution/index.js +9 -3
- package/execution/index.js.flow +12 -3
- package/execution/index.mjs +1 -1
- package/execution/values.js +11 -11
- package/execution/values.js.flow +10 -14
- package/graphql.js +5 -5
- package/graphql.js.flow +9 -9
- package/index.d.ts +19 -1
- package/index.js +27 -9
- package/index.js.flow +10 -3
- package/index.mjs +4 -3
- package/jsutils/ObjMap.js.flow +0 -1
- package/jsutils/Path.d.ts +6 -1
- package/jsutils/Path.js +3 -2
- package/jsutils/Path.js.flow +3 -2
- package/jsutils/Path.mjs +3 -2
- package/jsutils/PromiseOrValue.js.flow +0 -1
- package/jsutils/defineInspect.js +2 -2
- package/jsutils/defineInspect.js.flow +0 -1
- package/jsutils/devAssert.js.flow +0 -1
- package/jsutils/didYouMean.js.flow +0 -1
- package/jsutils/identityFunc.js.flow +0 -1
- package/jsutils/inspect.js +1 -2
- package/jsutils/inspect.js.flow +10 -8
- package/jsutils/inspect.mjs +1 -1
- package/jsutils/instanceOf.js.flow +2 -3
- package/jsutils/invariant.js.flow +0 -1
- package/jsutils/isAsyncIterable.js +19 -0
- package/jsutils/isAsyncIterable.js.flow +18 -0
- package/jsutils/isAsyncIterable.mjs +16 -0
- package/jsutils/isCollection.js +1 -1
- package/jsutils/isCollection.js.flow +0 -1
- package/jsutils/isObjectLike.js.flow +0 -1
- package/jsutils/isPromise.js.flow +0 -1
- package/jsutils/keyMap.js.flow +1 -2
- package/jsutils/keyValMap.js.flow +1 -2
- package/jsutils/mapValue.js +1 -1
- package/jsutils/mapValue.js.flow +1 -2
- package/jsutils/memoize3.js +2 -5
- package/jsutils/memoize3.js.flow +2 -5
- package/jsutils/memoize3.mjs +2 -5
- package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
- package/jsutils/printPathArray.js.flow +0 -1
- package/jsutils/promiseForObject.js.flow +1 -2
- package/jsutils/promiseReduce.js +1 -1
- package/jsutils/promiseReduce.js.flow +1 -1
- package/jsutils/promiseReduce.mjs +1 -1
- package/jsutils/suggestionList.js.flow +1 -2
- package/jsutils/toObjMap.js +1 -1
- package/jsutils/toObjMap.js.flow +5 -6
- package/language/ast.js +1 -1
- package/language/ast.js.flow +2 -3
- package/language/blockString.d.ts +1 -1
- package/language/blockString.js +53 -32
- package/language/blockString.js.flow +49 -34
- package/language/blockString.mjs +54 -33
- package/language/directiveLocation.js.flow +0 -1
- package/language/experimentalOnlineParser/grammar.d.ts +1006 -0
- package/language/experimentalOnlineParser/grammar.js +987 -0
- package/language/experimentalOnlineParser/grammar.js.flow +1000 -0
- package/language/experimentalOnlineParser/grammar.mjs +980 -0
- package/language/experimentalOnlineParser/index.d.ts +6 -0
- package/language/experimentalOnlineParser/index.js +31 -0
- package/language/experimentalOnlineParser/index.js.flow +7 -0
- package/language/experimentalOnlineParser/index.mjs +1 -0
- package/language/experimentalOnlineParser/onlineParser.d.ts +125 -0
- package/language/experimentalOnlineParser/onlineParser.js +604 -0
- package/language/experimentalOnlineParser/onlineParser.js.flow +723 -0
- package/language/experimentalOnlineParser/onlineParser.mjs +587 -0
- package/language/index.js +12 -12
- package/language/index.js.flow +0 -1
- package/language/kinds.js.flow +0 -1
- package/language/lexer.js +242 -183
- package/language/lexer.js.flow +191 -186
- package/language/lexer.mjs +239 -180
- package/language/location.js.flow +1 -2
- package/language/parser.js +73 -68
- package/language/parser.js.flow +112 -106
- package/language/parser.mjs +66 -62
- package/language/predicates.js +1 -1
- package/language/predicates.js.flow +1 -2
- package/language/printLocation.js +1 -1
- package/language/printLocation.js.flow +4 -4
- package/language/printer.js +20 -13
- package/language/printer.js.flow +27 -25
- package/language/printer.mjs +18 -11
- package/language/source.d.ts +12 -6
- package/language/source.js +25 -9
- package/language/source.js.flow +25 -8
- package/language/source.mjs +19 -7
- package/language/tokenKind.js.flow +0 -1
- package/language/visitor.d.ts +3 -3
- package/language/visitor.js +5 -5
- package/language/visitor.js.flow +5 -5
- package/language/visitor.mjs +3 -3
- package/package.json +1 -1
- package/polyfills/arrayFrom.js +2 -2
- package/polyfills/arrayFrom.js.flow +1 -2
- package/polyfills/arrayFrom.mjs +1 -1
- package/polyfills/find.js +1 -1
- package/polyfills/find.js.flow +1 -2
- package/polyfills/find.mjs +1 -1
- package/polyfills/isFinite.js +1 -1
- package/polyfills/isFinite.js.flow +1 -2
- package/polyfills/isFinite.mjs +1 -1
- package/polyfills/isInteger.js +1 -1
- package/polyfills/isInteger.js.flow +1 -2
- package/polyfills/isInteger.mjs +1 -1
- package/polyfills/objectEntries.js +1 -1
- package/polyfills/objectEntries.js.flow +2 -3
- package/polyfills/objectEntries.mjs +1 -1
- package/polyfills/objectValues.js +1 -1
- package/polyfills/objectValues.js.flow +2 -3
- package/polyfills/objectValues.mjs +1 -1
- package/polyfills/symbols.js +3 -5
- package/polyfills/symbols.js.flow +9 -6
- package/polyfills/symbols.mjs +3 -5
- package/subscription/index.js +1 -1
- package/subscription/index.js.flow +0 -1
- package/subscription/mapAsyncIterator.js +2 -2
- package/subscription/mapAsyncIterator.js.flow +9 -10
- package/subscription/mapAsyncIterator.mjs +1 -1
- package/subscription/subscribe.js +61 -73
- package/subscription/subscribe.js.flow +74 -88
- package/subscription/subscribe.mjs +53 -65
- package/type/definition.d.ts +181 -31
- package/type/definition.js +37 -32
- package/type/definition.js.flow +66 -51
- package/type/definition.mjs +20 -18
- package/type/directives.d.ts +17 -3
- package/type/directives.js +17 -16
- package/type/directives.js.flow +20 -21
- package/type/directives.mjs +6 -5
- package/type/index.d.ts +12 -0
- package/type/index.js +6 -6
- package/type/index.js.flow +0 -1
- package/type/introspection.js +86 -68
- package/type/introspection.js.flow +85 -54
- package/type/introspection.mjs +79 -61
- package/type/scalars.js +9 -9
- package/type/scalars.js.flow +3 -3
- package/type/scalars.mjs +1 -1
- package/type/schema.d.ts +17 -4
- package/type/schema.js +13 -13
- package/type/schema.js.flow +18 -16
- package/type/schema.mjs +1 -1
- package/type/validate.js +52 -19
- package/type/validate.js.flow +67 -18
- package/type/validate.mjs +44 -10
- package/utilities/TypeInfo.js +7 -7
- package/utilities/TypeInfo.js.flow +16 -18
- package/utilities/TypeInfo.mjs +1 -1
- package/utilities/assertValidName.js +2 -2
- package/utilities/assertValidName.js.flow +0 -1
- package/utilities/astFromValue.js +10 -10
- package/utilities/astFromValue.js.flow +2 -3
- package/utilities/buildASTSchema.js +17 -27
- package/utilities/buildASTSchema.js.flow +11 -28
- package/utilities/buildASTSchema.mjs +11 -21
- package/utilities/buildClientSchema.js +14 -14
- package/utilities/buildClientSchema.js.flow +41 -29
- package/utilities/buildClientSchema.mjs +5 -5
- package/utilities/coerceInputValue.js +14 -14
- package/utilities/coerceInputValue.js.flow +7 -6
- package/utilities/coerceInputValue.mjs +2 -2
- package/utilities/concatAST.js +9 -8
- package/utilities/concatAST.js.flow +9 -9
- package/utilities/concatAST.mjs +9 -6
- package/utilities/extendSchema.js +26 -19
- package/utilities/extendSchema.js.flow +58 -45
- package/utilities/extendSchema.mjs +9 -2
- package/utilities/findBreakingChanges.js +9 -9
- package/utilities/findBreakingChanges.js.flow +12 -11
- package/utilities/findDeprecatedUsages.d.ts +9 -1
- package/utilities/findDeprecatedUsages.js +11 -27
- package/utilities/findDeprecatedUsages.js.flow +15 -44
- package/utilities/findDeprecatedUsages.mjs +11 -25
- package/utilities/getIntrospectionQuery.js.flow +2 -3
- package/utilities/getOperationAST.js +1 -1
- package/utilities/getOperationAST.js.flow +1 -5
- package/utilities/getOperationAST.mjs +1 -1
- package/utilities/getOperationRootType.js +1 -1
- package/utilities/getOperationRootType.js.flow +5 -6
- package/utilities/index.d.ts +4 -1
- package/utilities/index.js +22 -22
- package/utilities/index.js.flow +1 -2
- package/utilities/index.mjs +1 -1
- package/utilities/introspectionFromSchema.js +6 -8
- package/utilities/introspectionFromSchema.js.flow +10 -10
- package/utilities/introspectionFromSchema.mjs +3 -4
- package/utilities/lexicographicSortSchema.js +10 -8
- package/utilities/lexicographicSortSchema.js.flow +19 -12
- package/utilities/lexicographicSortSchema.mjs +3 -1
- package/utilities/printSchema.js +15 -16
- package/utilities/printSchema.js.flow +34 -25
- package/utilities/printSchema.mjs +6 -7
- package/utilities/separateOperations.js +2 -2
- package/utilities/separateOperations.js.flow +2 -6
- package/utilities/separateOperations.mjs +1 -1
- package/utilities/stripIgnoredCharacters.js +6 -16
- package/utilities/stripIgnoredCharacters.js.flow +4 -13
- package/utilities/stripIgnoredCharacters.mjs +3 -10
- package/utilities/typeComparators.js +1 -1
- package/utilities/typeComparators.js.flow +2 -4
- package/utilities/typeFromAST.js +6 -6
- package/utilities/typeFromAST.js.flow +11 -14
- package/utilities/typeFromAST.mjs +2 -2
- package/utilities/typedQueryDocumentNode.d.ts +20 -0
- package/utilities/valueFromAST.js +6 -6
- package/utilities/valueFromAST.js.flow +7 -5
- package/utilities/valueFromASTUntyped.js +4 -4
- package/utilities/valueFromASTUntyped.js.flow +2 -3
- package/validation/ValidationContext.d.ts +3 -0
- package/validation/ValidationContext.js +7 -3
- package/validation/ValidationContext.js.flow +28 -22
- package/validation/ValidationContext.mjs +4 -0
- package/validation/index.d.ts +4 -0
- package/validation/index.js +52 -36
- package/validation/index.js.flow +4 -1
- package/validation/index.mjs +4 -1
- package/validation/rules/ExecutableDefinitions.js +1 -1
- package/validation/rules/ExecutableDefinitions.js.flow +0 -1
- package/validation/rules/ExecutableDefinitionsRule.js +3 -3
- package/validation/rules/ExecutableDefinitionsRule.js.flow +2 -3
- package/validation/rules/FieldsOnCorrectTypeRule.js +5 -5
- package/validation/rules/FieldsOnCorrectTypeRule.js.flow +9 -8
- package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +2 -3
- package/validation/rules/KnownArgumentNamesRule.js +5 -5
- package/validation/rules/KnownArgumentNamesRule.js.flow +5 -5
- package/validation/rules/KnownDirectivesRule.js +6 -6
- package/validation/rules/KnownDirectivesRule.js.flow +10 -11
- package/validation/rules/KnownFragmentNamesRule.js +1 -1
- package/validation/rules/KnownFragmentNamesRule.js.flow +3 -3
- package/validation/rules/KnownTypeNamesRule.js +12 -10
- package/validation/rules/KnownTypeNamesRule.js.flow +14 -11
- package/validation/rules/KnownTypeNamesRule.mjs +6 -5
- package/validation/rules/LoneAnonymousOperationRule.js +2 -2
- package/validation/rules/LoneAnonymousOperationRule.js.flow +2 -3
- package/validation/rules/LoneSchemaDefinition.js +1 -1
- package/validation/rules/LoneSchemaDefinition.js.flow +0 -1
- package/validation/rules/LoneSchemaDefinitionRule.js +1 -1
- package/validation/rules/LoneSchemaDefinitionRule.js.flow +2 -3
- package/validation/rules/NoFragmentCyclesRule.js +1 -1
- package/validation/rules/NoFragmentCyclesRule.js.flow +4 -5
- package/validation/rules/NoUndefinedVariablesRule.js +1 -1
- package/validation/rules/NoUndefinedVariablesRule.js.flow +3 -3
- package/validation/rules/NoUnusedFragmentsRule.js +1 -1
- package/validation/rules/NoUnusedFragmentsRule.js.flow +3 -3
- package/validation/rules/NoUnusedVariablesRule.js +1 -1
- package/validation/rules/NoUnusedVariablesRule.js.flow +3 -3
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +29 -27
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
- package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
- package/validation/rules/PossibleFragmentSpreadsRule.js.flow +7 -4
- package/validation/rules/PossibleTypeExtensions.js +1 -1
- package/validation/rules/PossibleTypeExtensions.js.flow +0 -1
- package/validation/rules/PossibleTypeExtensionsRule.js +8 -8
- package/validation/rules/PossibleTypeExtensionsRule.js.flow +8 -6
- package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
- package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +7 -6
- package/validation/rules/ScalarLeafsRule.js +3 -3
- package/validation/rules/ScalarLeafsRule.js.flow +3 -4
- package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.js.flow +3 -4
- package/validation/rules/UniqueArgumentNamesRule.js +1 -1
- package/validation/rules/UniqueArgumentNamesRule.js.flow +2 -3
- package/validation/rules/UniqueDirectiveNames.js +1 -1
- package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNamesRule.js +1 -1
- package/validation/rules/UniqueDirectiveNamesRule.js.flow +2 -3
- package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +4 -5
- package/validation/rules/UniqueEnumValueNames.js +1 -1
- package/validation/rules/UniqueEnumValueNames.js.flow +0 -1
- package/validation/rules/UniqueEnumValueNamesRule.js +2 -2
- package/validation/rules/UniqueEnumValueNamesRule.js.flow +11 -4
- package/validation/rules/UniqueFieldDefinitionNames.js +1 -1
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +0 -1
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -3
- package/validation/rules/UniqueFieldDefinitionNamesRule.js.flow +17 -6
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js.flow +3 -3
- package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.js.flow +3 -3
- package/validation/rules/UniqueOperationNamesRule.js +1 -1
- package/validation/rules/UniqueOperationNamesRule.js.flow +3 -3
- package/validation/rules/UniqueOperationTypes.js +1 -1
- package/validation/rules/UniqueOperationTypes.js.flow +0 -1
- package/validation/rules/UniqueOperationTypesRule.js +1 -1
- package/validation/rules/UniqueOperationTypesRule.js.flow +10 -4
- package/validation/rules/UniqueTypeNames.js +1 -1
- package/validation/rules/UniqueTypeNames.js.flow +0 -1
- package/validation/rules/UniqueTypeNamesRule.js +1 -1
- package/validation/rules/UniqueTypeNamesRule.js.flow +3 -4
- package/validation/rules/UniqueVariableNamesRule.js +1 -1
- package/validation/rules/UniqueVariableNamesRule.js.flow +3 -4
- package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
- package/validation/rules/ValuesOfCorrectTypeRule.js.flow +3 -4
- package/validation/rules/VariablesAreInputTypesRule.js +4 -4
- package/validation/rules/VariablesAreInputTypesRule.js.flow +3 -4
- package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
- package/validation/rules/VariablesInAllowedPositionRule.js.flow +6 -6
- package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +14 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.js +79 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +94 -0
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +68 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +16 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +34 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +38 -0
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +25 -0
- package/validation/specifiedRules.js +33 -33
- package/validation/specifiedRules.js.flow +0 -1
- package/validation/validate.js +7 -7
- package/validation/validate.js.flow +4 -9
- package/version.js +2 -2
- package/version.js.flow +2 -3
- package/version.mjs +2 -2
- package/polyfills/flatMap.js +0 -30
- package/polyfills/flatMap.js.flow +0 -28
- package/polyfills/flatMap.mjs +0 -23
package/language/parser.js
CHANGED
|
@@ -6,26 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.parse = parse;
|
|
7
7
|
exports.parseValue = parseValue;
|
|
8
8
|
exports.parseType = parseType;
|
|
9
|
+
exports.Parser = void 0;
|
|
9
10
|
|
|
10
|
-
var
|
|
11
|
+
var _syntaxError = require("../error/syntaxError.js");
|
|
11
12
|
|
|
12
|
-
var
|
|
13
|
+
var _kinds = require("./kinds.js");
|
|
13
14
|
|
|
14
|
-
var
|
|
15
|
+
var _ast = require("./ast.js");
|
|
15
16
|
|
|
16
|
-
var
|
|
17
|
+
var _tokenKind = require("./tokenKind.js");
|
|
17
18
|
|
|
18
|
-
var _source = require("./source");
|
|
19
|
+
var _source = require("./source.js");
|
|
19
20
|
|
|
20
|
-
var _directiveLocation = require("./directiveLocation");
|
|
21
|
+
var _directiveLocation = require("./directiveLocation.js");
|
|
21
22
|
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var _lexer = require("./lexer");
|
|
25
|
-
|
|
26
|
-
var _ast = require("./ast");
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
var _lexer = require("./lexer.js");
|
|
29
24
|
|
|
30
25
|
/**
|
|
31
26
|
* Given a GraphQL source, parses it into a Document.
|
|
@@ -73,11 +68,22 @@ function parseType(source, options) {
|
|
|
73
68
|
parser.expectToken(_tokenKind.TokenKind.EOF);
|
|
74
69
|
return type;
|
|
75
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* This class is exported only to assist people in implementing their own parsers
|
|
73
|
+
* without duplicating too much code and should be used only as last resort for cases
|
|
74
|
+
* such as experimental syntax or if certain features could not be contributed upstream.
|
|
75
|
+
*
|
|
76
|
+
* It is still part of the internal API and is versioned, so any changes to it are never
|
|
77
|
+
* considered breaking changes. If you still need to support multiple versions of the
|
|
78
|
+
* library, please use the `versionInfo` variable for version detection.
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
|
|
76
83
|
|
|
77
84
|
var Parser = /*#__PURE__*/function () {
|
|
78
85
|
function Parser(source, options) {
|
|
79
|
-
var sourceObj =
|
|
80
|
-
sourceObj instanceof _source.Source || (0, _devAssert.default)(0, "Must provide Source. Received: ".concat((0, _inspect.default)(sourceObj), "."));
|
|
86
|
+
var sourceObj = (0, _source.isSource)(source) ? source : new _source.Source(source);
|
|
81
87
|
this._lexer = new _lexer.Lexer(sourceObj);
|
|
82
88
|
this._options = options;
|
|
83
89
|
}
|
|
@@ -822,21 +828,25 @@ var Parser = /*#__PURE__*/function () {
|
|
|
822
828
|
;
|
|
823
829
|
|
|
824
830
|
_proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
|
|
825
|
-
var
|
|
831
|
+
var _this$_options2;
|
|
832
|
+
|
|
833
|
+
if (!this.expectOptionalKeyword('implements')) {
|
|
834
|
+
return [];
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
|
|
838
|
+
var types = []; // Optional leading ampersand
|
|
826
839
|
|
|
827
|
-
if (this.expectOptionalKeyword('implements')) {
|
|
828
|
-
// Optional leading ampersand
|
|
829
840
|
this.expectOptionalToken(_tokenKind.TokenKind.AMP);
|
|
830
841
|
|
|
831
842
|
do {
|
|
832
|
-
var _this$_options2;
|
|
833
|
-
|
|
834
843
|
types.push(this.parseNamedType());
|
|
835
|
-
} while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) ||
|
|
836
|
-
|
|
844
|
+
} while (this.expectOptionalToken(_tokenKind.TokenKind.AMP) || this.peek(_tokenKind.TokenKind.NAME));
|
|
845
|
+
|
|
846
|
+
return types;
|
|
837
847
|
}
|
|
838
848
|
|
|
839
|
-
return
|
|
849
|
+
return this.delimitedMany(_tokenKind.TokenKind.AMP, this.parseNamedType);
|
|
840
850
|
}
|
|
841
851
|
/**
|
|
842
852
|
* FieldsDefinition : { FieldDefinition+ }
|
|
@@ -972,18 +982,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
972
982
|
;
|
|
973
983
|
|
|
974
984
|
_proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
if (this.expectOptionalToken(_tokenKind.TokenKind.EQUALS)) {
|
|
978
|
-
// Optional leading pipe
|
|
979
|
-
this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
|
|
980
|
-
|
|
981
|
-
do {
|
|
982
|
-
types.push(this.parseNamedType());
|
|
983
|
-
} while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
return types;
|
|
985
|
+
return this.expectOptionalToken(_tokenKind.TokenKind.EQUALS) ? this.delimitedMany(_tokenKind.TokenKind.PIPE, this.parseNamedType) : [];
|
|
987
986
|
}
|
|
988
987
|
/**
|
|
989
988
|
* EnumTypeDefinition :
|
|
@@ -1334,15 +1333,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1334
1333
|
;
|
|
1335
1334
|
|
|
1336
1335
|
_proto.parseDirectiveLocations = function parseDirectiveLocations() {
|
|
1337
|
-
|
|
1338
|
-
this.expectOptionalToken(_tokenKind.TokenKind.PIPE);
|
|
1339
|
-
var locations = [];
|
|
1340
|
-
|
|
1341
|
-
do {
|
|
1342
|
-
locations.push(this.parseDirectiveLocation());
|
|
1343
|
-
} while (this.expectOptionalToken(_tokenKind.TokenKind.PIPE));
|
|
1344
|
-
|
|
1345
|
-
return locations;
|
|
1336
|
+
return this.delimitedMany(_tokenKind.TokenKind.PIPE, this.parseDirectiveLocation);
|
|
1346
1337
|
}
|
|
1347
1338
|
/*
|
|
1348
1339
|
* DirectiveLocation :
|
|
@@ -1385,8 +1376,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1385
1376
|
} // Core parsing utility functions
|
|
1386
1377
|
|
|
1387
1378
|
/**
|
|
1388
|
-
* Returns a location object, used to identify the place in
|
|
1389
|
-
* the source that created a given parsed object.
|
|
1379
|
+
* Returns a location object, used to identify the place in the source that created a given parsed object.
|
|
1390
1380
|
*/
|
|
1391
1381
|
;
|
|
1392
1382
|
|
|
@@ -1406,8 +1396,8 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1406
1396
|
return this._lexer.token.kind === kind;
|
|
1407
1397
|
}
|
|
1408
1398
|
/**
|
|
1409
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1410
|
-
*
|
|
1399
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1400
|
+
* Otherwise, do not change the parser state and throw an error.
|
|
1411
1401
|
*/
|
|
1412
1402
|
;
|
|
1413
1403
|
|
|
@@ -1423,8 +1413,8 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1423
1413
|
throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
|
|
1424
1414
|
}
|
|
1425
1415
|
/**
|
|
1426
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1427
|
-
*
|
|
1416
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1417
|
+
* Otherwise, do not change the parser state and return undefined.
|
|
1428
1418
|
*/
|
|
1429
1419
|
;
|
|
1430
1420
|
|
|
@@ -1455,8 +1445,8 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1455
1445
|
}
|
|
1456
1446
|
}
|
|
1457
1447
|
/**
|
|
1458
|
-
* If the next token is a given keyword, return "true" after advancing
|
|
1459
|
-
*
|
|
1448
|
+
* If the next token is a given keyword, return "true" after advancing the lexer.
|
|
1449
|
+
* Otherwise, do not change the parser state and return "false".
|
|
1460
1450
|
*/
|
|
1461
1451
|
;
|
|
1462
1452
|
|
|
@@ -1472,8 +1462,7 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1472
1462
|
return false;
|
|
1473
1463
|
}
|
|
1474
1464
|
/**
|
|
1475
|
-
* Helper function for creating an error when an unexpected lexed token
|
|
1476
|
-
* is encountered.
|
|
1465
|
+
* Helper function for creating an error when an unexpected lexed token is encountered.
|
|
1477
1466
|
*/
|
|
1478
1467
|
;
|
|
1479
1468
|
|
|
@@ -1482,10 +1471,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1482
1471
|
return (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token), "."));
|
|
1483
1472
|
}
|
|
1484
1473
|
/**
|
|
1485
|
-
* Returns a possibly empty list of parse nodes, determined by
|
|
1486
|
-
*
|
|
1487
|
-
*
|
|
1488
|
-
* to the next lex token after the closing token.
|
|
1474
|
+
* Returns a possibly empty list of parse nodes, determined by the parseFn.
|
|
1475
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1476
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1489
1477
|
*/
|
|
1490
1478
|
;
|
|
1491
1479
|
|
|
@@ -1501,10 +1489,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1501
1489
|
}
|
|
1502
1490
|
/**
|
|
1503
1491
|
* Returns a list of parse nodes, determined by the parseFn.
|
|
1504
|
-
* It can be empty only if open token is missing otherwise it will always
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
* after the closing token.
|
|
1492
|
+
* It can be empty only if open token is missing otherwise it will always return non-empty list
|
|
1493
|
+
* that begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1494
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1508
1495
|
*/
|
|
1509
1496
|
;
|
|
1510
1497
|
|
|
@@ -1522,10 +1509,9 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1522
1509
|
return [];
|
|
1523
1510
|
}
|
|
1524
1511
|
/**
|
|
1525
|
-
* Returns a non-empty list of parse nodes, determined by
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
1528
|
-
* to the next lex token after the closing token.
|
|
1512
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1513
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1514
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1529
1515
|
*/
|
|
1530
1516
|
;
|
|
1531
1517
|
|
|
@@ -1537,22 +1523,41 @@ var Parser = /*#__PURE__*/function () {
|
|
|
1537
1523
|
nodes.push(parseFn.call(this));
|
|
1538
1524
|
} while (!this.expectOptionalToken(closeKind));
|
|
1539
1525
|
|
|
1526
|
+
return nodes;
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1530
|
+
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
|
|
1531
|
+
* Advances the parser to the next lex token after last item in the list.
|
|
1532
|
+
*/
|
|
1533
|
+
;
|
|
1534
|
+
|
|
1535
|
+
_proto.delimitedMany = function delimitedMany(delimiterKind, parseFn) {
|
|
1536
|
+
this.expectOptionalToken(delimiterKind);
|
|
1537
|
+
var nodes = [];
|
|
1538
|
+
|
|
1539
|
+
do {
|
|
1540
|
+
nodes.push(parseFn.call(this));
|
|
1541
|
+
} while (this.expectOptionalToken(delimiterKind));
|
|
1542
|
+
|
|
1540
1543
|
return nodes;
|
|
1541
1544
|
};
|
|
1542
1545
|
|
|
1543
1546
|
return Parser;
|
|
1544
1547
|
}();
|
|
1545
1548
|
/**
|
|
1546
|
-
* A helper function to describe a token as a string for debugging
|
|
1549
|
+
* A helper function to describe a token as a string for debugging.
|
|
1547
1550
|
*/
|
|
1548
1551
|
|
|
1549
1552
|
|
|
1553
|
+
exports.Parser = Parser;
|
|
1554
|
+
|
|
1550
1555
|
function getTokenDesc(token) {
|
|
1551
1556
|
var value = token.value;
|
|
1552
1557
|
return getTokenKindDesc(token.kind) + (value != null ? " \"".concat(value, "\"") : '');
|
|
1553
1558
|
}
|
|
1554
1559
|
/**
|
|
1555
|
-
* A helper function to describe a token kind as a string for debugging
|
|
1560
|
+
* A helper function to describe a token kind as a string for debugging.
|
|
1556
1561
|
*/
|
|
1557
1562
|
|
|
1558
1563
|
|
package/language/parser.js.flow
CHANGED
|
@@ -1,63 +1,60 @@
|
|
|
1
1
|
// @flow strict
|
|
2
|
-
|
|
3
|
-
import inspect from '../jsutils/inspect';
|
|
4
|
-
import devAssert from '../jsutils/devAssert';
|
|
5
|
-
|
|
2
|
+
import type { GraphQLError } from '../error/GraphQLError';
|
|
6
3
|
import { syntaxError } from '../error/syntaxError';
|
|
7
|
-
import { type GraphQLError } from '../error/GraphQLError';
|
|
8
4
|
|
|
5
|
+
import type { TokenKindEnum } from './tokenKind';
|
|
6
|
+
import type {
|
|
7
|
+
Token,
|
|
8
|
+
NameNode,
|
|
9
|
+
VariableNode,
|
|
10
|
+
DocumentNode,
|
|
11
|
+
DefinitionNode,
|
|
12
|
+
OperationDefinitionNode,
|
|
13
|
+
OperationTypeNode,
|
|
14
|
+
VariableDefinitionNode,
|
|
15
|
+
SelectionSetNode,
|
|
16
|
+
SelectionNode,
|
|
17
|
+
FieldNode,
|
|
18
|
+
ArgumentNode,
|
|
19
|
+
FragmentSpreadNode,
|
|
20
|
+
InlineFragmentNode,
|
|
21
|
+
FragmentDefinitionNode,
|
|
22
|
+
ValueNode,
|
|
23
|
+
StringValueNode,
|
|
24
|
+
ListValueNode,
|
|
25
|
+
ObjectValueNode,
|
|
26
|
+
ObjectFieldNode,
|
|
27
|
+
DirectiveNode,
|
|
28
|
+
TypeNode,
|
|
29
|
+
NamedTypeNode,
|
|
30
|
+
TypeSystemDefinitionNode,
|
|
31
|
+
SchemaDefinitionNode,
|
|
32
|
+
OperationTypeDefinitionNode,
|
|
33
|
+
ScalarTypeDefinitionNode,
|
|
34
|
+
ObjectTypeDefinitionNode,
|
|
35
|
+
FieldDefinitionNode,
|
|
36
|
+
InputValueDefinitionNode,
|
|
37
|
+
InterfaceTypeDefinitionNode,
|
|
38
|
+
UnionTypeDefinitionNode,
|
|
39
|
+
EnumTypeDefinitionNode,
|
|
40
|
+
EnumValueDefinitionNode,
|
|
41
|
+
InputObjectTypeDefinitionNode,
|
|
42
|
+
DirectiveDefinitionNode,
|
|
43
|
+
TypeSystemExtensionNode,
|
|
44
|
+
SchemaExtensionNode,
|
|
45
|
+
ScalarTypeExtensionNode,
|
|
46
|
+
ObjectTypeExtensionNode,
|
|
47
|
+
InterfaceTypeExtensionNode,
|
|
48
|
+
UnionTypeExtensionNode,
|
|
49
|
+
EnumTypeExtensionNode,
|
|
50
|
+
InputObjectTypeExtensionNode,
|
|
51
|
+
} from './ast';
|
|
9
52
|
import { Kind } from './kinds';
|
|
10
|
-
import {
|
|
53
|
+
import { Location } from './ast';
|
|
54
|
+
import { TokenKind } from './tokenKind';
|
|
55
|
+
import { Source, isSource } from './source';
|
|
11
56
|
import { DirectiveLocation } from './directiveLocation';
|
|
12
|
-
import { type TokenKindEnum, TokenKind } from './tokenKind';
|
|
13
57
|
import { Lexer, isPunctuatorTokenKind } from './lexer';
|
|
14
|
-
import {
|
|
15
|
-
Location,
|
|
16
|
-
type Token,
|
|
17
|
-
type NameNode,
|
|
18
|
-
type VariableNode,
|
|
19
|
-
type DocumentNode,
|
|
20
|
-
type DefinitionNode,
|
|
21
|
-
type OperationDefinitionNode,
|
|
22
|
-
type OperationTypeNode,
|
|
23
|
-
type VariableDefinitionNode,
|
|
24
|
-
type SelectionSetNode,
|
|
25
|
-
type SelectionNode,
|
|
26
|
-
type FieldNode,
|
|
27
|
-
type ArgumentNode,
|
|
28
|
-
type FragmentSpreadNode,
|
|
29
|
-
type InlineFragmentNode,
|
|
30
|
-
type FragmentDefinitionNode,
|
|
31
|
-
type ValueNode,
|
|
32
|
-
type StringValueNode,
|
|
33
|
-
type ListValueNode,
|
|
34
|
-
type ObjectValueNode,
|
|
35
|
-
type ObjectFieldNode,
|
|
36
|
-
type DirectiveNode,
|
|
37
|
-
type TypeNode,
|
|
38
|
-
type NamedTypeNode,
|
|
39
|
-
type TypeSystemDefinitionNode,
|
|
40
|
-
type SchemaDefinitionNode,
|
|
41
|
-
type OperationTypeDefinitionNode,
|
|
42
|
-
type ScalarTypeDefinitionNode,
|
|
43
|
-
type ObjectTypeDefinitionNode,
|
|
44
|
-
type FieldDefinitionNode,
|
|
45
|
-
type InputValueDefinitionNode,
|
|
46
|
-
type InterfaceTypeDefinitionNode,
|
|
47
|
-
type UnionTypeDefinitionNode,
|
|
48
|
-
type EnumTypeDefinitionNode,
|
|
49
|
-
type EnumValueDefinitionNode,
|
|
50
|
-
type InputObjectTypeDefinitionNode,
|
|
51
|
-
type DirectiveDefinitionNode,
|
|
52
|
-
type TypeSystemExtensionNode,
|
|
53
|
-
type SchemaExtensionNode,
|
|
54
|
-
type ScalarTypeExtensionNode,
|
|
55
|
-
type ObjectTypeExtensionNode,
|
|
56
|
-
type InterfaceTypeExtensionNode,
|
|
57
|
-
type UnionTypeExtensionNode,
|
|
58
|
-
type EnumTypeExtensionNode,
|
|
59
|
-
type InputObjectTypeExtensionNode,
|
|
60
|
-
} from './ast';
|
|
61
58
|
|
|
62
59
|
/**
|
|
63
60
|
* Configuration options to control parser behavior
|
|
@@ -163,16 +160,23 @@ export function parseType(
|
|
|
163
160
|
return type;
|
|
164
161
|
}
|
|
165
162
|
|
|
166
|
-
|
|
163
|
+
/**
|
|
164
|
+
* This class is exported only to assist people in implementing their own parsers
|
|
165
|
+
* without duplicating too much code and should be used only as last resort for cases
|
|
166
|
+
* such as experimental syntax or if certain features could not be contributed upstream.
|
|
167
|
+
*
|
|
168
|
+
* It is still part of the internal API and is versioned, so any changes to it are never
|
|
169
|
+
* considered breaking changes. If you still need to support multiple versions of the
|
|
170
|
+
* library, please use the `versionInfo` variable for version detection.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
export class Parser {
|
|
167
175
|
_options: ?ParseOptions;
|
|
168
176
|
_lexer: Lexer;
|
|
169
177
|
|
|
170
178
|
constructor(source: string | Source, options?: ParseOptions) {
|
|
171
|
-
const sourceObj =
|
|
172
|
-
devAssert(
|
|
173
|
-
sourceObj instanceof Source,
|
|
174
|
-
`Must provide Source. Received: ${inspect(sourceObj)}.`,
|
|
175
|
-
);
|
|
179
|
+
const sourceObj = isSource(source) ? source : new Source(source);
|
|
176
180
|
|
|
177
181
|
this._lexer = new Lexer(sourceObj);
|
|
178
182
|
this._options = options;
|
|
@@ -852,20 +856,24 @@ class Parser {
|
|
|
852
856
|
* - ImplementsInterfaces & NamedType
|
|
853
857
|
*/
|
|
854
858
|
parseImplementsInterfaces(): Array<NamedTypeNode> {
|
|
855
|
-
|
|
856
|
-
|
|
859
|
+
if (!this.expectOptionalKeyword('implements')) {
|
|
860
|
+
return [];
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
if (this._options?.allowLegacySDLImplementsInterfaces === true) {
|
|
864
|
+
const types = [];
|
|
857
865
|
// Optional leading ampersand
|
|
858
866
|
this.expectOptionalToken(TokenKind.AMP);
|
|
859
867
|
do {
|
|
860
868
|
types.push(this.parseNamedType());
|
|
861
869
|
} while (
|
|
862
870
|
this.expectOptionalToken(TokenKind.AMP) ||
|
|
863
|
-
|
|
864
|
-
(this._options?.allowLegacySDLImplementsInterfaces === true &&
|
|
865
|
-
this.peek(TokenKind.NAME))
|
|
871
|
+
this.peek(TokenKind.NAME)
|
|
866
872
|
);
|
|
873
|
+
return types;
|
|
867
874
|
}
|
|
868
|
-
|
|
875
|
+
|
|
876
|
+
return this.delimitedMany(TokenKind.AMP, this.parseNamedType);
|
|
869
877
|
}
|
|
870
878
|
|
|
871
879
|
/**
|
|
@@ -999,15 +1007,9 @@ class Parser {
|
|
|
999
1007
|
* - UnionMemberTypes | NamedType
|
|
1000
1008
|
*/
|
|
1001
1009
|
parseUnionMemberTypes(): Array<NamedTypeNode> {
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
this.expectOptionalToken(TokenKind.PIPE);
|
|
1006
|
-
do {
|
|
1007
|
-
types.push(this.parseNamedType());
|
|
1008
|
-
} while (this.expectOptionalToken(TokenKind.PIPE));
|
|
1009
|
-
}
|
|
1010
|
-
return types;
|
|
1010
|
+
return this.expectOptionalToken(TokenKind.EQUALS)
|
|
1011
|
+
? this.delimitedMany(TokenKind.PIPE, this.parseNamedType)
|
|
1012
|
+
: [];
|
|
1011
1013
|
}
|
|
1012
1014
|
|
|
1013
1015
|
/**
|
|
@@ -1343,13 +1345,7 @@ class Parser {
|
|
|
1343
1345
|
* - DirectiveLocations | DirectiveLocation
|
|
1344
1346
|
*/
|
|
1345
1347
|
parseDirectiveLocations(): Array<NameNode> {
|
|
1346
|
-
|
|
1347
|
-
this.expectOptionalToken(TokenKind.PIPE);
|
|
1348
|
-
const locations = [];
|
|
1349
|
-
do {
|
|
1350
|
-
locations.push(this.parseDirectiveLocation());
|
|
1351
|
-
} while (this.expectOptionalToken(TokenKind.PIPE));
|
|
1352
|
-
return locations;
|
|
1348
|
+
return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
|
|
1353
1349
|
}
|
|
1354
1350
|
|
|
1355
1351
|
/*
|
|
@@ -1391,8 +1387,7 @@ class Parser {
|
|
|
1391
1387
|
// Core parsing utility functions
|
|
1392
1388
|
|
|
1393
1389
|
/**
|
|
1394
|
-
* Returns a location object, used to identify the place in
|
|
1395
|
-
* the source that created a given parsed object.
|
|
1390
|
+
* Returns a location object, used to identify the place in the source that created a given parsed object.
|
|
1396
1391
|
*/
|
|
1397
1392
|
loc(startToken: Token): Location | void {
|
|
1398
1393
|
if (this._options?.noLocation !== true) {
|
|
@@ -1412,8 +1407,8 @@ class Parser {
|
|
|
1412
1407
|
}
|
|
1413
1408
|
|
|
1414
1409
|
/**
|
|
1415
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1416
|
-
*
|
|
1410
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1411
|
+
* Otherwise, do not change the parser state and throw an error.
|
|
1417
1412
|
*/
|
|
1418
1413
|
expectToken(kind: TokenKindEnum): Token {
|
|
1419
1414
|
const token = this._lexer.token;
|
|
@@ -1430,8 +1425,8 @@ class Parser {
|
|
|
1430
1425
|
}
|
|
1431
1426
|
|
|
1432
1427
|
/**
|
|
1433
|
-
* If the next token is of the given kind, return that token after advancing
|
|
1434
|
-
*
|
|
1428
|
+
* If the next token is of the given kind, return that token after advancing the lexer.
|
|
1429
|
+
* Otherwise, do not change the parser state and return undefined.
|
|
1435
1430
|
*/
|
|
1436
1431
|
expectOptionalToken(kind: TokenKindEnum): ?Token {
|
|
1437
1432
|
const token = this._lexer.token;
|
|
@@ -1460,8 +1455,8 @@ class Parser {
|
|
|
1460
1455
|
}
|
|
1461
1456
|
|
|
1462
1457
|
/**
|
|
1463
|
-
* If the next token is a given keyword, return "true" after advancing
|
|
1464
|
-
*
|
|
1458
|
+
* If the next token is a given keyword, return "true" after advancing the lexer.
|
|
1459
|
+
* Otherwise, do not change the parser state and return "false".
|
|
1465
1460
|
*/
|
|
1466
1461
|
expectOptionalKeyword(value: string): boolean {
|
|
1467
1462
|
const token = this._lexer.token;
|
|
@@ -1473,8 +1468,7 @@ class Parser {
|
|
|
1473
1468
|
}
|
|
1474
1469
|
|
|
1475
1470
|
/**
|
|
1476
|
-
* Helper function for creating an error when an unexpected lexed token
|
|
1477
|
-
* is encountered.
|
|
1471
|
+
* Helper function for creating an error when an unexpected lexed token is encountered.
|
|
1478
1472
|
*/
|
|
1479
1473
|
unexpected(atToken?: ?Token): GraphQLError {
|
|
1480
1474
|
const token = atToken ?? this._lexer.token;
|
|
@@ -1486,10 +1480,9 @@ class Parser {
|
|
|
1486
1480
|
}
|
|
1487
1481
|
|
|
1488
1482
|
/**
|
|
1489
|
-
* Returns a possibly empty list of parse nodes, determined by
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
* to the next lex token after the closing token.
|
|
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.
|
|
1493
1486
|
*/
|
|
1494
1487
|
any<T>(
|
|
1495
1488
|
openKind: TokenKindEnum,
|
|
@@ -1506,10 +1499,9 @@ class Parser {
|
|
|
1506
1499
|
|
|
1507
1500
|
/**
|
|
1508
1501
|
* Returns a list of parse nodes, determined by the parseFn.
|
|
1509
|
-
* It can be empty only if open token is missing otherwise it will always
|
|
1510
|
-
*
|
|
1511
|
-
*
|
|
1512
|
-
* after the closing token.
|
|
1502
|
+
* It can be empty only if open token is missing otherwise it will always return non-empty list
|
|
1503
|
+
* that begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1504
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1513
1505
|
*/
|
|
1514
1506
|
optionalMany<T>(
|
|
1515
1507
|
openKind: TokenKindEnum,
|
|
@@ -1527,10 +1519,9 @@ class Parser {
|
|
|
1527
1519
|
}
|
|
1528
1520
|
|
|
1529
1521
|
/**
|
|
1530
|
-
* Returns a non-empty list of parse nodes, determined by
|
|
1531
|
-
*
|
|
1532
|
-
*
|
|
1533
|
-
* to the next lex token after the closing token.
|
|
1522
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1523
|
+
* This list begins with a lex token of openKind and ends with a lex token of closeKind.
|
|
1524
|
+
* Advances the parser to the next lex token after the closing token.
|
|
1534
1525
|
*/
|
|
1535
1526
|
many<T>(
|
|
1536
1527
|
openKind: TokenKindEnum,
|
|
@@ -1544,10 +1535,25 @@ class Parser {
|
|
|
1544
1535
|
} while (!this.expectOptionalToken(closeKind));
|
|
1545
1536
|
return nodes;
|
|
1546
1537
|
}
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* Returns a non-empty list of parse nodes, determined by the parseFn.
|
|
1541
|
+
* This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
|
|
1542
|
+
* Advances the parser to the next lex token after last item in the list.
|
|
1543
|
+
*/
|
|
1544
|
+
delimitedMany<T>(delimiterKind: TokenKindEnum, parseFn: () => T): Array<T> {
|
|
1545
|
+
this.expectOptionalToken(delimiterKind);
|
|
1546
|
+
|
|
1547
|
+
const nodes = [];
|
|
1548
|
+
do {
|
|
1549
|
+
nodes.push(parseFn.call(this));
|
|
1550
|
+
} while (this.expectOptionalToken(delimiterKind));
|
|
1551
|
+
return nodes;
|
|
1552
|
+
}
|
|
1547
1553
|
}
|
|
1548
1554
|
|
|
1549
1555
|
/**
|
|
1550
|
-
* A helper function to describe a token as a string for debugging
|
|
1556
|
+
* A helper function to describe a token as a string for debugging.
|
|
1551
1557
|
*/
|
|
1552
1558
|
function getTokenDesc(token: Token): string {
|
|
1553
1559
|
const value = token.value;
|
|
@@ -1555,7 +1561,7 @@ function getTokenDesc(token: Token): string {
|
|
|
1555
1561
|
}
|
|
1556
1562
|
|
|
1557
1563
|
/**
|
|
1558
|
-
* A helper function to describe a token kind as a string for debugging
|
|
1564
|
+
* A helper function to describe a token kind as a string for debugging.
|
|
1559
1565
|
*/
|
|
1560
1566
|
function getTokenKindDesc(kind: TokenKindEnum): string {
|
|
1561
1567
|
return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind;
|