postcss-calc 7.0.1 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,13 +28,25 @@ function stringify(node, prec) {
28
28
  right = node.right,
29
29
  op = node.operator;
30
30
  var str = "";
31
- if (left.type === 'MathExpression' && order[op] < order[left.operator]) str += `(${stringify(left, prec)})`;else str += stringify(left, prec);
31
+
32
+ if (left.type === 'MathExpression' && order[op] < order[left.operator]) {
33
+ str += `(${stringify(left, prec)})`;
34
+ } else {
35
+ str += stringify(left, prec);
36
+ }
37
+
32
38
  str += order[op] ? ` ${node.operator} ` : node.operator;
33
- if (right.type === 'MathExpression' && order[op] < order[right.operator]) str += `(${stringify(right, prec)})`;else str += stringify(right, prec);
39
+
40
+ if (right.type === 'MathExpression' && order[op] < order[right.operator]) {
41
+ str += `(${stringify(right, prec)})`;
42
+ } else {
43
+ str += stringify(right, prec);
44
+ }
45
+
34
46
  return str;
35
47
  }
36
48
 
37
- case "Value":
49
+ case 'Number':
38
50
  return round(node.value, prec);
39
51
 
40
52
  case 'Function':
@@ -47,8 +59,9 @@ function stringify(node, prec) {
47
59
 
48
60
  function _default(calc, node, originalValue, options, result, item) {
49
61
  var str = stringify(node, options.precision);
62
+ var shouldPrintCalc = node.type === "MathExpression" || node.type === "Function";
50
63
 
51
- if (node.type === "MathExpression") {
64
+ if (shouldPrintCalc) {
52
65
  // if calc expression couldn't be resolved to a single value, re-wrap it as
53
66
  // a calc()
54
67
  str = `${calc}(${str})`; // if the warnWhenCannotResolve option is on, inform the user that the calc
@@ -23,7 +23,10 @@ var MATCH_CALC = /((?:-(moz|webkit)-)?calc)/i;
23
23
  function transformValue(value, options, result, item) {
24
24
  return (0, _postcssValueParser.default)(value).walk(function (node) {
25
25
  // skip anything which isn't a calc() function
26
- if (node.type !== 'function' || !MATCH_CALC.test(node.value)) return node; // stringify calc expression and produce an AST
26
+ if (node.type !== 'function' || !MATCH_CALC.test(node.value)) {
27
+ return node;
28
+ } // stringify calc expression and produce an AST
29
+
27
30
 
28
31
  var contents = _postcssValueParser.default.stringify(node.nodes);
29
32
 
@@ -31,11 +34,12 @@ function transformValue(value, options, result, item) {
31
34
  // or a simplified calc expression
32
35
 
33
36
 
34
- var reducedAst = (0, _reducer.default)(ast, options.precision, item); // stringify AST and write it back
37
+ var reducedAst = (0, _reducer.default)(ast, options.precision); // stringify AST and write it back
35
38
 
36
39
  node.type = 'word';
37
40
  node.value = (0, _stringifier.default)(node.value, reducedAst, value, options, result, item);
38
- }, true).toString();
41
+ return false;
42
+ }).toString();
39
43
  }
40
44
 
41
45
  function transformSelector(value, options, result, item) {
@@ -49,7 +53,10 @@ function transformSelector(value, options, result, item) {
49
53
  // e.g. the "calc(3*3)" part of "div:nth-child(2n + calc(3*3))"
50
54
 
51
55
 
52
- if (node.type === 'tag') node.value = transformValue(node.value, options, result, item);
56
+ if (node.type === 'tag') {
57
+ node.value = transformValue(node.value, options, result, item);
58
+ }
59
+
53
60
  return;
54
61
  });
55
62
  }).processSync(value);
@@ -65,7 +72,9 @@ var _default = function _default(node, property, options, result) {
65
72
  var clone = node.clone();
66
73
  clone[property] = value;
67
74
  node.parent.insertBefore(node, clone);
68
- } else node[property] = value;
75
+ } else {
76
+ node[property] = value;
77
+ }
69
78
  };
70
79
 
71
80
  exports.default = _default;