Repository: shellscape/postcss-less (js)

Issue:
Rule with pseudo selector has false params property
We've been struggling with some baddish logic in postcss-less while analyzing rules. Given this rule:

``` css
.test1,
.test2:not(.test3) {
    width: 100%;
}
```

The resulting node looks like this:

``` js
Rule {
  raws: 
   { before: '',
     between: ' ',
     params: { value: '(.test3)', raw: '(.test3) ' },
     semicolon: true,
     after: '\n' },
  type: 'rule',
  nodes: 
   [ Declaration {
       raws: [Object],
       type: 'decl',
       parent: [Circular],
       source: [Object],
       prop: 'width',
       value: '100%' } ],
  parent: 
   Root { ... },
  source: 
   { start: { line: 1, column: 1 },
     input: 
      Input {
        css: '.test1,\n.test2:not(.test3) {\n    width: 100%;\n}\n',
        id: '<input css 1>' },
     end: { line: 4, column: 1 } },
  selector: '.test1,\n.test2:not(.test3)',
  params: '(.test3)',
  lastEach: 4,
  indexes: {},
  selectorAst: 
   Root { ... }
```

You'll notice that this is not a mixin definition or use, but the `params` property is being assigned based on the pseudo selector `:not` value. On the surface, this looks like a bug. The value of the pseudo selector should be simply part of the selector, as it's not treated any different in plain css, and params should be empty.


Pull request description:
fixes #56: pseudo selectors which use parens shouldn't result in params

Patch:
diff --git a/lib/less-parser.js b/lib/less-parser.js
index 5139d09..689ac29 100755
--- a/lib/less-parser.js
+++ b/lib/less-parser.js
@@ -197,7 +197,8 @@ export default class LessParser extends Parser {
                 }
             }
 
-            if (brackets.length > 0 || type === 'brackets' || params[0]) {
+            // we don't want to add params for pseudo-selectors that utilize parens (#56)
+            if ((isExtendRule || !colon) && (brackets.length > 0 || type === 'brackets' || params[0])) {
                 params.push(token);
             }
 


Test patch:
diff --git a/test/parser/mixins.spec.js b/test/parser/mixins.spec.js
index 9e791f0..3e367f9 100644
--- a/test/parser/mixins.spec.js
+++ b/test/parser/mixins.spec.js
@@ -52,16 +52,16 @@ describe('Parser', () => {
                     .mixin-id {
                         #b (@param1; @param2);
                     }
-        
+
                     .class {
                         .mixin1 (
-        
-        
+
+
                         )
-        
-        
+
+
                         ;
-        
+
                         .mixin2
                     }
                 `;
@@ -121,7 +121,7 @@ describe('Parser', () => {
                 `;
 
                 const root = parse(code);
-                
+
                 expect(root.first.selector).to.eql('.foo() !important');
                 expect(root.first.important).to.eql(true);
             });
@@ -153,36 +153,36 @@ describe('Parser', () => {
                         line-height: 1.6rem;
                         color: @c_white;
                         background-color: @c_blue1;
-                    
+
                         &_info {
                             background-color: @c_blue5;
                         }
-                    
+
                         &_danger {
                             background-color: @c_red2;
                         }
-                    
+
                         &_success {
                             background-color: @c_green3;
                         }
-                    
+
                         &_warning {
                             background-color: @c_yellow1;
                             color: @c_black1;
                         }
                     }
-                    
+
                     .badge-category {
                         &:extend(.m_badge-default);
                     }
-                    
+
                     .buy-sell-badge {
                         .m_text-uppercase();
-                    
+
                         &_buy {
                             &:extend(.m_text-success);
                         }
-                    
+
                         &_sell {
                             &:extend(.m_text-error);
                         }
diff --git a/test/parser/params.spec.js b/test/parser/params.spec.js
new file mode 100644
index 0000000..5c78885
--- /dev/null
+++ b/test/parser/params.spec.js
@@ -0,0 +1,19 @@
+// chai uses expressions for validation
+/* eslint no-unused-expressions: 0 */
+
+import {expect} from 'chai';
+import parse from '../../lib/less-parse';
+
+describe('Parser', () => {
+    describe('Params', () => {
+
+        it('should not assign parameters for pseudo-selectors (#56)', () => {
+            const code = '.test2:not(.test3) {}';
+            const root = parse(code);
+
+            expect(root.first.selector).to.eql('.test2:not(.test3)');
+            expect(root.first.params).to.be.undefined;
+        });
+
+    });
+});