Closed ArielGueta closed 6 years ago
I think you have an error in your syntax. The get-function
function in sass needs only one argument, can accept a second one but it is a boolean.
Try this:
@function json-encode($value) {
$type: type-of($value);
@if function-exists('_json-encode--#{$type}') {
@return call(get-function('_json-encode--#{$type}'), $value);
}
}
I don't have an error, It is working fine with webpack.
I think the solution is to upgrade node-sass to latest version.
According to the documentation here: http://sass-lang.com/documentation/Sass/Script/Functions.html#get_function-instance_method
You do have an error. You are calling the get-function
function and you are passing in $value
as the second argument. That argument needs to be a boolean
. What I guess you want to do is add $value
to the arguments of the call
function.
If it isn't valid, how does it works with webpack? there are also using node-sass under the hood.
Well, I am not sure what else you are using or what webpack adds. You can test the different scenarios, but according to the documentation your code is invalid except when you pass in a boolean as the $value
.
What I guess you want to do is add $value to the arguments of the call function.
call(get-function('_json-encode--#{$type}'), $value);
That's what I did.
And that is correct. So now it shouldn't give you an error.
the $value is in the call
arguments.
I'm sorry for the confusion. The first example was a typo. I'm using it how you said. It's valid and it throws and error.
you can see it by yourself if you try to compile the expression by using this library.
Yes, I can see another issue that might give you an error. Sorry for not noticing earlier. There is a possibility that your function doesn't return anything. You need to return a value every time. Try rewriting like this:
@function json-encode($value) {
$type: type-of($value);
@if function-exists('_json-encode--#{$type}') {
@return call(get-function('_json-encode--#{$type}'), $value);
} @else {
@return "{}"
}
}
It throws an error, I just omitted this.
@error 'Unknown type for #{$value} (#{$type}).';
Closing it as can't reproduce in an isolated environment. Thanks for your time and help!
Thanks for the library, I have a problem. I am getting the following error:
sass fail to parse the following expression: get-function("
It's only happening with this plugin. When using webpack loader it works fine. I think it's related to the node-sass version.
This is a valid scss. You can see the get-function in the docs.