Skip to content

Commit

Permalink
fix: Remove for-of syntax from values helpers for JSC memory reduct…
Browse files Browse the repository at this point in the history
…ion (#33)

* Remove for-of from values helpers

* Add changeset
  • Loading branch information
kitten authored Oct 19, 2024
1 parent c8986d5 commit 8af6125
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-cobras-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphql.web': patch
---

Remove `for-of` syntax from `valueFromTypeNode` and `valueFromASTUntyped` helpers for JSC memory reduction.
10 changes: 7 additions & 3 deletions src/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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;
Expand Down

0 comments on commit 8af6125

Please sign in to comment.