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

Problems parsing multiplication by negative constant #1291

Closed
al3jo opened this issue Jun 23, 2015 · 4 comments
Closed

Problems parsing multiplication by negative constant #1291

al3jo opened this issue Jun 23, 2015 · 4 comments

Comments

@al3jo
Copy link

al3jo commented Jun 23, 2015

Description

This partial file from Sass gets included when you need to support IE7.

There's a mixin here that libsass have trouble parsing: ie7-pull. That's a complex expression, but the isolated problem is the #{$decimal * -1}.

After calling this file in the console with node-sass spec.scss this is the output:

{
  "message": "invalid operands for multiplication",
  "column": 13,
  "line": 2,
  "file": "spec.scss",
  "status": 1
}

Workaround

A workaround for this particular case is pretty simple, just rewrite the mixin as follows:

@mixin ie7-pull($decimal) {
  $decimal: #{- $decimal};

  @if $unsemantic-ie7-support {
    /* <IE7> */
    *#{$lang-forward}: unquote("expression(Math.floor(#{$decimal} * (this.parentNode.offsetWidth - parseFloat(this.parentNode.currentStyle.paddingLeft) - parseFloat(this.parentNode.currentStyle.paddingRight))) + \"px\")");
    /* </IE7> */
  }
}

How to reproduce

Here's a sassmeister gist with some specific example. The code is also here:

Sass

@mixin spec1($decimal) {
  $decimal: unquote($decimal) * -1;
  value: $decimal;
}

@mixin spec2($decimal) {
  $decimal: -1 * unquote($decimal);
  value: $decimal;
}

@mixin spec3($decimal) {
  value: #{$decimal * -1};
}

@mixin spec1_fix($decimal) {
  $decimal: #{- $decimal};
  value: $decimal;
}

@mixin spec2_fix($decimal) {
  $decimal: #{- $decimal};
  value: $decimal;
}

@mixin spec3_fix($decimal) {
  value: #{- $decimal};
}

.my-element {
  @include spec1(3);
  @include spec1(-3);
  @include spec2(5);
  @include spec2(-5);
  @include spec3(7);
  @include spec3(-7);
}

Expected output

.my-element {
  value: -3;
  value: 3;
  value: -5;
  value: 5;
  value: -7;
  value: 7;
}

The above workaround can be applied to the specs provided for them to work.

Updated: to fix the duplicated mixins in the steps to reproduce

@mgreter
Copy link
Contributor

mgreter commented Jun 23, 2015

Latest ruby sass gives the following warnings, which is why libsass does not support this (yet?)

DEPRECATION WARNING: Passing 3, a non-string value, to unquote()
will be an error in future versions of Sass.
        on line 2 of foo.scss, in `spec1'
        from line 16 of foo.scss

@al3jo
Copy link
Author

al3jo commented Jun 23, 2015

As it turns out, this has to do with the deprecated warnings.
Updating the code to not use deprecated APIs fixes this.

Thanks

mgreter added a commit to mgreter/libsass that referenced this issue Jun 23, 2015
@mgreter
Copy link
Contributor

mgreter commented Jun 23, 2015

@xzyfer since it was easy I refactored the unquote function to match current latest ruby sass (also reporting a deprecation warning). IMO we currently support this for Lists, so IMO it's more correct this way. As a side note: Ruby sass quote function already errors out on other types than strings.

@mgreter mgreter added this to the 3.3 milestone Jun 23, 2015
@mgreter mgreter self-assigned this Jun 23, 2015
mgreter added a commit to mgreter/libsass that referenced this issue Jun 23, 2015
@xzyfer
Copy link
Contributor

xzyfer commented Jun 29, 2015

Specs added sass/sass-spec#411

mgreter added a commit to mgreter/libsass that referenced this issue Jun 30, 2015
mgreter added a commit to mgreter/libsass that referenced this issue Jun 30, 2015
mgreter added a commit to mgreter/libsass that referenced this issue Jun 30, 2015
xzyfer added a commit to xzyfer/sass-spec that referenced this issue Jul 8, 2015
xzyfer pushed a commit to xzyfer/libsass that referenced this issue Jul 8, 2015
xzyfer pushed a commit to xzyfer/libsass that referenced this issue Jul 8, 2015
xzyfer pushed a commit to xzyfer/libsass that referenced this issue Jul 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants