Skip to content

Commit a6b7dbd

Browse files
mgreterxzyfer
authored andcommitted
Improve deprecation handling in unquote function
Fixes #1291
1 parent 0a57e9d commit a6b7dbd

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

error_handling.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ namespace Sass {
2020
warn(msg, pstate);
2121
}
2222

23+
void deprecated(string msg, ParserState pstate)
24+
{
25+
string cwd(Sass::File::get_cwd());
26+
cerr << "DEPRECATION WARNING: " << msg << endl;
27+
cerr << "will be an error in future versions of Sass." << endl;
28+
string rel_path(Sass::File::resolve_relative_path(pstate.path, cwd, cwd));
29+
cerr << " on line " << pstate.line+1 << " of " << rel_path << endl;
30+
}
31+
2332
void error(string msg, ParserState pstate)
2433
{
2534
throw Sass_Error(Sass_Error::syntax, pstate, msg);

error_handling.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ namespace Sass {
2424
void warn(string msg, ParserState pstate);
2525
void warn(string msg, ParserState pstate, Backtrace* bt);
2626

27+
void deprecated(string msg, ParserState pstate);
28+
// void deprecated(string msg, ParserState pstate, Backtrace* bt);
29+
2730
void error(string msg, ParserState pstate);
2831
void error(string msg, ParserState pstate, Backtrace* bt);
2932

functions.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,15 @@ namespace Sass {
777777
result->sass_fix_1291(string_quoted->quote_mark() != 0);
778778
return result;
779779
}
780-
To_String to_string(&ctx);
781-
return new (ctx.mem) String_Constant(pstate, unquote(string(arg->perform(&to_string))));
780+
else if (dynamic_cast<String_Constant*>(arg)) {
781+
return (Expression*) arg;
782+
}
783+
else {
784+
To_String to_string(&ctx);
785+
string val(arg->perform(&to_string));
786+
deprecated("Passing " + val + ", a non-string value, to unquote()", pstate);
787+
return (Expression*) arg;
788+
}
782789
}
783790

784791
Signature quote_sig = "quote($string)";

0 commit comments

Comments
 (0)