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

added failing test for #49 #431

Closed
wants to merge 5 commits into from
Closed

Conversation

neonstalwart
Copy link
Contributor

test case to show problem described in #49

@neonstalwart
Copy link
Contributor Author

my naive first attempt was to try and remove duplicate rules when rendering a ruleset but this causes other tests to fail since they depend on the output containing duplicated rules. however, when the css is parsed, only the last rule will be effective so this wouldn't change the effect of the resulting css. in case anybody wants to see that approach, this is the diff. if @cloudhead likes this, i'll make a pull request of it. otherwise, i'll still be looking for other ways to fix this issue.

diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js
index cc9a60a..3aee4ca 100644
--- a/lib/less/tree/ruleset.js
+++ b/lib/less/tree/ruleset.js
@@ -114,6 +114,7 @@ tree.Ruleset.prototype = {
             rulesets = [], // node.Ruleset instances
             paths = [],    // Current selectors
             selector,      // The fully rendered selector
+            names = {},    // used to remove duplicate names in rulesets
             rule;

         if (! this.root) {
@@ -161,6 +162,11 @@ tree.Ruleset.prototype = {
                         return s.toCSS(env);
                     }).join('').trim();
                 }).join(env.compress ? ',' : (paths.length > 3 ? ',\n' : ', '));
+                // only keep the last occurence for rules with the same name
+                rules = rules.reverse().filter(function (rule) {
+                    var name = rule.substr(0, rule.indexOf(':'));
+                    return !(name in names) && (names[name] = 1);
+                }).reverse();
                 css.push(selector,
                         (env.compress ? '{' : ' {\n  ') +
                         rules.join(env.compress ? '' : '\n  ') +

 - this maintains the behavior where all mixins that matched the call
   are applied
 - if the result of applying the mixins produces rules with the same
   name then the last rule with that name wins
 - an alternative approach would be to only apply the last mixin that
   matches the call
@neonstalwart
Copy link
Contributor Author

@cloudhead, there are alternative ways to approach this fix but this was the least different to how things work now. i'd be glad to take a different approach if you prefer.

the following would be intentional and should be allowed:
	.foo {
		background: #fff;
		background: rgba(255, 255, 255, 0.8);
	}
@jeremyricketts
Copy link

So, what's the word on this fix? This looks like a 5 month old pull request on a 2 year old bug. (#324 #49 #71)

@Kalyse
Copy link

Kalyse commented Mar 13, 2012

Agree. This need merging.
Just managed to knock of 6KB from a gzipped CSS build, and 100kb from the non-gzipped version because of this. Like Dojo, I have a very modular CSS base for all of my components, so neonstalwarts pull request was extremely useful.

@neonstalwart
Copy link
Contributor Author

@jeremyricketts this is not the only open pull request that solves bugs that have existed for a long time.

a number of people maintain their own forks of this project because of the lack of support for this library. if you have the opportunity to try an alternative library you should do it.

unfortunately i need to maintain some projects that don't have the opportunity to move away from less right now so i have to keep trying to get pull requests applied.

my current philosophy is "no less, no more" - i won't be using it on any new projects.

i've learned a valuable lesson that a permissive license is only a small part of being open source.

@Kalyse
Copy link

Kalyse commented Mar 13, 2012

@neonstalwart

I tried a pull of your fork of less earlier and checked out the multi-mixin branch. Unfortunately it was using the older version of less and also wasn't compatible with the newer way of requiring modules. ie dropping require.paths.

I've tried to copy what you did by using the rules.toCSS() but I couldn't get it to work. Something about compression module missing.

I see also that the version of less that Dojo uses is old too, so I couldn't drop my .less files into the /themes/* as my own custom replacement of claro/soria etc. I'm assuming that the other projects that you were referring to is Dojo, and my question is, 1) Do you have plans to bring your fork upto date with the latest version of Less? 2) Will Dojo ship with a later version of less seeing as it doesn't support some of the more useful mixin properties at the moment. (ie using when() ).

@neonstalwart
Copy link
Contributor Author

yes, dojo is one of the other projects i was referring to. the fork in the neonstalwart account is just for me to provide pull requests - i don't keep it up to date unless i need to open another pull request. if i recall correctly, the "usable" branch in my repo is the best one to try but i haven't touched it in a while. the fork that i use for work with my employer is at https://github.com/cello/less.js and it should be usable in some form but i also don't update it unless i need to.

now that less 1.3 has just been released, i plan to update dojo to use that but dojo doesn't use a patched version of less so that won't help you.

@cloudhead
Copy link
Member

This won't work because we need the ability to specify multiple attributes with the same name..

@neonstalwart
Copy link
Contributor Author

@cloudhead did you look closely? it allows for multiple attributes with the same name - look at the tests.

@cloudhead
Copy link
Member

Ah I just looked at the diff. If we're comparing with values too though, may as well do it for everything?

@neonstalwart
Copy link
Contributor Author

@cloudhead what do you mean? what needs to change?

@cloudhead
Copy link
Member

Ok, here's the fix: cb78933

@neonstalwart
Copy link
Contributor Author

@cloudhead i see - that does the same thing i was doing except i was avoiding calling indexOf for every rule.

i'll try to get around to opening a pull request with some more tests to cover this and another with the change to be able to run the tests from any dir.

@neonstalwart
Copy link
Contributor Author

...and i see what you mean by do it for everything - not just mixins.

stefanklug pushed a commit to stefanklug/carto that referenced this pull request Jan 27, 2019
change underscore dependency to lodash
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

4 participants