less.js
less.js copied to clipboard
JavaScript evaluation - why forcing "Quotes" on strings?
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.
Please, try prepend your style declaration by ~. E.g:
@color: ~`
(localStorage.color && localStorage.color !== '')
? localStorage.color
: 'blue'
`;