graphql 15.1.0 → 15.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +10 -12
  3. package/error/GraphQLError.js +5 -5
  4. package/error/GraphQLError.js.flow +5 -5
  5. package/error/GraphQLError.mjs +1 -1
  6. package/error/formatError.js +1 -1
  7. package/error/formatError.js.flow +2 -3
  8. package/error/index.js +4 -4
  9. package/error/index.js.flow +0 -1
  10. package/error/locatedError.d.ts +2 -2
  11. package/error/locatedError.js +10 -5
  12. package/error/locatedError.js.flow +11 -5
  13. package/error/locatedError.mjs +6 -4
  14. package/error/syntaxError.js +1 -1
  15. package/error/syntaxError.js.flow +1 -2
  16. package/execution/execute.d.ts +24 -16
  17. package/execution/execute.js +123 -105
  18. package/execution/execute.js.flow +169 -153
  19. package/execution/execute.mjs +101 -82
  20. package/execution/index.d.ts +2 -0
  21. package/execution/index.js +9 -3
  22. package/execution/index.js.flow +12 -3
  23. package/execution/index.mjs +1 -1
  24. package/execution/values.js +11 -11
  25. package/execution/values.js.flow +10 -14
  26. package/graphql.js +5 -5
  27. package/graphql.js.flow +9 -9
  28. package/index.d.ts +19 -1
  29. package/index.js +27 -9
  30. package/index.js.flow +10 -3
  31. package/index.mjs +4 -3
  32. package/jsutils/ObjMap.js.flow +0 -1
  33. package/jsutils/Path.d.ts +6 -1
  34. package/jsutils/Path.js +3 -2
  35. package/jsutils/Path.js.flow +3 -2
  36. package/jsutils/Path.mjs +3 -2
  37. package/jsutils/PromiseOrValue.js.flow +0 -1
  38. package/jsutils/defineInspect.js +2 -2
  39. package/jsutils/defineInspect.js.flow +0 -1
  40. package/jsutils/devAssert.js.flow +0 -1
  41. package/jsutils/didYouMean.js.flow +0 -1
  42. package/jsutils/identityFunc.js.flow +0 -1
  43. package/jsutils/inspect.js +1 -2
  44. package/jsutils/inspect.js.flow +10 -8
  45. package/jsutils/inspect.mjs +1 -1
  46. package/jsutils/instanceOf.js.flow +2 -3
  47. package/jsutils/invariant.js.flow +0 -1
  48. package/jsutils/isAsyncIterable.js +19 -0
  49. package/jsutils/isAsyncIterable.js.flow +18 -0
  50. package/jsutils/isAsyncIterable.mjs +16 -0
  51. package/jsutils/isCollection.js +1 -1
  52. package/jsutils/isCollection.js.flow +0 -1
  53. package/jsutils/isObjectLike.js.flow +0 -1
  54. package/jsutils/isPromise.js.flow +0 -1
  55. package/jsutils/keyMap.js.flow +1 -2
  56. package/jsutils/keyValMap.js.flow +1 -2
  57. package/jsutils/mapValue.js +1 -1
  58. package/jsutils/mapValue.js.flow +1 -2
  59. package/jsutils/memoize3.js +2 -5
  60. package/jsutils/memoize3.js.flow +2 -5
  61. package/jsutils/memoize3.mjs +2 -5
  62. package/jsutils/nodejsCustomInspectSymbol.js.flow +0 -1
  63. package/jsutils/printPathArray.js.flow +0 -1
  64. package/jsutils/promiseForObject.js.flow +1 -2
  65. package/jsutils/promiseReduce.js +1 -1
  66. package/jsutils/promiseReduce.js.flow +1 -1
  67. package/jsutils/promiseReduce.mjs +1 -1
  68. package/jsutils/suggestionList.js.flow +1 -2
  69. package/jsutils/toObjMap.js +1 -1
  70. package/jsutils/toObjMap.js.flow +5 -6
  71. package/language/ast.js +1 -1
  72. package/language/ast.js.flow +2 -3
  73. package/language/blockString.d.ts +1 -1
  74. package/language/blockString.js +53 -32
  75. package/language/blockString.js.flow +49 -34
  76. package/language/blockString.mjs +54 -33
  77. package/language/directiveLocation.js.flow +0 -1
  78. package/language/experimentalOnlineParser/grammar.d.ts +1006 -0
  79. package/language/experimentalOnlineParser/grammar.js +987 -0
  80. package/language/experimentalOnlineParser/grammar.js.flow +1000 -0
  81. package/language/experimentalOnlineParser/grammar.mjs +980 -0
  82. package/language/experimentalOnlineParser/index.d.ts +6 -0
  83. package/language/experimentalOnlineParser/index.js +31 -0
  84. package/language/experimentalOnlineParser/index.js.flow +7 -0
  85. package/language/experimentalOnlineParser/index.mjs +1 -0
  86. package/language/experimentalOnlineParser/onlineParser.d.ts +125 -0
  87. package/language/experimentalOnlineParser/onlineParser.js +604 -0
  88. package/language/experimentalOnlineParser/onlineParser.js.flow +723 -0
  89. package/language/experimentalOnlineParser/onlineParser.mjs +587 -0
  90. package/language/index.js +12 -12
  91. package/language/index.js.flow +0 -1
  92. package/language/kinds.js.flow +0 -1
  93. package/language/lexer.js +242 -183
  94. package/language/lexer.js.flow +191 -186
  95. package/language/lexer.mjs +239 -180
  96. package/language/location.js.flow +1 -2
  97. package/language/parser.js +73 -68
  98. package/language/parser.js.flow +112 -106
  99. package/language/parser.mjs +66 -62
  100. package/language/predicates.js +1 -1
  101. package/language/predicates.js.flow +1 -2
  102. package/language/printLocation.js +1 -1
  103. package/language/printLocation.js.flow +4 -4
  104. package/language/printer.js +20 -13
  105. package/language/printer.js.flow +27 -25
  106. package/language/printer.mjs +18 -11
  107. package/language/source.d.ts +12 -6
  108. package/language/source.js +25 -9
  109. package/language/source.js.flow +25 -8
  110. package/language/source.mjs +19 -7
  111. package/language/tokenKind.js.flow +0 -1
  112. package/language/visitor.d.ts +3 -3
  113. package/language/visitor.js +5 -5
  114. package/language/visitor.js.flow +5 -5
  115. package/language/visitor.mjs +3 -3
  116. package/package.json +1 -1
  117. package/polyfills/arrayFrom.js +2 -2
  118. package/polyfills/arrayFrom.js.flow +1 -2
  119. package/polyfills/arrayFrom.mjs +1 -1
  120. package/polyfills/find.js +1 -1
  121. package/polyfills/find.js.flow +1 -2
  122. package/polyfills/find.mjs +1 -1
  123. package/polyfills/isFinite.js +1 -1
  124. package/polyfills/isFinite.js.flow +1 -2
  125. package/polyfills/isFinite.mjs +1 -1
  126. package/polyfills/isInteger.js +1 -1
  127. package/polyfills/isInteger.js.flow +1 -2
  128. package/polyfills/isInteger.mjs +1 -1
  129. package/polyfills/objectEntries.js +1 -1
  130. package/polyfills/objectEntries.js.flow +2 -3
  131. package/polyfills/objectEntries.mjs +1 -1
  132. package/polyfills/objectValues.js +1 -1
  133. package/polyfills/objectValues.js.flow +2 -3
  134. package/polyfills/objectValues.mjs +1 -1
  135. package/polyfills/symbols.js +3 -5
  136. package/polyfills/symbols.js.flow +9 -6
  137. package/polyfills/symbols.mjs +3 -5
  138. package/subscription/index.js +1 -1
  139. package/subscription/index.js.flow +0 -1
  140. package/subscription/mapAsyncIterator.js +2 -2
  141. package/subscription/mapAsyncIterator.js.flow +9 -10
  142. package/subscription/mapAsyncIterator.mjs +1 -1
  143. package/subscription/subscribe.js +61 -73
  144. package/subscription/subscribe.js.flow +74 -88
  145. package/subscription/subscribe.mjs +53 -65
  146. package/type/definition.d.ts +181 -31
  147. package/type/definition.js +37 -32
  148. package/type/definition.js.flow +66 -51
  149. package/type/definition.mjs +20 -18
  150. package/type/directives.d.ts +17 -3
  151. package/type/directives.js +17 -16
  152. package/type/directives.js.flow +20 -21
  153. package/type/directives.mjs +6 -5
  154. package/type/index.d.ts +12 -0
  155. package/type/index.js +6 -6
  156. package/type/index.js.flow +0 -1
  157. package/type/introspection.js +86 -68
  158. package/type/introspection.js.flow +85 -54
  159. package/type/introspection.mjs +79 -61
  160. package/type/scalars.js +9 -9
  161. package/type/scalars.js.flow +3 -3
  162. package/type/scalars.mjs +1 -1
  163. package/type/schema.d.ts +17 -4
  164. package/type/schema.js +13 -13
  165. package/type/schema.js.flow +18 -16
  166. package/type/schema.mjs +1 -1
  167. package/type/validate.js +52 -19
  168. package/type/validate.js.flow +67 -18
  169. package/type/validate.mjs +44 -10
  170. package/utilities/TypeInfo.js +7 -7
  171. package/utilities/TypeInfo.js.flow +16 -18
  172. package/utilities/TypeInfo.mjs +1 -1
  173. package/utilities/assertValidName.js +2 -2
  174. package/utilities/assertValidName.js.flow +0 -1
  175. package/utilities/astFromValue.js +10 -10
  176. package/utilities/astFromValue.js.flow +2 -3
  177. package/utilities/buildASTSchema.js +17 -27
  178. package/utilities/buildASTSchema.js.flow +11 -28
  179. package/utilities/buildASTSchema.mjs +11 -21
  180. package/utilities/buildClientSchema.js +14 -14
  181. package/utilities/buildClientSchema.js.flow +41 -29
  182. package/utilities/buildClientSchema.mjs +5 -5
  183. package/utilities/coerceInputValue.js +14 -14
  184. package/utilities/coerceInputValue.js.flow +7 -6
  185. package/utilities/coerceInputValue.mjs +2 -2
  186. package/utilities/concatAST.js +9 -8
  187. package/utilities/concatAST.js.flow +9 -9
  188. package/utilities/concatAST.mjs +9 -6
  189. package/utilities/extendSchema.js +26 -19
  190. package/utilities/extendSchema.js.flow +58 -45
  191. package/utilities/extendSchema.mjs +9 -2
  192. package/utilities/findBreakingChanges.js +9 -9
  193. package/utilities/findBreakingChanges.js.flow +12 -11
  194. package/utilities/findDeprecatedUsages.d.ts +9 -1
  195. package/utilities/findDeprecatedUsages.js +11 -27
  196. package/utilities/findDeprecatedUsages.js.flow +15 -44
  197. package/utilities/findDeprecatedUsages.mjs +11 -25
  198. package/utilities/getIntrospectionQuery.js.flow +2 -3
  199. package/utilities/getOperationAST.js +1 -1
  200. package/utilities/getOperationAST.js.flow +1 -5
  201. package/utilities/getOperationAST.mjs +1 -1
  202. package/utilities/getOperationRootType.js +1 -1
  203. package/utilities/getOperationRootType.js.flow +5 -6
  204. package/utilities/index.d.ts +4 -1
  205. package/utilities/index.js +22 -22
  206. package/utilities/index.js.flow +1 -2
  207. package/utilities/index.mjs +1 -1
  208. package/utilities/introspectionFromSchema.js +6 -8
  209. package/utilities/introspectionFromSchema.js.flow +10 -10
  210. package/utilities/introspectionFromSchema.mjs +3 -4
  211. package/utilities/lexicographicSortSchema.js +10 -8
  212. package/utilities/lexicographicSortSchema.js.flow +19 -12
  213. package/utilities/lexicographicSortSchema.mjs +3 -1
  214. package/utilities/printSchema.js +15 -16
  215. package/utilities/printSchema.js.flow +34 -25
  216. package/utilities/printSchema.mjs +6 -7
  217. package/utilities/separateOperations.js +2 -2
  218. package/utilities/separateOperations.js.flow +2 -6
  219. package/utilities/separateOperations.mjs +1 -1
  220. package/utilities/stripIgnoredCharacters.js +6 -16
  221. package/utilities/stripIgnoredCharacters.js.flow +4 -13
  222. package/utilities/stripIgnoredCharacters.mjs +3 -10
  223. package/utilities/typeComparators.js +1 -1
  224. package/utilities/typeComparators.js.flow +2 -4
  225. package/utilities/typeFromAST.js +6 -6
  226. package/utilities/typeFromAST.js.flow +11 -14
  227. package/utilities/typeFromAST.mjs +2 -2
  228. package/utilities/typedQueryDocumentNode.d.ts +20 -0
  229. package/utilities/valueFromAST.js +6 -6
  230. package/utilities/valueFromAST.js.flow +7 -5
  231. package/utilities/valueFromASTUntyped.js +4 -4
  232. package/utilities/valueFromASTUntyped.js.flow +2 -3
  233. package/validation/ValidationContext.d.ts +3 -0
  234. package/validation/ValidationContext.js +7 -3
  235. package/validation/ValidationContext.js.flow +28 -22
  236. package/validation/ValidationContext.mjs +4 -0
  237. package/validation/index.d.ts +4 -0
  238. package/validation/index.js +52 -36
  239. package/validation/index.js.flow +4 -1
  240. package/validation/index.mjs +4 -1
  241. package/validation/rules/ExecutableDefinitions.js +1 -1
  242. package/validation/rules/ExecutableDefinitions.js.flow +0 -1
  243. package/validation/rules/ExecutableDefinitionsRule.js +3 -3
  244. package/validation/rules/ExecutableDefinitionsRule.js.flow +2 -3
  245. package/validation/rules/FieldsOnCorrectTypeRule.js +5 -5
  246. package/validation/rules/FieldsOnCorrectTypeRule.js.flow +9 -8
  247. package/validation/rules/FragmentsOnCompositeTypesRule.js +4 -4
  248. package/validation/rules/FragmentsOnCompositeTypesRule.js.flow +2 -3
  249. package/validation/rules/KnownArgumentNamesRule.js +5 -5
  250. package/validation/rules/KnownArgumentNamesRule.js.flow +5 -5
  251. package/validation/rules/KnownDirectivesRule.js +6 -6
  252. package/validation/rules/KnownDirectivesRule.js.flow +10 -11
  253. package/validation/rules/KnownFragmentNamesRule.js +1 -1
  254. package/validation/rules/KnownFragmentNamesRule.js.flow +3 -3
  255. package/validation/rules/KnownTypeNamesRule.js +12 -10
  256. package/validation/rules/KnownTypeNamesRule.js.flow +14 -11
  257. package/validation/rules/KnownTypeNamesRule.mjs +6 -5
  258. package/validation/rules/LoneAnonymousOperationRule.js +2 -2
  259. package/validation/rules/LoneAnonymousOperationRule.js.flow +2 -3
  260. package/validation/rules/LoneSchemaDefinition.js +1 -1
  261. package/validation/rules/LoneSchemaDefinition.js.flow +0 -1
  262. package/validation/rules/LoneSchemaDefinitionRule.js +1 -1
  263. package/validation/rules/LoneSchemaDefinitionRule.js.flow +2 -3
  264. package/validation/rules/NoFragmentCyclesRule.js +1 -1
  265. package/validation/rules/NoFragmentCyclesRule.js.flow +4 -5
  266. package/validation/rules/NoUndefinedVariablesRule.js +1 -1
  267. package/validation/rules/NoUndefinedVariablesRule.js.flow +3 -3
  268. package/validation/rules/NoUnusedFragmentsRule.js +1 -1
  269. package/validation/rules/NoUnusedFragmentsRule.js.flow +3 -3
  270. package/validation/rules/NoUnusedVariablesRule.js +1 -1
  271. package/validation/rules/NoUnusedVariablesRule.js.flow +3 -3
  272. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +20 -20
  273. package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +29 -27
  274. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +12 -12
  275. package/validation/rules/PossibleFragmentSpreadsRule.js +5 -5
  276. package/validation/rules/PossibleFragmentSpreadsRule.js.flow +7 -4
  277. package/validation/rules/PossibleTypeExtensions.js +1 -1
  278. package/validation/rules/PossibleTypeExtensions.js.flow +0 -1
  279. package/validation/rules/PossibleTypeExtensionsRule.js +8 -8
  280. package/validation/rules/PossibleTypeExtensionsRule.js.flow +8 -6
  281. package/validation/rules/ProvidedRequiredArgumentsRule.js +7 -7
  282. package/validation/rules/ProvidedRequiredArgumentsRule.js.flow +7 -6
  283. package/validation/rules/ScalarLeafsRule.js +3 -3
  284. package/validation/rules/ScalarLeafsRule.js.flow +3 -4
  285. package/validation/rules/SingleFieldSubscriptionsRule.js +1 -1
  286. package/validation/rules/SingleFieldSubscriptionsRule.js.flow +3 -4
  287. package/validation/rules/UniqueArgumentNamesRule.js +1 -1
  288. package/validation/rules/UniqueArgumentNamesRule.js.flow +2 -3
  289. package/validation/rules/UniqueDirectiveNames.js +1 -1
  290. package/validation/rules/UniqueDirectiveNames.js.flow +0 -1
  291. package/validation/rules/UniqueDirectiveNamesRule.js +1 -1
  292. package/validation/rules/UniqueDirectiveNamesRule.js.flow +2 -3
  293. package/validation/rules/UniqueDirectivesPerLocationRule.js +4 -4
  294. package/validation/rules/UniqueDirectivesPerLocationRule.js.flow +4 -5
  295. package/validation/rules/UniqueEnumValueNames.js +1 -1
  296. package/validation/rules/UniqueEnumValueNames.js.flow +0 -1
  297. package/validation/rules/UniqueEnumValueNamesRule.js +2 -2
  298. package/validation/rules/UniqueEnumValueNamesRule.js.flow +11 -4
  299. package/validation/rules/UniqueFieldDefinitionNames.js +1 -1
  300. package/validation/rules/UniqueFieldDefinitionNames.js.flow +0 -1
  301. package/validation/rules/UniqueFieldDefinitionNamesRule.js +3 -3
  302. package/validation/rules/UniqueFieldDefinitionNamesRule.js.flow +17 -6
  303. package/validation/rules/UniqueFieldDefinitionNamesRule.mjs +1 -1
  304. package/validation/rules/UniqueFragmentNamesRule.js +1 -1
  305. package/validation/rules/UniqueFragmentNamesRule.js.flow +3 -3
  306. package/validation/rules/UniqueInputFieldNamesRule.js +1 -1
  307. package/validation/rules/UniqueInputFieldNamesRule.js.flow +3 -3
  308. package/validation/rules/UniqueOperationNamesRule.js +1 -1
  309. package/validation/rules/UniqueOperationNamesRule.js.flow +3 -3
  310. package/validation/rules/UniqueOperationTypes.js +1 -1
  311. package/validation/rules/UniqueOperationTypes.js.flow +0 -1
  312. package/validation/rules/UniqueOperationTypesRule.js +1 -1
  313. package/validation/rules/UniqueOperationTypesRule.js.flow +10 -4
  314. package/validation/rules/UniqueTypeNames.js +1 -1
  315. package/validation/rules/UniqueTypeNames.js.flow +0 -1
  316. package/validation/rules/UniqueTypeNamesRule.js +1 -1
  317. package/validation/rules/UniqueTypeNamesRule.js.flow +3 -4
  318. package/validation/rules/UniqueVariableNamesRule.js +1 -1
  319. package/validation/rules/UniqueVariableNamesRule.js.flow +3 -4
  320. package/validation/rules/ValuesOfCorrectTypeRule.js +8 -8
  321. package/validation/rules/ValuesOfCorrectTypeRule.js.flow +3 -4
  322. package/validation/rules/VariablesAreInputTypesRule.js +4 -4
  323. package/validation/rules/VariablesAreInputTypesRule.js.flow +3 -4
  324. package/validation/rules/VariablesInAllowedPositionRule.js +6 -6
  325. package/validation/rules/VariablesInAllowedPositionRule.js.flow +6 -6
  326. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +14 -0
  327. package/validation/rules/custom/NoDeprecatedCustomRule.js +79 -0
  328. package/validation/rules/custom/NoDeprecatedCustomRule.js.flow +94 -0
  329. package/validation/rules/custom/NoDeprecatedCustomRule.mjs +68 -0
  330. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +16 -0
  331. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js +34 -0
  332. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.flow +38 -0
  333. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs +25 -0
  334. package/validation/specifiedRules.js +33 -33
  335. package/validation/specifiedRules.js.flow +0 -1
  336. package/validation/validate.js +7 -7
  337. package/validation/validate.js.flow +4 -9
  338. package/version.js +2 -2
  339. package/version.js.flow +2 -3
  340. package/version.mjs +2 -2
  341. package/polyfills/flatMap.js +0 -30
  342. package/polyfills/flatMap.js.flow +0 -28
  343. package/polyfills/flatMap.mjs +0 -23
