SomMeri / less4j

Less language is an extension of css and less4j compiles it into regular css. Less adds several dynamic features into css: variables, expressions, nested rules, and so on. Less was designed to be compatible with css and any correct css file is also correct less file.
145 stars 47 forks source link

Exceptions with valid Less syntax #309

Closed sherrybomb closed 8 years ago

sherrybomb commented 8 years ago

I've found several instances of syntax that compiles with Less that cause Less4jExceptions using less4j 1.14:

1) no viable alternative at input 'html' in ruleset (which started at 380:1) 379: 380: html[data-sap-ui-browser ^= "ie"] { 381: .sapMOHRTitleIcon > .sapMOHRTitle {

*lessc compiles this to: html[data-sap-ui-browser^="ie"] .sapMOHRTitleIcon > .sapMOHRTitle {

2) no viable alternative at input 'border' in ruleset (which started at 32:2) 31: background: white; 32: border: 2px solid@sapUiPurple; 33: }

*lessc compiles this to: border:2px solid #ab218e

3) no viable alternative at input '=' in expression (which started at 31:89) 30: } 31: .GenerateGraphStyle (@colorValue1;@colorValue2;@contrastDiff) when (luma(@colorValue2) <= 50) { 32: color: @colorValue1;

4) no viable alternative at input 'margin' in ruleset (which started at 521:3) 520: font-size:@objectmanagerPropertyPanelButtonIconSize;//1.125rem 521: margin: 0@marginValueKey00 @marginValueKey0015rem @marginValueKey00 @marginValueKey0015rem; 522: line-height:2;

*lessc compiles this to: margin: 0 0 0.15rem 0 0.15rem;

5) no viable alternative at input 'background' in ruleset (which started at 79:73) 78: .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Verdana,Arial,sans-serif/{ffDefault}/; font-size: 1em; } 79: .ui-widget-content { border: 1px solid #aaaaaa/{borderColorContent}/; background: #ffffff/{bgColorContent}/ url(img/jQuery/ui-bg_flat_75_ffffff_40x100.png)/{bgImgUrlContent}/ 50%/{bgContentXPos}/ 50%/{bgContentYPos}/ repeat-x/{bgContentRepeat}/; color: #222222/{fcContent}/; } 80: .ui-widget-content a { color: #222222/{fcContent}/; }

*lessc compiles this to: .ui-widget-content{border:1px solid #aaaaaa;background:#ffffff url(img/jQuery/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x;color:#222222}

sherrybomb commented 8 years ago

And one more...

6) no viable alternative at input '-webkit-box-shadow' in ruleset (which started at 481:3) 480: box-shadow: 1px 1px 4px @defaultBoxShadowColor; 481: -webkit-box-shadow: 1px 1px 4px@defaultBoxShadowColor; 482: -moz-box-shadow: 1px 1px 4px @defaultBoxShadowColor;

davydotcom commented 8 years ago

If it helps looks like i have to back down all the way to 1.10.0 to not get these errors too

SomMeri commented 8 years ago

Thank you for the report, I will fix those.

Off-topic: it is better to close code examples into four ticks like shown here. The code will be easier to read people with same names as your variables wont be getting emails.

SomMeri commented 8 years ago

Retested on just released 1.15.0:

Fails: Number 1:

html[data-sap-ui-browser ^= "ie"] {
  .sapMOHRTitleIcon > .sapMOHRTitle {
    property: value;
  }
}

Number 3:

.GenerateGraphStyle (@colorValue1;@colorValue2;@contrastDiff) when (luma(@colorValue2) <= 50) {
  color: @colorValue1;
}

div {
  .GenerateGraphStyle(blue, red, 1);
}

Number 5:

div {
 .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Verdana,Arial,sans-serif/*{ffDefault}*/; font-size: 1em; }
 .ui-widget-content { border: 1px solid #aaaaaa/*{borderColorContent}*/; background: #ffffff/*{bgColorContent}*/ url(img/jQuery/ui-bg_flat_75_ffffff_40x100.png)/*{bgImgUrlContent}*/ 50%/*{bgContentXPos}*/ 50%/*{bgContentYPos}*/ repeat-x/*{bgContentRepeat}*/; color: #222222/*{fcContent}*/; }
 .ui-widget-content a { color: #222222/*{fcContent}*/; }
}

Works: Number 6:

@defaultBoxShadowColor: blue;
div {
  box-shadow: 1px 1px 4px @defaultBoxShadowColor;
  -webkit-box-shadow: 1px 1px 4px@defaultBoxShadowColor;
  -moz-box-shadow: 1px 1px 4px @defaultBoxShadowColor;
}

Number 2:

no-space {
 background: white;
 border: 2px solid@sapUiPurple;
}
@sapUiPurple: #ab218e;

Number 4:

@objectmanagerPropertyPanelButtonIconSize: 1.12rem;
@marginValueKey00:0;
@marginValueKey0015rem:0.15rem;
div {
 font-size:@objectmanagerPropertyPanelButtonIconSize;//1.125rem
 margin: 0@marginValueKey00 @marginValueKey0015rem @marginValueKey00 @marginValueKey0015rem;
 line-height:2;
}
SomMeri commented 8 years ago

Checklist:

davydotcom commented 8 years ago

Looks like its a result of a nested @media query

davydotcom commented 8 years ago

Ok narrowed it down in this example. an @media(max-width:720px) causes this error to happen. The only fix is to put a space between @media (max-width:720px)

SomMeri commented 8 years ago

@davydotcom Thank you, that should be easy to fix. I opened new issue for it (#311), so that this one tracks only original six problems.

SomMeri commented 8 years ago

All six referenced problems should disappears after next release. If they do not, let me know.

sherrybomb commented 8 years ago

Thanks for resolving these so promptly! When should I expect 1.15.1 to show up in Maven central?

SomMeri commented 8 years ago

If you need it, I can release tomorrow.

sherrybomb commented 8 years ago

Yes, that would be great.

SomMeri commented 8 years ago

@sherrybomb 1.15.1 was just released, it should be downloadable from maven within next few minutes.

davydotcom commented 8 years ago

Publishing less-asset-pipeline:2.6.1 with latest now thanks @SomMeri !!