graphql 14.0.2 → 14.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +5 -5
- package/codecov.yml +14 -0
- package/error/GraphQLError.js +2 -2
- package/error/GraphQLError.js.flow +4 -4
- package/error/GraphQLError.mjs +2 -2
- package/error/formatError.js +2 -2
- package/error/formatError.js.flow +1 -1
- package/error/formatError.mjs +2 -2
- package/error/index.js.flow +1 -1
- package/error/index.mjs +2 -2
- package/error/locatedError.js +2 -2
- package/error/locatedError.js.flow +1 -1
- package/error/locatedError.mjs +2 -2
- package/error/printError.js +2 -2
- package/error/printError.js.flow +1 -1
- package/error/printError.mjs +2 -2
- package/error/syntaxError.js +2 -2
- package/error/syntaxError.js.flow +1 -1
- package/error/syntaxError.mjs +2 -2
- package/execution/execute.js +20 -11
- package/execution/execute.js.flow +41 -27
- package/execution/execute.mjs +19 -13
- package/execution/index.js +6 -0
- package/execution/index.js.flow +7 -2
- package/execution/index.mjs +3 -3
- package/execution/values.js +10 -10
- package/execution/values.js.flow +8 -8
- package/execution/values.mjs +9 -9
- package/graphql.js +8 -8
- package/graphql.js.flow +18 -4
- package/graphql.mjs +8 -8
- package/index.js +18 -0
- package/index.js.flow +4 -1
- package/index.mjs +4 -4
- package/jsutils/ObjMap.js.flow +1 -1
- package/jsutils/{MaybePromise.js → PromiseOrValue.js} +0 -0
- package/jsutils/{MaybePromise.js.flow → PromiseOrValue.js.flow} +2 -2
- package/jsutils/{MaybePromise.mjs → PromiseOrValue.mjs} +0 -0
- package/jsutils/dedent.js +2 -2
- package/jsutils/dedent.js.flow +1 -1
- package/jsutils/dedent.mjs +2 -2
- package/jsutils/defineToJSON.js +18 -7
- package/jsutils/defineToJSON.js.flow +15 -6
- package/jsutils/defineToJSON.mjs +15 -7
- package/jsutils/defineToStringTag.js +6 -6
- package/jsutils/defineToStringTag.js.flow +4 -4
- package/jsutils/defineToStringTag.mjs +5 -5
- package/jsutils/inspect.js +109 -23
- package/jsutils/inspect.js.flow +112 -14
- package/jsutils/inspect.mjs +108 -17
- package/jsutils/instanceOf.js +2 -2
- package/jsutils/instanceOf.js.flow +1 -1
- package/jsutils/instanceOf.mjs +2 -2
- package/jsutils/invariant.js +2 -2
- package/jsutils/invariant.js.flow +1 -1
- package/jsutils/invariant.mjs +2 -2
- package/jsutils/isInvalid.js +2 -2
- package/jsutils/isInvalid.js.flow +1 -1
- package/jsutils/isInvalid.mjs +2 -2
- package/jsutils/isNullish.js +2 -2
- package/jsutils/isNullish.js.flow +1 -1
- package/jsutils/isNullish.mjs +2 -2
- package/jsutils/isPromise.js +2 -2
- package/jsutils/isPromise.js.flow +1 -1
- package/jsutils/isPromise.mjs +2 -2
- package/jsutils/keyMap.js +2 -2
- package/jsutils/keyMap.js.flow +1 -1
- package/jsutils/keyMap.mjs +2 -2
- package/jsutils/keyValMap.js +2 -2
- package/jsutils/keyValMap.js.flow +1 -1
- package/jsutils/keyValMap.mjs +2 -2
- package/jsutils/mapValue.js +54 -0
- package/jsutils/mapValue.js.flow +27 -0
- package/jsutils/mapValue.mjs +44 -0
- package/jsutils/memoize3.js +2 -2
- package/jsutils/memoize3.js.flow +1 -1
- package/jsutils/memoize3.mjs +2 -2
- package/jsutils/nodejsCustomInspectSymbol.js +18 -0
- package/jsutils/nodejsCustomInspectSymbol.js.flow +15 -0
- package/jsutils/nodejsCustomInspectSymbol.mjs +10 -0
- package/jsutils/orList.js +18 -5
- package/jsutils/orList.js.flow +14 -8
- package/jsutils/orList.mjs +15 -5
- package/jsutils/promiseForObject.js +2 -2
- package/jsutils/promiseForObject.js.flow +1 -1
- package/jsutils/promiseForObject.mjs +2 -2
- package/jsutils/promiseReduce.js +2 -2
- package/jsutils/promiseReduce.js.flow +5 -5
- package/jsutils/promiseReduce.mjs +2 -2
- package/jsutils/quotedOrList.js +2 -2
- package/jsutils/quotedOrList.js.flow +1 -1
- package/jsutils/quotedOrList.mjs +2 -2
- package/jsutils/suggestionList.js +2 -2
- package/jsutils/suggestionList.js.flow +1 -1
- package/jsutils/suggestionList.mjs +2 -2
- package/language/ast.js.flow +1 -1
- package/language/{blockStringValue.mjs → blockString.js} +39 -3
- package/language/{blockStringValue.js.flow → blockString.js.flow} +31 -2
- package/language/{blockStringValue.js → blockString.mjs} +31 -10
- package/language/directiveLocation.js +2 -2
- package/language/directiveLocation.js.flow +1 -1
- package/language/directiveLocation.mjs +2 -2
- package/language/index.js.flow +1 -1
- package/language/index.mjs +2 -2
- package/language/kinds.js +2 -2
- package/language/kinds.js.flow +1 -1
- package/language/kinds.mjs +2 -2
- package/language/lexer.js +60 -46
- package/language/lexer.js.flow +71 -69
- package/language/lexer.mjs +58 -45
- package/language/location.js +2 -2
- package/language/location.js.flow +1 -1
- package/language/location.mjs +2 -2
- package/language/parser.js +84 -83
- package/language/parser.js.flow +85 -94
- package/language/parser.mjs +83 -83
- package/language/predicates.js +2 -2
- package/language/predicates.js.flow +1 -1
- package/language/predicates.mjs +2 -2
- package/language/printer.js +15 -17
- package/language/printer.js.flow +21 -20
- package/language/printer.mjs +14 -17
- package/language/source.js +8 -7
- package/language/source.js.flow +1 -1
- package/language/source.mjs +2 -10
- package/language/visitor.js +7 -6
- package/language/visitor.js.flow +3 -5
- package/language/visitor.mjs +7 -6
- package/package.json +5 -2
- package/polyfills/find.js +31 -0
- package/polyfills/find.js.flow +29 -0
- package/polyfills/find.mjs +23 -0
- package/polyfills/flatMap.js +38 -0
- package/polyfills/flatMap.js.flow +34 -0
- package/polyfills/flatMap.mjs +30 -0
- package/{jsutils → polyfills}/isFinite.js +2 -2
- package/{jsutils → polyfills}/isFinite.js.flow +1 -1
- package/{jsutils → polyfills}/isFinite.mjs +2 -2
- package/{jsutils → polyfills}/isInteger.js +2 -2
- package/{jsutils → polyfills}/isInteger.js.flow +1 -1
- package/{jsutils → polyfills}/isInteger.mjs +2 -2
- package/polyfills/objectEntries.js +26 -0
- package/polyfills/objectEntries.js.flow +19 -0
- package/polyfills/objectEntries.mjs +18 -0
- package/{jsutils → polyfills}/objectValues.js +2 -2
- package/{jsutils → polyfills}/objectValues.js.flow +2 -2
- package/{jsutils → polyfills}/objectValues.mjs +2 -2
- package/subscription/asyncIteratorReject.js.flow +1 -1
- package/subscription/asyncIteratorReject.mjs +2 -2
- package/subscription/index.js.flow +1 -1
- package/subscription/index.mjs +2 -2
- package/subscription/mapAsyncIterator.js.flow +5 -5
- package/subscription/mapAsyncIterator.mjs +2 -2
- package/subscription/subscribe.js +2 -2
- package/subscription/subscribe.js.flow +1 -1
- package/subscription/subscribe.mjs +2 -2
- package/type/definition.js +161 -138
- package/type/definition.js.flow +193 -57
- package/type/definition.mjs +158 -140
- package/type/directives.js +35 -29
- package/type/directives.js.flow +39 -21
- package/type/directives.mjs +34 -31
- package/type/index.js +12 -0
- package/type/index.js.flow +5 -1
- package/type/index.mjs +6 -4
- package/type/introspection.js +11 -7
- package/type/introspection.js.flow +11 -8
- package/type/introspection.mjs +11 -7
- package/type/scalars.js +45 -34
- package/type/scalars.js.flow +41 -27
- package/type/scalars.mjs +45 -27
- package/type/schema.js +134 -88
- package/type/schema.js.flow +77 -11
- package/type/schema.mjs +132 -88
- package/type/validate.js +152 -187
- package/type/validate.js.flow +12 -61
- package/type/validate.mjs +143 -188
- package/utilities/TypeInfo.js +10 -23
- package/utilities/TypeInfo.js.flow +2 -2
- package/utilities/TypeInfo.mjs +3 -25
- package/utilities/assertValidName.js +2 -2
- package/utilities/assertValidName.js.flow +1 -1
- package/utilities/assertValidName.mjs +2 -2
- package/utilities/astFromValue.js +7 -6
- package/utilities/astFromValue.js.flow +7 -6
- package/utilities/astFromValue.mjs +9 -8
- package/utilities/buildASTSchema.js +213 -197
- package/utilities/buildASTSchema.js.flow +163 -173
- package/utilities/buildASTSchema.mjs +203 -198
- package/utilities/buildClientSchema.js +39 -47
- package/utilities/buildClientSchema.js.flow +49 -58
- package/utilities/buildClientSchema.mjs +38 -46
- package/utilities/coerceValue.js +41 -21
- package/utilities/coerceValue.js.flow +44 -49
- package/utilities/coerceValue.mjs +42 -23
- package/utilities/concatAST.js +9 -13
- package/utilities/concatAST.js.flow +3 -9
- package/utilities/concatAST.mjs +6 -13
- package/utilities/extendSchema.js +256 -630
- package/utilities/extendSchema.js.flow +190 -426
- package/utilities/extendSchema.mjs +256 -631
- package/utilities/findBreakingChanges.js +8 -6
- package/utilities/findBreakingChanges.js.flow +4 -3
- package/utilities/findBreakingChanges.mjs +7 -6
- package/utilities/findDeprecatedUsages.js +4 -4
- package/utilities/findDeprecatedUsages.js.flow +3 -3
- package/utilities/findDeprecatedUsages.mjs +4 -4
- package/utilities/getOperationAST.js +2 -2
- package/utilities/getOperationAST.js.flow +1 -1
- package/utilities/getOperationAST.mjs +2 -2
- package/utilities/getOperationRootType.js +6 -6
- package/utilities/getOperationRootType.js.flow +9 -7
- package/utilities/getOperationRootType.mjs +6 -6
- package/utilities/index.js.flow +1 -1
- package/utilities/index.mjs +2 -2
- package/utilities/introspectionFromSchema.js +2 -2
- package/utilities/introspectionFromSchema.js.flow +1 -1
- package/utilities/introspectionFromSchema.mjs +2 -2
- package/utilities/introspectionQuery.js +2 -2
- package/utilities/introspectionQuery.js.flow +1 -1
- package/utilities/introspectionQuery.mjs +2 -2
- package/utilities/isValidJSValue.js +4 -2
- package/utilities/isValidJSValue.js.flow +2 -1
- package/utilities/isValidJSValue.mjs +4 -2
- package/utilities/isValidLiteralValue.js +2 -2
- package/utilities/isValidLiteralValue.js.flow +1 -1
- package/utilities/isValidLiteralValue.mjs +2 -2
- package/utilities/lexicographicSortSchema.js +86 -124
- package/utilities/lexicographicSortSchema.js.flow +68 -96
- package/utilities/lexicographicSortSchema.mjs +86 -124
- package/utilities/schemaPrinter.js +47 -73
- package/utilities/schemaPrinter.js.flow +62 -111
- package/utilities/schemaPrinter.mjs +46 -73
- package/utilities/separateOperations.js +11 -10
- package/utilities/separateOperations.js.flow +1 -1
- package/utilities/separateOperations.mjs +11 -10
- package/utilities/typeComparators.js +2 -2
- package/utilities/typeComparators.js.flow +1 -1
- package/utilities/typeComparators.mjs +2 -2
- package/utilities/typeFromAST.js +9 -4
- package/utilities/typeFromAST.js.flow +5 -2
- package/utilities/typeFromAST.mjs +6 -4
- package/utilities/valueFromAST.js +9 -6
- package/utilities/valueFromAST.js.flow +5 -3
- package/utilities/valueFromAST.mjs +7 -5
- package/utilities/valueFromASTUntyped.js +7 -4
- package/utilities/valueFromASTUntyped.js.flow +5 -2
- package/utilities/valueFromASTUntyped.mjs +6 -4
- package/validation/ValidationContext.js +57 -82
- package/validation/ValidationContext.js.flow +53 -50
- package/validation/ValidationContext.mjs +53 -78
- package/validation/index.js.flow +1 -1
- package/validation/index.mjs +2 -2
- package/validation/rules/ExecutableDefinitions.js +3 -3
- package/validation/rules/ExecutableDefinitions.js.flow +3 -3
- package/validation/rules/ExecutableDefinitions.mjs +3 -3
- package/validation/rules/FieldsOnCorrectType.js +3 -3
- package/validation/rules/FieldsOnCorrectType.js.flow +2 -2
- package/validation/rules/FieldsOnCorrectType.mjs +3 -3
- package/validation/rules/FragmentsOnCompositeTypes.js +4 -4
- package/validation/rules/FragmentsOnCompositeTypes.js.flow +3 -3
- package/validation/rules/FragmentsOnCompositeTypes.mjs +4 -4
- package/validation/rules/KnownArgumentNames.js.flow +1 -1
- package/validation/rules/KnownArgumentNames.mjs +2 -2
- package/validation/rules/KnownDirectives.js +4 -4
- package/validation/rules/KnownDirectives.js.flow +5 -4
- package/validation/rules/KnownDirectives.mjs +4 -4
- package/validation/rules/KnownFragmentNames.js +3 -3
- package/validation/rules/KnownFragmentNames.js.flow +2 -2
- package/validation/rules/KnownFragmentNames.mjs +3 -3
- package/validation/rules/KnownTypeNames.js +60 -22
- package/validation/rules/KnownTypeNames.js.flow +55 -21
- package/validation/rules/KnownTypeNames.mjs +57 -22
- package/validation/rules/LoneAnonymousOperation.js +3 -3
- package/validation/rules/LoneAnonymousOperation.js.flow +2 -2
- package/validation/rules/LoneAnonymousOperation.mjs +3 -3
- package/validation/rules/LoneSchemaDefinition.js +2 -2
- package/validation/rules/LoneSchemaDefinition.js.flow +1 -1
- package/validation/rules/LoneSchemaDefinition.mjs +2 -2
- package/validation/rules/NoFragmentCycles.js +2 -2
- package/validation/rules/NoFragmentCycles.js.flow +3 -3
- package/validation/rules/NoFragmentCycles.mjs +2 -2
- package/validation/rules/NoUndefinedVariables.js +2 -2
- package/validation/rules/NoUndefinedVariables.js.flow +1 -1
- package/validation/rules/NoUndefinedVariables.mjs +2 -2
- package/validation/rules/NoUnusedFragments.js +10 -7
- package/validation/rules/NoUnusedFragments.js.flow +4 -4
- package/validation/rules/NoUnusedFragments.mjs +10 -7
- package/validation/rules/NoUnusedVariables.js +7 -5
- package/validation/rules/NoUnusedVariables.js.flow +4 -3
- package/validation/rules/NoUnusedVariables.mjs +7 -5
- package/validation/rules/OverlappingFieldsCanBeMerged.js +58 -33
- package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +4 -4
- package/validation/rules/OverlappingFieldsCanBeMerged.mjs +50 -34
- package/validation/rules/PossibleFragmentSpreads.js +4 -4
- package/validation/rules/PossibleFragmentSpreads.js.flow +3 -3
- package/validation/rules/PossibleFragmentSpreads.mjs +4 -4
- package/validation/rules/PossibleTypeExtensions.js +158 -0
- package/validation/rules/PossibleTypeExtensions.js.flow +160 -0
- package/validation/rules/PossibleTypeExtensions.mjs +146 -0
- package/validation/rules/ProvidedRequiredArguments.js +3 -3
- package/validation/rules/ProvidedRequiredArguments.js.flow +4 -4
- package/validation/rules/ProvidedRequiredArguments.mjs +5 -5
- package/validation/rules/ScalarLeafs.js +4 -4
- package/validation/rules/ScalarLeafs.js.flow +3 -3
- package/validation/rules/ScalarLeafs.mjs +4 -4
- package/validation/rules/SingleFieldSubscriptions.js +2 -2
- package/validation/rules/SingleFieldSubscriptions.js.flow +1 -1
- package/validation/rules/SingleFieldSubscriptions.mjs +2 -2
- package/validation/rules/UniqueArgumentNames.js +2 -2
- package/validation/rules/UniqueArgumentNames.js.flow +1 -1
- package/validation/rules/UniqueArgumentNames.mjs +2 -2
- package/validation/rules/UniqueDirectiveNames.js +55 -0
- package/validation/rules/UniqueDirectiveNames.js.flow +64 -0
- package/validation/rules/UniqueDirectiveNames.mjs +43 -0
- package/validation/rules/UniqueDirectivesPerLocation.js +2 -2
- package/validation/rules/UniqueDirectivesPerLocation.js.flow +1 -1
- package/validation/rules/UniqueDirectivesPerLocation.mjs +2 -2
- package/validation/rules/UniqueEnumValueNames.js +90 -0
- package/validation/rules/UniqueEnumValueNames.js.flow +85 -0
- package/validation/rules/UniqueEnumValueNames.mjs +77 -0
- package/validation/rules/UniqueFieldDefinitionNames.js +101 -0
- package/validation/rules/UniqueFieldDefinitionNames.js.flow +99 -0
- package/validation/rules/UniqueFieldDefinitionNames.mjs +88 -0
- package/validation/rules/UniqueFragmentNames.js +2 -2
- package/validation/rules/UniqueFragmentNames.js.flow +1 -1
- package/validation/rules/UniqueFragmentNames.mjs +2 -2
- package/validation/rules/UniqueInputFieldNames.js +2 -4
- package/validation/rules/UniqueInputFieldNames.js.flow +1 -2
- package/validation/rules/UniqueInputFieldNames.mjs +2 -4
- package/validation/rules/UniqueOperationNames.js +2 -2
- package/validation/rules/UniqueOperationNames.js.flow +1 -1
- package/validation/rules/UniqueOperationNames.mjs +2 -2
- package/validation/rules/UniqueOperationTypes.js +85 -0
- package/validation/rules/UniqueOperationTypes.js.flow +76 -0
- package/validation/rules/UniqueOperationTypes.mjs +73 -0
- package/validation/rules/UniqueTypeNames.js +62 -0
- package/validation/rules/UniqueTypeNames.js.flow +67 -0
- package/validation/rules/UniqueTypeNames.mjs +50 -0
- package/validation/rules/UniqueVariableNames.js +2 -2
- package/validation/rules/UniqueVariableNames.js.flow +1 -1
- package/validation/rules/UniqueVariableNames.mjs +2 -2
- package/validation/rules/ValuesOfCorrectType.js +30 -14
- package/validation/rules/ValuesOfCorrectType.js.flow +5 -6
- package/validation/rules/ValuesOfCorrectType.mjs +29 -14
- package/validation/rules/VariablesAreInputTypes.js +3 -3
- package/validation/rules/VariablesAreInputTypes.js.flow +2 -2
- package/validation/rules/VariablesAreInputTypes.mjs +3 -3
- package/validation/rules/VariablesInAllowedPosition.js +5 -5
- package/validation/rules/VariablesInAllowedPosition.js.flow +1 -1
- package/validation/rules/VariablesInAllowedPosition.mjs +5 -5
- package/validation/specifiedRules.js +15 -3
- package/validation/specifiedRules.js.flow +14 -1
- package/validation/specifiedRules.mjs +9 -3
- package/validation/validate.js +2 -2
- package/validation/validate.js.flow +1 -1
- package/validation/validate.mjs +2 -2
- package/jsutils/find.js +0 -22
- package/jsutils/find.js.flow +0 -19
- package/jsutils/find.mjs +0 -15
package/language/lexer.js
CHANGED
|
@@ -7,19 +7,21 @@ exports.createLexer = createLexer;
|
|
|
7
7
|
exports.getTokenDesc = getTokenDesc;
|
|
8
8
|
exports.TokenKind = void 0;
|
|
9
9
|
|
|
10
|
+
var _defineToJSON = _interopRequireDefault(require("../jsutils/defineToJSON"));
|
|
11
|
+
|
|
10
12
|
var _error = require("../error");
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _blockString = require("./blockString");
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
|
-
* Copyright (c)
|
|
19
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
18
20
|
*
|
|
19
21
|
* This source code is licensed under the MIT license found in the
|
|
20
22
|
* LICENSE file in the root directory of this source tree.
|
|
21
23
|
*
|
|
22
|
-
*
|
|
24
|
+
*
|
|
23
25
|
*/
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -109,13 +111,11 @@ function getTokenDesc(token) {
|
|
|
109
111
|
var value = token.value;
|
|
110
112
|
return value ? "".concat(token.kind, " \"").concat(value, "\"") : token.kind;
|
|
111
113
|
}
|
|
112
|
-
|
|
113
|
-
var charCodeAt = String.prototype.charCodeAt;
|
|
114
|
-
var slice = String.prototype.slice;
|
|
115
114
|
/**
|
|
116
115
|
* Helper function for constructing the Token object.
|
|
117
116
|
*/
|
|
118
117
|
|
|
118
|
+
|
|
119
119
|
function Tok(kind, start, end, line, column, prev, value) {
|
|
120
120
|
this.kind = kind;
|
|
121
121
|
this.start = start;
|
|
@@ -128,14 +128,14 @@ function Tok(kind, start, end, line, column, prev, value) {
|
|
|
128
128
|
} // Print a simplified form when appearing in JSON/util.inspect.
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
(0, _defineToJSON.default)(Tok, function () {
|
|
132
132
|
return {
|
|
133
133
|
kind: this.kind,
|
|
134
134
|
value: this.value,
|
|
135
135
|
line: this.line,
|
|
136
136
|
column: this.column
|
|
137
137
|
};
|
|
138
|
-
};
|
|
138
|
+
});
|
|
139
139
|
|
|
140
140
|
function printCharCode(code) {
|
|
141
141
|
return (// NaN/undefined represents access beyond the end of the file.
|
|
@@ -147,9 +147,9 @@ function printCharCode(code) {
|
|
|
147
147
|
/**
|
|
148
148
|
* Gets the next token from the source starting at the given position.
|
|
149
149
|
*
|
|
150
|
-
* This skips over whitespace
|
|
151
|
-
*
|
|
152
|
-
*
|
|
150
|
+
* This skips over whitespace until it finds the next lexable token, then lexes
|
|
151
|
+
* punctuators immediately or calls the appropriate helper function for more
|
|
152
|
+
* complicated tokens.
|
|
153
153
|
*/
|
|
154
154
|
|
|
155
155
|
|
|
@@ -165,7 +165,7 @@ function readToken(lexer, prev) {
|
|
|
165
165
|
return new Tok(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
var code = charCodeAt
|
|
168
|
+
var code = body.charCodeAt(pos); // SourceCharacter
|
|
169
169
|
|
|
170
170
|
switch (code) {
|
|
171
171
|
// !
|
|
@@ -194,7 +194,7 @@ function readToken(lexer, prev) {
|
|
|
194
194
|
// .
|
|
195
195
|
|
|
196
196
|
case 46:
|
|
197
|
-
if (charCodeAt
|
|
197
|
+
if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {
|
|
198
198
|
return new Tok(TokenKind.SPREAD, pos, pos + 3, line, col, prev);
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -304,8 +304,8 @@ function readToken(lexer, prev) {
|
|
|
304
304
|
// "
|
|
305
305
|
|
|
306
306
|
case 34:
|
|
307
|
-
if (charCodeAt
|
|
308
|
-
return readBlockString(source, pos, line, col, prev);
|
|
307
|
+
if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {
|
|
308
|
+
return readBlockString(source, pos, line, col, prev, lexer);
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
return readString(source, pos, line, col, prev);
|
|
@@ -332,8 +332,7 @@ function unexpectedCharacterMessage(code) {
|
|
|
332
332
|
}
|
|
333
333
|
/**
|
|
334
334
|
* Reads from body starting at startPosition until it finds a non-whitespace
|
|
335
|
-
*
|
|
336
|
-
* lexing.
|
|
335
|
+
* character, then returns the position of that character for lexing.
|
|
337
336
|
*/
|
|
338
337
|
|
|
339
338
|
|
|
@@ -342,7 +341,7 @@ function positionAfterWhitespace(body, startPosition, lexer) {
|
|
|
342
341
|
var position = startPosition;
|
|
343
342
|
|
|
344
343
|
while (position < bodyLength) {
|
|
345
|
-
var code = charCodeAt
|
|
344
|
+
var code = body.charCodeAt(position); // tab | space | comma | BOM
|
|
346
345
|
|
|
347
346
|
if (code === 9 || code === 32 || code === 44 || code === 0xfeff) {
|
|
348
347
|
++position;
|
|
@@ -353,7 +352,7 @@ function positionAfterWhitespace(body, startPosition, lexer) {
|
|
|
353
352
|
lexer.lineStart = position;
|
|
354
353
|
} else if (code === 13) {
|
|
355
354
|
// carriage return
|
|
356
|
-
if (charCodeAt
|
|
355
|
+
if (body.charCodeAt(position + 1) === 10) {
|
|
357
356
|
position += 2;
|
|
358
357
|
} else {
|
|
359
358
|
++position;
|
|
@@ -381,11 +380,11 @@ function readComment(source, start, line, col, prev) {
|
|
|
381
380
|
var position = start;
|
|
382
381
|
|
|
383
382
|
do {
|
|
384
|
-
code = charCodeAt
|
|
385
|
-
} while (code
|
|
383
|
+
code = body.charCodeAt(++position);
|
|
384
|
+
} while (!isNaN(code) && ( // SourceCharacter but not LineTerminator
|
|
386
385
|
code > 0x001f || code === 0x0009));
|
|
387
386
|
|
|
388
|
-
return new Tok(TokenKind.COMMENT, start, position, line, col, prev, slice
|
|
387
|
+
return new Tok(TokenKind.COMMENT, start, position, line, col, prev, body.slice(start + 1, position));
|
|
389
388
|
}
|
|
390
389
|
/**
|
|
391
390
|
* Reads a number token from the source file, either a float
|
|
@@ -404,43 +403,43 @@ function readNumber(source, start, firstCode, line, col, prev) {
|
|
|
404
403
|
|
|
405
404
|
if (code === 45) {
|
|
406
405
|
// -
|
|
407
|
-
code = charCodeAt
|
|
406
|
+
code = body.charCodeAt(++position);
|
|
408
407
|
}
|
|
409
408
|
|
|
410
409
|
if (code === 48) {
|
|
411
410
|
// 0
|
|
412
|
-
code = charCodeAt
|
|
411
|
+
code = body.charCodeAt(++position);
|
|
413
412
|
|
|
414
413
|
if (code >= 48 && code <= 57) {
|
|
415
414
|
throw (0, _error.syntaxError)(source, position, "Invalid number, unexpected digit after 0: ".concat(printCharCode(code), "."));
|
|
416
415
|
}
|
|
417
416
|
} else {
|
|
418
417
|
position = readDigits(source, position, code);
|
|
419
|
-
code = charCodeAt
|
|
418
|
+
code = body.charCodeAt(position);
|
|
420
419
|
}
|
|
421
420
|
|
|
422
421
|
if (code === 46) {
|
|
423
422
|
// .
|
|
424
423
|
isFloat = true;
|
|
425
|
-
code = charCodeAt
|
|
424
|
+
code = body.charCodeAt(++position);
|
|
426
425
|
position = readDigits(source, position, code);
|
|
427
|
-
code = charCodeAt
|
|
426
|
+
code = body.charCodeAt(position);
|
|
428
427
|
}
|
|
429
428
|
|
|
430
429
|
if (code === 69 || code === 101) {
|
|
431
430
|
// E e
|
|
432
431
|
isFloat = true;
|
|
433
|
-
code = charCodeAt
|
|
432
|
+
code = body.charCodeAt(++position);
|
|
434
433
|
|
|
435
434
|
if (code === 43 || code === 45) {
|
|
436
435
|
// + -
|
|
437
|
-
code = charCodeAt
|
|
436
|
+
code = body.charCodeAt(++position);
|
|
438
437
|
}
|
|
439
438
|
|
|
440
439
|
position = readDigits(source, position, code);
|
|
441
440
|
}
|
|
442
441
|
|
|
443
|
-
return new Tok(isFloat ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, slice
|
|
442
|
+
return new Tok(isFloat ? TokenKind.FLOAT : TokenKind.INT, start, position, line, col, prev, body.slice(start, position));
|
|
444
443
|
}
|
|
445
444
|
/**
|
|
446
445
|
* Returns the new position in the source after reading digits.
|
|
@@ -455,7 +454,7 @@ function readDigits(source, start, firstCode) {
|
|
|
455
454
|
if (code >= 48 && code <= 57) {
|
|
456
455
|
// 0 - 9
|
|
457
456
|
do {
|
|
458
|
-
code = charCodeAt
|
|
457
|
+
code = body.charCodeAt(++position);
|
|
459
458
|
} while (code >= 48 && code <= 57); // 0 - 9
|
|
460
459
|
|
|
461
460
|
|
|
@@ -478,11 +477,11 @@ function readString(source, start, line, col, prev) {
|
|
|
478
477
|
var code = 0;
|
|
479
478
|
var value = '';
|
|
480
479
|
|
|
481
|
-
while (position < body.length && (code = charCodeAt
|
|
480
|
+
while (position < body.length && !isNaN(code = body.charCodeAt(position)) && // not LineTerminator
|
|
482
481
|
code !== 0x000a && code !== 0x000d) {
|
|
483
482
|
// Closing Quote (")
|
|
484
483
|
if (code === 34) {
|
|
485
|
-
value += slice
|
|
484
|
+
value += body.slice(chunkStart, position);
|
|
486
485
|
return new Tok(TokenKind.STRING, start, position + 1, line, col, prev, value);
|
|
487
486
|
} // SourceCharacter
|
|
488
487
|
|
|
@@ -495,8 +494,8 @@ function readString(source, start, line, col, prev) {
|
|
|
495
494
|
|
|
496
495
|
if (code === 92) {
|
|
497
496
|
// \
|
|
498
|
-
value += slice
|
|
499
|
-
code = charCodeAt
|
|
497
|
+
value += body.slice(chunkStart, position - 1);
|
|
498
|
+
code = body.charCodeAt(position);
|
|
500
499
|
|
|
501
500
|
switch (code) {
|
|
502
501
|
case 34:
|
|
@@ -533,7 +532,7 @@ function readString(source, start, line, col, prev) {
|
|
|
533
532
|
|
|
534
533
|
case 117:
|
|
535
534
|
// u
|
|
536
|
-
var charCode = uniCharCode(charCodeAt
|
|
535
|
+
var charCode = uniCharCode(body.charCodeAt(position + 1), body.charCodeAt(position + 2), body.charCodeAt(position + 3), body.charCodeAt(position + 4));
|
|
537
536
|
|
|
538
537
|
if (charCode < 0) {
|
|
539
538
|
throw (0, _error.syntaxError)(source, position, 'Invalid character escape sequence: ' + "\\u".concat(body.slice(position + 1, position + 5), "."));
|
|
@@ -561,28 +560,43 @@ function readString(source, start, line, col, prev) {
|
|
|
561
560
|
*/
|
|
562
561
|
|
|
563
562
|
|
|
564
|
-
function readBlockString(source, start, line, col, prev) {
|
|
563
|
+
function readBlockString(source, start, line, col, prev, lexer) {
|
|
565
564
|
var body = source.body;
|
|
566
565
|
var position = start + 3;
|
|
567
566
|
var chunkStart = position;
|
|
568
567
|
var code = 0;
|
|
569
568
|
var rawValue = '';
|
|
570
569
|
|
|
571
|
-
while (position < body.length && (code = charCodeAt
|
|
570
|
+
while (position < body.length && !isNaN(code = body.charCodeAt(position))) {
|
|
572
571
|
// Closing Triple-Quote (""")
|
|
573
|
-
if (code === 34 && charCodeAt
|
|
574
|
-
rawValue += slice
|
|
575
|
-
return new Tok(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, (0,
|
|
572
|
+
if (code === 34 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34) {
|
|
573
|
+
rawValue += body.slice(chunkStart, position);
|
|
574
|
+
return new Tok(TokenKind.BLOCK_STRING, start, position + 3, line, col, prev, (0, _blockString.dedentBlockStringValue)(rawValue));
|
|
576
575
|
} // SourceCharacter
|
|
577
576
|
|
|
578
577
|
|
|
579
578
|
if (code < 0x0020 && code !== 0x0009 && code !== 0x000a && code !== 0x000d) {
|
|
580
579
|
throw (0, _error.syntaxError)(source, position, "Invalid character within String: ".concat(printCharCode(code), "."));
|
|
581
|
-
}
|
|
580
|
+
}
|
|
582
581
|
|
|
582
|
+
if (code === 10) {
|
|
583
|
+
// new line
|
|
584
|
+
++position;
|
|
585
|
+
++lexer.line;
|
|
586
|
+
lexer.lineStart = position;
|
|
587
|
+
} else if (code === 13) {
|
|
588
|
+
// carriage return
|
|
589
|
+
if (body.charCodeAt(position + 1) === 10) {
|
|
590
|
+
position += 2;
|
|
591
|
+
} else {
|
|
592
|
+
++position;
|
|
593
|
+
}
|
|
583
594
|
|
|
584
|
-
|
|
585
|
-
|
|
595
|
+
++lexer.line;
|
|
596
|
+
lexer.lineStart = position;
|
|
597
|
+
} else if ( // Escape Triple-Quote (\""")
|
|
598
|
+
code === 92 && body.charCodeAt(position + 1) === 34 && body.charCodeAt(position + 2) === 34 && body.charCodeAt(position + 3) === 34) {
|
|
599
|
+
rawValue += body.slice(chunkStart, position) + '"""';
|
|
586
600
|
position += 4;
|
|
587
601
|
chunkStart = position;
|
|
588
602
|
} else {
|
|
@@ -636,7 +650,7 @@ function readName(source, start, line, col, prev) {
|
|
|
636
650
|
var position = start + 1;
|
|
637
651
|
var code = 0;
|
|
638
652
|
|
|
639
|
-
while (position !== bodyLength && (code = charCodeAt
|
|
653
|
+
while (position !== bodyLength && !isNaN(code = body.charCodeAt(position)) && (code === 95 || // _
|
|
640
654
|
code >= 48 && code <= 57 || // 0-9
|
|
641
655
|
code >= 65 && code <= 90 || // A-Z
|
|
642
656
|
code >= 97 && code <= 122) // a-z
|
|
@@ -644,5 +658,5 @@ function readName(source, start, line, col, prev) {
|
|
|
644
658
|
++position;
|
|
645
659
|
}
|
|
646
660
|
|
|
647
|
-
return new Tok(TokenKind.NAME, start, position, line, col, prev, slice
|
|
661
|
+
return new Tok(TokenKind.NAME, start, position, line, col, prev, body.slice(start, position));
|
|
648
662
|
}
|
package/language/lexer.js.flow
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import defineToJSON from '../jsutils/defineToJSON';
|
|
10
11
|
import type { Token } from './ast';
|
|
11
12
|
import type { Source } from './source';
|
|
12
13
|
import { syntaxError } from '../error';
|
|
13
|
-
import
|
|
14
|
+
import { dedentBlockStringValue } from './blockString';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Given a Source object, this returns a Lexer for that source.
|
|
@@ -136,9 +137,6 @@ export function getTokenDesc(token: Token): string {
|
|
|
136
137
|
return value ? `${token.kind} "${value}"` : token.kind;
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
const charCodeAt = String.prototype.charCodeAt;
|
|
140
|
-
const slice = String.prototype.slice;
|
|
141
|
-
|
|
142
140
|
/**
|
|
143
141
|
* Helper function for constructing the Token object.
|
|
144
142
|
*/
|
|
@@ -162,14 +160,14 @@ function Tok(
|
|
|
162
160
|
}
|
|
163
161
|
|
|
164
162
|
// Print a simplified form when appearing in JSON/util.inspect.
|
|
165
|
-
Tok
|
|
163
|
+
defineToJSON(Tok, function() {
|
|
166
164
|
return {
|
|
167
165
|
kind: this.kind,
|
|
168
166
|
value: this.value,
|
|
169
167
|
line: this.line,
|
|
170
168
|
column: this.column,
|
|
171
169
|
};
|
|
172
|
-
};
|
|
170
|
+
});
|
|
173
171
|
|
|
174
172
|
function printCharCode(code) {
|
|
175
173
|
return (
|
|
@@ -177,19 +175,19 @@ function printCharCode(code) {
|
|
|
177
175
|
isNaN(code)
|
|
178
176
|
? TokenKind.EOF
|
|
179
177
|
: // Trust JSON for ASCII.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
178
|
+
code < 0x007f
|
|
179
|
+
? JSON.stringify(String.fromCharCode(code))
|
|
180
|
+
: // Otherwise print the escaped form.
|
|
181
|
+
`"\\u${('00' + code.toString(16).toUpperCase()).slice(-4)}"`
|
|
184
182
|
);
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
/**
|
|
188
186
|
* Gets the next token from the source starting at the given position.
|
|
189
187
|
*
|
|
190
|
-
* This skips over whitespace
|
|
191
|
-
*
|
|
192
|
-
*
|
|
188
|
+
* This skips over whitespace until it finds the next lexable token, then lexes
|
|
189
|
+
* punctuators immediately or calls the appropriate helper function for more
|
|
190
|
+
* complicated tokens.
|
|
193
191
|
*/
|
|
194
192
|
function readToken(lexer: Lexer<*>, prev: Token): Token {
|
|
195
193
|
const source = lexer.source;
|
|
@@ -204,7 +202,7 @@ function readToken(lexer: Lexer<*>, prev: Token): Token {
|
|
|
204
202
|
return new Tok(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
|
|
205
203
|
}
|
|
206
204
|
|
|
207
|
-
const code = charCodeAt
|
|
205
|
+
const code = body.charCodeAt(pos);
|
|
208
206
|
|
|
209
207
|
// SourceCharacter
|
|
210
208
|
switch (code) {
|
|
@@ -228,10 +226,7 @@ function readToken(lexer: Lexer<*>, prev: Token): Token {
|
|
|
228
226
|
return new Tok(TokenKind.PAREN_R, pos, pos + 1, line, col, prev);
|
|
229
227
|
// .
|
|
230
228
|
case 46:
|
|
231
|
-
if (
|
|
232
|
-
charCodeAt.call(body, pos + 1) === 46 &&
|
|
233
|
-
charCodeAt.call(body, pos + 2) === 46
|
|
234
|
-
) {
|
|
229
|
+
if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {
|
|
235
230
|
return new Tok(TokenKind.SPREAD, pos, pos + 3, line, col, prev);
|
|
236
231
|
}
|
|
237
232
|
break;
|
|
@@ -329,11 +324,8 @@ function readToken(lexer: Lexer<*>, prev: Token): Token {
|
|
|
329
324
|
return readNumber(source, pos, code, line, col, prev);
|
|
330
325
|
// "
|
|
331
326
|
case 34:
|
|
332
|
-
if (
|
|
333
|
-
|
|
334
|
-
charCodeAt.call(body, pos + 2) === 34
|
|
335
|
-
) {
|
|
336
|
-
return readBlockString(source, pos, line, col, prev);
|
|
327
|
+
if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {
|
|
328
|
+
return readBlockString(source, pos, line, col, prev, lexer);
|
|
337
329
|
}
|
|
338
330
|
return readString(source, pos, line, col, prev);
|
|
339
331
|
}
|
|
@@ -362,8 +354,7 @@ function unexpectedCharacterMessage(code) {
|
|
|
362
354
|
|
|
363
355
|
/**
|
|
364
356
|
* Reads from body starting at startPosition until it finds a non-whitespace
|
|
365
|
-
*
|
|
366
|
-
* lexing.
|
|
357
|
+
* character, then returns the position of that character for lexing.
|
|
367
358
|
*/
|
|
368
359
|
function positionAfterWhitespace(
|
|
369
360
|
body: string,
|
|
@@ -373,7 +364,7 @@ function positionAfterWhitespace(
|
|
|
373
364
|
const bodyLength = body.length;
|
|
374
365
|
let position = startPosition;
|
|
375
366
|
while (position < bodyLength) {
|
|
376
|
-
const code = charCodeAt
|
|
367
|
+
const code = body.charCodeAt(position);
|
|
377
368
|
// tab | space | comma | BOM
|
|
378
369
|
if (code === 9 || code === 32 || code === 44 || code === 0xfeff) {
|
|
379
370
|
++position;
|
|
@@ -384,7 +375,7 @@ function positionAfterWhitespace(
|
|
|
384
375
|
lexer.lineStart = position;
|
|
385
376
|
} else if (code === 13) {
|
|
386
377
|
// carriage return
|
|
387
|
-
if (charCodeAt
|
|
378
|
+
if (body.charCodeAt(position + 1) === 10) {
|
|
388
379
|
position += 2;
|
|
389
380
|
} else {
|
|
390
381
|
++position;
|
|
@@ -409,9 +400,9 @@ function readComment(source, start, line, col, prev): Token {
|
|
|
409
400
|
let position = start;
|
|
410
401
|
|
|
411
402
|
do {
|
|
412
|
-
code = charCodeAt
|
|
403
|
+
code = body.charCodeAt(++position);
|
|
413
404
|
} while (
|
|
414
|
-
code
|
|
405
|
+
!isNaN(code) &&
|
|
415
406
|
// SourceCharacter but not LineTerminator
|
|
416
407
|
(code > 0x001f || code === 0x0009)
|
|
417
408
|
);
|
|
@@ -423,7 +414,7 @@ function readComment(source, start, line, col, prev): Token {
|
|
|
423
414
|
line,
|
|
424
415
|
col,
|
|
425
416
|
prev,
|
|
426
|
-
slice
|
|
417
|
+
body.slice(start + 1, position),
|
|
427
418
|
);
|
|
428
419
|
}
|
|
429
420
|
|
|
@@ -442,12 +433,12 @@ function readNumber(source, start, firstCode, line, col, prev): Token {
|
|
|
442
433
|
|
|
443
434
|
if (code === 45) {
|
|
444
435
|
// -
|
|
445
|
-
code = charCodeAt
|
|
436
|
+
code = body.charCodeAt(++position);
|
|
446
437
|
}
|
|
447
438
|
|
|
448
439
|
if (code === 48) {
|
|
449
440
|
// 0
|
|
450
|
-
code = charCodeAt
|
|
441
|
+
code = body.charCodeAt(++position);
|
|
451
442
|
if (code >= 48 && code <= 57) {
|
|
452
443
|
throw syntaxError(
|
|
453
444
|
source,
|
|
@@ -457,26 +448,26 @@ function readNumber(source, start, firstCode, line, col, prev): Token {
|
|
|
457
448
|
}
|
|
458
449
|
} else {
|
|
459
450
|
position = readDigits(source, position, code);
|
|
460
|
-
code = charCodeAt
|
|
451
|
+
code = body.charCodeAt(position);
|
|
461
452
|
}
|
|
462
453
|
|
|
463
454
|
if (code === 46) {
|
|
464
455
|
// .
|
|
465
456
|
isFloat = true;
|
|
466
457
|
|
|
467
|
-
code = charCodeAt
|
|
458
|
+
code = body.charCodeAt(++position);
|
|
468
459
|
position = readDigits(source, position, code);
|
|
469
|
-
code = charCodeAt
|
|
460
|
+
code = body.charCodeAt(position);
|
|
470
461
|
}
|
|
471
462
|
|
|
472
463
|
if (code === 69 || code === 101) {
|
|
473
464
|
// E e
|
|
474
465
|
isFloat = true;
|
|
475
466
|
|
|
476
|
-
code = charCodeAt
|
|
467
|
+
code = body.charCodeAt(++position);
|
|
477
468
|
if (code === 43 || code === 45) {
|
|
478
469
|
// + -
|
|
479
|
-
code = charCodeAt
|
|
470
|
+
code = body.charCodeAt(++position);
|
|
480
471
|
}
|
|
481
472
|
position = readDigits(source, position, code);
|
|
482
473
|
}
|
|
@@ -488,7 +479,7 @@ function readNumber(source, start, firstCode, line, col, prev): Token {
|
|
|
488
479
|
line,
|
|
489
480
|
col,
|
|
490
481
|
prev,
|
|
491
|
-
slice
|
|
482
|
+
body.slice(start, position),
|
|
492
483
|
);
|
|
493
484
|
}
|
|
494
485
|
|
|
@@ -502,7 +493,7 @@ function readDigits(source, start, firstCode) {
|
|
|
502
493
|
if (code >= 48 && code <= 57) {
|
|
503
494
|
// 0 - 9
|
|
504
495
|
do {
|
|
505
|
-
code = charCodeAt
|
|
496
|
+
code = body.charCodeAt(++position);
|
|
506
497
|
} while (code >= 48 && code <= 57); // 0 - 9
|
|
507
498
|
return position;
|
|
508
499
|
}
|
|
@@ -527,14 +518,14 @@ function readString(source, start, line, col, prev): Token {
|
|
|
527
518
|
|
|
528
519
|
while (
|
|
529
520
|
position < body.length &&
|
|
530
|
-
(code = charCodeAt
|
|
521
|
+
!isNaN((code = body.charCodeAt(position))) &&
|
|
531
522
|
// not LineTerminator
|
|
532
523
|
code !== 0x000a &&
|
|
533
524
|
code !== 0x000d
|
|
534
525
|
) {
|
|
535
526
|
// Closing Quote (")
|
|
536
527
|
if (code === 34) {
|
|
537
|
-
value += slice
|
|
528
|
+
value += body.slice(chunkStart, position);
|
|
538
529
|
return new Tok(
|
|
539
530
|
TokenKind.STRING,
|
|
540
531
|
start,
|
|
@@ -558,8 +549,8 @@ function readString(source, start, line, col, prev): Token {
|
|
|
558
549
|
++position;
|
|
559
550
|
if (code === 92) {
|
|
560
551
|
// \
|
|
561
|
-
value += slice
|
|
562
|
-
code = charCodeAt
|
|
552
|
+
value += body.slice(chunkStart, position - 1);
|
|
553
|
+
code = body.charCodeAt(position);
|
|
563
554
|
switch (code) {
|
|
564
555
|
case 34:
|
|
565
556
|
value += '"';
|
|
@@ -587,10 +578,10 @@ function readString(source, start, line, col, prev): Token {
|
|
|
587
578
|
break;
|
|
588
579
|
case 117: // u
|
|
589
580
|
const charCode = uniCharCode(
|
|
590
|
-
charCodeAt
|
|
591
|
-
charCodeAt
|
|
592
|
-
charCodeAt
|
|
593
|
-
charCodeAt
|
|
581
|
+
body.charCodeAt(position + 1),
|
|
582
|
+
body.charCodeAt(position + 2),
|
|
583
|
+
body.charCodeAt(position + 3),
|
|
584
|
+
body.charCodeAt(position + 4),
|
|
594
585
|
);
|
|
595
586
|
if (charCode < 0) {
|
|
596
587
|
throw syntaxError(
|
|
@@ -625,24 +616,21 @@ function readString(source, start, line, col, prev): Token {
|
|
|
625
616
|
*
|
|
626
617
|
* """("?"?(\\"""|\\(?!=""")|[^"\\]))*"""
|
|
627
618
|
*/
|
|
628
|
-
function readBlockString(source, start, line, col, prev): Token {
|
|
619
|
+
function readBlockString(source, start, line, col, prev, lexer): Token {
|
|
629
620
|
const body = source.body;
|
|
630
621
|
let position = start + 3;
|
|
631
622
|
let chunkStart = position;
|
|
632
623
|
let code = 0;
|
|
633
624
|
let rawValue = '';
|
|
634
625
|
|
|
635
|
-
while (
|
|
636
|
-
position < body.length &&
|
|
637
|
-
(code = charCodeAt.call(body, position)) !== null
|
|
638
|
-
) {
|
|
626
|
+
while (position < body.length && !isNaN((code = body.charCodeAt(position)))) {
|
|
639
627
|
// Closing Triple-Quote (""")
|
|
640
628
|
if (
|
|
641
629
|
code === 34 &&
|
|
642
|
-
charCodeAt
|
|
643
|
-
charCodeAt
|
|
630
|
+
body.charCodeAt(position + 1) === 34 &&
|
|
631
|
+
body.charCodeAt(position + 2) === 34
|
|
644
632
|
) {
|
|
645
|
-
rawValue += slice
|
|
633
|
+
rawValue += body.slice(chunkStart, position);
|
|
646
634
|
return new Tok(
|
|
647
635
|
TokenKind.BLOCK_STRING,
|
|
648
636
|
start,
|
|
@@ -650,7 +638,7 @@ function readBlockString(source, start, line, col, prev): Token {
|
|
|
650
638
|
line,
|
|
651
639
|
col,
|
|
652
640
|
prev,
|
|
653
|
-
|
|
641
|
+
dedentBlockStringValue(rawValue),
|
|
654
642
|
);
|
|
655
643
|
}
|
|
656
644
|
|
|
@@ -668,14 +656,28 @@ function readBlockString(source, start, line, col, prev): Token {
|
|
|
668
656
|
);
|
|
669
657
|
}
|
|
670
658
|
|
|
671
|
-
|
|
672
|
-
|
|
659
|
+
if (code === 10) {
|
|
660
|
+
// new line
|
|
661
|
+
++position;
|
|
662
|
+
++lexer.line;
|
|
663
|
+
lexer.lineStart = position;
|
|
664
|
+
} else if (code === 13) {
|
|
665
|
+
// carriage return
|
|
666
|
+
if (body.charCodeAt(position + 1) === 10) {
|
|
667
|
+
position += 2;
|
|
668
|
+
} else {
|
|
669
|
+
++position;
|
|
670
|
+
}
|
|
671
|
+
++lexer.line;
|
|
672
|
+
lexer.lineStart = position;
|
|
673
|
+
} else if (
|
|
674
|
+
// Escape Triple-Quote (\""")
|
|
673
675
|
code === 92 &&
|
|
674
|
-
charCodeAt
|
|
675
|
-
charCodeAt
|
|
676
|
-
charCodeAt
|
|
676
|
+
body.charCodeAt(position + 1) === 34 &&
|
|
677
|
+
body.charCodeAt(position + 2) === 34 &&
|
|
678
|
+
body.charCodeAt(position + 3) === 34
|
|
677
679
|
) {
|
|
678
|
-
rawValue += slice
|
|
680
|
+
rawValue += body.slice(chunkStart, position) + '"""';
|
|
679
681
|
position += 4;
|
|
680
682
|
chunkStart = position;
|
|
681
683
|
} else {
|
|
@@ -714,10 +716,10 @@ function char2hex(a) {
|
|
|
714
716
|
return a >= 48 && a <= 57
|
|
715
717
|
? a - 48 // 0-9
|
|
716
718
|
: a >= 65 && a <= 70
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
719
|
+
? a - 55 // A-F
|
|
720
|
+
: a >= 97 && a <= 102
|
|
721
|
+
? a - 87 // a-f
|
|
722
|
+
: -1;
|
|
721
723
|
}
|
|
722
724
|
|
|
723
725
|
/**
|
|
@@ -732,7 +734,7 @@ function readName(source, start, line, col, prev): Token {
|
|
|
732
734
|
let code = 0;
|
|
733
735
|
while (
|
|
734
736
|
position !== bodyLength &&
|
|
735
|
-
(code = charCodeAt
|
|
737
|
+
!isNaN((code = body.charCodeAt(position))) &&
|
|
736
738
|
(code === 95 || // _
|
|
737
739
|
(code >= 48 && code <= 57) || // 0-9
|
|
738
740
|
(code >= 65 && code <= 90) || // A-Z
|
|
@@ -747,6 +749,6 @@ function readName(source, start, line, col, prev): Token {
|
|
|
747
749
|
line,
|
|
748
750
|
col,
|
|
749
751
|
prev,
|
|
750
|
-
slice
|
|
752
|
+
body.slice(start, position),
|
|
751
753
|
);
|
|
752
754
|
}
|