Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent max call stack when merging overlapping keys #483

Merged
merged 4 commits into from May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -42,7 +42,7 @@ export const merge = (a, b) => {
result[key] = a[key]
}
for (const key in b) {
if (!a[key]) {
if (!a[key] || typeof a[key] !== 'object') {
result[key] = b[key]
} else {
result[key] = merge(a[key], b[key])
Expand Down
31 changes: 29 additions & 2 deletions test/index.js
Expand Up @@ -11,6 +11,7 @@ import {
cloneFunction,
mapProps,
merge,
fontSize,
} from '../src'

const width = style({
Expand Down Expand Up @@ -277,13 +278,39 @@ test('mapProps copies propTypes', t => {

test('merge deeply merges', t => {
const result = merge(
{ hello: { hi: 'beep' } },
{ hello: { hey: 'boop' } },
{ hello: { hi: 'beep', merge: 'me', and: 'me' } },
{ hello: { hey: 'boop', merge: 'me', and: 'all of us' } },
)
t.deepEqual(result, {
hello: {
hi: 'beep',
hey: 'boop',
merge: 'me',
and: 'all of us'
}
})
})

test('variant can be composed', t => {
const system = compose(
variant({ key: 'typography' }),
fontSize,
color
)
const result = system({
theme: {
typography: {
primary: {
fontSize: '32px',
color: '#fff'
},
},
},
variant: 'primary',
color: '#111'
})
t.deepEqual(result, {
fontSize: '32px',
color: '#111'
})
})