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

Skip parsing undefined values #41

Merged
merged 3 commits into from
May 27, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/createSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export const createParser = (
const parseEntry = (obj: SomeObject, key: string) => {
const systemConfig = config[key];
let propValue: any = obj[key];

// See issue #35
if (propValue === undefined) {
return {};
}

const scale = get(props.theme, systemConfig.scale);

if (typeof propValue === 'function') {
Expand Down
13 changes: 13 additions & 0 deletions src/core/tests/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const theme = {
secondary: 'papayawhip',
},
fontSize: [0, 4, 8, 16],
space: [0, 4, 8, 16],
breakpoints: [40, 52, 64].map((n) => n + 'em'),
systemPropsId: false,
};
Expand Down Expand Up @@ -34,6 +35,8 @@ const parser = system({
},
fontSize: true,
border: true,
mx: { properties: ['marginLeft', 'marginRight'], scale: 'space' },
marginLeft: { property: 'marginLeft', scale: 'space' },
});

test('parses pseudo selectors', () => {
Expand Down Expand Up @@ -233,3 +236,13 @@ test('parses raw function values at each breakpoint', () => {
},
});
});

test('ignores undefined values - issue #35', () => {
const styles = parser({
theme,
color: undefined,
mx: '$2',
marginLeft: undefined,
});
expect(styles).toMatchObject({ marginLeft: 8, marginRight: 8 });
});