postcss-calc 8.2.0 → 8.2.1

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.
@@ -141,6 +141,8 @@ function collectAddSubItems(preOperator, node, collected, precision) {
141
141
  });
142
142
  }
143
143
  }
144
+ } else if (node.type === 'ParenthesizedExpression') {
145
+ collectAddSubItems(preOperator, node.content, collected, precision);
144
146
  } else {
145
147
  collected.push({
146
148
  node,
@@ -347,6 +349,7 @@ function convertNodesUnits(left, right, precision) {
347
349
  /**
348
350
  * @param {import('../parser').CalcNode} node
349
351
  * @param {number} precision
352
+ * @return {import('../parser').CalcNode}
350
353
  */
351
354
 
352
355
 
@@ -371,6 +374,12 @@ function reduce(node, precision) {
371
374
  return node;
372
375
  }
373
376
 
377
+ if (node.type === 'ParenthesizedExpression') {
378
+ if (node.content.type !== 'Function') {
379
+ return reduce(node.content, precision);
380
+ }
381
+ }
382
+
374
383
  return node;
375
384
  }
376
385
 
@@ -26,6 +26,8 @@ function round(value, prec) {
26
26
  /**
27
27
  * @param {number | false} prec
28
28
  * @param {import('../parser').CalcNode} node
29
+ *
30
+ * @return {string}
29
31
  */
30
32
 
31
33
 
@@ -63,6 +65,9 @@ function stringify(node, prec) {
63
65
  case 'Function':
64
66
  return node.value.toString();
65
67
 
68
+ case 'ParenthesizedExpression':
69
+ return `(${stringify(node.content, prec)})`;
70
+
66
71
  default:
67
72
  return round(node.value, prec) + node.unit;
68
73
  }
package/dist/parser.js CHANGED
@@ -828,8 +828,6 @@ case 1:
828
828
 
829
829
  case 2:
830
830
  /*! Production:: math_expression : CALC LPAREN math_expression RPAREN */
831
- case 7:
832
- /*! Production:: math_expression : LPAREN math_expression RPAREN */
833
831
 
834
832
  this.$ = yyvstack[yysp - 1];
835
833
  break;
@@ -846,6 +844,12 @@ case 6:
846
844
  this.$ = { type: 'MathExpression', operator: yyvstack[yysp - 1], left: yyvstack[yysp - 2], right: yyvstack[yysp] };
847
845
  break;
848
846
 
847
+ case 7:
848
+ /*! Production:: math_expression : LPAREN math_expression RPAREN */
849
+
850
+ this.$ = { type: 'ParenthesizedExpression', content: yyvstack[yysp - 1] };
851
+ break;
852
+
849
853
  case 8:
850
854
  /*! Production:: math_expression : function */
851
855
  case 9:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-calc",
3
- "version": "8.2.0",
3
+ "version": "8.2.1",
4
4
  "description": "PostCSS plugin to reduce calc()",
5
5
  "keywords": [
6
6
  "css",
@@ -40,7 +40,7 @@
40
40
  "postcss": "^8.2.2",
41
41
  "rimraf": "^3.0.2",
42
42
  "typescript": "^4.5.4",
43
- "uvu": "^0.5.2"
43
+ "uvu": "^0.5.3"
44
44
  },
45
45
  "dependencies": {
46
46
  "postcss-selector-parser": "^6.0.2",
@@ -6,5 +6,6 @@ export type Collectible = {
6
6
  /**
7
7
  * @param {import('../parser').CalcNode} node
8
8
  * @param {number} precision
9
+ * @return {import('../parser').CalcNode}
9
10
  */
10
- declare function reduce(node: import('../parser').CalcNode, precision: number): import("../parser").MathExpression | import("../parser").DimensionExpression | import("../parser").NumberExpression | import("../parser").FunctionExpression;
11
+ declare function reduce(node: import('../parser').CalcNode, precision: number): import('../parser').CalcNode;