Skip to content

Commit 4462a55

Browse files
authored
Produce a deprecation warning for ID strings that look like colors (#2361)
* Make the deprecation function more generic * Produce a deprecation warning for ID strings that look like colors Fixes #2302 Spec sass/sass-spec#1099
1 parent dcb2e3f commit 4462a55

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

src/error_handling.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,18 @@ namespace Sass {
180180
std::cerr << " on line " << pstate.line+1 << " of " << output_path << std::endl;
181181
}
182182

183-
void deprecated(std::string msg, std::string msg2, ParserState pstate)
183+
void deprecated(std::string msg, std::string msg2, bool with_column, ParserState pstate)
184184
{
185185
std::string cwd(Sass::File::get_cwd());
186186
std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
187187
std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
188188
std::string output_path(Sass::File::path_for_console(rel_path, pstate.path, pstate.path));
189189

190190
std::cerr << "DEPRECATION WARNING on line " << pstate.line + 1;
191+
if (with_column) std::cerr << ", column " << pstate.column + pstate.offset.column + 1;
191192
if (output_path.length()) std::cerr << " of " << output_path;
192193
std::cerr << ":" << std::endl;
193-
std::cerr << msg << " and will be an error in future versions of Sass." << std::endl;
194+
std::cerr << msg << std::endl;
194195
if (msg2.length()) std::cerr << msg2 << std::endl;
195196
std::cerr << std::endl;
196197
}

src/error_handling.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ namespace Sass {
195195
void warn(std::string msg, ParserState pstate, Backtrace* bt);
196196

197197
void deprecated_function(std::string msg, ParserState pstate);
198-
void deprecated(std::string msg, std::string msg2, ParserState pstate);
198+
void deprecated(std::string msg, std::string msg2, bool with_column, ParserState pstate);
199199
void deprecated_bind(std::string msg, ParserState pstate);
200200
// void deprecated(std::string msg, ParserState pstate, Backtrace* bt);
201201

src/expand.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ namespace Sass {
666666
d->name() == "url"
667667
)) {
668668
deprecated(
669-
"Naming a function \"" + d->name() + "\" is disallowed",
669+
"Naming a function \"" + d->name() + "\" is disallowed and will be an error in future versions of Sass.",
670670
"This name conflicts with an existing CSS function with special parse rules.",
671-
d->pstate()
671+
false, d->pstate()
672672
);
673673
}
674674

src/parser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,19 @@ namespace Sass {
16021602
if (lex< sequence < alternatives< hex, hex0 >, negate < exactly<'-'> > > >())
16031603
{ return lexed_hex_color(lexed); }
16041604

1605+
if (lex< hexa >())
1606+
{
1607+
std::string s = lexed.to_string();
1608+
1609+
deprecated(
1610+
"The value \""+s+"\" is currently parsed as a string, but it will be parsed as a color in",
1611+
"future versions of Sass. Use \"unquote('"+s+"')\" to continue parsing it as a string.",
1612+
true, pstate
1613+
);
1614+
1615+
return SASS_MEMORY_NEW(String_Quoted, pstate, lexed);
1616+
}
1617+
16051618
if (lex< sequence < exactly <'#'>, identifier > >())
16061619
{ return SASS_MEMORY_NEW(String_Quoted, pstate, lexed); }
16071620

src/prelexer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ namespace Sass {
10361036
const char* hexa(const char* src) {
10371037
const char* p = sequence< exactly<'#'>, one_plus<xdigit> >(src);
10381038
ptrdiff_t len = p - src;
1039-
return (len != 4 && len != 7 && len != 9) ? 0 : p;
1039+
return (len != 5 && len != 9) ? 0 : p;
10401040
}
10411041
const char* hex0(const char* src) {
10421042
const char* p = sequence< exactly<'0'>, exactly<'x'>, one_plus<xdigit> >(src);
@@ -1268,7 +1268,7 @@ namespace Sass {
12681268
optional_css_whitespace,
12691269
exactly<'='>,
12701270
optional_css_whitespace,
1271-
alternatives< variable, identifier_schema, identifier, quoted_string, number, hexa >,
1271+
alternatives< variable, identifier_schema, identifier, quoted_string, number, hex, hexa >,
12721272
zero_plus< sequence<
12731273
optional_css_whitespace,
12741274
exactly<','>,
@@ -1278,7 +1278,7 @@ namespace Sass {
12781278
optional_css_whitespace,
12791279
exactly<'='>,
12801280
optional_css_whitespace,
1281-
alternatives< variable, identifier_schema, identifier, quoted_string, number, hexa >
1281+
alternatives< variable, identifier_schema, identifier, quoted_string, number, hex, hexa >
12821282
>
12831283
> >
12841284
> >,
@@ -1313,6 +1313,7 @@ namespace Sass {
13131313
identifier,
13141314
quoted_string,
13151315
number,
1316+
hex,
13161317
hexa,
13171318
sequence <
13181319
exactly < '(' >,

0 commit comments

Comments
 (0)