graphql 15.2.0 → 15.5.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 +19 -10
- package/error/GraphQLError.js +8 -8
- package/error/GraphQLError.js.flow +2 -3
- package/error/GraphQLError.mjs +2 -2
- package/error/formatError.js +1 -1
- package/error/formatError.js.flow +0 -1
- 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 +10 -4
- package/error/locatedError.mjs +6 -4
- package/error/syntaxError.js +1 -1
- package/error/syntaxError.js.flow +0 -1
- package/execution/execute.d.ts +11 -15
- package/execution/execute.js +110 -110
- package/execution/execute.js.flow +132 -139
- package/execution/execute.mjs +92 -88
- package/execution/index.d.ts +1 -0
- package/execution/index.js +3 -3
- package/execution/index.js.flow +6 -2
- package/execution/values.js +11 -11
- package/execution/values.js.flow +0 -1
- package/graphql.js +5 -5
- package/graphql.js.flow +0 -1
- package/index.d.ts +2 -0
- package/index.js +9 -9
- package/index.js.flow +5 -2
- package/jsutils/ObjMap.js.flow +0 -1
- package/jsutils/Path.js.flow +0 -1
- 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 +13 -0
- package/jsutils/isAsyncIterable.js.flow +14 -0
- package/jsutils/isAsyncIterable.mjs +10 -0
- package/jsutils/isObjectLike.js.flow +0 -1
- package/jsutils/isPromise.js.flow +0 -1
- package/jsutils/keyMap.js.flow +0 -1
- package/jsutils/keyValMap.js.flow +0 -1
- package/jsutils/mapValue.js +1 -1
- package/jsutils/mapValue.js.flow +0 -1
- package/jsutils/memoize3.js +2 -5
- package/jsutils/memoize3.js.flow +2 -5
- package/jsutils/memoize3.mjs +2 -5
- package/jsutils/naturalCompare.js +69 -0
- package/jsutils/naturalCompare.js.flow +59 -0
- package/jsutils/naturalCompare.mjs +61 -0
- package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
- package/jsutils/printPathArray.js.flow +0 -1
- package/jsutils/promiseForObject.js.flow +0 -1
- package/jsutils/promiseReduce.js +1 -1
- package/jsutils/promiseReduce.js.flow +0 -1
- package/jsutils/safeArrayFrom.js +73 -0
- package/jsutils/safeArrayFrom.js.flow +59 -0
- package/jsutils/safeArrayFrom.mjs +66 -0
- package/jsutils/suggestionList.js +5 -1
- package/jsutils/suggestionList.js.flow +3 -2
- package/jsutils/suggestionList.mjs +3 -1
- package/jsutils/toObjMap.js +1 -1
- package/jsutils/toObjMap.js.flow +0 -1
- package/language/ast.js +1 -1
- package/language/ast.js.flow +0 -1
- package/language/blockString.d.ts +1 -1
- package/language/blockString.js +53 -32
- package/language/blockString.js.flow +51 -36
- 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 +188 -184
- package/language/lexer.mjs +238 -179
- package/language/location.js.flow +0 -1
- package/language/parser.js +73 -68
- package/language/parser.js.flow +62 -57
- package/language/parser.mjs +64 -60
- package/language/predicates.js +1 -1
- package/language/predicates.js.flow +0 -1
- package/language/printLocation.js +1 -1
- package/language/printLocation.js.flow +0 -1
- package/language/printer.js +20 -13
- package/language/printer.js.flow +26 -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 +26 -9
- 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 +3 -4
- package/language/visitor.mjs +3 -3
- package/package.json +2 -3
- 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 +1 -2
- package/polyfills/objectEntries.mjs +1 -1
- package/polyfills/objectValues.js +1 -1
- package/polyfills/objectValues.js.flow +1 -2
- 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 +8 -9
- package/subscription/mapAsyncIterator.mjs +1 -1
- package/subscription/subscribe.js +61 -73
- package/subscription/subscribe.js.flow +71 -85
- package/subscription/subscribe.mjs +53 -65
- package/type/definition.d.ts +17 -9
- package/type/definition.js +37 -32
- package/type/definition.js.flow +93 -63
- package/type/definition.mjs +19 -14
- package/type/directives.js +17 -16
- package/type/directives.js.flow +20 -13
- package/type/directives.mjs +6 -5
- package/type/index.js +6 -6
- package/type/index.js.flow +0 -1
- package/type/introspection.js +86 -65
- package/type/introspection.js.flow +75 -43
- package/type/introspection.mjs +79 -58
- package/type/scalars.js +9 -9
- package/type/scalars.js.flow +1 -2
- package/type/scalars.mjs +1 -1
- package/type/schema.js +13 -13
- package/type/schema.js.flow +2 -3
- package/type/schema.mjs +1 -1
- package/type/validate.js +52 -19
- package/type/validate.js.flow +54 -8
- package/type/validate.mjs +43 -9
- package/utilities/TypeInfo.js +7 -7
- package/utilities/TypeInfo.js.flow +1 -2
- package/utilities/assertValidName.js +2 -2
- package/utilities/assertValidName.js.flow +0 -1
- package/utilities/astFromValue.js +14 -16
- package/utilities/astFromValue.js.flow +6 -7
- package/utilities/astFromValue.mjs +6 -7
- package/utilities/buildASTSchema.js +17 -27
- package/utilities/buildASTSchema.js.flow +5 -21
- package/utilities/buildASTSchema.mjs +11 -21
- package/utilities/buildClientSchema.js +16 -15
- package/utilities/buildClientSchema.js.flow +28 -12
- package/utilities/buildClientSchema.mjs +5 -4
- package/utilities/coerceInputValue.js +17 -18
- package/utilities/coerceInputValue.js.flow +12 -10
- package/utilities/coerceInputValue.mjs +7 -7
- package/utilities/concatAST.js +9 -8
- package/utilities/concatAST.js.flow +8 -8
- package/utilities/concatAST.mjs +9 -6
- package/utilities/extendSchema.js +26 -19
- package/utilities/extendSchema.js.flow +19 -7
- package/utilities/extendSchema.mjs +8 -1
- package/utilities/findBreakingChanges.js +15 -11
- package/utilities/findBreakingChanges.js.flow +6 -3
- package/utilities/findBreakingChanges.mjs +5 -2
- package/utilities/findDeprecatedUsages.js +2 -2
- package/utilities/findDeprecatedUsages.js.flow +0 -1
- package/utilities/getIntrospectionQuery.d.ts +6 -0
- package/utilities/getIntrospectionQuery.js +8 -2
- package/utilities/getIntrospectionQuery.js.flow +17 -5
- package/utilities/getIntrospectionQuery.mjs +8 -2
- package/utilities/getOperationAST.js +1 -1
- package/utilities/getOperationAST.js.flow +0 -1
- package/utilities/getOperationRootType.js +1 -1
- package/utilities/getOperationRootType.js.flow +0 -1
- package/utilities/index.d.ts +3 -0
- package/utilities/index.js +22 -22
- package/utilities/index.js.flow +0 -1
- package/utilities/introspectionFromSchema.js +7 -5
- package/utilities/introspectionFromSchema.js.flow +2 -1
- package/utilities/introspectionFromSchema.mjs +3 -1
- package/utilities/lexicographicSortSchema.js +13 -9
- package/utilities/lexicographicSortSchema.js.flow +21 -13
- package/utilities/lexicographicSortSchema.mjs +5 -2
- package/utilities/printSchema.js +15 -16
- package/utilities/printSchema.js.flow +23 -16
- package/utilities/printSchema.mjs +5 -6
- package/utilities/separateOperations.js +46 -42
- package/utilities/separateOperations.js.flow +46 -37
- package/utilities/separateOperations.mjs +44 -40
- 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 +0 -1
- package/utilities/typeFromAST.js +6 -6
- package/utilities/typeFromAST.js.flow +2 -3
- package/utilities/typeFromAST.mjs +2 -2
- package/utilities/typedQueryDocumentNode.d.ts +20 -0
- package/utilities/valueFromAST.js +6 -6
- package/utilities/valueFromAST.js.flow +4 -2
- package/utilities/valueFromASTUntyped.js +4 -4
- package/utilities/valueFromASTUntyped.js.flow +0 -1
- package/validation/ValidationContext.js +3 -3
- package/validation/ValidationContext.js.flow +3 -4
- package/validation/index.js +38 -38
- package/validation/index.js.flow +0 -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 +0 -1
- package/validation/rules/FieldsOnCorrectTypeRule.js +8 -6
- package/validation/rules/FieldsOnCorrectTypeRule.js.flow +2 -2
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -1
- package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
- package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +0 -1
- package/validation/rules/KnownArgumentNamesRule.js +5 -5
- package/validation/rules/KnownArgumentNamesRule.js.flow +1 -1
- package/validation/rules/KnownDirectivesRule.js +6 -6
- package/validation/rules/KnownDirectivesRule.js.flow +4 -3
- package/validation/rules/KnownFragmentNamesRule.js +1 -1
- package/validation/rules/KnownFragmentNamesRule.js.flow +0 -1
- package/validation/rules/KnownTypeNamesRule.js +6 -6
- package/validation/rules/KnownTypeNamesRule.js.flow +1 -2
- package/validation/rules/LoneAnonymousOperationRule.js +2 -2
- package/validation/rules/LoneAnonymousOperationRule.js.flow +0 -1
- 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 +0 -1
- package/validation/rules/NoFragmentCyclesRule.js +1 -1
- package/validation/rules/NoFragmentCyclesRule.js.flow +1 -2
- package/validation/rules/NoUndefinedVariablesRule.js +1 -1
- package/validation/rules/NoUndefinedVariablesRule.js.flow +0 -1
- package/validation/rules/NoUnusedFragmentsRule.js +1 -1
- package/validation/rules/NoUnusedFragmentsRule.js.flow +0 -1
- package/validation/rules/NoUnusedVariablesRule.js +1 -1
- package/validation/rules/NoUnusedVariablesRule.js.flow +0 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +14 -14
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
- package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
- package/validation/rules/PossibleFragmentSpreadsRule.js.flow +5 -2
- 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 +6 -4
- package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
- package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +4 -3
- package/validation/rules/ScalarLeafsRule.js +3 -3
- package/validation/rules/ScalarLeafsRule.js.flow +0 -1
- package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
- package/validation/rules/SingleFieldSubscriptionsRule.js.flow +0 -1
- package/validation/rules/UniqueArgumentNamesRule.js +1 -1
- package/validation/rules/UniqueArgumentNamesRule.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNames.js +1 -1
- package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNamesRule.js +2 -2
- package/validation/rules/UniqueDirectiveNamesRule.js.flow +0 -1
- package/validation/rules/UniqueDirectiveNamesRule.mjs +1 -1
- package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
- package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +0 -1
- 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 +7 -2
- 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 +13 -4
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js +1 -1
- package/validation/rules/UniqueFragmentNamesRule.js.flow +0 -1
- package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
- package/validation/rules/UniqueInputFieldNamesRule.js.flow +0 -1
- package/validation/rules/UniqueOperationNamesRule.js +1 -1
- package/validation/rules/UniqueOperationNamesRule.js.flow +0 -1
- 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 +7 -2
- package/validation/rules/UniqueTypeNames.js +1 -1
- package/validation/rules/UniqueTypeNames.js.flow +0 -1
- package/validation/rules/UniqueTypeNamesRule.js +2 -2
- package/validation/rules/UniqueTypeNamesRule.js.flow +0 -1
- package/validation/rules/UniqueTypeNamesRule.mjs +1 -1
- package/validation/rules/UniqueVariableNamesRule.js +1 -1
- package/validation/rules/UniqueVariableNamesRule.js.flow +0 -1
- package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
- package/validation/rules/ValuesOfCorrectTypeRule.js.flow +0 -1
- package/validation/rules/VariablesAreInputTypesRule.js +4 -4
- package/validation/rules/VariablesAreInputTypesRule.js.flow +0 -1
- package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
- package/validation/rules/VariablesInAllowedPositionRule.js.flow +0 -1
- package/validation/rules/custom/NoDeprecatedCustomRule.js +47 -9
- package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +56 -13
- package/validation/rules/custom/NoDeprecatedCustomRule.mjs +43 -8
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +3 -3
- package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +0 -1
- 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 -5
- package/version.js +2 -2
- package/version.js.flow +2 -3
- package/version.mjs +2 -2
- package/jsutils/isCollection.js +0 -47
- package/jsutils/isCollection.js.flow +0 -39
- package/jsutils/isCollection.mjs +0 -40
- 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,5 +1,4 @@
|
|
|
1
1
|
// @flow strict
|
|
2
|
-
|
|
3
2
|
import { syntaxError } from '../error/syntaxError';
|
|
4
3
|
|
|
5
4
|
import type { Source } from './source';
|
|
@@ -96,7 +95,7 @@ export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean %checks {
|
|
|
96
95
|
);
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
function printCharCode(code) {
|
|
98
|
+
function printCharCode(code: number): string {
|
|
100
99
|
return (
|
|
101
100
|
// NaN/undefined represents access beyond the end of the file.
|
|
102
101
|
isNaN(code)
|
|
@@ -121,149 +120,159 @@ function readToken(lexer: Lexer, prev: Token): Token {
|
|
|
121
120
|
const body = source.body;
|
|
122
121
|
const bodyLength = body.length;
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
let pos = prev.end;
|
|
124
|
+
while (pos < bodyLength) {
|
|
125
|
+
const code = body.charCodeAt(pos);
|
|
127
126
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
127
|
+
const line = lexer.line;
|
|
128
|
+
const col = 1 + pos - lexer.lineStart;
|
|
131
129
|
|
|
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
|
-
|
|
157
|
-
return
|
|
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
|
-
|
|
257
|
-
|
|
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));
|
|
258
265
|
}
|
|
259
266
|
|
|
260
|
-
|
|
267
|
+
const line = lexer.line;
|
|
268
|
+
const col = 1 + pos - lexer.lineStart;
|
|
269
|
+
return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
|
|
261
270
|
}
|
|
262
271
|
|
|
263
272
|
/**
|
|
264
273
|
* Report a message that an unexpected character was encountered.
|
|
265
274
|
*/
|
|
266
|
-
function unexpectedCharacterMessage(code) {
|
|
275
|
+
function unexpectedCharacterMessage(code: number): string {
|
|
267
276
|
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
|
|
268
277
|
return `Cannot contain the invalid character ${printCharCode(code)}.`;
|
|
269
278
|
}
|
|
@@ -276,49 +285,18 @@ function unexpectedCharacterMessage(code) {
|
|
|
276
285
|
return `Cannot parse the unexpected character ${printCharCode(code)}.`;
|
|
277
286
|
}
|
|
278
287
|
|
|
279
|
-
/**
|
|
280
|
-
* Reads from body starting at startPosition until it finds a non-whitespace
|
|
281
|
-
* character, then returns the position of that character for lexing.
|
|
282
|
-
*/
|
|
283
|
-
function positionAfterWhitespace(
|
|
284
|
-
body: string,
|
|
285
|
-
startPosition: number,
|
|
286
|
-
lexer: Lexer,
|
|
287
|
-
): number {
|
|
288
|
-
const bodyLength = body.length;
|
|
289
|
-
let position = startPosition;
|
|
290
|
-
while (position < bodyLength) {
|
|
291
|
-
const code = body.charCodeAt(position);
|
|
292
|
-
// tab | space | comma | BOM
|
|
293
|
-
if (code === 9 || code === 32 || code === 44 || code === 0xfeff) {
|
|
294
|
-
++position;
|
|
295
|
-
} else if (code === 10) {
|
|
296
|
-
// new line
|
|
297
|
-
++position;
|
|
298
|
-
++lexer.line;
|
|
299
|
-
lexer.lineStart = position;
|
|
300
|
-
} else if (code === 13) {
|
|
301
|
-
// carriage return
|
|
302
|
-
if (body.charCodeAt(position + 1) === 10) {
|
|
303
|
-
position += 2;
|
|
304
|
-
} else {
|
|
305
|
-
++position;
|
|
306
|
-
}
|
|
307
|
-
++lexer.line;
|
|
308
|
-
lexer.lineStart = position;
|
|
309
|
-
} else {
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return position;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
288
|
/**
|
|
317
289
|
* Reads a comment token from the source file.
|
|
318
290
|
*
|
|
319
291
|
* #[\u0009\u0020-\uFFFF]*
|
|
320
292
|
*/
|
|
321
|
-
function readComment(
|
|
293
|
+
function readComment(
|
|
294
|
+
source: Source,
|
|
295
|
+
start: number,
|
|
296
|
+
line: number,
|
|
297
|
+
col: number,
|
|
298
|
+
prev: Token | null,
|
|
299
|
+
): Token {
|
|
322
300
|
const body = source.body;
|
|
323
301
|
let code;
|
|
324
302
|
let position = start;
|
|
@@ -349,7 +327,14 @@ function readComment(source, start, line, col, prev): Token {
|
|
|
349
327
|
* Int: -?(0|[1-9][0-9]*)
|
|
350
328
|
* Float: -?(0|[1-9][0-9]*)(\.[0-9]+)?((E|e)(+|-)?[0-9]+)?
|
|
351
329
|
*/
|
|
352
|
-
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 {
|
|
353
338
|
const body = source.body;
|
|
354
339
|
let code = firstCode;
|
|
355
340
|
let position = start;
|
|
@@ -420,7 +405,7 @@ function readNumber(source, start, firstCode, line, col, prev): Token {
|
|
|
420
405
|
/**
|
|
421
406
|
* Returns the new position in the source after reading digits.
|
|
422
407
|
*/
|
|
423
|
-
function readDigits(source, start, firstCode) {
|
|
408
|
+
function readDigits(source: Source, start: number, firstCode: number): number {
|
|
424
409
|
const body = source.body;
|
|
425
410
|
let position = start;
|
|
426
411
|
let code = firstCode;
|
|
@@ -443,7 +428,13 @@ function readDigits(source, start, firstCode) {
|
|
|
443
428
|
*
|
|
444
429
|
* "([^"\\\u000A\u000D]|(\\(u[0-9a-fA-F]{4}|["\\/bfnrt])))*"
|
|
445
430
|
*/
|
|
446
|
-
function readString(
|
|
431
|
+
function readString(
|
|
432
|
+
source: Source,
|
|
433
|
+
start: number,
|
|
434
|
+
line: number,
|
|
435
|
+
col: number,
|
|
436
|
+
prev: Token | null,
|
|
437
|
+
): Token {
|
|
447
438
|
const body = source.body;
|
|
448
439
|
let position = start + 1;
|
|
449
440
|
let chunkStart = position;
|
|
@@ -552,7 +543,14 @@ function readString(source, start, line, col, prev): Token {
|
|
|
552
543
|
*
|
|
553
544
|
* """("?"?(\\"""|\\(?!=""")|[^"\\]))*"""
|
|
554
545
|
*/
|
|
555
|
-
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 {
|
|
556
554
|
const body = source.body;
|
|
557
555
|
let position = start + 3;
|
|
558
556
|
let chunkStart = position;
|
|
@@ -634,7 +632,7 @@ function readBlockString(source, start, line, col, prev, lexer): Token {
|
|
|
634
632
|
* This is implemented by noting that char2hex() returns -1 on error,
|
|
635
633
|
* which means the result of ORing the char2hex() will also be negative.
|
|
636
634
|
*/
|
|
637
|
-
function uniCharCode(a, b, c, d) {
|
|
635
|
+
function uniCharCode(a: number, b: number, c: number, d: number): number {
|
|
638
636
|
return (
|
|
639
637
|
(char2hex(a) << 12) | (char2hex(b) << 8) | (char2hex(c) << 4) | char2hex(d)
|
|
640
638
|
);
|
|
@@ -648,7 +646,7 @@ function uniCharCode(a, b, c, d) {
|
|
|
648
646
|
*
|
|
649
647
|
* Returns -1 on error.
|
|
650
648
|
*/
|
|
651
|
-
function char2hex(a) {
|
|
649
|
+
function char2hex(a: number): number {
|
|
652
650
|
return a >= 48 && a <= 57
|
|
653
651
|
? a - 48 // 0-9
|
|
654
652
|
: a >= 65 && a <= 70
|
|
@@ -663,7 +661,13 @@ function char2hex(a) {
|
|
|
663
661
|
*
|
|
664
662
|
* [_A-Za-z][_0-9A-Za-z]*
|
|
665
663
|
*/
|
|
666
|
-
function readName(
|
|
664
|
+
function readName(
|
|
665
|
+
source: Source,
|
|
666
|
+
start: number,
|
|
667
|
+
line: number,
|
|
668
|
+
col: number,
|
|
669
|
+
prev: Token | null,
|
|
670
|
+
): Token {
|
|
667
671
|
const body = source.body;
|
|
668
672
|
const bodyLength = body.length;
|
|
669
673
|
let position = start + 1;
|
|
@@ -672,8 +676,8 @@ function readName(source, start, line, col, prev): Token {
|
|
|
672
676
|
position !== bodyLength &&
|
|
673
677
|
!isNaN((code = body.charCodeAt(position))) &&
|
|
674
678
|
(code === 95 || // _
|
|
675
|
-
|
|
676
|
-
|
|
679
|
+
(code >= 48 && code <= 57) || // 0-9
|
|
680
|
+
(code >= 65 && code <= 90) || // A-Z
|
|
677
681
|
(code >= 97 && code <= 122)) // a-z
|
|
678
682
|
) {
|
|
679
683
|
++position;
|
|
@@ -690,7 +694,7 @@ function readName(source, start, line, col, prev): Token {
|
|
|
690
694
|
}
|
|
691
695
|
|
|
692
696
|
// _ A-Z a-z
|
|
693
|
-
function isNameStart(code): boolean {
|
|
697
|
+
function isNameStart(code: number): boolean {
|
|
694
698
|
return (
|
|
695
699
|
code === 95 || (code >= 65 && code <= 90) || (code >= 97 && code <= 122)
|
|
696
700
|
);
|