less-docs icon indicating copy to clipboard operation
less-docs copied to clipboard

`$@` (Variable properties) should be documented

Open ayyash opened this issue 7 years ago • 3 comments

Under maps, section named: Using variable variables in lookups references lookups, not maps, so when I tried to apply it, the code looks like this

@foods: {
    dessert: ice cream; // Turn into a map
};
@key-to-lookup: dessert;
.lunch {
    treat: @foods[@@key-to-lookup];
}

Compilation result: variable @dessert not found. So if variable variables are not applicable to the new Maps, it should be removed from documentation.

ayyash avatar Jan 10 '19 06:01 ayyash

@ayyash You have defined dessert as a property, not a variable (there's no such "key" as @dessert, therefore you need the property variable syntax, as follows:

@foods: {
    dessert: ice cream; // Turn into a map
};
@key-to-lookup: dessert;
.lunch {
    treat: @foods[$@key-to-lookup];
}

Properties are referenced using $ or the plain name, but to look up a variable property, you need $@

matthew-dean avatar Jan 10 '19 19:01 matthew-dean

Updated the description as I don't think variable properties are currently documented, even though this functionality exists.

matthew-dean avatar Jan 10 '19 19:01 matthew-dean

See: https://github.com/less/less.js/issues/3362

matthew-dean avatar Feb 12 '19 02:02 matthew-dean