@@ -9,7 +9,7 @@ export function dedentBlockStringValue(rawString: string): string;
9
9
  /**
10
10
  * @internal
11
11
  */
12
- export function getBlockStringIndentation(lines: ReadonlyArray<string>): number;
12
+ export function getBlockStringIndentation(body: string): number;
13
13
 
14
14
  /**
15
15
  * Print a block string in the indented block form by adding a leading and
@@ -19,7 +19,7 @@ function dedentBlockStringValue(rawString) {
19
19
  // Expand a block string's raw value into independent lines.
20
20
  var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
21
21
 
22
- var commonIndent = getBlockStringIndentation(lines);
22
+ var commonIndent = getBlockStringIndentation(rawString);
23
23
 
24
24
  if (commonIndent !== 0) {
25
25
  for (var i = 1; i < lines.length; i++) {
@@ -28,57 +28,78 @@ function dedentBlockStringValue(rawString) {
28
28
  } // Remove leading and trailing blank lines.
29
29
 
30
30
 
31
- while (lines.length > 0 && isBlank(lines[0])) {
32
- lines.shift();
31
+ var startLine = 0;
32
+
33
+ while (startLine < lines.length && isBlank(lines[startLine])) {
34
+ ++startLine;
33
35
  }
34
36
 
35
- while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
36
- lines.pop();
37
+ var endLine = lines.length;
38
+
39
+ while (endLine > startLine && isBlank(lines[endLine - 1])) {
40
+ --endLine;
37
41
  } // Return a string of the lines joined with U+000A.
38
42
 
39
43
 
40
- return lines.join('\n');
44
+ return lines.slice(startLine, endLine).join('\n');
45
+ }
46
+
47
+ function isBlank(str) {
48
+ for (var i = 0; i < str.length; ++i) {
49
+ if (str[i] !== ' ' && str[i] !== '\t') {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ return true;
41
55
  }
42
56
  /**
43
57
  * @internal
44
58
  */
