Skip to content
Open
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: 3 additions & 3 deletions src/core/__tests__/compile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ describe('compile', () => {
});

it('value interpolations', () => {
// This interpolations are testing the ability to interpolate thruty and falsy values
// This interpolations are testing the ability to interpolate truthy and falsy values
expect(template`prop: 1; ${() => 0},${() => undefined},${() => null},${2}`({})).toEqual(
'prop: 1; 0,,,2'
'prop: 1; 0,_;,_;,2' // '_;' represents a falsy value
);

const tmpl = template`
Expand All @@ -39,7 +39,7 @@ describe('compile', () => {
`;
expect(tmpl({})).toEqual(`
background: dodgerblue;

_;
border: 1px solid blue;
`);
});
Expand Down
5 changes: 3 additions & 2 deletions src/core/__tests__/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ describe('parse', () => {
{
div: {
opacity: 0,
color: null
color: null,
content: '""'
}
},
''
)
).toEqual('div{opacity:0;}');
).toEqual('div{opacity:0;content:"";}');
expect(
parse(
{
Expand Down
9 changes: 5 additions & 4 deletions src/core/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export let compile = (str, defs, data) => {
tail = res.props ? '' : parse(res, '');
} else {
// Regular value returned. Can be falsy as well.
// Here we check if this is strictly a boolean with false value
// define it as `''` to be picked up as empty, otherwise use
// res value
tail = res === false ? '' : res;
// If this is `false`, `undefined` or `null`,
// define it as `_;` to be picked up as empty, otherwise use
// res value. The semicolon in `_;` is necessary to make `astish()`
// ignore such empty values.
tail = res === false || res == null ? '_;' : res;
}
}
return out + next + (tail == null ? '' : tail);
Expand Down
2 changes: 1 addition & 1 deletion src/core/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export let parse = (obj, selector) => {
})
: key
);
} else if (val != undefined) {
} else if (val != undefined && val !== '_') {
// Convert all but CSS variables
key = /^--/.test(key) ? key : key.replace(/[A-Z]/g, '-$&').toLowerCase();
// Push the line for this property
Expand Down