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

length for property group is always 1 #4325

Open
ackava opened this issue Mar 17, 2025 · 2 comments
Open

length for property group is always 1 #4325

ackava opened this issue Mar 17, 2025 · 2 comments
Labels

Comments

@ackava
Copy link

ackava commented Mar 17, 2025

To reproduce:

https://lesscss.org/less-preview/#eyJjb2RlIjoiI2xpYigpIHtcbiAgICAuY29sb3JzKCkge1xuICAgICAgQHByaW1hcnk6IGJsdWU7XG4gICAgICBAc2Vjb25kYXJ5OiBncmVlbjtcbiAgICB9XG4gICAgLnJ1bGVzKEBzaXplKSB7XG4gICAgICBib3JkZXI6IEBzaXplIHNvbGlkIHdoaXRlO1xuICAgIH1cbiAgfVxuICBcbiAgLmJveCB3aGVuICgjbGliLmNvbG9yc1tAcHJpbWFyeV0gPSBibHVlKSB7XG4gICAgd2lkdGg6IDEwMHB4O1xuICAgIGhlaWdodDogKCR3aWR0aCAvIDIpO1xuICB9XG4gIFxuICAuYmFyOmV4dGVuZCguYm94KSB7XG4gICAgQG1lZGlhIChtaW4td2lkdGg6IDYwMHB4KSB7XG4gICAgICB3aWR0aDogMjAwcHg7XG4gICAgICAjbGliLnJ1bGVzKDFweCk7XG4gICAgfVxuICB9IiwiYWN0aXZlVmVyc2lvbiI6IjQuMi4yIiwibWF0aCI6InBhcmVucy1kaXZpc2lvbiIsInN0cmljdFVuaXRzIjpmYWxzZX0=

.print(@list) {
  
  length-is {
    a: length(@list);
  }
}

.print({
  @a: {
    overflow: hidden;
  }
  @b: {
    overflow: hidden;
  }
});

Current behavior:

Output is:

length-is {
  a: 1;
}

Expected behavior:

Output should be,

length-is {
  a: 2;
}

As I need to iterate recursively to create few combinations, but problem is length is always zero, length works correctly for simple values, but not for property groups.

@ackava ackava added the bug label Mar 17, 2025
Copy link

dosubot bot commented Mar 17, 2025

The length function in Less is designed to work with lists that are either comma or space-separated, and it returns the number of top-level elements in such lists. However, when it comes to property groups, the length function treats them as a single entity, which is why you are seeing a length of 1 instead of the expected 2.

In your example, the property groups @a and @b are being treated as single elements, hence the length function returns 1. This behavior is consistent with how Less handles complex data types like property groups, which are not directly supported by the length function in the same way as simple lists or arrays.

To achieve the desired behavior, you might need to manually count the property groups or use a different approach to handle them, as the length function does not natively support counting individual property groups within a block.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@matthew-dean
Copy link
Member

The dosubot response is correct. You're passing in one value, and that single value is a detached ruleset.

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

No branches or pull requests

2 participants