Skip to content

feat(objects): add option to drop undefined keys instead of converting to nil.#677

Open
cognigy-fabian wants to merge 5 commits intodop251:masterfrom
Cognigy:cognigy
Open

feat(objects): add option to drop undefined keys instead of converting to nil.#677
cognigy-fabian wants to merge 5 commits intodop251:masterfrom
Cognigy:cognigy

Conversation

@cognigy-fabian
Copy link

We have the following code that constructs undefined keys inside an object and calls some Go binding:

const input = { foo: "bar" };
const { foo, undefinedKey } = input;
const newInput = { foo, undefinedKey };
actions.output(newInput);

Currently this exports the input to {"foo": "bar", "undefinedKey": nil} in Go.
With the new VM option it would export to {"foo": "bar"}.

…g to nil.

We have the following code that constructs `undefined` keys inside an object and calls some Go binding:
```js
const input = { foo: "bar" };
const { foo, undefinedKey } = input;
const newInput = { foo, undefinedKey };
actions.output(newInput);
```

Currently this exports the input to `{"foo": "bar", "undefinedKey": nil}` in Go.
With the new VM option it would export to `{"foo": "bar"}`.
@dop251
Copy link
Owner

dop251 commented Sep 3, 2025

I don't see a case for it, tbh... Both JS and Go distinguish between a property (or a map element) not present and being undefined (or nil). If you do not want the property to appear in the exported value you can delete it before exporting. It's not a job for goja to do data transformations during export.

fix(date): missing timeZone option handling for toLocaleString, toLocaleDateString, toLocaleTimeString
fix(date): fix missing nil check for timeZone handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants