Fixes tokenizer edge case.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 22 Dec 2016 07:59:41 +0000 (08:59 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 22 Dec 2016 07:59:41 +0000 (08:59 +0100)
If there is a semicolon marker after a property then the property
ends and its reference should be discarded. Otherwise next tokens
may get appended to the property.

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

index a88ee38..6ecad7f 100644 (file)
@@ -236,6 +236,7 @@ function intoTokens(source, externalContext, internalContext, isNested) {
       serializedBuffer = buffer.join('').trim();
       propertyToken.push([Token.PROPERTY_VALUE, serializedBuffer, [originalMetadata(metadata, serializedBuffer, externalContext)]]);
 
+      propertyToken = null;
       seekingValue = false;
       buffer = [];
     } else if (character == Marker.SEMICOLON && level == Level.RULE && propertyToken && buffer.length === 0) {
index 9bac5a3..bd92ab9 100644 (file)
@@ -1455,6 +1455,66 @@ vows.describe(tokenize)
           ]
         ]
       ],
+      '@apply - between properties': [
+        'a{display:block;@apply(--rule);color:red}',
+        [
+          [
+            'rule',
+            [
+              [
+                'rule-scope',
+                'a',
+                [
+                  [1, 0, undefined]
+                ]
+              ]
+            ],
+            [
+              [
+                'property',
+                [
+                  'property-name',
+                  'display',
+                  [
+                    [1, 2, undefined]
+                  ]
+                ],
+                [
+                  'property-value',
+                  'block',
+                  [
+                    [1, 10, undefined]
+                  ]
+                ]
+              ],
+              [
+                'at-rule',
+                '@apply(--rule)',
+                [
+                  [1, 16, undefined]
+                ]
+              ],
+              [
+                'property',
+                [
+                  'property-name',
+                  'color',
+                  [
+                    [1, 31, undefined]
+                  ]
+                ],
+                [
+                  'property-value',
+                  'red',
+                  [
+                    [1, 37, undefined]
+                  ]
+                ]
+              ]
+            ]
+          ]
+        ]
+      ],
       '@apply within a variable': [
         ':root{--layout-horizontal:{@apply(--layout)};}',
         [