Skip to content

fix: delete properties when reviver returns undefined - #107

Open
feritcemkahraman wants to merge 1 commit into
WebReflection:mainfrom
feritcemkahraman:fix-reviver-deletion
Open

feritcemkahraman wants to merge 1 commit into
WebReflection:mainfrom
feritcemkahraman:fix-reviver-deletion

Conversation

@feritcemkahraman

@feritcemkahraman feritcemkahraman commented Oct 11, 2026 •

Copy link
Copy Markdown

Returning undefined from a reviver currently assigns an own undefined property instead of deleting it, unlike JSON.parse. This keeps filtered object keys and creates dense array entries instead of holes. Apply the deletion rule through the same helper for immediate values, resolved string references, and deferred object/circular references.

Adds throwing regressions compared with JSON.parse and a circular-reference deletion case. Updates all tracked JavaScript distributions using the repository's generators.

Validation:

  • New object/array regression fails on the original source; the circular deletion check independently fails on the original source.
  • npm test: passes with 100% statements, branches, functions, and lines.
  • CJS/Rollup/Babel/Terser generation: passes; source ESM, bundled ESM, CJS, and three browser variants pass the deletion checks.
  • tsc -p . --noEmit and git diff --check: pass.
  • npm run ts has the same TS5055 declaration-overwrite failure in a clean original worktree. The Unix shell size pipeline and PHP/Python/Go tests were not run; only JavaScript is changed.

Reproduction using Flatted's own output

The input is produced by Flatted.stringify, not JSON.stringify or a hand-written Flatted payload:

const input = { remove: 1, keep: 'ok' };
const text = Flatted.stringify(input);
const result = Flatted.parse(text, (key, value) =>
  key === 'remove' ? undefined : value
);
console.log(text); // [{"remove":1,"keep":"1"},"ok"]
console.log(Object.keys(result));

On the original implementation the keys are ['remove', 'keep'] and remove is still an own property. With this PR the keys are ['keep']. The regression test likewise calls Flatted.parse(Flatted.stringify(filtered), reviver). This concerns the documented reviver property-deletion behavior, not interchangeability of Flatted and JSON wire formats. Rechecked with the original CJS source on 12 October.

@WebReflection

Copy link
Copy Markdown
Owner

I need you to show me how you can produce that entry out of flatted, then I can consider the PR, thanks.

If you cannot use flatted to produce invalid entries, this is NOT A BUG, just expected behavior, lately so many pointless issues or security concerns out of the same concept: flatted is not compatible with JSON and never will, thanks for your understanding.

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.

2 participants