Skip to content

Commit

Permalink
fix: doesn't remove calc for single function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 10, 2019
1 parent b5e20dc commit d71d9cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 18 additions & 4 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,31 @@ test(
);

test(
'should skip constant()',
'should skip constant function',
testValue,
'calc(constant(safe-area-inset-left))',
'constant(safe-area-inset-left)',
'calc(constant(safe-area-inset-left))',
);

test(
'should skip env()',
'should skip env function',
testValue,
'calc(env(safe-area-inset-left))',
'env(safe-area-inset-left)',
'calc(env(safe-area-inset-left))',
);

test(
'should skip env function (#1)',
testValue,
'calc(env(safe-area-inset-left, 50px 20px))',
'calc(env(safe-area-inset-left, 50px 20px))',
);

test(
'should skip unknown function',
testValue,
'calc(unknown(safe-area-inset-left))',
'calc(unknown(safe-area-inset-left))',
);

test(
Expand Down
4 changes: 1 addition & 3 deletions src/lib/stringifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export default function (
) {
let str = stringify(node, options.precision);

const shouldPrintCalc =
node.type === "MathExpression" ||
(node.type === "Function" && node.value.toLowerCase().slice(0, 4) === "var(");
const shouldPrintCalc = node.type === "MathExpression" || node.type === "Function";

if (shouldPrintCalc) {
// if calc expression couldn't be resolved to a single value, re-wrap it as
Expand Down

0 comments on commit d71d9cf

Please sign in to comment.