Fixes #946 - `-ms-grid-columns` repeat syntax.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 18 May 2017 19:21:02 +0000 (21:21 +0200)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 18 May 2017 19:28:13 +0000 (21:28 +0200)
Why:

* Apparently our tokenizer didn't recognize it properly, see:
  https://msdn.microsoft.com/library/Hh772246

History.md
lib/tokenizer/tokenize.js
test/tokenizer/tokenize-test.js

index c064286..c5db6ea 100644 (file)
@@ -1,3 +1,8 @@
+[4.1.3 / 2017-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.2...4.1)
+==================
+
+* Fixed issue [#946](https://github.com/jakubpawlowicz/clean-css/issues/946) - tokenizing `-ms-grid-columns` repeat syntax.
+
 [4.1.2 / 2017-05-10](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.1...v4.1.2)
 ==================
 
index 15fb584..7c071dd 100644 (file)
@@ -28,6 +28,7 @@ var BLOCK_RULES = [
   '@supports'
 ];
 
+var REPEAT_PATTERN = /^\[\s*\d+\s*\]$/;
 var RULE_WORD_SEPARATOR_PATTERN = /[\s\(]/;
 var TAIL_BROKEN_VALUE_PATTERN = /[\s|\}]*$/;
 
@@ -376,6 +377,12 @@ function intoTokens(source, externalContext, internalContext, isNested) {
       // comma within a property after space, e.g. a{background:url(image.png) ,<--
       propertyToken.push([Token.PROPERTY_VALUE, character, [[position.line, position.column, position.source]]]);
 
+      buffer = [];
+    } else if (character == Marker.CLOSE_SQUARE_BRACKET && propertyToken && propertyToken.length > 1 && buffer.length > 0 && isRepeatToken(buffer)) {
+      buffer.push(character);
+      serializedBuffer = buffer.join('').trim();
+      propertyToken[propertyToken.length - 1][1] += serializedBuffer;
+
       buffer = [];
     } else if ((isSpace || (isNewLineNix && !isNewLineWin)) && level == Level.RULE && seekingValue && propertyToken && buffer.length > 0) {
       // space or *nix newline within property, e.g. a{margin:0 <--
@@ -460,4 +467,8 @@ function tokenScopeFrom(tokenType) {
   }
 }
 
+function isRepeatToken(buffer) {
+  return REPEAT_PATTERN.test(buffer.join('') + Marker.CLOSE_SQUARE_BRACKET);
+}
+
 module.exports = tokenize;
index f487d82..583fbad 100644 (file)
@@ -536,6 +536,42 @@ vows.describe(tokenize)
           ]
         ]
       ],
+      'a rule with grid repeat': [
+        '.block{-ms-grid-columns:( 1fr )[5]}',
+        [
+          [
+            'rule',
+            [
+              [
+                'rule-scope',
+                '.block',
+                [
+                  [1, 0, undefined]
+                ]
+              ]
+            ],
+            [
+              [
+                'property',
+                [
+                  'property-name',
+                  '-ms-grid-columns',
+                  [
+                    [1, 7, undefined]
+                  ]
+                ],
+                [
+                  'property-value',
+                  '( 1fr )[5]',
+                  [
+                    [1, 24, undefined]
+                  ]
+                ]
+              ]
+            ]
+          ]
+        ]
+      ],
       'a rule with two properties where first ends with a round close bracket': [
         'a{width:calc(100% - 25px);width:50rem}',
         [