Fixes #880 - incorrect token type identification.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 6 Feb 2017 06:17:45 +0000 (07:17 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 7 Feb 2017 10:12:01 +0000 (11:12 +0100)
Why:

* When there is no space after nested block scope, e.g.
  `@media(` in `@media(min-width:100px)` it should still be
  handled correctly by tokenizer.

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

index 3bdb0ec..cc6b51f 100644 (file)
@@ -2,6 +2,7 @@
 ==================
 
 * Fixed issue [#881](https://github.com/jakubpawlowicz/clean-css/issues/881) - incorrect `require` arity.
+* Fixed issue [#880](https://github.com/jakubpawlowicz/clean-css/issues/880) - incorrect token type identification.
 
 [4.0.4 / 2017-02-04](https://github.com/jakubpawlowicz/clean-css/compare/v4.0.3...v4.0.4)
 ==================
index 30e5583..15fb584 100644 (file)
@@ -28,6 +28,7 @@ var BLOCK_RULES = [
   '@supports'
 ];
 
+var RULE_WORD_SEPARATOR_PATTERN = /[\s\(]/;
 var TAIL_BROKEN_VALUE_PATTERN = /[\s|\}]*$/;
 
 function tokenize(source, externalContext) {
@@ -436,7 +437,7 @@ function originalMetadata(metadata, value, externalContext, selectorFallbacks) {
 
 function tokenTypeFrom(buffer) {
   var isAtRule = buffer[0] == Marker.AT || buffer[0] == Marker.UNDERSCORE;
-  var ruleWord = buffer.join('').split(/\s/)[0];
+  var ruleWord = buffer.join('').split(RULE_WORD_SEPARATOR_PATTERN)[0];
 
   if (isAtRule && BLOCK_RULES.indexOf(ruleWord) > -1) {
     return Token.NESTED_BLOCK;
index 742c8dc..f487d82 100644 (file)
@@ -1785,6 +1785,56 @@ vows.describe(tokenize)
           ]
         ]
       ],
+      'media query without space abc': [
+        '@media(min-width:980px){.block{color:red}}',
+        [
+          [
+            'nested-block',
+            [
+              [
+                'nested-block-scope',
+                '@media(min-width:980px)',
+                [
+                  [1, 0, undefined]
+                ]
+              ]
+            ],
+            [
+              [
+                'rule',
+                [
+                  [
+                    'rule-scope',
+                    '.block',
+                    [
+                      [1, 24, undefined]
+                    ]
+                  ]
+                ],
+                [
+                  [
+                    'property',
+                    [
+                      'property-name',
+                      'color',
+                      [
+                        [1, 31, undefined]
+                      ]
+                    ],
+                    [
+                      'property-value',
+                      'red',
+                      [
+                        [1, 37, undefined]
+                      ]
+                    ]
+                  ]
+                ]
+              ]
+            ]
+          ]
+        ]
+      ],
       'multiple media query': [
         '@media print,(min-width:980px){a{color:red}}',
         [