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

Variable argument maps #919

Closed
wants to merge 6 commits into from
Closed

Variable argument maps #919

wants to merge 6 commits into from

Conversation

nex3
Copy link
Contributor

@nex3 nex3 commented Sep 13, 2013

Add support for passing maps as variable arguments and using the keywords() function to access them.

# The splat argument for this function, if one exists.
# The first splat argument for this function, if one exists.
#
# This could be a lsit of positional arguments, a map of keyword

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lsit => list

Handles argument lists with both args and varargs when passed only the
explicitly mentioned arguments.
if value && keywords.include?(var.underscored_name)
raise Sass::SyntaxError.new("#{desc} was passed argument $#{var.name} both by position and by name.")
if callable.splat
rest = args[callable.args.length..-1]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be args[callable.args.length..-1] || [] because it's nil when the the number of args is the same.

I pushed a test and fix for this to the branch.

@chriseppstein
Copy link

$adjust-by: (alpha: -10%, "blue": 30%);
.color {c: scale-color($color: purple, $red: -20%, $adjust-by...)};

Raises the error:

Syntax error: Positional arguments must come before keyword arguments.

But the arglist contains only keywords. I think we should allow arglist passing of the form:

something(arg1, arg2, $kwarg1: v1, $kwarg2: v2, $positional_args..., $kwargs...)
// or
something(arg1, arg2, $positional_args..., $kwarg1: v1, $kwarg2: v2, $kwargs...)

Maps can be passed as variable arguments, just like lists. For example, if
`$map` is `(lightness: 10%, blue: -30%)`, you can write `scale-color($color,
$map...)` and it will do the same thing as `scale-color($color, $lightness: 10%,
$blue: 30%)`. To pass a variable argument list and map at the same time, just do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this example doesn't actually work. I updated it.

@chriseppstein
Copy link

Landed as a4e9233

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