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

Functions named calc() or -*-calc() should not be called #1706

Closed
andrew-skybound opened this issue Nov 6, 2015 · 8 comments
Closed

Functions named calc() or -*-calc() should not be called #1706

andrew-skybound opened this issue Nov 6, 2015 · 8 comments

Comments

@andrew-skybound
Copy link

Ruby SASS always outputs function arguments literally when the called function's name is calc() or -*-calc(), even if a custom @function with one of those names has been defined.

As an aside, I have noticed that when call() is used (in both SASS and Libsass) the redefined functions are called. This behavior would need to be preserved to prevent a regression.

Input SASS:

@function calc($e) { @return custom; }
@function -foo-calc($e) { @return custom; }

.test {
    a: calc(1px * 1%);
    b: -foo-calc(2px * 2%);
    c: call(calc, 3px * 3%);
}

Ruby SASS Output (3.4.19):

.test {
    a: calc(1px * 1%);
    b: -foo-calc(2px * 2%);
    c: custom;
}

Libsass Output (3.2.5):

.test {
    a: custom;
    b: custom;
    c: custom;
}
@saper
Copy link
Member

saper commented Nov 13, 2015

Ruby gives a warning:
DEPRECATION WARNING on line 1 of libsass-todo-issues/issue_1706/input.scss:
Naming a function "calc" is disallowed and will be an error in future versions of Sass.
This name conflicts with an existing CSS function with special parse rules.

DEPRECATION WARNING on line 2 of libsass-todo-issues/issue_1706/input.scss:
Naming a function "-foo-calc" is disallowed and will be an error in future versions of Sass.
This name conflicts with an existing CSS function with special parse rules.

@xzyfer
Copy link
Contributor

xzyfer commented Nov 13, 2015

Spec added sass/sass-spec#608

@LPGhatguy
Copy link

I would promote this bug's fix being delayed until after #1776 is also resolved -- as it stands this bug is the best way to sidestep the issue.

@mgreter mgreter modified the milestones: 3.3.3, 3.4 Jan 9, 2016
@mgreter mgreter self-assigned this Jan 9, 2016
@mgreter mgreter modified the milestones: 3.3.4, 3.3.3 Jan 9, 2016
@mgreter
Copy link
Contributor

mgreter commented Jan 9, 2016

Started some initial progress, but fixing all different cases will take a bit longer.

My WIP 3.4 branch currently yields (had to reduce seconds args to numbers)

.test {
  a: calc(1px * 1);
  b: custom;
  c: calc(9px); }

@xzyfer
Copy link
Contributor

xzyfer commented Jan 12, 2016

IIRC Ruby Sass opts out of evaluating arguments for certain special functions like calc. I think this is ideal approach. https://github.com/sass/sass/blob/stable/lib/sass/scss/parser.rb#L932

There is ongoing discussion in Ruby Sass about how to best handle calc - sass/sass#818

@lunelson
Copy link

I noticed the following today with 3.3.4: anything starting with calc seems to be skipped:

@function calcfoo() { @return 'hello world'; }
@function barcalc() { @return 'hello world'; }

.test {
  out: calcfoo();
  out: barcalc();
}
.test {
  out: calcfoo();
  out: "hello world"; }

@lunelson
Copy link

lunelson commented May 4, 2016

So is this the spec then? I have a group of functions that operate on calc() expressions—would be good to know what the future-proof naming convention is

@function calc(){ @return 'hello world'; }
@function -foo-calc(){ @return 'hello world'; }
@function foo-calc(){ @return 'hello world'; }
@function calc-foo(){ @return 'hello world'; }

.test {
  out: calc(); // won't be processed
  out: -foo-calc(); // won't be processed
  out: foo-calc(); // ok?
  out: calc-foo(); // ok?
}
.test {
  out: calc();
  out: -foo-calc();
  out: "hello world";
  out: "hello world";
}

@xzyfer
Copy link
Contributor

xzyfer commented May 4, 2016

I'm on my phone so can't verify but my intuition is that -foo-calc isn't
parse because it looks like a vendor prefix.
On 4 May 2016 7:52 PM, "Lu Nelson" notifications@github.com wrote:

So is this the spec then? I have a group of functions that operate on
calc() expressions—would be good to know what the future-proof naming
convention is

@function calc(){ @return 'hello world'; }@function -foo-calc(){ @return 'hello world'; }@function foo-calc(){ @return 'hello world'; }@function calc-foo(){ @return 'hello world'; }
.test {
out: calc(); // won't be processed
out: -foo-calc(); // won't be processed
out: foo-calc(); // ok?
out: calc-foo(); // ok?
} css.test {
out: calc();
out: -foo-calc();
out: "hello world";
out: "hello world";
}


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#1706 (comment)

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

6 participants