graphql 16.0.1 → 16.3.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/README.md +4 -4
- package/error/GraphQLError.d.ts +17 -1
- package/error/GraphQLError.js +28 -10
- package/error/GraphQLError.mjs +28 -19
- package/error/locatedError.js +2 -8
- package/error/locatedError.mjs +2 -6
- package/execution/collectFields.d.ts +8 -8
- package/execution/collectFields.js +8 -8
- package/execution/collectFields.mjs +7 -7
- package/execution/execute.d.ts +5 -5
- package/execution/execute.js +28 -17
- package/execution/execute.mjs +30 -19
- package/execution/index.d.ts +1 -1
- package/execution/index.js +6 -0
- package/execution/index.mjs +1 -1
- package/execution/mapAsyncIterator.js +3 -1
- package/execution/mapAsyncIterator.mjs +3 -1
- package/execution/subscribe.d.ts +1 -1
- package/execution/subscribe.js +10 -2
- package/execution/subscribe.mjs +8 -1
- package/execution/values.d.ts +3 -5
- package/execution/values.js +7 -8
- package/execution/values.mjs +5 -6
- package/graphql.js +12 -4
- package/graphql.mjs +8 -1
- package/index.d.ts +7 -61
- package/index.js +30 -0
- package/index.mjs +62 -111
- package/jsutils/devAssert.js +1 -1
- package/jsutils/devAssert.mjs +1 -1
- package/jsutils/instanceOf.js +3 -1
- package/jsutils/instanceOf.mjs +3 -1
- package/jsutils/invariant.js +1 -1
- package/jsutils/invariant.mjs +1 -1
- package/jsutils/mapValue.js +2 -2
- package/jsutils/mapValue.mjs +2 -2
- package/jsutils/promiseReduce.mjs +1 -1
- package/jsutils/toError.d.ts +4 -0
- package/jsutils/toError.js +25 -0
- package/jsutils/toError.mjs +18 -0
- package/language/blockString.d.ts +7 -3
- package/language/blockString.js +121 -64
- package/language/blockString.mjs +111 -62
- package/language/characterClasses.d.ts +9 -0
- package/language/characterClasses.js +13 -0
- package/language/characterClasses.mjs +12 -0
- package/language/index.d.ts +0 -1
- package/language/lexer.d.ts +1 -1
- package/language/lexer.js +23 -15
- package/language/lexer.mjs +23 -15
- package/language/parser.d.ts +40 -40
- package/language/parser.js +9 -8
- package/language/parser.mjs +7 -6
- package/language/predicates.d.ts +4 -4
- package/language/printLocation.d.ts +1 -1
- package/language/printLocation.mjs +1 -1
- package/language/printer.js +5 -3
- package/language/printer.mjs +4 -2
- package/language/source.js +2 -2
- package/language/source.mjs +1 -1
- package/language/visitor.js +12 -13
- package/language/visitor.mjs +11 -12
- package/package.json +4 -1
- package/type/assertName.mjs +1 -1
- package/type/definition.d.ts +18 -14
- package/type/definition.js +13 -11
- package/type/definition.mjs +10 -16
- package/type/directives.d.ts +1 -1
- package/type/directives.js +9 -9
- package/type/directives.mjs +7 -7
- package/type/index.d.ts +5 -27
- package/type/index.js +24 -0
- package/type/index.mjs +26 -40
- package/type/introspection.d.ts +2 -2
- package/type/introspection.js +12 -8
- package/type/introspection.mjs +16 -12
- package/type/scalars.d.ts +10 -0
- package/type/scalars.js +20 -12
- package/type/scalars.mjs +17 -12
- package/type/schema.d.ts +4 -4
- package/type/schema.js +11 -9
- package/type/schema.mjs +11 -10
- package/type/validate.js +39 -30
- package/type/validate.mjs +42 -33
- package/utilities/TypeInfo.d.ts +9 -9
- package/utilities/TypeInfo.js +6 -2
- package/utilities/TypeInfo.mjs +11 -7
- package/utilities/assertValidName.js +3 -2
- package/utilities/assertValidName.mjs +3 -2
- package/utilities/astFromValue.js +8 -6
- package/utilities/astFromValue.mjs +7 -5
- package/utilities/buildASTSchema.d.ts +1 -1
- package/utilities/buildASTSchema.js +2 -2
- package/utilities/buildASTSchema.mjs +2 -2
- package/utilities/buildClientSchema.js +9 -7
- package/utilities/buildClientSchema.mjs +17 -15
- package/utilities/coerceInputValue.js +9 -7
- package/utilities/coerceInputValue.mjs +9 -7
- package/utilities/extendSchema.d.ts +1 -1
- package/utilities/extendSchema.js +50 -42
- package/utilities/extendSchema.mjs +71 -60
- package/utilities/findBreakingChanges.js +9 -22
- package/utilities/findBreakingChanges.mjs +13 -22
- package/utilities/getIntrospectionQuery.d.ts +4 -0
- package/utilities/getIntrospectionQuery.js +4 -0
- package/utilities/getIntrospectionQuery.mjs +4 -0
- package/utilities/getOperationRootType.d.ts +1 -1
- package/utilities/index.d.ts +0 -25
- package/utilities/index.mjs +21 -44
- package/utilities/introspectionFromSchema.d.ts +1 -1
- package/utilities/lexicographicSortSchema.js +8 -7
- package/utilities/lexicographicSortSchema.mjs +16 -15
- package/utilities/printSchema.d.ts +1 -1
- package/utilities/printSchema.js +14 -12
- package/utilities/printSchema.mjs +20 -15
- package/utilities/separateOperations.js +2 -0
- package/utilities/separateOperations.mjs +2 -0
- package/utilities/sortValueNode.d.ts +9 -0
- package/utilities/sortValueNode.js +47 -0
- package/utilities/sortValueNode.mjs +39 -0
- package/utilities/stripIgnoredCharacters.js +7 -23
- package/utilities/stripIgnoredCharacters.mjs +6 -25
- package/utilities/typeComparators.d.ts +1 -1
- package/utilities/typeComparators.mjs +3 -3
- package/utilities/typeFromAST.d.ts +4 -4
- package/utilities/typeFromAST.js +13 -24
- package/utilities/typeFromAST.mjs +12 -25
- package/utilities/valueFromAST.d.ts +1 -1
- package/utilities/valueFromAST.js +6 -4
- package/utilities/valueFromAST.mjs +7 -5
- package/utilities/valueFromASTUntyped.d.ts +1 -1
- package/utilities/valueFromASTUntyped.js +1 -11
- package/utilities/valueFromASTUntyped.mjs +2 -6
- package/validation/ValidationContext.d.ts +10 -10
- package/validation/index.d.ts +0 -29
- package/validation/index.mjs +29 -58
- package/validation/rules/FieldsOnCorrectTypeRule.js +2 -2
- package/validation/rules/FieldsOnCorrectTypeRule.mjs +3 -3
- package/validation/rules/KnownArgumentNamesRule.d.ts +1 -1
- package/validation/rules/KnownArgumentNamesRule.js +3 -1
- package/validation/rules/KnownArgumentNamesRule.mjs +3 -1
- package/validation/rules/KnownDirectivesRule.d.ts +1 -1
- package/validation/rules/KnownDirectivesRule.js +13 -9
- package/validation/rules/KnownDirectivesRule.mjs +8 -4
- package/validation/rules/KnownTypeNamesRule.d.ts +1 -1
- package/validation/rules/KnownTypeNamesRule.js +2 -2
- package/validation/rules/KnownTypeNamesRule.mjs +1 -1
- package/validation/rules/OverlappingFieldsCanBeMergedRule.js +41 -36
- package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +41 -39
- package/validation/rules/PossibleFragmentSpreadsRule.js +2 -2
- package/validation/rules/PossibleFragmentSpreadsRule.mjs +1 -1
- package/validation/rules/PossibleTypeExtensionsRule.js +16 -10
- package/validation/rules/PossibleTypeExtensionsRule.mjs +15 -9
- package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +1 -1
- package/validation/rules/ProvidedRequiredArgumentsRule.js +10 -5
- package/validation/rules/ProvidedRequiredArgumentsRule.mjs +9 -4
- package/validation/rules/UniqueArgumentDefinitionNamesRule.js +9 -3
- package/validation/rules/UniqueArgumentDefinitionNamesRule.mjs +9 -3
- package/validation/rules/UniqueArgumentNamesRule.js +3 -1
- package/validation/rules/UniqueArgumentNamesRule.mjs +3 -1
- package/validation/rules/UniqueEnumValueNamesRule.js +3 -1
- package/validation/rules/UniqueEnumValueNamesRule.mjs +3 -1
- package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -1
- package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +5 -3
- package/validation/rules/UniqueOperationTypesRule.js +3 -1
- package/validation/rules/UniqueOperationTypesRule.mjs +3 -1
- package/validation/rules/UniqueVariableNamesRule.js +3 -1
- package/validation/rules/UniqueVariableNamesRule.mjs +3 -1
- package/validation/rules/ValuesOfCorrectTypeRule.js +2 -2
- package/validation/rules/ValuesOfCorrectTypeRule.mjs +5 -5
- package/validation/rules/VariablesInAllowedPositionRule.js +2 -2
- package/validation/rules/VariablesInAllowedPositionRule.mjs +1 -1
- package/validation/specifiedRules.d.ts +1 -1
- package/validation/specifiedRules.js +47 -47
- package/validation/specifiedRules.mjs +41 -41
- package/version.js +3 -3
- package/version.mjs +3 -3
package/language/blockString.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.dedentBlockStringLines = dedentBlockStringLines;
|
|
7
|
+
exports.isPrintableAsBlockString = isPrintableAsBlockString;
|
|
8
8
|
exports.printBlockString = printBlockString;
|
|
9
9
|
|
|
10
|
+
var _characterClasses = require('./characterClasses.js');
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Produces the value of a block string from its parsed raw value, similar to
|
|
12
14
|
* CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
|
|
@@ -15,94 +17,128 @@ exports.printBlockString = printBlockString;
|
|
|
15
17
|
*
|
|
16
18
|
* @internal
|
|
17
19
|
*/
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
const lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
|
|
20
|
+
function dedentBlockStringLines(lines) {
|
|
21
|
+
var _firstNonEmptyLine2;
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
let commonIndent = Number.MAX_SAFE_INTEGER;
|
|
24
|
+
let firstNonEmptyLine = null;
|
|
25
|
+
let lastNonEmptyLine = -1;
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
lines[i] = lines[i].slice(commonIndent);
|
|
27
|
-
}
|
|
28
|
-
} // Remove leading and trailing blank lines.
|
|
27
|
+
for (let i = 0; i < lines.length; ++i) {
|
|
28
|
+
var _firstNonEmptyLine;
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const line = lines[i];
|
|
31
|
+
const indent = leadingWhitespace(line);
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (indent === line.length) {
|
|
34
|
+
continue; // skip empty lines
|
|
35
|
+
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
firstNonEmptyLine =
|
|
38
|
+
(_firstNonEmptyLine = firstNonEmptyLine) !== null &&
|
|
39
|
+
_firstNonEmptyLine !== void 0
|
|
40
|
+
? _firstNonEmptyLine
|
|
41
|
+
: i;
|
|
42
|
+
lastNonEmptyLine = i;
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
if (i !== 0 && indent < commonIndent) {
|
|
45
|
+
commonIndent = indent;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
41
48
|
|
|
42
|
-
return lines
|
|
49
|
+
return lines // Remove common indentation from all lines but first.
|
|
50
|
+
.map((line, i) => (i === 0 ? line : line.slice(commonIndent))) // Remove leading and trailing blank lines.
|
|
51
|
+
.slice(
|
|
52
|
+
(_firstNonEmptyLine2 = firstNonEmptyLine) !== null &&
|
|
53
|
+
_firstNonEmptyLine2 !== void 0
|
|
54
|
+
? _firstNonEmptyLine2
|
|
55
|
+
: 0,
|
|
56
|
+
lastNonEmptyLine + 1,
|
|
57
|
+
);
|
|
43
58
|
}
|
|
44
59
|
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
function leadingWhitespace(str) {
|
|
61
|
+
let i = 0;
|
|
62
|
+
|
|
63
|
+
while (
|
|
64
|
+
i < str.length &&
|
|
65
|
+
(0, _characterClasses.isWhiteSpace)(str.charCodeAt(i))
|
|
66
|
+
) {
|
|
67
|
+
++i;
|
|
50
68
|
}
|
|
51
69
|
|
|
52
|
-
return
|
|
70
|
+
return i;
|
|
53
71
|
}
|
|
54
72
|
/**
|
|
55
73
|
* @internal
|
|
56
74
|
*/
|
|
57
75
|
|
|
58
|
-
function
|
|
59
|
-
|
|
76
|
+
function isPrintableAsBlockString(value) {
|
|
77
|
+
if (value === '') {
|
|
78
|
+
return true; // empty string is printable
|
|
79
|
+
}
|
|
60
80
|
|
|
61
|
-
let isFirstLine = true;
|
|
62
81
|
let isEmptyLine = true;
|
|
63
|
-
let
|
|
64
|
-
let
|
|
82
|
+
let hasIndent = false;
|
|
83
|
+
let hasCommonIndent = true;
|
|
84
|
+
let seenNonEmptyLine = false;
|
|
65
85
|
|
|
66
86
|
for (let i = 0; i < value.length; ++i) {
|
|
67
|
-
switch (value.
|
|
68
|
-
case
|
|
87
|
+
switch (value.codePointAt(i)) {
|
|
88
|
+
case 0x0000:
|
|
89
|
+
case 0x0001:
|
|
90
|
+
case 0x0002:
|
|
91
|
+
case 0x0003:
|
|
92
|
+
case 0x0004:
|
|
93
|
+
case 0x0005:
|
|
94
|
+
case 0x0006:
|
|
95
|
+
case 0x0007:
|
|
96
|
+
case 0x0008:
|
|
97
|
+
case 0x000b:
|
|
98
|
+
case 0x000c:
|
|
99
|
+
case 0x000e:
|
|
100
|
+
case 0x000f:
|
|
101
|
+
return false;
|
|
102
|
+
// Has non-printable characters
|
|
103
|
+
|
|
104
|
+
case 0x000d:
|
|
69
105
|
// \r
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// falls through
|
|
106
|
+
return false;
|
|
107
|
+
// Has \r or \r\n which will be replaced as \n
|
|
75
108
|
|
|
76
109
|
case 10:
|
|
77
110
|
// \n
|
|
78
|
-
|
|
111
|
+
if (isEmptyLine && !seenNonEmptyLine) {
|
|
112
|
+
return false; // Has leading new line
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
seenNonEmptyLine = true;
|
|
79
116
|
isEmptyLine = true;
|
|
80
|
-
|
|
117
|
+
hasIndent = false;
|
|
81
118
|
break;
|
|
82
119
|
|
|
83
120
|
case 9: // \t
|
|
84
121
|
|
|
85
122
|
case 32:
|
|
86
123
|
// <space>
|
|
87
|
-
|
|
124
|
+
hasIndent || (hasIndent = isEmptyLine);
|
|
88
125
|
break;
|
|
89
126
|
|
|
90
127
|
default:
|
|
91
|
-
|
|
92
|
-
isEmptyLine &&
|
|
93
|
-
!isFirstLine &&
|
|
94
|
-
(commonIndent === null || indent < commonIndent)
|
|
95
|
-
) {
|
|
96
|
-
commonIndent = indent;
|
|
97
|
-
}
|
|
98
|
-
|
|
128
|
+
hasCommonIndent && (hasCommonIndent = hasIndent);
|
|
99
129
|
isEmptyLine = false;
|
|
100
130
|
}
|
|
101
131
|
}
|
|
102
132
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
133
|
+
if (isEmptyLine) {
|
|
134
|
+
return false; // Has trailing empty lines
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (hasCommonIndent && seenNonEmptyLine) {
|
|
138
|
+
return false; // Has internal indent
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return true;
|
|
106
142
|
}
|
|
107
143
|
/**
|
|
108
144
|
* Print a block string in the indented block form by adding a leading and
|
|
@@ -112,27 +148,48 @@ function getBlockStringIndentation(value) {
|
|
|
112
148
|
* @internal
|
|
113
149
|
*/
|
|
114
150
|
|
|
115
|
-
function printBlockString(value,
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
const
|
|
151
|
+
function printBlockString(value, options) {
|
|
152
|
+
const escapedValue = value.replace(/"""/g, '\\"""'); // Expand a block string's raw value into independent lines.
|
|
153
|
+
|
|
154
|
+
const lines = escapedValue.split(/\r\n|[\n\r]/g);
|
|
155
|
+
const isSingleLine = lines.length === 1; // If common indentation is found we can fix some of those cases by adding leading new line
|
|
156
|
+
|
|
157
|
+
const forceLeadingNewLine =
|
|
158
|
+
lines.length > 1 &&
|
|
159
|
+
lines
|
|
160
|
+
.slice(1)
|
|
161
|
+
.every(
|
|
162
|
+
(line) =>
|
|
163
|
+
line.length === 0 ||
|
|
164
|
+
(0, _characterClasses.isWhiteSpace)(line.charCodeAt(0)),
|
|
165
|
+
); // Trailing triple quotes just looks confusing but doesn't force trailing new line
|
|
166
|
+
|
|
167
|
+
const hasTrailingTripleQuotes = escapedValue.endsWith('\\"""'); // Trailing quote (single or double) or slash forces trailing new line
|
|
168
|
+
|
|
169
|
+
const hasTrailingQuote = value.endsWith('"') && !hasTrailingTripleQuotes;
|
|
119
170
|
const hasTrailingSlash = value.endsWith('\\');
|
|
171
|
+
const forceTrailingNewline = hasTrailingQuote || hasTrailingSlash;
|
|
120
172
|
const printAsMultipleLines =
|
|
121
|
-
!
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
173
|
+
!(options !== null && options !== void 0 && options.minimize) && // add leading and trailing new lines only if it improves readability
|
|
174
|
+
(!isSingleLine ||
|
|
175
|
+
value.length > 70 ||
|
|
176
|
+
forceTrailingNewline ||
|
|
177
|
+
forceLeadingNewLine ||
|
|
178
|
+
hasTrailingTripleQuotes);
|
|
125
179
|
let result = ''; // Format a multi-line block quote to account for leading space.
|
|
126
180
|
|
|
127
|
-
|
|
181
|
+
const skipLeadingNewLine =
|
|
182
|
+
isSingleLine && (0, _characterClasses.isWhiteSpace)(value.charCodeAt(0));
|
|
183
|
+
|
|
184
|
+
if ((printAsMultipleLines && !skipLeadingNewLine) || forceLeadingNewLine) {
|
|
128
185
|
result += '\n';
|
|
129
186
|
}
|
|
130
187
|
|
|
131
|
-
result +=
|
|
188
|
+
result += escapedValue;
|
|
132
189
|
|
|
133
|
-
if (printAsMultipleLines) {
|
|
190
|
+
if (printAsMultipleLines || forceTrailingNewline) {
|
|
134
191
|
result += '\n';
|
|
135
192
|
}
|
|
136
193
|
|
|
137
|
-
return '"""' + result
|
|
194
|
+
return '"""' + result + '"""';
|
|
138
195
|
}
|
package/language/blockString.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isWhiteSpace } from './characterClasses.mjs';
|
|
1
2
|
/**
|
|
2
3
|
* Produces the value of a block string from its parsed raw value, similar to
|
|
3
4
|
* CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
|
|
@@ -6,94 +7,126 @@
|
|
|
6
7
|
*
|
|
7
8
|
* @internal
|
|
8
9
|
*/
|
|
9
|
-
export function dedentBlockStringValue(rawString) {
|
|
10
|
-
// Expand a block string's raw value into independent lines.
|
|
11
|
-
const lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
export function dedentBlockStringLines(lines) {
|
|
12
|
+
var _firstNonEmptyLine2;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
} // Remove leading and trailing blank lines.
|
|
14
|
+
let commonIndent = Number.MAX_SAFE_INTEGER;
|
|
15
|
+
let firstNonEmptyLine = null;
|
|
16
|
+
let lastNonEmptyLine = -1;
|
|
20
17
|
|
|
21
|
-
let
|
|
18
|
+
for (let i = 0; i < lines.length; ++i) {
|
|
19
|
+
var _firstNonEmptyLine;
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
21
|
+
const line = lines[i];
|
|
22
|
+
const indent = leadingWhitespace(line);
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
if (indent === line.length) {
|
|
25
|
+
continue; // skip empty lines
|
|
26
|
+
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
firstNonEmptyLine =
|
|
29
|
+
(_firstNonEmptyLine = firstNonEmptyLine) !== null &&
|
|
30
|
+
_firstNonEmptyLine !== void 0
|
|
31
|
+
? _firstNonEmptyLine
|
|
32
|
+
: i;
|
|
33
|
+
lastNonEmptyLine = i;
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
if (i !== 0 && indent < commonIndent) {
|
|
36
|
+
commonIndent = indent;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return lines // Remove common indentation from all lines but first.
|
|
41
|
+
.map((line, i) => (i === 0 ? line : line.slice(commonIndent))) // Remove leading and trailing blank lines.
|
|
42
|
+
.slice(
|
|
43
|
+
(_firstNonEmptyLine2 = firstNonEmptyLine) !== null &&
|
|
44
|
+
_firstNonEmptyLine2 !== void 0
|
|
45
|
+
? _firstNonEmptyLine2
|
|
46
|
+
: 0,
|
|
47
|
+
lastNonEmptyLine + 1,
|
|
48
|
+
);
|
|
34
49
|
}
|
|
35
50
|
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
function leadingWhitespace(str) {
|
|
52
|
+
let i = 0;
|
|
53
|
+
|
|
54
|
+
while (i < str.length && isWhiteSpace(str.charCodeAt(i))) {
|
|
55
|
+
++i;
|
|
41
56
|
}
|
|
42
57
|
|
|
43
|
-
return
|
|
58
|
+
return i;
|
|
44
59
|
}
|
|
45
60
|
/**
|
|
46
61
|
* @internal
|
|
47
62
|
*/
|
|
48
63
|
|
|
49
|
-
export function
|
|
50
|
-
|
|
64
|
+
export function isPrintableAsBlockString(value) {
|
|
65
|
+
if (value === '') {
|
|
66
|
+
return true; // empty string is printable
|
|
67
|
+
}
|
|
51
68
|
|
|
52
|
-
let isFirstLine = true;
|
|
53
69
|
let isEmptyLine = true;
|
|
54
|
-
let
|
|
55
|
-
let
|
|
70
|
+
let hasIndent = false;
|
|
71
|
+
let hasCommonIndent = true;
|
|
72
|
+
let seenNonEmptyLine = false;
|
|
56
73
|
|
|
57
74
|
for (let i = 0; i < value.length; ++i) {
|
|
58
|
-
switch (value.
|
|
59
|
-
case
|
|
75
|
+
switch (value.codePointAt(i)) {
|
|
76
|
+
case 0x0000:
|
|
77
|
+
case 0x0001:
|
|
78
|
+
case 0x0002:
|
|
79
|
+
case 0x0003:
|
|
80
|
+
case 0x0004:
|
|
81
|
+
case 0x0005:
|
|
82
|
+
case 0x0006:
|
|
83
|
+
case 0x0007:
|
|
84
|
+
case 0x0008:
|
|
85
|
+
case 0x000b:
|
|
86
|
+
case 0x000c:
|
|
87
|
+
case 0x000e:
|
|
88
|
+
case 0x000f:
|
|
89
|
+
return false;
|
|
90
|
+
// Has non-printable characters
|
|
91
|
+
|
|
92
|
+
case 0x000d:
|
|
60
93
|
// \r
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// falls through
|
|
94
|
+
return false;
|
|
95
|
+
// Has \r or \r\n which will be replaced as \n
|
|
66
96
|
|
|
67
97
|
case 10:
|
|
68
98
|
// \n
|
|
69
|
-
|
|
99
|
+
if (isEmptyLine && !seenNonEmptyLine) {
|
|
100
|
+
return false; // Has leading new line
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
seenNonEmptyLine = true;
|
|
70
104
|
isEmptyLine = true;
|
|
71
|
-
|
|
105
|
+
hasIndent = false;
|
|
72
106
|
break;
|
|
73
107
|
|
|
74
108
|
case 9: // \t
|
|
75
109
|
|
|
76
110
|
case 32:
|
|
77
111
|
// <space>
|
|
78
|
-
|
|
112
|
+
hasIndent || (hasIndent = isEmptyLine);
|
|
79
113
|
break;
|
|
80
114
|
|
|
81
115
|
default:
|
|
82
|
-
|
|
83
|
-
isEmptyLine &&
|
|
84
|
-
!isFirstLine &&
|
|
85
|
-
(commonIndent === null || indent < commonIndent)
|
|
86
|
-
) {
|
|
87
|
-
commonIndent = indent;
|
|
88
|
-
}
|
|
89
|
-
|
|
116
|
+
hasCommonIndent && (hasCommonIndent = hasIndent);
|
|
90
117
|
isEmptyLine = false;
|
|
91
118
|
}
|
|
92
119
|
}
|
|
93
120
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
121
|
+
if (isEmptyLine) {
|
|
122
|
+
return false; // Has trailing empty lines
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (hasCommonIndent && seenNonEmptyLine) {
|
|
126
|
+
return false; // Has internal indent
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return true;
|
|
97
130
|
}
|
|
98
131
|
/**
|
|
99
132
|
* Print a block string in the indented block form by adding a leading and
|
|
@@ -103,27 +136,43 @@ export function getBlockStringIndentation(value) {
|
|
|
103
136
|
* @internal
|
|
104
137
|
*/
|
|
105
138
|
|
|
106
|
-
export function printBlockString(value,
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const
|
|
139
|
+
export function printBlockString(value, options) {
|
|
140
|
+
const escapedValue = value.replace(/"""/g, '\\"""'); // Expand a block string's raw value into independent lines.
|
|
141
|
+
|
|
142
|
+
const lines = escapedValue.split(/\r\n|[\n\r]/g);
|
|
143
|
+
const isSingleLine = lines.length === 1; // If common indentation is found we can fix some of those cases by adding leading new line
|
|
144
|
+
|
|
145
|
+
const forceLeadingNewLine =
|
|
146
|
+
lines.length > 1 &&
|
|
147
|
+
lines
|
|
148
|
+
.slice(1)
|
|
149
|
+
.every((line) => line.length === 0 || isWhiteSpace(line.charCodeAt(0))); // Trailing triple quotes just looks confusing but doesn't force trailing new line
|
|
150
|
+
|
|
151
|
+
const hasTrailingTripleQuotes = escapedValue.endsWith('\\"""'); // Trailing quote (single or double) or slash forces trailing new line
|
|
152
|
+
|
|
153
|
+
const hasTrailingQuote = value.endsWith('"') && !hasTrailingTripleQuotes;
|
|
110
154
|
const hasTrailingSlash = value.endsWith('\\');
|
|
155
|
+
const forceTrailingNewline = hasTrailingQuote || hasTrailingSlash;
|
|
111
156
|
const printAsMultipleLines =
|
|
112
|
-
!
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
157
|
+
!(options !== null && options !== void 0 && options.minimize) && // add leading and trailing new lines only if it improves readability
|
|
158
|
+
(!isSingleLine ||
|
|
159
|
+
value.length > 70 ||
|
|
160
|
+
forceTrailingNewline ||
|
|
161
|
+
forceLeadingNewLine ||
|
|
162
|
+
hasTrailingTripleQuotes);
|
|
116
163
|
let result = ''; // Format a multi-line block quote to account for leading space.
|
|
117
164
|
|
|
118
|
-
|
|
165
|
+
const skipLeadingNewLine = isSingleLine && isWhiteSpace(value.charCodeAt(0));
|
|
166
|
+
|
|
167
|
+
if ((printAsMultipleLines && !skipLeadingNewLine) || forceLeadingNewLine) {
|
|
119
168
|
result += '\n';
|
|
120
169
|
}
|
|
121
170
|
|
|
122
|
-
result +=
|
|
171
|
+
result += escapedValue;
|
|
123
172
|
|
|
124
|
-
if (printAsMultipleLines) {
|
|
173
|
+
if (printAsMultipleLines || forceTrailingNewline) {
|
|
125
174
|
result += '\n';
|
|
126
175
|
}
|
|
127
176
|
|
|
128
|
-
return '"""' + result
|
|
177
|
+
return '"""' + result + '"""';
|
|
129
178
|
}
|
|
@@ -7,7 +7,19 @@ exports.isDigit = isDigit;
|
|
|
7
7
|
exports.isLetter = isLetter;
|
|
8
8
|
exports.isNameContinue = isNameContinue;
|
|
9
9
|
exports.isNameStart = isNameStart;
|
|
10
|
+
exports.isWhiteSpace = isWhiteSpace;
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* ```
|
|
14
|
+
* WhiteSpace ::
|
|
15
|
+
* - "Horizontal Tab (U+0009)"
|
|
16
|
+
* - "Space (U+0020)"
|
|
17
|
+
* ```
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function isWhiteSpace(code) {
|
|
21
|
+
return code === 0x0009 || code === 0x0020;
|
|
22
|
+
}
|
|
11
23
|
/**
|
|
12
24
|
* ```
|
|
13
25
|
* Digit :: one of
|
|
@@ -15,6 +27,7 @@ exports.isNameStart = isNameStart;
|
|
|
15
27
|
* ```
|
|
16
28
|
* @internal
|
|
17
29
|
*/
|
|
30
|
+
|
|
18
31
|
function isDigit(code) {
|
|
19
32
|
return code >= 0x0030 && code <= 0x0039;
|
|
20
33
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```
|
|
3
|
+
* WhiteSpace ::
|
|
4
|
+
* - "Horizontal Tab (U+0009)"
|
|
5
|
+
* - "Space (U+0020)"
|
|
6
|
+
* ```
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export function isWhiteSpace(code) {
|
|
10
|
+
return code === 0x0009 || code === 0x0020;
|
|
11
|
+
}
|
|
1
12
|
/**
|
|
2
13
|
* ```
|
|
3
14
|
* Digit :: one of
|
|
@@ -5,6 +16,7 @@
|
|
|
5
16
|
* ```
|
|
6
17
|
* @internal
|
|
7
18
|
*/
|
|
19
|
+
|
|
8
20
|
export function isDigit(code) {
|
|
9
21
|
return code >= 0x0030 && code <= 0x0039;
|
|
10
22
|
}
|
package/language/index.d.ts
CHANGED
package/language/lexer.d.ts
CHANGED
package/language/lexer.js
CHANGED
|
@@ -10,12 +10,12 @@ var _syntaxError = require('../error/syntaxError.js');
|
|
|
10
10
|
|
|
11
11
|
var _ast = require('./ast.js');
|
|
12
12
|
|
|
13
|
-
var _tokenKind = require('./tokenKind.js');
|
|
14
|
-
|
|
15
13
|
var _blockString = require('./blockString.js');
|
|
16
14
|
|
|
17
15
|
var _characterClasses = require('./characterClasses.js');
|
|
18
16
|
|
|
17
|
+
var _tokenKind = require('./tokenKind.js');
|
|
18
|
+
|
|
19
19
|
/**
|
|
20
20
|
* Given a Source object, creates a Lexer for that source.
|
|
21
21
|
* A Lexer is a stateful stream generator in that every time
|
|
@@ -893,11 +893,11 @@ function readEscapedCharacter(lexer, position) {
|
|
|
893
893
|
function readBlockString(lexer, start) {
|
|
894
894
|
const body = lexer.source.body;
|
|
895
895
|
const bodyLength = body.length;
|
|
896
|
-
|
|
897
|
-
const startColumn = 1 + start - lexer.lineStart;
|
|
896
|
+
let lineStart = lexer.lineStart;
|
|
898
897
|
let position = start + 3;
|
|
899
898
|
let chunkStart = position;
|
|
900
|
-
let
|
|
899
|
+
let currentLine = '';
|
|
900
|
+
const blockLines = [];
|
|
901
901
|
|
|
902
902
|
while (position < bodyLength) {
|
|
903
903
|
const code = body.charCodeAt(position); // Closing Triple-Quote (""")
|
|
@@ -907,15 +907,18 @@ function readBlockString(lexer, start) {
|
|
|
907
907
|
body.charCodeAt(position + 1) === 0x0022 &&
|
|
908
908
|
body.charCodeAt(position + 2) === 0x0022
|
|
909
909
|
) {
|
|
910
|
-
|
|
911
|
-
|
|
910
|
+
currentLine += body.slice(chunkStart, position);
|
|
911
|
+
blockLines.push(currentLine);
|
|
912
|
+
const token = createToken(
|
|
913
|
+
lexer,
|
|
912
914
|
_tokenKind.TokenKind.BLOCK_STRING,
|
|
913
915
|
start,
|
|
914
|
-
position + 3,
|
|
915
|
-
|
|
916
|
-
startColumn,
|
|
917
|
-
(0, _blockString.dedentBlockStringValue)(rawValue),
|
|
916
|
+
position + 3, // Return a string of the lines joined with U+000A.
|
|
917
|
+
(0, _blockString.dedentBlockStringLines)(blockLines).join('\n'),
|
|
918
918
|
);
|
|
919
|
+
lexer.line += blockLines.length - 1;
|
|
920
|
+
lexer.lineStart = lineStart;
|
|
921
|
+
return token;
|
|
919
922
|
} // Escaped Triple-Quote (\""")
|
|
920
923
|
|
|
921
924
|
if (
|
|
@@ -924,21 +927,26 @@ function readBlockString(lexer, start) {
|
|
|
924
927
|
body.charCodeAt(position + 2) === 0x0022 &&
|
|
925
928
|
body.charCodeAt(position + 3) === 0x0022
|
|
926
929
|
) {
|
|
927
|
-
|
|
930
|
+
currentLine += body.slice(chunkStart, position);
|
|
931
|
+
chunkStart = position + 1; // skip only slash
|
|
932
|
+
|
|
928
933
|
position += 4;
|
|
929
|
-
chunkStart = position;
|
|
930
934
|
continue;
|
|
931
935
|
} // LineTerminator
|
|
932
936
|
|
|
933
937
|
if (code === 0x000a || code === 0x000d) {
|
|
938
|
+
currentLine += body.slice(chunkStart, position);
|
|
939
|
+
blockLines.push(currentLine);
|
|
940
|
+
|
|
934
941
|
if (code === 0x000d && body.charCodeAt(position + 1) === 0x000a) {
|
|
935
942
|
position += 2;
|
|
936
943
|
} else {
|
|
937
944
|
++position;
|
|
938
945
|
}
|
|
939
946
|
|
|
940
|
-
|
|
941
|
-
|
|
947
|
+
currentLine = '';
|
|
948
|
+
chunkStart = position;
|
|
949
|
+
lineStart = position;
|
|
942
950
|
continue;
|
|
943
951
|
} // SourceCharacter
|
|
944
952
|
|