From 2b69eea533502398ebe0e7c7ca930253814ea2f3 Mon Sep 17 00:00:00 2001
From: Matthew Dean <matthew-dean@users.noreply.github.com>
Date: Wed, 13 Jan 2021 12:40:29 -0800
Subject: [PATCH] Fixes #3586

---
 packages/less/src/less/tree/dimension.js                   | 3 ++-
 packages/less/src/less/tree/operation.js                   | 7 +++++--
 .../test-data/less/math/parens-division/media-math.less    | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/packages/less/src/less/tree/dimension.js b/packages/less/src/less/tree/dimension.js
index 80e4a0607..8cbb3249d 100644
--- a/packages/less/src/less/tree/dimension.js
+++ b/packages/less/src/less/tree/dimension.js
@@ -66,7 +66,8 @@ Dimension.prototype = Object.assign(new Node(), {
     // so `1px + 2` will yield `3px`.
     operate(context, op, other) {
         /* jshint noempty:false */
-        let value = this._operate(context, op, this.value, other.value), unit = this.unit.clone();
+        let value = this._operate(context, op, this.value, other.value);
+        let unit = this.unit.clone();
 
         if (op === '+' || op === '-') {
             if (unit.numerator.length === 0 && unit.denominator.length === 0) {
diff --git a/packages/less/src/less/tree/operation.js b/packages/less/src/less/tree/operation.js
index 225da1ac0..2805326be 100644
--- a/packages/less/src/less/tree/operation.js
+++ b/packages/less/src/less/tree/operation.js
@@ -29,8 +29,11 @@ Operation.prototype = Object.assign(new Node(), {
             if (b instanceof Dimension && a instanceof Color) {
                 b = b.toColor();
             }
-            if (!a.operate) {
-                if (a instanceof Operation && a.op === '/' && context.math === MATH.PARENS_DIVISION) {
+            if (!a.operate || !b.operate) {
+                if (
+                    (a instanceof Operation || b instanceof Operation)
+                    && a.op === '/' && context.math === MATH.PARENS_DIVISION
+                ) {
                     return new Operation(this.op, [a, b], this.isSpaced);
                 }
                 throw { type: 'Operation',
diff --git a/packages/test-data/less/math/parens-division/media-math.less b/packages/test-data/less/math/parens-division/media-math.less
index b3df9118e..c2d34a608 100644
--- a/packages/test-data/less/math/parens-division/media-math.less
+++ b/packages/test-data/less/math/parens-division/media-math.less
@@ -1,4 +1,4 @@
-@var: 16;
+@var: 10 + 6;
 
 @media (min-width: @var + 1) {
   .foo { bar: 1; }