From 3ad60a8cbbc380d7466cf1fd666e55271be3423f Mon Sep 17 00:00:00 2001 From: Looky1173 Date: Sat, 8 Oct 2022 21:51:14 +0200 Subject: [PATCH] Fix #491 --- src/core/__tests__/compile.test.js | 6 +++--- src/core/__tests__/parse.test.js | 5 +++-- src/core/compile.js | 2 +- src/core/parse.js | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/__tests__/compile.test.js b/src/core/__tests__/compile.test.js index 1beef589..4d01d9fc 100644 --- a/src/core/__tests__/compile.test.js +++ b/src/core/__tests__/compile.test.js @@ -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` @@ -39,7 +39,7 @@ describe('compile', () => { `; expect(tmpl({})).toEqual(` background: dodgerblue; - + _ border: 1px solid blue; `); }); diff --git a/src/core/__tests__/parse.test.js b/src/core/__tests__/parse.test.js index 590b0cda..ea53399c 100644 --- a/src/core/__tests__/parse.test.js +++ b/src/core/__tests__/parse.test.js @@ -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( { diff --git a/src/core/compile.js b/src/core/compile.js index 83363d6f..0d016272 100644 --- a/src/core/compile.js +++ b/src/core/compile.js @@ -33,7 +33,7 @@ export let compile = (str, defs, data) => { // 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; + tail = res === false || res === undefined || res === null ? '_' : res; } } return out + next + (tail == null ? '' : tail); diff --git a/src/core/parse.js b/src/core/parse.js index fb05f852..e5cebdb5 100644 --- a/src/core/parse.js +++ b/src/core/parse.js @@ -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