arpadHegedus / postcss-node-sass

A PostCSS plugin to parse styles with node-sass
MIT License
23 stars 16 forks source link

sass fail to parse the following expression #3

Closed ArielGueta closed 6 years ago

ArielGueta commented 6 years ago

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.

@function json-encode($value) {
  $type: type-of($value);

  @if function-exists('_json-encode--#{$type}') {
    @return call(get-function('_json-encode--#{$type}', $value));
  }
}

This is a valid scss. You can see the get-function in the docs.

arpadHegedus commented 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);
  }
}
ArielGueta commented 6 years ago

I don't have an error, It is working fine with webpack.

ArielGueta commented 6 years ago

I think the solution is to upgrade node-sass to latest version.

arpadHegedus commented 6 years ago

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.

ArielGueta commented 6 years ago

If it isn't valid, how does it works with webpack? there are also using node-sass under the hood.

arpadHegedus commented 6 years ago

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.

ArielGueta commented 6 years ago

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.

arpadHegedus commented 6 years ago

And that is correct. So now it shouldn't give you an error.

ArielGueta commented 6 years ago

the $value is in the call arguments.

ArielGueta commented 6 years ago

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.

ArielGueta commented 6 years ago

you can see it by yourself if you try to compile the expression by using this library.

arpadHegedus commented 6 years ago

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 "{}"
  }
}
ArielGueta commented 6 years ago

It throws an error, I just omitted this.

@error 'Unknown type for #{$value} (#{$type}).';

ArielGueta commented 6 years ago

Closing it as can't reproduce in an isolated environment. Thanks for your time and help!