From: Jakub Pawlowicz Date: Mon, 6 Feb 2017 06:17:45 +0000 (+0100) Subject: Fixes #880 - incorrect token type identification. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=18a6b5ac1a08781066852daa1d2d8290b6429dd1;p=clean-css.git Fixes #880 - incorrect token type identification. 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. --- diff --git a/History.md b/History.md index 3bdb0ecf..cc6b51fe 100644 --- a/History.md +++ b/History.md @@ -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) ================== diff --git a/lib/tokenizer/tokenize.js b/lib/tokenizer/tokenize.js index 30e55836..15fb584a 100644 --- a/lib/tokenizer/tokenize.js +++ b/lib/tokenizer/tokenize.js @@ -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; diff --git a/test/tokenizer/tokenize-test.js b/test/tokenizer/tokenize-test.js index 742c8dc9..f487d822 100644 --- a/test/tokenizer/tokenize-test.js +++ b/test/tokenizer/tokenize-test.js @@ -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}}', [