less.js icon indicating copy to clipboard operation
less.js copied to clipboard

JavaScript evaluation - why forcing "Quotes" on strings?

Open chrisjacob opened this issue 15 years ago • 1 comments

If the javascript evaluates to typeof(result) === 'string' then double-quotes (") wrap the result... why?

JS

localStorage['color'] = "pink";

LESS processed clientside

@color: `
(localStorage.color && localStorage.color !== '') 
? localStorage.color 
: 'blue'
`;

body { background-color: @color; }

Resulting CSS

body {
  background-color: "pink";
}

However I need to not have a quoted string...:

body {
  background-color: pink;
}

Line: https://github.com/cloudhead/less.js/blob/master/dist/less-1.1.4.js#L1849

My current monkey patch is to change:

return new(tree.Quoted)('"' + result + '"', result, this.escaped, this.index);

for

return new(tree.Anonymous)(result);

... but I haven't yet considered security or other concerns with this patch.

Any tips?

Personally I don't think the quotes should be there by default... since quotes are rarely needed in CSS.

chrisjacob avatar Aug 29 '11 15:08 chrisjacob

Please, try prepend your style declaration by ~. E.g:

   @color: ~`
       (localStorage.color && localStorage.color !== '') 
       ? localStorage.color 
       : 'blue'
   `;

imeleshkov avatar Oct 28 '11 15:10 imeleshkov