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

Nested File-Import with Sub-Element Selector has unexpected result #2395

Closed
gu-stav opened this issue Jan 15, 2015 · 4 comments
Closed

Nested File-Import with Sub-Element Selector has unexpected result #2395

gu-stav opened this issue Jan 15, 2015 · 4 comments

Comments

@gu-stav
Copy link

gu-stav commented Jan 15, 2015

/* main.less */

html[lang="ru"] {
  @import "languages/ru/clip.less";
}
/* clip.less */

.clip {
  &_sublabel { ... }
  &_module[data-module="touristinfo"] &_details { ... }
}

Result:

/* correct */
html[lang="ru"] .clip_sublabel { ... }

/* incorrect */
html[lang="ru"] .clip_module[data-module="touristinfo"] html[lang="ru"] .clip_details { ... }

/* expected */
html[lang="ru"] .clip_module[data-module="touristinfo"] .clip_details { ... }

OS: Ubuntu 14.10
Less-Version: [email protected]

@seven-phases-max
Copy link
Member

Could you please provide more info on why you think it "fails"? In fact the result is expected (I guess the point of your confusion is the behaviour of & there so see the docs for more details, specifically notice the .grand { .parent { ... example).

@gu-stav
Copy link
Author

gu-stav commented Jan 15, 2015

The unexpected part is the difference between:

.some {
  &_thing &_within { ... }
}

which, I guess, renders to:

.some_thing .some_within { ... }

But when it's nested, as shown above

/* main.less */
.wrap {
  @import 'include.less'
}

/* include.less */
.some {
  &_thing &_within { ... }
}

compiles to

.wrap .some_thing .wrap .some_within { ... }

but I believe it should be

.wrap .some_thing .some_within { ... }

Otherwise it messes the nested single selector up. Don't you think so, @seven-phases-max? Otherwise it would not be possible to wrap a BEM-Block easy inside of another block (html.js/ html.no-js CSS-Class, e.g.) ...

EDIT: After thinking about this more, I understand your point - less respects the wrapping element around the element as parent. But don't you think this is confusing? Could it be thinkable to have the ability for passing in the context of an import like:

.wrap {
  @import 'some.less'
}

/* some.less */
// context == .wrap

.wrap {
  @import (no-context) 'some.less'
}

/* some.less */
// context == ''

@gu-stav gu-stav changed the title Nested File-Import with Sub-Element Selector Fails Nested File-Import with Sub-Element Selector has unexpected result Jan 15, 2015
@seven-phases-max
Copy link
Member

but I believe it should be

Well, no, regardless of what we think personally the & keyword in Less "represents all parent selectors (not just the nearest ancestor)". This is stated in the docs section I linked above.

Otherwise it would not be possible to wrap a BEM-Block easy inside of another block

The & Less feature is not designed specifically for BEM or any other particular naming scheme.


So in summary: this is expected behaviour. (See also related #1075 feature request as well as duplicates of this one: #9, #127, #1158, #1575, #2388 etc.)

@seven-phases-max
Copy link
Member

Closing as expected behaviour.

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

No branches or pull requests

2 participants