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 parent selectors &:not(&) - 2026 #2400

Merged
merged 4 commits into from
Jan 28, 2015

Conversation

SomMeri
Copy link
Member

@SomMeri SomMeri commented Jan 20, 2015

Related to #2026 - nested parent selectors.

E.g. parent selector in following code should be replaced:

.foo {
    .selector:not(&_bar) {
        color:red;
    }
}

and compile into:

.foo {
    .selector:not(.foo_bar) {
        color:red;
    }
}

color: #ff0000;
}
}
&:nth-child(@{num}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[edit] extra space - its less, so just needs tidying

@lukeapage
Copy link
Member

Congratulations on editing that code - I wrote it originally and I still find it daunting any time I have to go back and make changes, it takes time to understand. Thanks for adding the comments. Any chance you could add a comment in this PR on roughly what you changed? I've spent a while looking at it and get the basic concept, but I'm a little lost on what has changed and what hasn't.

If you don't have time to do the tidyups, I can do that after pulling.

@SomMeri
Copy link
Member Author

SomMeri commented Jan 27, 2015

This is the new part and it calls this new function. The rest is mostly extracting pieces of code into functions and renaming variables.

New functions: replaceParentSelector contains mostly code that used to be inlined. E.g. it was called only from one place after I extracted it. The same with addReplacementIntoPath and addAllReplacementsIntoPath.

The change is in replaceParentSelector. It used to loop through all selector elements. Parent selectors & were replaced and everything else was left as is. It did not worked correctly, because this &:not(&) is parsed into three elements array with elements being:

  • &
  • :not
  • parenthesis(selector(elements:[&]))

So, it would look at parenthesis(selector(elements:[&])), conclude it is not parent selector and leave it alone. Find selector function looks for such structures. If it is found, new code calls replaceParentSelector recursively on found nested selector.

The last step is to pack it all back into parenthesis+selector and store into newSelectors so it can be added into paths the same way as normal parent selector replacement.

jurcovicovam added 2 commits January 28, 2015 09:50
Bug fixed: fixed handling of multi level nesting.
…6-v1

Conflicts:
	lib/less/parser/parser.js
	lib/less/tree/ruleset.js
@SomMeri
Copy link
Member Author

SomMeri commented Jan 28, 2015

@lukeapage I modified the pull request. Changes:

  • merged less.js master changes,
  • fixed spacing and commented code,
  • fixed one more bug - multiple rulesets nestings.

@lukeapage
Copy link
Member

Sorry about whitspace merging! Hope it wasnt too painfull.. I started
noticing quite varied coding styles..

@SomMeri
Copy link
Member Author

SomMeri commented Jan 28, 2015

I did not noticed. Git apparently handled that fine :)

lukeapage added a commit that referenced this pull request Jan 28, 2015
@lukeapage lukeapage merged commit 85dde91 into less:master Jan 28, 2015
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.

2 participants