Fixes #288 - adds smarter expression parsing.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Sat, 7 Jun 2014 21:14:09 +0000 (22:14 +0100)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Sat, 7 Jun 2014 21:14:09 +0000 (22:14 +0100)
History.md
lib/text/expressions.js
test/unit-test.js

index 9171db5..c2d1057 100644 (file)
@@ -19,6 +19,7 @@
 * Fixed issue [#257](https://github.com/GoalSmashers/clean-css/issues/257) - turns hsla/rgba to transparent if possible.
 * Fixed issue [#265](https://github.com/GoalSmashers/clean-css/issues/265) - adds support for multiple input files.
 * Fixed issue [#275](https://github.com/GoalSmashers/clean-css/issues/275) - handling transform properties.
+* Fixed issue [#288](https://github.com/GoalSmashers/clean-css/issues/288) - adds smarter expression parsing.
 
 [2.1.8 / 2014-03-28](https://github.com/GoalSmashers/clean-css/compare/v2.1.7...v2.1.8)
 ==================
index da1f52e..b231d85 100644 (file)
@@ -26,8 +26,12 @@ module.exports = function Expressions() {
         }
       }
 
-      if (level === 0 || !next)
+      if (level === 0 && next == ')')
         break;
+      if (!next) {
+        end = data.substring(0, end).lastIndexOf('}');
+        break;
+      }
     }
 
     return end;
index 623c853..3d129da 100644 (file)
@@ -330,7 +330,8 @@ vows.describe('clean-units').addBatch({
     'in comment': "/*! expression(this.runtimeStyle['zoom']) */",
     'complex': 'a{width:expression((this.parentNode.innerWidth + this.parentNode.innerHeight) / 2 )}',
     'with parentheses': "a{width:expression(this.parentNode.innerText == ')' ? '5px' : '10px' )}",
-    'open ended (broken)': "a{width:expression(this.parentNode.innerText == }"
+    'open ended (broken)': "a{width:expression(this.parentNode.innerText == }",
+    'function call & advanced': 'a{zoom:expression(function(el){el.style.zoom="1"}(this))}'
   }),
   'text content': cssContext({
     'normal #1': 'a{content:"."}',