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

fix: Fix Safari 10–13 sticky regular expression quirks (#15)

* Fix constRe match for Safari

* Add quirk fix for floatPartRe

* Update operationDefinitionRe just in case

* Update character classes for names to be more precise

* Add changeset

Changed files
+17 -5
.changeset
src
+5
.changeset/curvy-geese-hope.md
···
+
---
+
'@0no-co/graphql.web': patch
+
---
+
+
Fix browser quirk occurring in Safari 10–13 causing sticky regular expressions in the parser to match when they shouldn't / match too eagerly.
+12 -5
src/parser.ts
···
idx--;
}
-
const nameRe = /[_\w][_\d\w]*/y;
+
const nameRe = /[_A-Za-z]\w*/y;
function name(): ast.NameNode | undefined {
let match: string | undefined;
if ((match = advance(nameRe))) {
···
}
}
-
const constRe = /null|true|false/y;
-
const variableRe = /\$[_\w][_\d\w]*/y;
+
// NOTE(Safari10 Quirk): This needs to be wrapped in a non-capturing group
+
const constRe = /(?:null|true|false)/y;
+
+
const variableRe = /\$[_A-Za-z]\w*/y;
const intRe = /-?\d+/y;
-
const floatPartRe = /(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
+
+
// NOTE(Safari10 Quirk): This cannot be further simplified
+
const floatPartRe = /(?:\.\d+)?[eE][+-]?\d+|\.\d+/y;
+
const complexStringRe = /\\/g;
const blockStringRe = /"""(?:[\s\S]+(?="""))?"""/y;
const stringRe = /"(?:[^"\r\n]+)?"/y;
···
}
}
-
const operationDefinitionRe = /query|mutation|subscription/y;
+
// NOTE(Safari10 Quirk): This *might* need to be wrapped in a group, but worked without it too
+
const operationDefinitionRe = /(?:query|mutation|subscription)/y;
+
function operationDefinition(): ast.OperationDefinitionNode | undefined {
let _operation: string | undefined;
let _name: ast.NameNode | undefined;