Skip to content

Avoid mutating patch options when defaulting context - #756

Merged
ExplodingCabbage merged 2 commits into
kpdecker:masterfrom
tolgacodes-dev:fix/preserve-patch-options
Nov 25, 2026
Merged

ExplodingCabbage merged 2 commits into
kpdecker:masterfrom
tolgacodes-dev:fix/preserve-patch-options

Conversation

@tolgacodes-dev

Copy link
Copy Markdown
Contributor

Passing a frozen options object to createPatch throws when the caller leaves context at its default:

createPatch('notes.txt', 'before\n', 'after\n', '', '', Object.freeze({}));
// TypeError: Cannot add property context, object is not extensible

structuredPatch currently writes context: 4 back onto the caller's object. Read the option into a local variable with the same default instead. The regression compares the patch produced with frozen empty options to the one produced with an explicit four lines of context.

The regression fails on the original code. yarn test passes with the change (377 tests).

@ExplodingCabbage ExplodingCabbage left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Always sweet when a fix also simplifies the code, as here.

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