summaryrefslogtreecommitdiff
path: root/includes/external/school/node_modules/graphql/language/printLocation.js.flow
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
committerMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
commit3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch)
tree75be5fba4368472fb11c8015aee026b2b9a71888 /includes/external/school/node_modules/graphql/language/printLocation.js.flow
parent8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff)
downloadpluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'includes/external/school/node_modules/graphql/language/printLocation.js.flow')
-rw-r--r--includes/external/school/node_modules/graphql/language/printLocation.js.flow88
1 files changed, 88 insertions, 0 deletions
diff --git a/includes/external/school/node_modules/graphql/language/printLocation.js.flow b/includes/external/school/node_modules/graphql/language/printLocation.js.flow
new file mode 100644
index 0000000..db3bf91
--- /dev/null
+++ b/includes/external/school/node_modules/graphql/language/printLocation.js.flow
@@ -0,0 +1,88 @@
+// @flow strict
+import type { Source } from './source';
+import type { Location } from './ast';
+import type { SourceLocation } from './location';
+import { getLocation } from './location';
+
+/**
+ * Render a helpful description of the location in the GraphQL Source document.
+ */
+export function printLocation(location: Location): string {
+ return printSourceLocation(
+ location.source,
+ getLocation(location.source, location.start),
+ );
+}
+
+/**
+ * Render a helpful description of the location in the GraphQL Source document.
+ */
+export function printSourceLocation(
+ source: Source,
+ sourceLocation: SourceLocation,
+): string {
+ const firstLineColumnOffset = source.locationOffset.column - 1;
+ const body = whitespace(firstLineColumnOffset) + source.body;
+
+ const lineIndex = sourceLocation.line - 1;
+ const lineOffset = source.locationOffset.line - 1;
+ const lineNum = sourceLocation.line + lineOffset;
+
+ const columnOffset = sourceLocation.line === 1 ? firstLineColumnOffset : 0;
+ const columnNum = sourceLocation.column + columnOffset;
+ const locationStr = `${source.name}:${lineNum}:${columnNum}\n`;
+
+ const lines = body.split(/\r\n|[\n\r]/g);
+ const locationLine = lines[lineIndex];
+
+ // Special case for minified documents
+ if (locationLine.length > 120) {
+ const subLineIndex = Math.floor(columnNum / 80);
+ const subLineColumnNum = columnNum % 80;
+ const subLines = [];
+ for (let i = 0; i < locationLine.length; i += 80) {
+ subLines.push(locationLine.slice(i, i + 80));
+ }
+
+ return (
+ locationStr +
+ printPrefixedLines([
+ [`${lineNum}`, subLines[0]],
+ ...subLines.slice(1, subLineIndex + 1).map((subLine) => ['', subLine]),
+ [' ', whitespace(subLineColumnNum - 1) + '^'],
+ ['', subLines[subLineIndex + 1]],
+ ])
+ );
+ }
+
+ return (
+ locationStr +
+ printPrefixedLines([
+ // Lines specified like this: ["prefix", "string"],
+ [`${lineNum - 1}`, lines[lineIndex - 1]],
+ [`${lineNum}`, locationLine],
+ ['', whitespace(columnNum - 1) + '^'],
+ [`${lineNum + 1}`, lines[lineIndex + 1]],
+ ])
+ );
+}
+
+function printPrefixedLines(lines: $ReadOnlyArray<[string, string]>): string {
+ const existingLines = lines.filter(([_, line]) => line !== undefined);
+
+ const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
+ return existingLines
+ .map(
+ ([prefix, line]) =>
+ leftPad(padLen, prefix) + (line ? ' | ' + line : ' |'),
+ )
+ .join('\n');
+}
+
+function whitespace(len: number): string {
+ return Array(len + 1).join(' ');
+}
+
+function leftPad(len: number, str: string): string {
+ return whitespace(len - str.length) + str;
+}