Skip to content

Commit

Permalink
Fix lean and reverse to strict naming
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Apr 15, 2020
1 parent b352576 commit da22b1a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default function bss({
if (selector.indexOf('animation') === 0)
props.out.push(['animation', selector.slice(10) + ' ' + x])
parseAddProps(ani || at || supports || rules, i, x, props, level)
props.prop = props.value = props.propEnd = null
props.prop = props.value = props.propEnd = props.strict = null
selector.indexOf('@supports') === 0
? supports = Object.assign([], { selector })
: selector[0] === '@'
Expand Down Expand Up @@ -247,16 +247,16 @@ export default function bss({
propEnd: null,
value: null,
out: [],
lean: true,
strict: null,
comma: 0,
end: 0,
quote: false
}
}

function propsParseLoop(s, i, v, x) {
if (!x.value && x.prop !== null && x.lean && v === ':')
x.lean = false
if (!x.value && x.prop !== null && !x.strict && v === ':')
x.strict = true
if (!x.value && x.prop !== null && x.out.length && v === ',') {
x.value = x.comma
x.prop = x.out[x.out.length - 1][0]
Expand All @@ -279,7 +279,7 @@ export default function bss({
&& (i === s.length - 1
|| s[i + 1] === ';'
|| s[i + 1] === '}'
|| (x.lean
|| (!x.strict
&& s[i - 1] !== ','
&& v === '\n'
)
Expand All @@ -292,13 +292,12 @@ export default function bss({
)
x.end = i + (s[i + 1] === ';' ? 2 : 1)
x.comma = x.value
x.value = x.prop = x.propEnd = null
x.lean = true
x.value = x.prop = x.propEnd = x.strict = null
}
}

function propParse(key, value, x) {
if (!x.lean)
if (x.strict)
return [key, value]

key = props.reduce((acc, fn) => fn(acc), key.trim())
Expand Down
25 changes: 25 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,31 @@ t('Fails gracefully on bad prop syntax', () => {
]
})

t('Mixed strict and lean works', () => {
b`
bc blue
bc:blue;
`.toString()

return [
cn() + cn() + '{background-color:blue;bc:blue;}',
b.rules.pop()
]
})

t('Mixed nesting and lean works', () => {
b`
input:checked + label::after {
w 18
}
`.toString()

return [
b.rules.pop(),
cn() + ' input:checked + label::after{width:18px;}'
]
})

t('Support multiline props', () => {
b`
transform: translateY(20px)
Expand Down

0 comments on commit da22b1a

Please sign in to comment.