2

I'm trying the following statement in LESS, but its giving me an error:

(~".table-column[width='@{size}']") {
    // do something
}
----------
ERROR :
---------- 
*ParseError: Missing closing ')'*

I'm using lessc 2.5.3, with nodejs on windows. LESS is new to me and any pointers would be helpful.

Thanks

scniro
  • 16,844
  • 8
  • 62
  • 106
kallada
  • 1,829
  • 4
  • 33
  • 64

1 Answers1

3

No need for the parens, nor the string quotes, nor the ~ (unless you are trying to use a ~ sibling selector). Observe the following...

@size: 40px;

.table-column[width='@{size}'] {
    background-color: tomato;
}

// -- conversion
.table-column[width='40px'] {
    background-color: tomato;
}

Codepen link - working demo

Also check out the LESS variables docs - specifically, variable interpolation, for more information.

scniro
  • 16,844
  • 8
  • 62
  • 106
  • `(~".table-column[width='@{size}']")` compiles to `.table-column[width='40px']` *not* to `~ .table-column[width='40px']`. So while the answer was accepted, you'd better fix it (like I did) to not misdirect future readers. – seven-phases-max Oct 07 '15 at 14:08
  • excuse me for the rude response. `(~".table-column[width='@{size}']")` does not even compile, and OP is using a `~` sibling selector which I demo'd in my [codepen](http://codepen.io/anon/pen/LpymwL) example – scniro Oct 07 '15 at 14:10
  • Open less2css.org and test the code with version 1.3.3 (this is the Less version that out-of-date syntax in the Q was valid in). `~` in quotes there is the part of string interpolation, *not* a selector cobinator. So the downovote is fair (because the code in your answer does not produce the same selector as the original source code did). – seven-phases-max Oct 07 '15 at 14:16
  • you're making assumptions. How do you **know** OP is not intending to use a `~` selector. It was not specified, nor was feedback provided on my answer. Speaking of specifying, **why** would I use 1.3.3 when version 2.5.3 was specified in the question? Sure, maybe you know something about older LESS syntax, but you made that assumption and it is not fair nor your place to rudely interrupt when you are not certain the intentions of the OP. – scniro Oct 07 '15 at 14:21
  • roll'd back to your revision You could have been friendlier about it – scniro Oct 07 '15 at 14:29
  • It's not assumptions. It's *well known* Less syntax change in v1.4.0 (see [changelog](https://github.com/less/less.js/blob/master/CHANGELOG.md#140-beta-1--2), http://stackoverflow.com/questions/19553367/less-unrecognized-input-error-when-using-bootstrap etc.) – seven-phases-max Oct 07 '15 at 14:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91618/discussion-between-scniro-and-seven-phases-max). – scniro Oct 07 '15 at 14:31