11import Comment from 'postcss/lib/comment' ;
22import Parser from 'postcss/lib/parser' ;
3+ import Rule from './rule' ;
34import findExtendRule from './find-extend-rule' ;
45import isMixinToken from './is-mixin-token' ;
56import lessTokenizer from './less-tokenize' ;
@@ -11,6 +12,17 @@ export default class LessParser extends Parser {
1112 this . tokens = lessTokenizer ( this . input ) ;
1213 }
1314
15+ rule ( tokens ) {
16+ tokens . pop ( ) ;
17+
18+ const node = new Rule ( ) ;
19+
20+ this . init ( node , tokens [ 0 ] [ 2 ] , tokens [ 0 ] [ 3 ] ) ;
21+ node . raws . between = this . spacesFromEnd ( tokens ) ;
22+ this . raw ( node , 'selector' , tokens ) ;
23+ this . current = node ;
24+ }
25+
1426 comment ( token ) {
1527 const node = new Comment ( ) ;
1628 const content = token [ 1 ] ;
@@ -33,7 +45,7 @@ export default class LessParser extends Parser {
3345 node . raws . right = '' ;
3446 } else {
3547 const match = text . match ( / ^ ( \s * ) ( [ ^ ] * [ ^ \s ] ) ( \s * ) $ / ) ;
36-
48+
3749 node . text = match [ 2 ] ;
3850
3951 // Add extra spaces to generate a comment in a common style /*[space][text][space]*/
@@ -79,15 +91,15 @@ export default class LessParser extends Parser {
7991 * @type {boolean }
8092 */
8193 this . current . ruleWithoutBody = true ;
82-
94+
8395 // remove `nodes` property from rules without body
8496 // eslint-disable-next-line
8597 delete this . current . nodes ;
8698 this . current . extendRule = this . current . selector . indexOf ( '&:extend' ) >= 0 ;
8799 this . current . important = this . current . selector . indexOf ( '!important' ) >= 0 ;
88100
89101 this . pos -- ;
90-
102+
91103 this . end ( this . tokens [ this . pos ] ) ;
92104 }
93105
0 commit comments