45
59
 
46
60
 
47
- function getBlockStringIndentation(lines) {
48
- var commonIndent = null;
61
+ function getBlockStringIndentation(value) {
62
+ var _commonIndent;
49
63
 
50
- for (var i = 1; i < lines.length; i++) {
51
- var line = lines[i];
52
- var indent = leadingWhitespace(line);
64
+ var isFirstLine = true;
65
+ var isEmptyLine = true;
66
+ var indent = 0;
67
+ var commonIndent = null;
53
68
 
54
- if (indent === line.length) {
55
- continue; // skip empty lines
56
- }
69
+ for (var i = 0; i < value.length; ++i) {
70
+ switch (value.charCodeAt(i)) {
71
+ case 13:
72
+ // \r
73
+ if (value.charCodeAt(i + 1) === 10) {
74
+ ++i; // skip \r\n as one symbol
75
+ }
76
+
77
+ // falls through
78
+
79
+ case 10:
80
+ // \n
81
+ isFirstLine = false;
82
+ isEmptyLine = true;
83
+ indent = 0;
84
+ break;
57
85
 
58
- if (commonIndent === null || indent < commonIndent) {
59
- commonIndent = indent;
86
+ case 9: // \t
60
87
 
61
- if (commonIndent === 0) {
88
+ case 32:
89
+ // <space>
90
+ ++indent;
62
91
  break;
63
- }
64
- }
65
- }
66
-
67
- return commonIndent === null ? 0 : commonIndent;
68
- }
69
92
 
70
- function leadingWhitespace(str) {
71
- var i = 0;
93
+ default:
94
+ if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {
95
+ commonIndent = indent;
96
+ }
72
97
 
73
- while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
74
- i++;
98
+ isEmptyLine = false;
99
+ }
75
100
  }
76
101
 
77
- return i;
78
- }
79
-
80
- function isBlank(str) {
81
- return leadingWhitespace(str) === str.length;
102
+ return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
82
103
  }
83
104
  /**
84
105
  * Print a block string in the indented block form by adding a leading and
@@ -1,5 +1,4 @@
1
1
  // @flow strict
2
-
3
2
  /**
4
3
  * Produces the value of a block string from its parsed raw value, similar to
5
4
  * CoffeeScript's block string, Python's docstring trim or Ruby's strip_heredoc.
@@ -13,7 +12,7 @@ export function dedentBlockStringValue(rawString: string): string {
13
12
  const lines = rawString.split(/\r\n|[\n\r]/g);
14
13
 
15
14
  // Remove common indentation from all lines but first.
16
- const commonIndent = getBlockStringIndentation(lines);
15
+ const commonIndent = getBlockStringIndentation(rawString);
17
16
 
18
17
  if (commonIndent !== 0) {
19
18
  for (let i = 1; i < lines.length; i++) {
@@ -22,52 +21,68 @@ export function dedentBlockStringValue(rawString: string): string {
22
21
  }
23
22
 
24
23
  // Remove leading and trailing blank lines.
25
- while (lines.length > 0 && isBlank(lines[0])) {
26
- lines.shift();
24
+ let startLine = 0;
25
+ while (startLine < lines.length && isBlank(lines[startLine])) {
26
+ ++startLine;
27
27
  }
28
- while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
29
- lines.pop();
28
+
29
+ let endLine = lines.length;
30
+ while (endLine > startLine && isBlank(lines[endLine - 1])) {
31
+ --endLine;
30
32
  }
31
33
 
32
34
  // Return a string of the lines joined with U+000A.
33
- return lines.join('\n');
35
+ return lines.slice(startLine, endLine).join('\n');
36
+ }
37
+
38
+ function isBlank(str: string): boolean {
39
+ for (let i = 0; i < str.length; ++i) {
40
+ if (str[i] !== ' ' && str[i] !== '\t') {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ return true;
34
46
  }
47
+
35
48
  /**
36
49
  * @internal
37
50
  */
38
- export function getBlockStringIndentation(
39
- lines: $ReadOnlyArray<string>,
40
- ): number {
51
+ export function getBlockStringIndentation(value: string): number {
52
+ let isFirstLine = true;
53
+ let isEmptyLine = true;
54
+ let indent = 0;
41
55
  let commonIndent = null;
42
56
 
43
- for (let i = 1; i < lines.length; i++) {
44
- const line = lines[i];
45
- const indent = leadingWhitespace(line);
46
- if (indent === line.length) {
47
- continue; // skip empty lines
48
- }
49
-
50
- if (commonIndent === null || indent < commonIndent) {
51
- commonIndent = indent;
52
- if (commonIndent === 0) {
57
+ for (let i = 0; i < value.length; ++i) {
58
+ switch (value.charCodeAt(i)) {
59
+ case 13: // \r
60
+ if (value.charCodeAt(i + 1) === 10) {
61
+ ++i; // skip \r\n as one symbol
62
+ }
63
+ // falls through
64
+ case 10: // \n
65
+ isFirstLine = false;
66
+ isEmptyLine = true;
67
+ indent = 0;
53
68
  break;
54
- }
69
+ case 9: // \t
70
+ case 32: // <space>
71
+ ++indent;
72
+ break;
73
+ default:
74
+ if (
75
+ isEmptyLine &&
76
+ !isFirstLine &&
77
+ (commonIndent === null || indent < commonIndent)
78
+ ) {
79
+ commonIndent = indent;
80
+ }
81
+ isEmptyLine = false;
55
82
  }
56
83
  }
57
84
 
58
- return commonIndent === null ? 0 : commonIndent;
59
- }
60
-
61
- function leadingWhitespace(str) {
62
- let i = 0;
63
- while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
64
- i++;
65
- }
66
- return i;
67
- }
68
-
69
- function isBlank(str) {
70
- return leadingWhitespace(str) === str.length;
85
+ return commonIndent ?? 0;
71
86
  }
72
87
 
73
88
  /**
@@ -10,7 +10,7 @@ export function dedentBlockStringValue(rawString) {
10
10
  // Expand a block string's raw value into independent lines.
11
11
  var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
12
12
 
13
- var commonIndent = getBlockStringIndentation(lines);
13
+ var commonIndent = getBlockStringIndentation(rawString);
14
14
 
15
15
  if (commonIndent !== 0) {
16
16
  for (var i = 1; i < lines.length; i++) {
@@ -19,56 +19,78 @@ export function dedentBlockStringValue(rawString) {
19
19
  } // Remove leading and trailing blank lines.
20
20
 
21
21
 
22
- while (lines.length > 0 && isBlank(lines[0])) {
23
- lines.shift();
22
+ var startLine = 0;
23
+
24
+ while (startLine < lines.length && isBlank(lines[startLine])) {
25
+ ++startLine;
24
26
  }
25
27
 
26
- while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
27
- lines.pop();
28
+ var endLine = lines.length;
29
+
30
+ while (endLine > startLine && isBlank(lines[endLine - 1])) {
31
+ --endLine;
28
32
  } // Return a string of the lines joined with U+000A.
29
33
 
30
34
 
31
- return lines.join('\n');
35
+ return lines.slice(startLine, endLine).join('\n');
36
+ }
37
+
38
+ function isBlank(str) {
39
+ for (var i = 0; i < str.length; ++i) {
40
+ if (str[i] !== ' ' && str[i] !== '\t') {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ return true;
32
46
  }
33
47
  /**
34
48
  * @internal
35
49
  */
36
50
 
37
- export function getBlockStringIndentation(lines) {
38
- var commonIndent = null;
39
51
 
40
- for (var i = 1; i < lines.length; i++) {
41
- var line = lines[i];
42
- var indent = leadingWhitespace(line);
43
-
44
- if (indent === line.length) {
45
- continue; // skip empty lines
46
- }
52
+ export function getBlockStringIndentation(value) {
53
+ var _commonIndent;
47
54
 
48
- if (commonIndent === null || indent < commonIndent) {
49
- commonIndent = indent;
55
+ var isFirstLine = true;
56
+ var isEmptyLine = true;
57
+ var indent = 0;
58
+ var commonIndent = null;
50
59
 
51
- if (commonIndent === 0) {
60
+ for (var i = 0; i < value.length; ++i) {
61
+ switch (value.charCodeAt(i)) {
62
+ case 13:
63
+ // \r
64
+ if (value.charCodeAt(i + 1) === 10) {
65
+ ++i; // skip \r\n as one symbol
66
+ }
67
+
68
+ // falls through
69
+
70
+ case 10:
71
+ // \n
72
+ isFirstLine = false;
73
+ isEmptyLine = true;
74
+ indent = 0;
52
75
  break;
53
- }
54
- }
55
- }
56
76
 
57
- return commonIndent === null ? 0 : commonIndent;
58
- }
77
+ case 9: // \t
59
78
 
60
- function leadingWhitespace(str) {
61
- var i = 0;
79
+ case 32:
80
+ // <space>
81
+ ++indent;
82
+ break;
62
83
 
63
- while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
64
- i++;
65
- }
84
+ default:
85
+ if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {
86
+ commonIndent = indent;
87
+ }
66
88
 
67
- return i;
68
- }
89
+ isEmptyLine = false;
90
+ }
91
+ }
69
92
 
70
- function isBlank(str) {
71
- return leadingWhitespace(str) === str.length;
93
+ return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
72
94
  }
73
95
  /**
74
96
  * Print a block string in the indented block form by adding a leading and
@@ -78,7 +100,6 @@ function isBlank(str) {
78
100
  * @internal
79
101
  */
80
102
 
81
-
82
103
  export function printBlockString(value) {
83
104
  var indentation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
84
105
  var preferMultipleLines = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -1,5 +1,4 @@
1
1
  // @flow strict
2
-
3
2
  /**
4
3
  * The set of allowed directive location values.
5
4
  */