From e0272b2cab3b4b844576775fab6bf22537bf95f5 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sat, 19 Oct 2024 09:13:27 +0100 Subject: [PATCH 1/2] Remove for-of from values helpers --- src/values.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/values.ts b/src/values.ts index 3c21f41..945f580 100644 --- a/src/values.ts +++ b/src/values.ts @@ -18,13 +18,16 @@ export function valueFromASTUntyped( return node.value; case 'ListValue': { const values: unknown[] = []; - for (const value of node.values) values.push(valueFromASTUntyped(value, variables)); + for (let i = 0, l = node.values.length; i < l; i++) + values.push(valueFromASTUntyped(node.values[i], variables)); return values; } case 'ObjectValue': { const obj = Object.create(null); - for (const field of node.fields) + for (let i = 0, l = node.fields.length; i < l; i++) { + const field = node.fields[i]; obj[field.name.value] = valueFromASTUntyped(field.value, variables); + } return obj; } case 'Variable': @@ -47,7 +50,8 @@ export function valueFromTypeNode( } else if (type.kind === 'ListType') { if (node.kind === 'ListValue') { const values: unknown[] = []; - for (const value of node.values) { + for (let i = 0, l = node.values.length; i < l; i++) { + const value = node.values[i]; const coerced = valueFromTypeNode(value, type.type, variables); if (coerced === undefined) { return undefined; From 803ed129273a1f399bf496fe9d803ade5986ba43 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sat, 19 Oct 2024 09:14:22 +0100 Subject: [PATCH 2/2] Add changeset --- .changeset/nasty-cobras-repair.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nasty-cobras-repair.md diff --git a/.changeset/nasty-cobras-repair.md b/.changeset/nasty-cobras-repair.md new file mode 100644 index 0000000..cb9c7b9 --- /dev/null +++ b/.changeset/nasty-cobras-repair.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphql.web': patch +--- + +Remove `for-of` syntax from `valueFromTypeNode` and `valueFromASTUntyped` helpers for JSC memory reduction.