Skip to content

Commit

Permalink
fixed deepMergeObject overwriting values with undefined (#753)
Browse files Browse the repository at this point in the history
feat-fix: fixed deepMergeObject overwriting values with undefined
  • Loading branch information
Ellpeck authored Apr 16, 2024
1 parent 15d147d commit 2eb92e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/util/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export function deepMergeObject(base?: Mergeable, addon?: Mergeable): Mergeable

function deepMergeObjectWithResult(addon: MergeableRecord, base: MergeableRecord, result: MergeableRecord): void {
for(const key of Object.keys(addon)) {
// values that are undefined (like from a partial object) should NOT be overwritten
if(addon[key] === undefined) {
continue
}

if(typeof addon[key] === 'object') {
if(key in base) {
result[key] = deepMergeObject(base[key] as Mergeable, addon[key] as Mergeable)
Expand Down
3 changes: 3 additions & 0 deletions test/functionality/util/objects-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,8 @@ describe('Objects', () => {
throws(true as boolean[], true as boolean[], 'lied booleans as arrays')
})
})
describe('with undefined', () => {
merged({ a: 3, b: 4 }, { a: undefined, b: 7 }, { a: 3, b: 7 }, 'do not overwrite on undefined')
})
})
})

2 comments on commit 2eb92e0

@github-actions
Copy link

Choose a reason for hiding this comment

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

"artificial" Benchmark Suite

Benchmark suite Current: 2eb92e0 Previous: 1e5ddeb Ratio
Retrieve AST from R code 307.9973126818182 ms 305.50355490909095 ms 1.01
Normalize R AST 32.93066913636363 ms 33.04192136363636 ms 1.00
Produce dataflow information 67.19553954545455 ms 66.58585145454545 ms 1.01
Total per-file 1531.1773226363637 ms 1512.547620909091 ms 1.01
Static slicing 1.3782187825036059 ms (1.2533728246640692) 1.3817132831241319 ms (1.27303105869458) 1.00
Reconstruct code 0.45717586571451374 ms (0.25517039796452456) 0.45135141022522257 ms (0.25927254974160097) 1.01
Total per-slice 1.8500854432768716 ms (1.3285977164359422) 1.8475447304133532 ms (1.3326721674469058) 1.00
failed to reconstruct/re-parse 0 # 0 # 1
times hit threshold 0 # 0 # 1
reduction (characters) 0.7329390759026897 # 0.7329390759026897 # 1
reduction (normalized tokens) 0.7209834969577295 # 0.7209834969577295 # 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

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

"social-science" Benchmark Suite

Benchmark suite Current: 2eb92e0 Previous: 1e5ddeb Ratio
Retrieve AST from R code 311.85749960000004 ms 330.55613118 ms 0.94
Normalize R AST 35.2939004 ms 36.10837608 ms 0.98
Produce dataflow information 182.8283064 ms 188.6117503 ms 0.97
Total per-file 3674.31826338 ms 3858.78617088 ms 0.95
Static slicing 8.456555029306035 ms (14.805251753066617) 8.763488287471356 ms (15.142795018273485) 0.96
Reconstruct code 0.4863226545896253 ms (0.23132549748827436) 0.6295735167403027 ms (0.28826473087031307) 0.77
Total per-slice 8.952155711652116 ms (14.91626419502245) 9.403718790030862 ms (15.25727767695505) 0.95
failed to reconstruct/re-parse 7 # 7 # 1
times hit threshold 298 # 298 # 1
reduction (characters) 0.8935817303062389 # 0.8935817303062389 # 1
reduction (normalized tokens) 0.8531248144961375 # 0.8531248144961375 # 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.