Implemented named arguments #619
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've reimplemented named arguments using the same syntax as James' earlier implementation - i.e.
.mixin(@arg: value, @arg2: value).Named arguments are particularly useful when working with CSS frameworks. For instance, if you had a mixin like this:
You can then either use it like this, as usual:
Or set specific parameters like this:
I'm not yet convinced that this is the best syntax: it's certainly consistent with mixin definitions, but it feels a little bit strange if you're passing variables in with the same name as the keyword argument (e.g.
.mixin(@width: @width)). Feedback and/or suggestions on an alternative syntax from LESS users would be appreciated!The implementation places constraints on keyword arguments similar to those of Python: errors are thrown when positional arguments are placed after keyword arguments, when multiple values are received for a parameter, and when unexpected keyword arguments are received.
Finally, I'm not really sure how well named arguments work with combined with some of the recent additions to mixins (mainly patterns and
@arguments); the current behaviour works, but might be unintuitive. Again, feedback from users would be helpful!