Skip to content

Commit

Permalink
fix(hiccup-css): fn & auto-prefix handling
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 5, 2018
1 parent 787d0ab commit f3190ff
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/hiccup-css/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ export function _css(acc: string[], parent: any[], rules: any[], opts: CSSOpts)
const n = rules.length;
const sel: string[] = [];
let curr: any, isFn;
for (let i = 0; i < n; i++) {
const r = rules[i];

function process(i, r) {
if (isArray(r)) {
_css(acc, makeSelector(parent, sel), r, opts);
} else if (isIterable(r) && !isString(r)) {
_css(acc, makeSelector(parent, sel), [...r], opts);
} else if ((isFn = isFunction(r)) || opts.fns[r]) {
if (i === 0) {
return opts.fns[r] ?
opts.fns[r].apply(null, rules.slice(i + 1))(acc, opts) :
r(acc, opts);
if (opts.fns[r]) {
opts.fns[r].apply(null, rules.slice(i + 1))(acc, opts);
return true;
}
r(acc, opts);
} else if (isFn) {
sel.push(r());
process(i, r());
} else {
throw new Error(`quoted fn ('${r}') only allowed at head position`);
}
Expand All @@ -71,6 +73,12 @@ export function _css(acc: string[], parent: any[], rules: any[], opts: CSSOpts)
sel.push(r);
}
}

for (let i = 0; i < n; i++) {
if (process(i, rules[i])) {
return acc;
}
}
if (curr) {
acc.push(formatRule(parent, sel, curr, opts));
}
Expand All @@ -95,9 +103,8 @@ export function formatDecls(rules: any, opts: CSSOpts) {
for (let v of opts.vendors) {
acc.push(`${space}${v}${r}:${f.valSep}${val};`);
}
} else {
acc.push(`${space}${r}:${f.valSep}${val};`);
}
acc.push(`${space}${r}:${f.valSep}${val};`);
}
}
return acc.join(f.decls) + f.decls;
Expand Down

0 comments on commit f3190ff

Please sign in to comment.