Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On invalid LESS, throw exception rather than emit blanks #478

Merged
merged 1 commit into from Sep 27, 2013

Conversation

atdt
Copy link
Collaborator

@atdt atdt commented Sep 26, 2013

This patch makes lessphp throw errors when it is called to compile LESS code
that references undefined variables or mixins. A mixin invocation will cause an
exception to be thrown if it fails to match, whether it is because no mixin of
that name exists, or because the invocation fails to match against the
signatures or guards of defined mixins. This is consistent with the behavior of
the reference LESS implementation.

The patch removes cases from tests/inputs/* that fail to compile. A new test
suite, ErrorHandlingTest.php, verifies the new error-throwing behavior.

This patch makes lessphp throw errors when it is called to compile LESS code
that references undefined variables or mixins. A mixin invocation will cause an
exception to be thrown if it fails to match, whether it is because no mixin of
that name exists, or because the invocation fails to match against the
signatures or guards of defined mixins. This is consistent with the behavior of
the reference LESS implementation.

The patch removes cases from tests/inputs/* that fail to compile. A new test
suite, ErrorHandlingTest.php, verifies the new error-throwing behavior.
@jgonera
Copy link

jgonera commented Sep 27, 2013

Fixes #475.

leafo added a commit that referenced this pull request Sep 27, 2013
On invalid LESS, throw exception rather than emit blanks
@leafo leafo merged commit a39a773 into leafo:master Sep 27, 2013
@leafo
Copy link
Owner

leafo commented Sep 27, 2013

Awesome, thanks for the patch

@mitom
Copy link

mitom commented Sep 27, 2013

After this patch trying to compile twitter bootstrap results in a
Fatal Error: .pull-right is undefined: bootstrap/less/bootstrap.less on line 60

@atdt
Copy link
Collaborator Author

atdt commented Sep 27, 2013

Hrm, I'll investigate.

@jdlrobson
Copy link

@mitom I'm pretty sure this is an issue with Bootstrap...

Looking at the bootstrap LESS implementation I found a minimum test case:

.dropdown-menu {
  position: absolute;
}

@media (min-width: 100px) {
  .navbar-right {
    .dropdown-menu {
      .pull-right > .dropdown-menu();
    }
  }
}

If you render this before the patch you get

.dropdown-menu {
  position: absolute;
}

After the patch you get the error you are reporting.
I'm pretty sure that media query is invalid LESS so it is doing exactly what it is meant to be doing (it gets confused by the syntax and thinks there is a mixin called pull-right)

Can anyone confirm?

@jdlrobson
Copy link

This seems to be consistent with the nodejs implementation of less
When I try to render this I get:

NameError: .pull-right > .dropdown-menu is undefined in less/common/common.less:11:6
10 .dropdown-menu {
11 .pull-right > .dropdown-menu();
12 }

@jdlrobson
Copy link

I'm running lessc 1.3.3 (LESS Compiler) [JavaScript] so it seems this is new syntax introduced since then that bootstrap is using that lessphp doesn't yet support.

As an interim measure until we reflect that new syntax we might want to consider a variable --hide-errors or something similar? Although it seems surfacing the error is a much better thing exactly for this reason.

@Krinkle Krinkle mentioned this pull request Sep 30, 2013
@tomsarduy
Copy link

#483

@mattleff
Copy link

@atdt said:

A mixin invocation will cause an exception to be thrown if it fails to match, whether it is because no mixin of that name exists, or because the invocation fails to match against the signatures or guards of defined mixins. This is consistent with the behavior of the reference LESS implementation.

This is not consistent with reference LESS implementation, specifically as it relates to guards. If a guard must match in order to avoid throwing an exception there is no point to having the guard. Guards as they exist in lessphp now are either matching (in which case the selectors, properties, etc. will be added) or they throw an exception in which case the whole .less file not be rendered. The last two tests in tests/ErrorHandlingTest.php disagree with the results from Less.js. (See here and here).

It is not possible to run the doc examples anymore. IMO, it is better to allow guards by reverting the undefined mixin error to a break.

cc/ @leafo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants