Mirror: The spec-compliant minimum of client-side GraphQL.

fix: Handle unexpected EOF for comments (end of input) (#62)

* Add extra EOF test cases

* Fix unexpected EOF in comments

* Add changeset

* Apply lints

Changed files
+15 -1
.changeset
src
+5
.changeset/mighty-frogs-push.md
···
+
---
+
"@0no-co/graphql.web": patch
+
---
+
+
Handle trailing comment ending in EOF (end of input)
+8
src/__tests__/parser.test.ts
···
expect(doc).toMatchSnapshot();
});
+
it('parses unexpected EOF', () => {
+
expect(() => parse('#')).toThrow();
+
expect(() => parse(' ')).toThrow();
+
expect(() => parse('q($')).toThrow();
+
expect(() => parse('{x{')).toThrow();
+
expect(() => parse('#\n')).toThrow();
+
});
+
it('parses basic documents', () => {
expect(() => parse('{')).toThrow();
expect(() => parse('{}x ')).toThrow();
+2 -1
src/parser.ts
···
char === 65279 /*'\ufeff'*/;
char = input.charCodeAt(idx++) | 0
) {
-
if (char === 35 /*'#'*/) while ((char = input.charCodeAt(idx++)) !== 10 && char !== 13);
+
if (char === 35 /*'#'*/)
+
while ((char = input.charCodeAt(idx++) | 0) && char !== 10 && char !== 13);
}
idx--;
}