Skip to content

Fails to parse selector with variable without leading space #146

@vilchik-elena

Description

@vilchik-elena
  • Node Version: v8.11.3
  • NPM Version: 6.10.0
  • postcss Version: 7.0.26
  • postcss-less Version: 3.1.4

LESS

.foo(@i : 1 ) when (@i <= 10){
  @num : @i *10 ;
  .height-@{num}{
      height : @num * 1%;
  }
}

JavaScript

const postcss = require('postcss');
const syntax = require('postcss-less');
async function foo() {
  const less = `
  .foo(@i : 1 ) when (@i <= 10){
    @num : @i *10 ;
    .height-@{num}{
        height : @num * 1%;
    }
  }
  `;

  await postcss().process(less, { syntax });
}

foo().catch(e => console.log(e));

Errors

{ CssSyntaxError: <css input>:5:7: Unknown word
    at Input.error (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss/lib/input.js:130:16)
    at LessParser.unknownWord (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss/lib/parser.js:563:22)
    at LessParser.unknownWord (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss-less/lib/LessParser.js:209:11)
    at LessParser.decl (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss/lib/parser.js:235:16)
    at LessParser.decl (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss-less/lib/LessParser.js:32:11)
    at LessParser.other (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss/lib/parser.js:133:18)
    at LessParser.other (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss-less/lib/LessParser.js:158:13)
    at LessParser.parse (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss/lib/parser.js:77:16)
    at parse (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss-less/lib/index.js:11:12)
    at new LazyResult (/Users/elenavilchik/Projects/tmp/post-less-test/node_modules/postcss/lib/lazy-result.js:60:16)
  name: 'CssSyntaxError',
  reason: 'Unknown word',
  source: '\n.foo(@i : 1 ) when (@i <= 10){\n  @num : @i *10 ;\n  .height-@{num}{\n      height : @num * 1%;\n  }\n}\n',
  line: 5,
  column: 7,
  input: 
   { line: 5,
     column: 7,
     source: '\n.foo(@i : 1 ) when (@i <= 10){\n  @num : @i *10 ;\n  .height-@{num}{\n      height : @num * 1%;\n  }\n}\n' } }

Expected Behavior

When space is added after .height-@{num} less code is parsed normally, still it is valid even without that space and should be parsed.

Actual Behavior

Parsing error is emitted.

How can we reproduce the behavior?

Execute the js script I've provided.

I checked your sources quickly, may be problem is in https://github.com/shellscape/postcss-less/blob/master/lib/nodes/interpolation.js#L7, it consumes second { as there is no space to stop consumption.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions