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

Allows root (non-value) functions in Less #2785

Merged
merged 9 commits into from
Mar 15, 2016
Merged

Conversation

matthew-dean
Copy link
Member

This PR greatly increases the utility of @plugin in the following ways:

  1. Custom functions can be called from the root of a ruleset. This is so plugins can return any type of node, not just a Value node. Less still checks during evaluation if the node is allowed there. So, for example, if no custom function is defined, then Less will assume it's an unknown CSS function, which is not allowed in the root.
  2. Like mixins, custom functions can receive detached rulesets, to do more advanced transformations of rules via JavaScript, or: to simply pass "structured data" to a function. Or, to pass a Less list and another node type to do some kind of processing on each member of the list as it relates to that Node. There really isn't a limitation here.
  3. Functions now allow semi-colon separators. This addresses Allow Semicolon as Function Argument Separator #1505 and a number of the use cases in Allow parametrized mixins as detached rulesets to form 'lambdas' #2270.

I've added some additional tests demonstrating custom functions.

@matthew-dean
Copy link
Member Author

Just as an aside, I discovered from this that creating Less nodes is HARD. That is, there is very little "auto-conversion" of strings to node types, and Less nodes are very granular. So there's certainly still room for improvement on the API side.

@matthew-dean matthew-dean changed the title Root functions for custom plugins Allows root (non-value) functions in Less Jan 27, 2016
@matthew-dean
Copy link
Member Author

@seven-phases-max I probably went overkill on the number of tests I added, but I did one for every node type found in a ruleset root that should produce an error.

Take a look and let me know if you think it's safe to merge.

matthew-dean added a commit that referenced this pull request Mar 15, 2016
Allows root (non-value) functions in Less
@matthew-dean matthew-dean merged commit 2f07cd7 into master Mar 15, 2016
@matthew-dean matthew-dean deleted the root-functions branch March 15, 2016 16:52
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