imports #4

Open
iframeskills opened this Issue May 24, 2012 · 13 comments

Projects

None yet

9 participants

@iframeskills

(thanks for the great plugin! small issue below:)

@media screen {
  @import "homepage.less";
  @import "searchresults.less";
}

-> fails

@media screen {
@import "homepage.less";
@import "searchresults.less";
}

-> does not fail.

Whitespace before imports seem to break compilation

/*@import "homepage.less";*/

also breaks. blocklevel comments and imports don't get along either.

@marceloverdijk
Owner

Hi @iframeskills,

I know imports can be a little bit cranky...
The lesscss-maven-plugin uses my lesscss-java library (https://github.com/marceloverdijk/lesscss-java).

Resolving imports is done using a regexp pattern in https://github.com/marceloverdijk/lesscss-java/blob/master/src/main/java/org/lesscss/LessSource.java:

private static final Pattern IMPORT_PATTERN = Pattern.compile("^(?!\\s*//\\s*)@import\\s+(url\\()?\\s*\"(.+)\\s*\"(\\))?\\s*;.*$", MULTILINE);

I think this needs a little bit of tweaking...

@jandebleser

Perhaps this is a better regex?

^\s*(?!//)\s*@import\s+(url\()?\s*\"(.+)\s*\"(\))?\s*;.*$

And as for the block comments, it's always better to filter them out before parsing the file.

/\*.*?\*/
@marceloverdijk
Owner

Good point about filtering block comments before parsing; I will definitely add that!

Honestly, I'm very bad at reg exp, can you maybe explain your changes?

@jandebleser

I just changed the first part
this:

(?!\\s*//\\s*)

into this (now with double backslashes):

\\s*(?!//)\\s*

What it does: The \s* allows whitespace, and the (?!//) disallows line comments.
What you had before did not allow whitespace at all.

Thanks for the great plugin by the way :)

@jandebleser

And you could even omit the line comment part, since the whitespace rule will already filter it out.
This would then be the regex (with double backslashes):

^\\s*@import\\s+(url\\()?\\s*\"(.+)\\s*\"(\\))?\\s*;.*$
@candrews
Collaborator

I'm seeing this issue as well - do you have a guess when this fix may be made? Thanks!

@alanshaw

+1

I just got caught out as well.

@marceloverdijk
Owner

I was waiting for a next less version...

@disolovyov

You might as well incorporate single quotes into the regex, as this is also valid:

@import 'file.less';

Regexes aside, have you considered not tying lesscss-java releases strictly to less.js?

@rweng
rweng commented Dec 3, 2012

+1 to singe quotes in regex. This broke my build.

@MattSenter

+1 This just got me too. Was about to file an issue after tracking it down, only to realize I should have read this one first! =)

@paulfairless paulfairless referenced this issue in paulfairless/grails-lesscss-resources Jan 21, 2013
Closed

@import appears broken #26

@cpopov cpopov was assigned Mar 1, 2013
@cpopov
Collaborator
cpopov commented Mar 1, 2013

I will look into it. Simple quote imports is fixed for 1.3.3. I need to reproduce the issue with white spaces.

@cpopov
Collaborator
cpopov commented Mar 3, 2013

normally lesscss.js manages imports. But I am not sure how it will work in a Rhino environment. I am just thinking that if lesscss.js manages imports, maybe we shouldn't do a pre-processing with regexps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment