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/lexer.js.flow
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @flow strict
|
|
2
|
-
|
|
3
2
|
import { syntaxError } from '../error/syntaxError';
|
|
4
3
|
|
|
4
|
+
import type { Source } from './source';
|
|
5
|
+
import type { TokenKindEnum } from './tokenKind';
|
|
5
6
|
import { Token } from './ast';
|
|
6
|
-
import {
|
|
7
|
+
import { TokenKind } from './tokenKind';
|
|
7
8
|
import { dedentBlockStringValue } from './blockString';
|
|
8
|
-
import { type TokenKindEnum, TokenKind } from './tokenKind';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Given a Source object, creates a Lexer for that source.
|
|
@@ -95,7 +95,7 @@ export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean %checks {
|
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
function printCharCode(code) {
|
|
98
|
+
function printCharCode(code: number): string {
|
|
99
99
|
return (
|
|
100
100
|
// NaN/undefined represents access beyond the end of the file.
|
|
101
101
|
isNaN(code)
|
|
@@ -120,149 +120,159 @@ function readToken(lexer: Lexer, prev: Token): Token {
|
|
|
120
120
|
const body = source.body;
|
|
121
121
|
const bodyLength = body.length;
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
let pos = prev.end;
|
|
124
|
+
while (pos < bodyLength) {
|
|
125
|
+
const code = body.charCodeAt(pos);
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
127
|
+
const line = lexer.line;
|
|
128
|
+
const col = 1 + pos - lexer.lineStart;
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
130
|
+
// SourceCharacter
|
|
131
|
+
switch (code) {
|
|
132
|
+
case 0xfeff: // <BOM>
|
|
133
|
+
case 9: // \t
|
|
134
|
+
case 32: // <space>
|
|
135
|
+
case 44: // ,
|
|
136
|
+
++pos;
|
|
137
|
+
continue;
|
|
138
|
+
case 10: // \n
|
|
139
|
+
++pos;
|
|
140
|
+
++lexer.line;
|
|
141
|
+
lexer.lineStart = pos;
|
|
142
|
+
continue;
|
|
143
|
+
case 13: // \r
|
|
144
|
+
if (body.charCodeAt(pos + 1) === 10) {
|
|
145
|
+
pos += 2;
|
|
146
|
+
} else {
|
|
147
|
+
++pos;
|
|
148
|
+
}
|
|
149
|
+
++lexer.line;
|
|
150
|
+
lexer.lineStart = pos;
|
|
151
|
+
continue;
|
|
152
|
+
case 33: // !
|
|
153
|
+
return new Token(TokenKind.BANG, pos, pos + 1, line, col, prev);
|
|
154
|
+
case 35: // #
|
|
155
|
+
return readComment(source, pos, line, col, prev);
|
|
156
|
+
case 36: // $
|
|
157
|
+
return new Token(TokenKind.DOLLAR, pos, pos + 1, line, col, prev);
|
|
158
|
+
case 38: // &
|
|
159
|
+
return new Token(TokenKind.AMP, pos, pos + 1, line, col, prev);
|
|
160
|
+
case 40: // (
|
|
161
|
+
return new Token(TokenKind.PAREN_L, pos, pos + 1, line, col, prev);
|
|
162
|
+
case 41: // )
|
|
163
|
+
return new Token(TokenKind.PAREN_R, pos, pos + 1, line, col, prev);
|
|
164
|
+
case 46: // .
|
|
165
|
+
if (
|
|
166
|
+
body.charCodeAt(pos + 1) === 46 &&
|
|
167
|
+
body.charCodeAt(pos + 2) === 46
|
|
168
|
+
) {
|
|
169
|
+
return new Token(TokenKind.SPREAD, pos, pos + 3, line, col, prev);
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
case 58: // :
|
|
173
|
+
return new Token(TokenKind.COLON, pos, pos + 1, line, col, prev);
|
|
174
|
+
case 61: // =
|
|
175
|
+
return new Token(TokenKind.EQUALS, pos, pos + 1, line, col, prev);
|
|
176
|
+
case 64: // @
|
|
177
|
+
return new Token(TokenKind.AT, pos, pos + 1, line, col, prev);
|
|
178
|
+
case 91: // [
|
|
179
|
+
return new Token(TokenKind.BRACKET_L, pos, pos + 1, line, col, prev);
|
|
180
|
+
case 93: // ]
|
|
181
|
+
return new Token(TokenKind.BRACKET_R, pos, pos + 1, line, col, prev);
|
|
182
|
+
case 123: // {
|
|
183
|
+
return new Token(TokenKind.BRACE_L, pos, pos + 1, line, col, prev);
|
|
184
|
+
case 124: // |
|
|
185
|
+
return new Token(TokenKind.PIPE, pos, pos + 1, line, col, prev);
|
|
186
|
+
case 125: // }
|
|
187
|
+
return new Token(TokenKind.BRACE_R, pos, pos + 1, line, col, prev);
|
|
188
|
+
case 34: // "
|
|
189
|
+
if (
|
|
190
|
+
body.charCodeAt(pos + 1) === 34 &&
|
|
191
|
+
body.charCodeAt(pos + 2) === 34
|
|
192
|
+
) {
|
|
193
|
+
return readBlockString(source, pos, line, col, prev, lexer);
|
|
194
|
+
}
|
|
195
|
+
return readString(source, pos, line, col, prev);
|
|
196
|
+
case 45: // -
|
|
197
|
+
case 48: // 0
|
|
198
|
+
case 49: // 1
|
|
199
|
+
case 50: // 2
|
|
200
|
+
case 51: // 3
|
|
201
|
+
case 52: // 4
|
|
202
|
+
case 53: // 5
|
|
203
|
+
case 54: // 6
|
|
204
|
+
case 55: // 7
|
|
205
|
+
case 56: // 8
|
|
206
|
+
case 57: // 9
|
|
207
|
+
return readNumber(source, pos, code, line, col, prev);
|
|
208
|
+
case 65: // A
|
|
209
|
+
case 66: // B
|
|
210
|
+
case 67: // C
|
|
211
|
+
case 68: // D
|
|
212
|
+
case 69: // E
|
|
213
|
+
case 70: // F
|
|
214
|
+
case 71: // G
|
|
215
|
+
case 72: // H
|
|
216
|
+
case 73: // I
|
|
217
|
+
case 74: // J
|
|
218
|
+
case 75: // K
|
|
219
|
+
case 76: // L
|
|
220
|
+
case 77: // M
|
|
221
|
+
case 78: // N
|
|
222
|
+
case 79: // O
|
|
223
|
+
case 80: // P
|
|
224
|
+
case 81: // Q
|
|
225
|
+
case 82: // R
|
|
226
|
+
case 83: // S
|
|
227
|
+
case 84: // T
|
|
228
|
+
case 85: // U
|
|
229
|
+
case 86: // V
|
|
230
|
+
case 87: // W
|
|
231
|
+
case 88: // X
|
|
232
|
+
case 89: // Y
|
|
233
|
+
case 90: // Z
|
|
234
|
+
case 95: // _
|
|
235
|
+
case 97: // a
|
|
236
|
+
case 98: // b
|
|
237
|
+
case 99: // c
|
|
238
|
+
case 100: // d
|
|
239
|
+
case 101: // e
|
|
240
|
+
case 102: // f
|
|
241
|
+
case 103: // g
|
|
242
|
+
case 104: // h
|
|
243
|
+
case 105: // i
|
|
244
|
+
case 106: // j
|
|
245
|
+
case 107: // k
|
|
246
|
+
case 108: // l
|
|
247
|
+
case 109: // m
|
|
248
|
+
case 110: // n
|
|
249
|
+
case 111: // o
|
|
250
|
+
case 112: // p
|
|
251
|
+
case 113: // q
|
|
252
|
+
case 114: // r
|
|
253
|
+
case 115: // s
|
|
254
|
+
case 116: // t
|
|
255
|
+
case 117: // u
|
|
256
|
+
case 118: // v
|
|
257
|
+
case 119: // w
|
|
258
|
+
case 120: // x
|
|
259
|
+
case 121: // y
|
|
260
|
+
case 122: // z
|
|
261
|
+
return readName(source, pos, line, col, prev);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
throw syntaxError(source, pos, unexpectedCharacterMessage(code));
|
|
257
265
|
}
|
|
258
266
|
|
|
259
|
-
|
|
267
|
+
const line = lexer.line;
|
|
268
|
+
const col = 1 + pos - lexer.lineStart;
|
|
269
|
+
return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
|
|
260
270
|
}
|
|
261
271
|
|
|
262
272
|
/**
|
|
263
273
|
* Report a message that an unexpected character was encountered.
|
|
264
274
|
*/
|
|
265
|
-
function unexpectedCharacterMessage(code) {
|
|
275
|
+
function unexpectedCharacterMessage(code: number): string {
|
|
266
276
|
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
|
|
267
277
|
return `Cannot contain the invalid character ${printCharCode(code)}.`;
|
|
268
278
|
}
|
|
@@ -275,49 +285,18 @@ function unexpectedCharacterMessage(code) {
|
|
|
275
285
|
return `Cannot parse the unexpected character ${printCharCode(code)}.`;
|
|
276
286
|
}
|
|
277
287
|
|
|
278
|
-
/**
|
|
279
|
-
* Reads from body starting at startPosition until it finds a non-whitespace
|
|
280
|
-
* character, then returns the position of that character for lexing.
|
|
281
|
-
*/
|
|
282
|
-
function positionAfterWhitespace(
|
|
283
|
-
body: string,
|
|
284
|
-
startPosition: number,
|
|
285
|
-
lexer: Lexer,
|
|
286
|
-
): number {
|
|
287
|
-
const bodyLength = body.length;
|
|
288
|
-
let position = startPosition;
|
|
289
|
-
while (position < bodyLength) {
|
|
290
|
-
const code = body.charCodeAt(position);
|
|
291
|
-
// tab | space | comma | BOM
|
|
292
|
-
if (code === 9 || code === 32 || code === 44 || code === 0xfeff) {
|
|
293
|
-
++position;
|
|
294
|
-
} else if (code === 10) {
|
|
295
|
-
// new line
|
|
296
|
-
++position;
|
|
297
|
-
++lexer.line;
|
|
298
|
-
lexer.lineStart = position;
|
|
299
|
-
} else if (code === 13) {
|
|
300
|
-
// carriage return
|
|
301
|
-
if (body.charCodeAt(position + 1) === 10) {
|
|
302
|
-
position += 2;
|
|
303
|
-
} else {
|
|
304
|
-
++position;
|
|
305
|
-
}
|
|
306
|
-
++lexer.line;
|
|
307
|
-
lexer.lineStart = position;
|
|
308
|
-
} else {
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return position;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
288
|
/**
|
|
316
289
|
* Reads a comment token from the source file.
|
|
317
290
|
*
|
|
318
291
|
* #[\u0009\u0020-\uFFFF]*
|
|
319
292
|
*/
|
|
320
|
-
function readComment(
|
|
293
|
+
function readComment(
|
|
294
|
+
source: Source,
|
|
295
|
+
start: number,
|
|
296
|
+
line: number,
|
|
297
|
+
col: number,
|
|
298
|
+
prev: Token | null,
|
|
299
|
+
): Token {
|
|
321
300
|
const body = source.body;
|
|
322
301
|
let code;
|
|
323
302
|
let position = start;
|
|
@@ -348,7 +327,14 @@ function readComment(source, start, line, col, prev): Token {
|
|
|
348
327
|
* Int: -?(0|[1-9][0-9]*)
|
|
349
328
|
* Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
|
|
350
329
|
*/
|
|
351
|
-
function readNumber(
|
|
330
|
+
function readNumber(
|
|
331
|
+
source: Source,
|
|
332
|
+
start: number,
|
|
333
|
+
firstCode: number,
|
|
334
|
+
line: number,
|
|
335
|
+
col: number,
|
|
336
|
+
prev: Token | null,
|
|
337
|
+
): Token {
|
|
352
338
|
const body = source.body;
|
|
353
339
|
let code = firstCode;
|
|
354
340
|
let position = start;
|
|
@@ -419,7 +405,7 @@ function readNumber(source, start, firstCode, line, col, prev): Token {
|
|
|
419
405
|
/**
|
|
420
406
|
* Returns the new position in the source after reading digits.
|
|
421
407
|
*/
|
|
422
|
-
function readDigits(source, start, firstCode) {
|
|
408
|
+
function readDigits(source: Source, start: number, firstCode: number): number {
|
|
423
409
|
const body = source.body;
|
|
424
410
|
let position = start;
|
|
425
411
|
let code = firstCode;
|
|
@@ -442,7 +428,13 @@ function readDigits(source, start, firstCode) {
|
|
|
442
428
|
*
|
|
443
429
|
* "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
|
|
444
430
|
*/
|
|
445
|
-
function readString(
|
|
431
|
+
function readString(
|
|
432
|
+
source: Source,
|
|
433
|
+
start: number,
|
|
434
|
+
line: number,
|
|
435
|
+
col: number,
|
|
436
|
+
prev: Token | null,
|
|
437
|
+
): Token {
|
|
446
438
|
const body = source.body;
|
|
447
439
|
let position = start + 1;
|
|
448
440
|
let chunkStart = position;
|
|
@@ -551,7 +543,14 @@ function readString(source, start, line, col, prev): Token {
|
|
|
551
543
|
*
|
|
552
544
|
* """("?"?(\\"""|\\(?!=""")|[^"\\]))*"""
|
|
553
545
|
*/
|
|
554
|
-
function readBlockString(
|
|
546
|
+
function readBlockString(
|
|
547
|
+
source: Source,
|
|
548
|
+
start: number,
|
|
549
|
+
line: number,
|
|
550
|
+
col: number,
|
|
551
|
+
prev: Token | null,
|
|
552
|
+
lexer: Lexer,
|
|
553
|
+
): Token {
|
|
555
554
|
const body = source.body;
|
|
556
555
|
let position = start + 3;
|
|
557
556
|
let chunkStart = position;
|
|
@@ -633,7 +632,7 @@ function readBlockString(source, start, line, col, prev, lexer): Token {
|
|
|
633
632
|
* This is implemented by noting that char2hex() returns -1 on error,
|
|
634
633
|
* which means the result of ORing the char2hex() will also be negative.
|
|
635
634
|
*/
|
|
636
|
-
function uniCharCode(a, b, c, d) {
|
|
635
|
+
function uniCharCode(a: number, b: number, c: number, d: number): number {
|
|
637
636
|
return (
|
|
638
637
|
(char2hex(a) << 12) | (char2hex(b) << 8) | (char2hex(c) << 4) | char2hex(d)
|
|
639
638
|
);
|
|
@@ -647,7 +646,7 @@ function uniCharCode(a, b, c, d) {
|
|
|
647
646
|
*
|
|
648
647
|
* Returns -1 on error.
|
|
649
648
|
*/
|
|
650
|
-
function char2hex(a) {
|
|
649
|
+
function char2hex(a: number): number {
|
|
651
650
|
return a >= 48 && a <= 57
|
|
652
651
|
? a - 48 // 0-9
|
|
653
652
|
: a >= 65 && a <= 70
|
|
@@ -662,7 +661,13 @@ function char2hex(a) {
|
|
|
662
661
|
*
|
|
663
662
|
* [_A-Za-z][_0-9A-Za-z]*
|
|
664
663
|
*/
|
|
665
|
-
function readName(
|
|
664
|
+
function readName(
|
|
665
|
+
source: Source,
|
|
666
|
+
start: number,
|
|
667
|
+
line: number,
|
|
668
|
+
col: number,
|
|
669
|
+
prev: Token | null,
|
|
670
|
+
): Token {
|
|
666
671
|
const body = source.body;
|
|
667
672
|
const bodyLength = body.length;
|
|
668
673
|
let position = start + 1;
|
|
@@ -671,8 +676,8 @@ function readName(source, start, line, col, prev): Token {
|
|
|
671
676
|
position !== bodyLength &&
|
|
672
677
|
!isNaN((code = body.charCodeAt(position))) &&
|
|
673
678
|
(code === 95 || // _
|
|
674
|
-
|
|
675
|
-
|
|
679
|
+
(code >= 48 && code <= 57) || // 0-9
|
|
680
|
+
(code >= 65 && code <= 90) || // A-Z
|
|
676
681
|
(code >= 97 && code <= 122)) // a-z
|
|
677
682
|
) {
|
|
678
683
|
++position;
|
|
@@ -689,7 +694,7 @@ function readName(source, start, line, col, prev): Token {
|
|
|
689
694
|
}
|
|
690
695
|
|
|
691
696
|
// _ A-Z a-z
|
|
692
|
-
function isNameStart(code): boolean {
|
|
697
|
+
function isNameStart(code: number): boolean {
|
|
693
698
|
return (
|
|
694
699
|
code === 95 || (code >= 65 && code <= 90) || (code >= 97 && code <= 122)
|
|
695
700
|
);
|